1 /*
2  * Copyright (c) 2017-2021 Nordic Semiconductor ASA
3  * Copyright (c) 2015 Runtime Inc
4  * Copyright (c) 2017 Linaro Ltd
5  * Copyright (c) 2020 Gerson Fernando Budke <nandojve@gmail.com>
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 #ifndef ZEPHYR_SUBSYS_STORAGE_FLASH_MAP_PRIV_H_
11 #define ZEPHYR_SUBSYS_STORAGE_FLASH_MAP_PRIV_H_
12 
13 #include <zephyr/types.h>
14 #include <stddef.h>
15 #include <sys/types.h>
16 #include <zephyr/device.h>
17 
18 extern const struct flash_area *flash_map;
19 extern const int flash_map_entries;
20 
get_flash_area_from_id(int idx)21 static inline struct flash_area const *get_flash_area_from_id(int idx)
22 {
23 	for (int i = 0; i < flash_map_entries; i++) {
24 		if (flash_map[i].fa_id == idx) {
25 			return &flash_map[i];
26 		}
27 	}
28 
29 	return NULL;
30 }
31 
32 
is_in_flash_area_bounds(const struct flash_area * fa,off_t off,size_t len)33 static inline bool is_in_flash_area_bounds(const struct flash_area *fa,
34 					   off_t off, size_t len)
35 {
36 	return (off >= 0) && ((off + len) <= fa->fa_size);
37 }
38 
39 #endif /* ZEPHYR_SUBSYS_STORAGE_FLASH_MAP_PRIV_H_ */
40