boot: swap by fingerprint status#2688
Draft
DOAR-Infineon wants to merge 1 commit into
Draft
Conversation
Based on mcu-tools#2122 implementation idea Signed-off-by: INFINEON\DovhalA <artem.dovhal@infineon.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #2122 implementation idea
Swap Fingerprint: SHA256-Based Swap Progress Tracking
Overview
The swap fingerprint feature (
MCUBOOT_SWAP_FINGERPRINT) replaces per-stepstatus byte writes during image swap with pre-computed SHA256 fingerprint tables
and post-copy verification.
Instead of writing a progress byte to flash after each state transition (3 writes
per sector in SCRATCH mode), the bootloader:
FLASH_AREA_IMAGE_FINGERPRINT)Motivation
The current swap implementations write status bytes to flash after each state
transition. This works but:
The fingerprint approach eliminates runtime status writes, adds content-level
verification of each copy operation, and provides tamper detection.
How It Works
Fingerprint Tables
Two SHA256 hash tables are pre-computed and stored in the dedicated fingerprint
partition:
should contain after the swap completes
should contain after the swap completes
Content-only hashing (no address or device binding) allows the same hash to
verify data regardless of its current location — primary, secondary, or scratch.
Dedicated Flash Partition
Fingerprint tables are stored in
FLASH_AREA_IMAGE_FINGERPRINT(flash areaID 6), a dedicated partition separate from both image slots. This partition is
never erased during the swap, eliminating the power failure vulnerability that
would occur if tables were stored in the primary trailer.
Partition layout:
Partition size:
BOOT_FINGERPRINT_MAX_ENTRIES * 64 + 32 + BOOT_MAX_ALIGN + 16bytes. For
MAX_ENTRIES=128: 8248 bytes (round up to flash erase boundaries).Verified Copies
After each copy operation during the swap,
boot_write_status()hashes thedestination and compares against the fingerprint table. A mismatch is a fatal
error — the swap is aborted. This replaces the status byte write with an
integrity verification.
For SCRATCH swap, verification per state:
Power Failure Recovery
On recovery,
swap_read_status_bytes()scans sectors in swap order (last sectorfirst, matching
swap_run()iteration) and compares live hashes against storedfingerprints. For the interrupted sector, it also hashes scratch to determine the
exact resume state.
Two integrity layers protect against init-time power failure:
Its presence guarantees all prior writes completed.
Recovery state machine (6 cases):