Skip to content

Commit

Permalink
subsys: storage: Add flash_map abstraction module
Browse files Browse the repository at this point in the history
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
nvlsianpu authored and Anas Nashif committed Jan 15, 2018
1 parent 4a713aa commit 25269fb
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 0 deletions.
90 changes: 90 additions & 0 deletions include/flash_map.h
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__ */
1 change: 1 addition & 0 deletions subsys/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ add_subdirectory_ifdef(CONFIG_MCUBOOT_IMG_MANAGER dfu)
add_subdirectory_ifdef(CONFIG_NET_BUF net)
add_subdirectory_ifdef(CONFIG_USB usb)
add_subdirectory(random)
add_subdirectory(storage)
2 changes: 2 additions & 0 deletions subsys/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ source "subsys/usb/Kconfig"
source "subsys/dfu/Kconfig"

source "subsys/random/Kconfig"

source "subsys/storage/Kconfig"
1 change: 1 addition & 0 deletions subsys/storage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory_ifdef(CONFIG_FLASH_MAP flash_map)
13 changes: 13 additions & 0 deletions subsys/storage/Kconfig
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
3 changes: 3 additions & 0 deletions subsys/storage/flash_map/CMakeLists.txt
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)

28 changes: 28 additions & 0 deletions subsys/storage/flash_map/Kconfig
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.
Loading

0 comments on commit 25269fb

Please sign in to comment.