Merge branch 'bugfix/nvs_part_ptr_wrong_init_4.4' into 'release/v4.4'

bugfix (nvs_flash): Fix nvs_flash_init_partition_ptr (backport v4.4)

See merge request espressif/esp-idf!18672
This commit is contained in:
Zim Kalinowski 2022-08-24 17:06:53 +08:00
commit 72313054ad
2 changed files with 30 additions and 1 deletions

View File

@ -106,7 +106,7 @@ extern "C" esp_err_t nvs_flash_init_partition_ptr(const esp_partition_t *partiti
}
esp_err_t init_res = NVSPartitionManager::get_instance()->init_custom(part,
partition->address / SPI_FLASH_SEC_SIZE,
0,
partition->size / SPI_FLASH_SEC_SIZE);
if (init_res != ESP_OK) {

View File

@ -49,6 +49,35 @@ TEST_CASE("flash erase deinitializes initialized partition", "[nvs]")
nvs_flash_deinit();
}
TEST_CASE("nvs_flash_init_partition_ptr() works correctly", "[nvs]")
{
// First, open and write to partition using normal initialization
nvs_handle_t handle;
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
nvs_flash_erase();
err = nvs_flash_init();
}
TEST_ESP_OK(err);
TEST_ESP_OK(nvs_open("uninit_ns", NVS_READWRITE, &handle));
TEST_ESP_OK(nvs_set_i32(handle, "foo", 0x12345678));
nvs_close(handle);
nvs_flash_deinit();
// Then open and read using partition ptr initialization
const esp_partition_t* nvs_partition = esp_partition_find_first(
ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs");
TEST_ESP_OK(nvs_flash_init_partition_ptr(nvs_partition));
TEST_ESP_OK(nvs_open("uninit_ns", NVS_READWRITE, &handle));
int32_t foo = 0;
TEST_ESP_OK(nvs_get_i32(handle, "foo", &foo));
nvs_close(handle);
TEST_ASSERT_EQUAL_INT32(foo, 0x12345678);
nvs_flash_deinit();
}
// test could have different output on host tests
TEST_CASE("nvs deinit with open handle", "[nvs]")
{