Skip to content

Commit

Permalink
storage: flash_map: Don't generate flash area when no device
Browse files Browse the repository at this point in the history
Change in default flash map generation, where partitions hanging of
disabled devices will not have flash area generated.

Signed-off-by: Dominik Ermel <[email protected]>
  • Loading branch information
de-nordic authored and henrikbrixandersen committed Nov 21, 2024
1 parent bbfb546 commit 77ebf82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion subsys/storage/flash_map/flash_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int flash_area_open(uint8_t id, const struct flash_area **fap)
return -ENOENT;
}

if (!area->fa_dev || !device_is_ready(area->fa_dev)) {
if (!device_is_ready(area->fa_dev)) {
return -ENODEV;
}

Expand Down
10 changes: 7 additions & 3 deletions subsys/storage/flash_map/flash_map_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@
#define FLASH_AREA_FOO(part) \
{.fa_id = DT_FIXED_PARTITION_ID(part), \
.fa_off = DT_REG_ADDR(part), \
.fa_dev = DEVICE_DT_GET_OR_NULL(DT_MTD_FROM_FIXED_PARTITION(part)), \
.fa_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(part)), \
.fa_size = DT_REG_SIZE(part), \
.fa_label = DT_PROP_OR(part, label, NULL), },
#else
#define FLASH_AREA_FOO(part) \
{.fa_id = DT_FIXED_PARTITION_ID(part), \
.fa_off = DT_REG_ADDR(part), \
.fa_dev = DEVICE_DT_GET_OR_NULL(DT_MTD_FROM_FIXED_PARTITION(part)), \
.fa_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(part)), \
.fa_size = DT_REG_SIZE(part), },
#endif

#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_FOO)
#define FLASH_AREA_FOOO(part) \
COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(DT_MTD_FROM_FIXED_PARTITION(part)), \
(FLASH_AREA_FOO(part)), ())

#define FOREACH_PARTITION(n) DT_FOREACH_CHILD(DT_DRV_INST(n), FLASH_AREA_FOOO)

/* We iterate over all compatible 'fixed-partitions' nodes and
* use DT_FOREACH_CHILD to iterate over all the partitions for that
Expand Down
4 changes: 2 additions & 2 deletions tests/subsys/storage/flash_map/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ ZTEST(flash_map, test_flash_area_disabled_device)

/* Test that attempting to open a disabled flash area fails */
rc = flash_area_open(FIXED_PARTITION_ID(disabled_a), &fa);
zassert_equal(rc, -ENODEV, "Open did not fail");
zassert_equal(rc, -ENOENT, "Open did not fail");
rc = flash_area_open(FIXED_PARTITION_ID(disabled_b), &fa);
zassert_equal(rc, -ENODEV, "Open did not fail");
zassert_equal(rc, -ENOENT, "Open did not fail");
}

/**
Expand Down

0 comments on commit 77ebf82

Please sign in to comment.