Skip to content

Commit e8306c9

Browse files
rcasallas-silabsjmartinez-silabs
authored andcommitted
Pull request project-chip#2097: Cherry-pick: Increase the max supported KVS entries.
Merge in WMN_TOOLS/matter from cherry-pick/increase_kvs_entries to RC_2.3.1-1.3 Squashed commit of the following: commit 7f0c9bc82e79b6a7ca7d7993529f34f259b01ec3 Author: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Tue Sep 10 15:01:55 2024 -0400 Cherry-pick: Increase the max supported KVS entries.
1 parent cd7fd2c commit e8306c9

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

src/platform/silabs/KeyValueStoreManagerImpl.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ uint16_t KeyValueStoreManagerImpl::hashKvsKeyString(const char * key) const
8888
CHIP_ERROR KeyValueStoreManagerImpl::MapKvsKeyToNvm3(const char * key, uint16_t hash, uint32_t & nvm3Key, bool isSlotNeeded) const
8989
{
9090
CHIP_ERROR err;
91-
char * strPrefix = nullptr;
92-
uint8_t firstEmptyKeySlot = kMaxEntries;
93-
for (uint8_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++)
91+
char * strPrefix = nullptr;
92+
uint16_t firstEmptyKeySlot = kMaxEntries;
93+
for (uint16_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++)
9494
{
9595
if (mKvsKeyMap[keyIndex] == hash)
9696
{
@@ -170,7 +170,7 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void)
170170
sizeof(mKvsKeyMap));
171171
#else
172172
SystemLayer().StartTimer(
173-
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(SILABS_KVS_SAVE_DELAY_SECONDS)),
173+
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(SL_KVS_SAVE_DELAY_SECONDS)),
174174
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
175175
#endif // defined(SLI_SI91X_MCU_INTERFACE) && CHIP_CONFIG_ENABLE_ICD_SERVER
176176
}
@@ -253,7 +253,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
253253
void KeyValueStoreManagerImpl::ErasePartition(void)
254254
{
255255
// Iterate over all the Matter Kvs nvm3 records and delete each one...
256-
for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kMaxConfigKey_MatterKvs; nvm3Key++)
256+
for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kConfigKey_KvsLastKeySlot; nvm3Key++)
257257
{
258258
SilabsConfig::ClearConfigValue(nvm3Key);
259259
}

src/platform/silabs/SilabsConfig.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
#endif
3636

3737
// Delay before Key/Value is actually saved in NVM
38-
#define SILABS_KVS_SAVE_DELAY_SECONDS 5
38+
#ifndef SL_KVS_SAVE_DELAY_SECONDS
39+
#define SL_KVS_SAVE_DELAY_SECONDS 2
40+
#endif
3941

40-
static_assert((KVS_MAX_ENTRIES <= 255), "Implementation supports up to 255 Kvs entries");
42+
static_assert((KVS_MAX_ENTRIES <= 511), "Implementation supports up to 511 Kvs entries");
4143
static_assert((KVS_MAX_ENTRIES >= 30), "Mininimal Kvs entries requirement is not met");
4244

4345
namespace chip {
@@ -89,7 +91,8 @@ class SilabsConfig
8991
// Persistent counter values set at runtime. Retained during factory reset.
9092
static constexpr uint8_t kMatterCounter_KeyBase = 0x74;
9193
// Persistent config values set at runtime. Cleared during factory reset.
92-
static constexpr uint8_t kMatterKvs_KeyBase = 0x75;
94+
static constexpr uint8_t kMatterKvs_KeyBase = 0x75;
95+
static constexpr uint8_t kMatterKvs_ExtendedRange = 0x76;
9396

9497
// Key definitions for well-known configuration values.
9598
// Factory config keys
@@ -161,7 +164,8 @@ class SilabsConfig
161164
// Matter KVS storage Keys
162165
static constexpr Key kConfigKey_KvsStringKeyMap = SilabsConfigKey(kMatterKvs_KeyBase, 0x00);
163166
static constexpr Key kConfigKey_KvsFirstKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, 0x01);
164-
static constexpr Key kConfigKey_KvsLastKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, KVS_MAX_ENTRIES);
167+
static constexpr Key kConfigKey_KvsLastKeySlot =
168+
SilabsConfigKey(kMatterKvs_KeyBase + (KVS_MAX_ENTRIES >> 8), KVS_MAX_ENTRIES & UINT8_MAX);
165169

166170
// Set key id limits for each group.
167171
static constexpr Key kMinConfigKey_MatterFactory = SilabsConfigKey(kMatterFactory_KeyBase, 0x00);
@@ -174,7 +178,9 @@ class SilabsConfig
174178
static constexpr Key kMaxConfigKey_MatterCounter = SilabsConfigKey(kMatterCounter_KeyBase, 0x1F);
175179

176180
static constexpr Key kMinConfigKey_MatterKvs = kConfigKey_KvsStringKeyMap;
177-
static constexpr Key kMaxConfigKey_MatterKvs = kConfigKey_KvsLastKeySlot;
181+
static constexpr Key kMaxConfigKey_MatterKvs = SilabsConfigKey(kMatterKvs_ExtendedRange, 0xFF);
182+
static_assert(kConfigKey_KvsLastKeySlot <= kMaxConfigKey_MatterKvs,
183+
"Configured KVS_MAX_ENTRIES overflows the reserved KVS Key range");
178184

179185
static CHIP_ERROR Init(void);
180186
static void DeInit(void);

third_party/silabs/SiWx917_sdk.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ template("siwx917_sdk") {
173173
# 1->SOC and 0->NCP
174174
"RSI_WLAN_API_ENABLE",
175175
"NVM3_DEFAULT_NVM_SIZE=40960",
176-
"NVM3_DEFAULT_MAX_OBJECT_SIZE=4092",
176+
"NVM3_DEFAULT_MAX_OBJECT_SIZE=${sl_nvm3_max_object_size}",
177177
"NVM3_LOCK_OVERRIDE=1",
178178
"KVS_MAX_ENTRIES=${kvs_max_entries}",
179179
"${silabs_mcu}=1",

third_party/silabs/efr32_sdk.gni

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ declare_args() {
3838
# enable by default for thread/non-wifi-ncp builds
3939
enable_openthread_cli = !(use_rs9116 || use_wf200 || use_SiWx917)
4040
kvs_max_entries = 255
41+
sl_nvm3_max_object_size = 4092
4142

4243
# Use Silabs factory data provider example.
4344
# Users can implement their own.
@@ -286,7 +287,7 @@ template("efr32_sdk") {
286287
"HARD_FAULT_LOG_ENABLE",
287288
"CORTEXM3_EFM32_MICRO",
288289
"NVM3_DEFAULT_NVM_SIZE=40960",
289-
"NVM3_DEFAULT_MAX_OBJECT_SIZE=4092",
290+
"NVM3_DEFAULT_MAX_OBJECT_SIZE=${sl_nvm3_max_object_size}",
290291
"KVS_MAX_ENTRIES=${kvs_max_entries}",
291292
"EFR32_OPENTHREAD_API",
292293
"PHY=EMBER_PHY_RAIL",

0 commit comments

Comments
 (0)