Skip to content

Commit

Permalink
devicetree: Add DT_FIXED_PARTITION_ADDR macro
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
57300 authored and carlescufi committed Aug 7, 2023
1 parent 99599b5 commit e28cbb3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions include/zephyr/devicetree/fixed-partitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,42 @@ extern "C" {
COND_CODE_1(DT_NODE_EXISTS(DT_MEM_FROM_FIXED_PARTITION(node_id)), \
(DT_PARENT(DT_MEM_FROM_FIXED_PARTITION(node_id))), (DT_GPARENT(node_id)))

/**
* @brief Get the absolute address of a fixed partition
*
* Example devicetree fragment:
*
* &flash_controller {
* flash@1000000 {
* compatible = "soc-nv-flash";
* partitions {
* compatible = "fixed-partitions";
* storage_partition: partition@3a000 {
* label = "storage";
* };
* };
* };
* };
*
* Here, the "storage" partition is seen to belong to flash memory
* starting at address 0x1000000. The partition's unit address of
* 0x3a000 represents an offset inside that flash memory.
*
* Example usage:
*
* DT_FIXED_PARTITION_ADDR(DT_NODELABEL(storage_partition)) // 0x103a000
*
* This macro can only be used with partitions 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-partitions child node
* @return the partition's offset plus the base address of the flash
* node containing it.
*/
#define DT_FIXED_PARTITION_ADDR(node_id) \
(DT_REG_ADDR(DT_MEM_FROM_FIXED_PARTITION(node_id)) + DT_REG_ADDR(node_id))

/**
* @}
*/
Expand Down

0 comments on commit e28cbb3

Please sign in to comment.