Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add powerfail during final sector erase #354

Merged
merged 9 commits into from
Oct 13, 2023

Conversation

jpbland1
Copy link
Contributor

@jpbland1 jpbland1 commented Aug 23, 2023

Add powerfail during final sector erase, exposing the problems of losing the encryption key when the power fails before the key can be written back, failing to select the correct NVM_FLASH_WRITEONCE sector when a sector is corrupt, and losing the testing state when the power fails before the partition state can be set. these issues are addressed in the next commit
ZD 15415

@jpbland1 jpbland1 marked this pull request as ready for review August 23, 2023 01:55
@jpbland1 jpbland1 force-pushed the wolfboot-finalize branch 2 times, most recently from eeec343 to 9aed410 Compare August 23, 2023 03:25
danielinux
danielinux previously approved these changes Sep 7, 2023
Copy link
Member

@danielinux danielinux left a comment

Choose a reason for hiding this comment

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

LGTM. Off to @rizlik for double checking the logic.

@danielinux danielinux removed their assignment Sep 12, 2023
@rizlik rizlik assigned jpbland1 and unassigned rizlik Sep 25, 2023
@rizlik
Copy link
Contributor

rizlik commented Sep 25, 2023

investigate a way to avoid erasing the key until wolfBoot_success

the problems of losing the encryption key when the power fails before the key can be written back, failing to select the correct NVM_FLASH_WRITEONCE sector when a sector is corrupt, and losing the testing state when the power fails before the partition state can be set. these issues are addressed in the next commit
repeatable steps so that power failure wont erase the encryption key and wont cause skipping the testing phase of boot. this is done by marking the update partition as final swap when erasing the final sector and backing up the key in boot sector 0 after swaping the real boot sector 0 to swap. then when a power failure occurs the encryption key will be available in either boot sector 0 or the normal location. the intermediate phase also prevents skipping the testing phase since the last sector, which holds the boot state, is erased and then set repeatably, since the final swap state is set on the update partition
leave the encryption key for wolfBoot_success to erase.
FINAL_SWAP was also stopping the case where the partition was put into testing before the update sector status flags could be erased. now, don't erase the update sector flags. instead put the update partition in IMG_STATE_FINAL_FLAGS state before putting the boot partition in IMG_STATE_TESTING. Then only erase the update sector flags on wolfBoot_update_trigger. under this scheme, the sector flags are intact if the power failed before we could set IMG_STATE_TESTING but are wiped if we do need to swap over after after wolfBoot_success fails to be called
NVM_FLASH_WRITEONCE can powerfail after FLAGS_FINAL and TESTING partition states have been set
@danielinux danielinux changed the title add powerfail during final sector erase, exposing Add powerfail during final sector erase Oct 13, 2023
@danielinux danielinux merged commit f4ea778 into wolfSSL:master Oct 13, 2023
69 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