settings: (NVS) fetch sector size from driver
NVS back-end initialization should fetch size of the flash erase blocks from the flash API instead of DT. This allows to work well when used storage partition is not located in embedded memory. NVS back-end sector multiplier configuration was set to 8K as DT value for native posix targets flash sector sizes is 1 B, while its flash driver supports 8k. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
53c688292a
commit
9ac3755612
3 changed files with 16 additions and 3 deletions
|
@ -133,14 +133,29 @@ int settings_backend_init(void)
|
|||
u16_t cnt = 0;
|
||||
size_t nvs_sector_size, nvs_size = 0;
|
||||
const struct flash_area *fa;
|
||||
struct flash_sector hw_flash_sector;
|
||||
u32_t sector_cnt = 1;
|
||||
|
||||
rc = flash_area_open(DT_FLASH_AREA_STORAGE_ID, &fa);
|
||||
if (rc) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = flash_area_get_sectors(DT_FLASH_AREA_STORAGE_ID, §or_cnt,
|
||||
&hw_flash_sector);
|
||||
if (rc == -ENODEV) {
|
||||
return rc;
|
||||
} else if (rc != 0 && rc != -ENOMEM) {
|
||||
k_panic();
|
||||
}
|
||||
|
||||
nvs_sector_size = CONFIG_SETTINGS_NVS_SECTOR_SIZE_MULT *
|
||||
DT_FLASH_ERASE_BLOCK_SIZE;
|
||||
hw_flash_sector.fs_size;
|
||||
|
||||
if (nvs_sector_size > UINT16_MAX) {
|
||||
return -EDOM;
|
||||
}
|
||||
|
||||
while (cnt < CONFIG_SETTINGS_NVS_SECTOR_COUNT) {
|
||||
nvs_size += nvs_sector_size;
|
||||
if (nvs_size > fa->fa_size) {
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
CONFIG_SETTINGS_NVS_SECTOR_SIZE_MULT=8192
|
|
@ -1 +0,0 @@
|
|||
CONFIG_SETTINGS_NVS_SECTOR_SIZE_MULT=8192
|
Loading…
Add table
Add a link
Reference in a new issue