-
Notifications
You must be signed in to change notification settings - Fork 128
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
Calculate end of bootloader to update SHA256 #716
base: main
Are you sure you want to change the base?
Conversation
88a72ae
to
e767ecd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Briefly looking at your changes and argumentation, they look good to me! Ill wait until the PR is ready for review and Ill do a more thorough review and some testing.
Thanks for contributting to espflash!
e767ecd
to
db05d51
Compare
I left some print statements in there mostly to illustrate the issue. Do you want those removed? Are there any plans to add logging crates? I briefly looked into creating some tests. Are there any existing test |
db05d51
to
0ba42b5
Compare
Not sure what you mean, |
0ba42b5
to
eab6916
Compare
eab6916
to
83159a9
Compare
log line added:
|
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
83159a9
to
7a83fc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! Did some testing and review and everything seems to be working, left some minor comments!
let hash = hasher.finalize(); | ||
bootloader.to_mut()[bootloader_len - 32..].copy_from_slice(&hash); | ||
log::info!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more a debug log to me
log::info!( | |
debug!( |
@@ -4,6 +4,7 @@ use std::{borrow::Cow, io::Write, iter::once, mem::size_of}; | |||
|
|||
use bytemuck::{bytes_of, from_bytes, Pod, Zeroable}; | |||
use esp_idf_part::{Partition, PartitionTable, Type}; | |||
use log; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use log; | |
use log::debug; |
To be consisten with other places of the code.
// the hash is at the end of the bootloader, but the bootloader bytes are padded. | ||
// the real end of the bootloader is the end of the segments plus the 16-byte aligned 1-byte checksum. | ||
// the checksum is stored in the last byte so that the file is a multiple of 16 bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any documentation/esptool source code links that we could add here?
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 #715