From 5df93af87aba2df3c1d6aaf951c5edcc59717aa8 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Mon, 6 Aug 2018 17:52:09 +0200 Subject: [PATCH] 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 --- include/flash_map.h | 10 ++++++++++ subsys/storage/flash_map/flash_map.c | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/include/flash_map.h b/include/flash_map.h index 752a43b5f86..170d3041769 100644 --- a/include/flash_map.h +++ b/include/flash_map.h @@ -77,6 +77,16 @@ u8_t flash_area_align(const struct flash_area *fa); int flash_area_get_sectors(int fa_id, u32_t *count, struct flash_sector *sectors); +/** + * Check whether given flash area has supporting flash driver + * in the system. + * + * @param fa Flash area. + * + * @return 1 On success. -ENODEV if no driver match. + */ +int flash_area_has_driver(const struct flash_area *fa); + #ifdef __cplusplus } #endif diff --git a/subsys/storage/flash_map/flash_map.c b/subsys/storage/flash_map/flash_map.c index 03d00eea751..0c87c43f352 100644 --- a/subsys/storage/flash_map/flash_map.c +++ b/subsys/storage/flash_map/flash_map.c @@ -264,6 +264,15 @@ u8_t flash_area_align(const struct flash_area *fa) return flash_get_write_block_size(dev); } +int flash_area_has_driver(const struct flash_area *fa) +{ + if (get_flash_dev_from_id(fa->fa_device_id) == NULL) { + return -ENODEV; + } + + return 1; +} + static int flash_map_init(struct device *dev) { unsigned int i;