@@ -12,13 +12,13 @@ extern "C" {
12
12
13
13
extern " C" uint32_t _SPIFFS_start;
14
14
15
- UpdaterClass::UpdaterClass ()
15
+ UpdaterClass::UpdaterClass ()
16
16
: _error(0 )
17
17
, _buffer(0 )
18
18
, _bufferLen(0 )
19
19
, _size(0 )
20
20
, _startAddress(0 )
21
- , _currentAddress(0 )
21
+ , _currentAddress(0 )
22
22
{
23
23
}
24
24
@@ -39,18 +39,18 @@ bool UpdaterClass::begin(size_t size){
39
39
#endif
40
40
return false ;
41
41
}
42
-
42
+
43
43
if (size == 0 ){
44
44
_error = UPDATE_ERROR_SIZE;
45
45
#ifdef DEBUG_UPDATER
46
46
printError (DEBUG_UPDATER);
47
47
#endif
48
48
return false ;
49
49
}
50
-
50
+
51
51
_reset ();
52
52
_error = 0 ;
53
-
53
+
54
54
// size of current sketch rounded to a sector
55
55
uint32_t currentSketchSize = (ESP.getSketchSize () + FLASH_SECTOR_SIZE - 1 ) & (~(FLASH_SECTOR_SIZE - 1 ));
56
56
// address of the end of the space available for sketch and update
@@ -59,7 +59,7 @@ bool UpdaterClass::begin(size_t size){
59
59
uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1 ) & (~(FLASH_SECTOR_SIZE - 1 ));
60
60
// address where we will start writing the update
61
61
uint32_t updateStartAddress = updateEndAddress - roundedSize;
62
-
62
+
63
63
// make sure that the size of both sketches is less than the total space (updateEndAddress)
64
64
if (updateStartAddress < currentSketchSize){
65
65
_error = UPDATE_ERROR_SPACE;
@@ -68,13 +68,13 @@ bool UpdaterClass::begin(size_t size){
68
68
#endif
69
69
return false ;
70
70
}
71
-
71
+
72
72
// initialize
73
73
_startAddress = updateStartAddress;
74
74
_currentAddress = _startAddress;
75
75
_size = size;
76
76
_buffer = new uint8_t [FLASH_SECTOR_SIZE];
77
-
77
+
78
78
return true ;
79
79
}
80
80
@@ -85,30 +85,30 @@ bool UpdaterClass::end(bool evenIfRemaining){
85
85
#endif
86
86
return false ;
87
87
}
88
-
88
+
89
89
if (hasError () || (!isFinished () && !evenIfRemaining)){
90
90
#ifdef DEBUG_UPDATER
91
91
DEBUG_UPDATER.printf (" premature end: res:%u, pos:%u/%u\n " , getError (), progress (), _size);
92
92
#endif
93
-
93
+
94
94
_reset ();
95
95
return false ;
96
96
}
97
-
97
+
98
98
if (evenIfRemaining){
99
99
if (_bufferLen > 0 ){
100
100
_writeBuffer ();
101
101
}
102
102
_size = progress ();
103
103
}
104
-
104
+
105
105
eboot_command ebcmd;
106
106
ebcmd.action = ACTION_COPY_RAW;
107
107
ebcmd.args [0 ] = _startAddress;
108
108
ebcmd.args [1 ] = 0x00000 ;
109
109
ebcmd.args [2 ] = _size;
110
110
eboot_command_write (&ebcmd);
111
-
111
+
112
112
#ifdef DEBUG_UPDATER
113
113
DEBUG_UPDATER.printf (" Staged: address:0x%08X, size:0x%08X\n " , _startAddress, _size);
114
114
#endif
@@ -126,23 +126,23 @@ bool UpdaterClass::_writeBuffer(){
126
126
_error = UPDATE_ERROR_WRITE;
127
127
_currentAddress = (_startAddress + _size);
128
128
#ifdef DEBUG_UPDATER
129
- printError (DEBUG_UPDATER);
129
+ printError (DEBUG_UPDATER);
130
130
#endif
131
- return false ;
132
- }
133
- _currentAddress += _bufferLen;
134
- _bufferLen = 0 ;
135
- return true ;
131
+ return false ;
132
+ }
133
+ _currentAddress += _bufferLen;
134
+ _bufferLen = 0 ;
135
+ return true ;
136
136
}
137
137
138
138
size_t UpdaterClass::write (uint8_t *data, size_t len) {
139
139
size_t left = len;
140
140
if (hasError () || !isRunning ())
141
141
return 0 ;
142
-
142
+
143
143
if (len > remaining ())
144
144
len = remaining ();
145
-
145
+
146
146
while ((_bufferLen + left) > FLASH_SECTOR_SIZE) {
147
147
size_t toBuff = FLASH_SECTOR_SIZE - _bufferLen;
148
148
memcpy (_buffer + _bufferLen, data + (len - left), toBuff);
@@ -170,7 +170,7 @@ size_t UpdaterClass::writeStream(Stream &data) {
170
170
size_t toRead = 0 ;
171
171
if (hasError () || !isRunning ())
172
172
return 0 ;
173
-
173
+
174
174
while (remaining ()) {
175
175
toRead = FLASH_SECTOR_SIZE - _bufferLen;
176
176
toRead = data.readBytes (_buffer + _bufferLen, toRead);
0 commit comments