Skip to content

Commit 63fe36d

Browse files
nordicjmanhmolt
andcommitted
sysbuild: Add bootconf image
Adds a semi-zephyr project which will lock the bootconf area on supported devices. Generates and flashes a seprate hex file which is also added into the production hex file. Some issues with CMake have also been tidied up to improve readability. To enable the bootconf configuration generation and flashing, set SB_CONFIG_BM_BOOT_BOOTCONF_LOCK_WRITES=y. Disabled by default. Co-authored-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no> Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no> Signed-off-by: Mateusz Michalek <mateusz.michalek@nordicsemi.no>
1 parent 695b0c7 commit 63fe36d

File tree

4 files changed

+119
-20
lines changed

4 files changed

+119
-20
lines changed

cmake/bootconf/CMakeLists.txt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr
10+
COMPONENTS zephyr_default:dts,kconfig
11+
REQUIRED HINTS $ENV{ZEPHYR_BASE}
12+
)
13+
14+
project(bootconf)
15+
16+
# Manually include board configuration to enable automatic runners.yaml generation
17+
include(${BOARD_DIR}/board.cmake OPTIONAL)
18+
19+
# Create the runners_yaml_props_target that flash system expects
20+
add_custom_target(runners_yaml_props_target)
21+
22+
# Set hex_file property to point to zephyr.hex in this directory
23+
set_target_properties(runners_yaml_props_target PROPERTIES
24+
hex_file "${CMAKE_BINARY_DIR}/bootconf.hex"
25+
)
26+
27+
# Override the runners.yaml path to use CMAKE_CURRENT_BINARY_DIR/zephyr instead of
28+
# PROJECT_BINARY_DIR, this ensures runners.yaml is generated at <build>/softdevice/zephyr where
29+
# west expects it
30+
set(PROJECT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/zephyr)
31+
32+
# Include flash support to automatically generate runners.yaml
33+
include(${ZEPHYR_BASE}/cmake/flash/CMakeLists.txt)
34+
35+
# Generate bootconf file
36+
add_custom_target(bootconf_target
37+
ALL
38+
DEPENDS ${CMAKE_BINARY_DIR}/bootconf.hex
39+
)
40+
41+
dt_nodelabel(boot_partition_node_full_path NODELABEL "boot_partition")
42+
dt_reg_size(boot_partition_node_size PATH "${boot_partition_node_full_path}")
43+
44+
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bootconf.hex
45+
COMMAND ${Python3_EXECUTABLE}
46+
${ZEPHYR_NRF_MODULE_DIR}/scripts/reglock.py
47+
--output ${CMAKE_BINARY_DIR}/bootconf.hex
48+
--size ${boot_partition_node_size}
49+
--soc ${CONFIG_SOC}
50+
VERBATIM
51+
DEPENDS ${dts_files}
52+
)
53+
54+
if(${boot_partition_node_size} GREATER 0x7c00)
55+
message(WARNING
56+
"boot_partition doesn't fit into protection region. "
57+
"Protection will be applied over maximum allowed span."
58+
)
59+
endif()
60+
61+
set(BYPRODUCT_HEX_NAME
62+
"${CMAKE_BINARY_DIR}/bootconf.hex"
63+
CACHE FILEPATH "MCUboot with signed softdevice and flash metadata hex file" FORCE
64+
)

cmake/bootconf/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Nothing here

sysbuild/CMakeLists.txt

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
function(bm_install_setup)
8-
if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE)
8+
if(NOT SB_CONFIG_BM_BOOTLOADER_NONE)
99
ExternalZephyrProject_Add(
1010
APPLICATION ${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME}
1111
SOURCE_DIR ${SB_CONFIG_BM_BOOTLOADER_IMAGE_PATH}
@@ -15,7 +15,14 @@ function(bm_install_setup)
1515
sysbuild_add_dependencies(CONFIGURE ${DEFAULT_IMAGE} ${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME})
1616
sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${SB_CONFIG_BM_BOOTLOADER_IMAGE_NAME})
1717

