Skip to content

Commit 7e8bb54

Browse files
committed
sysbuild: Add support for relocation pattern in nRF54H20
Update sdk-zephyr revision and enhance Kconfig handling. If the 'fw-to-relocate' chosen node exists, the firmware will: - automatically calculate the Load Memory Address (LMA) adjustment for firmware relocation. - Modified Kconfig handling in cmake modules to accommodate a new property "fw-to-relocate". - Ensured backward compatibility by falling back to "zephyr,code-partition" if ther is not property "fw-to-relocate". JIRA: NCSDK-36461 Signed-off-by: Jan Zyczkowski <[email protected]>
1 parent 2287cc7 commit 7e8bb54

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

cmake/modules/kconfig.cmake

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ if(CONFIG_NCS_IS_VARIANT_IMAGE)
2929
else()
3030
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake)
3131

32-
dt_chosen(code_partition PROPERTY "zephyr,code-partition")
32+
dt_chosen(code_partition PROPERTY "fw-to-relocate")
33+
if("${code_partition}" STREQUAL "")
34+
dt_chosen(code_partition PROPERTY "zephyr,code-partition")
35+
endif()
36+
3337
dt_partition_addr(code_partition_offset PATH "${code_partition}" REQUIRED)
3438
dt_reg_size(code_partition_size PATH "${code_partition}" REQUIRED)
3539

@@ -44,8 +48,24 @@ if(CONFIG_NCS_IS_VARIANT_IMAGE)
4448
# Additionally, convert primary slot dependencies to secondary slot dependencies.
4549
set(dotconfig_variant_content)
4650
foreach(line IN LISTS dotconfig_content)
51+
dt_chosen(fw_to_relocate_property PROPERTY "fw-to-relocate")
4752
if("${line}" MATCHES "^CONFIG_FLASH_LOAD_OFFSET=.*$")
48-
string(REGEX REPLACE "CONFIG_FLASH_LOAD_OFFSET=(.*)" "CONFIG_FLASH_LOAD_OFFSET=${code_partition_offset}" line ${line})
53+
# Change the CONFIG_FLASH_LOAD_OFFSET value only if the fw_to_relocate_property is empty - meaning that the firmware is not being relocated.
54+
if("${fw_to_relocate_property}" STREQUAL "")
55+
string(REGEX REPLACE "CONFIG_FLASH_LOAD_OFFSET=(.*)" "CONFIG_FLASH_LOAD_OFFSET=${code_partition_offset}" line ${line})
56+
endif()
57+
endif()
58+
59+
# Change the CONFIG_BUILD_OUTPUT_ADJUST_LMA value only if the fw_to_relocate_property is not empty - meaning that the firmware is being relocated.
60+
if(NOT "${fw_to_relocate_property}" STREQUAL "")
61+
if("${line}" MATCHES "^CONFIG_BUILD_OUTPUT_ADJUST_LMA=.*$")
62+
63+
dt_partition_addr(fw_to_relocate_offset ABSOLUTE PATH "${fw_to_relocate_property}" REQUIRED)
64+
dt_chosen(tcm_code_property PROPERTY "zephyr,code-partition")
65+
dt_reg_addr(tcm_code_addr PATH "${tcm_code_property}" REQUIRED)
66+
67+
string(REGEX REPLACE "CONFIG_BUILD_OUTPUT_ADJUST_LMA=(.*)" "CONFIG_BUILD_OUTPUT_ADJUST_LMA=${flash_base_addr}+${fw_to_relocate_offset}-${tcm_code_addr}" line ${line})
68+
endif()
4969
endif()
5070

5171
if("${line}" MATCHES "^CONFIG_FLASH_LOAD_SIZE=.*$")
@@ -62,7 +82,10 @@ if(CONFIG_NCS_IS_VARIANT_IMAGE)
6282
set(autoconf_variant_content)
6383
foreach(line IN LISTS autoconf_content)
6484
if("${line}" MATCHES "^#define CONFIG_FLASH_LOAD_OFFSET .*$")
65-
string(REGEX REPLACE "#define CONFIG_FLASH_LOAD_OFFSET (.*)" "#define CONFIG_FLASH_LOAD_OFFSET ${code_partition_offset}" line ${line})
85+
# Change the CONFIG_FLASH_LOAD_OFFSET value only if the fw_to_relocate_property is empty - meaning that the firmware is not being relocated.
86+
if("${fw_to_relocate_property}" STREQUAL "")
87+
string(REGEX REPLACE "#define CONFIG_FLASH_LOAD_OFFSET (.*)" "#define CONFIG_FLASH_LOAD_OFFSET ${code_partition_offset}" line ${line})
88+
endif()
6689
endif()
6790

6891
if("${line}" MATCHES "^#define CONFIG_FLASH_LOAD_SIZE .*$")

cmake/sysbuild/sign_nrf54h20.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function(check_merged_slot_boundaries merged_partition images)
2525
set(end_offset)
2626
sysbuild_get(start_offset IMAGE ${image} VAR CONFIG_ROM_START_OFFSET KCONFIG)
2727
sysbuild_get(end_offset IMAGE ${image} VAR CONFIG_ROM_END_OFFSET KCONFIG)
28-
dt_chosen(code_flash TARGET ${image} PROPERTY "zephyr,code-partition")
28+
dt_chosen(code_flash TARGET ${image} PROPERTY "fw-to-relocate")
29+
if("${code_flash}" STREQUAL "")
30+
dt_chosen(code_flash TARGET ${image} PROPERTY "zephyr,code-partition")
31+
endif()
32+
2933
dt_partition_addr(code_addr PATH "${code_flash}" TARGET ${image} REQUIRED ABSOLUTE)
3034
dt_reg_size(code_size TARGET ${image} PATH ${code_flash})
3135

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Nordic Semiconductor nRF54H MCU line
2+
3+
# Copyright (c) 2025 Nordic Semiconductor ASA
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
6+
if SOC_NRF54H20_CPURAD
7+
8+
rsource "Kconfig.defconfig.nrf54h20_cpurad"
9+
10+
endif # SOC_NRF54H20_CPURAD
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Nordic Semiconductor nRF54H20 Radio MCU
2+
3+
# Copyright (c) 2025 Nordic Semiconductor ASA
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
6+
if SOC_NRF54H20_CPURAD
7+
8+
# Support for firmware relocation pattern (load from MRAM, run from TCM)
9+
# If 'fw-to-relocate' chosen node exists, use it to calculate LMA adjustment
10+
# Otherwise, fall back to standard code-partition calculation
11+
DT_CHOSEN_FW_TO_RELOCATE = fw-to-relocate
12+
DT_CHOSEN_Z_CODE = zephyr,code-partition
13+
DT_CHOSEN_Z_SRAM = zephyr,sram
14+
15+
config BUILD_OUTPUT_ADJUST_LMA
16+
default "$(dt_chosen_partition_addr_hex,$(DT_CHOSEN_FW_TO_RELOCATE)) - \
17+
$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE))" \
18+
if "$(dt_chosen_enabled,$(DT_CHOSEN_FW_TO_RELOCATE))" = "y"
19+
20+
endif # SOC_NRF54H20_CPURAD

0 commit comments

Comments
 (0)