Skip to content
Closed
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: 2 additions & 2 deletions cmake/mcuboot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ function(zephyr_mcuboot_tasks)
dt_chosen(chosen_ram PROPERTY "zephyr,sram")
dt_reg_addr(chosen_ram_address PATH ${chosen_ram})
dt_nodelabel(slot0_partition NODELABEL "slot0_partition" REQUIRED)
dt_reg_addr(slot0_partition_address PATH ${slot0_partition})
dt_fixed_partition_addr(slot0_partition_address PATH ${slot0_partition})
dt_nodelabel(slot1_partition NODELABEL "slot1_partition" REQUIRED)
dt_reg_addr(slot1_partition_address PATH ${slot1_partition})
dt_fixed_partition_addr(slot1_partition_address PATH ${slot1_partition})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I present a complete failure showcase for this:

diff --git a/dts/vendor/nordic/nrf52840_partition.dtsi b/dts/vendor/nordic/nrf52840_partition.dtsi
index 1fa90a3ed71..fd51c151379 100644
--- a/dts/vendor/nordic/nrf52840_partition.dtsi
+++ b/dts/vendor/nordic/nrf52840_partition.dtsi
@@ -23,15 +23,24 @@
 			reg = <0x00000000 0x0000C000>;
 		};
 
-		slot0_partition: partition@c000 {
+                slot_partitions: partition@c000 {
+                        compatible = "fixed-subpartitions";
+                        label = "image-0";
+                        reg = <0x0000c000 0xec000>;
+                        ranges = <0x0 0xc000 0xec000>;
+                        #address-cells = <1>;
+                        #size-cells = <1>;
+
+		slot0_partition: partition@0 {
 			label = "image-0";
-			reg = <0x0000C000 0x00076000>;
+			reg = <0x00000000 0x00076000>;
 		};
 
-		slot1_partition: partition@82000 {
+		slot1_partition: partition@76000 {
 			label = "image-1";
-			reg = <0x00082000 0x00076000>;
+			reg = <0x00076000 0x00076000>;
 		};
+};
 
 		/*
 		 * The flash starting at 0x000f8000 and ending at

Build samples/subsys/mgmt/mcumgr/smp_svr for nrf52840dk/nrf52840 with -DFILE_SUFFIX="ram_load" and observe the huge error. The issue on your board has the correct solution described on #97413 (comment) you are not setting ranges and then declaring a child node has address 0, this means it starts at physical address 0x0, your DTS file is wrong

Copy link
Contributor Author

@JarmouniA JarmouniA Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+      ranges = <0x0 0x70000000 0x1000000>;
 
 	partitions { 

Ranges here has no effect on the individual partitions absolute address (seen in devicetree_generated.h), because I think the immediate childnode is partitions, not the the partition@x itself. Adding ranges = <.... inside partitions node gives build errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need both ranges, the one with addresses on the outside one and one without parameters on the partitions node

Copy link
Contributor Author

@JarmouniA JarmouniA Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if ranges takes care of this, why do DT_FIXED_PARTITION_ADDR and DT_FIXED_SUBPARTITION_ADDR macros exist!?


dt_prop(write_block_size PATH "${flash_node}" PROPERTY "write-block-size")
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD)
Expand Down
48 changes: 48 additions & 0 deletions cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4469,6 +4469,54 @@ function(dt_chosen var)
endif()
endfunction()

# Usage:
# dt_fixed_partition_addr(<var> PATH <partition_path> [TARGET <target>])
#
# Returns the absolute address of a fixed partition, i.e., the sum of the
# base address of the containing grand-parent node and the partition's offset.
#
# <var> : Return variable where the address value will be stored
# PATH <path> : Node path (partition node)
# TARGET <target>: Optional target to retrieve devicetree information from

function(dt_fixed_partition_addr var)
set(req_single_args "PATH")
set(single_args "TARGET")
cmake_parse_arguments(DT_FIXED_PART "" "${req_single_args};${single_args}" "" ${ARGN})

dt_target_internal(DT_FIXED_PART_TARGET)

foreach(arg ${req_single_args})
if(NOT DEFINED DT_FIXED_PART_${arg})
message(FATAL_ERROR "dt_fixed_partition_addr(${ARGV0} ...) missing required argument: ${arg}")
endif()
endforeach()

# Get canonical path of partition node
dt_path_internal(partition_canonical "${DT_FIXED_PART_PATH}" "${DT_FIXED_PART_TARGET}")

# Get grand-parent node
string(REGEX REPLACE "\/partitions\/partition@[0-9a-fA-F]+" "" partition_gparent "${partition_canonical}")

# Get grand-parent node address (base address)
get_target_property(gparent_addr_list "${DT_FIXED_PART_TARGET}" "DT_REG|${partition_gparent}|ADDR")
list(GET gparent_addr_list 0 gparent_addr)

# Get partition offset
get_target_property(partition_addr_list "${DT_FIXED_PART_TARGET}" "DT_REG|${partition_canonical}|ADDR")
list(GET partition_addr_list 0 partition_addr)

# If either address is missing, return undefined
if("${gparent_addr}" STREQUAL "NONE" OR "${partition_addr}" STREQUAL "NONE")
message(FATAL_ERROR "No partition DT addr or no grand-parent node's DT addr is found")
set(${var} PARENT_SCOPE)
return()
endif()

math(EXPR partition_abs_addr "${gparent_addr} + ${partition_addr}" OUTPUT_FORMAT HEXADECIMAL)
set(${var} ${partition_abs_addr} PARENT_SCOPE)
endfunction()

# Internal helper. Check that the CMake target named by variable 'var' is valid
# for use in other dt_* functions. If 'var' is undefined, set it to the default
# name of "devicetree_target", which is initialized in cmake/modules/dts.cmake.
Expand Down