From 1abde6ed5842110a2e9511e4947b1dbbae059a19 Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Tue, 22 Jan 2019 11:30:05 +0800 Subject: [PATCH] fis(nvs_flash): Fix recovery after power-off during erase operation Current code for recovery after power-off do not clean-up partially erased items for FULL pages. If the erasure was part of modification operation, this gets luckily cleaned-up because of duplicate detection logic. For erase-only operation, the problem still exists. This patch adds the recovery for FULL pages also. esp-idf commit ID: 9a3c4b71 --- components/nvs_flash/src/nvs_page.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/nvs_flash/src/nvs_page.cpp b/components/nvs_flash/src/nvs_page.cpp index 2a17cff2..a5ee0b6c 100644 --- a/components/nvs_flash/src/nvs_page.cpp +++ b/components/nvs_flash/src/nvs_page.cpp @@ -594,6 +594,16 @@ esp_err_t Page::mLoadEntryTable() assert(item.span > 0); size_t span = item.span; + + if (item.datatype == ItemType::BLOB || item.datatype == ItemType::SZ) { + for (size_t j = i + 1; j < i + span; ++j) { + if (mEntryTable.get(j) != EntryState::WRITTEN) { + eraseEntryAndSpan(i); + break; + } + } + } + i += span - 1; }