Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boot: bootutil: loader: Fix issue with stuck revert #2199

Merged
merged 2 commits into from
Feb 12, 2025
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
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
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
Loading