Fix bootloader SHA256 to hash actual image size, not full allocated region#5331
Fix bootloader SHA256 to hash actual image size, not full allocated region#5331
Conversation
|
@copilot - my comment about then end might be wrong, looking again it appears the file i'm looking at might also have the partition table and other data, so please disregard my comment as to the memory end location and do your own research |
…2KB region - Add getActualBootloaderSize() helper to parse bootloader image structure - Calculate actual size by parsing segment headers, hash, and checksum - Only hash the actual bootloader data instead of full BOOTLOADER_SIZE - This prevents different hashes for same bootloader due to garbage data in unused memory Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
- Define MAX_SEGMENT_SIZE constant instead of magic number - Use bitwise alignment operation for better efficiency - Clarify that checksum byte is part of ESP-IDF image format Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com>
Understood. The implementation doesn't rely on the B9A0 endpoint - instead, it dynamically parses the bootloader image structure from flash to determine the actual size. The code:
This approach works for any bootloader image regardless of its specific size, and only hashes the actual bootloader data (not unused/garbage memory beyond it). |
|
@copilot Will this approach also work for S2, S3 and C3 which have slightly different bootloaders? |
Yes, the implementation works for all ESP32 variants (S2, S3, C3, C6, etc.) because:
The parsing logic is based on ESP-IDF's |
|
The image size computation should be shared with |
Bootloader SHA256 calculation was hashing the full 32KB allocated region (BOOTLOADER_SIZE) instead of the actual bootloader image size. This caused hash mismatches for identical bootloaders when devices had different garbage data in unused flash memory beyond the actual bootloader end (~47KB for ESP32 classic).
Changes
Added
getActualBootloaderSize(): Parses bootloader image structure from flashModified
calculateBootloaderSHA256(): Now uses actual bootloader size instead of full allocated regionThis ensures consistent SHA256 hashes for identical bootloaders regardless of unused memory content.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.