Skip to content

Commit 6eca39f

Browse files
committed
cmake: Generate confirmed images in Direct XIP
If building with revert functionality, generate the confirmed images so the application will boot after flashing the default set of artifacts. Ref: NCSIDB-1208 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 1ec3ab7 commit 6eca39f

File tree

3 files changed

+94
-11
lines changed

3 files changed

+94
-11
lines changed

cmake/sysbuild/image_signing.cmake

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ function(zephyr_mcuboot_tasks)
9393
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} --slot-size ${slot_size} --header-size ${CONFIG_ROM_START_OFFSET} ${imgtool_rom_command})
9494
endif()
9595

96-
set(imgtool_directxip_hex_command)
97-
98-
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
99-
set(imgtool_directxip_hex_command --confirm)
100-
endif()
101-
10296
# Arguments to imgtool.
10397
if(NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "")
10498
# Separate extra arguments into the proper format for adding to
@@ -208,6 +202,25 @@ function(zephyr_mcuboot_tasks)
208202
${imgtool_sign} ${imgtool_args} ${imgtool_bin_extra} ${imgtool_encrypt_extra_args} --encrypt
209203
"${keyfile_enc}" ${input_arg} ${output}.encrypted.bin)
210204
endif()
205+
206+
# Generate and use the confirmed image in Direct XIP with revert, so the
207+
# default application will boot after flashing.
208+
if(CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
209+
list(APPEND byproducts ${output}.confirmed.bin)
210+
zephyr_runner_file(bin ${output}.confirmed.bin)
211+
set(BYPRODUCT_KERNEL_SIGNED_CONFIRMED_BIN_NAME "${output}.confirmed.bin"
212+
CACHE FILEPATH "Signed and confirmed kernel bin file" FORCE
213+
)
214+
if("${keyfile_enc}" STREQUAL "")
215+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
216+
${imgtool_sign} ${imgtool_args} ${imgtool_bin_extra} --pad --confirm ${input_arg}
217+
${output}.confirmed.bin)
218+
else()
219+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
220+
${imgtool_sign} ${imgtool_args} ${imgtool_bin_extra} ${imgtool_encrypt_extra_args}
221+
--encrypt "${keyfile_enc}" --clear --pad --confirm ${input_arg} ${output}.confirmed.bin)
222+
endif()
223+
endif()
211224
endif()
212225

213226
# Set up .hex outputs.
@@ -236,12 +249,11 @@ function(zephyr_mcuboot_tasks)
236249
# after the commands which generate the unsigned versions.
237250
if("${keyfile_enc}" STREQUAL "")
238251
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
239-
${imgtool_sign} ${imgtool_args} ${imgtool_directxip_hex_command} ${imgtool_hex_extra}
240-
${input_arg} ${output}.hex)
252+
${imgtool_sign} ${imgtool_args} ${imgtool_hex_extra} ${input_arg} ${output}.hex)
241253
else()
242254
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
243-
${imgtool_sign} ${imgtool_args} ${imgtool_directxip_hex_command} ${imgtool_hex_extra}
244-
${imgtool_encrypt_extra_args} --encrypt "${keyfile_enc}" --clear ${input_arg} ${output}.hex)
255+
${imgtool_sign} ${imgtool_args} ${imgtool_hex_extra} ${imgtool_encrypt_extra_args} --encrypt
256+
"${keyfile_enc}" --clear ${input_arg} ${output}.hex)
245257

246258
list(APPEND byproducts ${output}.encrypted.hex)
247259
set(BYPRODUCT_KERNEL_SIGNED_ENCRYPTED_HEX_NAME "${output}.encrypted.hex"
@@ -252,6 +264,27 @@ function(zephyr_mcuboot_tasks)
252264
${imgtool_sign} ${imgtool_args} ${imgtool_hex_extra} ${imgtool_encrypt_extra_args} --encrypt
253265
"${keyfile_enc}" ${input_arg} ${output}.encrypted.hex)
254266
endif()
267+
268+
# Generate and use the confirmed image in Direct XIP with revert, so the
269+
# default application will boot after flashing.
270+
if(CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
271+
list(APPEND byproducts ${output}.confirmed.hex)
272+
if((NOT CONFIG_PARTITION_MANAGER_ENABLED) OR CONFIG_NCS_IS_VARIANT_IMAGE)
273+
zephyr_runner_file(hex ${output}.confirmed.hex)
274+
endif()
275+
set(BYPRODUCT_KERNEL_SIGNED_CONFIRMED_HEX_NAME "${output}.confirmed.hex"
276+
CACHE FILEPATH "Signed and confirmed kernel hex file" FORCE
277+
)
278+
if("${keyfile_enc}" STREQUAL "")
279+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
280+
${imgtool_sign} ${imgtool_args} ${imgtool_hex_extra} --pad --confirm ${input_arg}
281+
${output}.confirmed.hex)
282+
else()
283+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
284+
${imgtool_sign} ${imgtool_args} ${imgtool_hex_extra} ${imgtool_encrypt_extra_args}
285+
--encrypt "${keyfile_enc}" --clear --pad --confirm ${input_arg} ${output}.confirmed.hex)
286+
endif()
287+
endif()
255288
endif()
256289

