From 624e051372167ea13acf0efa7447f6ee840eefb0 Mon Sep 17 00:00:00 2001 From: TOKITA Hiroshi Date: Sat, 15 Jun 2024 11:16:38 +0900 Subject: [PATCH] linker: devicetree_regions: Add support memory region flag setting Add `zephyr,memory-region-flags` for supporting memory region flags setting. For example, when the below node is in the devicetree, ``` test_sram: sram@20010000 { compatible = "zephyr,memory-region", "mmio-sram"; reg = < 0x20010000 0x1000 >; zephyr,memory-region = "FOOBAR"; zephyr,memory-region-flags = "rw"; }; ``` We get the following line in MEMORY section of linker script. ``` FOOBAR (rw) : ORIGIN = (0x20010000), LENGTH = (0x1000) ``` Signed-off-by: TOKITA Hiroshi --- cmake/linker_script/arm/linker.cmake | 3 +- cmake/modules/extensions.cmake | 61 +++++++++++------- dts/bindings/base/zephyr,memory-common.yaml | 7 +++ include/zephyr/linker/devicetree_regions.h | 70 +++++++++++++++++++-- 4 files changed, 112 insertions(+), 29 deletions(-) diff --git a/cmake/linker_script/arm/linker.cmake b/cmake/linker_script/arm/linker.cmake index bb501a16cdb..ad639f373cc 100644 --- a/cmake/linker_script/arm/linker.cmake +++ b/cmake/linker_script/arm/linker.cmake @@ -41,10 +41,9 @@ zephyr_linker_memory(NAME FLASH FLAGS rx START ${FLASH_ADDR} SIZE ${FLASH_SIZ zephyr_linker_memory(NAME RAM FLAGS wx START ${RAM_ADDR} SIZE ${RAM_SIZE}) zephyr_linker_memory(NAME IDT_LIST FLAGS wx START ${IDT_ADDR} SIZE 2K) -# Only use 'rw' as FLAGS. It's not used anyway. dt_comp_path(paths COMPATIBLE "zephyr,memory-region") foreach(path IN LISTS paths) - zephyr_linker_dts_memory(PATH ${path} FLAGS rw) + zephyr_linker_dts_memory(PATH ${path}) endforeach() if(CONFIG_XIP) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index b91566024ef..ab1f6f59cda 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -4633,7 +4633,7 @@ function(zephyr_linker) endfunction() # Usage: -# zephyr_linker_memory(NAME START
SIZE FLAGS ) +# zephyr_linker_memory(NAME START
SIZE [FLAGS ]) # # Zephyr linker memory. # This function specifies a memory region for the platform in use. @@ -4650,14 +4650,18 @@ endfunction() # All the following are valid values: # 1048576, 0x10000, 1024k, 1024K, 1m, and 1M. # FLAGS : Flags describing properties of the memory region. -# Currently supported: # r: Read-only region # w: Read-write region # x: Executable region -# The flags r and x, or w and x may be combined like: rx, wx. +# a: Allocatable region +# i: Initialized region +# l: Same as ā€˜i’ +# !: Invert the sense of any of the attributes that follow +# The flags may be combined like: rx, rx!w. function(zephyr_linker_memory) - set(single_args "FLAGS;NAME;SIZE;START") - cmake_parse_arguments(MEMORY "" "${single_args}" "" ${ARGN}) + set(req_single_args "NAME;SIZE;START") + set(single_args "FLAGS") + cmake_parse_arguments(MEMORY "" "${req_single_args};${single_args}" "" ${ARGN}) if(MEMORY_UNPARSED_ARGUMENTS) message(FATAL_ERROR "zephyr_linker_memory(${ARGV0} ...) given unknown " @@ -4665,7 +4669,7 @@ function(zephyr_linker_memory) ) endif() - foreach(arg ${single_args}) + foreach(arg ${req_single_args}) if(NOT DEFINED MEMORY_${arg}) message(FATAL_ERROR "zephyr_linker_memory(${ARGV0} ...) missing required " "argument: ${arg}" @@ -4674,6 +4678,7 @@ function(zephyr_linker_memory) endforeach() set(MEMORY) + zephyr_linker_arg_val_list(MEMORY "${req_single_args}") zephyr_linker_arg_val_list(MEMORY "${single_args}") string(REPLACE ";" "\;" MEMORY "${MEMORY}") @@ -4683,7 +4688,7 @@ function(zephyr_linker_memory) endfunction() # Usage: -# zephyr_linker_memory_ifdef( NAME START
SIZE FLAGS ) +# zephyr_linker_memory_ifdef( NAME START
SIZE [FLAGS ]) # # Will create memory region if is enabled. # @@ -4746,9 +4751,9 @@ function(zephyr_linker_dts_section) endfunction() # Usage: -# zephyr_linker_dts_memory(PATH FLAGS ) -# zephyr_linker_dts_memory(NODELABEL FLAGS ) -# zephyr_linker_dts_memory(CHOSEN FLAGS ) +# zephyr_linker_dts_memory(PATH ) +# zephyr_linker_dts_memory(NODELABEL ) +# zephyr_linker_dts_memory(CHOSEN ) # # Zephyr linker devicetree memory. # This function specifies a memory region for the platform in use based on its @@ -4763,15 +4768,9 @@ endfunction() # NODELABEL