Skip to content

Commit 99599b5

Browse files
57300carlescufi
authored andcommitted
devicetree: Add DT_MEM_FROM_FIXED_PARTITION macro
This is a new fixed-partitions API, which serves as a companion to the existing `DT_MTD_FROM_FIXED_PARTITION()`. In the following example: flash-controller@0 { compatible = "flash-controller"; flash@1000000 { compatible = "soc-nv-flash"; partitions { compatible = "fixed-partitions"; partition@3a000 {}; }; }; }; `DT_MTD_FROM_FIXED_PARTITION()` would let us map `partition@3a000` to `flash-controller@0`. Now, the new `DT_MEM_FROM_FIXED_PARTITION()` can let us retrieve the memory node (`flash@1000000`) as well, in a manner consistent with the existing API. Caution: if a fixed partition is not said to belong to a memory node, like in this alternative example: flash@0 { compatible = "spi-nor"; partitions { compatible = "fixed-partitions"; partition@0 {}; }; }; then `DT_MEM_FROM_FIXED_PARTITION()` will map `partition@0` to an invalid node identifier. This partition belongs to `flash@0`, which could be an MTD on a SPI bus. For consistency, the existing `DT_MTD_FROM_FIXED_PARTITION()` is now re- expressed in terms of the new `DT_MEM_FROM_FIXED_PARTITION()`. Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent a5895d6 commit 99599b5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

include/zephyr/devicetree/fixed-partitions.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,24 @@ extern "C" {
7878
#define DT_FIXED_PARTITION_ID(node_id) DT_CAT(node_id, _PARTITION_ID)
7979

8080
/**
81-
* @brief Get the node identifier of the flash device for a partition
81+
* @brief Get the node identifier of the flash memory for a partition
82+
* @param node_id node identifier for a fixed-partitions child node
83+
* @return the node identifier of the internal memory that contains the
84+
* fixed-partitions node, or @ref DT_INVALID_NODE if it doesn't exist.
85+
*/
86+
#define DT_MEM_FROM_FIXED_PARTITION(node_id) \
87+
COND_CODE_1(DT_NODE_HAS_COMPAT(DT_GPARENT(node_id), soc_nv_flash), (DT_GPARENT(node_id)), \
88+
(DT_INVALID_NODE))
89+
90+
/**
91+
* @brief Get the node identifier of the flash controller for a partition
8292
* @param node_id node identifier for a fixed-partitions child node
8393
* @return the node identifier of the memory technology device that
8494
* contains the fixed-partitions node.
8595
*/
86-
#define DT_MTD_FROM_FIXED_PARTITION(node_id) \
87-
COND_CODE_1(DT_NODE_HAS_COMPAT(DT_GPARENT(node_id), soc_nv_flash), \
88-
(DT_PARENT(DT_GPARENT(node_id))), \
89-
(DT_GPARENT(node_id)))
96+
#define DT_MTD_FROM_FIXED_PARTITION(node_id) \
97+
COND_CODE_1(DT_NODE_EXISTS(DT_MEM_FROM_FIXED_PARTITION(node_id)), \
98+
(DT_PARENT(DT_MEM_FROM_FIXED_PARTITION(node_id))), (DT_GPARENT(node_id)))
9099

91100
/**
92101
* @}

0 commit comments

Comments
 (0)