Skip to content

Commit e28cbb3

Browse files
57300carlescufi
authored andcommitted
devicetree: Add DT_FIXED_PARTITION_ADDR macro
This convenience API returns the absolute address of a fixed partition, i.e., relative offset + base address. It's distinct from `DT_REG_ADDR()` and `FIXED_PARTITION_OFFSET()`, both of which return just the offset. The base address is taken from the parent memory node as given by the newly added `DT_MEM_FROM_FIXED_PARTITION()`. This is expected to ensure that the returned address is directly addressable by the CPU. This is also meant to prevent `DT_FIXED_PARTITION_ADDR()` from working with external memory partitions. Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent 99599b5 commit e28cbb3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

include/zephyr/devicetree/fixed-partitions.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,42 @@ extern "C" {
9797
COND_CODE_1(DT_NODE_EXISTS(DT_MEM_FROM_FIXED_PARTITION(node_id)), \
9898
(DT_PARENT(DT_MEM_FROM_FIXED_PARTITION(node_id))), (DT_GPARENT(node_id)))
9999

100+
/**
101+
* @brief Get the absolute address of a fixed partition
102+
*
103+
* Example devicetree fragment:
104+
*
105+
* &flash_controller {
106+
* flash@1000000 {
107+
* compatible = "soc-nv-flash";
108+
* partitions {
109+
* compatible = "fixed-partitions";
110+
* storage_partition: partition@3a000 {
111+
* label = "storage";
112+
* };
113+
* };
114+
* };
115+
* };
116+
*
117+
* Here, the "storage" partition is seen to belong to flash memory
118+
* starting at address 0x1000000. The partition's unit address of
119+
* 0x3a000 represents an offset inside that flash memory.
120+
*
121+
* Example usage:
122+
*
123+
* DT_FIXED_PARTITION_ADDR(DT_NODELABEL(storage_partition)) // 0x103a000
124+
*
125+
* This macro can only be used with partitions of internal memory
126+
* addressable by the CPU. Otherwise, it may produce a compile-time
127+
* error, such as: `'__REG_IDX_0_VAL_ADDRESS' undeclared`.
128+
*
129+
* @param node_id node identifier for a fixed-partitions child node
130+
* @return the partition's offset plus the base address of the flash
131+
* node containing it.
132+
*/
133+
#define DT_FIXED_PARTITION_ADDR(node_id) \
134+
(DT_REG_ADDR(DT_MEM_FROM_FIXED_PARTITION(node_id)) + DT_REG_ADDR(node_id))
135+
100136
/**
101137
* @}
102138
*/

0 commit comments

Comments
 (0)