Skip to content

Commit ce42cac

Browse files
sigvartmhanangl
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 f15d384 commit ce42cac

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
@@ -1108,6 +1108,11 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
11081108
if (BOOT_CURR_IMG(state) == 1) {
11091109
min_addr = PM_CPUNET_APP_ADDRESS;
11101110
max_addr = PM_CPUNET_APP_ADDRESS + PM_CPUNET_APP_SIZE;
1111+
#ifdef PM_S1_ADDRESS
1112+
} else if (BOOT_CURR_IMG(state) == 0) {
1113+
min_addr = PM_S0_ADDRESS;
1114+
max_addr = pri_fa->fa_off + pri_fa->fa_size;
1115+
#endif
11111116
} else
11121117
#endif
11131118
{
@@ -1228,18 +1233,37 @@ boot_validated_swap_type(struct boot_loader_state *state,
12281233
{
12291234
const struct flash_area *primary_fa;
12301235
rc = flash_area_open(flash_area_id_from_multi_image_slot(
1231-
BOOT_CURR_IMG(state),
1232-
BOOT_PRIMARY_SLOT),
1233-
&primary_fa);
1234-
1236+
BOOT_CURR_IMG(state), BOOT_PRIMARY_SLOT),
1237+
&primary_fa);
12351238
if (rc != 0) {
12361239
return BOOT_SWAP_TYPE_FAIL;
12371240
}
1238-
/* Get start and end of primary slot for current image */
1239-
if (reset_addr < primary_fa->fa_off ||
1240-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
1241-
/* The image in the secondary slot is not intended for this image
1242-
*/
1241+
1242+
/* Check start and end of primary slot for current image */
1243+
if (reset_addr < primary_fa->fa_off) {
1244+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
1245+
const struct flash_area *nsib_fa;
1246+
1247+
/* NSIB upgrade slot */
1248+
rc = flash_area_open((uint32_t)_image_1_primary_slot_id,
1249+
&nsib_fa);
1250+
1251+
if (rc != 0) {
1252+
return BOOT_SWAP_TYPE_FAIL;
1253+
}
1254+
1255+
/* Image is placed before Primary and within the NSIB slot */
1256+
if (reset_addr > nsib_fa->fa_off
1257+
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
1258+
/* Set primary to be NSIB upgrade slot */
1259+
BOOT_IMG_AREA(state, 0) = nsib_fa;
1260+
}
1261+
#else
1262+
return BOOT_SWAP_TYPE_NONE;
1263+
#endif
1264+
1265+
} else if (reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
1266+
/* The image in the secondary slot is not intended for any */
12431267
return BOOT_SWAP_TYPE_NONE;
12441268
}
12451269
}
@@ -1503,7 +1527,7 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
15031527
BOOT_LOG_INF("Image %d upgrade secondary slot -> primary slot", image_index);
15041528
BOOT_LOG_INF("Erasing the primary slot");
15051529

1506-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index),
1530+
rc = flash_area_open(flash_area_get_id(BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT)),
15071531
&fap_primary_slot);
15081532
assert (rc == 0);
15091533

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)