From ffc58c960a1373cbac9ff253ff079422a36f54d2 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 | 10 ++++----- .../Zephyr/ConfigurationManagerImpl.cpp | 22 +++++++++++++------ 4 files changed, 22 insertions(+), 14 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..9931640c5d 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,17 +467,17 @@ 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 it to an unexpected state. For this reason, set this option if the entire configuration is supposed to be cleared on a factory reset, including - device-specific entries. + device-specific entries. It makes sense only for NVS filesystem. config CHIP_MALLOC_SYS_HEAP bool "Memory allocator based on Zephyr sys_heap" diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp index 398fb12f32..dfc2d38b0a 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 } - if (status) { ChipLogError(DeviceLayer, "Factory reset failed: %d", status); } -#else +#else // CONFIG_SETTINGS_NVS || CONFIG_SETTINGS_ZMS + 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(); }