Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmake/modules/kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ if(CONFIG_NCS_IS_VARIANT_IMAGE)

import_kconfig("CONFIG" ${DOTCONFIG})
else()
include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake)

dt_chosen(code_partition PROPERTY "zephyr,code-partition")
dt_reg_addr(code_partition_offset PATH "${code_partition}" REQUIRED)
dt_partition_addr(code_partition_offset PATH "${code_partition}" REQUIRED)
dt_reg_size(code_partition_size PATH "${code_partition}" REQUIRED)

set(preload_autoconf_h ${PRELOAD_BINARY_DIR}/zephyr/include/generated/zephyr/autoconf.h)
Expand Down
121 changes: 108 additions & 13 deletions cmake/sysbuild/bootloader_dts_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,115 @@
# data coming from the devicetree for configurations using
# a bootloader.

function(get_address_from_dt_partition_nodelabel label address)
dt_nodelabel(partition_node TARGET ${DEFAULT_IMAGE} NODELABEL ${label} REQUIRED)
dt_reg_addr(partition_offset TARGET ${DEFAULT_IMAGE} PATH ${partition_node})
function(dt_get_parent node)
string(FIND "${${node}}" "/" pos REVERSE)

if(pos EQUAL -1)
message(FATAL_ERROR "Unable to get parent of node: ${${node}}")
endif()

string(SUBSTRING "${${node}}" 0 ${pos} ${node})
set(${node} "${${node}}" PARENT_SCOPE)
endfunction()

# Usage:
# dt_partition_addr(<var> [LABEL <label>|PATH <path>] [TARGET <target>] [ABSOLUTE])
#
# Get the partition address, based on the path or label.
# The value will be returned in the <var> parameter.
# The returned address is either relative to the memory controller, or absolute if ABSOLUTE is
# specified.
#
# The <path> value may be any of these:
#
# - absolute path to a node, like '/foo/bar'
# - a node alias, like 'my-alias'
# - a node alias followed by a path to a child node, like 'my-alias/child-node'
#
# Results can be:
# - The base address of the register block
# - <var> will be undefined if node does not exists or does not have a register block at the
# requested index or with the requested name
#
# <var> : Return variable where the address value will be stored
# LABEL <label> : Node label
# PATH <path> : Node path
# TARGET <target>: Optional target to retrieve devicetree information from
# ABSOLUTE : Return absolute address rather than address relative to the memory controller
# REQUIRED : Generate a fatal error if the node is not found
function(dt_partition_addr var)
cmake_parse_arguments(arg_DT_PARTITION "ABSOLUTE;REQUIRED" "LABEL;PATH;TARGET" "" ${ARGN})

zephyr_check_arguments_required(${CMAKE_CURRENT_FUNCTION} arg_DT_PARTITION PATH LABEL)
zephyr_check_arguments_exclusive(${CMAKE_CURRENT_FUNCTION} arg_DT_PARTITION PATH LABEL)

if(NOT arg_DT_PARTITION_PATH)
# Calculate the partition path, based on the label.
dt_nodelabel(arg_DT_PARTITION_PATH NODELABEL "${arg_DT_PARTITION_LABEL}" TARGET
"${arg_DT_PARTITION_TARGET}")
if(NOT DEFINED arg_DT_PARTITION_PATH)
if(arg_DT_PARTITION_REQUIRED)
message(FATAL_ERROR "dt_partition_addr: Unable to find a node with label: "
"${arg_DT_PARTITION_LABEL} for target: ${arg_DT_PARTITION_TARGET}")
else()
set(${var} "${var}-NOTFOUND" PARENT_SCOPE)
return()
endif()
endif()
else()
# Check if a partition with the given path exists.
dt_node_exists(arg_DT_PARTITION_EXISTS PATH "${arg_DT_PARTITION_PATH}" TARGET
"${arg_DT_PARTITION_TARGET}")
if(NOT arg_DT_PARTITION_EXISTS)
if(arg_DT_PARTITION_REQUIRED)
message(FATAL_ERROR "dt_partition_addr: Unable to find a node with path: "
"${arg_DT_PARTITION_PATH} for target: ${arg_DT_PARTITION_TARGET}")
else()
set(${var} "${var}-NOTFOUND" PARENT_SCOPE)
return()
endif()
endif()
endif()

# Get the parent "two levels up" (../../) of the partition node
# This is the partition flash area node
string(REPLACE "/" ";" partition_node_split ${partition_node})
list(LENGTH partition_node_split child_path_length)
math(EXPR parent_path_length "${child_path_length} - 2")
list(SUBLIST partition_node_split 0 ${parent_path_length} parent_path_split)
string(REPLACE ";" "/" flash_area_node "${parent_path_split}")
# Get the list of partitions and subpartitions.
dt_comp_path(fixed_partitions COMPATIBLE "fixed-partitions" TARGET "${arg_DT_PARTITION_TARGET}")
dt_comp_path(fixed_subpartitions COMPATIBLE "fixed-subpartitions" TARGET
"${arg_DT_PARTITION_TARGET}")

dt_reg_addr(flash_area_addr TARGET ${DEFAULT_IMAGE} PATH ${flash_area_node})
# Read the partition offset.
dt_reg_addr(dt_partition_offset PATH "${arg_DT_PARTITION_PATH}" TARGET
"${arg_DT_PARTITION_TARGET}")

