wolfBoot_update_trigger: Fix double-write-after-erase in NVM...WRITEONCE#573
Merged
dgarske merged 3 commits intowolfSSL:masterfrom Jun 30, 2025
Merged
Conversation
(when NVM_FLASH_WRITEONCE workaround is active)
94ecf06 to
81a63ee
Compare
after correcting update_trigger double write
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a double-write-after-erase issue for write-once NVM devices by staging the update flag and trailer in NVM_CACHE before performing a single flash write, and updates unit tests to reflect the new selected sector index.
- Updated unit tests to expect selection of sector 1 and verify erasure of bank 0.
- Refactored
wolfBoot_update_triggerto erase the full sector and write flags/trailer from cache for write-once NVM. - Removed redundant partition-state call and moved state updates into each branch.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tools/unit-tests/unit-nvm.c | Adjusted expected fresh sector from 0 to 1 and bank assertion. |
| tools/unit-tests/unit-enc-nvm.c | Updated expected fresh sector from 0 to 1 and bank assertion. |
| src/libwolfboot.c | Staged flags/trailer in cache for write-once NVM and updated erase size. |
Comments suppressed due to low confidence (3)
src/libwolfboot.c:763
- [nitpick] Add a comment explaining the offset calculation and the adjustment under
FLAGS_HOMEto clarify why flags and trailer are positioned at this offset.
uint32_t offset = SECTOR_FLAGS_SIZE;
tools/unit-tests/unit-nvm.c:269
- Introduce a dedicated unit test for the
NVM_FLASH_WRITEONCEpath to verify that flags and trailer are staged in cache and only one flash write occurs.
/* Triggering update to set flags */
dgarske
approved these changes
Jun 30, 2025
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.
when wolfBoot_update_trigger is called on a device with NVM_ write-once workaround, it will cause an illegal second write to flash to set the UPDATING flag.
Instead, write the flag and the trailer in NVM_CACHE before committing to the flash.
Reported in zd19815