devicetree: fixed-partition: Add sub-partition macros

Adds some macros for usage with sub-partitions

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2025-05-20 10:46:14 +01:00 committed by Dan Kalowsky
commit 656b6f37da

View file

@ -133,6 +133,82 @@ extern "C" {
#define DT_FIXED_PARTITION_ADDR(node_id) \
(DT_REG_ADDR(DT_MEM_FROM_FIXED_PARTITION(node_id)) + DT_REG_ADDR(node_id))
/**
* @brief Test if fixed-subpartitions compatible node exists
*
* @param node_id DTS node to test
* @return 1 if node exists and is fixed-subpartitions compatible, 0 otherwise.
*/
#define DT_FIXED_SUBPARTITION_EXISTS(node_id) \
DT_NODE_HAS_COMPAT(DT_PARENT(node_id), fixed_subpartitions)
/**
* @brief Get the node identifier of the flash memory for a subpartition
* @param node_id node identifier for a fixed-subpartitions child node
* @return the node identifier of the internal memory that contains the
* fixed-subpartitions node, or @ref DT_INVALID_NODE if it doesn't exist.
*/
#define DT_MEM_FROM_FIXED_SUBPARTITION(node_id) \
COND_CODE_1(DT_NODE_HAS_COMPAT(DT_GPARENT(DT_PARENT(node_id)), soc_nv_flash), \
(DT_GPARENT(DT_PARENT(node_id))), (DT_INVALID_NODE))
/**
* @brief Get the node identifier of the flash controller for a subpartition
* @param node_id node identifier for a fixed-subpartitions child node
* @return the node identifier of the memory technology device that
* contains the fixed-subpartitions node.
*/
#define DT_MTD_FROM_FIXED_SUBPARTITION(node_id) \
COND_CODE_1(DT_NODE_EXISTS(DT_MEM_FROM_FIXED_SUBPARTITION(node_id)), \
(DT_PARENT(DT_MEM_FROM_FIXED_SUBPARTITION(node_id))), (DT_GPARENT(node_id)))
/**
* @brief Get the absolute address of a fixed subpartition
*
* Example devicetree fragment:
*
* &flash_controller {
* flash@1000000 {
* compatible = "soc-nv-flash";
*
* partitions {
* compatible = "fixed-partitions";
*
* slot0_partition: partition@10000 {
* compatible = "fixed-subpartitions";
* reg = <0x00010000 0x40000>;
* ranges = <0x0 0x10000 0x40000>;
* #address-cells = <1>;
* #size-cells = <1>;
*
* storage_partition: partition@0 {
* label = "storage";
* reg = <0x00000000 0x40000>;
* };
* };
* };
* };
* };
*
* Here, the "storage" partition is seen to belong to flash memory
* starting at address 0x1000000. The partition's unit address of
* 0x10000 represents an offset inside that flash memory.
*
* Example usage:
*
* DT_FIXED_SUBPARTITION_ADDR(DT_NODELABEL(storage_partition)) // 0x1010000
*
* This macro can only be used with subpartitions of internal memory
* addressable by the CPU. Otherwise, it may produce a compile-time
* error, such as: `'__REG_IDX_0_VAL_ADDRESS' undeclared`.
*
* @param node_id node identifier for a fixed-subpartitions child node
* @return the subpartition's offset plus the base address of the flash
* node containing it.
*/
#define DT_FIXED_SUBPARTITION_ADDR(node_id) \
(DT_REG_ADDR(DT_MEM_FROM_FIXED_SUBPARTITION(node_id)) + DT_REG_ADDR(node_id))
/**
* @}
*/