Skip to content

Commit 5b49577

Browse files
committed
sysbuild: Allow to use imgtool-based headers
It is possible to add MCUboot header through --pad-header option. In such cases, the FLASH_LOAD_OFFSET does not point to the begining of the slot, but to the beginning of the executable area, thus the check for the active slot should use ranges instead of exact values. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent a390985 commit 5b49577

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

cmake/sysbuild/sign_nrf54h20.cmake

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,14 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
206206
SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP)
207207
if(CONFIG_NCS_IS_VARIANT_IMAGE)
208208
set(slot_size ${slot1_size})
209+
set(slot_addr ${slot1_addr})
209210
else()
210211
set(slot_size ${slot0_size})
212+
set(slot_addr ${slot0_addr})
211213
endif()
212-
set(imgtool_rom_command --rom-fixed ${code_addr})
214+
# Adjust start offset, based on the active slot and code partition address.
215+
math(EXPR start_offset "${start_offset} + ${code_addr} - ${slot_addr}")
216+
set(imgtool_rom_command --rom-fixed ${slot_addr})
213217
else()
214218
message(FATAL_ERROR "Only Direct XIP MCUboot modes are supported.")
215219
return()
@@ -218,7 +222,8 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
218222
# Basic 'imgtool sign' command with known image information.
219223
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign
220224
--version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --header-size
221-
${start_offset} --slot-size ${slot_size} ${imgtool_rom_command})
225+
${start_offset} --slot-size ${slot_size} --pad-header
226+
${imgtool_rom_command})
222227
set(imgtool_args --align ${write_block_size} ${imgtool_args})
223228

224229
# Extensionless prefix of any output file.
@@ -284,8 +289,8 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
284289
"${output}.signed.confirmed.hex" CACHE FILEPATH
285290
"Signed and confirmed kernel hex file" FORCE)
286291
list(APPEND imgtool_cmd COMMAND
287-
${imgtool_sign} ${imgtool_args} --pad --confirm ${merged_hex}
288-
${output}.signed.confirmed.hex)
292+
${imgtool_sign} ${imgtool_args} --pad --pad-header --confirm
293+
${merged_hex} ${output}.signed.confirmed.hex)
289294
endif()
290295

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

samples/dfu/ab/src/ab_utils.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ LOG_MODULE_DECLARE(ab_sample);
3939

4040
#define SLOT_A_OFFSET FIXED_PARTITION_OFFSET(SLOT_A_PARTITION)
4141
#define SLOT_B_OFFSET FIXED_PARTITION_OFFSET(SLOT_B_PARTITION)
42+
#define SLOT_A_SIZE FIXED_PARTITION_SIZE(SLOT_A_PARTITION)
43+
#define SLOT_B_SIZE FIXED_PARTITION_SIZE(SLOT_B_PARTITION)
4244

4345
#define SLOT_A_FLASH_AREA_ID FIXED_PARTITION_ID(SLOT_A_PARTITION)
4446
#define SLOT_B_FLASH_AREA_ID FIXED_PARTITION_ID(SLOT_B_PARTITION)
4547

46-
#define IS_SLOT_A (CODE_PARTITION_OFFSET == SLOT_A_OFFSET)
47-
#define IS_SLOT_B (CODE_PARTITION_OFFSET == SLOT_B_OFFSET)
48+
#define IS_SLOT_A \
49+
(CODE_PARTITION_OFFSET >= SLOT_A_OFFSET && \
50+
CODE_PARTITION_OFFSET < SLOT_A_OFFSET + SLOT_A_SIZE)
51+
#define IS_SLOT_B \
52+
(CODE_PARTITION_OFFSET >= SLOT_B_OFFSET && \
53+
CODE_PARTITION_OFFSET < SLOT_B_OFFSET + SLOT_B_SIZE)
4854

4955
#endif /* CONFIG_PARTITION_MANAGER_ENABLED */
5056

0 commit comments

Comments
 (0)