Skip to content

Commit 5df93af

Browse files
nvlsianpucarlescufi
authored andcommitted
subsys: storage: flash_map: add API for check flash driver support
Some applications might want to check whether flash_areas binds to any flash drive in the system. It might be better to do that while sanity check at application start-up then while regular run process. Example of such application is the mcuboot. This patch introduce such API for checking whether device bindings were resolved properly during system startup. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 12c0244 commit 5df93af

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/flash_map.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ u8_t flash_area_align(const struct flash_area *fa);
7777
int flash_area_get_sectors(int fa_id, u32_t *count,
7878
struct flash_sector *sectors);
7979

80+
/**
81+
* Check whether given flash area has supporting flash driver
82+
* in the system.
83+
*
84+
* @param fa Flash area.
85+
*
86+
* @return 1 On success. -ENODEV if no driver match.
87+
*/
88+
int flash_area_has_driver(const struct flash_area *fa);
89+
8090
#ifdef __cplusplus
8191
}
8292
#endif

subsys/storage/flash_map/flash_map.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,15 @@ u8_t flash_area_align(const struct flash_area *fa)
264264
return flash_get_write_block_size(dev);
265265
}
266266

267+
int flash_area_has_driver(const struct flash_area *fa)
268+
{
269+
if (get_flash_dev_from_id(fa->fa_device_id) == NULL) {
270+
return -ENODEV;
271+
}
272+
273+
return 1;
274+
}
275+
267276
static int flash_map_init(struct device *dev)
268277
{
269278
unsigned int i;

0 commit comments

Comments
 (0)