Skip to content

Commit de30821

Browse files
authored
Backport esp8266#7547
1 parent 83e5d1f commit de30821

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

bootloaders/eboot/eboot.c

+25-11
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ int copy_raw(const uint32_t src_addr,
159159
gzip = true;
160160
}
161161
while (left > 0) {
162-
if (!verify) {
163-
if (SPIEraseSector(daddr/buffer_size)) {
164-
return 2;
165-
}
166-
}
167162
if (!gzip) {
168163
if (SPIRead(saddr, buffer, buffer_size)) {
169164
return 3;
@@ -190,8 +185,25 @@ int copy_raw(const uint32_t src_addr,
190185
return 9;
191186
}
192187
} 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+
}
195207
}
196208
}
197209
saddr += buffer_size;
@@ -229,18 +241,20 @@ int main()
229241
ets_wdt_enable();
230242

231243
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.
234248
// Verify the copy
235249
ets_putc('c'); ets_putc('m'); ets_putc('p'); ets_putc(':');
236250
if (res == 0) {
237251
ets_wdt_disable();
238252
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2], true);
239253
ets_wdt_enable();
240254
}
241-
ets_putc('0'+res); ets_putc('\n');
242-
**/
243255

256+
ets_putc('0'+res); ets_putc('\n');
257+
#endif
244258
if (res == 0) {
245259
cmd.action = ACTION_LOAD_APP;
246260
cmd.args[0] = cmd.args[1];

0 commit comments

Comments
 (0)