Skip to content

Commit 7ab4d24

Browse files
authored
Re-calculate the bootloader's SHA256 (#567)
* Re-calculate the bootloader's SHA256 * CHANGELOG.md entry
1 parent 31817fa commit 7ab4d24

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- Fixed `defmt` parsing when data is read in parts (#503)
3030
- Use partition table instead of hard-coded values for the location of partitions (#516)
3131
- Fixed a missed `flush` call that may be causing communication errors (#521)
32+
- Fix "SHA-256 comparison failed: [...] attempting to boot anyway..." (#567)
3233

3334
### Changed
3435
- Created `FlashData`, `FlashDataBuilder` and `FlashSettings` structs to reduce number of input arguments in some functions (#512, #566)

espflash/src/image_format/idf_bootloader.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ impl<'a> IdfBootloaderFormat<'a> {
7373
bytes_of(&header).iter().copied(),
7474
);
7575

76+
// re-calculate hash of the bootloader - needed since we modified the header
77+
let bootloader_len = bootloader.len();
78+
let mut hasher = Sha256::new();
79+
hasher.update(&bootloader[..bootloader_len - 32]);
80+
let hash = hasher.finalize();
81+
bootloader.to_mut()[bootloader_len - 32..].copy_from_slice(&hash);
82+
7683
// write the header of the app
7784
// use the same settings as the bootloader
7885
// just update the entry point

0 commit comments

Comments
 (0)