Skip to content

Commit

Permalink
[Infineon][SVE-2] CYW30739 fix for TC-RR-1.1 (#22392)
Browse files Browse the repository at this point in the history
* [Infineon][SVE-2] Fix TC-RR-1.1 for CYW30739.

* Change CHIP_CONFIG_MAX_FABRICS from 5 to 4.
* Optimize KVS key storage size:
  * Only store non-zero bytes of the key to the flash.
  * Decrease the value size field from 4 bytes to 2 bytes.
* Adjust the flash layout for a larger KVS session.
* Change ota-requestor-app to Thread MTD.

* Change CHIP_CONFIG_MAX_FABRICS back to 5.

* Adjust more flash space for the KVS session.
  • Loading branch information
hsusid authored and pull[bot] committed Oct 4, 2022
1 parent 84a0773 commit f323f48
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/ota-requestor-app/infineon/cyw30739/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ import("${chip_root}/src/platform/Infineon/CYW30739/args.gni")

cyw30739_sdk_target = get_label_info(":sdk", "label_no_toolchain")

chip_openthread_ftd = true
chip_openthread_ftd = false

chip_enable_ota_requestor = true
16 changes: 9 additions & 7 deletions src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value,
CHIP_ERROR err = CHIP_NO_ERROR;
KeyConfigIdEntry * entry;

const size_t keyLength = strnlen(key, PersistentStorageDelegate::kKeyLengthMax + 1);
const size_t keyLength = strnlen(key, PersistentStorageDelegate::kKeyLengthMax);
VerifyOrExit(keyLength != 0 && keyLength <= PersistentStorageDelegate::kKeyLengthMax &&
value_size <= kMaxPersistedValueLengthSupported,
err = CHIP_ERROR_INVALID_ARGUMENT);

entry = AllocateEntry(key, keyLength);
entry = AllocateEntry(key);
VerifyOrExit(entry != nullptr, ChipLogError(DeviceLayer, "%s AllocateEntry %s", __func__, ErrorStr(err));
err = CHIP_ERROR_NO_MEMORY);

Expand All @@ -129,7 +129,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value,
}

entry->SetValueSize(value_size);
SuccessOrExit(err = CYW30739Config::WriteConfigValueBin(entry->GetKeyConfigKey(), &entry->mStorage, sizeof(entry->mStorage)));
SuccessOrExit(err = CYW30739Config::WriteConfigValueBin(entry->GetKeyConfigKey(), &entry->mStorage, entry->mStorage.GetSize()));

exit:
return err;
Expand Down Expand Up @@ -171,25 +171,27 @@ CHIP_ERROR KeyValueStoreManagerImpl::EraseAll(void)
return CHIP_NO_ERROR;
}

KeyValueStoreManagerImpl::KeyStorage::KeyStorage(const char * key, size_t keyLength) : mValueSize(0)
KeyValueStoreManagerImpl::KeyStorage::KeyStorage(const char * key) : mValueSize(0)
{
memset(mKey, 0, sizeof(mKey));
memcpy(mKey, key, keyLength);

if (key != NULL)
strncpy(mKey, key, sizeof(mKey));
}

bool KeyValueStoreManagerImpl::KeyStorage::IsMatchKey(const char * key) const
{
return strncmp(mKey, key, sizeof(mKey)) == 0;
}

KeyValueStoreManagerImpl::KeyConfigIdEntry * KeyValueStoreManagerImpl::AllocateEntry(const char * key, size_t keyLength)
KeyValueStoreManagerImpl::KeyConfigIdEntry * KeyValueStoreManagerImpl::AllocateEntry(const char * key)
{
Optional<uint8_t> freeConfigID;
KeyConfigIdEntry * newEntry = FindEntry(key, &freeConfigID);
ReturnErrorCodeIf(newEntry != nullptr, newEntry);
ReturnErrorCodeIf(!freeConfigID.HasValue(), nullptr);

newEntry = Platform::New<KeyConfigIdEntry>(freeConfigID.Value(), KeyStorage(key, keyLength));
newEntry = Platform::New<KeyConfigIdEntry>(freeConfigID.Value(), KeyStorage(key));
ReturnErrorCodeIf(newEntry == nullptr, nullptr);

KeyConfigIdEntry * entry = static_cast<KeyConfigIdEntry *>(slist_tail(&mKeyConfigIdList));
Expand Down
11 changes: 6 additions & 5 deletions src/platform/Infineon/CYW30739/KeyValueStoreManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager

struct KeyStorage
{
KeyStorage(const char * key = nullptr, size_t keyLength = 0);
KeyStorage(const char * key = nullptr);

constexpr size_t GetSize() const { return sizeof(mValueSize) + strnlen(mKey, sizeof(mKey)); }
bool IsMatchKey(const char * key) const;

size_t mValueSize;
uint16_t mValueSize;
char mKey[PersistentStorageDelegate::kKeyLengthMax];
};

Expand All @@ -81,14 +82,14 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager
}
constexpr KeyConfigIdEntry * Next() const { return static_cast<KeyConfigIdEntry *>(next); }
constexpr uint8_t NextConfigID() const { return mConfigID + 1; }
constexpr size_t GetValueSize() const { return mStorage.mValueSize; }
constexpr void SetValueSize(size_t valueSize) { mStorage.mValueSize = valueSize; }
constexpr uint16_t GetValueSize() const { return mStorage.mValueSize; }
constexpr void SetValueSize(uint16_t valueSize) { mStorage.mValueSize = valueSize; }

uint8_t mConfigID;
KeyStorage mStorage;
};

KeyConfigIdEntry * AllocateEntry(const char * key, size_t keyLength);
KeyConfigIdEntry * AllocateEntry(const char * key);
KeyConfigIdEntry * FindEntry(const char * key, Optional<uint8_t> * freeConfigID = nullptr);

// ===== Members for internal use by the following friends.
Expand Down
2 changes: 1 addition & 1 deletion third_party/infineon/cyw30739_sdk/btp_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main():
items["ConfigXS1Location"] = items["ConfigDS2Location"] + ds_len

if option.enable_ota:
items["ConfigXS1Length"] = 0x00076000
items["ConfigXS1Length"] = 0x00073000
items["ConfigXS2Location"] = (
items["ConfigXS1Location"] + items["ConfigXS1Length"]
)
Expand Down
6 changes: 3 additions & 3 deletions third_party/infineon/cyw30739_sdk/flash.btp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ DevicePreset "30739 Flash"
DLConfigSerialControlBaudRate = 115200
DLConfigEEPROMAccessSpeed = 100
DLConfigVSOffset = 0
ConfigDSLocation = 0x505000
ConfigDS2Location = 0x519000
ConfigDSLocation = 0x509000
ConfigDS2Location = 0x51d000
DLConfigSSLocation = 0x500000
DLConfigIncludeBTWSecurityKey = 0
DLConfigVSLocation = 0x501000
DLConfigVSLength = 0x2000
DLConfigVSLength = 0x4000
DLConfigRemoteDeviceCount = 0
DLConfigBD_ADDRBase = "30739A0*****"
DLConfigFixedBD_ADDRFlag = "Can change"
Expand Down

0 comments on commit f323f48

Please sign in to comment.