Merge branch 'fix/nvs_tool_entry_unknown_type_crash' into 'master'

fix(nvs): Fix nvs_tool accepting an unknown entry type

See merge request espressif/esp-idf!30503
This commit is contained in:
Adam Múdry 2024-05-17 21:05:22 +08:00
commit 7b32f27e81
3 changed files with 19 additions and 13 deletions

View File

@ -1,7 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
from typing import Any, Dict, List, Optional from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from zlib import crc32 from zlib import crc32
@ -123,9 +126,9 @@ class NVS_Page:
# Load an entry # Load an entry
entry = NVS_Entry( entry = NVS_Entry(
i - 2, index=(i - 2),
page_data[i * nvs_const.entry_size: (i + 1) * nvs_const.entry_size], entry_data=page_data[i * nvs_const.entry_size: (i + 1) * nvs_const.entry_size],
entry_states[i - 2], entry_state=entry_states[i - 2],
) )
self.entries.append(entry) self.entries.append(entry)
@ -137,13 +140,13 @@ class NVS_Page:
if page_addr * nvs_const.entry_size >= nvs_const.page_size: if page_addr * nvs_const.entry_size >= nvs_const.page_size:
break break
child_entry = NVS_Entry( child_entry = NVS_Entry(
entry_idx, index=entry_idx,
page_data[ entry_data=page_data[
page_addr page_addr
* nvs_const.entry_size: (page_addr + 1) * nvs_const.entry_size: (page_addr + 1)
* nvs_const.entry_size * nvs_const.entry_size
], ],
entry_states[entry_idx], entry_state=entry_states[entry_idx],
) )
entry.child_assign(child_entry) entry.child_assign(child_entry)
entry.compute_crc() entry.compute_crc()
@ -269,6 +272,8 @@ class NVS_Entry:
for entry in self.children: for entry in self.children:
children_data += entry.raw children_data += entry.raw
if self.data: if self.data:
if self.data['value'] is not None:
if self.data['size']:
children_data = children_data[: self.data['size']] # Discard padding children_data = children_data[: self.data['size']] # Discard padding
self.metadata['crc']['data_computed'] = crc32(children_data, 0xFFFFFFFF) self.metadata['crc']['data_computed'] = crc32(children_data, 0xFFFFFFFF)
@ -279,7 +284,7 @@ class NVS_Entry:
is_empty=self.is_empty, is_empty=self.is_empty,
index=self.index, index=self.index,
metadata=self.metadata, metadata=self.metadata,
children=self.children,
key=self.key, key=self.key,
data=self.data, data=self.data,
children=self.children,
) )

6
components/nvs_flash/nvs_partition_tool/nvs_tool.py Normal file → Executable file
View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import argparse import argparse
import os import os
@ -25,11 +25,11 @@ def program_args() -> argparse.Namespace:
help='check partition for potential errors', help='check partition for potential errors',
) )
tmp = { tmp = {
'all': 'print everything', 'all': 'print written, erased and empty entries',
'written': 'print only currently written entries', 'written': 'print only currently written entries',
'minimal': 'print only namespace:key=value pairs', 'minimal': 'print only namespace:key=value pairs',
'namespaces': 'list all written namespaces',
'blobs': 'print all blobs and strings', 'blobs': 'print all blobs and strings',
'namespaces': 'list all written namespaces',
'storage_info': 'print storage related information (free/used entries, etc)', 'storage_info': 'print storage related information (free/used entries, etc)',
'none': 'do not print anything (if you only want to do integrity check)', 'none': 'do not print anything (if you only want to do integrity check)',
} }

View File

@ -14,6 +14,7 @@ components/heap/test_multi_heap_host/test_all_configs.sh
components/mbedtls/esp_crt_bundle/gen_crt_bundle.py components/mbedtls/esp_crt_bundle/gen_crt_bundle.py
components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/test_gen_crt_bundle.py components/mbedtls/esp_crt_bundle/test_gen_crt_bundle/test_gen_crt_bundle.py
components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py components/nvs_flash/nvs_partition_generator/nvs_partition_gen.py
components/nvs_flash/nvs_partition_tool/nvs_tool.py
components/partition_table/check_sizes.py components/partition_table/check_sizes.py
components/partition_table/gen_empty_partition.py components/partition_table/gen_empty_partition.py
components/partition_table/gen_esp32part.py components/partition_table/gen_esp32part.py