]> granicus.if.org Git - esp-idf/commitdiff
nvs_flash: Version compatibility check for nvs storage
authorSagar Bijwe <sagar@espressif.com>
Wed, 25 Jul 2018 15:11:09 +0000 (20:41 +0530)
committerbot <bot@espressif.com>
Sun, 5 Aug 2018 00:00:56 +0000 (00:00 +0000)
This change adds a check for compatibility between the nvs version
found on nvs flash and the one assumed by running code during nvs
initialization. Any mismatch is reported to the user using new error
code ESP_ERR_NVS_NEW_VERSION_FOUND.

45 files changed:
components/driver/test/test_adc2.c
components/esp32/esp_err_to_name.c
components/esp32/test/test_esp32.c
components/nvs_flash/include/nvs.h
components/nvs_flash/src/nvs_page.cpp
components/nvs_flash/src/nvs_page.hpp
components/nvs_flash/test/test_nvs.c
components/nvs_flash/test_nvs_host/test_nvs.cpp
examples/bluetooth/a2dp_gatts_coex/main/main.c
examples/bluetooth/a2dp_sink/main/main.c
examples/bluetooth/a2dp_source/main/main.c
examples/bluetooth/ble_adv/main/app_bt.c
examples/bluetooth/ble_hid_device_demo/main/ble_hidd_demo_main.c
examples/bluetooth/ble_spp_server/main/ble_spp_server_demo.c
examples/bluetooth/ble_throughput/throughput_client/main/example_ble_client_throughput.c
examples/bluetooth/ble_throughput/throughput_server/main/example_ble_server_throughput.c
examples/bluetooth/blufi/main/blufi_example_main.c
examples/bluetooth/bt_discovery/main/bt_discovery.c
examples/bluetooth/bt_spp_acceptor/main/example_spp_acceptor_demo.c
examples/bluetooth/bt_spp_initiator/main/example_spp_initiator_demo.c
examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c
examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c
examples/bluetooth/controller_hci_uart/main/controller_hci_uart_demo.c
examples/bluetooth/gatt_client/main/gattc_demo.c
examples/bluetooth/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md
examples/bluetooth/gatt_security_client/main/example_ble_sec_gattc_demo.c
examples/bluetooth/gatt_security_server/main/example_ble_sec_gatts_demo.c
examples/bluetooth/gatt_server/main/gatts_demo.c
examples/bluetooth/gatt_server/tutorial/Gatt_Server_Example_Walkthrough.md
examples/bluetooth/gatt_server_service_table/main/gatts_table_creat_demo.c
examples/bluetooth/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md
examples/bluetooth/gattc_multi_connect/main/gattc_multi_connect.c
examples/protocols/aws_iot/subscribe_publish/main/subscribe_publish_sample.c
examples/protocols/aws_iot/thing_shadow/main/thing_shadow_sample.c
examples/protocols/esp_http_client/main/esp_http_client_example.c
examples/storage/nvs_rw_blob/main/nvs_blob_example_main.c
examples/storage/nvs_rw_value/main/nvs_value_example_main.c
examples/system/console/main/console_example_main.c
examples/system/ota/main/ota_example_main.c
examples/wifi/espnow/main/espnow_example_main.c
examples/wifi/iperf/main/main.c
examples/wifi/power_save/main/power_save.c
examples/wifi/scan/main/scan.c
examples/wifi/simple_wifi/main/simple_wifi.c
examples/wifi/wps/main/wps.c

index 815f5c79a9d75d40774fb83b81f1eed83b631889..ec6e2ff4f60bb23df4e4e5520a8d30f40293a11b 100644 (file)
@@ -56,8 +56,8 @@ TEST_CASE("adc2 work with wifi","[adc]")
     //init wifi
     printf("nvs init\n");
     esp_err_t r = nvs_flash_init();
