From 2e9a1cd859580ba15ea95c78f3e3a5e41e26b8b6 Mon Sep 17 00:00:00 2001 From: Carol Yang Date: Sat, 4 Jun 2022 20:22:01 -0700 Subject: [PATCH 01/13] [OTA] Update README wth a more detailed multiple fabrics example (#19198) --- examples/ota-requestor-app/linux/README.md | 104 ++++++++++++++++----- 1 file changed, 82 insertions(+), 22 deletions(-) diff --git a/examples/ota-requestor-app/linux/README.md b/examples/ota-requestor-app/linux/README.md index a306eb1e3899dd..f14d5fa7cdf094 100644 --- a/examples/ota-requestor-app/linux/README.md +++ b/examples/ota-requestor-app/linux/README.md @@ -212,7 +212,7 @@ scripts/examples/gn_build_example.sh examples/ota-provider-app/linux/ out chip_c **Run the OTA Provider application** ``` -out/chip-ota-provider-app --discriminator 22 --secured-device-port 5565 --KVS /tmp/chip_kvs_provider --filepath /tmp/test.bin +out/chip-ota-provider-app --discriminator 22 --secured-device-port 5565 --KVS /tmp/chip_kvs_provider --filepath /tmp/ota-image.bin ``` #### In terminal 2: @@ -270,7 +270,7 @@ scripts/examples/gn_build_example.sh examples/ota-provider-app/linux/ out chip_c **Run the OTA Provider application** ``` -out/chip-ota-provider-app --discriminator 22 --secured-device-port 5565 --KVS /tmp/chip_kvs_provider --filepath /tmp/test.bin +out/chip-ota-provider-app --discriminator 22 --secured-device-port 5565 --KVS /tmp/chip_kvs_provider --filepath /tmp/ota-image.bin ``` #### In terminal 2: @@ -304,7 +304,7 @@ out/chip-tool pairing onnetwork-long 0x1234567890 20202021 18 **Write to the DefaultOTAProviders attribute** ``` -out/chip-tool otasoftwareupdaterequestor write default-ota-providers '[{"fabricIndex": 1, "providerNodeID": 3735928559, "endpoint": 0}]' 0x0000001234567890 0 +out/chip-tool otasoftwareupdaterequestor write default-ota-providers '[{"providerNodeID": 3735928559, "endpoint": 0}]' 0x1234567890 0 ``` Every 60 seconds from when the OTA Requestor application has launched, the OTA @@ -319,48 +319,108 @@ structs. Each entry in this list is a default OTA Provider per fabric. There can not be more than one entry containing the same fabric. To add more than one entry to the `DefaultOTAProviders` attribute, the OTA -Requestor app must be commissioned on multiple fabrics. This can be done as -specified below: +Requestor app must be commissioned into multiple fabrics. At least one OTA +Provider app should be commissioned into each corresponding fabric that the OTA +Requestor app had been commissioned into. -**Build and run the OTA Requestor application** +The following example has two OTA Provider apps, each commissioned into a +different fabric (alpha and beta) and one OTA Requestor app commissioned into +both alpha and beta fabrics. + +### In terminal 1: + +**Build the OTA Provider application** + +``` +scripts/examples/gn_build_example.sh examples/ota-provider-app/linux/ out chip_config_network_layer_ble=false +``` + +**Run the first OTA Provider application** + +``` +out/chip-ota-provider-app --discriminator 22 --secured-device-port 5565 --KVS /tmp/chip_kvs_provider --filepath /tmp/ota-image.bin +``` + +### In terminal 2: + +**Run the second OTA Provider application** + +``` +out/chip-ota-provider-app --discriminator 23 --secured-device-port 5566 --KVS /tmp/chip_kvs_provider2 --filepath /tmp/ota-image2.bin +``` + +### In terminal 3: + +**Build the OTA Requestor application** ``` scripts/examples/gn_build_example.sh examples/ota-requestor-app/linux/ out chip_config_network_layer_ble=false -out/chip-ota-requestor-app --discriminator 18 --secured-device-port 5560 --KVS /tmp/chip_kvs_requestor --otaDownloadPath /tmp/test.bin ``` -**Commission to the first fabric** +**Run the OTA Requestor application** ``` -out/chip-tool pairing onnetwork-long 0x1234567890 20202021 18 +out/chip-ota-requestor-app --discriminator 18 --secured-device-port 5560 --KVS /tmp/chip_kvs_requestor --periodicQueryTimeout 10 ``` -**Open Basic Commissioning Window** +### In terminal 4: + +**Commission the first OTA Provider into the first fabric (alpha)** ``` -out/chip-tool administratorcommissioning open-basic-commissioning-window 600 0x1234567890 0 --timedInteractionTimeoutMs 600 +out/chip-tool pairing onnetwork-long 0xC0FFEE 20202021 22 ``` -**Commission to the second fabric** +**Commission the second OTA Provider into the second fabric (beta)** ``` -out/chip-tool pairing onnetwork-long 0x858 20202021 18 --commissioner-name beta +out/chip-tool pairing onnetwork-long 0xB0BA 20202021 23 --commissioner-name beta ``` -For all operations, specify which fabric to use by passing in -`--commissioner-name`. The supported values are alpha, beta, and gamma. By -default, if none is supplied, alpha is used. +**Commission the OTA Requestor application into the first fabric (alpha)** + +``` +out/chip-tool pairing onnetwork-long 0xDEB 20202021 18 +``` + +**Open Basic Commissioning Window for the OTA Requestor application** + +``` +out/chip-tool administratorcommissioning open-basic-commissioning-window 600 0xDEB 0 --timedInteractionTimeoutMs 600 +``` + +**Commission the OTA Requestor application into the second fabric (beta)** + +``` +out/chip-tool pairing onnetwork-long 0xB0B 20202021 18 --commissioner-name beta +``` -**Write/Read DefaultOTAProviders on first fabric** +**Write/Read DefaultOTAProviders on the first fabric (alpha)** ``` -out/chip-tool otasoftwareupdaterequestor write default-ota-providers '[{"fabricIndex": 1, "providerNodeID": 3735928559, "endpoint": 0}]' 0x0000001234567890 0 -out/chip-tool otasoftwareupdaterequestor read default-ota-providers 0x1234567890 0 +out/chip-tool otasoftwareupdaterequestor write default-ota-providers '[{"providerNodeID": 12648430, "endpoint": 0}]' 0xDEB 0 +out/chip-tool otasoftwareupdaterequestor read default-ota-providers 0xDEB 0 ``` -**Write/Read DefaultOTAProviders on second fabric** +**Write/Read DefaultOTAProviders on second fabric (beta)** ``` -out/chip-tool otasoftwareupdaterequestor write default-ota-providers '[{"fabricIndex": 2, "providerNodeID": 1, "endpoint": 0}]' 0x858 0 --commissioner-name beta -out/chip-tool otasoftwareupdaterequestor read default-ota-providers 0x858 0 --commissioner-name beta +out/chip-tool otasoftwareupdaterequestor write default-ota-providers '[{"providerNodeID": 45242, "endpoint": 0}]' 0xB0B 0 --commissioner-name beta +out/chip-tool otasoftwareupdaterequestor read default-ota-providers 0xB0B 0 --commissioner-name beta ``` + +**Write ACL for the first OTA Provider application** + +``` +out/chip-tool accesscontrol write acl '[{"privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"privilege": 3, "authMode": 2, "subjects": null, "targets": [{"cluster": 41, "endpoint": null, "deviceType": null}]}]' 0xC0FFEE 0 +``` + +**Write ACL for the second OTA Provider application** + +``` +out/chip-tool accesscontrol write acl '[{"privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"privilege": 3, "authMode": 2, "subjects": null, "targets": [{"cluster": 41, "endpoint": null, "deviceType": null}]}]' 0xB0BA 0 --commissioner-name beta +``` + +NOTE: For all operations, specify which fabric to use by passing in +`--commissioner-name`. The supported values are alpha, beta, and gamma. By +default, if none is supplied, alpha is used. From 2d1f8a1eff8602f1f4ee85114d3d86accb25117d Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Sun, 5 Jun 2022 21:00:22 -0400 Subject: [PATCH 02/13] Don't reuse a commissionee device if it has the wrong device id. (#19141) Found during investigation of https://github.com/project-chip/connectedhomeip/issues/15409 but there may be more problems left in that issue. If we get into EstablishPASEConnection and find an existing commissionee for the peer address (which is easy for BLE, where the peer address is basically a singleton), but the device id does not match the passed-in one, we should not reuse that device. If we try to, Commission will fail to find the commissionee device by device id and fail out. --- src/controller/CHIPDeviceController.cpp | 33 +++++++++++++++---------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index 2e41add804e9c4..125c459c1e8471 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -556,24 +556,31 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re current = FindCommissioneeDevice(peerAddress); if (current != nullptr) { - - if (current->IsSecureConnected()) + if (current->GetDeviceId() == remoteDeviceId) { - if (mPairingDelegate) + // We might be able to just reuse its connection if it has one or is + // working on one. + if (current->IsSecureConnected()) { - // We already have an open secure session to this device, call the callback immediately and early return. - mPairingDelegate->OnPairingComplete(CHIP_NO_ERROR); + if (mPairingDelegate) + { + // We already have an open secure session to this device, call the callback immediately and early return. + mPairingDelegate->OnPairingComplete(CHIP_NO_ERROR); + } + return CHIP_NO_ERROR; + } + if (current->IsSessionSetupInProgress()) + { + // We're not connected yet, but we're in the process of connecting. Pairing delegate will get a callback when + // connection completes + return CHIP_NO_ERROR; } - return CHIP_NO_ERROR; - } - if (current->IsSessionSetupInProgress()) - { - // We're not connected yet, but we're in the process of connecting. Pairing delegate will get a callback when - // connection completes - return CHIP_NO_ERROR; } - // Something has gone strange. Delete the old device, try again. + // Either the consumer wants to assign a different device id to this + // peer address now (so we can't reuse the commissionee device we have + // already) or something has gone strange. Delete the old device, try + // again. ChipLogError(Controller, "Found unconnected device, removing"); ReleaseCommissioneeDevice(current); } From a8f12fa537d25efc0209fdaa2cb0a72a1eb2314b Mon Sep 17 00:00:00 2001 From: cpagravel Date: Mon, 6 Jun 2022 02:46:46 -0700 Subject: [PATCH 03/13] Fix broken Chef NRF build caused by #18955 (#19204) --- examples/chef/nrfconnect/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/chef/nrfconnect/CMakeLists.txt b/examples/chef/nrfconnect/CMakeLists.txt index 921458db215900..483f275bbdf2c8 100644 --- a/examples/chef/nrfconnect/CMakeLists.txt +++ b/examples/chef/nrfconnect/CMakeLists.txt @@ -122,6 +122,7 @@ set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo") include(${PIGWEED_ROOT}/pw_build/pigweed.cmake) include(${PIGWEED_ROOT}/pw_protobuf_compiler/proto.cmake) +pw_set_module_config(pw_rpc_CONFIG pw_rpc.disable_global_mutex_config) pw_set_backend(pw_log pw_log_basic) pw_set_backend(pw_assert pw_assert_log) pw_set_backend(pw_sys_io pw_sys_io.nrfconnect) From 0ef4a9d97f70cb0f409d6736ec9c79217b691153 Mon Sep 17 00:00:00 2001 From: doru91 Date: Mon, 6 Jun 2022 14:32:01 +0300 Subject: [PATCH 04/13] Move K32W0 PDM writes to the idle task (#18978) * [K32W0] Use PDM SaveOnIdle Lengthy flash operations are postponed on the idle task. Signed-off-by: Doru Gucea * Restyled by clang-format * Fix KVS Signed-off-by: Doru Gucea * Restyled by clang-format Co-authored-by: Restyled.io --- .../nxp/k32w/k32w0/main/AppTask.cpp | 2 - .../k32w/k32w0/app/support/FreeRtosHooks.c | 6 +- src/platform/nxp/k32w/k32w0/BUILD.gn | 2 + src/platform/nxp/k32w/k32w0/K32W0Config.cpp | 357 ++++++------------ src/platform/nxp/k32w/k32w0/K32W0Config.h | 16 +- .../k32w/k32w0/KeyValueStoreManagerImpl.cpp | 232 +++++------- src/platform/nxp/k32w/k32w0/RamStorage.cpp | 283 ++++++++++++++ src/platform/nxp/k32w/k32w0/RamStorage.h | 62 +++ .../nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh | 3 + .../k32w0_sdk/sdk_fixes/settings_k32w_c.patch | 11 + 10 files changed, 574 insertions(+), 400 deletions(-) create mode 100644 src/platform/nxp/k32w/k32w0/RamStorage.cpp create mode 100644 src/platform/nxp/k32w/k32w0/RamStorage.h create mode 100644 third_party/nxp/k32w0_sdk/sdk_fixes/settings_k32w_c.patch diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp index f5b14b9eb2a7e3..8d120eb6c5abaa 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp @@ -97,8 +97,6 @@ static OTAImageProcessorImpl gImageProcessor; constexpr uint16_t requestedOtaBlockSize = 1024; #endif -extern bool shouldReset; - CHIP_ERROR AppTask::StartAppTask() { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/examples/platform/nxp/k32w/k32w0/app/support/FreeRtosHooks.c b/examples/platform/nxp/k32w/k32w0/app/support/FreeRtosHooks.c index 8b94397ae7a39d..5bdb70c6ee21fc 100644 --- a/examples/platform/nxp/k32w/k32w0/app/support/FreeRtosHooks.c +++ b/examples/platform/nxp/k32w/k32w0/app/support/FreeRtosHooks.c @@ -27,6 +27,7 @@ #include #include +#include "PDM.h" #include "PWR_Interface.h" #include "TimersManager.h" #include "board.h" @@ -52,6 +53,8 @@ #define APP_DBG_LOG(...) #endif +#define PDM_MAX_WRITES_INFINITE 0xFF + static inline void mutex_init(mbedtls_threading_mutex_t * p_mutex) { assert(p_mutex != NULL); @@ -229,10 +232,11 @@ static void BOARD_ActionOnIdle(void) #endif } -extern void OTAIdleActivities(); +extern void OTAIdleActivities(void); void vApplicationIdleHook(void) { + PDM_vIdleTask(PDM_MAX_WRITES_INFINITE); OTAIdleActivities(); BOARD_ActionOnIdle(); } diff --git a/src/platform/nxp/k32w/k32w0/BUILD.gn b/src/platform/nxp/k32w/k32w0/BUILD.gn index e813d8253c48bd..dddeef7374b20a 100644 --- a/src/platform/nxp/k32w/k32w0/BUILD.gn +++ b/src/platform/nxp/k32w/k32w0/BUILD.gn @@ -47,6 +47,8 @@ static_library("k32w0") { "NFCManagerImpl.h", "PlatformManagerImpl.cpp", "PlatformManagerImpl.h", + "RamStorage.cpp", + "RamStorage.h", "ble_function_mux.c", ] diff --git a/src/platform/nxp/k32w/k32w0/K32W0Config.cpp b/src/platform/nxp/k32w/k32w0/K32W0Config.cpp index 6c8e4f9c1f2ad7..bab9d1eb2e618b 100644 --- a/src/platform/nxp/k32w/k32w0/K32W0Config.cpp +++ b/src/platform/nxp/k32w/k32w0/K32W0Config.cpp @@ -36,15 +36,26 @@ namespace chip { namespace DeviceLayer { namespace Internal { +static ramBufferDescriptor * ramDescr; + +constexpr uint16_t kNvmIdChipConfigData = 0x5000; +constexpr uint16_t kRamBufferInitialSize = 3072; + CHIP_ERROR K32WConfig::Init() { - CHIP_ERROR err; + CHIP_ERROR err = CHIP_NO_ERROR; int pdmStatus; /* Initialise the Persistent Data Manager */ pdmStatus = PDM_Init(); SuccessOrExit(err = MapPdmInitStatus(pdmStatus)); + ramDescr = getRamBuffer(kNvmIdChipConfigData, kRamBufferInitialSize); + if (!ramDescr) + { + err = CHIP_ERROR_NO_MEMORY; + } + exit: return err; } @@ -53,12 +64,12 @@ CHIP_ERROR K32WConfig::ReadConfigValue(Key key, bool & val) { CHIP_ERROR err; bool tempVal; - uint16_t bytesRead; - PDM_teStatus pdmStatus; + rsError status; + uint16_t sizeToRead = sizeof(tempVal); VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - pdmStatus = PDM_eReadDataFromRecord((uint16_t) key, &tempVal, sizeof(bool), &bytesRead); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); + status = ramStorageGet(ramDescr, key, 0, (uint8_t *) &tempVal, &sizeToRead); + SuccessOrExit(err = MapRamStorageStatus(status)); val = tempVal; exit: @@ -69,22 +80,13 @@ CHIP_ERROR K32WConfig::ReadConfigValue(Key key, uint32_t & val) { CHIP_ERROR err; uint32_t tempVal; - uint16_t bytesRead; - uint16_t recordSize; - PDM_teStatus pdmStatus; + rsError status; + uint16_t sizeToRead = sizeof(tempVal); VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - if (PDM_bDoesDataExist((uint16_t) key, &recordSize)) - { - pdmStatus = PDM_eReadDataFromRecord((uint16_t) key, &tempVal, sizeof(uint32_t), &bytesRead); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - val = tempVal; - } - else - { - err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - goto exit; - } + status = ramStorageGet(ramDescr, key, 0, (uint8_t *) &tempVal, &sizeToRead); + SuccessOrExit(err = MapRamStorageStatus(status)); + val = tempVal; exit: return err; @@ -93,24 +95,14 @@ CHIP_ERROR K32WConfig::ReadConfigValue(Key key, uint32_t & val) CHIP_ERROR K32WConfig::ReadConfigValue(Key key, uint64_t & val) { CHIP_ERROR err; - uint64_t tempVal; - uint16_t bytesRead; - uint16_t recordSize; - PDM_teStatus pdmStatus; + uint32_t tempVal; + rsError status; + uint16_t sizeToRead = sizeof(tempVal); VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - - if (PDM_bDoesDataExist((uint16_t) key, &recordSize)) - { - pdmStatus = PDM_eReadDataFromRecord((uint16_t) key, &tempVal, sizeof(uint64_t), &bytesRead); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - val = tempVal; - } - else - { - err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - goto exit; - } + status = ramStorageGet(ramDescr, key, 0, (uint8_t *) &tempVal, &sizeToRead); + SuccessOrExit(err = MapRamStorageStatus(status)); + val = tempVal; exit: return err; @@ -119,130 +111,44 @@ CHIP_ERROR K32WConfig::ReadConfigValue(Key key, uint64_t & val) CHIP_ERROR K32WConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen) { CHIP_ERROR err; - const uint8_t * strEnd; - char * pData = NULL; - uint16_t bytesRead; - uint16_t recordSize; - PDM_teStatus pdmStatus; - - outLen = 0; + rsError status; + uint16_t sizeToRead = bufSize; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - if (PDM_bDoesDataExist((uint16_t) key, &recordSize)) - { - pData = (char *) pvPortMalloc(recordSize); - VerifyOrExit((pData != NULL), err = CHIP_ERROR_NO_MEMORY); - - pdmStatus = PDM_eReadDataFromRecord((uint16_t) key, pData, recordSize, &bytesRead); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - - strEnd = (const uint8_t *) memchr(pData, 0, bytesRead); - VerifyOrExit(strEnd != NULL, err = CHIP_ERROR_INVALID_ARGUMENT); - - outLen = strEnd - (const uint8_t *) pData; - - // NOTE: the caller is allowed to pass NULL for buf to query the length of the stored value. - - if (buf != NULL) - { - VerifyOrExit(bufSize > outLen, err = CHIP_ERROR_BUFFER_TOO_SMALL); - - memcpy(buf, pData, outLen + 1); - } - } - else - { - err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - goto exit; - } + // We can call ramStorageGet with null pointer to only retrieve the size + status = ramStorageGet(ramDescr, key, 0, (uint8_t *) buf, &sizeToRead); + SuccessOrExit(err = MapRamStorageStatus(status)); + outLen = sizeToRead; exit: - if (pData != NULL) - { - vPortFree((void *) pData); - } return err; } CHIP_ERROR K32WConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen) { - CHIP_ERROR err; - uint8_t * pData = NULL; - uint16_t bytesRead; - uint16_t recordSize; - PDM_teStatus pdmStatus; - - outLen = 0; - - VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - - if (PDM_bDoesDataExist((uint16_t) key, &recordSize)) - { - pData = (uint8_t *) pvPortMalloc(recordSize); - VerifyOrExit((pData != NULL), err = CHIP_ERROR_NO_MEMORY); - - pdmStatus = PDM_eReadDataFromRecord((uint16_t) key, pData, recordSize, &bytesRead); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - - if (buf != NULL) - { - VerifyOrExit((bufSize >= bytesRead), err = CHIP_ERROR_BUFFER_TOO_SMALL); - memcpy(buf, pData, bytesRead); - } - outLen = bytesRead; - } - else - { - err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - goto exit; - } - -exit: - if (pData != NULL) - { - vPortFree((void *) pData); - } - - return err; + return ReadConfigValueStr(key, (char *) buf, bufSize, outLen); } CHIP_ERROR K32WConfig::ReadConfigValueCounter(uint8_t counterIdx, uint32_t & val) { - CHIP_ERROR err; - uint32_t tempVal; - uint16_t bytesRead; - uint16_t recordSize; - PDM_teStatus pdmStatus; - Key key = kMinConfigKey_ChipCounter + counterIdx; - VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - - if (PDM_bDoesDataExist((uint16_t) key, &recordSize)) - { - pdmStatus = PDM_eReadDataFromRecord((uint16_t) key, &tempVal, sizeof(uint32_t), &bytesRead); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - val = tempVal; - } - else - { - err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - goto exit; - } - -exit: - return err; + return ReadConfigValue(key, val); } CHIP_ERROR K32WConfig::WriteConfigValue(Key key, bool val) { CHIP_ERROR err; + rsError status; PDM_teStatus pdmStatus; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - pdmStatus = PDM_eSaveRecordData((uint16_t) key, &val, sizeof(bool)); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); + status = ramStorageSet(&ramDescr, key, (uint8_t *) &val, sizeof(bool)); + SuccessOrExit(err = MapRamStorageStatus(status)); + pdmStatus = + PDM_eSaveRecordDataInIdleTask((uint16_t) kNvmIdChipConfigData, ramDescr, ramDescr->ramBufferLen + kRamDescHeaderSize); + SuccessOrExit(err = MapPdmStatus(pdmStatus)); exit: return err; } @@ -250,10 +156,15 @@ CHIP_ERROR K32WConfig::WriteConfigValue(Key key, bool val) CHIP_ERROR K32WConfig::WriteConfigValue(Key key, uint32_t val) { CHIP_ERROR err; + rsError status; PDM_teStatus pdmStatus; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - pdmStatus = PDM_eSaveRecordData((uint16_t) key, &val, sizeof(uint32_t)); + status = ramStorageSet(&ramDescr, key, (uint8_t *) &val, sizeof(uint32_t)); + SuccessOrExit(err = MapRamStorageStatus(status)); + + pdmStatus = + PDM_eSaveRecordDataInIdleTask((uint16_t) kNvmIdChipConfigData, ramDescr, ramDescr->ramBufferLen + kRamDescHeaderSize); SuccessOrExit(err = MapPdmStatus(pdmStatus)); exit: @@ -263,10 +174,15 @@ CHIP_ERROR K32WConfig::WriteConfigValue(Key key, uint32_t val) CHIP_ERROR K32WConfig::WriteConfigValue(Key key, uint64_t val) { CHIP_ERROR err; + rsError status; PDM_teStatus pdmStatus; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - pdmStatus = PDM_eSaveRecordData((uint16_t) key, &val, sizeof(uint64_t)); + status = ramStorageSet(&ramDescr, key, (uint8_t *) &val, sizeof(uint64_t)); + SuccessOrExit(err = MapRamStorageStatus(status)); + + pdmStatus = + PDM_eSaveRecordDataInIdleTask((uint16_t) kNvmIdChipConfigData, ramDescr, ramDescr->ramBufferLen + kRamDescHeaderSize); SuccessOrExit(err = MapPdmStatus(pdmStatus)); exit: @@ -282,25 +198,18 @@ CHIP_ERROR K32WConfig::WriteConfigValueStr(Key key, const char * str, size_t str { CHIP_ERROR err; PDM_teStatus pdmStatus; + rsError status; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. if (str != NULL) { - uint8_t * pData = (uint8_t *) pvPortMalloc(strLen + 1); - - if (pData != NULL) - { - memcpy(pData, str, strLen); - pData[strLen] = '\0'; - pdmStatus = PDM_eSaveRecordData((uint16_t) key, (void *) pData, strLen + 1); - vPortFree((void *) pData); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - } - else - { - err = CHIP_ERROR_NO_MEMORY; - } + status = ramStorageSet(&ramDescr, key, (uint8_t *) str, strLen); + SuccessOrExit(err = MapRamStorageStatus(status)); + + pdmStatus = + PDM_eSaveRecordDataInIdleTask((uint16_t) kNvmIdChipConfigData, ramDescr, ramDescr->ramBufferLen + kRamDescHeaderSize); + SuccessOrExit(err = MapPdmStatus(pdmStatus)); } else { @@ -314,48 +223,28 @@ CHIP_ERROR K32WConfig::WriteConfigValueStr(Key key, const char * str, size_t str CHIP_ERROR K32WConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen) { - CHIP_ERROR err; - PDM_teStatus pdmStatus; - - VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - - if ((data != NULL) && (dataLen > 0)) - { - pdmStatus = PDM_eSaveRecordData((uint16_t) key, (void *) data, dataLen); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - } - else - { - err = ClearConfigValue(key); - SuccessOrExit(err); - } - -exit: - return err; + return WriteConfigValueStr(key, (char *) data, dataLen); } CHIP_ERROR K32WConfig::WriteConfigValueCounter(uint8_t counterIdx, uint32_t val) { - CHIP_ERROR err; - PDM_teStatus pdmStatus; - Key key = kMinConfigKey_ChipCounter + counterIdx; - VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - pdmStatus = PDM_eSaveRecordData((uint16_t) key, &val, sizeof(uint32_t)); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); - -exit: - return err; + return WriteConfigValue(key, val); } CHIP_ERROR K32WConfig::ClearConfigValue(Key key) { CHIP_ERROR err = CHIP_NO_ERROR; + rsError status; + PDM_teStatus pdmStatus; VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - PDM_vDeleteDataRecord((uint16_t) key); + status = ramStorageDelete(ramDescr, key, 0); + SuccessOrExit(err = MapRamStorageStatus(status)); - SuccessOrExit(err); + pdmStatus = + PDM_eSaveRecordDataInIdleTask((uint16_t) kNvmIdChipConfigData, ramDescr, ramDescr->ramBufferLen + kRamDescHeaderSize); + SuccessOrExit(err = MapPdmStatus(pdmStatus)); exit: return err; @@ -363,66 +252,73 @@ CHIP_ERROR K32WConfig::ClearConfigValue(Key key) bool K32WConfig::ConfigValueExists(Key key) { - CHIP_ERROR err; - uint16_t size = 0; - - VerifyOrExit(ValidConfigKey(key), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // Verify key id. - VerifyOrExit(PDM_bDoesDataExist((uint16_t) key, &size), err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); + rsError status; + uint16_t sizeToRead; + bool found = false; -exit: - // Return true if the record was found. - return (err == CHIP_NO_ERROR); + if (ValidConfigKey(key)) + { + status = ramStorageGet(ramDescr, key, 0, NULL, &sizeToRead); + found = (status == RS_ERROR_NONE && sizeToRead != 0); + } + return found; } CHIP_ERROR K32WConfig::FactoryResetConfig(void) { - CHIP_ERROR err; + CHIP_ERROR err = CHIP_NO_ERROR; + PDM_teStatus pdmStatus; - err = FactoryResetConfigInternal(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig); + FactoryResetConfigInternal(kMinConfigKey_ChipConfig, kMaxConfigKey_ChipConfig); + FactoryResetConfigInternal(kMinConfigKey_KVSKey, kMaxConfigKey_KVSKey); + FactoryResetConfigInternal(kMinConfigKey_KVSValue, kMaxConfigKey_KVSValue); - if (err == CHIP_NO_ERROR) - { - err = FactoryResetConfigInternal(kMinConfigKey_KVS, kMaxConfigKey_KVS); - } + pdmStatus = PDM_eSaveRecordData((uint16_t) kNvmIdChipConfigData, ramDescr, ramDescr->ramBufferLen + kRamDescHeaderSize); + SuccessOrExit(err = MapPdmStatus(pdmStatus)); +exit: return err; } -CHIP_ERROR K32WConfig::FactoryResetConfigInternal(Key firstKey, Key lastKey) +void K32WConfig::FactoryResetConfigInternal(Key firstKey, Key lastKey) { - CHIP_ERROR err; - - // Iterate over all the CHIP Config PDM ID records and delete each one - err = ForEachRecord(firstKey, lastKey, false, [](const Key & pdmKey, const size_t & length) -> CHIP_ERROR { - CHIP_ERROR err2; - - err2 = ClearConfigValue(pdmKey); - SuccessOrExit(err2); + for (Key key = firstKey; key <= lastKey; key++) + { + ramStorageDelete(ramDescr, key, 0); + } +} - exit: - return err2; - }); +CHIP_ERROR K32WConfig::MapPdmStatus(PDM_teStatus pdmStatus) +{ + CHIP_ERROR err; - // Return success at end of iterations. - if (err == CHIP_END_OF_INPUT) + switch (pdmStatus) { + case PDM_E_STATUS_OK: err = CHIP_NO_ERROR; + break; + default: + err = CHIP_ERROR(ChipError::Range::kPlatform, pdmStatus); + break; } return err; } -CHIP_ERROR K32WConfig::MapPdmStatus(PDM_teStatus pdmStatus) +CHIP_ERROR K32WConfig::MapRamStorageStatus(rsError rsStatus) { CHIP_ERROR err; - switch (pdmStatus) + switch (rsStatus) { - case PDM_E_STATUS_OK: + case RS_ERROR_NONE: err = CHIP_NO_ERROR; break; + case RS_ERROR_NOT_FOUND: + err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; + break; default: - err = CHIP_ERROR(ChipError::Range::kPlatform, pdmStatus); + err = CHIP_ERROR_BUFFER_TOO_SMALL; break; } @@ -437,8 +333,7 @@ CHIP_ERROR K32WConfig::MapPdmInitStatus(int pdmStatus) bool K32WConfig::ValidConfigKey(Key key) { // Returns true if the key is in the valid CHIP Config PDM key range. - - if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVS)) + if ((key >= kMinConfigKey_ChipFactory) && (key <= kMaxConfigKey_KVSValue)) { return true; } @@ -446,40 +341,6 @@ bool K32WConfig::ValidConfigKey(Key key) return false; } -CHIP_ERROR K32WConfig::ForEachRecord(Key firstKey, Key lastKey, bool addNewRecord, ForEachRecordFunct funct) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - for (Key pdmKey = firstKey; pdmKey <= lastKey; pdmKey++) - { - uint16_t dataLen; - - if (PDM_bDoesDataExist((uint16_t) pdmKey, &dataLen)) - { - if (!addNewRecord) - { - // Invoke the caller's function - // (for retrieve,store,delete,enumerate GroupKey operations). - err = funct(pdmKey, dataLen); - } - } - else - { - if (addNewRecord) - { - // Invoke caller's function - // (for add GroupKey operation). - err = funct(pdmKey, dataLen); - } - } - - SuccessOrExit(err); - } - -exit: - return err; -} - void K32WConfig::RunConfigUnitTest() {} } // namespace Internal diff --git a/src/platform/nxp/k32w/k32w0/K32W0Config.h b/src/platform/nxp/k32w/k32w0/K32W0Config.h index bae56b39845996..803149947a7a71 100644 --- a/src/platform/nxp/k32w/k32w0/K32W0Config.h +++ b/src/platform/nxp/k32w/k32w0/K32W0Config.h @@ -29,6 +29,7 @@ #include #include "PDM.h" +#include "RamStorage.h" namespace chip { namespace DeviceLayer { @@ -59,7 +60,9 @@ class K32WConfig * Cleared during factory reset. */ static constexpr uint8_t kPDMId_ChipCounter = 0x03; /**< PDM id for settings containing dynamic counter values set at runtime. * Retained during factory reset. */ - static constexpr uint8_t kPDMId_KVS = 0x04; /**< PDM id for settings containing KVS set at runtime. + static constexpr uint8_t kPDMId_KVSKey = 0x04; /**< PDM id for settings containing KVS keys set at runtime. + * Cleared during factory reset. */ + static constexpr uint8_t kPDMId_KVSValue = 0x05; /**< PDM id for settings containing KVS values set at runtime. * Cleared during factory reset. */ using Key = uint32_t; @@ -104,8 +107,10 @@ class K32WConfig static constexpr Key kMaxConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0xFF); static constexpr Key kMinConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0x00); static constexpr Key kMaxConfigKey_ChipCounter = K32WConfigKey(kPDMId_ChipCounter, 0xFF); // Allows 32 Counters to be created. - static constexpr Key kMinConfigKey_KVS = K32WConfigKey(kPDMId_KVS, 0x00); - static constexpr Key kMaxConfigKey_KVS = K32WConfigKey(kPDMId_KVS, 0xFF); + static constexpr Key kMinConfigKey_KVSKey = K32WConfigKey(kPDMId_KVSKey, 0x00); + static constexpr Key kMaxConfigKey_KVSKey = K32WConfigKey(kPDMId_KVSKey, 0xFF); + static constexpr Key kMinConfigKey_KVSValue = K32WConfigKey(kPDMId_KVSValue, 0x00); + static constexpr Key kMaxConfigKey_KVSValue = K32WConfigKey(kPDMId_KVSValue, 0xFF); static CHIP_ERROR Init(void); @@ -131,15 +136,14 @@ class K32WConfig static void RunConfigUnitTest(void); protected: - using ForEachRecordFunct = std::function; - static CHIP_ERROR ForEachRecord(Key firstKey, Key lastKey, bool addNewRecord, ForEachRecordFunct funct); static constexpr uint8_t GetPDMId(uint32_t key); static constexpr uint8_t GetRecordKey(uint32_t key); private: static CHIP_ERROR MapPdmStatus(PDM_teStatus pdmStatus); + static CHIP_ERROR MapRamStorageStatus(rsError rsStatus); static CHIP_ERROR MapPdmInitStatus(int pdmStatus); - static CHIP_ERROR FactoryResetConfigInternal(Key firstKey, Key lastKey); + static void FactoryResetConfigInternal(Key firstKey, Key lastKey); }; /** diff --git a/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp index cf30ee9a4c6eb1..3d2dd7374f0d90 100644 --- a/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp @@ -38,105 +38,65 @@ namespace DeviceLayer { namespace PersistedStorage { /* TODO: adjust these values */ -constexpr size_t kMaxNumberOfKeys = 125; +constexpr size_t kMaxNumberOfKeys = 150; constexpr size_t kMaxKeyValueBytes = 255; KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance; -/* hashmap having: - * - the matter key string as key; - * - internal PDM identifier as value; - */ -std::unordered_map g_kvs_map; - -/* set containing used PDM identifiers */ -std::set g_key_ids_set; - -/* used to check if we need to restore values from flash (e.g.: reset) */ -static bool g_restored_from_flash = false; - -CHIP_ERROR RestoreFromFlash() +uint16_t GetStringKeyId(const char * key, uint16_t * freeId) { - CHIP_ERROR err = CHIP_NO_ERROR; - uint8_t key_id = 0; - char key_string_id[kMaxKeyValueBytes] = { 0 }; - size_t key_string_id_size = 0; - uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS; - uint16_t pdm_internal_id = 0; - - if (g_restored_from_flash) - { - /* already restored from flash, nothing to do */ - return err; - } - - for (key_id = 0; key_id < kMaxNumberOfKeys; key_id++) + CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; + uint8_t keyId = 0; + uint8_t pdmIdKvsKey = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVSKey; + bool bFreeIdxFound = false; + char keyString[kMaxKeyValueBytes] = { 0 }; + size_t keyStringSize = 0; + uint16_t pdmInternalId; + + for (keyId = 0; keyId < kMaxNumberOfKeys; keyId++) { - /* key was saved as string in flash (key_string_id) using (key_id + kMaxNumberOfKeys) as PDM key - * value corresponding to key_string_id was saved in flash using key_id as PDM key - */ - - pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id + kMaxNumberOfKeys); - err = chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueStr(pdm_internal_id, key_string_id, kMaxKeyValueBytes, - key_string_id_size); - - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - err = CHIP_NO_ERROR; - continue; - } - else if (err != CHIP_NO_ERROR) - { - ChipLogProgress(DeviceLayer, "KVS, Error while restoring Matter key [%s] from flash with PDM id: %i", key_string_id, - pdm_internal_id); - return err; - } + pdmInternalId = chip::DeviceLayer::Internal::K32WConfigKey(pdmIdKvsKey, keyId); + err = + chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueStr(pdmInternalId, keyString, kMaxKeyValueBytes, keyStringSize); - if (key_string_id_size) + if (err == CHIP_NO_ERROR) { - g_key_ids_set.insert(key_id); - key_string_id_size = 0; - if (!g_kvs_map.insert(std::make_pair(std::string(key_string_id), key_id)).second) + if (strcmp(key, keyString) == 0) { - /* key collision is not expected when restoring from flash */ - ChipLogProgress(DeviceLayer, "KVS, Unexpected collision while restoring Matter key [%s] from flash with PDM id: %i", - key_string_id, pdm_internal_id); - } - else - { - ChipLogProgress(DeviceLayer, "KVS, restored Matter key [%s] from flash with PDM id: %i", key_string_id, - pdm_internal_id); + // found the entry we are looking for + break; } } + else if ((NULL != freeId) && (false == bFreeIdxFound)) + { + bFreeIdxFound = true; + *freeId = keyId; + } } - - g_restored_from_flash = true; - - return err; + return keyId; } CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size, size_t offset_bytes) { - CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS; - std::unordered_map::const_iterator it; - size_t read_bytes = 0; - uint8_t key_id = 0; - uint16_t pdm_internal_id = 0; + CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + uint8_t pdmIdKvsValue = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVSValue; + size_t read_bytes = 0; + uint8_t keyId = 0; + uint16_t pdmInternalId = 0; - VerifyOrExit((key != NULL) && (value != NULL) && (RestoreFromFlash() == CHIP_NO_ERROR), err = CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrExit((key != NULL) && (value != NULL), err = CHIP_ERROR_INVALID_ARGUMENT); - if ((it = g_kvs_map.find(key)) != g_kvs_map.end()) - { - key_id = it->second; - pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id); + keyId = GetStringKeyId(key, NULL); - err = - chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueBin(pdm_internal_id, (uint8_t *) value, value_size, read_bytes); + if (keyId < kMaxNumberOfKeys) + { + // This is the ID of the actual data + pdmInternalId = chip::DeviceLayer::Internal::K32WConfigKey(pdmIdKvsValue, keyId); + err = chip::DeviceLayer::Internal::K32WConfig::ReadConfigValueBin(pdmInternalId, (uint8_t *) value, value_size, read_bytes); *read_bytes_size = read_bytes; - ChipLogProgress(DeviceLayer, "KVS, get Matter key [%s] with PDM id: %i", key, pdm_internal_id); + ChipLogProgress(DeviceLayer, "KVS, get Matter key [%s] with PDM id: %i", key, pdmInternalId); } exit: @@ -145,69 +105,57 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) { - CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; - uint8_t key_id; - bool_t put_key = false; - uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS; - std::unordered_map::const_iterator it; - uint16_t pdm_internal_id = 0; - - VerifyOrExit((key != NULL) && (value != NULL) && (RestoreFromFlash() == CHIP_NO_ERROR), err = CHIP_ERROR_INVALID_ARGUMENT); - - if ((it = g_kvs_map.find(key)) == g_kvs_map.end()) /* new key */ - { - for (key_id = 0; key_id < kMaxNumberOfKeys; key_id++) - { - std::set::iterator iter = std::find(g_key_ids_set.begin(), g_key_ids_set.end(), key_id); + CHIP_ERROR err = CHIP_ERROR_INVALID_ARGUMENT; + bool_t putKey = false; + uint8_t pdmIdKvsKey = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVSKey; + uint8_t pdmIdKvsValue = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVSValue; + uint16_t pdmInternalId = 0; + uint16_t freeKeyId; + uint8_t keyId; - if (iter == g_key_ids_set.end()) - { - if (g_key_ids_set.size() >= kMaxNumberOfKeys) - { - return CHIP_ERROR_NO_MEMORY; - } + VerifyOrExit((key != NULL) && (value != NULL), err = CHIP_ERROR_INVALID_ARGUMENT); - g_key_ids_set.insert(key_id); + keyId = GetStringKeyId(key, &freeKeyId); - put_key = true; - break; - } - } + // Key already exists + if (keyId < kMaxNumberOfKeys) + { + // Update just the value in this case + putKey = false; } - else /* overwrite key */ + else { - put_key = true; - key_id = it->second; + // Need to write both the value and the string key + putKey = true; + keyId = freeKeyId; } - if (put_key) - { - pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id); - ChipLogProgress(DeviceLayer, "KVS, save in flash the value of the Matter key [%s] with PDM id: %i", key, pdm_internal_id); + pdmInternalId = chip::DeviceLayer::Internal::K32WConfigKey(pdmIdKvsValue, keyId); + ChipLogProgress(DeviceLayer, "KVS, save in flash the value of the Matter key [%s] with PDM id: %i", key, pdmInternalId); - g_kvs_map.insert(std::make_pair(std::string(key), key_id)); - err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueBin(pdm_internal_id, (uint8_t *) value, value_size); + err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueBin(pdmInternalId, (uint8_t *) value, value_size); - /* save the 'key' in flash such that it can be retrieved later on */ - if (err == CHIP_NO_ERROR) + /* save the 'key' in flash such that it can be retrieved later on */ + if (err == CHIP_NO_ERROR) + { + if (true == putKey) { - pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id + kMaxNumberOfKeys); - ChipLogProgress(DeviceLayer, "KVS, save in flash the Matter key [%s] with PDM id: %i", key, pdm_internal_id); + pdmInternalId = chip::DeviceLayer::Internal::K32WConfigKey(pdmIdKvsKey, keyId); + ChipLogProgress(DeviceLayer, "KVS, save in flash the Matter key [%s] with PDM id: %i", key, pdmInternalId); - /* TODO (MATTER-132): do we need to make sure that "key" is NULL-terminated? */ - err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueStr(pdm_internal_id, key, strlen(key) + 1); + err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueStr(pdmInternalId, key, strlen(key) + 1); if (err != CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, "KVS, Error while saving in flash the Matter key [%s] with PDM id: %i", key, - pdm_internal_id); + pdmInternalId); } } - else - { - ChipLogProgress(DeviceLayer, "KVS, Error while saving in flash the value of the Matter key [%s] with PDM id: %i", key, - pdm_internal_id); - } + } + else + { + ChipLogProgress(DeviceLayer, "KVS, Error while saving in flash the value of the Matter key [%s] with PDM id: %i", key, + pdmInternalId); } exit: @@ -216,48 +164,46 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) { - CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; - std::unordered_map::const_iterator it; - uint8_t pdm_id_kvs = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVS; - uint8_t key_id = 0; - uint16_t pdm_internal_id = 0; + CHIP_ERROR err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND; + uint8_t pdmIdKvsKey = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVSKey; + uint8_t pdmIdKvsValue = chip::DeviceLayer::Internal::K32WConfig::kPDMId_KVSValue; + uint8_t keyId = 0; + uint16_t pdmInternalId = 0; - VerifyOrExit((key != NULL) && (RestoreFromFlash() == CHIP_NO_ERROR), err = CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrExit((key != NULL), err = CHIP_ERROR_INVALID_ARGUMENT); - if ((it = g_kvs_map.find(key)) != g_kvs_map.end()) - { - key_id = it->second; - pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id); + keyId = GetStringKeyId(key, NULL); - g_key_ids_set.erase(key_id); - g_kvs_map.erase(it); + if (keyId < kMaxNumberOfKeys) + { + // entry exists so we can remove it + pdmInternalId = chip::DeviceLayer::Internal::K32WConfigKey(pdmIdKvsKey, keyId); - ChipLogProgress(DeviceLayer, "KVS, delete from flash the Matter key [%s] with PDM id: %i", key, pdm_internal_id); - err = chip::DeviceLayer::Internal::K32WConfig::ClearConfigValue(pdm_internal_id); + ChipLogProgress(DeviceLayer, "KVS, delete from flash the Matter key [%s] with PDM id: %i", key, pdmInternalId); + err = chip::DeviceLayer::Internal::K32WConfig::ClearConfigValue(pdmInternalId); /* also delete the 'key string' from flash */ if (err == CHIP_NO_ERROR) { - pdm_internal_id = chip::DeviceLayer::Internal::K32WConfigKey(pdm_id_kvs, key_id + kMaxNumberOfKeys); + pdmInternalId = chip::DeviceLayer::Internal::K32WConfigKey(pdmIdKvsValue, keyId); ChipLogProgress(DeviceLayer, "KVS, delete from flash the value of the Matter key [%s] with PDM id: %i", key, - pdm_internal_id); + pdmInternalId); - err = chip::DeviceLayer::Internal::K32WConfig::ClearConfigValue(pdm_internal_id); + err = chip::DeviceLayer::Internal::K32WConfig::ClearConfigValue(pdmInternalId); if (err != CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, "KVS, Error while deleting from flash the value of the Matter key [%s] with PDM id: %i", key, - pdm_internal_id); + pdmInternalId); } } else { ChipLogProgress(DeviceLayer, "KVS, Error while deleting from flash the Matter key [%s] with PDM id: %i", key, - pdm_internal_id); + pdmInternalId); } } - exit: return err; } diff --git a/src/platform/nxp/k32w/k32w0/RamStorage.cpp b/src/platform/nxp/k32w/k32w0/RamStorage.cpp new file mode 100644 index 00000000000000..4d23aa7024ad64 --- /dev/null +++ b/src/platform/nxp/k32w/k32w0/RamStorage.cpp @@ -0,0 +1,283 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * NVM Writes are time-consuming so instead of blocking the main tasks (e.g.: Matter) + * buffer the writes in a RAM buffer that gets to be written in the Idle Task + */ +#include +#include +#include + +#include "FunctionLib.h" +#include "RamStorage.h" + +#ifndef RAM_STORAGE_LOG +#define RAM_STORAGE_LOG 0 +#endif + +#include + +#if RAM_STORAGE_LOG +#include "fsl_debug_console.h" +#define RAM_STORAGE_PRINTF(...) \ + PRINTF("[%s] ", __FUNCTION__); \ + PRINTF(__VA_ARGS__); \ + PRINTF("\n\r"); +#else +#define RAM_STORAGE_PRINTF(...) +#endif + +/* increment size for dynamic memory re-allocation in case the + * initial RAM buffer size gets insufficient + */ +constexpr size_t kRamBufferReallocSize = 512; +constexpr size_t kRamBufferMaxAllocSize = 10240; + +ramBufferDescriptor * getRamBuffer(uint16_t nvmId, uint16_t initialSize) +{ + ramBufferDescriptor * ramDescr = NULL; + bool bLoadDataFromNvm = false; + uint16_t bytesRead = 0; + uint16_t recordSize = 0; + uint16_t allocSize = initialSize; + + /* Check if dataset is present and get its size */ + if (PDM_bDoesDataExist(nvmId, &recordSize)) + { + bLoadDataFromNvm = true; + while (recordSize > allocSize) + { + // increase size until NVM data fits + allocSize += kRamBufferReallocSize; + } + } + + if (allocSize <= kRamBufferMaxAllocSize) + { + ramDescr = (ramBufferDescriptor *) malloc(allocSize); + if (ramDescr) + { + ramDescr->ramBufferLen = 0; + ramDescr->ramBufferMaxLen = allocSize - kRamDescHeaderSize; + + if (bLoadDataFromNvm) + { + /* Try to load the dataset in RAM */ + if (PDM_E_STATUS_OK != PDM_eReadDataFromRecord(nvmId, ramDescr, recordSize, &bytesRead)) + { + memset(ramDescr, 0, allocSize); + } + } + } + } + + return ramDescr; +} + +static rsError ramStorageAdd(ramBufferDescriptor * pBuffer, uint16_t aKey, const uint8_t * aValue, uint16_t aValueLength) +{ + rsError error = RS_ERROR_NONE; + struct settingsBlock currentBlock = { 0 }; + const uint16_t newBlockLength = sizeof(settingsBlock) + aValueLength; + + if (pBuffer->ramBufferLen + newBlockLength <= pBuffer->ramBufferMaxLen) + { + currentBlock.key = aKey; + currentBlock.length = aValueLength; + + memcpy(&pBuffer->pRamBuffer[pBuffer->ramBufferLen], ¤tBlock, sizeof(settingsBlock)); + memcpy(&pBuffer->pRamBuffer[pBuffer->ramBufferLen + sizeof(settingsBlock)], aValue, aValueLength); + pBuffer->ramBufferLen += newBlockLength; + + error = RS_ERROR_NONE; + } + else + { + error = RS_ERROR_NO_BUFS; + } + + RAM_STORAGE_PRINTF("key = %d lengthWriten = %d err = %d", aKey, aValueLength, error); + + return error; +} + +rsError ramStorageGet(const ramBufferDescriptor * pBuffer, uint16_t aKey, int aIndex, uint8_t * aValue, uint16_t * aValueLength) +{ + uint16_t i = 0; + uint16_t valueLength = 0; + uint16_t readLength = 0; + int currentIndex = 0; + struct settingsBlock currentBlock = { 0 }; + rsError error = RS_ERROR_NOT_FOUND; + + while (i < pBuffer->ramBufferLen) + { + memcpy(¤tBlock, &pBuffer->pRamBuffer[i], sizeof(settingsBlock)); + + if (aKey == currentBlock.key) + { + if (currentIndex == aIndex) + { + readLength = currentBlock.length; + + // Perform read only if an input buffer was passed in + if (aValue != NULL && aValueLength != NULL) + { + // Adjust read length if input buffer size is smaller + if (readLength > *aValueLength) + { + readLength = *aValueLength; + } + + memcpy(aValue, &pBuffer->pRamBuffer[i + sizeof(settingsBlock)], readLength); + } + + valueLength = currentBlock.length; + error = RS_ERROR_NONE; + break; + } + + currentIndex++; + } + + i += sizeof(settingsBlock) + currentBlock.length; + } + + if (aValueLength != NULL) + { + *aValueLength = valueLength; + } + + RAM_STORAGE_PRINTF("key = %d err = %d", aKey, error); + + return error; +} + +static rsError ramStorageSetInternal(ramBufferDescriptor * pBuffer, uint16_t aKey, const uint8_t * aValue, uint16_t aValueLength) +{ + uint16_t i = 0; + uint16_t currentBlockLength = 0; + uint16_t nextBlockStart = 0; + struct settingsBlock currentBlock = { 0 }; + + // Delete all entries of aKey + while (i < pBuffer->ramBufferLen) + { + memcpy(¤tBlock, &pBuffer->pRamBuffer[i], sizeof(settingsBlock)); + currentBlockLength = sizeof(settingsBlock) + currentBlock.length; + + if (aKey == currentBlock.key) + { + nextBlockStart = i + currentBlockLength; + + if (nextBlockStart < pBuffer->ramBufferLen) + { + memmove(&pBuffer->pRamBuffer[i], &pBuffer->pRamBuffer[nextBlockStart], pBuffer->ramBufferLen - nextBlockStart); + } + + VerifyOrDie(pBuffer->ramBufferLen >= currentBlockLength); + pBuffer->ramBufferLen -= currentBlockLength; + } + else + { + i += currentBlockLength; + } + } + + return ramStorageAdd(pBuffer, aKey, aValue, aValueLength); +} + +rsError ramStorageSet(ramBufferDescriptor ** pBuffer, uint16_t aKey, const uint8_t * aValue, uint16_t aValueLength) +{ + rsError err = RS_ERROR_NONE; + uint16_t allocSize = (*pBuffer)->ramBufferMaxLen; + ramBufferDescriptor * ptr = NULL; + + if (allocSize <= (*pBuffer)->ramBufferLen + aValueLength) + { + while ((allocSize < (*pBuffer)->ramBufferLen + aValueLength)) + { + /* Need to realocate the memory buffer, increase size by kRamBufferReallocSize until NVM data fits */ + allocSize += kRamBufferReallocSize; + } + + allocSize += kRamDescHeaderSize; + + if (kRamBufferMaxAllocSize <= kRamBufferMaxAllocSize) + { + ptr = (ramBufferDescriptor *) realloc((void *) (*pBuffer), allocSize); + VerifyOrExit((NULL != ptr), err = RS_ERROR_NO_BUFS); + *pBuffer = ptr; + (*pBuffer)->ramBufferMaxLen = allocSize; + } + else + { + err = RS_ERROR_NO_BUFS; + } + } + + err = ramStorageSetInternal(*pBuffer, aKey, aValue, aValueLength); + +exit: + return err; +} + +rsError ramStorageDelete(ramBufferDescriptor * pBuffer, uint16_t aKey, int aIndex) +{ + uint16_t i = 0; + int currentIndex = 0; + uint16_t nextBlockStart = 0; + uint16_t currentBlockLength = 0; + struct settingsBlock currentBlock = { 0 }; + rsError error = RS_ERROR_NOT_FOUND; + + while (i < pBuffer->ramBufferLen) + { + memcpy(¤tBlock, &pBuffer->pRamBuffer[i], sizeof(settingsBlock)); + currentBlockLength = sizeof(settingsBlock) + currentBlock.length; + + if (aKey == currentBlock.key) + { + if (currentIndex == aIndex) + { + nextBlockStart = i + currentBlockLength; + + if (nextBlockStart < pBuffer->ramBufferLen) + { + memmove(&pBuffer->pRamBuffer[i], &pBuffer->pRamBuffer[nextBlockStart], pBuffer->ramBufferLen - nextBlockStart); + } + + VerifyOrDie(pBuffer->ramBufferLen >= currentBlockLength); + pBuffer->ramBufferLen -= currentBlockLength; + + error = RS_ERROR_NONE; + break; + } + else + { + currentIndex++; + } + } + + i += currentBlockLength; + } + RAM_STORAGE_PRINTF("key = %d err = %d", aKey, error); + return error; +} diff --git a/src/platform/nxp/k32w/k32w0/RamStorage.h b/src/platform/nxp/k32w/k32w0/RamStorage.h new file mode 100644 index 00000000000000..b1bc0ea3ad2ad6 --- /dev/null +++ b/src/platform/nxp/k32w/k32w0/RamStorage.h @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +typedef enum +{ + RS_ERROR_NONE, + RS_ERROR_NOT_FOUND, + RS_ERROR_NO_BUFS +} rsError; + +/* the structure used for keeping the records has the same structure both in RAM and in NVM: + * ramBufferLen | ramBufferMaxLen | settingsBlock | .... | settingsBlock + * + * ramBufferLen shows how much of the RAM buffer is currently occupied with settingsBlock structures + * ramBufferMaxLen shows the total malloc'ed size. Dynamic re-allocation is possible + */ +typedef struct +{ + uint16_t ramBufferLen; + uint16_t ramBufferMaxLen; + uint8_t pRamBuffer[1]; +} ramBufferDescriptor; + +struct settingsBlock +{ + uint16_t key; + uint16_t length; +} __attribute__((packed)); + +#define member_size(type, member) sizeof(((type *) 0)->member) + +constexpr size_t kRamDescHeaderSize = + member_size(ramBufferDescriptor, ramBufferLen) + member_size(ramBufferDescriptor, ramBufferMaxLen); + +/* Return a RAM buffer with initialSize and populated with the contents of NVM ID - if found in flash */ +ramBufferDescriptor * getRamBuffer(uint16_t nvmId, uint16_t initialSize); + +/* search pBuffer for aKey and return its value in aValue. aValueLength will contain the length of aValueLength */ +rsError ramStorageGet(const ramBufferDescriptor * pBuffer, uint16_t aKey, int aIndex, uint8_t * aValue, uint16_t * aValueLength); + +/* search pBuffer for aKey and set its value to aValue (having aValueLength length) */ +rsError ramStorageSet(ramBufferDescriptor ** pBuffer, uint16_t aKey, const uint8_t * aValue, uint16_t aValueLength); + +/* search pBuffer for aKey and delete it */ +rsError ramStorageDelete(ramBufferDescriptor * pBuffer, uint16_t aKey, int aIndex); diff --git a/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh b/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh index 324199c6db7f5a..6566feb72700bc 100755 --- a/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh +++ b/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh @@ -40,6 +40,9 @@ patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/Flash convert_to_dos "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/MemManager/Interface/MemManager.h patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/MemManager/Interface -p1 <"$SOURCE_DIR/MemManager_h.patch" +#internal: THREADIP-3660 +patch -N --binary -d ./third_party/openthread/ot-nxp/src/k32w0/platform -p1 <"$SOURCE_DIR/settings_k32w_c.patch" + SIGN_FILE_PATH="$NXP_K32W061_SDK_ROOT"/tools/imagetool/sign_images.sh convert_to_dos "$SIGN_FILE_PATH" patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/tools/imagetool/ -p1 <"$SOURCE_DIR/sign_images_sh.patch" diff --git a/third_party/nxp/k32w0_sdk/sdk_fixes/settings_k32w_c.patch b/third_party/nxp/k32w0_sdk/sdk_fixes/settings_k32w_c.patch new file mode 100644 index 00000000000000..08571a4d66b795 --- /dev/null +++ b/third_party/nxp/k32w0_sdk/sdk_fixes/settings_k32w_c.patch @@ -0,0 +1,11 @@ +--- a/settings_k32w.c ++++ b/settings_k32w.c +@@ -52,7 +52,7 @@ + #define NVM_START_ID 0x4F00 + + /* WARNING - the defines below must be in sync with OT NVM datasets from Settings.hpp */ +-#define NVM_MAX_ID 7 ++#define NVM_MAX_ID 20 + + static uint8_t sPdmBuffer[pdmBufferSize] __attribute__((aligned(4))) = {0}; + From 090f75c967f37eb5d9f9c9b7121753e9e3638cf4 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Mon, 6 Jun 2022 09:10:42 -0400 Subject: [PATCH 05/13] Update submodule (#19222) --- third_party/efr32_sdk/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/efr32_sdk/repo b/third_party/efr32_sdk/repo index fe333c141368e2..c48b8de1bed36c 160000 --- a/third_party/efr32_sdk/repo +++ b/third_party/efr32_sdk/repo @@ -1 +1 @@ -Subproject commit fe333c141368e2cb393526c2708d0cdecec06ad3 +Subproject commit c48b8de1bed36cc57dd8caba94ecda8a7352524c From 9c1660c7b202b1d246c3baa0e9bef6386c010678 Mon Sep 17 00:00:00 2001 From: Jakub Date: Mon, 6 Jun 2022 15:12:52 +0200 Subject: [PATCH 06/13] [Tizen] Vscode compile commands support (#19155) * Use tizen_sdk_sysroot instead of sysroot arg during tizen build. * Fix tizen sdk build to support toolchain output dir * Add Tizen builds optionally to unified build * Add generation of compile_commands for tizen platform * Add compile_commands path to intellisense configuration * Add GN Language Server * Fix unit integration test --- .devcontainer/devcontainer.json | 3 ++- .vscode/c_cpp_properties.json | 1 + BUILD.gn | 14 ++++++++++++++ build/config/sysroot.gni | 2 ++ build/config/tizen/config.gni | 3 +++ build/config/tizen/tizen_sysroot.gni | 18 ++++++++++++++++++ examples/lighting-app/tizen/README.md | 2 +- gn_build.sh | 14 ++++++++++++++ scripts/build/builders/tizen.py | 2 +- .../build/testdata/build_all_except_host.txt | 16 ++++++++-------- scripts/helpers/update_compile_commands.sh | 3 +++ third_party/tizen/tizen_sdk.gni | 4 ++-- 12 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 build/config/tizen/tizen_sysroot.gni diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2e8c6507588deb..ba21e5e4402d30 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -38,7 +38,8 @@ "christian-kohler.path-intellisense", "knisterpeter.vscode-github", "npclaudiu.vscode-gn", - "marus25.cortex-debug" + "marus25.cortex-debug", + "msedge-dev.gnls" ], // Use 'settings' to set *default* container specific settings.json values on container create. // You can edit these settings after create using File > Preferences > Settings > Remote. diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 02040c430cdcf6..425b49fdf84ae3 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -89,6 +89,7 @@ "cppStandard": "gnu++14", "intelliSenseMode": "gcc-arm", "compilerPath": "/opt/tizen-sdk/tools/arm-linux-gnueabi-gcc-9.2/bin/arm-linux-gnueabi-gcc", + "compileCommands": "${workspaceFolder}/out/debug/compile_commands.tizen_arm.json", "browse": { "path": ["${workspaceFolder}/out/debug/"], "limitSymbolsToIncludedHeaders": true diff --git a/BUILD.gn b/BUILD.gn index f126d387ca8291..8f67da4dca7739 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -178,6 +178,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") { # Enable building for Android. enable_android_builds = false + # Enable building for Tizen. + enable_tizen_builds = false + # Set this to true to enable TI builds by default. enable_ti_simplelink_builds = false @@ -284,6 +287,8 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") { enable_bl602_lighting_app_build = enable_bl602_builds enable_fake_tests = enable_default_builds && host_os == "linux" + + enable_tizen_lighting_app = enable_tizen_builds } if (enable_host_clang_build) { @@ -468,6 +473,12 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") { } } + if (enable_tizen_lighting_app) { + group("tizen_lighting_app") { + deps = [ "${chip_root}/examples/lighting-app/tizen/(${chip_root}/build/toolchain/tizen:tizen_arm)" ] + } + } + group("default") { deps = [] if (enable_host_clang_build) { @@ -487,6 +498,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") { ":android_x86", ] } + if (enable_tizen_builds) { + deps += [ ":tizen_lighting_app" ] + } if (enable_standalone_chip_cert_build) { deps += [ ":standalone_chip_cert" ] } diff --git a/build/config/sysroot.gni b/build/config/sysroot.gni index bf2669f0a469b0..8c5d105c76e4cd 100644 --- a/build/config/sysroot.gni +++ b/build/config/sysroot.gni @@ -26,6 +26,8 @@ if (sysroot_platform_config == "") { sysroot_platform_config = "${build_root}/config/webos/webos_sysroot.gni" } else if (is_clang && current_cpu == "arm" && current_os == "freertos") { sysroot_platform_config = "${build_root}/toolchain/arm/arm_sysroot.gni" + } else if (current_os == "tizen") { + sysroot_platform_config = "${build_root}/config/tizen/tizen_sysroot.gni" } } diff --git a/build/config/tizen/config.gni b/build/config/tizen/config.gni index eb3be358bbf6a7..585a889ccfbffd 100644 --- a/build/config/tizen/config.gni +++ b/build/config/tizen/config.gni @@ -13,6 +13,9 @@ # limitations under the License. declare_args() { + # Location of The Tizen sysroot + tizen_sdk_sysroot = "" + # Location of the Tizen SDK. tizen_sdk_root = "" } diff --git a/build/config/tizen/tizen_sysroot.gni b/build/config/tizen/tizen_sysroot.gni new file mode 100644 index 00000000000000..ab2943869d061d --- /dev/null +++ b/build/config/tizen/tizen_sysroot.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") +import("${build_root}/config/tizen/config.gni") + +sysroot = tizen_sdk_sysroot diff --git a/examples/lighting-app/tizen/README.md b/examples/lighting-app/tizen/README.md index d2063a7a55977c..f2707b0e3f318f 100644 --- a/examples/lighting-app/tizen/README.md +++ b/examples/lighting-app/tizen/README.md @@ -15,7 +15,7 @@ gn gen --check \ --fail-on-unused-args \ --export-compile-commands \ --root=$PW_PROJECT_ROOT/examples/lighting-app/tizen \ - "--args=target_os=\"tizen\" target_cpu=\"arm\" tizen_sdk_root=\"$TIZEN_SDK_ROOT\" sysroot=\"$TIZEN_SDK_SYSROOT\"" \ + "--args=target_os=\"tizen\" target_cpu=\"arm\" tizen_sdk_root=\"$TIZEN_SDK_ROOT\" tizen_sdk_sysroot=\"$TIZEN_SDK_SYSROOT\"" \ $PW_PROJECT_ROOT/out/tizen-arm-light ``` diff --git a/gn_build.sh b/gn_build.sh index 35fbb41cf23f5b..86e2ff6889c6d3 100755 --- a/gn_build.sh +++ b/gn_build.sh @@ -192,6 +192,20 @@ fi echo +tizen_sdk_args="" + +if [[ -d "${TIZEN_SDK_ROOT}" && -d "${TIZEN_SDK_SYSROOT}" ]]; then + tizen_sdk_args+="tizen_sdk_root=\"$TIZEN_SDK_ROOT\" tizen_sdk_sysroot=\"$TIZEN_SDK_SYSROOT\"" + extra_args+=" $tizen_sdk_args enable_tizen_builds=true" +else + echo + echo "Hint: Set \$TIZEN_SDK_ROOT and \$TIZEN_SDK_SYSROOT to enable building for Tizen" + echo " Required Tizen SDK can be obtained from" + echo " https://developer.tizen.org/development/tizen-studio/download" +fi + +echo + _chip_banner "Build: GN configure" gn --root="$CHIP_ROOT" gen --check --fail-on-unused-args "$CHIP_ROOT/out/debug" --args='target_os="all"'"$extra_args$user_args" diff --git a/scripts/build/builders/tizen.py b/scripts/build/builders/tizen.py index efaf444a8568a4..29d6672ccc19d6 100644 --- a/scripts/build/builders/tizen.py +++ b/scripts/build/builders/tizen.py @@ -105,7 +105,7 @@ def GnBuildArgs(self): 'target_os="tizen"', 'target_cpu="%s"' % self.board.TargetCpuName(), 'tizen_sdk_root="%s"' % os.environ['TIZEN_SDK_ROOT'], - 'sysroot="%s"' % os.environ['TIZEN_SDK_SYSROOT'], + 'tizen_sdk_sysroot="%s"' % os.environ['TIZEN_SDK_SYSROOT'], ] def _generate_flashbundle(self): diff --git a/scripts/build/testdata/build_all_except_host.txt b/scripts/build/testdata/build_all_except_host.txt index 4ca17313e493aa..12ee5aa27f27f5 100644 --- a/scripts/build/testdata/build_all_except_host.txt +++ b/scripts/build/testdata/build_all_except_host.txt @@ -1117,28 +1117,28 @@ source "$ZEPHYR_BASE/zephyr-env.sh"; west build --cmake-only -d {out}/telink-tlsr9518adk80d-light-switch -b tlsr9518adk80d {root}/examples/light-switch-app/telink' # Generating tizen-arm-light -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light # Generating tizen-arm-light-asan -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-asan # Generating tizen-arm-light-no-ble -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble # Generating tizen-arm-light-no-ble-asan -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble-asan # Generating tizen-arm-light-no-ble-no-wifi -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false chip_enable_wifi=false target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble-no-wifi +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false chip_enable_wifi=false target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble-no-wifi # Generating tizen-arm-light-no-ble-no-wifi-asan -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false chip_enable_wifi=false is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble-no-wifi-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_config_network_layer_ble=false chip_enable_wifi=false is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-ble-no-wifi-asan # Generating tizen-arm-light-no-wifi -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_enable_wifi=false target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-wifi +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_enable_wifi=false target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-wifi # Generating tizen-arm-light-no-wifi-asan -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_enable_wifi=false is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-wifi-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/tizen '--args=chip_enable_wifi=false is_asan=true target_os="tizen" target_cpu="arm" tizen_sdk_root="TEST_TIZEN_SDK_ROOT" tizen_sdk_sysroot="TEST_TIZEN_SDK_SYSROOT"' {out}/tizen-arm-light-no-wifi-asan # Building ameba-amebad-all-clusters ninja -C {out}/ameba-amebad-all-clusters diff --git a/scripts/helpers/update_compile_commands.sh b/scripts/helpers/update_compile_commands.sh index 0c07af40ac6c5c..15b03c1799a0d7 100755 --- a/scripts/helpers/update_compile_commands.sh +++ b/scripts/helpers/update_compile_commands.sh @@ -40,3 +40,6 @@ mv "$CHIP_ROOT/out/debug/compile_commands.json" "$CHIP_ROOT/out/debug/compile_co gn --root="$CHIP_ROOT" gen "$CHIP_ROOT/out/debug" --export-compile-commands=efr32_lock_app mv "$CHIP_ROOT/out/debug/compile_commands.json" "$CHIP_ROOT/out/debug/compile_commands.efr32.json" + +gn --root="$CHIP_ROOT" gen "$CHIP_ROOT/out/debug" --export-compile-commands=tizen_lighting_app +mv "$CHIP_ROOT/out/debug/compile_commands.json" "$CHIP_ROOT/out/debug/compile_commands.tizen_arm.json" diff --git a/third_party/tizen/tizen_sdk.gni b/third_party/tizen/tizen_sdk.gni index dc17cf701fc762..05484aed50be3c 100644 --- a/third_party/tizen/tizen_sdk.gni +++ b/third_party/tizen/tizen_sdk.gni @@ -63,7 +63,7 @@ template("tizen_sdk_package") { # Output directory where packaging will occur. We need a separate directory # for this, because Tizen Studio CLI scans "res" (resources), "shared" and # "lib" directories for items to pack. In our case it could include in the - # TPK package libraries available in ${root_build_dir}/lib directory. + # TPK package libraries available in ${root_out_dir}/lib directory. tizen_package_dir = "${root_build_dir}/package" tizen_package_out_dir = "${tizen_package_dir}/out" @@ -94,7 +94,7 @@ template("tizen_sdk_package") { if (manifest_apps["service"] != "") { dependencies += [ ":${target_name}:app:service" ] copy("${target_name}:app:service") { - sources = [ root_build_dir + "/" + manifest_apps["service"] ] + sources = [ root_out_dir + "/" + manifest_apps["service"] ] outputs = [ "${tizen_package_out_dir}/{{source_file_part}}" ] deps = invoker.deps } From 94c51bb34903f7310ad0901cb122a4f61ff1c1af Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 6 Jun 2022 10:12:52 -0400 Subject: [PATCH 07/13] Fix typos in build script for constants of app types (#19232) * Fix constant typo in lighting app (for artifact generation) * fix two more typos in constants --- scripts/build/builders/host.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 77903cd64ca7e8..19e20724625e8a 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -140,13 +140,13 @@ def OutputNames(self): yield 'controller/python' # Directory containing WHL files elif self == HostApp.NL_TEST_RUNNER: yield 'chip_nl_test_runner_wheels' - elif self == HostApp.LIGHTING: + elif self == HostApp.LIGHT: yield 'chip-lighting-app' yield 'chip-lighting-app.map' - elif self == HostApp.TV_CASTING_APP: + elif self == HostApp.TV_CASTING: yield 'chip-tv-casting-app' yield 'chip-tv-casting-app.map' - elif self == HostApp.BRIDGE_APP: + elif self == HostApp.BRIDGE: yield 'chip-bridge-app' yield 'chip-bridge-app.map' else: From 89009338630d829892665447f9716c66120726ee Mon Sep 17 00:00:00 2001 From: davidgoogle <49926720+davidgoogle@users.noreply.github.com> Date: Mon, 6 Jun 2022 07:28:43 -0700 Subject: [PATCH 08/13] Fix dangling entries in host.py builder (#19202) Co-authored-by: Andrei Litvin --- scripts/build/builders/host.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 19e20724625e8a..3baf39e387e291 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -140,9 +140,6 @@ def OutputNames(self): yield 'controller/python' # Directory containing WHL files elif self == HostApp.NL_TEST_RUNNER: yield 'chip_nl_test_runner_wheels' - elif self == HostApp.LIGHT: - yield 'chip-lighting-app' - yield 'chip-lighting-app.map' elif self == HostApp.TV_CASTING: yield 'chip-tv-casting-app' yield 'chip-tv-casting-app.map' From 92c39bee2455a46473a1b3b3f8dc1e2abf1c84bf Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Mon, 6 Jun 2022 16:28:58 +0200 Subject: [PATCH 09/13] [Tizen] Fix array size for DNS-SD type name (#19226) --- src/platform/Tizen/DnssdImpl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/Tizen/DnssdImpl.h b/src/platform/Tizen/DnssdImpl.h index 05695b7f789586..9f2d2ef0abcee4 100755 --- a/src/platform/Tizen/DnssdImpl.h +++ b/src/platform/Tizen/DnssdImpl.h @@ -44,7 +44,7 @@ struct GenericContext struct RegisterContext : public GenericContext { dnssd_service_h service; - char type[kDnssdTypeMaxSize + kDnssdProtocolTextMaxSize + 1]; + char type[kDnssdTypeAndProtocolMaxSize + 1]; char name[Common::kInstanceNameMaxLength + 1]; uint16_t port; uint32_t interfaceId; @@ -64,7 +64,7 @@ struct RegisterContext : public GenericContext struct BrowseContext : public GenericContext { dnssd_browser_h browser; - char type[kDnssdTypeMaxSize + kDnssdProtocolTextMaxSize + 1]; + char type[kDnssdTypeAndProtocolMaxSize + 1]; uint32_t interfaceId; std::vector services; @@ -89,7 +89,7 @@ struct BrowseContext : public GenericContext struct ResolveContext : public GenericContext { dnssd_service_h service; - char type[kDnssdTypeMaxSize + kDnssdProtocolTextMaxSize + 1]; + char type[kDnssdTypeAndProtocolMaxSize + 1]; char name[Common::kInstanceNameMaxLength + 1]; uint32_t interfaceId; bool isResolving; From 3ef748cf8ac11031becee1550536a43e1331de63 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Mon, 6 Jun 2022 17:18:31 +0200 Subject: [PATCH 10/13] [nrfconnect] Fixed MPU fault during DFU over SMP (#19227) Flash NOP device was disabled during the last nRF Connect SDK version update, but it turn out to cause MPU fault during DFU over SMP. Restored enabling flash NOP device. --- config/nrfconnect/chip-module/Kconfig.features | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/nrfconnect/chip-module/Kconfig.features b/config/nrfconnect/chip-module/Kconfig.features index cdcac79444c824..b63983a11e9e3f 100644 --- a/config/nrfconnect/chip-module/Kconfig.features +++ b/config/nrfconnect/chip-module/Kconfig.features @@ -93,6 +93,12 @@ config SYSTEM_WORKQUEUE_STACK_SIZE if SOC_SERIES_NRF53X +# FLASH nop device is enabled to prevent bus faults when mcumgr tries to access +# simulated partition with network core image data. +config FLASH_NOP_DEVICE + bool + default y + # Enable custom SMP request to erase settings partition. config MCUMGR_GRP_ZEPHYR_BASIC bool From 53068dfc6dfe2c4094b0c9dd82fcc66c99a0c152 Mon Sep 17 00:00:00 2001 From: Evgeniy Morozov Date: Mon, 6 Jun 2022 18:21:53 +0300 Subject: [PATCH 11/13] Update attributes and commands for lock app (#19133) * [#18407] Update attributes and feature map for lock-app * Update auto-generated files --- examples/lock-app/lock-common/lock-app.matter | 4 +--- examples/lock-app/lock-common/lock-app.zap | 7 ++++--- zzz_generated/lock-app/zap-generated/access.h | 6 ------ .../lock-app/zap-generated/endpoint_config.h | 16 +++++++--------- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/examples/lock-app/lock-common/lock-app.matter b/examples/lock-app/lock-common/lock-app.matter index 580559080fd970..902876e2a62c41 100644 --- a/examples/lock-app/lock-common/lock-app.matter +++ b/examples/lock-app/lock-common/lock-app.matter @@ -593,7 +593,6 @@ server cluster DoorLock = 257 { attribute access(write: manage) boolean enablePrivacyModeButton = 43; attribute access(write: administer) int8u wrongCodeEntryLimit = 48; attribute access(write: administer) int8u userCodeTemporaryDisableTime = 49; - attribute access(write: administer) boolean requirePINforRemoteOperation = 51; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; @@ -2183,8 +2182,7 @@ endpoint 1 { ram attribute enablePrivacyModeButton; ram attribute wrongCodeEntryLimit default = 3; ram attribute userCodeTemporaryDisableTime default = 10; - ram attribute requirePINforRemoteOperation; - ram attribute featureMap default = 0x113; + ram attribute featureMap default = 0x133; ram attribute clusterRevision default = 6; } } diff --git a/examples/lock-app/lock-common/lock-app.zap b/examples/lock-app/lock-common/lock-app.zap index 7541d086cd6586..c4ce3db3e46ad9 100755 --- a/examples/lock-app/lock-common/lock-app.zap +++ b/examples/lock-app/lock-common/lock-app.zap @@ -7850,7 +7850,7 @@ "mfgCode": null, "side": "server", "type": "boolean", - "included": 1, + "included": 0, "storageOption": "RAM", "singleton": 0, "bounded": 0, @@ -7934,7 +7934,7 @@ "storageOption": "RAM", "singleton": 0, "bounded": 0, - "defaultValue": "0x113", + "defaultValue": "0x133", "reportable": 1, "minInterval": 1, "maxInterval": 65534, @@ -8082,5 +8082,6 @@ "endpointVersion": 1, "deviceIdentifier": 10 } - ] + ], + "log": [] } \ No newline at end of file diff --git a/zzz_generated/lock-app/zap-generated/access.h b/zzz_generated/lock-app/zap-generated/access.h index 6d2165b16fe94e..40c11608f1bec3 100644 --- a/zzz_generated/lock-app/zap-generated/access.h +++ b/zzz_generated/lock-app/zap-generated/access.h @@ -45,7 +45,6 @@ /* Cluster: Door Lock, Attribute: EnablePrivacyModeButton, Privilege: view */ \ /* Cluster: Door Lock, Attribute: WrongCodeEntryLimit, Privilege: view */ \ /* Cluster: Door Lock, Attribute: UserCodeTemporaryDisableTime, Privilege: view */ \ - /* Cluster: Door Lock, Attribute: RequirePINforRemoteOperation, Privilege: view */ \ /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: view */ \ 49, /* Cluster: Network Commissioning, Attribute: MaxNetworks, Privilege: administer */ \ 49, /* Cluster: Network Commissioning, Attribute: Networks, Privilege: administer */ \ @@ -76,7 +75,6 @@ /* Cluster: Door Lock, Attribute: EnablePrivacyModeButton, Privilege: view */ \ /* Cluster: Door Lock, Attribute: WrongCodeEntryLimit, Privilege: view */ \ /* Cluster: Door Lock, Attribute: UserCodeTemporaryDisableTime, Privilege: view */ \ - /* Cluster: Door Lock, Attribute: RequirePINforRemoteOperation, Privilege: view */ \ /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: view */ \ 0, /* Cluster: Network Commissioning, Attribute: MaxNetworks, Privilege: administer */ \ 1, /* Cluster: Network Commissioning, Attribute: Networks, Privilege: administer */ \ @@ -107,7 +105,6 @@ /* Cluster: Door Lock, Attribute: EnablePrivacyModeButton, Privilege: view */ \ /* Cluster: Door Lock, Attribute: WrongCodeEntryLimit, Privilege: view */ \ /* Cluster: Door Lock, Attribute: UserCodeTemporaryDisableTime, Privilege: view */ \ - /* Cluster: Door Lock, Attribute: RequirePINforRemoteOperation, Privilege: view */ \ /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: view */ \ kMatterAccessPrivilegeAdminister, /* Cluster: Network Commissioning, Attribute: MaxNetworks, Privilege: administer */ \ kMatterAccessPrivilegeAdminister, /* Cluster: Network Commissioning, Attribute: Networks, Privilege: administer */ \ @@ -137,7 +134,6 @@ 257, /* Cluster: Door Lock, Attribute: EnablePrivacyModeButton, Privilege: manage */ \ 257, /* Cluster: Door Lock, Attribute: WrongCodeEntryLimit, Privilege: administer */ \ 257, /* Cluster: Door Lock, Attribute: UserCodeTemporaryDisableTime, Privilege: administer */ \ - 257, /* Cluster: Door Lock, Attribute: RequirePINforRemoteOperation, Privilege: administer */ \ 48, /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: administer */ \ 49, /* Cluster: Network Commissioning, Attribute: InterfaceEnabled, Privilege: administer */ \ 6, /* Cluster: On/Off, Attribute: StartUpOnOff, Privilege: manage */ \ @@ -159,7 +155,6 @@ 43, /* Cluster: Door Lock, Attribute: EnablePrivacyModeButton, Privilege: manage */ \ 48, /* Cluster: Door Lock, Attribute: WrongCodeEntryLimit, Privilege: administer */ \ 49, /* Cluster: Door Lock, Attribute: UserCodeTemporaryDisableTime, Privilege: administer */ \ - 51, /* Cluster: Door Lock, Attribute: RequirePINforRemoteOperation, Privilege: administer */ \ 0, /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: administer */ \ 4, /* Cluster: Network Commissioning, Attribute: InterfaceEnabled, Privilege: administer */ \ 16387, /* Cluster: On/Off, Attribute: StartUpOnOff, Privilege: manage */ \ @@ -181,7 +176,6 @@ kMatterAccessPrivilegeManage, /* Cluster: Door Lock, Attribute: EnablePrivacyModeButton, Privilege: manage */ \ kMatterAccessPrivilegeAdminister, /* Cluster: Door Lock, Attribute: WrongCodeEntryLimit, Privilege: administer */ \ kMatterAccessPrivilegeAdminister, /* Cluster: Door Lock, Attribute: UserCodeTemporaryDisableTime, Privilege: administer */ \ - kMatterAccessPrivilegeAdminister, /* Cluster: Door Lock, Attribute: RequirePINforRemoteOperation, Privilege: administer */ \ kMatterAccessPrivilegeAdminister, /* Cluster: General Commissioning, Attribute: Breadcrumb, Privilege: administer */ \ kMatterAccessPrivilegeAdminister, /* Cluster: Network Commissioning, Attribute: InterfaceEnabled, Privilege: administer */ \ kMatterAccessPrivilegeManage, /* Cluster: On/Off, Attribute: StartUpOnOff, Privilege: manage */ \ diff --git a/zzz_generated/lock-app/zap-generated/endpoint_config.h b/zzz_generated/lock-app/zap-generated/endpoint_config.h index f89c5f494cca40..cd0a33315180ab 100644 --- a/zzz_generated/lock-app/zap-generated/endpoint_config.h +++ b/zzz_generated/lock-app/zap-generated/endpoint_config.h @@ -129,7 +129,7 @@ #define ZAP_ATTRIBUTE_MASK(mask) ATTRIBUTE_MASK_##mask // This is an array of EmberAfAttributeMetadata structures. -#define GENERATED_ATTRIBUTE_COUNT 261 +#define GENERATED_ATTRIBUTE_COUNT 260 #define GENERATED_ATTRIBUTES \ { \ \ @@ -543,10 +543,8 @@ { 0x00000030, ZAP_TYPE(INT8U), 1, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(4) }, /* WrongCodeEntryLimit */ \ { 0x00000031, ZAP_TYPE(INT8U), 1, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ - ZAP_MIN_MAX_DEFAULTS_INDEX(5) }, /* UserCodeTemporaryDisableTime */ \ - { 0x00000033, ZAP_TYPE(BOOLEAN), 1, ZAP_ATTRIBUTE_MASK(WRITABLE), \ - ZAP_SIMPLE_DEFAULT(0) }, /* RequirePINforRemoteOperation */ \ - { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x113) }, /* FeatureMap */ \ + ZAP_MIN_MAX_DEFAULTS_INDEX(5) }, /* UserCodeTemporaryDisableTime */ \ + { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x133) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(6) }, /* ClusterRevision */ \ } @@ -1017,8 +1015,8 @@ /* Endpoint: 1, Cluster: Door Lock (server) */ \ .clusterId = 0x00000101, \ .attributes = ZAP_ATTRIBUTE_INDEX(233), \ - .attributeCount = 28, \ - .clusterSize = 42, \ + .attributeCount = 27, \ + .clusterSize = 41, \ .mask = ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(ATTRIBUTE_CHANGED_FUNCTION) | ZAP_CLUSTER_MASK(PRE_ATTRIBUTE_CHANGED_FUNCTION), \ .functions = chipFuncArrayDoorLockServer, \ .acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 71 ) ,\ @@ -1035,7 +1033,7 @@ // This is an array of EmberAfEndpointType structures. #define GENERATED_ENDPOINT_TYPES \ { \ - { ZAP_CLUSTER_INDEX(0), 21, 311 }, { ZAP_CLUSTER_INDEX(21), 6, 207 }, \ + { ZAP_CLUSTER_INDEX(0), 21, 311 }, { ZAP_CLUSTER_INDEX(21), 6, 206 }, \ } // Largest attribute size is needed for various buffers @@ -1047,7 +1045,7 @@ static_assert(ATTRIBUTE_LARGEST <= CHIP_CONFIG_MAX_ATTRIBUTE_STORE_ELEMENT_SIZE, #define ATTRIBUTE_SINGLETONS_SIZE (37) // Total size of attribute storage -#define ATTRIBUTE_MAX_SIZE (518) +#define ATTRIBUTE_MAX_SIZE (517) // Number of fixed endpoints #define FIXED_ENDPOINT_COUNT (2) From acd17c798f82c84e522102bb7d8c080ab3b4d41c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Jun 2022 11:26:58 -0400 Subject: [PATCH 12/13] Bump third_party/mbedtls/repo from `bdd6905` to `7bda291` (#19219) Bumps [third_party/mbedtls/repo](https://github.com/ARMmbed/mbedtls) from `bdd6905` to `7bda291`. - [Release notes](https://github.com/ARMmbed/mbedtls/releases) - [Commits](https://github.com/ARMmbed/mbedtls/compare/bdd6905a5cb44fce66af373b3faa80f23002afc4...7bda29142761b1a302a13f005649cf24f5f69e0a) --- updated-dependencies: - dependency-name: third_party/mbedtls/repo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- third_party/mbedtls/repo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/mbedtls/repo b/third_party/mbedtls/repo index bdd6905a5cb44f..7bda29142761b1 160000 --- a/third_party/mbedtls/repo +++ b/third_party/mbedtls/repo @@ -1 +1 @@ -Subproject commit bdd6905a5cb44fce66af373b3faa80f23002afc4 +Subproject commit 7bda29142761b1a302a13f005649cf24f5f69e0a From d2a519200ea76ed5e91e6eb29a04f28515f58b2b Mon Sep 17 00:00:00 2001 From: Ricardo Casallas <77841255+rcasallas-silabs@users.noreply.github.com> Date: Mon, 6 Jun 2022 12:19:05 -0400 Subject: [PATCH 13/13] Groups cluster: GroupInfo is now removed from the GroupTable whenever the last endpoint is removed from the group. (#19221) --- .../suites/TestGroupKeyManagementCluster.yaml | 29 ++++++ src/credentials/GroupDataProviderImpl.cpp | 8 +- .../chip-tool/zap-generated/test/Commands.h | 56 +++++++++-- .../zap-generated/test/Commands.h | 98 +++++++++++++++++-- 4 files changed, 173 insertions(+), 18 deletions(-) diff --git a/src/app/tests/suites/TestGroupKeyManagementCluster.yaml b/src/app/tests/suites/TestGroupKeyManagementCluster.yaml index 2c8f97e754aa6e..2562004cbf86aa 100644 --- a/src/app/tests/suites/TestGroupKeyManagementCluster.yaml +++ b/src/app/tests/suites/TestGroupKeyManagementCluster.yaml @@ -223,6 +223,35 @@ tests: EpochStartTime2: 2110002, } + - label: "Remove Group 1" + cluster: "Groups" + endpoint: 1 + command: "RemoveGroup" + arguments: + values: + - name: "groupId" + value: 0x0101 + response: + values: + - name: "status" + value: 0 + - name: "groupId" + value: 0x0101 + + - label: "Read GroupTable 2" + command: "readAttribute" + attribute: "GroupTable" + response: + value: + [ + { + FabricIndex: 1, + GroupId: 0x0102, + endpoints: [1], + GroupName: "Group #2", + }, + ] + - label: "Remove All" cluster: "Groups" endpoint: 1 diff --git a/src/credentials/GroupDataProviderImpl.cpp b/src/credentials/GroupDataProviderImpl.cpp index c5d65bfcb6e850..4c56a0943d2670 100644 --- a/src/credentials/GroupDataProviderImpl.cpp +++ b/src/credentials/GroupDataProviderImpl.cpp @@ -1187,11 +1187,15 @@ CHIP_ERROR GroupDataProviderImpl::RemoveEndpoint(chip::FabricIndex fabric_index, prev.next = endpoint.next; ReturnErrorOnFailure(prev.Save(mStorage)); } - if (group.endpoint_count > 0) + + if (group.endpoint_count > 1) { group.endpoint_count--; + return group.Save(mStorage); } - return group.Save(mStorage); + + // No more endpoints, remove the group + return RemoveGroupInfoAt(fabric_index, group.index); } CHIP_ERROR GroupDataProviderImpl::RemoveEndpoint(chip::FabricIndex fabric_index, chip::EndpointId endpoint_id) diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 5d1391e71e837c..e278dd701e1deb 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -64781,7 +64781,7 @@ class TestGroupKeyManagementClusterSuite : public TestCommand { public: TestGroupKeyManagementClusterSuite(CredentialIssuerCommands * credsIssuerConfig) : - TestCommand("TestGroupKeyManagementCluster", 18, credsIssuerConfig) + TestCommand("TestGroupKeyManagementCluster", 20, credsIssuerConfig) { AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); AddArgument("cluster", &mCluster); @@ -64962,11 +64962,40 @@ class TestGroupKeyManagementClusterSuite : public TestCommand break; case 15: VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + { + chip::app::Clusters::Groups::Commands::RemoveGroupResponse::DecodableType value; + VerifyOrReturn(CheckDecodeValue(chip::app::DataModel::Decode(*data, value))); + VerifyOrReturn(CheckValue("status", value.status, 0)); + + VerifyOrReturn(CheckValue("groupId", value.groupId, 257U)); + } break; case 16: VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + { + chip::app::DataModel::DecodableList< + chip::app::Clusters::GroupKeyManagement::Structs::GroupInfoMapStruct::DecodableType> + value; + VerifyOrReturn(CheckDecodeValue(chip::app::DataModel::Decode(*data, value))); + { + auto iter_0 = value.begin(); + VerifyOrReturn(CheckNextListItemDecodes("groupTable", iter_0, 0)); + VerifyOrReturn(CheckValue("groupTable[0].groupId", iter_0.GetValue().groupId, 258U)); + VerifyOrReturn(CheckValuePresent("groupTable[0].groupName", iter_0.GetValue().groupName)); + VerifyOrReturn(CheckValueAsString("groupTable[0].groupName.Value()", iter_0.GetValue().groupName.Value(), + chip::CharSpan("Group #2", 8))); + VerifyOrReturn(CheckValue("groupTable[0].fabricIndex", iter_0.GetValue().fabricIndex, 1)); + VerifyOrReturn(CheckNoMoreListItems("groupTable", iter_0, 1)); + } + } break; case 17: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + case 18: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + case 19: VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), EMBER_ZCL_STATUS_NOT_FOUND)); break; default: @@ -65184,7 +65213,22 @@ class TestGroupKeyManagementClusterSuite : public TestCommand ); } case 15: { - LogStep(15, "Remove All"); + LogStep(15, "Remove Group 1"); + ListFreer listFreer; + chip::app::Clusters::Groups::Commands::RemoveGroup::Type value; + value.groupId = 257U; + return SendCommand(kIdentityAlpha, GetEndpoint(1), Groups::Id, Groups::Commands::RemoveGroup::Id, value, + chip::NullOptional + + ); + } + case 16: { + LogStep(16, "Read GroupTable 2"); + return ReadAttribute(kIdentityAlpha, GetEndpoint(0), GroupKeyManagement::Id, + GroupKeyManagement::Attributes::GroupTable::Id, true, chip::NullOptional); + } + case 17: { + LogStep(17, "Remove All"); ListFreer listFreer; chip::app::Clusters::Groups::Commands::RemoveAllGroups::Type value; return SendCommand(kIdentityAlpha, GetEndpoint(1), Groups::Id, Groups::Commands::RemoveAllGroups::Id, value, @@ -65192,8 +65236,8 @@ class TestGroupKeyManagementClusterSuite : public TestCommand ); } - case 16: { - LogStep(16, "KeySet Remove 2"); + case 18: { + LogStep(18, "KeySet Remove 2"); ListFreer listFreer; chip::app::Clusters::GroupKeyManagement::Commands::KeySetRemove::Type value; value.groupKeySetID = 418U; @@ -65202,8 +65246,8 @@ class TestGroupKeyManagementClusterSuite : public TestCommand ); } - case 17: { - LogStep(17, "KeySet Read (also removed)"); + case 19: { + LogStep(19, "KeySet Read (also removed)"); ListFreer listFreer; chip::app::Clusters::GroupKeyManagement::Commands::KeySetRead::Type value; value.groupKeySetID = 418U; diff --git a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h index cb365729dc77c8..a252c1bfa4b71e 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h @@ -108178,16 +108178,24 @@ class TestGroupKeyManagementCluster : public TestCommandBridge { err = TestKeySetReadNotRemoved_14(); break; case 15: - ChipLogProgress(chipTool, " ***** Test Step 15 : Remove All\n"); - err = TestRemoveAll_15(); + ChipLogProgress(chipTool, " ***** Test Step 15 : Remove Group 1\n"); + err = TestRemoveGroup1_15(); break; case 16: - ChipLogProgress(chipTool, " ***** Test Step 16 : KeySet Remove 2\n"); - err = TestKeySetRemove2_16(); + ChipLogProgress(chipTool, " ***** Test Step 16 : Read GroupTable 2\n"); + err = TestReadGroupTable2_16(); break; case 17: - ChipLogProgress(chipTool, " ***** Test Step 17 : KeySet Read (also removed)\n"); - err = TestKeySetReadAlsoRemoved_17(); + ChipLogProgress(chipTool, " ***** Test Step 17 : Remove All\n"); + err = TestRemoveAll_17(); + break; + case 18: + ChipLogProgress(chipTool, " ***** Test Step 18 : KeySet Remove 2\n"); + err = TestKeySetRemove2_18(); + break; + case 19: + ChipLogProgress(chipTool, " ***** Test Step 19 : KeySet Read (also removed)\n"); + err = TestKeySetReadAlsoRemoved_19(); break; } @@ -108252,6 +108260,12 @@ class TestGroupKeyManagementCluster : public TestCommandBridge { VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); break; case 17: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + case 18: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + case 19: VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), EMBER_ZCL_STATUS_NOT_FOUND)); break; } @@ -108267,7 +108281,7 @@ class TestGroupKeyManagementCluster : public TestCommandBridge { private: std::atomic_uint16_t mTestIndex; - const uint16_t mTestCount = 18; + const uint16_t mTestCount = 20; chip::Optional mNodeId; chip::Optional mCluster; @@ -108757,7 +108771,71 @@ class TestGroupKeyManagementCluster : public TestCommandBridge { return CHIP_NO_ERROR; } - CHIP_ERROR TestRemoveAll_15() + CHIP_ERROR TestRemoveGroup1_15() + { + CHIPDevice * device = GetDevice("alpha"); + CHIPTestGroups * cluster = [[CHIPTestGroups alloc] initWithDevice:device endpoint:1 queue:mCallbackQueue]; + VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE); + + __auto_type * params = [[CHIPGroupsClusterRemoveGroupParams alloc] init]; + params.groupId = [NSNumber numberWithUnsignedShort:257U]; + [cluster removeGroupWithParams:params + completionHandler:^(CHIPGroupsClusterRemoveGroupResponseParams * _Nullable values, NSError * _Nullable err) { + NSLog(@"Remove Group 1 Error: %@", err); + + VerifyOrReturn(CheckValue("status", err ? err.code : 0, 0)); + + { + id actualValue = values.status; + VerifyOrReturn(CheckValue("status", actualValue, 0)); + } + + { + id actualValue = values.groupId; + VerifyOrReturn(CheckValue("groupId", actualValue, 257U)); + } + + NextTest(); + }]; + + return CHIP_NO_ERROR; + } + + CHIP_ERROR TestReadGroupTable2_16() + { + CHIPDevice * device = GetDevice("alpha"); + CHIPTestGroupKeyManagement * cluster = [[CHIPTestGroupKeyManagement alloc] initWithDevice:device + endpoint:0 + queue:mCallbackQueue]; + VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE); + + CHIPReadParams * params = [[CHIPReadParams alloc] init]; + params.fabricFiltered = [NSNumber numberWithBool:true]; + [cluster readAttributeGroupTableWithParams:params + completionHandler:^(NSArray * _Nullable value, NSError * _Nullable err) { + NSLog(@"Read GroupTable 2 Error: %@", err); + + VerifyOrReturn(CheckValue("status", err ? err.code : 0, 0)); + + { + id actualValue = value; + VerifyOrReturn(CheckValue("GroupTable", [actualValue count], static_cast(1))); + VerifyOrReturn(CheckValue("GroupId", + ((CHIPGroupKeyManagementClusterGroupInfoMapStruct *) actualValue[0]).groupId, 258U)); + VerifyOrReturn(CheckValueAsString("GroupName", + ((CHIPGroupKeyManagementClusterGroupInfoMapStruct *) actualValue[0]).groupName, + @"Group #2")); + VerifyOrReturn(CheckValue("FabricIndex", + ((CHIPGroupKeyManagementClusterGroupInfoMapStruct *) actualValue[0]).fabricIndex, 1)); + } + + NextTest(); + }]; + + return CHIP_NO_ERROR; + } + + CHIP_ERROR TestRemoveAll_17() { CHIPDevice * device = GetDevice("alpha"); CHIPTestGroups * cluster = [[CHIPTestGroups alloc] initWithDevice:device endpoint:1 queue:mCallbackQueue]; @@ -108774,7 +108852,7 @@ class TestGroupKeyManagementCluster : public TestCommandBridge { return CHIP_NO_ERROR; } - CHIP_ERROR TestKeySetRemove2_16() + CHIP_ERROR TestKeySetRemove2_18() { CHIPDevice * device = GetDevice("alpha"); CHIPTestGroupKeyManagement * cluster = [[CHIPTestGroupKeyManagement alloc] initWithDevice:device @@ -108796,7 +108874,7 @@ class TestGroupKeyManagementCluster : public TestCommandBridge { return CHIP_NO_ERROR; } - CHIP_ERROR TestKeySetReadAlsoRemoved_17() + CHIP_ERROR TestKeySetReadAlsoRemoved_19() { CHIPDevice * device = GetDevice("alpha"); CHIPTestGroupKeyManagement * cluster = [[CHIPTestGroupKeyManagement alloc] initWithDevice:device