sys/flash_map: Add flash_area_find_idx() function
This is an internal utility function that will simplify an upcoming
feature (inclusion of non-overlapping default flash areas).
const struct flash_area *flash_map;
int flash_map_entries;
-int
-flash_area_open(uint8_t id, const struct flash_area **fap)
+static int
+flash_area_find_idx(uint8_t id)
{
- const struct flash_area *area;
int i;
if (flash_map == NULL) {
- return SYS_EACCES;
+ return -1;
}
for (i = 0; i < flash_map_entries; i++) {
- area = flash_map + i;
- if (area->fa_id == id) {
- *fap = area;
- return 0;
+ if (flash_map[i].fa_id == id) {
+ return i;
}
}
+ return -1;
+}
+
+int
+flash_area_open(uint8_t id, const struct flash_area **fap)
+{
+ int idx;
+
+ if (flash_map == NULL) {
+ return SYS_EACCES;
+ }
+
+ idx = flash_area_find_idx(id);
+ if (idx == -1) {
return SYS_ENOENT;
}
+ *fap = &flash_map[idx];
+
+ return 0;
+}
+
int
flash_area_to_sectors(int id, int *cnt, struct flash_area *ret)
{
