Skip to content

Commit 4beedbb

Browse files
committed
sysbuild: Remove offsets from merged slots
Adjust logic, so the merged slots do not include gaps between images. Ref: NCSDK-25612 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 544b25a commit 4beedbb

File tree

6 files changed

+78
-12
lines changed

6 files changed

+78
-12
lines changed

cmake/sysbuild/sign_nrf54h20.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,14 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
247247
SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP)
248248
if(CONFIG_NCS_IS_VARIANT_IMAGE)
249249
set(slot_size ${slot1_size})
250+
set(slot_addr ${slot1_addr})
250251
else()
251252
set(slot_size ${slot0_size})
253+
set(slot_addr ${slot0_addr})
252254
endif()
253-
set(imgtool_rom_command --rom-fixed ${code_addr})
255+
# Adjust start offset, based on the active slot and code partition address.
256+
math(EXPR start_offset "${start_offset} + ${code_addr} - ${slot_addr}")
257+
set(imgtool_rom_command --rom-fixed ${slot_addr})
254258
else()
255259
message(FATAL_ERROR "Only Direct XIP MCUboot modes are supported.")
256260
return()
@@ -259,7 +263,8 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
259263
# Basic 'imgtool sign' command with known image information.
260264
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign
261265
--version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --header-size
262-
${start_offset} --slot-size ${slot_size} ${imgtool_rom_command})
266+
${start_offset} --slot-size ${slot_size} --pad-header
267+
${imgtool_rom_command})
263268
set(imgtool_args --align ${write_block_size} ${imgtool_args})
264269

265270
# Extensionless prefix of any output file.
@@ -325,8 +330,8 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
325330
"${output}.signed.confirmed.hex" CACHE FILEPATH
326331
"Signed and confirmed kernel hex file" FORCE)
327332
list(APPEND imgtool_cmd COMMAND
328-
${imgtool_sign} ${imgtool_args} --pad --confirm ${merged_hex}
329-
${output}.signed.confirmed.hex)
333+
${imgtool_sign} ${imgtool_args} --pad --pad-header --confirm
334+
${merged_hex} ${output}.signed.confirmed.hex)
330335
endif()
331336

332337
if(NOT "${keyfile_enc}" STREQUAL "")

samples/zephyr/subsys/mgmt/mcumgr/smp_svr/boards/nrf54h20dk_nrf54h20_cpuapp_merged_slot.overlay

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55
*/
66

77
#include "../sysbuild/nrf54h20dk_nrf54h20_memory_map_merged_slot.dtsi"
8+
9+
/ {
10+
chosen {
11+
zephyr,code-partition = &cpuapp_slot0_partition;
12+
};
13+
};
14+
15+
secondary_app_partition: &cpuapp_slot1_partition {
16+
};

samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf54h20dk_nrf54h20_memory_map_merged_slot.dtsi

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,57 @@
55
*/
66

77
/* On nRF54H20 the Direct XIP mode is supported in the merged slot configuration
8-
* Merge application and radio slots by extending the application parition.
8+
* Extend slot0_partition and slot1_partition to cover both application and
9+
* radio images, as well as MCUboot image metadata (header and trailer).
10+
* Those partitions will be used by MCUboot to verify the merged image to boot.
11+
* Apart from that, they will be used by the MCUmgr subsystem to correctly
12+
* handle flags, stored inside the MCUboot image trailer.
13+
* Use cpu<app|rad>_slot<0|1>_partition as zephyr,code-partition, so the
14+
* application and radio sizes are correctly reported.
915
*/
10-
&cpuapp_slot0_partition {
11-
reg = <0x40000 DT_SIZE_K(656)>;
12-
};
16+
/delete-node/&cpuapp_slot0_partition;
17+
/delete-node/&cpuapp_slot1_partition;
18+
/delete-node/&cpurad_slot0_partition;
19+
/delete-node/&cpurad_slot1_partition;
20+
21+
&mram1x {
22+
partitions {
23+
/* Merged partition used by the MCUboot (variant 0). */
24+
slot0_partition: partition@40000 {
25+
reg = <0x40000 DT_SIZE_K(656)>;
26+
};
27+
28+
/* Application code partition (variant 0).
29+
* Offset by the MCUboot header size (2048 bytes).
30+
*/
31+
cpuapp_slot0_partition: partition@40800 {
32+
reg = <0x40800 DT_SIZE_K(326)>;
33+
};
34+
35+
/* Radio code partition (variant 0).
36+
* Reduced by the MCUboot trailer size (224 bytes).
37+
*/
38+
cpurad_slot0_partition: partition@92000 {
39+
reg = <0x92000 (DT_SIZE_K(328) - 224)>;
40+
};
41+
42+
/* Merged partition used by the MCUboot (variant 1). */
43+
slot1_partition: partition@100000 {
44+
reg = <0x100000 DT_SIZE_K(656)>;
45+
};
46+
47+
/* Application code partition (variant 1).
48+
* Offset by the MCUboot header size (2048 bytes).
49+
*/
50+
cpuapp_slot1_partition: partition@100800 {
51+
reg = <0x100800 DT_SIZE_K(326)>;
52+
};
1353

14-
&cpuapp_slot1_partition {
15-
reg = <0x100000 DT_SIZE_K(656)>;
54+
/* Radio code partition (variant 1).
55+
* Reduced by the MCUboot trailer size (224 bytes).
56+
*/
57+
cpurad_slot1_partition: partition@152000 {
58+
reg = <0x152000 (DT_SIZE_K(328) - 224)>;
59+
};
60+
};
1661
};

subsys/bootloader/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,9 @@ config MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE
170170
help
171171
This is a Kconfig which is informative only, the value should not be changed.
172172

173+
config NCS_MCUBOOT_BOOTLOADER_SIGN_MERGED_BINARY
174+
bool "Sign merged binary instead of individual images"
175+
help
176+
This is a Kconfig which is informative only, the value should not be changed.
177+
173178
endmenu

sysbuild/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
693693
if(SB_CONFIG_MCUBOOT_SIGN_MERGED_BINARY AND SB_CONFIG_SOC_NRF54H20)
694694
UpdateableImage_Get(images ALL)
695695
foreach(image ${images})
696+
set_config_bool(${image} CONFIG_NCS_MCUBOOT_BOOTLOADER_SIGN_MERGED_BINARY
697+
true)
696698
set(${image}_SIGNING_SCRIPT
697699
"${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/image_signing_nrf54h20.cmake"
698700
CACHE INTERNAL "MCUboot signing script" FORCE)

west.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ manifest:
6565
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/modules.html
6666
- name: zephyr
6767
repo-path: sdk-zephyr
68-
revision: pull/3309/head
68+
revision: pull/3310/head
6969
import:
7070
# In addition to the zephyr repository itself, NCS also
7171
# imports the contents of zephyr/west.yml at the above
@@ -128,7 +128,7 @@ manifest:
128128
compare-by-default: true
129129
- name: mcuboot
130130
repo-path: sdk-mcuboot
131-
revision: a999034ba25e3118a2c23b4a1a3d6dcc3920a16f
131+
revision: pull/538/head
132132
path: bootloader/mcuboot
133133
- name: qcbor
134134
url: https://github.com/laurencelundblade/QCBOR

0 commit comments

Comments
 (0)