-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
espflash save-image
does not update the App Image SHA256 in the correct location.
#715
Milestone
Comments
chris-subtlebytes
pushed a commit
to chris-subtlebytes/espflash
that referenced
this issue
Dec 29, 2024
The current implementation uses the last 32 bytes of the bootloader file. When Secure Boot V2 is enabled, the bootloader is padded. The new implementation walks through the segments to find the end and adds the 16-byte aligned 1-byte checksum to update the SHA256 instead of incorrectly updating the padding. Closes esp-rs#715
chris-subtlebytes
pushed a commit
to chris-subtlebytes/espflash
that referenced
this issue
Dec 30, 2024
The current implementation uses the last 32 bytes of the bootloader file. When Secure Boot V2 is enabled, the bootloader is padded. The new implementation walks through the segments to find the end and adds the 16-byte aligned 1-byte checksum to update the SHA256 instead of incorrectly updating the padding. Closes esp-rs#715
more details:
snippet from
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When generating a project with secure boot v2, the bootloader is padded: https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32c3/security/secure-boot-v2.html#secure-padding
Using a padded image with
espflash save-image --bootloader path-to-bootloader ...
will read the file into a buffer:flasher/mod.rs
:Then that bootloader buffer gets passed to
image_format.rs
IdfBootloaderFormat
. From there, the header is updated to match the args so the sha256 needs updating. However, the location of the sha256 is naively calculated as being the last 32 bytes of the bootloader file. However, it's actually the last 32 bytes of the bootloader without padding.image_format.rs
:One approach, which I'm not sure is the correct one due to all the different environments but worked in my specific case, was to walk through the bootloader segments while adding up the length. Then adding width the 16-byte aligned 1-byte checksum at the end. Maybe a better approach can be derived by referencing
esptool/bin_image.py
directly.https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32c3/api-reference/system/app_image_format.html#application-image-structures
Without this, secure-boot-enabled ESPs will not boot because the first-stage bootloader will detect the mismatch between the actual and old unchanged SHA256.
This appears to be related but not the same as #713
The text was updated successfully, but these errors were encountered: