Skip to content

Commit 54435e0

Browse files
de-nordickartben
authored andcommitted
storage/flash_map: Add FIXED_PARTITION_BY_NODE macro
Macro allows to instantiate flash_area object pointer from DTS node. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 2672a3a commit 54435e0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/zephyr/storage/flash_map.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ uint8_t flash_area_erased_val(const struct flash_area *fa);
419419
* @return Pointer to flash_area type object representing partition
420420
*/
421421
#define FIXED_PARTITION(label) FIXED_PARTITION_1(DT_NODELABEL(label))
422+
423+
/**
424+
* Get pointer to flash_area object by partition node in DTS
425+
*
426+
* @param node DTS node of a partition
427+
*
428+
* @return Pointer to flash_area type object representing partition
429+
*/
430+
#define FIXED_PARTITION_BY_NODE(node) FIXED_PARTITION_1(node)
431+
422432
#define FIXED_PARTITION_1(node) FIXED_PARTITION_0(DT_DEP_ORD(node))
423433
#define FIXED_PARTITION_0(ord) \
424434
((const struct flash_area *)&DT_CAT(global_fixed_partition_ORD_, ord))

tests/subsys/storage/flash_map/src/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ ZTEST(flash_map, test_flash_area_disabled_device)
3030
zassert_equal(rc, -ENOENT, "Open did not fail");
3131
rc = flash_area_open(FIXED_PARTITION_ID(disabled_b), &fa);
3232
zassert_equal(rc, -ENOENT, "Open did not fail");
33+
34+
/* Note lack of tests for FIXED_PARTITION(...) instantiation,
35+
* because this macro will fail, at compile time, if node does not
36+
* exist or is disabled.
37+
*/
3338
}
3439

3540
ZTEST(flash_map, test_flash_area_device_is_ready)
@@ -143,6 +148,10 @@ ZTEST(flash_map, test_fixed_partition_node_macros)
143148
DT_REG_SIZE(SLOT1_PARTITION_NODE));
144149
zassert_equal(FIXED_PARTITION_NODE_DEVICE(SLOT1_PARTITION_NODE),
145150
DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(SLOT1_PARTITION_NODE)));
151+
152+
/* Taking by node and taking by label should give same device */
153+
zassert_equal(FIXED_PARTITION_BY_NODE(DT_NODELABEL(SLOT1_PARTITION)),
154+
FIXED_PARTITION(SLOT1_PARTITION));
146155
}
147156

148157
ZTEST(flash_map, test_flash_area_erase_and_flatten)

0 commit comments

Comments
 (0)