math(EXPR ${address} "${flash_area_addr} + ${partition_offset}")
set(${address} ${${address}} PARENT_SCOPE)
# The partition parent should be either a fixed-partitions or a fixed-subpartitions node.
set(dt_partition_parent "${arg_DT_PARTITION_PATH}")
dt_get_parent(dt_partition_parent)

if("${dt_partition_parent}" IN_LIST fixed_subpartitions)
# If the parent is a subpartition, add the parent partition address.
dt_reg_addr(parent_addr PATH "${dt_partition_parent}" TARGET "${arg_DT_PARTITION_TARGET}")
math(EXPR dt_partition_offset "${dt_partition_offset} + ${parent_addr}" OUTPUT_FORMAT
HEXADECIMAL)

# Get the parent of the subpartition node, which should be a fixed-partitions node.
dt_get_parent(dt_partition_parent)
elseif(NOT "${dt_partition_parent}" IN_LIST fixed_partitions)
message(FATAL_ERROR "dt_partition_addr: Node is not a partition or subpartition: "
"${arg_DT_PARTITION_PATH} in target: ${arg_DT_PARTITION_TARGET}")
endif()

if(NOT arg_DT_PARTITION_ABSOLUTE)
# A parent of the "fixed-partitions" node should be the memory controller.
dt_get_parent(dt_partition_parent)
# Add the memory controller base address to get an absolute address.
dt_reg_addr(parent_addr PATH "${dt_partition_parent}" TARGET "${arg_DT_PARTITION_TARGET}")
math(EXPR dt_partition_offset "${dt_partition_offset} + ${parent_addr}" OUTPUT_FORMAT
HEXADECIMAL)
endif()

set(${var} "${dt_partition_offset}" PARENT_SCOPE)
endfunction()

function(get_address_from_dt_partition_nodelabel label address)
dt_partition_addr(${address} LABEL "${label}" TARGET "${DEFAULT_IMAGE}" ABSOLUTE REQUIRED)
set(${address} "${${address}}" PARENT_SCOPE)
endfunction()
4 changes: 3 additions & 1 deletion cmake/sysbuild/image_signing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Since this file is brought in via include(), we do the work in a
# function to avoid polluting the top-level scope.

include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake)

function(zephyr_runner_file type path)
# Property magic which makes west flash choose the signed build
# output of a given type.
Expand Down Expand Up @@ -87,7 +89,7 @@ function(zephyr_mcuboot_tasks)
set(imgtool_rom_command)
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP_WITH_REVERT OR CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP)
dt_chosen(code_partition PROPERTY "zephyr,code-partition")
dt_reg_addr(code_partition_offset PATH "${code_partition}" REQUIRED)
dt_partition_addr(code_partition_offset PATH "${code_partition}" REQUIRED)
set(imgtool_rom_command --rom-fixed ${code_partition_offset})
endif()
set(imgtool_sign ${PYTHON_EXECUTABLE} ${IMGTOOL} sign --version ${CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION} --align ${write_block_size} --slot-size ${slot_size} --header-size ${CONFIG_ROM_START_OFFSET} ${imgtool_rom_command})
Expand Down
8 changes: 5 additions & 3 deletions cmake/sysbuild/sign_nrf54h20.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sysbuild/bootloader_dts_utils.cmake)

function(merge_images_nrf54h20 output_artifact images)
find_program(MERGEHEX mergehex.py HINTS ${ZEPHYR_BASE}/scripts/build/ NAMES
mergehex NAMES_PER_DIR)
Expand Down Expand Up @@ -177,10 +179,10 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)
dt_prop(write_block_size TARGET mcuboot PATH "${flash_node}" PROPERTY
"write-block-size")
dt_nodelabel(slot0_path TARGET mcuboot NODELABEL "slot0_partition" REQUIRED)
dt_reg_addr(slot0_addr TARGET mcuboot PATH ${slot0_path})
dt_partition_addr(slot0_addr PATH "${slot0_path}" TARGET mcuboot REQUIRED)
dt_reg_size(slot0_size TARGET mcuboot PATH ${slot0_path})
dt_nodelabel(slot1_path TARGET mcuboot NODELABEL "slot1_partition" REQUIRED)
dt_reg_addr(slot1_addr TARGET mcuboot PATH ${slot1_path})
dt_partition_addr(slot1_addr PATH "${slot1_path}" TARGET mcuboot REQUIRED)
dt_reg_size(slot1_size TARGET mcuboot PATH ${slot1_path})
if(NOT write_block_size)
set(write_block_size 4)
Expand All @@ -190,7 +192,7 @@ function(mcuboot_sign_merged_nrf54h20 merged_hex main_image)

# Fetch devicetree details for the active code partition.
dt_chosen(code_flash TARGET ${main_image} PROPERTY "zephyr,code-partition")
dt_reg_addr(code_addr TARGET ${main_image} PATH ${code_flash})
dt_partition_addr(code_addr PATH "${code_flash}" TARGET ${main_image} REQUIRED)
set(start_offset)
sysbuild_get(start_offset IMAGE ${main_image} VAR CONFIG_ROM_START_OFFSET
KCONFIG)
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ manifest:
# https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/modules.html
- name: zephyr
repo-path: sdk-zephyr
revision: e2ea7ff53ff6701c74be3da713c33d473c311aad
revision: d47f109210e74e2e9df3ab5485a32b8a34254caf
import:
# In addition to the zephyr repository itself, NCS also
# imports the contents of zephyr/west.yml at the above
Expand Down
Loading