33# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
44
55function (merge_images_nrf54h20 output_artifact images )
6- find_program (MERGEHEX mergehex.py HINTS ${ZEPHYR_BASE} /scripts/build/ NAMES mergehex NAMES_PER_DIR )
6+ find_program (MERGEHEX mergehex.py HINTS ${ZEPHYR_BASE} /scripts/build/ NAMES
7+ mergehex NAMES_PER_DIR )
78 if (NOT DEFINED MERGEHEX)
89 message (FATAL_ERROR "Can't merge images: can't find mergehex.py" )
910 return ()
@@ -12,8 +13,10 @@ function(merge_images_nrf54h20 output_artifact images)
1213 foreach (image ${images} )
1314 # Build a dependency list for the final (merged) artifact.
1415 sysbuild_get (BINARY_DIR IMAGE ${image} VAR APPLICATION_BINARY_DIR CACHE )
15- sysbuild_get (BINARY_HEX_FILE IMAGE ${image} VAR RUNNERS_HEX_FILE_TO_MERGE CACHE )
16- cmake_path (APPEND BINARY_DIR "zephyr" ${BINARY_HEX_FILE} OUTPUT_VARIABLE app_binary )
16+ sysbuild_get (BINARY_HEX_FILE IMAGE ${image} VAR RUNNERS_HEX_FILE_TO_MERGE
17+ CACHE )
18+ cmake_path (APPEND BINARY_DIR "zephyr" ${BINARY_HEX_FILE} OUTPUT_VARIABLE
19+ app_binary )
1720 list (APPEND binaries_to_merge "${app_binary} " )
1821 endforeach ()
1922
@@ -37,7 +40,8 @@ function(disable_programming_nrf54h20 images)
3740endfunction ()
3841
3942function (mcuboot_sign_merged_nrf54h20 merged_hex main_image )
40- find_program (IMGTOOL imgtool.py HINTS ${ZEPHYR_MCUBOOT_MODULE_DIR} /scripts/ NAMES imgtool NAMES_PER_DIR )
43+ find_program (IMGTOOL imgtool.py HINTS ${ZEPHYR_MCUBOOT_MODULE_DIR} /scripts/
44+ NAMES imgtool NAMES_PER_DIR )
4145 find_program (HEX2BIN hex2bin.py NAMES hex2bin )
4246 set (keyfile "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE} " )
4347 set (keyfile_enc "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE} " )
@@ -51,8 +55,9 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
5155 # No signature key file, no signed binaries. No error, though:
5256 # this is the documented behavior.
5357 message (WARNING "Neither SB_CONFIG_SIGNATURE_TYPE or "
54- "SB_CONFIG_BOOT_SIGNATURE_KEY_FILE are set, the generated build will not be "
55- "bootable by MCUboot unless it is signed manually/externally." )
58+ "SB_CONFIG_BOOT_SIGNATURE_KEY_FILE are set, the generated"
59+ " build will not be bootable by MCUboot unless it is "
60+ "signed manually/externally." )
5661 return ()
5762 endif ()
5863
@@ -79,31 +84,37 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
7984 # imgtool. So, this is maintained here for backward compatibility
8085 #
8186 if (NOT WEST OR NOT WEST_TOPDIR)
82- message (FATAL_ERROR "Can't sign images for MCUboot: west workspace undefined. "
83- "To fix, ensure `west topdir` is a valid workspace directory." )
87+ message (FATAL_ERROR "Can't sign images for MCUboot: west workspace "
88+ "undefined. To fix, ensure `west topdir` is a "
89+ "valid workspace directory." )
8490 endif ()
8591 set (${file} "${WEST_TOPDIR} /${${file} }" )
8692 endif ()
8793 endif ()
8894
8995 if (NOT EXISTS "${${file} }" )
90- message (FATAL_ERROR "Can't sign images for MCUboot: can't find file ${${file} } "
91- "(Note: Relative paths are searched through "
92- "SB_APPLICATION_CONFIG_DIR=\" ${SB_APPLICATION_CONFIG_DIR} \" "
93- "and WEST_TOPDIR=\" ${WEST_TOPDIR} \" )" )
96+ message (FATAL_ERROR "Can't sign images for MCUboot: can't find file "
97+ "${${file} } (Note: Relative paths are searched "
98+ "through SB_APPLICATION_CONFIG_DIR="
99+ "\" ${SB_APPLICATION_CONFIG_DIR} \" and WEST_TOPDIR="
100+ "\" ${WEST_TOPDIR} \" )" )
94101 endif ()
95102 endforeach ()
96103 endif ()
97104
98105 # No imgtool, no signed binaries.
99106 if (NOT DEFINED IMGTOOL)
100- message (FATAL_ERROR "Can't sign images for MCUboot: can't find imgtool. To fix, install imgtool with pip3, or add the mcuboot repository to the west manifest and ensure it has a scripts/imgtool.py file." )
107+ message (FATAL_ERROR "Can't sign images for MCUboot: can't find imgtool. "
108+ "To fix, install imgtool with pip3, or add the mcuboot "
109+ "repository to the west manifest and ensure it has "
110+ "a scripts/imgtool.py file." )
101111 return ()
102112 endif ()
103113
104114 # No hex2bin, no signed bin files.
105115 if (SB_CONFIG_BUILD_OUTPUT_BIN AND NOT DEFINED HEX2BIN)
106- message (FATAL_ERROR "Can't convert HEX files for MCUboot: can't find hex2bin. To fix, install hex2bin with pip3." )
116+ message (FATAL_ERROR "Can't convert HEX files for MCUboot: can't find "
117+ "hex2bin. To fix, install hex2bin with pip3." )
107118 return ()
108119 endif ()
109120
@@ -117,9 +128,11 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
117128
118129 # Fetch extra arguments to imgtool from the main image Kconfig.
119130 set (CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS)
120- sysbuild_get (CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS IMAGE ${main_image} VAR CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS KCONFIG )
131+ sysbuild_get (CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS IMAGE ${main_image} VAR
132+ CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS KCONFIG )
121133 if (NOT CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS STREQUAL "" )
122- separate_arguments (imgtool_args UNIX_COMMAND ${CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS} )
134+ separate_arguments (imgtool_args UNIX_COMMAND
135+ ${CONFIG_MCUBOOT_EXTRA_IMGTOOL_ARGS} )
123136 else ()
124137 set (imgtool_args)
125138 endif ()
@@ -152,13 +165,17 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
152165 set (CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION)
153166 set (CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE)
154167 set (CONFIG_NCS_IS_VARIANT_IMAGE)
155- sysbuild_get (CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION IMAGE ${main_image} VAR CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION KCONFIG )
156- sysbuild_get (CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE IMAGE ${main_image} VAR CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE KCONFIG )
157- sysbuild_get (CONFIG_NCS_IS_VARIANT_IMAGE IMAGE ${main_image} VAR CONFIG_NCS_IS_VARIANT_IMAGE CACHE )
168+ sysbuild_get (CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION IMAGE ${main_image} VAR
169+ CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION KCONFIG )
170+ sysbuild_get (CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE IMAGE ${main_image} VAR
171+ CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE KCONFIG )
172+ sysbuild_get (CONFIG_NCS_IS_VARIANT_IMAGE IMAGE ${main_image} VAR
173+ CONFIG_NCS_IS_VARIANT_IMAGE CACHE )
158174
159175 # Fetch devicetree details for flash and slot information.
160176 dt_chosen (flash_node TARGET mcuboot PROPERTY "zephyr,flash" )
161- dt_prop (write_block_size TARGET mcuboot PATH "${flash_node} " PROPERTY "write-block-size" )
177+ dt_prop (write_block_size TARGET mcuboot PATH "${flash_node} " PROPERTY
178+ "write-block-size" )
162179 dt_nodelabel (slot0_path TARGET mcuboot NODELABEL "slot0_partition" REQUIRED )
163180 dt_reg_addr (slot0_addr TARGET mcuboot PATH ${slot0_path} )
164181 dt_reg_size (slot0_size TARGET mcuboot PATH ${slot0_path} )
@@ -167,14 +184,16 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
167184 dt_reg_size (slot1_size TARGET mcuboot PATH ${slot1_path} )
168185 if (NOT write_block_size)
169186 set (write_block_size 4)
170- message (WARNING "slot0_partition write block size devicetree parameter is missing, assuming write block size is 4" )
187+ message (WARNING "slot0_partition write block size devicetree parameter is "
188+ "missing, assuming write block size is 4" )
171189 endif ()
172190
173191 # Fetch devicetree details for the active code partition.
174192 dt_chosen (code_flash TARGET ${main_image} PROPERTY "zephyr,code-partition" )
175193 dt_reg_addr (code_addr TARGET ${main_image} PATH ${code_flash} )
176194 set (start_offset)
177- sysbuild_get (start_offset IMAGE ${main_image} VAR CONFIG_ROM_START_OFFSET KCONFIG )
195+ sysbuild_get (start_offset IMAGE ${main_image} VAR CONFIG_ROM_START_OFFSET
196+ KCONFIG )
178197
179198 # Append key file path.
180199 if (NOT "${keyfile} " STREQUAL "" )
@@ -183,7 +202,8 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
183202
184203 # Construct imgtool command, based on the selected MCUboot mode.
185204 set (imgtool_rom_command)
186- if (SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT OR SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP)
205+ if (SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT OR
206+ SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP)
187207 if (CONFIG_NCS_IS_VARIANT_IMAGE)
188208 set (slot_size ${slot1_size} )
189209 else ()
@@ -197,25 +217,30 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
197217
198218 # Basic 'imgtool sign' command with known image information.
199219 set (imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign
200- --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --header-size ${start_offset}
201- --slot-size ${slot_size} ${imgtool_rom_command} )
220+ --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --header-size
221+ ${start_offset} --slot-size ${slot_size} ${imgtool_rom_command} )
202222 set (imgtool_args --align ${write_block_size} ${imgtool_args} )
203223
204224 # Extensionless prefix of any output file.
205225 sysbuild_get (BINARY_DIR IMAGE ${main_image} VAR APPLICATION_BINARY_DIR CACHE )
206- sysbuild_get (BINARY_BIN_FILE IMAGE ${main_image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG )
226+ sysbuild_get (BINARY_BIN_FILE IMAGE ${main_image} VAR
227+ CONFIG_KERNEL_BIN_NAME KCONFIG )
207228 cmake_path (GET BINARY_DIR PARENT_PATH sysbuild_build_dir )
208229 if (CONFIG_NCS_IS_VARIANT_IMAGE)
209- cmake_path (APPEND sysbuild_build_dir "zephyr" "${BINARY_BIN_FILE} _secondary_app" OUTPUT_VARIABLE output )
230+ cmake_path (APPEND sysbuild_build_dir "zephyr"
231+ "${BINARY_BIN_FILE} _secondary_app" OUTPUT_VARIABLE output )
210232 else ()
211- cmake_path (APPEND sysbuild_build_dir "zephyr" "${BINARY_BIN_FILE} " OUTPUT_VARIABLE output )
233+ cmake_path (APPEND sysbuild_build_dir "zephyr" "${BINARY_BIN_FILE} "
234+ OUTPUT_VARIABLE output )
212235 endif ()
213236
214237 # List of additional build byproducts.
215238 set (byproducts ${output} .merged.hex)
216239
217- sysbuild_get (CONFIG_MCUBOOT_BOOTLOADER_USES_SHA512 IMAGE ${main_image} VAR CONFIG_MCUBOOT_BOOTLOADER_USES_SHA512 KCONFIG )
218- sysbuild_get (CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE IMAGE ${main_image} VAR CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE KCONFIG )
240+ sysbuild_get (CONFIG_MCUBOOT_BOOTLOADER_USES_SHA512 IMAGE ${main_image} VAR
241+ CONFIG_MCUBOOT_BOOTLOADER_USES_SHA512 KCONFIG )
242+ sysbuild_get (CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE IMAGE ${main_image}
243+ VAR CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE KCONFIG )
219244
220245 # Set proper hash calculation algorithm for signing
221246 if (CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE)
@@ -239,32 +264,35 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
239264 )
240265
241266 if (NOT "${keyfile_enc} " STREQUAL "" )
242- # When encryption is enabled, set the encrypted bit when signing the image but do not
243- # encrypt the data, this means that when the image is moved out of the primary into the
244- # secondary, it will be encrypted rather than being in unencrypted
267+ # When encryption is enabled, set the encrypted bit when signing the image
268+ # but do not encrypt the data, this means that when the image is moved out
269+ # of the primary into the secondary, it will be encrypted rather than
270+ # being in unencrypted.
245271 list (APPEND imgtool_cmd COMMAND
246- ${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc} " --clear ${merged_hex} ${output} .signed.hex)
272+ ${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc} " --clear
273+ ${merged_hex} ${output} .signed.hex)
247274 else ()
248275 list (APPEND imgtool_cmd COMMAND
249276 ${imgtool_sign} ${imgtool_args} ${merged_hex} ${output} .signed.hex)
250277 endif ()
251278
252- if (CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE OR SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT)
279+ if (CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE OR
280+ SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT)
253281 list (APPEND byproducts ${output} .signed.confirmed.hex)
254282 set (final_artifact_hex ${output} .signed.confirmed.hex)
255- set (BYPRODUCT_KERNEL_SIGNED_CONFIRMED_HEX_NAME " ${output} .signed.confirmed.hex"
256- CACHE FILEPATH "Signed and confirmed kernel hex file" FORCE
257- )
283+ set (BYPRODUCT_KERNEL_SIGNED_CONFIRMED_HEX_NAME
284+ " ${output} .signed. confirmed. hex" CACHE FILEPATH
285+ "Signed and confirmed kernel hex file" FORCE )
258286 list (APPEND imgtool_cmd COMMAND
259287 ${imgtool_sign} ${imgtool_args} --pad --confirm ${merged_hex}
260288 ${output} .signed.confirmed.hex)
261289 endif ()
262290
263291 if (NOT "${keyfile_enc} " STREQUAL "" )
264292 list (APPEND byproducts ${output} .signed.encrypted.hex)
265- set (BYPRODUCT_KERNEL_SIGNED_ENCRYPTED_HEX_NAME " ${output} .signed.encrypted.hex"
266- CACHE FILEPATH "Signed and encrypted kernel hex file" FORCE
267- )
293+ set (BYPRODUCT_KERNEL_SIGNED_ENCRYPTED_HEX_NAME
294+ " ${output} .signed. encrypted. hex" CACHE FILEPATH
295+ "Signed and encrypted kernel hex file" FORCE )
268296 list (APPEND imgtool_cmd COMMAND
269297 ${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc} " ${merged_hex}
270298 ${output} .signed.encrypted.hex)
0 commit comments