Repository navigation
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #929
Scan targets checked: wolfboot-src, wolfboot-bugs
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: tools/unit-tests/unit-update-flash.c
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Encrypted updates remain unrecoverable, and partial external-flash reads are not rejected.
1 open finding
What changed in this PR
Adds recovery for power loss while backing up UPDATE sector 0.
Changes:
- Recovers image size from the SWAP header.
- Adds forward-update, rollback, and invalid-header tests.
| File | Description |
|---|---|
src/update_flash.c |
Adds interrupted-swap recovery logic. |
tools/unit-tests/unit-update-flash.c |
Tests sector-0 recovery scenarios. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…d the BOOT->UPDATE copy step caused unrecoverable failure
bigbrett
force-pushed
the
rollback-powerfail-fix
branch
from
October 8, 2026 16:59
1e76dbf to
481ad8b
Compare
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.

Fixes a power-fail edge case that could result in an unrecoverable boot failure.
Problem
A power loss during the backup of the initial sector (sector 0, which contains the image header) that occurs after UPDATE's sector 0 is erased but before it is rewritten would leave UPDATE without a valid image header.
wolfBoot_update()then can't open the UPDATE image and can't resume the swap.If this were a forward update, it would be dropped, which is not as big of a deal, however if it were a rollback, then it would leave the device booting the image that failed to confirm.
The existing code comments acknowledged this failure case, but had no solution for it. I'm pretty sure this PR and tests demonstrate an effective fix.
Fix
If UPDATE can't be opened and the sector 0 flag is
SECT_FLAG_SWAPPING,wolfBoot_update()now takes the image size from the copy of UPDATE's sector 0 in SWAP. It only uses the copy if the magic and size fields are valid. The size is only needed to get the swap through sector 0. After that, the existing code re-reads both headers and recomputes the total size.With
EXT_ENCRYPTED, the header is decrypted with the IV for UPDATE offset 0. The SWAP copy is only tried after the existing fallback-IV open of UPDATE also fails.DELTA_UPDATESbuilds keep the old behavior.