Skip to content

Commit 90e7078

Browse files
tejlmandnashif
authored andcommitted
cmake: CMake devicetree related linker functions implemented
This commit introduces zephyr_linker_dts CMake functions for creation of linker scripts based on devicetree nodes. The linker devicetree functions supports the following features: - Configuration of memory sections based on devicetree nodes Overview of functions introduced with this commit: - zephyr_linker_dts_memory Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent a7d2fd9 commit 90e7078

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

cmake/extensions.cmake

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,6 +2979,77 @@ macro(zephyr_linker_memory_ifdef feature_toggle)
29792979
endif()
29802980
endmacro()
29812981

2982+
# Usage:
2983+
# zephyr_linker_dts_memory(NAME <name> PATH <path> FLAGS <flags>)
2984+
# zephyr_linker_dts_memory(NAME <name> NODELABEL <nodelabel> FLAGS <flags>)
2985+
# zephyr_linker_dts_memory(NAME <name> CHOSEN <prop> FLAGS <flags>)
2986+
#
2987+
# Zephyr linker devicetree memory.
2988+
# This function specifies a memory region for the platform in use based on its
2989+
# devicetree configuration.
2990+
#
2991+
# The memory will only be defined if the devicetree node or a devicetree node
2992+
# matching the nodelabel exists and has status okay.
2993+
#
2994+
# Only one of PATH, NODELABEL, and CHOSEN parameters may be given.
2995+
#
2996+
# NAME <name> : Name of the memory region, for example FLASH.
2997+
# PATH <path> : Devicetree node identifier.
2998+
# NODELABEL <label>: Node label
2999+
# CHOSEN <prop> : Chosen property, add memory section described by the
3000+
# /chosen property if it exists.
3001+
# FLAGS <flags> : Flags describing properties of the memory region.
3002+
# Currently supported:
3003+
# r: Read-only region
3004+
# w: Read-write region
3005+
# x: Executable region
3006+
# The flags r and x, or w and x may be combined like: rx, wx.
3007+
#
3008+
function(zephyr_linker_dts_memory)
3009+
set(single_args "CHOSEN;FLAGS;NAME;PATH;NODELABEL")
3010+
cmake_parse_arguments(DTS_MEMORY "" "${single_args}" "" ${ARGN})
3011+
3012+
if(DTS_MEMORY_UNPARSED_ARGUMENTS)
3013+
message(FATAL_ERROR "zephyr_linker_dts_memory(${ARGV0} ...) given unknown "
3014+
"arguments: ${DTS_MEMORY_UNPARSED_ARGUMENTS}"
3015+
)
3016+
endif()
3017+
3018+
if((DEFINED DTS_MEMORY_PATH AND (DEFINED DTS_MEMORY_NODELABEL OR DEFINED DTS_MEMORY_CHOSEN))
3019+
OR (DEFINED DTS_MEMORY_NODELABEL AND DEFINED DTS_MEMORY_CHOSEN))
3020+
message(FATAL_ERROR "zephyr_linker_dts_memory(${ARGV0} ...), only one of "
3021+
"PATH, NODELABEL, and CHOSEN is allowed."
3022+
)
3023+
endif()
3024+
3025+
if(DEFINED DTS_MEMORY_NODELABEL)
3026+
dt_nodelabel(DTS_MEMORY_PATH NODELABEL ${DTS_MEMORY_NODELABEL})
3027+
endif()
3028+
3029+
if(DEFINED DTS_MEMORY_CHOSEN)
3030+
dt_chosen(DTS_MEMORY_PATH PROPERTY ${DTS_MEMORY_CHOSEN})
3031+
endif()
3032+
3033+
if(NOT DEFINED DTS_MEMORY_PATH)
3034+
return()
3035+
endif()
3036+
3037+
dt_node_exists(exists PATH ${DTS_MEMORY_PATH})
3038+
if(NOT ${exists})
3039+
return()
3040+
endif()
3041+
3042+
dt_reg_addr(addr PATH ${DTS_MEMORY_PATH})
3043+
dt_reg_size(size PATH ${DTS_MEMORY_PATH})
3044+
3045+
zephyr_linker_memory(
3046+
NAME ${DTS_MEMORY_NAME}
3047+
START ${addr}
3048+
SIZE ${size}
3049+
FLAGS ${DTS_MEMORY_FLAGS}
3050+
)
3051+
endfunction()
3052+
29823053
# Usage:
29833054
# zephyr_linker_group(NAME <name> [VMA <region|group>] [LMA <region|group>])
29843055
# zephyr_linker_group(NAME <name> GROUP <group>)

0 commit comments

Comments
 (0)