Skip to content

Commit

Permalink
cmake: extensions: Check status of "zephyr,memory-region" DT nodes
Browse files Browse the repository at this point in the history
Functions `zephyr_linker_dts_memory()` and `zephyr_linker_dts_section()`
are described as defining a memory region or section based on a DT node,
as long as it "exists and has status okay". However, only the existence
of the node is actually checked, using `dt_node_exists()`. To fix that,
employ `dt_node_has_status()` instead, which can check both conditions.

The status check is important, because both functions require the given
DT node to contain a `zephyr,memory-region` property (not to be confused
with the compatible string). This property is required by the associated
binding as well, but required properties can be omitted from nodes which
don't have status "okay". In those cases, edtlib won't raise an error,
and neither should CMake, because those nodes should be ignored.

Speaking of that property, add a missing error check for it as a bonus
(tucked behind the status check, of course).

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
  • Loading branch information
57300 committed Oct 9, 2023
1 parent f666b90 commit 87e7931
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmake/modules/extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4049,8 +4049,8 @@ function(zephyr_linker_dts_section)
)
endif()

dt_node_exists(exists PATH ${DTS_SECTION_PATH})
if(NOT ${exists})
dt_node_has_status(okay PATH ${DTS_SECTION_PATH} STATUS okay)
if(NOT ${okay})
return()
endif()

Expand Down Expand Up @@ -4122,14 +4122,19 @@ function(zephyr_linker_dts_memory)
return()
endif()

dt_node_exists(exists PATH ${DTS_MEMORY_PATH})
if(NOT ${exists})
dt_node_has_status(okay PATH ${DTS_MEMORY_PATH} STATUS okay)
if(NOT ${okay})
return()
endif()

dt_reg_addr(addr PATH ${DTS_MEMORY_PATH})
dt_reg_size(size PATH ${DTS_MEMORY_PATH})
dt_prop(name PATH ${DTS_MEMORY_PATH} PROPERTY "zephyr,memory-region")
if(NOT DEFINED name)
message(FATAL_ERROR "zephyr_linker_dts_memory(${ARGV0} ...) missing "
"\"zephyr,memory-region\" property"
)
endif()
zephyr_string(SANITIZE name ${name})

zephyr_linker_memory(
Expand Down

0 comments on commit 87e7931

Please sign in to comment.