Skip to content

wolfBoot_update_trigger: Fix double-write-after-erase in NVM...WRITEONCE#573

Merged
dgarske merged 3 commits intowolfSSL:masterfrom
danielinux:update-trigger-doublewrite-fix
Jun 30, 2025
Merged

wolfBoot_update_trigger: Fix double-write-after-erase in NVM...WRITEONCE#573
dgarske merged 3 commits intowolfSSL:masterfrom
danielinux:update-trigger-doublewrite-fix

Conversation

@danielinux
Copy link
Copy Markdown
Member

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

@danielinux danielinux self-assigned this May 21, 2025
(when NVM_FLASH_WRITEONCE workaround is active)
@danielinux danielinux force-pushed the update-trigger-doublewrite-fix branch from 94ecf06 to 81a63ee Compare June 30, 2025 11:00
@danielinux danielinux marked this pull request as ready for review June 30, 2025 11:43
@danielinux danielinux requested review from Copilot and dgarske June 30, 2025 11:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_trigger to 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_HOME to 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_WRITEONCE path to verify that flags and trailer are staged in cache and only one flash write occurs.
    /* Triggering update to set flags */

@danielinux danielinux removed their assignment Jun 30, 2025
@dgarske dgarske merged commit 80f9e99 into wolfSSL:master Jun 30, 2025
262 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants