|
7 | 7 | * Generate memory regions from devicetree nodes. |
8 | 8 | */ |
9 | 9 |
|
| 10 | +/** |
| 11 | + * @brief Get the linker memory-region name in a token form |
| 12 | + * |
| 13 | + * This attempts to use the zephyr,memory-region property (with |
| 14 | + * non-alphanumeric characters replaced with underscores) returning a token. |
| 15 | + * |
| 16 | + * Example devicetree fragment: |
| 17 | + * |
| 18 | + * @code{.dts} |
| 19 | + * / { |
| 20 | + * soc { |
| 21 | + * sram1: memory@2000000 { |
| 22 | + * zephyr,memory-region = "MY_NAME"; |
| 23 | + * }; |
| 24 | + * sram2: memory@2001000 { |
| 25 | + * zephyr,memory-region = "MY@OTHER@NAME"; |
| 26 | + * }; |
| 27 | + * }; |
| 28 | + * }; |
| 29 | + * @endcode |
| 30 | + * |
| 31 | + * Example usage: |
| 32 | + * |
| 33 | + * @code{.c} |
| 34 | + * LINKER_DT_NODE_REGION_NAME_TOKEN(DT_NODELABEL(sram1)) // MY_NAME |
| 35 | + * LINKER_DT_NODE_REGION_NAME_TOKEN(DT_NODELABEL(sram2)) // MY_OTHER_NAME |
| 36 | + * @endcode |
| 37 | + * |
| 38 | + * @param node_id node identifier |
| 39 | + * @return the name of the memory memory region the node will generate |
| 40 | + */ |
| 41 | +#define LINKER_DT_NODE_REGION_NAME_TOKEN(node_id) \ |
| 42 | + DT_STRING_TOKEN(node_id, zephyr_memory_region) |
| 43 | + |
10 | 44 | /** |
11 | 45 | * @brief Get the linker memory-region name |
12 | 46 | * |
|
15 | 49 | * |
16 | 50 | * Example devicetree fragment: |
17 | 51 | * |
| 52 | + * @code{.dts} |
18 | 53 | * / { |
19 | 54 | * soc { |
20 | 55 | * sram1: memory@2000000 { |
|
25 | 60 | * }; |
26 | 61 | * }; |
27 | 62 | * }; |
| 63 | + * @endcode |
28 | 64 | * |
29 | 65 | * Example usage: |
30 | 66 | * |
| 67 | + * @code{.c} |
31 | 68 | * LINKER_DT_NODE_REGION_NAME(DT_NODELABEL(sram1)) // "MY_NAME" |
32 | 69 | * LINKER_DT_NODE_REGION_NAME(DT_NODELABEL(sram2)) // "MY_OTHER_NAME" |
| 70 | + * @endcode |
33 | 71 | * |
34 | 72 | * @param node_id node identifier |
35 | 73 | * @return the name of the memory memory region the node will generate |
36 | 74 | */ |
37 | 75 | #define LINKER_DT_NODE_REGION_NAME(node_id) \ |
38 | | - DT_STRING_TOKEN(node_id, zephyr_memory_region) |
| 76 | + STRINGIFY(LINKER_DT_NODE_REGION_NAME_TOKEN(node_id)) |
39 | 77 |
|
40 | 78 | /** @cond INTERNAL_HIDDEN */ |
41 | 79 |
|
42 | 80 | #define _DT_COMPATIBLE zephyr_memory_region |
43 | 81 |
|
44 | | -#define _DT_SECTION_PREFIX(node_id) UTIL_CAT(__, LINKER_DT_NODE_REGION_NAME(node_id)) |
| 82 | +#define _DT_SECTION_PREFIX(node_id) UTIL_CAT(__, LINKER_DT_NODE_REGION_NAME_TOKEN(node_id)) |
45 | 83 | #define _DT_SECTION_START(node_id) UTIL_CAT(_DT_SECTION_PREFIX(node_id), _start) |
46 | 84 | #define _DT_SECTION_END(node_id) UTIL_CAT(_DT_SECTION_PREFIX(node_id), _end) |
47 | 85 | #define _DT_SECTION_SIZE(node_id) UTIL_CAT(_DT_SECTION_PREFIX(node_id), _size) |
|
50 | 88 | /** |
51 | 89 | * @brief Declare a memory region |
52 | 90 | * |
| 91 | + * Example devicetree fragment: |
| 92 | + * |
| 93 | + * @code{.dts} |
| 94 | + * test_sram: sram@20010000 { |
| 95 | + * compatible = "zephyr,memory-region", "mmio-sram"; |
| 96 | + * reg = < 0x20010000 0x1000 >; |
| 97 | + * zephyr,memory-region = "FOOBAR"; |
| 98 | + * }; |
| 99 | + * @endcode |
| 100 | + * |
| 101 | + * will result in: |
| 102 | + * |
| 103 | + * @code{.unparsed} |
| 104 | + * FOOBAR (rw) : ORIGIN = (0x20010000), LENGTH = (0x1000) |
| 105 | + * @endcode |
| 106 | + * |
53 | 107 | * @param node_id devicetree node identifier |
54 | 108 | * @param attr region attributes |
55 | 109 | */ |
56 | | -#define _REGION_DECLARE(node_id) \ |
57 | | - LINKER_DT_NODE_REGION_NAME(node_id) : \ |
58 | | - ORIGIN = DT_REG_ADDR(node_id), \ |
| 110 | +#define _REGION_DECLARE(node_id) \ |
| 111 | + LINKER_DT_NODE_REGION_NAME_TOKEN(node_id) : \ |
| 112 | + ORIGIN = DT_REG_ADDR(node_id), \ |
59 | 113 | LENGTH = DT_REG_SIZE(node_id) |
60 | 114 |
|
61 | 115 | /** |
62 | 116 | * @brief Declare a memory section from the device tree nodes with |
63 | 117 | * compatible 'zephyr,memory-region' |
64 | 118 | * |
| 119 | + * Example devicetree fragment: |
| 120 | + * |
| 121 | + * @code{.dts} |
| 122 | + * test_sram: sram@20010000 { |
| 123 | + * compatible = "zephyr,memory-region", "mmio-sram"; |
| 124 | + * reg = < 0x20010000 0x1000 >; |
| 125 | + * zephyr,memory-region = "FOOBAR"; |
| 126 | + * }; |
| 127 | + * @endcode |
| 128 | + * |
| 129 | + * will result in: |
| 130 | + * |
| 131 | + * @code{.unparsed} |
| 132 | + * FOOBAR 0x20010000 (NOLOAD) : |
| 133 | + * { |
| 134 | + * __FOOBAR_start = .; |
| 135 | + * KEEP(*(FOOBAR)) |
| 136 | + * KEEP(*(FOOBAR.*)) |
| 137 | + * __FOOBAR_end = .; |
| 138 | + * } > FOOBAR |
| 139 | + * __FOOBAR_size = __FOOBAR_end - __FOOBAR_start; |
| 140 | + * __FOOBAR_load_start = LOADADDR(FOOBAR); |
| 141 | + * @endcode |
| 142 | + * |
65 | 143 | * @param node_id devicetree node identifier |
66 | 144 | */ |
67 | 145 | #define _SECTION_DECLARE(node_id) \ |
68 | | - LINKER_DT_NODE_REGION_NAME(node_id) DT_REG_ADDR(node_id) (NOLOAD) : \ |
| 146 | + LINKER_DT_NODE_REGION_NAME_TOKEN(node_id) DT_REG_ADDR(node_id) (NOLOAD) : \ |
69 | 147 | { \ |
70 | 148 | _DT_SECTION_START(node_id) = .; \ |
71 | | - KEEP(*(LINKER_DT_NODE_REGION_NAME(node_id))) \ |
72 | | - KEEP(*(LINKER_DT_NODE_REGION_NAME(node_id).*)) \ |
| 149 | + KEEP(*(LINKER_DT_NODE_REGION_NAME_TOKEN(node_id))) \ |
| 150 | + KEEP(*(LINKER_DT_NODE_REGION_NAME_TOKEN(node_id).*)) \ |
73 | 151 | _DT_SECTION_END(node_id) = .; \ |
74 | | - } > LINKER_DT_NODE_REGION_NAME(node_id) \ |
| 152 | + } > LINKER_DT_NODE_REGION_NAME_TOKEN(node_id) \ |
75 | 153 | _DT_SECTION_SIZE(node_id) = _DT_SECTION_END(node_id) - _DT_SECTION_START(node_id); \ |
76 | | - _DT_SECTION_LOAD(node_id) = LOADADDR(LINKER_DT_NODE_REGION_NAME(node_id)); |
| 154 | + _DT_SECTION_LOAD(node_id) = LOADADDR(LINKER_DT_NODE_REGION_NAME_TOKEN(node_id)); |
77 | 155 |
|
78 | 156 | /** @endcond */ |
79 | 157 |
|
|
0 commit comments