Skip to content

Commit 2ac7976

Browse files
taltenbachnordicjm
authored andcommitted
bootutil: Fix the reading of image headers after partial swap completion
After a partial swap has been resumed and completed, the image headers are reloaded. The idea is that we want to update the bootloader state (boot_data) to properly reflect the new state of the slots: the image headers in the primary and secondary slots are now respectively the headers of the new and previous active image. However, the implementation was doing the exact opposite when swap-scratch was used, which could lead to erroneous behaviors such as a failure when validating the primary slot. Signed-off-by: Thomas Altenbach <[email protected]>
1 parent 84416fd commit 2ac7976

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

boot/bootutil/src/loader.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,10 +1963,21 @@ boot_prepare_image_for_update(struct boot_loader_state *state,
19631963
rc = boot_complete_partial_swap(state, bs);
19641964
assert(rc == 0);
19651965
#endif
1966-
/* Attempt to read an image header from each slot. Ensure that
1967-
* image headers in slots are aligned with headers in boot_data.
1966+
/* Attempt to read an image header from each slot. Ensure that image headers in slots
1967+
* are aligned with headers in boot_data.
1968+
*
1969+
* The boot status (last param) is used to figure out in which slot the header of each
1970+
* image is currently located. This is useful as in the middle of an upgrade process,
1971+
* the header of a given image could have already been moved to the other slot. However,
1972+
* providing it at the end of the upgrade, as it is the case here, would cause the
1973+
* reading of the header of the primary image from the secondary slot and the secondary
1974+
* image from the primary slot, since the images have been swapped. That's not what we
1975+
* want here, since the goal is to upgrade the bootloader state to reflect the new state
1976+
* of the slots: the image headers in the primary and secondary slots must now
1977+
* respectively be the headers of the new and previous active image. So NULL is provided
1978+
* as boot status.
19681979
*/
1969-
rc = boot_read_image_headers(state, false, bs);
1980+
rc = boot_read_image_headers(state, false, NULL);
19701981
assert(rc == 0);
19711982

19721983
/* Swap has finished set to NONE */

0 commit comments

Comments
 (0)