boot: bootutil: Fix last sector index computation for swap-offset #2214
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.
I'm currently trying to modify the simulator to test upgrades with the largest possible images for all possible upgrade strategies (currently this is not made for some strategies such as swap-offset). While playing with the simulator I noticed the swap-offset upgrade was failing if an image is large enough to use all the available sectors.
Let's consider this very simple scenario, with slots containing a single sector for the firmware image:
Here, the swap-offset needs to swap a single sector and the index of the last sector of the primary slot to be swapped is
0
.However, the
find_last_idx
is in fact returning1
. And in the general case, it is returning the number of sectors to swap rather than the index of the last sector to swap.In
swap_run
, this is causing the swap to be aborted because of a supposedly too large image if the image uses all the available sectors: