devicetree: flash-partitions: expose helper macros
Make generally available the macro that provides the flash device in which a particular partition can be found. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
ba24cd2f0f
commit
e571c88565
3 changed files with 36 additions and 13 deletions
|
@ -317,6 +317,27 @@
|
||||||
*/
|
*/
|
||||||
#define DT_PARENT(node_id) UTIL_CAT(node_id, _PARENT)
|
#define DT_PARENT(node_id) UTIL_CAT(node_id, _PARENT)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get a node identifier for a grandparent node
|
||||||
|
*
|
||||||
|
* Example devicetree fragment:
|
||||||
|
*
|
||||||
|
* gparent: grandparent-node {
|
||||||
|
* parent: parent-node {
|
||||||
|
* child: child-node { ... }
|
||||||
|
* };
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* The following are equivalent ways to get the same node identifier:
|
||||||
|
*
|
||||||
|
* DT_GPARENT(DT_NODELABEL(child))
|
||||||
|
* DT_PARENT(DT_PARENT(DT_NODELABEL(child))
|
||||||
|
*
|
||||||
|
* @param node_id node identifier
|
||||||
|
* @return a node identifier for the node's parent's parent
|
||||||
|
*/
|
||||||
|
#define DT_GPARENT(node_id) DT_PARENT(DT_PARENT(node_id))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a node identifier for a child node
|
* @brief Get a node identifier for a child node
|
||||||
*
|
*
|
||||||
|
|
|
@ -68,6 +68,17 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
#define DT_FIXED_PARTITION_ID(node_id) DT_CAT(node_id, _PARTITION_ID)
|
#define DT_FIXED_PARTITION_ID(node_id) DT_CAT(node_id, _PARTITION_ID)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the node identifier of the flash device for a partition
|
||||||
|
* @param node_id node identifier for a fixed-partitions child node
|
||||||
|
* @return the node identifier of the memory technology device that
|
||||||
|
* contains the fixed-partitions node.
|
||||||
|
*/
|
||||||
|
#define DT_MTD_FROM_FIXED_PARTITION(node_id) \
|
||||||
|
COND_CODE_1(DT_NODE_HAS_COMPAT(DT_GPARENT(node_id), soc_nv_flash), \
|
||||||
|
(DT_PARENT(DT_GPARENT(node_id))), \
|
||||||
|
(DT_GPARENT(node_id)))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,19 +10,10 @@
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <storage/flash_map.h>
|
#include <storage/flash_map.h>
|
||||||
|
|
||||||
/* Get the grand parent of a node */
|
|
||||||
#define GPARENT(node_id) DT_PARENT(DT_PARENT(node_id))
|
|
||||||
|
|
||||||
/* return great-grandparent label if 'soc-nv-flash' else grandparent label */
|
|
||||||
#define DT_FLASH_DEV_FROM_PARTITION(part) \
|
|
||||||
DT_LABEL(COND_CODE_1(DT_NODE_HAS_COMPAT(GPARENT(part), soc_nv_flash), \
|
|
||||||
(DT_PARENT(GPARENT(part))), \
|
|
||||||
(GPARENT(part))))
|
|
||||||
|
|
||||||
#define FLASH_AREA_FOO(part) \
|
#define FLASH_AREA_FOO(part) \
|
||||||
{.fa_id = DT_FIXED_PARTITION_ID(part), \
|
{.fa_id = DT_FIXED_PARTITION_ID(part), \
|
||||||
.fa_off = DT_REG_ADDR(part), \
|
.fa_off = DT_REG_ADDR(part), \
|
||||||
.fa_dev_name = DT_FLASH_DEV_FROM_PARTITION(part), \
|
.fa_dev_name = DT_LABEL(DT_MTD_FROM_FIXED_PARTITION(part)), \
|
||||||
.fa_size = DT_REG_SIZE(part),},
|
.fa_size = DT_REG_SIZE(part),},
|
||||||
|
|
||||||
#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_FOO)
|
#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_FOO)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue