bootutil: Fix device bricked after power failure during swap-move revert #2100
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.
This PR proposes a fix to #1966, which describes a scenario where a device can be bricked if a revert process is interrupted when using swap-move.
As suggested in this message, a very straightforward fix might be enough. The latter is implemented in this PR.
The idea is to perform a revert no matter the state of the magic number in the secondary slot's trailer, provided the
copy-done
flag is set in the primary slot but the
image-ok
flag is not. Thecopy-done
flag is set only after having completed an upgrade orrevert process so if the
copy-done
flag is set but theimage-ok
is unset, it is guaranteed an upgrade has been performed but the new image has not been confirmed, which implies a revert is needed.That looks good to me but perhaps I missed some corner cases that would justify that
BOOT_MAGIC_UNSET
was used instead ofBOOT_MAGIC_ANY
. @utzig @d3zd3z do you have any input on that point?Fixes #1966