Skip to content

Commit 516f7dc

Browse files
tomchynordicjm
authored andcommitted
bootloader_dts_utils: Align address macros
Align dt_partition_addr(..) function to handle all mapped partitions as well as (old) fixed-(sub)partitions. Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
1 parent 7c4cde6 commit 516f7dc

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

cmake/sysbuild/bootloader_dts_utils.cmake

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,47 @@ function(dt_partition_addr var)
8484
dt_reg_addr(dt_partition_offset PATH "${arg_DT_PARTITION_PATH}" TARGET
8585
"${arg_DT_PARTITION_TARGET}")
8686

87+
# Read compatible property to adjust the offset and address caluculation for subpartitions.
88+
dt_prop(partition_compat PATH "${arg_DT_PARTITION_PATH}" TARGET "${arg_DT_PARTITION_TARGET}"
89+
PROPERTY compatible)
90+
8791
# The partition parent should be either a fixed-partitions or a fixed-subpartitions node.
8892
set(dt_partition_parent "${arg_DT_PARTITION_PATH}")
8993
dt_get_parent(dt_partition_parent)
9094

91-
if("${dt_partition_parent}" IN_LIST fixed_subpartitions)
95+
if("${partition_compat}" STREQUAL "zephyr,mapped-partition")
96+
dt_prop(parent_compat PATH "${dt_partition_parent}" TARGET "${arg_DT_PARTITION_TARGET}"
97+
PROPERTY compatible)
98+
# Go up in the tree until the NVM memory controller is reached.
99+
while("${parent_compat}" STREQUAL "zephyr,mapped-partition")
100+
dt_get_parent(dt_partition_parent)
101+
dt_prop(parent_compat PATH "${dt_partition_parent}" TARGET "${arg_DT_PARTITION_TARGET}"
102+
PROPERTY compatible)
103+
endwhile()
104+
elseif("${dt_partition_parent}" IN_LIST fixed_subpartitions)
92105
# Get the parent of the subpartition node, which should be a fixed-partitions node.
93106
dt_get_parent(dt_partition_parent)
94107
elseif(NOT "${dt_partition_parent}" IN_LIST fixed_partitions)
95-
message(FATAL_ERROR "dt_partition_addr: Node is not a partition or subpartition: "
108+
message(FATAL_ERROR "dt_partition_addr: Node is not a (mapped) partition or subpartition: "
96109
"${arg_DT_PARTITION_PATH} in target: ${arg_DT_PARTITION_TARGET}")
97110
endif()
98111

99-
if(NOT arg_DT_PARTITION_ABSOLUTE)
100-
# A parent of the "fixed-partitions" node should be the memory controller.
112+
if("${partition_compat}" STREQUAL "zephyr,mapped-partition")
113+
if(NOT arg_DT_PARTITION_ABSOLUTE)
114+
# Skip the "partitions" node.
115+
dt_get_parent(dt_partition_parent)
116+
# A grandparent of the upmost "mapped-partition" node should be the memory controller.
117+
dt_reg_addr(mem_ctrl_addr PATH "${dt_partition_parent}" TARGET "${arg_DT_PARTITION_TARGET}")
118+
# Subtract the memory controller base address to get a relative address.
119+
math(EXPR dt_partition_offset "${dt_partition_offset} - ${mem_ctrl_addr}" OUTPUT_FORMAT
120+
HEXADECIMAL)
121+
endif()
122+
elseif(arg_DT_PARTITION_ABSOLUTE)
123+
# A parent of the "fixed-partitions" should be the memory controller.
101124
dt_get_parent(dt_partition_parent)
102125
# Add the memory controller base address to get an absolute address.
103126
dt_reg_addr(parent_addr PATH "${dt_partition_parent}" TARGET "${arg_DT_PARTITION_TARGET}")
104-
math(EXPR dt_partition_offset "${dt_partition_offset} - ${parent_addr}" OUTPUT_FORMAT
127+
math(EXPR dt_partition_offset "${dt_partition_offset} + ${parent_addr}" OUTPUT_FORMAT
105128
HEXADECIMAL)
106129
endif()
107130

0 commit comments

Comments
 (0)