reserved-memory: Introduce support for reserved-memory node
Introduce a set of header files to be able to define and declare sections and regions in the linker script. Introduce also DT helpers to retrieve data back. Signed-off-by: Carlo Caione <ccaione@baylibre.com>
This commit is contained in:
parent
f4db14f349
commit
ae2be2db8a
4 changed files with 226 additions and 0 deletions
59
include/linker/devicetree_reserved.h
Normal file
59
include/linker/devicetree_reserved.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Carlo Caione <ccaione@baylibre.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Generate memory regions and sections from reserved-memory nodes.
|
||||
*/
|
||||
|
||||
#include <devicetree.h>
|
||||
|
||||
/* Reserved memory node */
|
||||
#define _NODE_RESERVED DT_INST(0, reserved_memory)
|
||||
|
||||
/* Unquoted region label */
|
||||
#define _DT_LABEL_TOKEN(res) DT_STRING_TOKEN(res, label)
|
||||
|
||||
/* _start and _end section symbols */
|
||||
#define _DT_RESERVED_PREFIX(res) UTIL_CAT(__, _DT_LABEL_TOKEN(res))
|
||||
#define _DT_RESERVED_START(res) UTIL_CAT(_DT_RESERVED_PREFIX(res), _start)
|
||||
#define _DT_RESERVED_END(res) UTIL_CAT(_DT_RESERVED_PREFIX(res), _end)
|
||||
|
||||
/* Declare a reserved memory region */
|
||||
#define _RESERVED_REGION_DECLARE(res) DT_STRING_TOKEN(res, label) (rw) : \
|
||||
ORIGIN = DT_REG_ADDR(res), \
|
||||
LENGTH = DT_REG_SIZE(res)
|
||||
|
||||
/* Declare a reserved memory section */
|
||||
#define _RESERVED_SECTION_DECLARE(res) SECTION_DATA_PROLOGUE(_DT_LABEL_TOKEN(res), ,) \
|
||||
{ \
|
||||
_DT_RESERVED_START(res) = .; \
|
||||
KEEP(*(._DT_LABEL_TOKEN(res))) \
|
||||
KEEP(*(._DT_LABEL_TOKEN(res).*)) \
|
||||
_DT_RESERVED_END(res) = \
|
||||
_DT_RESERVED_START(res) + DT_REG_SIZE(res); \
|
||||
} GROUP_LINK_IN(_DT_LABEL_TOKEN(res))
|
||||
|
||||
/* Declare reserved memory linker symbols */
|
||||
#define _RESERVED_SYMBOL_DECLARE(res) extern char _DT_RESERVED_START(res)[]; \
|
||||
extern char _DT_RESERVED_END(res)[];
|
||||
|
||||
/* Apply a macro to a reserved memory region */
|
||||
#define _RESERVED_REGION_APPLY(f) \
|
||||
COND_CODE_1(IS_ENABLED(UTIL_CAT(_NODE_RESERVED, _EXISTS)), \
|
||||
(DT_FOREACH_CHILD(_NODE_RESERVED, f)), ())
|
||||
|
||||
/**
|
||||
* @brief Generate region definitions for all the reserved memory regions
|
||||
*/
|
||||
#define DT_RESERVED_MEM_REGIONS() _RESERVED_REGION_APPLY(_RESERVED_REGION_DECLARE)
|
||||
|
||||
/**
|
||||
* @brief Generate section definitions for all the reserved memory regions
|
||||
*/
|
||||
#define DT_RESERVED_MEM_SECTIONS() _RESERVED_REGION_APPLY(_RESERVED_SECTION_DECLARE)
|
||||
|
||||
/**
|
||||
* @brief Generate linker script symbols for all the reserved memory regions
|
||||
*/
|
||||
#define DT_RESERVED_MEM_SYMBOLS() _RESERVED_REGION_APPLY(_RESERVED_SYMBOL_DECLARE)
|
|
@ -33,6 +33,7 @@
|
|||
#ifdef ZTEST_UNITTEST
|
||||
#define DT_NODE_HAS_STATUS(node, status) 0
|
||||
#else
|
||||
#include <linker/devicetree_reserved.h>
|
||||
#include <devicetree.h>
|
||||
#endif
|
||||
|
||||
|
@ -213,6 +214,10 @@ extern char _image_rodata_size[];
|
|||
extern char _vector_start[];
|
||||
extern char _vector_end[];
|
||||
|
||||
#if DT_NODE_HAS_STATUS(_NODE_RESERVED, okay)
|
||||
DT_RESERVED_MEM_SYMBOLS()
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SW_VECTOR_RELAY
|
||||
extern char __vector_relay_table[];
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue