Skip to content

Commit 1e05867

Browse files
committed
[nrf noup] boot/../loader: Fix MCUboot update with NRF53
Previously, when CONFIG_NRF53_MULTI_IMAGE_UPDATE was set and the MCUboot upgrade image was uploaded, but not verified or confirmed, booting the DK caused MCUboot to attempt to start the MCUboot upgrade image as the application image. This was only recoverable with: nrfjprog --family NRF53 --qspieraseall. Signed-off-by: Markus Lassila <[email protected]>
1 parent 61dc653 commit 1e05867

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

boot/bootutil/src/loader.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
12951295
bool upgrade_valid = false;
12961296
#if defined(PM_S1_ADDRESS)
12971297
owner_nsib[BOOT_CURR_IMG(state)] = false;
1298+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
1299+
const struct flash_area *revert_primary_fa = NULL;
1300+
#endif
12981301
#endif
12991302

13001303
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
@@ -1350,8 +1353,11 @@ boot_validated_swap_type(struct boot_loader_state *state,
13501353
/* Image is placed before Primary and within the NSIB slot */
13511354
if (reset_addr > nsib_fa->fa_off
13521355
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
1356+
/* Revert back to Primary if there is no swap */
1357+
revert_primary_fa = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
1358+
13531359
/* Set primary to be NSIB upgrade slot */
1354-
BOOT_IMG_AREA(state, 0) = nsib_fa;
1360+
BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT) = nsib_fa;
13551361
owner_nsib[BOOT_CURR_IMG(state)] = true;
13561362
}
13571363
#else
@@ -1423,6 +1429,15 @@ boot_validated_swap_type(struct boot_loader_state *state,
14231429
!CONFIG_NRF53_MULTI_IMAGE_UPDATE && CONFIG_PCD_APP */
14241430
}
14251431

1432+
#if defined(PM_S1_ADDRESS) && defined(CONFIG_SOC_NRF5340_CPUAPP) && \
1433+
defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
1434+
if (!upgrade_valid && revert_primary_fa) {
1435+
/* Revert back to Primary */
1436+
BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT) = revert_primary_fa;
1437+
owner_nsib[BOOT_CURR_IMG(state)] = false;
1438+
}
1439+
#endif
1440+
14261441
return swap_type;
14271442
}
14281443
#endif

0 commit comments

Comments
 (0)