Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion boot/bootutil/src/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
hdr = boot_img_hdr(state, slot);
if (boot_check_header_erased(state, slot) == 0 ||
(hdr->ih_flags & IMAGE_F_NON_BOOTABLE)) {

#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_MOVE) || defined(MCUBOOT_SWAP_USING_OFFSET)
/*
* This fixes an issue where an image might be erased, but a trailer
Expand All @@ -1048,6 +1047,27 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
*/
if (slot != BOOT_PRIMARY_SLOT) {
swap_erase_trailer_sectors(state, fap);

#if defined(MCUBOOT_SWAP_USING_MOVE)
if (bs->swap_type == BOOT_SWAP_TYPE_REVERT ||
boot_swap_type_multi(BOOT_CURR_IMG(state)) == BOOT_SWAP_TYPE_REVERT) {
const struct flash_area *fap_pri;

rc = flash_area_open(flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I guess that flash_area_id_from_multi_image_slot returning -1 never happens here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

would be a very interesting flash setup heh

BOOT_PRIMARY_SLOT),
&fap_pri);

if (rc == 0) {
rc = swap_erase_trailer_sectors(state, fap_pri);
flash_area_close(fap_pri);

if (rc == 0) {
BOOT_LOG_INF("Cleared image %d primary slot trailer due to stuck revert",
BOOT_CURR_IMG(state));
}
}
}
#endif
}
#endif

Expand Down
3 changes: 3 additions & 0 deletions docs/release-notes.d/fix-stuck-revert.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Fixed issue for swap using move whereby a device could get
stuck in a revert loop despite there being no image in the
secondary slot