18-
if(NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
18+
if(SB_CONFIG_BM_BOOT_BOOTCONF_LOCK_WRITES)
19+
ExternalZephyrProject_Add(
20+
APPLICATION bootconf
21+
SOURCE_DIR ${ZEPHYR_NRF_BM_MODULE_DIR}/cmake/bootconf
22+
)
23+
endif()
24+
25+
if(NOT SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
1926
ExternalZephyrProject_Add(
2027
APPLICATION ${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME}
2128
SOURCE_DIR ${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_PATH}
@@ -118,7 +125,7 @@ endfunction()
118125
function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
119126
cmake_parse_arguments(PRE_CMAKE "" "" "IMAGES" ${ARGN})
120127

121-
if(NOT DEFINED SB_CONFIG_NCS_BM)
128+
if(NOT SB_CONFIG_NCS_BM)
122129
# Disable bare-metal on all images
123130
foreach(image ${PRE_CMAKE_IMAGES})
124131
set_config_int(${image} CONFIG_NCS_BM n)
@@ -127,10 +134,10 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
127134
return()
128135
endif()
129136

130-
if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE)
137+
if(NOT SB_CONFIG_BM_BOOTLOADER_NONE)
131138
set(bm_install_images 1)
132139

133-
if(NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
140+
if(NOT SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
134141
# Firmware loader present
135142
set_target_properties(${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME} PROPERTIES
136143
IMAGE_CONF_SCRIPT ${ZEPHYR_NRF_BM_MODULE_DIR}/sysbuild/image_configurations/MAIN_image_default.cmake
@@ -192,7 +199,7 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
192199
set_config_int(${image} CONFIG_BM_METADATA_WRITE n)
193200
endif()
194201

195-
if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE AND NOT image STREQUAL "mcuboot")
202+
if(NOT SB_CONFIG_BM_BOOTLOADER_NONE AND NOT image STREQUAL "mcuboot")
196203
if(SB_CONFIG_SOC_SERIES_NRF54LX)
197204
set_config_int(installer CONFIG_ROM_START_OFFSET 0x800)
198205
else()
@@ -204,15 +211,15 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
204211
if(SB_CONFIG_SOFTDEVICE_NONE)
205212
set_config_bool(${DEFAULT_IMAGE} CONFIG_SOFTDEVICE n)
206213

207-
if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE AND NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
214+
if(NOT SB_CONFIG_BM_BOOTLOADER_NONE AND NOT SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
208215
set_config_bool(${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME} CONFIG_SOFTDEVICE n)
209216
endif()
210217
else()
211218
foreach(option SOFTDEVICE_S115 SOFTDEVICE_S145)
212219
if(SB_CONFIG_${option})
213220
set_config_bool(${DEFAULT_IMAGE} CONFIG_${option} y)
214221

215-
if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE AND NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_NONE AND NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_UART_MCUMGR)
222+
if(NOT SB_CONFIG_BM_BOOTLOADER_NONE AND NOT SB_CONFIG_BM_FIRMWARE_LOADER_NONE AND NOT SB_CONFIG_BM_FIRMWARE_LOADER_UART_MCUMGR)
216223
set_config_bool(${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME} CONFIG_${option} y)
217224
endif()
218225
break()
@@ -222,38 +229,50 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
222229
endfunction()
223230

224231
function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake)
225-
if(NOT DEFINED SB_CONFIG_NCS_BM)
232+
if(NOT SB_CONFIG_NCS_BM)
226233
return()
227234
endif()
228235

229236
cmake_parse_arguments(PRE_CMAKE "" "" "IMAGES" ${ARGN})
230237

231-
if(NOT DEFINED SB_CONFIG_BM_BOOTLOADER_NONE)
238+
if(NOT SB_CONFIG_BM_BOOTLOADER_NONE)
232239
set(check_targets mcuboot;${DEFAULT_IMAGE})
233240
set(dependency_targets ${SB_CONFIG_SOFTDEVICE_FILE})
234241
set(production_targets mcuboot;${DEFAULT_IMAGE})
235242
set(production_files)
236243

237-
if(NOT DEFINED SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
244+
if(NOT SB_CONFIG_BM_FIRMWARE_LOADER_NONE)
238245
list(APPEND check_targets installer)
239246
list(APPEND check_targets ${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME})
240247
list(APPEND production_targets ${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME})
241248
endif()
242249

250+
if(SB_CONFIG_BM_BOOT_BOOTCONF_LOCK_WRITES)
251+
list(APPEND check_targets bootconf)
252+
list(APPEND dependency_targets bootconf)
253+
list(APPEND production_targets bootconf)
254+
endif()
255+
243256
foreach(image ${check_targets})
244-
sysbuild_get(${image}_kernel_bin_name IMAGE ${image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG)
245257
sysbuild_get(${image}_binary_dir IMAGE ${image} VAR APPLICATION_BINARY_DIR CACHE)
246258

247259
list(APPEND dependency_targets
248260
${image}_extra_byproducts
249261
${${image}_binary_dir}/zephyr/.config
250-
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}.bin
251262
)
252263

253-
if("${image}" STREQUAL "${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME}")
264+
if(NOT "${image}" STREQUAL "bootconf")
265+
sysbuild_get(${image}_kernel_bin_name IMAGE ${image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG)
266+
254267
list(APPEND dependency_targets
255-
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}.signed.bin
268+
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}.bin
256269
)
270+
271+
if("${image}" STREQUAL "${SB_CONFIG_BM_FIRMWARE_LOADER_IMAGE_NAME}")
272+
list(APPEND dependency_targets
273+
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}.signed.bin
274+
)
275+
endif()
257276
endif()
258277
endforeach()
259278

@@ -280,15 +299,24 @@ function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake)
280299
endif()
281300

282301
foreach(image ${production_targets})
283-
sysbuild_get(${image}_kernel_bin_name IMAGE ${image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG)
284302
sysbuild_get(${image}_binary_dir IMAGE ${image} VAR APPLICATION_BINARY_DIR CACHE)
285303

286-
if("${image}" STREQUAL "mcuboot")
304+
if("${image}" STREQUAL "bootconf")
287305
list(APPEND production_files
288-
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}_signed_softdevice_flash_metadata.hex)
306+
${${image}_binary_dir}/bootconf.hex
307+
)
289308
else()
290-
list(APPEND production_files
291-
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}.signed.hex)
309+
sysbuild_get(${image}_kernel_bin_name IMAGE ${image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG)
310+
311+
if("${image}" STREQUAL "mcuboot")
312+
list(APPEND production_files
313+
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}_signed_softdevice_flash_metadata.hex
314+
)
315+
else()
316+
list(APPEND production_files
317+
${${image}_binary_dir}/zephyr/${${image}_kernel_bin_name}.signed.hex
318+
)
319+
endif()
292320
endif()
293321
endforeach()
294322

sysbuild/Kconfig.bm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ config BM_BOOT_IMG_HASH_ALG_PURE
106106

107107
endchoice
108108

109+
config BM_BOOT_BOOTCONF_LOCK_WRITES
110+
bool "Protect bootloader's NVM from writes"
111+
depends on SOC_NRF54L15_CPUAPP || SOC_NRF54L10_CPUAPP || SOC_NRF54L05_CPUAPP
112+
help
113+
Sets RRAMC's BOOTCONF region protection to disable writes.
114+
109115
endmenu
110116

111117
endif # BM_BOOTLOADER_MCUBOOT

0 commit comments

Comments
 (0)