mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-07 06:01:35 +03:00
eboot: .RODATA, upstream uzlib, move CRC, save 112 bytes (#7844)
RODATA can be copied automatically by the bootrom, so no reason not to allow its use for strings and constants in eboot.c Revert to pfalcon's original uzlib since the single patch to remove RODATA is not required. Rationalize eboot.ld linker script, clean up BSS and init it in code. Saves 112 bytes of space in the bootloader sector by removing the extra code associated with literal loads. * Move CRC out of bootload sector We added protection to only erase the bootload sector when flashing an image when the new sector != the old sector. This was intended to minimize the chance of bricking (i.e. if there was a powerfail during flashing of the boot sector the chip would be dead). Unfortunately, by placing the CRC inside the eboot sector *every* application will have a unique eboot sector (due to the crc/len), so this protection doesn't work. Move the CRC into the first 8 bytes of IROM itself. This frees up extra space in the boot sector and ensures that eboot won't be reflashed unless there really is an eboot change.
This commit is contained in:
committed by
GitHub
parent
6c564c269c
commit
07b4c09b90
@ -444,22 +444,24 @@ bool EspClass::checkFlashConfig(bool needsEquals) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// These are defined in the linker script, and filled in by the elf2bin.py util
|
||||
extern "C" uint32_t __crc_len;
|
||||
extern "C" uint32_t __crc_val;
|
||||
|
||||
bool EspClass::checkFlashCRC() {
|
||||
// The CRC and total length are placed in extra space at the end of the 4K chunk
|
||||
// of flash occupied by the bootloader. If the bootloader grows to >4K-8 bytes,
|
||||
// we'll need to adjust this.
|
||||
uint32_t flashsize = *((uint32_t*)(0x40200000 + 4088)); // Start of PROGMEM plus 4K-8
|
||||
uint32_t flashcrc = *((uint32_t*)(0x40200000 + 4092)); // Start of PROGMEM plus 4K-4
|
||||
// Dummy CRC fill
|
||||
uint32_t z[2];
|
||||
z[0] = z[1] = 0;
|
||||
|
||||
uint32_t firstPart = (uintptr_t)&__crc_len - 0x40200000; // How many bytes to check before the 1st CRC val
|
||||
|
||||
// Start the checksum
|
||||
uint32_t crc = crc32((const void*)0x40200000, 4096-8, 0xffffffff);
|
||||
uint32_t crc = crc32((const void*)0x40200000, firstPart, 0xffffffff);
|
||||
// Pretend the 2 words of crc/len are zero to be idempotent
|
||||
crc = crc32(z, 8, crc);
|
||||
// Finish the CRC calculation over the rest of flash
|
||||
crc = crc32((const void*)0x40201000, flashsize-4096, crc);
|
||||
return crc == flashcrc;
|
||||
crc = crc32((const void*)(0x40200000 + firstPart + 8), __crc_len - (firstPart + 8), crc);
|
||||
return crc == __crc_val;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user