Skip to content

Commit

Permalink
Merge pull request #7547 from earlephilhower/noboom
Browse files Browse the repository at this point in the history
Don't overwrite boot sector unless OTA changes it
  • Loading branch information
devyte authored Sep 2, 2020
2 parents 8b7126d + f1c8982 commit d02bc02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions bootloaders/eboot/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Binary file modified bootloaders/eboot/eboot.elf
Binary file not shown.

0 comments on commit d02bc02

Please sign in to comment.