diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index 867a462dccdf33..4a6cc6dd6e889e 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -835,6 +835,12 @@ menu "CHIP Device Layer" default "nvs" help Label of the partition to store key-values in the "chip-counters" namespace. + + config CHIP_KVS_NAMESPACE_PARTITION_LABEL + string "chip-kvs namespace partition label" + default "nvs" + help + Label of the partition to store key-values in the "chip-kvs" namespace. endmenu diff --git a/src/platform/ESP32/CHIPDevicePlatformConfig.h b/src/platform/ESP32/CHIPDevicePlatformConfig.h index 7fb89b27adec60..3bc56162c00350 100644 --- a/src/platform/ESP32/CHIPDevicePlatformConfig.h +++ b/src/platform/ESP32/CHIPDevicePlatformConfig.h @@ -97,4 +97,5 @@ #define CHIP_DEVICE_CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION_LABEL #define CHIP_DEVICE_CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION_LABEL #define CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION_LABEL +#define CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION CONFIG_CHIP_KVS_NAMESPACE_PARTITION_LABEL #define CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index f11576f621a7fc..21923bc4c568c3 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -119,6 +119,8 @@ CHIP_ERROR ConfigurationManagerImpl::Init() SuccessOrExit(MapConfigError(esp_err)); esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION); SuccessOrExit(MapConfigError(esp_err)); + esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION); + SuccessOrExit(MapConfigError(esp_err)); #endif // Force initialization of NVS namespaces if they doesn't already exist. diff --git a/src/platform/ESP32/KeyValueStoreManagerImpl.cpp b/src/platform/ESP32/KeyValueStoreManagerImpl.cpp index 20ddf596256f30..9b2ee12e000a01 100644 --- a/src/platform/ESP32/KeyValueStoreManagerImpl.cpp +++ b/src/platform/ESP32/KeyValueStoreManagerImpl.cpp @@ -75,7 +75,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t VerifyOrReturnError(offset_bytes == 0, CHIP_ERROR_NOT_IMPLEMENTED); Internal::ScopedNvsHandle handle; - ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READONLY)); + ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READONLY, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION)); char keyHash[NVS_KEY_NAME_MAX_SIZE]; VerifyOrDo(HashIfLongKey(key, keyHash) == false, key = keyHash); @@ -95,7 +95,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); Internal::ScopedNvsHandle handle; - ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE)); + ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION)); char keyHash[NVS_KEY_NAME_MAX_SIZE]; VerifyOrDo(HashIfLongKey(key, keyHash) == false, key = keyHash); @@ -112,7 +112,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) { Internal::ScopedNvsHandle handle; - ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE)); + ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION)); char keyHash[NVS_KEY_NAME_MAX_SIZE]; VerifyOrDo(HashIfLongKey(key, keyHash) == false, key = keyHash); @@ -129,7 +129,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::EraseAll(void) { Internal::ScopedNvsHandle handle; - ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE)); + ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION)); ReturnMappedErrorOnFailure(nvs_erase_all(handle)); ReturnMappedErrorOnFailure(nvs_commit(handle));