Skip to content

Commit 4b9be0b

Browse files
sigvartmhbjarki-andreasen
authored andcommitted
[nrf noup] boot: Add support for NSIB and multi-image
This adds support for using both NSIB and the multi-image configuration in MCUboot. Before this was not possible due to upgradable bootloader support through NSIB was using the `UPDATEABLE_IMAGE_NUMBER` configuration to update the updateable bootloader. In this commit we change from using `FLASH_AREA_IMAGE_PRIMARY` to get the flash area ID to using the bootloader state where we set the flash area ID of the free updatable bootloader slot if the image is intended for this slot. Ref. NCSDK-19223 Ref. NCSDK-23305 Signed-off-by: Sigvart Hovland <[email protected]> (cherry picked from commit 3ec5084)
1 parent ed8c353 commit 4b9be0b

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

boot/bootutil/src/loader.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,11 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
11601160
if (BOOT_CURR_IMG(state) == 1) {
11611161
min_addr = PM_CPUNET_APP_ADDRESS;
11621162
max_addr = PM_CPUNET_APP_ADDRESS + PM_CPUNET_APP_SIZE;
1163+
#ifdef PM_S1_ADDRESS
1164+
} else if (BOOT_CURR_IMG(state) == 0) {
1165+
min_addr = PM_S0_ADDRESS;
1166+
max_addr = pri_fa->fa_off + pri_fa->fa_size;
1167+
#endif
11631168
} else
11641169
#endif
11651170
{
@@ -1280,18 +1285,37 @@ boot_validated_swap_type(struct boot_loader_state *state,
12801285
{
12811286
const struct flash_area *primary_fa;
12821287
rc = flash_area_open(flash_area_id_from_multi_image_slot(
1283-
BOOT_CURR_IMG(state),
1284-
BOOT_PRIMARY_SLOT),
1285-
&primary_fa);
1286-
1288+
BOOT_CURR_IMG(state), BOOT_PRIMARY_SLOT),
1289+
&primary_fa);
12871290
if (rc != 0) {
12881291
return BOOT_SWAP_TYPE_FAIL;
12891292
}
1290-
/* Get start and end of primary slot for current image */
1291-
if (reset_addr < primary_fa->fa_off ||
1292-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
1293-
/* The image in the secondary slot is not intended for this image
1294-
*/
1293+
1294+
/* Check start and end of primary slot for current image */
1295+
if (reset_addr < primary_fa->fa_off) {
1296+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
1297+
const struct flash_area *nsib_fa;
1298+
1299+
/* NSIB upgrade slot */
1300+
rc = flash_area_open((uint32_t)_image_1_primary_slot_id,
1301+
&nsib_fa);
1302+
1303+
if (rc != 0) {
1304+
return BOOT_SWAP_TYPE_FAIL;
1305+
}
1306+
1307+
/* Image is placed before Primary and within the NSIB slot */
1308+
if (reset_addr > nsib_fa->fa_off
1309+
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
1310+
/* Set primary to be NSIB upgrade slot */
1311+
BOOT_IMG_AREA(state, 0) = nsib_fa;
1312+
}
1313+
#else
1314+
return BOOT_SWAP_TYPE_NONE;
1315+
#endif
1316+
1317+
} else if (reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
1318+
/* The image in the secondary slot is not intended for any */
12951319
return BOOT_SWAP_TYPE_NONE;
12961320
}
12971321
}
@@ -1567,7 +1591,7 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
15671591
BOOT_LOG_INF("Image %d upgrade secondary slot -> primary slot", image_index);
15681592
BOOT_LOG_INF("Erasing the primary slot");
15691593

1570-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index),
1594+
rc = flash_area_open(flash_area_get_id(BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT)),
15711595
&fap_primary_slot);
15721596
assert (rc == 0);
15731597

boot/zephyr/include/sysflash/sysflash.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,24 @@
2323
/* If B0 is present then two bootloaders are present, and we must use
2424
* a single secondary slot for both primary slots.
2525
*/
26-
#ifdef PM_B0_ADDRESS
27-
26+
#if defined(PM_B0_ADDRESS)
2827
extern uint32_t _image_1_primary_slot_id[];
28+
#endif
29+
#if defined(PM_B0_ADDRESS) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
30+
#define FLASH_AREA_IMAGE_PRIMARY(x) \
31+
((x == 0) ? \
32+
PM_MCUBOOT_PRIMARY_ID : \
33+
(x == 1) ? \
34+
PM_MCUBOOT_PRIMARY_1_ID : \
35+
255 )
36+
37+
#define FLASH_AREA_IMAGE_SECONDARY(x) \
38+
((x == 0) ? \
39+
PM_MCUBOOT_SECONDARY_ID: \
40+
(x == 1) ? \
41+
PM_MCUBOOT_SECONDARY_1_ID: \
42+
255 )
43+
#elif defined(PM_B0_ADDRESS)
2944

3045
#define FLASH_AREA_IMAGE_PRIMARY(x) \
3146
((x == 0) ? \

0 commit comments

Comments
 (0)