forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subsys: storage: Add flash_map abstraction module
Introduce flas_map module is abstraction over flash memory and its driver for using flash memories along with description of available flash areas. Module provides simple API for write/read/erase and so one. Signed-off-by: Andrzej Puzdrowski <[email protected]>
- Loading branch information
Showing
13 changed files
with
586 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (c) 2017 Nordic Semiconductor ASA | ||
* Copyright (c) 2015 Runtime Inc | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef __FLASH_MAP_H__ | ||
#define __FLASH_MAP_H__ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* | ||
* Provides abstraction of flash regions for type of use. | ||
* I.e. dude where's my image? | ||
* | ||
* System will contain a map which contains flash areas. Every | ||
* region will contain flash identifier, offset within flash and length. | ||
* | ||
* 1. This system map could be in a file within filesystem (Initializer | ||
* must know/figure out where the filesystem is at). | ||
* 2. Map could be at fixed location for project (compiled to code) | ||
* 3. Map could be at specific place in flash (put in place at mfg time). | ||
* | ||
* Note that the map you use must be valid for BSP it's for, | ||
* match the linker scripts when platform executes from flash, | ||
* and match the target offset specified in download script. | ||
*/ | ||
#include <zephyr/types.h> | ||
#include <stddef.h> | ||
#include <sys/types.h> | ||
|
||
#define SOC_FLASH_0_ID 0 /* device_id for SoC flash memory driver */ | ||
#define SPI_FLASH_0_ID 1 /* device_id for external SPI flash driver */ | ||
|
||
struct flash_area { | ||
u8_t fa_id; | ||
u8_t fa_device_id; | ||
u16_t pad16; | ||
off_t fa_off; | ||
size_t fa_size; | ||
}; | ||
|
||
struct flash_sector { | ||
off_t fs_off; | ||
size_t fs_size; | ||
}; | ||
|
||
/* | ||
* Initializes flash map. Memory will be referenced by flash_map code | ||
* from this on. | ||
*/ | ||
void flash_map_init(void); | ||
|
||
/* | ||
* Start using flash area. | ||
*/ | ||
int flash_area_open(u8_t id, const struct flash_area **fa); | ||
|
||
void flash_area_close(const struct flash_area *fa); | ||
|
||
/* | ||
* Read/write/erase. Offset is relative from beginning of flash area. | ||
*/ | ||
int flash_area_read(const struct flash_area *fa, off_t off, void *dst, | ||
size_t len); | ||
int flash_area_write(const struct flash_area *fa, off_t off, const void *src, | ||
size_t len); | ||
int flash_area_erase(const struct flash_area *fa, off_t off, size_t len); | ||
/* int flash_area_is_empty(const struct flash_area *, bool *); */ | ||
|
||
/* | ||
* Alignment restriction for flash writes. | ||
*/ | ||
u8_t flash_area_align(const struct flash_area *fa); | ||
|
||
/* | ||
* Given flash area ID, return info about sectors within the area. | ||
*/ | ||
int flash_area_get_sectors(int fa_id, uint32_t *count, | ||
struct flash_sector *sectors); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __FLASH_MAP_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory_ifdef(CONFIG_FLASH_MAP flash_map) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Kconfig - Subsystem configuration options | ||
# | ||
# Copyright (c) 2018 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
|
||
menu "Storage" | ||
|
||
source "subsys/storage/flash_map/Kconfig" | ||
|
||
endmenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
zephyr_sources(flash_map.c) | ||
zephyr_sources_ifndef(CONFIG_FLASH_MAP_CUSTOM flash_map_default.c) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Kconfig - Flash map abstraction module | ||
# | ||
# Copyright (c) 2017 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
# | ||
# Flash map | ||
# | ||
|
||
menuconfig FLASH_MAP | ||
bool | ||
prompt "Flash map abstraction module" | ||
default n | ||
depends on FLASH | ||
help | ||
Enable support of flash map abstraction. | ||
|
||
config FLASH_MAP_CUSTOM | ||
bool | ||
prompt "Custom flash map description" | ||
default n | ||
depends on FLASH_MAP | ||
help | ||
This option enables custom flash map description. | ||
User must provide such a description in place of default on | ||
if had enabled this option. |
Oops, something went wrong.