Skip to content

Commit 396120f

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 0a58adb commit 396120f

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
@@ -1426,6 +1426,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
14261426
bool upgrade_valid = false;
14271427
#if defined(PM_S1_ADDRESS)
14281428
owner_nsib[BOOT_CURR_IMG(state)] = false;
1429+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
1430+
const struct flash_area *revert_primary_fa = NULL;
1431+
#endif
14291432
#endif
14301433

14311434
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
@@ -1481,8 +1484,11 @@ boot_validated_swap_type(struct boot_loader_state *state,
14811484
/* Image is placed before Primary and within the NSIB slot */
14821485
if (reset_addr > nsib_fa->fa_off
14831486
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
1487+
/* Revert back to Primary if there is no swap */
1488+
revert_primary_fa = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
1489+
14841490
/* Set primary to be NSIB upgrade slot */
1485-
BOOT_IMG_AREA(state, 0) = nsib_fa;
1491+
BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT) = nsib_fa;
14861492
owner_nsib[BOOT_CURR_IMG(state)] = true;
14871493
}
14881494
#else
@@ -1555,6 +1561,15 @@ boot_validated_swap_type(struct boot_loader_state *state,
15551561
!CONFIG_NRF53_MULTI_IMAGE_UPDATE && CONFIG_PCD_APP */
15561562
}
15571563

1564+
#if defined(PM_S1_ADDRESS) && defined(CONFIG_SOC_NRF5340_CPUAPP) && \
1565+
defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
1566+
if (!upgrade_valid && revert_primary_fa) {
1567+
/* Revert back to Primary */
1568+
BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT) = revert_primary_fa;
1569+
owner_nsib[BOOT_CURR_IMG(state)] = false;
1570+
}
1571+
#endif
1572+
15581573
return swap_type;
15591574
}
15601575
#endif

0 commit comments

Comments
 (0)