Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telink] Allow to erase entire NVS on factory reset by default; Fix IDM-7.1 test. (Cherry-pick #23434 & #23676) #23677

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/telink/chip-module/Kconfig
Original file line number Diff line number Diff line change
@@ -266,3 +266,8 @@ config CHIP_CERTIFiCATION_DECLARATION_OTA_IMAGE_ID
for sending it via OTA Software Update purposes.

endif

# See config/zephyr/Kconfig for full definition
config CHIP_FACTORY_RESET_ERASE_NVS
bool
default y
11 changes: 11 additions & 0 deletions config/zephyr/Kconfig
Original file line number Diff line number Diff line change
@@ -196,6 +196,17 @@ config CHIP_OPERATIONAL_TIME_SAVE_INTERVAL
precisely operation time in case of device reboot and maximizing flash memory
lifetime.

config CHIP_FACTORY_RESET_ERASE_NVS
bool "Erase NVS flash pages on factory reset"
depends on SETTINGS_NVS
help
When factory reset is requested, erase flash pages occupied by non-volatile storage
instead of removing Matter-related settings only. This provides a more robust
factory reset mechanism and allows to regain the original storage performance if any
firmware issue has brought it to an unexpected state. For this reason, it is
advisable to set this option if all configuration, including device-specific
entries, is supposed to be cleared on a factory reset.

config CHIP_MALLOC_SYS_HEAP
bool "Memory allocator based on Zephyr sys_heap"
imply SYS_HEAP_RUNTIME_STATS
27 changes: 24 additions & 3 deletions src/platform/Zephyr/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
@@ -32,6 +32,11 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS
#include <zephyr/fs/nvs.h>
#include <zephyr/settings/settings.h>
#endif

namespace chip {
namespace DeviceLayer {

@@ -168,14 +173,30 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void)
void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
{
ChipLogProgress(DeviceLayer, "Performing factory reset");

#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS
void * storage = nullptr;
int status = settings_storage_get(&storage);

if (status == 0)
{
status = nvs_clear(static_cast<nvs_fs *>(storage));
}

if (status)
{
ChipLogError(DeviceLayer, "Factory reset failed: %d", status);
}
#else
const CHIP_ERROR err = PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset();

if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Factory reset failed: %" CHIP_ERROR_FORMAT, err.Format());
}

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
ThreadStackMgr().ErasePersistentInfo();
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
ConnectivityMgr().ErasePersistentInfo();
#endif

PlatformMgr().Shutdown();
}