Skip to content

Commit

Permalink
storage/flash_map: Make flash_area.fa_dev_name optional
Browse files Browse the repository at this point in the history
With switch to compile time resolved device object and usage of
flash_area.fa_dev, the filed flash_area.fa_dev_name becomes optional
as there are no more device_get_binding calls within flash_map
that rely on that filed, or any other references to that field.

The added Kconfig option, FLASH_MAP_DEV_NAME_IN_FLASH_AREA, allows
to remove the flash_area.fa_dev_name field, when disabled.
The option is set to y by default to support external code that may
relay on the existence of flash_area.fa_dev_name.

Configurations for samples and tests that require the fa_dev_name
have been altered to have proper Kconfig options enabled.

Signed-off-by: Dominik Ermel <[email protected]>
  • Loading branch information
de-nordic committed Apr 2, 2021
1 parent 3ed48b1 commit 5b8d8eb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/storage/flash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ struct flash_area {
off_t fa_off;
/** Total size */
size_t fa_size;
#if defined(CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA)
/**
* Name of the flash device, suitable for passing to
* device_get_binding().
*/
const char *fa_dev_name;
#endif
#if defined(CONFIG_FLASH_MAP_DEV_IN_FLASH_AREA)
/**
* Pointer to device structure for the flash device.
Expand Down
1 change: 1 addition & 0 deletions subsys/settings/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ config SETTINGS_NVS
bool "NVS non-volatile storage support"
depends on NVS
depends on FLASH_MAP
depends on FLASH_MAP_DEV_NAME_IN_FLASH_AREA
help
Enables NVS storage support

Expand Down
24 changes: 24 additions & 0 deletions subsys/storage/flash_map/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ if FLASH_MAP
config FLASH_MAP_SHELL
bool "Enable flash map shell interface"
depends on SHELL
select FLASH_MAP_DEV_NAME_IN_FLASH_AREA
help
This enables shell commands to list and test flash maps.
The option depends on FLASH_MAP_DEV_NAME_IN_FLASH_AREA being selected, even when
FLASH_MAP_DEV_IN_FLASH_AREA is enabled, to be able to list names of devices tied to
flash areas, as the names need to be accessible from flash_area structure.

config FLASH_MAP_DEV_IN_FLASH_AREA
bool "Switch flash map to use compile time evaluated devices objects"
Expand All @@ -36,6 +40,26 @@ config FLASH_MAP_DEV_IN_FLASH_AREA
custom map populates the flash_area.fa_dev areas you may want to set this option to
improve flash map performance.

if FLASH_MAP_DEV_IN_FLASH_AREA
config FLASH_MAP_DEV_NAME_IN_FLASH_AREA
bool "Keep fa_dev_name filed to flash_area structure"
default y
help
The options allows storage of string name of flash device that is tied to the flash area
record. This may be useful when device_get_binding is used for obtaining device object
for the flash_area or when in need to have such information at run-time.
The flash map does not use flash_area.fa_dev_name internally when
FLASH_MAP_USE_DEV_IN_FLASH_AREA is enabled, and in such case, unless used by other code,
this can be safely disabled and will reduce size of flash_area structure by size of
a pointer.
endif

if !FLASH_MAP_DEV_IN_FLASH_AREA
config FLASH_MAP_DEV_NAME_IN_FLASH_AREA
bool
default y
endif

config FLASH_MAP_CUSTOM
bool "Custom flash map description"
help
Expand Down
5 changes: 4 additions & 1 deletion subsys/storage/flash_map/flash_map_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#define FLASH_AREA_FOO(part) \
{.fa_id = DT_FIXED_PARTITION_ID(part), \
.fa_off = DT_REG_ADDR(part), \
.fa_dev_name = DT_LABEL(DT_MTD_FROM_FIXED_PARTITION(part)), \
COND_CODE_1(CONFIG_FLASH_MAP_DEV_NAME_IN_FLASH_AREA, \
(.fa_dev_name = DT_LABEL(DT_MTD_FROM_FIXED_PARTITION(part)),), \
() \
) \
COND_CODE_1(CONFIG_FLASH_MAP_DEV_IN_FLASH_AREA, \
(.fa_dev = DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(part)),), \
() \
Expand Down

0 comments on commit 5b8d8eb

Please sign in to comment.