Skip to content

Commit 12accd1

Browse files
ahasztagrlubos
authored andcommitted
cmake: Added the possibility to generate MCUBoot zip for nrf54h20
The needed changes were linked to untangling the use of partition manager. Signed-off-by: Artur Hadasz <[email protected]>
1 parent a7917f8 commit 12accd1

File tree

4 files changed

+98
-23
lines changed

4 files changed

+98
-23
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
# This file contains utility functions used for handling
5+
# data coming from the devicetree for configurations using
6+
# a bootloader.
7+
8+
function(get_address_from_dt_partition_nodelabel label address)
9+
dt_nodelabel(partition_node TARGET ${DEFAULT_IMAGE} NODELABEL ${label} REQUIRED)
10+
dt_reg_addr(partition_offset TARGET ${DEFAULT_IMAGE} PATH ${partition_node})
11+
12+
# Get the parent "two levels up" (../../) of the partition node
13+
# This is the partition flash area node
14+
string(REPLACE "/" ";" partition_node_split ${partition_node})
15+
list(LENGTH partition_node_split child_path_length)
16+
math(EXPR parent_path_length "${child_path_length} - 2")
17+
list(SUBLIST partition_node_split 0 ${parent_path_length} parent_path_split)
18+
string(REPLACE ";" "/" flash_area_node "${parent_path_split}")
19+
20+
dt_reg_addr(flash_area_addr TARGET ${DEFAULT_IMAGE} PATH ${flash_area_node})
21+
22+
math(EXPR ${address} "${flash_area_addr} + ${partition_offset}")
23+
set(${address} ${${address}} PARENT_SCOPE)
24+
endfunction()

cmake/sysbuild/sign_nrf54h20.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,15 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
246246

247247
# Set up .bin outputs.
248248
if(SB_CONFIG_BUILD_OUTPUT_BIN)
249+
set(bin_byproducts)
249250
foreach(hex_file ${byproducts})
250251
string(REGEX REPLACE "\\.[^.]*$" "" file_path ${hex_file})
251252
list(APPEND imgtool_cmd COMMAND
252253
${PYTHON_EXECUTABLE} ${HEX2BIN} ${hex_file} ${file_path}.bin
253254
)
255+
list(APPEND bin_byproducts ${file_path}.bin)
254256
endforeach()
257+
list(APPEND byproducts ${bin_byproducts})
255258
endif()
256259

257260
add_custom_target(

cmake/sysbuild/zip.cmake

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2024 Nordic Semiconductor ASA
22
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
33

4+
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake)
5+
46
function(mcuboot_image_number_to_slot result image secondary)
57
if(secondary)
68
set(secondary_offset "+ 1")
@@ -113,12 +115,18 @@ function(dfu_app_zip_package)
113115
mcuboot_image_number_to_slot(slot_secondary ${SB_CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER} y)
114116

115117
if(NOT SB_CONFIG_MCUBOOT_BUILD_DIRECT_XIP_VARIANT)
118+
if(SB_CONFIG_PARTITION_MANAGER)
119+
set(load_address "$<TARGET_PROPERTY:partition_manager,PM_APP_ADDRESS>")
120+
else()
121+
get_address_from_dt_partition_nodelabel("slot${slot_primary}_partition" load_address)
122+
endif()
123+
116124
# Application
117125
math(EXPR slot_primary "${slot_primary} + 1")
118126
math(EXPR slot_secondary "${slot_secondary} + 1")
119127

