Skip to content

Commit 037f4da

Browse files
sigvartmhde-nordic
authored andcommitted
[nrf noup] booutil: loader: 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 Signed-off-by: Sigvart Hovland <[email protected]> (cherry picked from commit 8fe7070) Signed-off-by: Dominik Ermel <[email protected]>
1 parent 3af997b commit 037f4da

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

boot/bootutil/src/loader.c

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,11 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
844844
if (BOOT_CURR_IMG(state) == 1) {
845845
min_addr = PM_CPUNET_APP_ADDRESS;
846846
max_addr = PM_CPUNET_APP_ADDRESS + PM_CPUNET_APP_SIZE;
847+
#ifdef PM_S1_ADDRESS
848+
} else if (BOOT_CURR_IMG(state) == 0) {
849+
min_addr = PM_S0_ADDRESS;
850+
max_addr = pri_fa->fa_off + pri_fa->fa_size;
851+
#endif
847852
} else
848853
#endif
849854
{
@@ -962,20 +967,33 @@ boot_validated_swap_type(struct boot_loader_state *state,
962967
if(reset_addr < PM_CPUNET_B0N_ADDRESS)
963968
#endif
964969
{
970+
const struct flash_area *nsib_fa;
965971
const struct flash_area *primary_fa;
966972
rc = flash_area_open(flash_area_id_from_multi_image_slot(
967-
BOOT_CURR_IMG(state),
968-
BOOT_PRIMARY_SLOT),
969-
&primary_fa);
970-
973+
BOOT_CURR_IMG(state), BOOT_PRIMARY_SLOT),
974+
&primary_fa);
971975
if (rc != 0) {
972976
return BOOT_SWAP_TYPE_FAIL;
973977
}
974-
/* Get start and end of primary slot for current image */
975-
if (reset_addr < primary_fa->fa_off ||
976-
reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
977-
/* The image in the secondary slot is not intended for this image
978-
*/
978+
979+
/* Check start and end of primary slot for current image */
980+
if (reset_addr < primary_fa->fa_off) {
981+
/* NSIB upgrade slot */
982+
rc = flash_area_open((uint32_t)_image_1_primary_slot_id,
983+
&nsib_fa);
984+
985+
if (rc != 0) {
986+
return BOOT_SWAP_TYPE_FAIL;
987+
}
988+
989+
/* Image is placed before Primary and within the NSIB slot */
990+
if (reset_addr > nsib_fa->fa_off
991+
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
992+
/* Set primary to be NSIB upgrade slot */
993+
BOOT_IMG_AREA(state, 0) = nsib_fa;
994+
}
995+
} else if (reset_addr > (primary_fa->fa_off + primary_fa->fa_size)) {
996+
/* The image in the secondary slot is not intended for any */
979997
return BOOT_SWAP_TYPE_NONE;
980998
}
981999
}
@@ -1239,7 +1257,7 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
12391257
BOOT_LOG_INF("Image %d upgrade secondary slot -> primary slot", image_index);
12401258
BOOT_LOG_INF("Erasing the primary slot");
12411259

1242-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index),
1260+
rc = flash_area_open(flash_area_get_id(BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT)),
12431261
&fap_primary_slot);
12441262
assert (rc == 0);
12451263

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)