Skip to content

Commit 95dbbde

Browse files
nordicjmkartben
authored andcommitted
cmake: mcuboot: Set encrypted header flag when key is used
Uses the clear imgtool argument to set the encrypted flag in the header of the signed hex output, without encrypting the data. This addresses an issue whereby the first update would swap images and leave the swapped output in the secondary slot without encryption Signed-off-by: Jamie McCrae <[email protected]>
1 parent fe29c40 commit 95dbbde

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cmake/mcuboot.cmake

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,18 @@ function(zephyr_mcuboot_tasks)
183183
set(BYPRODUCT_KERNEL_SIGNED_HEX_NAME "${output}.signed.hex"
184184
CACHE FILEPATH "Signed kernel hex file" FORCE
185185
)
186-
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
187-
${imgtool_sign} ${imgtool_args} ${output}.hex ${output}.signed.hex)
186+
187+
if(NOT "${keyfile_enc}" STREQUAL "")
188+
# When encryption is enabled, set the encrypted bit when signing the image but do not
189+
# encrypt the data, this means that when the image is moved out of the primary into the
190+
# secondary, it will be encrypted rather than being in unencrypted
191+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
192+
${imgtool_sign} ${imgtool_args} --encrypt "${keyfile_enc}" --clear
193+
${output}.hex ${output}.signed.hex)
194+
else()
195+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
196+
${imgtool_sign} ${imgtool_args} ${output}.hex ${output}.signed.hex)
197+
endif()
188198

189199
if(CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE)
190200
list(APPEND byproducts ${output}.signed.confirmed.hex)

0 commit comments

Comments
 (0)