From 3d783fff72ebd51f4eadc95286878160fddee682 Mon Sep 17 00:00:00 2001 From: Arkadiusz Balys Date: Fri, 11 Oct 2024 10:19:24 +0200 Subject: [PATCH] [nrf toup][Zephyr] Add ZMS to Zephyr port Added a possibility to use ZMS fs backend in Zephyr. NVS fs backend imply is now controlled by the nrfconnect platform configuration directly. All other platforms use NVS fs backend by default. Signed-off-by: Arkadiusz Balys --- config/nxp/chip-module/Kconfig | 2 +- config/telink/chip-module/Kconfig | 2 +- config/zephyr/Kconfig | 8 ++++---- .../Zephyr/ConfigurationManagerImpl.cpp | 20 +++++++++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/config/nxp/chip-module/Kconfig b/config/nxp/chip-module/Kconfig index 7ee0917ebe..196d150488 100644 --- a/config/nxp/chip-module/Kconfig +++ b/config/nxp/chip-module/Kconfig @@ -206,7 +206,7 @@ config CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID endif #CHIP_FACTORY_DATA_BUILD # See config/zephyr/Kconfig for full definition -config CHIP_FACTORY_RESET_ERASE_NVS +config CHIP_FACTORY_RESET_ERASE_SETTINGS bool default y diff --git a/config/telink/chip-module/Kconfig b/config/telink/chip-module/Kconfig index b76e3962d2..4cab201f78 100644 --- a/config/telink/chip-module/Kconfig +++ b/config/telink/chip-module/Kconfig @@ -164,7 +164,7 @@ config CHIP_DEVICE_GENERATE_ROTATING_DEVICE_UID endif #CHIP_FACTORY_DATA_BUILD # See config/zephyr/Kconfig for full definition -config CHIP_FACTORY_RESET_ERASE_NVS +config CHIP_FACTORY_RESET_ERASE_SETTINGS bool default n diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig index aded7eea23..c151391fd1 100644 --- a/config/zephyr/Kconfig +++ b/config/zephyr/Kconfig @@ -44,7 +44,7 @@ menuconfig CHIP imply HWINFO imply FLASH imply FLASH_MAP - imply NVS + imply NVS if !CHIP_NRF_PLATFORM imply SETTINGS help Enables Matter libraries required for the Matter protocol stack to work. @@ -467,11 +467,11 @@ config CHIP_CERTIFiCATION_DECLARATION_OTA_IMAGE_ID endif -config CHIP_FACTORY_RESET_ERASE_NVS +config CHIP_FACTORY_RESET_ERASE_SETTINGS bool "Erase NVS flash pages on factory reset" - depends on SETTINGS_NVS + depends on SETTINGS_NVS || SETTINGS_ZMS help - Erases flash pages occupied by non-volatile storage when a factory reset + Erases non-volatile pages occupied by non-volatile storage when a factory reset is requested, instead of removing Matter-related settings only. Enabling this option provides a more robust factory reset mechanism and allows to regain the original storage performance if any firmware issue has brought diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp index 398fb12f32..61b196be94 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.cpp +++ b/src/platform/Zephyr/ConfigurationManagerImpl.cpp @@ -37,10 +37,14 @@ #include #include -#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS -#include +#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS #include -#endif +#ifdef CONFIG_SETTINGS_NVS +#include +#elif CONFIG_SETTINGS_ZMS +#include +#endif // CONFIG_SETTINGS_NVS || CONFIG_SETTINGS_ZMS +#endif // CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS #ifdef CONFIG_NET_L2_OPENTHREAD #include @@ -194,20 +198,24 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) ThreadStackMgr().LockThreadStack(); #endif -#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS +#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS void * storage = nullptr; int status = settings_storage_get(&storage); if (status == 0) { +#ifdef CONFIG_SETTINGS_NVS status = nvs_clear(static_cast(storage)); +#elif CONFIG_SETTINGS_ZMS + status = zms_clear(static_cast(storage)); +#endif // CONFIG_SETTINGS_NVS || CONFIG_SETTINGS_ZMS } - if (status) { ChipLogError(DeviceLayer, "Factory reset failed: %d", status); } #else + const CHIP_ERROR err = PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset(); if (err != CHIP_NO_ERROR) @@ -216,7 +224,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) } ConnectivityMgr().ErasePersistentInfo(); -#endif +#endif // CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS PlatformMgr().Shutdown(); }