Skip to content

Commit ce11597

Browse files
committed
bootutil: fix upgrade issue in swap-move
A previous fix for allowing padded images in the primary slot, ended up causing an issue that would fail to upgrade under the right circumstances. The issue was caused when the following set of steps happened after an upgrade was detected: 1) trailer is erased on the primary slot 2) status is written to the primary slot 3) trailer is erased on the secondary slot 4) reset 1) trailer is erased on the primary slot 2) status partially written or not written to primary slot (no magic) 3) reset This would result in images stored in the same slots they were initially, aka no upgrade, which would fail the simulator test for upgraded images. The previous padded images fix was reverted and the status source was upgraded to also check that the secondary slot has a valid magic in it, so that there's never a circumstance where there is no trailer in any of the slots while an upgrade operation is being decided on. Signed-off-by: Fabio Utzig <[email protected]>
1 parent 7fd42d5 commit ce11597

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

boot/bootutil/src/swap_move.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ int
264264
swap_status_source(struct boot_loader_state *state)
265265
{
266266
struct boot_swap_state state_primary_slot;
267+
struct boot_swap_state state_secondary_slot;
267268
int rc;
268269
uint8_t source;
269270
uint8_t image_index;
@@ -280,8 +281,15 @@ swap_status_source(struct boot_loader_state *state)
280281

281282
BOOT_LOG_SWAP_STATE("Primary image", &state_primary_slot);
282283

284+
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SECONDARY(image_index),
285+
&state_secondary_slot);
286+
assert(rc == 0);
287+
288+
BOOT_LOG_SWAP_STATE("Secondary image", &state_secondary_slot);
289+
283290
if (state_primary_slot.magic == BOOT_MAGIC_GOOD &&
284-
state_primary_slot.copy_done == BOOT_FLAG_UNSET) {
291+
state_primary_slot.copy_done == BOOT_FLAG_UNSET &&
292+
state_secondary_slot.magic != BOOT_MAGIC_GOOD) {
285293

286294
source = BOOT_STATUS_SOURCE_PRIMARY_SLOT;
287295

0 commit comments

Comments
 (0)