-    if (r == ESP_ERR_NVS_NO_FREE_PAGES) {
-        printf("no free pages, erase..\n");
+    if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
+        printf("no free pages or nvs version mismatch, erase..\n");
         TEST_ESP_OK(nvs_flash_erase());
         r = nvs_flash_init();
     } 
index 49de0e56d46d581fe34b50e08f0a0d5eac4d2fa4..7b74704e01fd075fc0a64e4af9de4653d3d9fa03 100644 (file)
@@ -160,6 +160,11 @@ static const esp_err_msg_t esp_err_msg_table[] = {
 #   ifdef      ESP_ERR_NVS_PART_NOT_FOUND
     ERR_TBL_IT(ESP_ERR_NVS_PART_NOT_FOUND),                 /*  4367 0x110f Partition with specified name is not found
                                                                             in the partition table */
+#   endif
+#   ifdef      ESP_ERR_NVS_NEW_VERSION_FOUND
+    ERR_TBL_IT(ESP_ERR_NVS_NEW_VERSION_FOUND),              /*  4368 0x1110 NVS partition contains data in new format
+                                                                            and cannot be recognized by this version of
+                                                                            code */
 #   endif
     // components/ulp/include/esp32/ulp.h
 #   ifdef      ESP_ERR_ULP_BASE
index 0681660ff1ea30e0bc0dcfe673b513f0b3479bb4..cdca805df40692fda22c73466167ecd6df591744 100644 (file)
@@ -83,8 +83,8 @@ TEST_CASE("wifi stop and deinit","[wifi]")
     //init nvs
     ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
     esp_err_t r = nvs_flash_init();
-    if (r == ESP_ERR_NVS_NO_FREE_PAGES) {
-        ESP_LOGI(TAG, EMPH_STR("no free pages, erase.."));
+    if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
+        ESP_LOGI(TAG, EMPH_STR("no free pages or nvs version mismatch, erase.."));
         TEST_ESP_OK(nvs_flash_erase());
         r = nvs_flash_init();
     } 
index b3ba37fb4fc3cd4286f62a92163b2e7a45ef126b..44c6c7a2ca3a57a4bfa1dda14924ca040dfd64d1 100644 (file)
@@ -44,6 +44,7 @@ typedef uint32_t nvs_handle;
 #define ESP_ERR_NVS_NO_FREE_PAGES       (ESP_ERR_NVS_BASE + 0x0d)  /*!< NVS partition doesn't contain any empty pages. This may happen if NVS partition was truncated. Erase the whole partition and call nvs_flash_init again. */
 #define ESP_ERR_NVS_VALUE_TOO_LONG      (ESP_ERR_NVS_BASE + 0x0e)  /*!< String or blob length is longer than supported by the implementation */
 #define ESP_ERR_NVS_PART_NOT_FOUND      (ESP_ERR_NVS_BASE + 0x0f)  /*!< Partition with specified name is not found in the partition table */
+#define ESP_ERR_NVS_NEW_VERSION_FOUND   (ESP_ERR_NVS_BASE + 0x10)  /*!< NVS partition contains data in new format and cannot be recognized by this version of code */
 
 #define NVS_DEFAULT_PART_NAME           "nvs"   /*!< Default partition name of the NVS partition in the partition table */
 /**
index fb9cf3d40c404ae63ee7e035775be1bfe44239c1..73dabe8ea70f867232005f34fa68b14ed06d6d69 100644 (file)
@@ -64,6 +64,11 @@ esp_err_t Page::load(uint32_t sectorNumber)
     } else {
         mState = header.mState;
         mSeqNumber = header.mSeqNumber;
+        if(header.mVersion < NVS_VERSION) {
+            return ESP_ERR_NVS_NEW_VERSION_FOUND;
+        } else {
+            mVersion = header.mVersion;
+        }
     }
 
     switch (mState) {
@@ -633,6 +638,7 @@ esp_err_t Page::initialize()
     Header header;
     header.mState = mState;
     header.mSeqNumber = mSeqNumber;
+    header.mVersion = mVersion;
     header.mCrc32 = header.calculateCrc32();
 
     auto rc = spi_flash_write(mBaseAddress, &header, sizeof(header));
@@ -826,6 +832,15 @@ esp_err_t Page::setSeqNumber(uint32_t seqNumber)
     return ESP_OK;
 }
 
+esp_err_t Page::setVersion(uint8_t ver)
+{
+    if (mState != PageState::UNINITIALIZED) {
+        return ESP_ERR_NVS_INVALID_STATE;
+    }
+    mVersion = ver;
+    return ESP_OK;
+}
+
 esp_err_t Page::erase()
 {
     auto sector = mBaseAddress / SPI_FLASH_SEC_SIZE;
index f6f6a8ac6075dd1924ccda3c9bdc23e3d483086e..e98deb22f5c76762b4abb6809a8cbd17307d66a6 100644 (file)
@@ -87,6 +87,8 @@ public:
     esp_err_t getSeqNumber(uint32_t& seqNumber) const;
 
     esp_err_t setSeqNumber(uint32_t seqNumber);
+    esp_err_t setVersion(uint8_t version);
 
     esp_err_t writeItem(uint8_t nsIndex, ItemType datatype, const char* key, const void* data, size_t dataSize, uint8_t chunkIdx = CHUNK_ANY);
 
@@ -146,12 +148,13 @@ protected:
     public:
         Header()
         {
-            std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT32_MAX);
+            std::fill_n(mReserved, sizeof(mReserved)/sizeof(mReserved[0]), UINT8_MAX);
         }
 
         PageState mState;       // page state
         uint32_t mSeqNumber;    // sequence number of this page
-        uint32_t mReserved[5];  // unused, must be 0xffffffff
+        uint8_t mVersion;       // nvs format version
+        uint8_t mReserved[19];  // unused, must be 0xff
         uint32_t mCrc32;        // crc of everything except mState
 
         uint32_t calculateCrc32();
@@ -202,6 +205,7 @@ protected:
     uint32_t mBaseAddress = 0;
     PageState mState = PageState::INVALID;
     uint32_t mSeqNumber = UINT32_MAX;
+    uint8_t mVersion = NVS_VERSION;
     typedef CompressedEnumTable<EntryState, 2, ENTRY_COUNT> TEntryTable;
     TEntryTable mEntryTable;
     size_t mNextFreeEntry = INVALID_ENTRY;
index 32d5b2956a5fb3eb71ae1a5e830bc13e74b10898..8f4ba97c0e26c25081e32f418604ba8c32e51585 100644 (file)
@@ -16,7 +16,7 @@ TEST_CASE("various nvs tests", "[nvs]")
 {
     nvs_handle handle_1;
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_LOGW(TAG, "nvs_flash_init failed (0x%x), erasing partition and retrying", err);
         const esp_partition_t* nvs_partition = esp_partition_find_first(
                 ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
@@ -83,7 +83,7 @@ TEST_CASE("calculate used and free space", "[nvs]")
     TEST_ASSERT_TRUE(h_count_entries == 0);
 
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_LOGW(TAG, "nvs_flash_init failed (0x%x), erasing partition and retrying", err);
         const esp_partition_t* nvs_partition = esp_partition_find_first(
                 ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
index 4309f6d56118fe933b81d749285e762a3ddef4d8..411cb3ef82a7cd75d83db0a6ad017ae52c639ffa 100644 (file)
@@ -1710,6 +1710,20 @@ TEST_CASE("Check that orphaned blobs are erased during init", "[nvs]")
     TEST_ESP_OK(storage.writeItem(1, ItemType::BLOB, "key3", blob, sizeof(blob)));
 }
 
+
+TEST_CASE("Check for nvs version incompatibility", "[nvs]")
+{
+    SpiFlashEmulator emu(3);
+
+    int32_t val1 = 0x12345678;
+    Page p;
+    p.load(0);
+    TEST_ESP_OK(p.setVersion(Page::NVS_VERSION - 1));
+    TEST_ESP_OK(p.writeItem(1, ItemType::I32, "foo", &val1, sizeof(val1)));
+
+    TEST_ESP_ERR(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3), ESP_ERR_NVS_NEW_VERSION_FOUND);
+}
+
 TEST_CASE("Check that NVS supports old blob format without blob index", "[nvs]")
 {
     SpiFlashEmulator emu("../nvs_partition_generator/part_old_blob_format.bin");
index b57e4249c21f4d9e2d3ba2ad4bb560d93080febb..69e489930566cf6d137437ea32410b52e0b61a45 100644 (file)
@@ -636,7 +636,7 @@ void app_main()
 
     // Initialize NVS.
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
@@ -703,4 +703,4 @@ void app_main()
     bt_app_work_dispatch(bt_av_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
     //gatt server init
     ble_gatts_init();
-}
\ No newline at end of file
+}
index e4881b34002a4b4e78ed108857380de274ff5114..045672125bcf654f6fe0c48ec426315567a826d6 100644 (file)
@@ -46,7 +46,7 @@ void app_main()
 {
     /* Initialize NVS — it is used to store PHY calibration data */
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 602dc01d8ee771fd447f862ebf3a20b04cc7a625..3da55895f011146d20b895c4165cb74fa44dcf30 100644 (file)
@@ -100,7 +100,7 @@ void app_main()
 {
     // Initialize NVS.
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 246d87b3047f5dae268cafc8fc850a87c3d05219..0a67c32468f7fc35e8b10fd2fc8e0fa3b8a69b9d 100644 (file)
@@ -214,7 +214,7 @@ void app_main()
 {
     /* Initialize NVS — it is used to store PHY calibration data */
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 487b2723d7daff000cbf2fb9bfec53f051729625..3094f6bc7fe4a314fc8df1e8b5adc06332a3afe8 100644 (file)
@@ -265,7 +265,7 @@ void app_main()
 
     // Initialize NVS.
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 2da39c5fe8f13d56e0e26ee725fe84073781b0ab..999b047e7803b6419350e7170134932b3f07b01f 100644 (file)
@@ -655,7 +655,7 @@ void app_main()
 
     // Initialize NVS
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index fefb1236bec3cbd4bf0ce4bbf0fff0315767450d..56362cac62ee0afe333cb7f1bf9e07fe062b5887 100644 (file)
@@ -519,7 +519,7 @@ void app_main()
 {
     // Initialize NVS.
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index a1a416b06f2a2ed59b7973f4c864649279793ede..0b245ac676bf24faf1b20e22692575dbc8e06745 100644 (file)
@@ -641,7 +641,7 @@ void app_main()
 
     // Initialize NVS.
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 2ad02c198b69581d0c96c6c24ddee582cd608a30..bb046306e836ab4cb474d1be5867f7123d792937 100644 (file)
@@ -381,7 +381,7 @@ void app_main()
 
     // Initialize NVS
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 65671144392e1e01db3c293527b51dc2aa4c2c5c..ef2b11ef53ccbec9fd63ffd4fb26239c84615257 100644 (file)
@@ -273,7 +273,7 @@ void app_main()
 {
     /* Initialize NVS — it is used to store PHY calibration data */
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 84a8ed48633342d8bad69647b0a8e4e950640a8c..df72951052700e841538c5ea8756aeb2ee3ade37 100644 (file)
@@ -138,7 +138,7 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 void app_main()
 {
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index d8b00ebec30c9c8305bc05bd472d18b61031a9ca..ad42c9956b218c47c703e06e777d335ef43bf01d 100644 (file)
@@ -223,7 +223,7 @@ void app_main()
     }
 
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 72a354eb0e84a0fe855e3ba4f992e84d63bab5f9..51c23c094e514ee694b5a3b6a1c575d9a4bc01ab 100644 (file)
@@ -140,7 +140,7 @@ void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *param)
 void app_main()
 {
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 218ff34373799afa37227b9c54e23d7d2b4a819a..f5ef880a7ba887ff6e2489ebccb2bc6f62863705 100644 (file)
@@ -208,7 +208,7 @@ void app_main()
     }
 
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 006a951b3918700d654cab6e7322997999ca07fe..0eb7ef77812bf1599e24d07948e082d4f3636bfa 100644 (file)
@@ -37,7 +37,7 @@ void app_main()
 
     /* Initialize NVS — it is used to store PHY calibration data */
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 1f2cc20e41dfc1b612fc59f7d381f4d7f3674200..ac49348be226523dbe8095a9bb7ba82bc917123a 100644 (file)
@@ -414,7 +414,7 @@ void app_main()
 {
     // Initialize NVS.
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 49725751d13f33efa793bcae88953ec34d854afd..2ed2c86b5e5fa3386fff40cc108a0a876c0467cb 100644 (file)
@@ -41,7 +41,7 @@ void app_main()
 {
     // Initialize NVS.
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
@@ -103,7 +103,7 @@ The main function starts by initializing the non-volatile storage library. This
 
 ```c
 esp_err_t ret = nvs_flash_init();
-if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
     ESP_ERROR_CHECK(nvs_flash_erase());
     ret = nvs_flash_init();
 }
index 71c2a415ac6cd17581f8f43022d2dacb6f019805..052a81c87f748e94a8babde4e95f235952a1ed4b 100644 (file)
@@ -460,7 +460,7 @@ void app_main()
 {
     // Initialize NVS.
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index de4376d743f5e4fb81323889bd6664ca56eb3807..c9b567946c9306f84f1822bc577daa9c1bc5ba68 100644 (file)
@@ -466,7 +466,7 @@ void app_main()
 
     // Initialize NVS.
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 76dc104a2b117dceffd9d7a59c297b4e77272d3e..57f17b1dd26d8726c02cbb88e4666240c9cfa78a 100644 (file)
@@ -679,7 +679,7 @@ void app_main()
 
     // Initialize NVS.
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 34a44d415c1f64efccf7fd5800dbbfea8f61f189..495a2bde8f06868c536bb7ffbe72b40e1602a3f5 100644 (file)
@@ -44,7 +44,7 @@ The entry point to this example is the app_main() function:
 
     // Initialize NVS.
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index cc62e5013e53d81dabb2ba47cea3b9b6a198798f..704e735b904c24c654ac3a95cf923f5c2ead4363 100644 (file)
@@ -517,7 +517,7 @@ void app_main()
 
     /* Initialize NVS. */
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index a317dc8da27eab9ff2222285984f6534f97b3fa3..c86d82cc2c9fb11a05608e4989cf45be8f06a5ec 100644 (file)
@@ -81,7 +81,7 @@ void app_main()
 
     // Initialize NVS.
     ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index 71f70d4701819b40356b2b41bfaac5bd65dd2a24..f7daa4453500abbb4f780a232043648ea1d935e0 100644 (file)
@@ -886,7 +886,7 @@ static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp
 void app_main()
 {
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index d4e22bd1ecd28319c2370d60a85f0e722b11a03b..c5b48ae8e72dabd675f73ef49736f272b20a4738 100644 (file)
@@ -321,7 +321,7 @@ void app_main()
 {
     // Initialize NVS.
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         err = nvs_flash_init();
     }
index 2b489d57be7c031cc01a1f3e88a9600d4c9eb792..0a382b9d6b4922aba2886a59670d91d2f56a8864 100644 (file)
@@ -356,7 +356,7 @@ static void initialise_wifi(void)
 void app_main()
 {
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         err = nvs_flash_init();
     }
index 4a489080b9190a62197816f0a9bcc4066c5ce8fc..b3b45b6eb37b7e05494afd7c5ff436f70a347791 100644 (file)
@@ -351,7 +351,7 @@ static void http_test_task(void *pvParameters)
 void app_main()
 {
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
       ESP_ERROR_CHECK(nvs_flash_erase());
       ret = nvs_flash_init();
     }
index 8c11e72fd085d20ada664e87fdf7155efb1c8a58..e5bd6eabe5a7ef5e88f1616e3b16a2580d1d1256 100644 (file)
@@ -147,7 +147,7 @@ esp_err_t print_what_saved(void)
 void app_main()
 {
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         // NVS partition was truncated and needs to be erased
         // Retry nvs_flash_init
         ESP_ERROR_CHECK(nvs_flash_erase());
index c4aa598ae1e7b5b013c609186d25658897f213f4..cd03269f0da453b5f9028431b4fe2e112387e323 100644 (file)
@@ -20,7 +20,7 @@ void app_main()
 {
     // Initialize NVS
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         // NVS partition was truncated and needs to be erased
         // Retry nvs_flash_init
         ESP_ERROR_CHECK(nvs_flash_erase());
index 0c7e566abe0b9ed86ca39abc7e8b905106c2e9bc..a115c6f9998eea7a937ddbde12fabd49c7495722 100644 (file)
@@ -50,7 +50,7 @@ static void initialize_filesystem()
 static void initialize_nvs()
 {
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK( nvs_flash_erase() );
         err = nvs_flash_init();
     }
index b5e0f606255b6518283302226a5d3e57b8e8a385..1c09c0aa27aa97a31a99829001e6b1c3c7d041ef 100644 (file)
@@ -301,7 +301,7 @@ void app_main()
 {
     // Initialize NVS.
     esp_err_t err = nvs_flash_init();
-    if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         // OTA app partition table has a smaller NVS partition size than the non-OTA
         // partition table. This size mismatch may cause NVS initialization to fail.
         // If this happens, we erase NVS partition and initialize NVS again.
index 68e56ff654a6b7c2ae281cb329e34f1731425939..afb1428c52536b73fffd4aa8c52868f74113a27a 100644 (file)
@@ -375,7 +375,7 @@ void app_main()
 {
     // Initialize NVS
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK( nvs_flash_erase() );
         ret = nvs_flash_init();
     }
index bb4940f79b57ae61867b66ac9edc3a8fa4a0ee4f..ffeeb680b59a3bbd7ebe34aaa1537256d439af2d 100644 (file)
@@ -71,7 +71,7 @@ static void initialize_console()
 void app_main(void)
 {
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index f40b898bcf99956222e9cdd06772c9a7b0314934..d2e60fdfd1fb39bf7914a604a447d4e20bf407aa 100644 (file)
@@ -89,7 +89,7 @@ void app_main()
 {
     // Initialize NVS
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index ee82d859df67b7092ff992f0e1e1001239dbdf9a..fa27bf7f21ab4d59164c48f336f23f947ed517ab 100644 (file)
@@ -117,7 +117,7 @@ void app_main()
 {
     // Initialize NVS
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }
index ccc5590165e2fb26e2d300ac0cc45fa0df71c4bd..456e880eefceb0ce8ad334c447e5118d0660b064 100644 (file)
@@ -130,7 +130,7 @@ void app_main()
 {
     //Initialize NVS
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
       ESP_ERROR_CHECK(nvs_flash_erase());
       ret = nvs_flash_init();
     }
index 6fb8ad24683bafed472fd0be472a63e9ae41edd9..50ab8de9bc0bb71f05d5113403cee19711e50efb 100644 (file)
@@ -112,7 +112,7 @@ void app_main()
 {
     /* Initialize NVS — it is used to store PHY calibration data */
     esp_err_t ret = nvs_flash_init();
-    if (ret == ESP_ERR_NVS_NO_FREE_PAGES) {
+    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
         ESP_ERROR_CHECK(nvs_flash_erase());
         ret = nvs_flash_init();
     }