Skip to content

Commit c527fd9

Browse files
committed
boot: bootutil: swap_scratch: Fix issue with bricking device
Fixes an issue with the swap using scratch algorithm that would cause the image loaded into the primary slot to be corrupt and unbootable if a device was rebooted during an erase of the scratch section that had not completed Signed-off-by: Jamie McCrae <[email protected]>
1 parent 31ac3c4 commit c527fd9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

boot/bootutil/src/swap_scratch.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,12 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
778778
BOOT_STATUS_ASSERT(rc == 0);
779779

780780
if (erase_scratch) {
781-
rc = boot_erase_region(fap_scratch, 0, flash_area_get_size(fap_scratch), false);
781+
/* Scratch trailers MUST be erased backwards, this is to avoid an issue whereby a
782+
* device reboots in the process of erasing the scratch if it erased forwards, if that
783+
* happens then the scratch which is partially erased would be wrote back to the
784+
* primary slot, causing a corrupt unbootable image
785+
*/
786+
rc = boot_erase_region(fap_scratch, 0, flash_area_get_size(fap_scratch), true);
782787
assert(rc == 0);
783788
}
784789
}

0 commit comments

Comments
 (0)