feat(nvs): Optimize read-only NVS loading

This commit is contained in:
Adam Múdry
2025-03-24 15:55:18 +01:00
parent 851e869bb2
commit 4a6b99bc4a
3 changed files with 61 additions and 63 deletions

View File

@@ -110,7 +110,7 @@ public:
size_t columns = size / column_size; size_t columns = size / column_size;
size_t column; size_t column;
for(column = 0; column < columns; ++column) for(column = 0; column < columns; column = column + 1)
{ {
// read column // read column
if((err = esp_partition_read_raw(&esp_partition, dst_offset + (column * column_size), buff, column_size)) != ESP_OK) return err; if((err = esp_partition_read_raw(&esp_partition, dst_offset + (column * column_size), buff, column_size)) != ESP_OK) return err;

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -56,6 +56,7 @@ esp_err_t PageManager::load(Partition *partition, uint32_t baseSector, uint32_t
// if power went out after a new item for the given key was written, // if power went out after a new item for the given key was written,
// but before the old one was erased, we end up with a duplicate item // but before the old one was erased, we end up with a duplicate item
if (!partition->get_readonly()) {
Page& lastPage = back(); Page& lastPage = back();
size_t lastItemIndex = SIZE_MAX; size_t lastItemIndex = SIZE_MAX;
Item item; Item item;
@@ -125,9 +126,10 @@ esp_err_t PageManager::load(Partition *partition, uint32_t baseSector, uint32_t
} }
// partition should have at least one free page if it is not read-only // partition should have at least one free page if it is not read-only
if (!partition->get_readonly() && mFreePageList.empty()) { if (mFreePageList.empty()) {
return ESP_ERR_NVS_NO_FREE_PAGES; return ESP_ERR_NVS_NO_FREE_PAGES;
} }
}
return ESP_OK; return ESP_OK;
} }

View File

@@ -36,16 +36,12 @@ def test_examples_parttool(dut: Dut) -> None:
cmds = [ cmds = [
'read_partition --partition-type=data --partition-subtype=nvs --output custom1.bin', 'read_partition --partition-type=data --partition-subtype=nvs --output custom1.bin',
'erase_partition --partition-name=custom', 'erase_partition --partition-name=custom',
'write_partition --partition-name=custom --input custom.bin', 'write_partition --partition-name=custom --input custom.bin --ignore-readonly',
'get_partition_info --partition-boot-default --info size', 'get_partition_info --partition-boot-default --info size',
] ]
for cmd in cmds: for cmd in cmds:
try:
subprocess.check_call(BASE_CMD + cmd.split()) subprocess.check_call(BASE_CMD + cmd.split())
except subprocess.CalledProcessError as e:
print(e.output)
raise
clean_files = ['custom.bin', 'custom1.bin'] clean_files = ['custom.bin', 'custom1.bin']
for clean_file in clean_files: for clean_file in clean_files: