Skip to content

Commit c8ba190

Browse files
committed
cmake: sysbuild: Fix b0 signing
Fixes b0 signing to work for both application and network core images, and to only generate the dfu_mcuboot.zip if it is an MCUboot image Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent e494059 commit c8ba190

File tree

1 file changed

+34
-35
lines changed

1 file changed

+34
-35
lines changed

cmake/sysbuild/b0_mcuboot_signing.cmake

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Since this file is brought in via include(), we do the work in a
1111
# function to avoid polluting the top-level scope.
1212

13-
function(ncs_secure_boot_mcuboot_sign application application_name bin_files signed_targets)
13+
function(ncs_secure_boot_mcuboot_sign application output_name bin_files signed_targets prefix)
1414
set(keyfile "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}")
1515

1616
# Find imgtool. Even though west is installed, imgtool might not be.
@@ -38,15 +38,15 @@ function(ncs_secure_boot_mcuboot_sign application application_name bin_files sig
3838
sysbuild_get(CONFIG_BUILD_OUTPUT_BIN IMAGE ${application} VAR CONFIG_BUILD_OUTPUT_BIN KCONFIG)
3939
sysbuild_get(CONFIG_BUILD_OUTPUT_HEX IMAGE ${application} VAR CONFIG_BUILD_OUTPUT_HEX KCONFIG)
4040

41-
string(TOUPPER "${application_name}" application_name_uppercase)
42-
set(imgtool_sign ${imgtool_path} sign --version ${SB_CONFIG_SECURE_BOOT_MCUBOOT_VERSION} --align 4 --slot-size $<TARGET_PROPERTY:partition_manager,PM_${application_name_uppercase}_SIZE> --pad-header --header-size ${SB_CONFIG_PM_MCUBOOT_PAD})
41+
string(TOUPPER "${application}" application_uppercase)
42+
set(imgtool_sign ${imgtool_path} sign --version ${SB_CONFIG_SECURE_BOOT_MCUBOOT_VERSION} --align 4 --slot-size $<TARGET_PROPERTY:partition_manager,${prefix}PM_${application_uppercase}_SIZE> --pad-header --header-size ${SB_CONFIG_PM_MCUBOOT_PAD})
4343

4444
if(NOT "${keyfile}" STREQUAL "")
4545
set(imgtool_extra -k "${keyfile}" ${imgtool_extra})
4646
endif()
4747

4848
# Extensionless prefix of any output file.
49-
set(output ${PROJECT_BINARY_DIR}/signed_by_mcuboot_and_b0_${application})
49+
set(output ${PROJECT_BINARY_DIR}/signed_by_mcuboot_and_b0_${output_name})
5050

5151
# List of additional build byproducts.
5252
set(byproducts)
@@ -121,45 +121,44 @@ function(ncs_secure_boot_mcuboot_sign application application_name bin_files sig
121121
endif()
122122
endfunction()
123123

124-
if(SB_CONFIG_BOOTLOADER_MCUBOOT AND SB_CONFIG_SECURE_BOOT)
125-
set(bin_files)
126-
set(signed_targets)
127-
124+
if(SB_CONFIG_BOOTLOADER_MCUBOOT)
128125
if(SB_CONFIG_SECURE_BOOT_APPCORE)
129-
set(s0_image_name "mcuboot")
130-
set(s0_application_name "${s0_image_name}")
131-
else()
132-
get_property(image_name GLOBAL PROPERTY DOMAIN_APP_CPUNET)
133-
set(s0_image_name "${image_name}")
134-
set(s0_application_name "mcuboot_primary_1")
135-
endif()
126+
set(bin_files)
127+
set(signed_targets)
136128

137-
ncs_secure_boot_mcuboot_sign("${s0_image_name}" "${s0_application_name}" "${bin_files}" "${signed_targets}")
129+
ncs_secure_boot_mcuboot_sign(mcuboot s0_image "${bin_files}" "${signed_targets}" "")
138130

139-
if(SB_CONFIG_SECURE_BOOT_BUILD_S1_VARIANT_IMAGE)
140-
ncs_secure_boot_mcuboot_sign("s1_image" "s1_image" "${bin_files}" "${signed_targets}")
131+
if(SB_CONFIG_SECURE_BOOT_BUILD_S1_VARIANT_IMAGE)
132+
ncs_secure_boot_mcuboot_sign(s1_image s1_image "${bin_files}" "${signed_targets}" "")
133+
endif()
134+
135+
if(bin_files)
136+
sysbuild_get(mcuboot_fw_info_firmware_version IMAGE mcuboot VAR CONFIG_FW_INFO_FIRMWARE_VERSION KCONFIG)
137+
138+
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/fw_zip.cmake)
139+
140+
generate_dfu_zip(
141+
OUTPUT ${PROJECT_BINARY_DIR}/dfu_mcuboot.zip
142+
BIN_FILES ${bin_files}
143+
TYPE mcuboot
144+
IMAGE mcuboot
145+
SCRIPT_PARAMS
146+
"signed_by_mcuboot_and_b0_s0_image.binload_address=$<TARGET_PROPERTY:partition_manager,PM_S0_ADDRESS>"
147+
"signed_by_mcuboot_and_b0_s1_image.binload_address=$<TARGET_PROPERTY:partition_manager,PM_S1_ADDRESS>"
148+
"version_MCUBOOT=${SB_CONFIG_SECURE_BOOT_MCUBOOT_VERSION}"
149+
"version_B0=${mcuboot_fw_info_firmware_version}"
150+
DEPENDS ${signed_targets}
151+
)
152+
endif()
141153
endif()
142154

143-
if(bin_files)
144-
sysbuild_get(mcuboot_fw_info_firmware_version IMAGE mcuboot VAR CONFIG_FW_INFO_FIRMWARE_VERSION KCONFIG)
145-
146-
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/fw_zip.cmake)
147-
148-
generate_dfu_zip(
149-
OUTPUT ${PROJECT_BINARY_DIR}/dfu_mcuboot.zip
150-
BIN_FILES ${bin_files}
151-
TYPE mcuboot
152-
IMAGE mcuboot
153-
SCRIPT_PARAMS
154-
"signed_by_mcuboot_and_b0_${s0_image_name}.binload_address=$<TARGET_PROPERTY:partition_manager,PM_S0_ADDRESS>"
155-
"signed_by_mcuboot_and_b0_s1_image.binload_address=$<TARGET_PROPERTY:partition_manager,PM_S1_ADDRESS>"
156-
"version_MCUBOOT=${SB_CONFIG_SECURE_BOOT_MCUBOOT_VERSION}"
157-
"version_B0=${mcuboot_fw_info_firmware_version}"
158-
DEPENDS ${signed_targets}
159-
)
155+
if(SB_CONFIG_SECURE_BOOT_NETCORE)
156+
get_property(image_name GLOBAL PROPERTY DOMAIN_APP_CPUNET)
157+
ncs_secure_boot_mcuboot_sign(${image_name} ${image_name} "${bin_files}" "${signed_targets}" CPUNET_)
160158
endif()
161159

162160
# Clear temp variables
161+
set(image_name)
163162
set(bin_files)
164163
set(signed_targets)
165164
endif()

0 commit comments

Comments
 (0)