Skip to content

Commit

Permalink
[nrf toup][Zephyr] Add ZMS to Zephyr port
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ArekBalysNordic committed Oct 14, 2024
1 parent 5c19b19 commit ffc58c9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/nxp/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion config/telink/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions config/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down
22 changes: 15 additions & 7 deletions src/platform/Zephyr/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS
#include <zephyr/fs/nvs.h>
#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS
#include <zephyr/settings/settings.h>
#endif
#ifdef CONFIG_SETTINGS_NVS
#include <zephyr/fs/nvs.h>
#elif CONFIG_SETTINGS_ZMS
#include <zephyr/fs/zms.h>
#endif // CONFIG_SETTINGS_NVS || CONFIG_SETTINGS_ZMS
#endif // CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS

#ifdef CONFIG_NET_L2_OPENTHREAD
#include <platform/ThreadStackManager.h>
Expand Down Expand Up @@ -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<nvs_fs *>(storage));
#elif CONFIG_SETTINGS_ZMS
status = zms_clear(static_cast<zms_fs *>(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)
Expand All @@ -216,7 +224,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
}

ConnectivityMgr().ErasePersistentInfo();
#endif
#endif // CONFIG_CHIP_FACTORY_RESET_ERASE_SETTINGS

PlatformMgr().Shutdown();
}
Expand Down

0 comments on commit ffc58c9

Please sign in to comment.