Skip to content

Commit f96de6c

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 1618783 commit f96de6c

2 files changed

Lines changed: 19 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+
#ifdef CONFIG_NCS_MCUBOOT_DISCARDS_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+
#ifdef CONFIG_NCS_MCUBOOT_DISCARDS_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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,18 @@ config NCS_MCUBOOT_MANUFACTURING_APP_KEY_IDENTIFIER
15641564
help
15651565
Manufacturing application key identifier.
15661566

1567+
1568+
config NCS_MCUBOOT_DISCARDS_HEADER_IN_SECONDARY_MCUBOOT
1569+
bool "Discard MCUboot header in second stage MCUboot bootloader image" if !PARTITION_MANAGER_ENABLED
1570+
depends on MCUBOOT_MCUBOOT_IMAGE_NUMBER != -1
1571+
help
1572+
Default n to keep compatibility with PM built MCUboot images.
1573+
When selected, the MCUboot header, attached to MCUboot image for DFU,
1574+
will be discarded while MCUboot will be copied to s0/s1 slots, leaving
1575+
more space within slot for the MCUboot image.
1576+
When unselected the MCUboot header will be kept and copied with
1577+
MCUboot image to the s0/s1 slot.
1578+
15671579
configdefault PSA_CRYPTO
15681580
default y if SOC_NRF54H20 && BOOT_SIGNATURE_TYPE_ED25519
15691581

0 commit comments

Comments
 (0)