257290
set_property(GLOBAL APPEND PROPERTY extra_post_build_byproducts ${byproducts})

cmake/sysbuild/image_signing_split.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,40 @@ function(zephyr_mcuboot_tasks)
245245
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
246246
${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/mergehex.py -o ${output_merged}.encrypted.hex ${output_internal}.encrypted.hex ${output_external}.encrypted.hex)
247247
endif()
248+
249+
if(CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
250+
list(APPEND byproducts ${output_merged}.confirmed.hex)
251+
if(CONFIG_NCS_IS_VARIANT_IMAGE)
252+
zephyr_runner_file(hex ${output_merged}.confirmed.hex)
253+
endif()
254+
set(BYPRODUCT_KERNEL_SIGNED_CONFIRMED_HEX_NAME "${output_merged}.confirmed.hex"
255+
CACHE FILEPATH "Signed and confirmed kernel hex file" FORCE
256+
)
257+
258+
if("${keyfile_enc}" STREQUAL "")
259+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
260+
${imgtool_internal_sign} ${imgtool_args} --pad --confirm ${input_internal_arg}.hex
261+
${output_internal}.confirmed.hex)
262+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
263+
${imgtool_external_sign} ${imgtool_args} --pad --confirm ${output_external}.hex
264+
${output_external}.confirmed.hex)
265+
# Combine the signed confirmed hex files into a single output hex file
266+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
267+
${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/mergehex.py -o ${output_merged}.confirmed.hex ${output_internal}.confirmed.hex ${output_external}.confirmed.hex)
268+
else()
269+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
270+
${imgtool_internal_sign} ${imgtool_args} ${imgtool_encrypt_extra_args} --encrypt
271+
"${keyfile_enc}" --clear --pad --confirm ${input_internal_arg}
272+
${output_internal}.confirmed.hex)
273+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
274+
${imgtool_external_sign} ${imgtool_args} ${imgtool_encrypt_extra_args} --encrypt
275+
"${keyfile_enc}" --clear --pad --confirm ${input_external_arg}
276+
${output_external}.confirmed.hex)
277+
# Combine the signed confirmed hex files into a single output hex file
278+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
279+
${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/mergehex.py -o ${output_merged}.confirmed.hex ${output_internal}.confirmed.hex ${output_external}.confirmed.hex)
280+
endif()
281+
endif()
248282
endif()
249283

250284
# Set up .bin outputs.
@@ -261,6 +295,19 @@ function(zephyr_mcuboot_tasks)
261295
CACHE FILEPATH "Signed kernel bin files" FORCE
262296
)
263297

298+
if(CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT)
299+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
300+
${CMAKE_OBJCOPY} --input-target=ihex --output-target=binary ${output_internal}.confirmed.hex ${output_internal}.confirmed.bin)
301+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
302+
${CMAKE_OBJCOPY} --input-target=ihex --output-target=binary ${output_external}.confirmed.hex ${output_external}.confirmed.bin)
303+
304+
list(APPEND byproducts "${output_internal}.confirmed.bin;${output_external}.confirmed.bin")
305+
306+
set(BYPRODUCT_KERNEL_SIGNED_CONFIRMED_BIN_NAME "${output_internal}.confirmed.bin;${output_external}.confirmed.bin"
307+
CACHE FILEPATH "Signed kernel bin files" FORCE
308+
)
309+
endif()
310+
264311
if(NOT "${keyfile_enc}" STREQUAL "")
265312
# Instead of re-signing, convert the encrypted hex files to binary using objcopy
266313
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND

cmake/sysbuild/partition_manager.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ function(partition_manager)
256256
# So for each domain we should just include the generated hex file.
257257
# Those are available thorugh sysbuild_get, but not locally as there is no parent image.
258258
list(APPEND explicitly_assigned ${part})
259-
sysbuild_get(${part}_PM_HEX_FILE IMAGE ${part} VAR BYPRODUCT_KERNEL_SIGNED_HEX_NAME CACHE)
259+
sysbuild_get(${part}_PM_HEX_FILE IMAGE ${part} VAR BYPRODUCT_KERNEL_SIGNED_CONFIRMED_HEX_NAME CACHE)
260+
if(NOT ${part}_PM_HEX_FILE)
261+
sysbuild_get(${part}_PM_HEX_FILE IMAGE ${part} VAR BYPRODUCT_KERNEL_SIGNED_HEX_NAME CACHE)
262+
endif()
260263
if(NOT ${part}_PM_HEX_FILE)
261264
sysbuild_get(${part}_PM_HEX_FILE IMAGE ${part} VAR BYPRODUCT_KERNEL_HEX_NAME CACHE)
262265
endif()

0 commit comments

Comments
 (0)