Skip to content

Commit 5e9fea3

Browse files
committed
[nrf fromlist] devicetree: Fix ADDRESS macro for non-nv-flash
Currently the DT_FIXED_PARTITION_ADDR as well as DT_FIXED_SUBPARTITION_ADDR works only for partitions under the soc,nv-flash -compatible nodes. This commit adds a conditional expression, so the macro covers all types of partitions. Upstream PR #: 96808 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 2b25237 commit 5e9fea3

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

include/zephyr/devicetree/fixed-partitions.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ extern "C" {
131131
* node containing it.
132132
*/
133133
#define DT_FIXED_PARTITION_ADDR(node_id) \
134-
(DT_REG_ADDR(DT_MEM_FROM_FIXED_PARTITION(node_id)) + DT_REG_ADDR(node_id))
134+
(DT_REG_ADDR(node_id) + (DT_REG_ADDR(COND_CODE_1( \
135+
DT_NODE_EXISTS(DT_MEM_FROM_FIXED_PARTITION(node_id)), \
136+
(DT_MEM_FROM_FIXED_PARTITION(node_id)), (DT_GPARENT(node_id))))))
135137

136138
/**
137139
* @brief Test if fixed-subpartitions compatible node exists
@@ -207,7 +209,9 @@ extern "C" {
207209
* node containing it.
208210
*/
209211
#define DT_FIXED_SUBPARTITION_ADDR(node_id) \
210-
(DT_REG_ADDR(DT_MEM_FROM_FIXED_SUBPARTITION(node_id)) + DT_REG_ADDR(node_id))
212+
(DT_REG_ADDR(node_id) + (DT_REG_ADDR(COND_CODE_1( \
213+
DT_NODE_EXISTS(DT_MEM_FROM_FIXED_SUBPARTITION(node_id)), \
214+
(DT_MEM_FROM_FIXED_SUBPARTITION(node_id)), (DT_GPARENT(DT_PARENT(node_id)))))))
211215

212216
/**
213217
* @}

tests/lib/devicetree/api/src/main.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,13 +3271,7 @@ ZTEST(devicetree_api, test_fixed_partitions)
32713271
/* Test DT_FIXED_PARTITION_ADDR. */
32723272
zassert_equal(DT_FIXED_PARTITION_ADDR(TEST_PARTITION_0), 0x20000000);
32733273
zassert_equal(DT_FIXED_PARTITION_ADDR(TEST_PARTITION_1), 0x200000c0);
3274-
3275-
/* DT_FIXED_PARTITION_ADDR(TEST_PARTITION_2) expands to an invalid expression.
3276-
* Test this by way of string comparison.
3277-
*/
3278-
zassert_true(!strcmp(TO_STRING(DT_FIXED_PARTITION_ADDR(TEST_PARTITION_2)),
3279-
"(__REG_IDX_0_VAL_ADDRESSU + 458624U)"));
3280-
zassert_equal(DT_REG_ADDR(TEST_PARTITION_2), 458624);
3274+
zassert_equal(DT_FIXED_PARTITION_ADDR(TEST_PARTITION_2), 0x33291080);
32813275

32823276
/* Test that all DT_FIXED_PARTITION_ID are defined and unique. */
32833277
#define FIXED_PARTITION_ID_COMMA(node_id) DT_FIXED_PARTITION_ID(node_id),

0 commit comments

Comments
 (0)