Skip to content

Commit 33094fc

Browse files
committed
boot: bootutil: loader: Fix issue with stuck revert
Fixes an issue (only for swap using move, unsure if it affects other modes) whereby a device can get into a state that there is a valid primary image, no secondary image but the primary image flag is still set to revert, which then makes loading a firmware update from the application impossible due to it assuming that a revert will happen upon device reboot Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent 25e2761 commit 33094fc

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

boot/bootutil/src/loader.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,6 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
10341034
hdr = boot_img_hdr(state, slot);
10351035
if (boot_check_header_erased(state, slot) == 0 ||
10361036
(hdr->ih_flags & IMAGE_F_NON_BOOTABLE)) {
1037-
10381037
#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_MOVE) || defined(MCUBOOT_SWAP_USING_OFFSET)
10391038
/*
10401039
* This fixes an issue where an image might be erased, but a trailer
@@ -1048,6 +1047,27 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
10481047
*/
10491048
if (slot != BOOT_PRIMARY_SLOT) {
10501049
swap_erase_trailer_sectors(state, fap);
1050+
1051+
#if defined(MCUBOOT_SWAP_USING_MOVE)
1052+
if (bs->swap_type == BOOT_SWAP_TYPE_REVERT ||
1053+
boot_swap_type_multi(BOOT_CURR_IMG(state)) == BOOT_SWAP_TYPE_REVERT) {
1054+
const struct flash_area *fap_pri;
1055+
1056+
rc = flash_area_open(flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state),
1057+
BOOT_PRIMARY_SLOT),
1058+
&fap_pri);
1059+
1060+
if (rc == 0) {
1061+
rc = swap_erase_trailer_sectors(state, fap_pri);
1062+
flash_area_close(fap_pri);
1063+
1064+
if (rc == 0) {
1065+
BOOT_LOG_INF("Cleared image %d primary slot trailer due to stuck revert",
1066+
BOOT_CURR_IMG(state));
1067+
}
1068+
}
1069+
}
1070+
#endif
10511071
}
10521072
#endif
10531073

0 commit comments

Comments
 (0)