nvs: initialize using layout from partition table

This commit is contained in:
Ivan Grokhotkov 2016-11-15 18:23:29 +08:00
parent 8ab4e11840
commit 51021b06f8
2 changed files with 24 additions and 18 deletions

View File

@ -18,24 +18,20 @@
extern "C" { extern "C" {
#endif #endif
/** Initialise NVS flash storage with default flash sector layout /**
* @brief Initialize NVS flash storage with layout given in the partition table.
Temporarily, this region is hardcoded as a 12KB (0x3000 byte) *
region starting at 36KB (0x9000 byte) offset in flash. * @return ESP_OK if storage was successfully initialized.
@return ESP_OK if flash was successfully initialised.
*/ */
esp_err_t nvs_flash_init(void); esp_err_t nvs_flash_init(void);
/** Initialise NVS flash storage with custom flash sector layout /**
* @brief Initialize NVS flash storage with custom flash sector layout
@param baseSector Flash sector (units of 4096 bytes) offset to start NVS. * @note Make sure specified sectors don't fall within ranges occupied
@param sectorCount Length (in flash sectors) of NVS region. * by other partitions.
* @param baseSector Flash sector (units of 4096 bytes) offset to start NVS
@return ESP_OK if flash was successfully initialised. * @param sectorCount Length (in flash sectors) of NVS region
* @return ESP_OK if flash was successfully initialized
@note Use this parameter if you're not using the options in menuconfig for
configuring flash layout & partition table.
*/ */
esp_err_t nvs_flash_init_custom(uint32_t baseSector, uint32_t sectorCount); esp_err_t nvs_flash_init_custom(uint32_t baseSector, uint32_t sectorCount);

View File

@ -16,6 +16,7 @@
#include "nvs_storage.hpp" #include "nvs_storage.hpp"
#include "intrusive_list.h" #include "intrusive_list.h"
#include "nvs_platform.hpp" #include "nvs_platform.hpp"
#include "esp_partition.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
@ -61,11 +62,20 @@ extern "C" void nvs_dump()
s_nvs_storage.debugDump(); s_nvs_storage.debugDump();
} }
#ifdef ESP_PLATFORM
extern "C" esp_err_t nvs_flash_init(void) extern "C" esp_err_t nvs_flash_init(void)
{ {
return nvs_flash_init_custom(9, 3); const esp_partition_t* partition = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
if (partition == NULL) {
return ESP_ERR_NOT_FOUND;
} }
return nvs_flash_init_custom(partition->address / SPI_FLASH_SEC_SIZE,
partition->size / SPI_FLASH_SEC_SIZE);
}
#endif
extern "C" esp_err_t nvs_flash_init_custom(uint32_t baseSector, uint32_t sectorCount) extern "C" esp_err_t nvs_flash_init_custom(uint32_t baseSector, uint32_t sectorCount)
{ {
Lock::init(); Lock::init();