mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-03 07:02:28 +03:00
Don't overwrite boot sector unless OTA changes it
There is a window where the eboot sector is erased and unwritten/partially written. If there's a power cycle at this time, the chip will brick due to eboot being corrupted. Avoid this by checking if the new eboot 4K sector is identical to the one already in flash, and if so don't rewrite it.
This commit is contained in:
parent
1ff927d04c
commit
cf1b8e067a
@ -159,11 +159,6 @@ int copy_raw(const uint32_t src_addr,
|
||||
gzip = true;
|
||||
}
|
||||
while (left > 0) {
|
||||
if (!verify) {
|
||||
if (SPIEraseSector(daddr/buffer_size)) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
if (!gzip) {
|
||||
if (SPIRead(saddr, buffer, buffer_size)) {
|
||||
return 3;
|
||||
@ -190,8 +185,25 @@ int copy_raw(const uint32_t src_addr,
|
||||
return 9;
|
||||
}
|
||||
} else {
|
||||
if (SPIWrite(daddr, buffer, buffer_size)) {
|
||||
return 4;
|
||||
// Special treatment for address 0 (bootloader). Only erase and
|
||||
// rewrite if the data is different (i.e. very rarely).
|
||||
bool skip = false;
|
||||
if (daddr == 0) {
|
||||
if (SPIRead(daddr, buffer2, buffer_size)) {
|
||||
return 4;
|
||||
}
|
||||
if (!memcmp(buffer2, buffer, buffer_size)) {
|
||||
ets_putc('B'); // Note we skipped the bootloader in output
|
||||
skip = true; // And skip erase/write
|
||||
}
|
||||
}
|
||||
if (!skip) {
|
||||
if (SPIEraseSector(daddr/buffer_size)) {
|
||||
return 2;
|
||||
}
|
||||
if (SPIWrite(daddr, buffer, buffer_size)) {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
saddr += buffer_size;
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user