3
3
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
4
4
5
5
function (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)
7
8
if (NOT DEFINED MERGEHEX)
8
9
message (FATAL_ERROR "Can't merge images: can't find mergehex.py" )
9
10
return ()
@@ -12,8 +13,10 @@ function(merge_images_nrf54h20 output_artifact images)
12
13
foreach (image ${images} )
13
14
# Build a dependency list for the final (merged) artifact.
14
15
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)
17
20
list (APPEND binaries_to_merge "${app_binary} " )
18
21
endforeach ()
19
22
@@ -37,7 +40,8 @@ function(disable_programming_nrf54h20 images)
37
40
endfunction ()
38
41
39
42
function (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)
41
45
find_program (HEX2BIN hex2bin.py NAMES hex2bin)
42
46
set (keyfile "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE} " )
43
47
set (keyfile_enc "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE} " )
@@ -51,8 +55,9 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
51
55
# No signature key file, no signed binaries. No error, though:
52
56
# this is the documented behavior.
53
57
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." )
56
61
return ()
57
62
endif ()
58
63
@@ -79,31 +84,37 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
79
84
# imgtool. So, this is maintained here for backward compatibility
80
85
#
81
86
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." )
84
90
endif ()
85
91
set (${file} "${WEST_TOPDIR} /${${file} }" )
86
92
endif ()
87
93
endif ()
88
94
89
95
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} \" )" )
94
101
endif ()
95
102
endforeach ()
96
103
endif ()
97
104
98
105
# No imgtool, no signed binaries.
99
106
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." )
101
111
return ()
102
112
endif ()
103
113
104
114
# No hex2bin, no signed bin files.
105
115
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." )
107
118
return ()
108
119
endif ()
109
120
@@ -117,9 +128,11 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
117
128
118
129
# Fetch extra arguments to imgtool from the main image Kconfig.
119
130
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)
121
133
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} )
123
136
else ()
124
137
set (imgtool_args)
125
138
endif ()
@@ -152,13 +165,17 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
152
165
set (CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION)
153
166
set (CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE)
154
167
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 )
158
174
159
175
# Fetch devicetree details for flash and slot information.
160
176
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" )
162
179
dt_nodelabel(slot0_path TARGET mcuboot NODELABEL "slot0_partition" REQUIRED)
163
180
dt_reg_addr(slot0_addr TARGET mcuboot PATH ${slot0_path} )
164
181
dt_reg_size(slot0_size TARGET mcuboot PATH ${slot0_path} )
@@ -167,14 +184,16 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
167
184
dt_reg_size(slot1_size TARGET mcuboot PATH ${slot1_path} )
168
185
if (NOT write_block_size)
169
186
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" )
171
189
endif ()
172
190
173
191
# Fetch devicetree details for the active code partition.
174
192
dt_chosen(code_flash TARGET ${main_image} PROPERTY "zephyr,code-partition" )
175
193
dt_reg_addr(code_addr TARGET ${main_image} PATH ${code_flash} )
176
194
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)
178
197
179
198
# Append key file path.
180
199
if (NOT "${keyfile} " STREQUAL "" )
@@ -183,7 +202,8 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
183
202
184
203
# Construct imgtool command, based on the selected MCUboot mode.
185
204
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)
187
207
if (CONFIG_NCS_IS_VARIANT_IMAGE)
188
208
set (slot_size ${slot1_size} )
189
209
else ()
@@ -197,25 +217,30 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
197
217
198
218
# Basic 'imgtool sign' command with known image information.
199
219
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} )
202
222
set (imgtool_args --align ${write_block_size} ${imgtool_args} )
203
223
204
224
# Extensionless prefix of any output file.
205
225
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)
207
228
cmake_path(GET BINARY_DIR PARENT_PATH sysbuild_build_dir)
208
229
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 )
210
232
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 )
212
235
endif ()
213
236
214
237
# List of additional build byproducts.
215
238
set (byproducts ${output} .merged.hex)
216
239
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)
219
244
220
245
# Set proper hash calculation algorithm for signing
221
246
if (CONFIG_MCUBOOT_BOOTLOADER_SIGNATURE_TYPE_PURE)
@@ -239,32 +264,35 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
239
264
)
240
265
241
266
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.
245
271
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)
247
274
else ()
248
275
list (APPEND imgtool_cmd COMMAND
249
276
${imgtool_sign} ${imgtool_args} ${merged_hex} ${output} .signed.hex)
250
277
endif ()
251
278
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)
253
281
list (APPEND byproducts ${output} .signed.confirmed.hex)
254
282
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 )
258
286
list (APPEND imgtool_cmd COMMAND
259
287
${imgtool_sign} ${imgtool_args} --pad --confirm ${merged_hex}
260
288
${output} .signed.confirmed.hex)
261
289
endif ()
262
290
263
291
if (NOT "${keyfile_enc} " STREQUAL "" )
264
292
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 )
268
296
list (APPEND imgtool_cmd COMMAND
269
297
${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc} " ${merged_hex}
270
298
${output} .signed.encrypted.hex)
0 commit comments