Skip to content

Commit 16a29c2

Browse files
committed
[nrf noup] zephyr: Header skip support for secondary MCUboot update
Commit adds NCS_KEEP_MCUBOOT_HEADER_IN_SECONDARY_MCUBOOT Kconfig, default y, that controls whether MCUboot will keep MCUboot image header while moving update to s0/s1 slot. This allows to reduce siez of image in transfer, as smalles possible header can be used without alignment to VTOR, and allows more space for s0/s1 binary image. The option is by default set to y, so users do not have to change anything in existing configurations. Note that setting this option to n will create MCUboot image that can not be used to update secondary MCUboot instances built prior to the option existence and these with the option set to y. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
1 parent b852c43 commit 16a29c2

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

boot/bootutil/src/swap_nsib.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void nsib_swap_run(struct boot_loader_state *state, struct boot_status *bs)
3737
const struct flash_area *fap_pri;
3838
const struct flash_area *fap_sec;
3939
int rc;
40+
#ifndef CONFIG_NCS_KEEP_MCUBOOT_HEADER_IN_SECONDARY_MCUBOOT
41+
const struct image_header *hdr = boot_img_hdr(state, BOOT_SLOT_SECONDARY);
42+
#endif
4043

4144
BOOT_LOG_INF("Starting swap using nsib algorithm.");
4245

@@ -53,7 +56,11 @@ void nsib_swap_run(struct boot_loader_state *state, struct boot_status *bs)
5356
rc = boot_erase_region(fap_pri, 0, fap_pri->fa_size, false);
5457
assert(rc == 0);
5558

59+
#ifndef CONFIG_NCS_KEEP_MCUBOOT_HEADER_IN_SECONDARY_MCUBOOT
60+
rc = boot_copy_region(state, fap_sec, fap_pri, hdr->ih_hdr_size, 0, hdr->ih_img_size);
61+
#else
5662
rc = boot_copy_region(state, fap_sec, fap_pri, 0, 0, fap_pri->fa_size);
63+
#endif
5764
assert(rc == 0);
5865

5966
rc = swap_scramble_trailer_sectors(state, fap_sec);

boot/zephyr/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,20 @@ config NCS_MCUBOOT_MANUFACTURING_APP_KEY_IDENTIFIER
15641564
help
15651565
Manufacturing application key identifier.
15661566

1567+
1568+
config NCS_KEEP_MCUBOOT_HEADER_IN_SECONDARY_MCUBOOT
1569+
bool "Keep MCUboot header in second stage MCUboot bootloader image" if !PARTITION_MANAGER_ENABLED
1570+
default y
1571+
depends on MCUBOOT_MCUBOOT_IMAGE_NUMBER != -1
1572+
help
1573+
Default y to keep compatibility with PM built MCUboot images.
1574+
When selected, the MCUboot header, attached to MCUboot image for DFU,
1575+
will be also copied to s0/s1 slots with MCUboot, even though it is not used
1576+
after secondary stage MCUboot updates itself by copying the
1577+
update from update slot to target slot.
1578+
When unselected the MCUboot header will be stripped, so the entire s0/s1
1579+
slot can be used for executable binary part of MCUboot image.
1580+
15671581
configdefault PSA_CRYPTO
15681582
default y if SOC_NRF54H20 && BOOT_SIGNATURE_TYPE_ED25519
15691583

0 commit comments

Comments
 (0)