120128
set(generate_script_app_params
121-
"${app_update_name}load_address=$<TARGET_PROPERTY:partition_manager,PM_APP_ADDRESS>"
129+
"${app_update_name}load_address=${load_address}"
122130
"${app_update_name}image_index=${SB_CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER}"
123131
"${app_update_name}slot_index_primary=${slot_primary}"
124132
"${app_update_name}slot_index_secondary=${slot_secondary}"
@@ -135,45 +143,75 @@ function(dfu_app_zip_package)
135143
list(APPEND signed_targets ${DEFAULT_IMAGE}_extra_byproducts)
136144
set(include_files INCLUDE ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin)
137145
else()
146+
if(SB_CONFIG_PARTITION_MANAGER)
147+
set(primary_load_address "$<TARGET_PROPERTY:partition_manager,PM_MCUBOOT_PRIMARY_APP_ADDRESS>")
148+
set(secondary_load_address "$<TARGET_PROPERTY:partition_manager,PM_MCUBOOT_SECONDARY_APP_ADDRESS>")
149+
else()
150+
get_address_from_dt_partition_nodelabel("slot${slot_primary}_partition" primary_load_address)
151+
get_address_from_dt_partition_nodelabel("slot${slot_secondary}_partition" secondary_load_address)
152+
endif()
153+
138154
# Application in DirectXIP mode
139155
set(generate_script_app_params
140-
"${app_update_name}load_address=$<TARGET_PROPERTY:partition_manager,PM_MCUBOOT_PRIMARY_APP_ADDRESS>"
156+
"${app_update_name}load_address=${primary_load_address}"
141157
"${app_update_name}version_MCUBOOT+XIP=${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION}"
142158
"${app_update_name}image_index=${SB_CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER}"
143159
"${app_update_name}slot=${slot_primary}"
144-
"${secondary_app_update_name}load_address=$<TARGET_PROPERTY:partition_manager,PM_MCUBOOT_SECONDARY_APP_ADDRESS>"
160+
"${secondary_app_update_name}load_address=${secondary_load_address}"
145161
"${secondary_app_update_name}image_index=${SB_CONFIG_MCUBOOT_APPLICATION_IMAGE_NUMBER}"
146162
"${secondary_app_update_name}slot=${slot_secondary}"
147163
"${secondary_app_update_name}version_MCUBOOT+XIP=${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION}"
148164
)
149165

150-
list(APPEND bin_files
151-
"${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin"
152-
"${CMAKE_BINARY_DIR}/mcuboot_secondary_app/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin"
153-
)
154-
set(exclude_files EXCLUDE
155-
${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin
156-
${CMAKE_BINARY_DIR}/mcuboot_secondary_app/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin
157-
)
166+
if(NOT SB_CONFIG_MCUBOOT_SIGN_MERGED_BINARY)
167+
list(APPEND bin_files
168+
"${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin"
169+
"${CMAKE_BINARY_DIR}/mcuboot_secondary_app/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin"
170+
)
171+
set(exclude_files EXCLUDE
172+
${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin
173+
${CMAKE_BINARY_DIR}/mcuboot_secondary_app/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin
174+
)
175+
set(include_files INCLUDE
176+
${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
177+
${CMAKE_BINARY_DIR}/mcuboot_secondary_app/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
178+
)
179+
else()
180+
list(APPEND bin_files
181+
"${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.signed.bin"
182+
"${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}_secondary_app.signed.bin"
183+
)
184+
endif()
185+
158186
list(APPEND zip_names "${app_update_name};${secondary_app_update_name}")
159187
list(APPEND signed_targets ${DEFAULT_IMAGE}_extra_byproducts mcuboot_secondary_app_extra_byproducts)
160-
set(include_files INCLUDE
161-
${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
162-
${CMAKE_BINARY_DIR}/mcuboot_secondary_app/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
163-
)
164188
endif()
165189
endif()
166190
endif()
167191

168-
if(SB_CONFIG_DFU_ZIP_NET)
192+
if(SB_CONFIG_DFU_ZIP_NET AND NOT SB_CONFIG_MCUBOOT_SIGN_MERGED_BINARY)
169193
# Network core
170194
get_property(image_name GLOBAL PROPERTY DOMAIN_APP_CPUNET)
171195
set(net_update_name "${image_name}.bin")
172196
sysbuild_get(net_core_board IMAGE ${image_name} VAR BOARD CACHE)
173-
sysbuild_get(net_update_version IMAGE ${image_name} VAR CONFIG_FW_INFO_FIRMWARE_VERSION KCONFIG)
197+
198+
if(SB_CONFIG_SECURE_BOOT_NETCORE)
199+
sysbuild_get(net_update_version IMAGE ${image_name} VAR CONFIG_FW_INFO_FIRMWARE_VERSION KCONFIG)
200+
else()
201+
sysbuild_get(net_update_version IMAGE ${image_name} VAR CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION KCONFIG)
202+
endif()
174203

175204
mcuboot_image_number_to_slot(net_update_slot_primary ${SB_CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER} n)
176205
mcuboot_image_number_to_slot(net_update_slot_secondary ${SB_CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER} y)
206+
207+
if(SB_CONFIG_PARTITION_MANAGER)
208+
set(net_load_address "$<TARGET_PROPERTY:partition_manager,CPUNET_PM_APP_ADDRESS>")
209+
else()
210+
get_address_from_dt_partition_nodelabel("slot${net_update_slot_primary}_partition"
211+
net_load_address
212+
)
213+
endif()
214+
177215
math(EXPR net_update_slot_primary "${net_update_slot_primary} + 1")
178216
math(EXPR net_update_slot_secondary "${net_update_slot_secondary} + 1")
179217

@@ -182,14 +220,26 @@ function(dfu_app_zip_package)
182220
"${net_update_name}image_index=${SB_CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER}"
183221
"${net_update_name}slot_index_primary=${net_update_slot_primary}"
184222
"${net_update_name}slot_index_secondary=${net_update_slot_secondary}"
185-
"${net_update_name}load_address=$<TARGET_PROPERTY:partition_manager,CPUNET_PM_APP_ADDRESS>"
223+
"${net_update_name}load_address=${net_load_address}"
186224
"${net_update_name}version=${net_update_version}"
187225
"${net_update_name}board=${net_core_board}"
188226
"${net_update_name}soc=${SB_CONFIG_SOC}"
189227
)
190-
list(APPEND bin_files "${CMAKE_BINARY_DIR}/signed_by_mcuboot_and_b0_${image_name}.bin")
228+
229+
if(SB_CONFIG_SECURE_BOOT_NETCORE)
230+
list(APPEND bin_files "${CMAKE_BINARY_DIR}/signed_by_mcuboot_and_b0_${image_name}.bin")
231+
list(APPEND signed_targets ${image_name}_signed_packaged_target)
232+
else()
233+
sysbuild_get(net_CONFIG_KERNEL_BIN_NAME IMAGE ${image_name} VAR CONFIG_KERNEL_BIN_NAME KCONFIG)
234+
if(SB_CONFIG_BOOT_ENCRYPTION)
235+
list(APPEND bin_files "${CMAKE_BINARY_DIR}/${image_name}/zephyr/${net_CONFIG_KERNEL_BIN_NAME}.signed.encrypted.bin")
236+
else()
237+
list(APPEND bin_files "${CMAKE_BINARY_DIR}/${image_name}/zephyr/${net_CONFIG_KERNEL_BIN_NAME}.signed.bin")
238+
endif()
239+
endif()
240+
191241
list(APPEND zip_names "${net_update_name}")
192-
list(APPEND signed_targets ${image_name}_extra_byproducts ${image_name}_signed_packaged_target)
242+
list(APPEND signed_targets ${image_name}_extra_byproducts)
193243
endif()
194244

195245
if(SB_CONFIG_DFU_ZIP_WIFI_FW_PATCH)

sysbuild/Kconfig.zip

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
menuconfig DFU_ZIP
66
bool "Create DFU zip package"
77
depends on BOOTLOADER_MCUBOOT || (SECURE_BOOT_APPCORE && SECURE_BOOT_BUILD_S1_VARIANT_IMAGE)
8-
depends on PARTITION_MANAGER
98
default y
109
help
1110
Build DFU zip package that contains a manifest file and selected update images.
@@ -24,8 +23,7 @@ config DFU_ZIP_NET
2423
bool "Network core update"
2524
depends on SUPPORT_NETCORE
2625
depends on !NETCORE_NONE
27-
depends on SECURE_BOOT_NETCORE
28-
depends on NETCORE_APP_UPDATE
26+
depends on (SECURE_BOOT_NETCORE && NETCORE_APP_UPDATE) || SOC_SERIES_NRF54HX
2927
default y
3028
help
3129
Include network-core update in DFU zip.

0 commit comments

Comments
 (0)