@@ -159,11 +159,6 @@ int copy_raw(const uint32_t src_addr,
159
159
gzip = true;
160
160
}
161
161
while (left > 0 ) {
162
- if (!verify ) {
163
- if (SPIEraseSector (daddr /buffer_size )) {
164
- return 2 ;
165
- }
166
- }
167
162
if (!gzip ) {
168
163
if (SPIRead (saddr , buffer , buffer_size )) {
169
164
return 3 ;
@@ -190,8 +185,25 @@ int copy_raw(const uint32_t src_addr,
190
185
return 9 ;
191
186
}
192
187
} else {
193
- if (SPIWrite (daddr , buffer , buffer_size )) {
194
- return 4 ;
188
+ // Special treatment for address 0 (bootloader). Only erase and
189
+ // rewrite if the data is different (i.e. very rarely).
190
+ bool skip = false;
191
+ if (daddr == 0 ) {
192
+ if (SPIRead (daddr , buffer2 , buffer_size )) {
193
+ return 4 ;
194
+ }
195
+ if (!memcmp (buffer2 , buffer , buffer_size )) {
196
+ ets_putc ('B' ); // Note we skipped the bootloader in output
197
+ skip = true; // And skip erase/write
198
+ }
199
+ }
200
+ if (!skip ) {
201
+ if (SPIEraseSector (daddr /buffer_size )) {
202
+ return 2 ;
203
+ }
204
+ if (SPIWrite (daddr , buffer , buffer_size )) {
205
+ return 4 ;
206
+ }
195
207
}
196
208
}
197
209
saddr += buffer_size ;
@@ -229,18 +241,20 @@ int main()
229
241
ets_wdt_enable ();
230
242
231
243
ets_putc ('0' + res ); ets_putc ('\n' );
232
-
233
- /** disabled in 2.7.3
244
+ #if 0
245
+ //devyte: this verify step below (cmp:) only works when the end of copy operation above does not overwrite the
246
+ //beginning of the image in the empty area, see #7458. Disabling for now.
247
+ //TODO: replace the below verify with hash type, crc, or similar.
234
248
// Verify the copy
235
249
ets_putc ('c' ); ets_putc ('m' ); ets_putc ('p' ); ets_putc (':' );
236
250
if (res == 0 ) {
237
251
ets_wdt_disable ();
238
252
res = copy_raw (cmd .args [0 ], cmd .args [1 ], cmd .args [2 ], true);
239
253
ets_wdt_enable ();
240
254
}
241
- ets_putc('0'+res); ets_putc('\n');
242
- **/
243
255
256
+ ets_putc ('0' + res ); ets_putc ('\n' );
257
+ #endif
244
258
if (res == 0 ) {
245
259
cmd .action = ACTION_LOAD_APP ;
246
260
cmd .args [0 ] = cmd .args [1 ];
0 commit comments