Skip to content

Commit b4464ad

Browse files
sigvartmhjfischer-no
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]> Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 03af90f) (cherry picked from commit 0d43674)
1 parent 6024d0a commit b4464ad

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
@@ -845,6 +845,11 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
845845
if (BOOT_CURR_IMG(state) == 1) {
846846
min_addr = PM_CPUNET_APP_ADDRESS;
847847
max_addr = PM_CPUNET_APP_ADDRESS + PM_CPUNET_APP_SIZE;
848+
#ifdef PM_S1_ADDRESS
849+
} else if (BOOT_CURR_IMG(state) == 0) {
850+
min_addr = PM_S0_ADDRESS;
851+
max_addr = pri_fa->fa_off + pri_fa->fa_size;
852+
#endif
848853
} else
849854
#endif
850855
{
@@ -965,18 +970,37 @@ boot_validated_swap_type(struct boot_loader_state *state,
965970
{
966971
const struct flash_area *primary_fa;
967972
rc = flash_area_open(flash_area_id_from_multi_image_slot(
968-
BOOT_CURR_IMG(state),
969-
BOOT_PRIMARY_SLOT),
970-
&primary_fa);
971-
973+
BOOT_CURR_IMG(state), BOOT_PRIMARY_SLOT),
974+
&primary_fa);
972975
if (rc != 0) {
973976
return BOOT_SWAP_TYPE_FAIL;
974977
}
975-
/* Get start and end of primary slot for current image */
976-
if (reset_addr < primary_fa->fa_off ||
977-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
978-
/* The image in the secondary slot is not intended for this image
979-
*/
978+
979+
/* Check start and end of primary slot for current image */
980+
if (reset_addr < primary_fa->fa_off) {
981+
#if defined(CONFIG_SOC_NRF5340_CPUAPP) && defined(CONFIG_NRF53_MULTI_IMAGE_UPDATE)
982+
const struct flash_area *nsib_fa;
983+
984+
/* NSIB upgrade slot */
985+
rc = flash_area_open((uint32_t)_image_1_primary_slot_id,
986+
&nsib_fa);
987+
988+
if (rc != 0) {
989+
return BOOT_SWAP_TYPE_FAIL;
990+
}
991+
992+
/* Image is placed before Primary and within the NSIB slot */
993+
if (reset_addr > nsib_fa->fa_off
994+
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
995+
/* Set primary to be NSIB upgrade slot */
996+
BOOT_IMG_AREA(state, 0) = nsib_fa;
997+
}
998+
#else
999+
return BOOT_SWAP_TYPE_NONE;
1000+
#endif
1001+
1002+
} else if (reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
1003+
/* The image in the secondary slot is not intended for any */
9801004
return BOOT_SWAP_TYPE_NONE;
9811005
}
9821006
}
@@ -1240,7 +1264,7 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
12401264
BOOT_LOG_INF("Image %d upgrade secondary slot -> primary slot", image_index);
12411265
BOOT_LOG_INF("Erasing the primary slot");
12421266

1243-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index),
1267+
rc = flash_area_open(flash_area_get_id(BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT)),
12441268
&fap_primary_slot);
12451269
assert (rc == 0);
12461270

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)