diff --git a/.github/.wordlist.txt b/.github/.wordlist.txt index 6b71bab558ed4e..850f970b1a8a0f 100644 --- a/.github/.wordlist.txt +++ b/.github/.wordlist.txt @@ -12,6 +12,7 @@ aabbccddeeff aarch abcdef abfb +appwrite ABI ABIs ables @@ -175,6 +176,7 @@ CatalogVendorId CBB cbd ccf +csg CCMP CCS CCSTUDIO @@ -315,6 +317,7 @@ dataset datasets DataVersion dbf +doru DBG dBm DBUILD @@ -594,8 +597,10 @@ IDF IDL IDLs idx +ifconfig ifdef ifdefs +itsfoss IGMP ignoreApplyUpdate ignoreQueryImage @@ -897,6 +902,8 @@ optionOverride optionsMask optionsOverride orgs +otaissues +otatesting OTA OTADownloader otaDownloadPath @@ -940,7 +947,10 @@ pbxproj PCA pcaps PDFs +PDM PDK +PSECT +pdm peerAddrStr peerNodeId peerSessionId @@ -949,6 +959,7 @@ percentageLiftValue periodicQueryTimeout pexpect pickString +psect PID Pigweed PinCode @@ -1019,6 +1030,7 @@ QRCodeUrl QSPI QueryImage QueryImageResponse +Quickstart queryImageStatus qvCHIP RADVD @@ -1028,6 +1040,7 @@ rAv RCP ReadAttribute ReadConfigValue +RPis readelf readfds README @@ -1089,6 +1102,7 @@ scalable scm sco scp +ssbl ScriptBinding SDC SDHC @@ -1119,6 +1133,7 @@ SetupQRCode sexualized SHA ShadeConfiguration +SSBL showDocumentation shubhamdp SIGINT @@ -1345,6 +1360,7 @@ whde whitespace whitespaces whl +wg wic WiFiNetworkDiagnostics WindowCovering diff --git a/.github/workflows/examples-k32w.yaml b/.github/workflows/examples-k32w.yaml index 834d513b9e2019..91ca49a9482b03 100644 --- a/.github/workflows/examples-k32w.yaml +++ b/.github/workflows/examples-k32w.yaml @@ -70,8 +70,8 @@ jobs: run: | scripts/run_in_build_env.sh "\ ./scripts/build/build_examples.py \ - --target k32w-light-release \ - --target k32w-light-tokenizer-release \ + --target k32w-light-ota-se \ + --target k32w-light-release-no-ota \ --target k32w-lock-low-power-release \ --target k32w-shell-release \ build \ @@ -82,7 +82,7 @@ jobs: run: | .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ k32w k32w061+release light \ - out/artifacts/k32w-light-release/chip-k32w061-light-example \ + out/artifacts/k32w-light-release-no-ota/chip-k32w061-light-example \ /tmp/bloat_reports/ - name: Get lock size stats timeout-minutes: 5 diff --git a/examples/lighting-app/nxp/k32w/k32w0/BUILD.gn b/examples/lighting-app/nxp/k32w/k32w0/BUILD.gn index 449c7ba01b322b..5e811f8900e0d8 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/BUILD.gn +++ b/examples/lighting-app/nxp/k32w/k32w0/BUILD.gn @@ -21,6 +21,7 @@ import("${k32w0_sdk_build_root}/k32w0_sdk.gni") import("${chip_root}/src/crypto/crypto.gni") import("${chip_root}/src/lib/core/core.gni") +import("${chip_root}/src/lib/core/core.gni") import("${chip_root}/src/platform/device.gni") if (chip_pw_tokenizer_logging) { @@ -82,7 +83,7 @@ k32w0_executable("light_app") { deps = [ ":sdk", "${chip_root}/examples/common/QRCode", - "${chip_root}/examples/ota-requestor-app/ota-requestor-common", + "${chip_root}/examples/lighting-app/lighting-common/", "${chip_root}/src/lib", "${chip_root}/third_party/mbedtls:mbedtls", "${k32w0_platform_dir}/app/support:freertos_mbedtls_utils", @@ -108,6 +109,15 @@ k32w0_executable("light_app") { ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ] + if (chip_enable_ota_requestor) { + ldflags += [ + "-Wl,--defsym", + "-Wl,__app_load_address__=0x4000", + "-Wl,--defsym", + "-Wl,__app_stated_size__=0x99A00", + ] + } + output_dir = root_out_dir } diff --git a/examples/lighting-app/nxp/k32w/k32w0/README.md b/examples/lighting-app/nxp/k32w/k32w0/README.md index d059e2ed46775c..571779f83ca519 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/README.md +++ b/examples/lighting-app/nxp/k32w/k32w0/README.md @@ -23,13 +23,14 @@ network. - [Device UI](#device-ui) - [Building](#building) - [Flashing and debugging](#flashdebug) -- [Testing the example](#testing-the-example) - [Pigweed Tokenizer](#tokenizer) - [Detokenizer script](#detokenizer) - [Notes](#detokenizer-notes) - [Known issues](#detokenizer-known-issues) - -
+- [OTA](#ota) - [Writing the SSBL](#ssbl) - [Writing the PSECT](#psect) - + [Writing the application](#appwrite) - [OTA Testing](#otatesting) - + [Known issues](#otaissues) + @@ -226,13 +227,6 @@ All you have to do is to replace the Openthread binaries from the above documentation with _out/debug/chip-k32w061-light-example.bin_ if DK6Programmer is used or with _out/debug/chip-k32w061-light-example_ if MCUXpresso is used. -## Testing the example - -The app can be deployed against any generic OpenThread Border Router. See the -guide -[Commissioning NXP K32W using Android CHIPTool](../../../docs/guides/nxp_k32w_android_commissioning.md) -for step-by-step instructions. - ## Pigweed tokenizer @@ -299,3 +293,207 @@ script won't find them in the special-created sections. If run, closed and rerun with the serial option on the same serial port, the detokenization script will get stuck and not show any logs. The solution is to unplug and plug the board and then rerun the script. + + + +## OTA + +The internal flash needs to be prepared for the OTA process. First 16K of the +internal flash needs to be populated with a Secondary Stage Bootloader (SSBL) +related data while the last 8.5K of flash space is holding image directory +related data (PSECT). The space between these two zones will be filled by the +application. + + + +### Writing the SSBL + +The SSBL can ge generated from one of the SDK demo examples. The SDK demo +example needs to be compiled inside MCUXpresso with the define _PDM_EXT_FLASH_. +The SSBL demo application can be imported from the _Quickstart panel_: _Import +SDK example(s)_ -> select _wireless->framework->ssbl_ application. + +![SSBL Application Select](../../../../platform/nxp/k32w/k32w0/doc/images/ssbl_select.JPG) + +The SSBL project must be compiled using the PDM_EXT_FLASH define. + +![PDM_EXT_FLASH](../../../../platform/nxp/k32w/k32w0/doc/images/pdm_ext_flash.JPG) + +Once compiled, the required ssbl file is called k32w061dk6_ssbl.bin + +![SSBL_BIN](../../../../platform/nxp/k32w/k32w0/doc/images/ssbl_bin.JPG) + +Before writing the SSBL, it it recommanded to fully erase the internal flash: + +``` +DK6Programmer.exe -V 5 -P 1000000 -s -e Flash +``` + +k32w061dk6_ssbl.bin must be written at address 0 in the internal flash: + +``` +DK6Programmer.exe -V2 -s -P 1000000 -Y -p FLASH@0x00="k32w061dk6_ssbl.bin" +``` + + + +### Writing the PSECT + +First, image directory 0 must be written: + +``` +DK6Programmer.exe -V5 -s -P 1000000 -w image_dir_0=0000000010000000 +``` + +Here is the interpretation of the fields: + +``` +00000000 -> start address 0x00000000 +1000 -> size = 0x0010 pages of 512-bytes (= 8kB) +00 -> not bootable (only used by the SSBL to support SSBL update) +00 -> SSBL Image Type +``` + +Second, image directory 1 must be written: + +``` +DK6Programmer.exe -V5 -s -P 1000000 -w image_dir_1=00400000CD040101 +``` + +Here is the interpretation of the fields: + +``` +00400000 -> start address 0x00004000 +CD04 -> 0x4CD pages of 512-bytes (= 614,5kB) +01 -> bootable flag +01 -> image type for the application +``` + + + +### Writing the application + +DK6Programmer can be used for flashing the application: + +``` +DK6Programmer.exe -V2 -s -P 1000000 -Y -p FLASH@0x4000="chip-k32w061-light-example.bin" +``` + +If debugging is needed, MCUXpresso can be used then for flashing the +application. Please make sure that the application is written at address 0x4000: + +![FLASH_LOCATION](../../../../platform/nxp/k32w/k32w0/doc/images/flash_location.JPG) + + + +### OTA Testing + +The OTA topology used for OTA testing is illustrated in the figure below. +Topology is similar with the one used for Matter Test Events. + +![OTA_TOPOLOGY](../../../../platform/nxp/k32w/k32w0/doc/images/ota_topology.JPG) + +The concept for OTA is the next one: + +- there is an OTA Provider Application that holds the OTA image. In our case, + this is a Linux application running on an Ubuntu based-system; +- the OTA Requestor functionality is embedded inside the Lighting Application. + It will be used for requesting OTA blocks from the OTA Provider; +- the controller (a linux application called chip-tool) will be used for + commissioning both the device and the OTA Provider App. The device will be + commissioned using the standard Matter flow (BLE + IEEE 802.15.4) while the + OTA Provider Application will be commissioned using the _onnetwork_ option + of chip-tool; +- during commissioning, each device is assigned a node id by the chip-tool + (can be specified manually by the user). Using the node id of the device and + of the lighting application, chip-tool triggers the OTA transfer by invoking + the _announce-ota-provider_ command - basically, the OTA Requestor is + informed of the node id of the OTA Provider Application. + +_Computer #1_ can be any system running an Ubuntu distribution. We recommand +using TE 7.5 instructions from +[here](https://groups.csa-iot.org/wg/matter-csg/document/24839), where RPi 4 are +proposed. Also, TE 7.5 instructions document point to the OS/Docker images that +should be used on the RPis. For compatibility reasons, we recommand compiling +chip-tool and OTA Provider applications with the same commit id that was used +for compiling the Lighting Application. Also, please note that there is a single +controller (chip-tool) running on Computer #1 which is used for commissioning +both the device and the OTA Provider Application. If needed, +[these instructions](https://itsfoss.com/connect-wifi-terminal-ubuntu/) could be +used for connecting the RPis to WiFi. + +Build the Linux OTA provider application: + +``` +doru@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/ota-provider-app/linux out/ota-provider-app chip_config_network_layer_ble=false +``` + +Build OTA image and start the OTA Provider Application: + +``` +doru@computer1:~/connectedhomeip$ : ./src/app/ota_image_tool.py create -v 0xDEAD -p 0xBEEF -vn 1 -vs "1.0" -da sha256 chip-k32w061-light-example.bin chip-k32w061-light-example.ota +doru@computer1:~/connectedhomeip$ : rm -rf /tmp/chip_* +doru@computer1:~/connectedhomeip$ : ./out/ota-provider-app/chip-ota-provider-app -f chip-k32w061-light-example.ota +``` + +Build Linux chip-tool: + +``` +doru@computer1:~/connectedhomeip$ : ./scripts/examples/gn_build_example.sh examples/chip-tool out/chip-tool-app +``` + +Provision the OTA provider application and assign node id _1_. Also, grant ACL +entries to allow OTA requestors: + +``` +doru@computer1:~/connectedhomeip$ : rm -rf /tmp/chip_* +doru@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool pairing onnetwork 1 20202021 +doru@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool accesscontrol write acl '[{"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [112233], "targets": null}, {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": null, "targets": null}]' 1 0 +``` + +Provision the device and assign node id _2_: + +``` +doru@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool pairing ble-thread 2 hex: 20202021 3840 +``` + +Start the OTA process: + +``` +doru@computer1:~/connectedhomeip$ : ./out/chip-tool-app/chip-tool otasoftwareupdaterequestor announce-ota-provider 1 0 0 0 2 0 +``` + + + +## Known issues + +- SRP cache on the openthread border router needs to flushed each time a new + commissioning process is attempted. For this, factory reset the device, then + execute _ot-ctl server disable_ followed by _ot-ctl server enable_. After + this step, the commissioning process of the device can start; +- Due to some MDNS issues, the commissioning of the OTA Provider Application + may fail. Please make sure that the SRP cache is disabled (_ot-ctl srp + server disable_) on the openthread border router while commissioning the OTA + Provider Application; +- No other Docker image should be running (e.g.: Docker image needed by Test + Harness) except the OTBR one. A docker image can be killed using the + command: + +``` +doru@computer1:~/connectedhomeip$ : sudo docker kill $container_id +``` + +- In order to avoid MDNS issues, only one interface should be active at one + time. E.g.: if WiFi is used then disable the Ethernet interface and also + disable multicast on that interface: + +``` +doru@computer1:~/connectedhomeip$ sudo ip link set dev eth0 down +doru@computer1:~/connectedhomeip$ sudo ifconfig eth0 -multicast +``` + +- If OTBR Docker image is used, then the "-B" parameter should point to the + interface used for the backbone. + +- If Wi-Fi is used on a RPI4, then a 5Ghz network should be selected. + Otherwise, issues related to BLE-WiFi combo may appear. diff --git a/examples/lighting-app/nxp/k32w/k32w0/args.gni b/examples/lighting-app/nxp/k32w/k32w0/args.gni index 114ae5310569ca..8bbd1e952f5ab9 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/args.gni +++ b/examples/lighting-app/nxp/k32w/k32w0/args.gni @@ -20,4 +20,6 @@ k32w0_sdk_target = get_label_info(":sdk", "label_no_toolchain") declare_args() { chip_enable_ota_requestor = true + chip_stack_lock_tracking = "fatal" + chip_enable_ble = true } diff --git a/examples/lighting-app/nxp/k32w/k32w0/data.bin b/examples/lighting-app/nxp/k32w/k32w0/data.bin deleted file mode 100644 index 05db12377ed787..00000000000000 Binary files a/examples/lighting-app/nxp/k32w/k32w0/data.bin and /dev/null differ diff --git a/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index 45428ef35d17d5..8b248f9e76e22c 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/lighting-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -86,7 +86,7 @@ * {MAJOR_VERSION}.0d{MINOR_VERSION} */ #ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING -#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "04-2020-te2" +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "03-2022-te8" #endif #ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION @@ -101,13 +101,6 @@ #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "NXP Demo App" #endif -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for CHIP-over-BLE (CHIPOBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - /** * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC * diff --git a/examples/lighting-app/nxp/k32w/k32w0/include/FreeRTOSConfig.h b/examples/lighting-app/nxp/k32w/k32w0/include/FreeRTOSConfig.h index 9419372bbed91a..8c533831108e98 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/include/FreeRTOSConfig.h +++ b/examples/lighting-app/nxp/k32w/k32w0/include/FreeRTOSConfig.h @@ -44,7 +44,8 @@ #define configCPU_CLOCK_HZ (SystemCoreClock) #define configTICK_RATE_HZ ((TickType_t) 100) #define configMAX_PRIORITIES (8) -#define configMINIMAL_STACK_SIZE ((unsigned short) 90) +// idle task stack size needs to be increased for OTA EEPROM processing +#define configMINIMAL_STACK_SIZE ((unsigned short) 450) #define configMAX_TASK_NAME_LEN 20 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 @@ -74,7 +75,7 @@ /* Hook function related definitions. */ #ifndef configUSE_IDLE_HOOK -#define configUSE_IDLE_HOOK 0 +#define configUSE_IDLE_HOOK 1 #endif #define configUSE_TICK_HOOK 0 #define configCHECK_FOR_STACK_OVERFLOW 0 @@ -99,7 +100,7 @@ #define configUSE_TIMERS 1 #define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) #define configTIMER_QUEUE_LENGTH 10 -#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 4) +#define configTIMER_TASK_STACK_DEPTH (360) /* Define to trap errors during development. */ #define configASSERT(x) \ diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp index be977affa6ff2b..eb8e749278b314 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp @@ -34,17 +34,18 @@ #include /* OTA related includes */ +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR #include "OTAImageProcessorImpl.h" #include "OtaSupport.h" #include #include #include #include +#endif #include "Keyboard.h" #include "LED.h" #include "LEDWidget.h" -#include "TimersManager.h" #include "app_config.h" #if CHIP_CRYPTO_HSM @@ -68,7 +69,6 @@ static LEDWidget sStatusLED; static LEDWidget sLightLED; static bool sIsThreadProvisioned = false; -static bool sIsThreadEnabled = false; static bool sHaveBLEConnections = false; static uint32_t eventMask = 0; @@ -85,12 +85,18 @@ using namespace chip; AppTask AppTask::sAppTask; /* OTA related variables */ +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR static DefaultOTARequestor gRequestorCore; static DefaultOTARequestorStorage gRequestorStorage; static DeviceLayer::DefaultOTARequestorDriver gRequestorUser; static BDXDownloader gDownloader; static OTAImageProcessorImpl gImageProcessor; +constexpr uint16_t requestedOtaBlockSize = 1024; +#endif + +extern bool shouldReset; + CHIP_ERROR AppTask::StartAppTask() { CHIP_ERROR err = CHIP_NO_ERROR; @@ -111,9 +117,7 @@ CHIP_ERROR AppTask::Init() CHIP_ERROR err = CHIP_NO_ERROR; // Init ZCL Data Model and start server - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - chip::Server::GetInstance().Init(initParams); + PlatformMgr().ScheduleWork(InitServer, 0); // Initialize device attestation config #ifdef ENABLE_HSM_DEVICE_ATTESTATION @@ -122,25 +126,13 @@ CHIP_ERROR AppTask::Init() SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); #endif - // Initialize and interconnect the Requestor and Image Processor objects -- START - SetRequestorInstance(&gRequestorCore); - - gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage()); - gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); - gRequestorUser.Init(&gRequestorCore, &gImageProcessor); - - gImageProcessor.SetOTAImageFile("test.txt"); - gImageProcessor.SetOTADownloader(&gDownloader); - - // Connect the gDownloader and Image Processor objects - gDownloader.SetImageProcessorDelegate(&gImageProcessor); - // Initialize and interconnect the Requestor and Image Processor objects -- END +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + PlatformMgr().ScheduleWork(InitOTA, 0); +#endif // QR code will be used with CHIP Tool PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); - TMR_Init(); - /* HW init leds */ LED_Init(); @@ -156,8 +148,7 @@ CHIP_ERROR AppTask::Init() sStatusLED.Init(SYSTEM_STATE_LED); sLightLED.Init(LIGHT_STATE_LED); - sLightLED.Set(!LightingMgr().IsTurnedOff()); - UpdateClusterState(); + UpdateDeviceState(); /* intialize the Keyboard and button press calback */ KBD_Init(KBD_Callback); @@ -188,13 +179,38 @@ CHIP_ERROR AppTask::Init() K32W_LOG("Current Software Version: %s", currentSoftwareVer); -#if CONFIG_CHIP_NFC_COMMISSIONING PlatformMgr().AddEventHandler(ThreadProvisioningHandler, 0); -#endif return err; } +void AppTask::InitServer(intptr_t arg) +{ + static chip::CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + + // Init ZCL Data Model and start server + VerifyOrDie((chip::Server::GetInstance().Init(initParams)) == CHIP_NO_ERROR); +} + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +void AppTask::InitOTA(intptr_t arg) +{ + // Initialize and interconnect the Requestor and Image Processor objects -- START + SetRequestorInstance(&gRequestorCore); + + gRequestorStorage.Init(chip::Server::GetInstance().GetPersistentStorage()); + gRequestorCore.Init(chip::Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader); + gRequestorUser.SetMaxDownloadBlockSize(requestedOtaBlockSize); + gRequestorUser.Init(&gRequestorCore, &gImageProcessor); + gImageProcessor.SetOTADownloader(&gDownloader); + + // Connect the gDownloader and Image Processor objects + gDownloader.SetImageProcessorDelegate(&gImageProcessor); + // Initialize and interconnect the Requestor and Image Processor objects -- END +} +#endif + void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; @@ -225,9 +241,7 @@ void AppTask::AppTaskMain(void * pvParameter) #if CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI K32WUartProcess(); #endif - sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); - sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled(); - sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); + sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); PlatformMgr().UnlockChipStack(); } @@ -245,7 +259,7 @@ void AppTask::AppTaskMain(void * pvParameter) // Otherwise, blink the LED ON for a very short time. if (sAppTask.mFunction != kFunction_FactoryReset) { - if (sIsThreadProvisioned && sIsThreadEnabled) + if (sIsThreadProvisioned) { sStatusLED.Blink(950, 50); } @@ -263,16 +277,6 @@ void AppTask::AppTaskMain(void * pvParameter) sLightLED.Animate(); HandleKeyboard(); - - if (gDownloader.GetState() == OTADownloader::State::kInProgress) - { - OTA_TransactionResume(); - - if (!EEPROM_isBusy()) - { - gDownloader.FetchNextData(); - } - } } } @@ -483,15 +487,32 @@ void AppTask::OTAHandler(AppEvent * aEvent) if (aEvent->ButtonEvent.PinNo != OTA_BUTTON) return; +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR if (sAppTask.mFunction != kFunction_NoneSelected) { K32W_LOG("Another function is scheduled. Could not initiate OTA!"); return; } + PlatformMgr().ScheduleWork(StartOTAQuery, 0); +#endif +} + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +void AppTask::StartOTAQuery(intptr_t arg) +{ static_cast(GetRequestorInstance())->TriggerImmediateQuery(); } +void AppTask::PostOTAResume() +{ + AppEvent event; + event.Type = AppEvent::kEventType_OTAResume; + event.Handler = OTAResumeEventHandler; + sAppTask.PostEvent(&event); +} +#endif + void AppTask::BleHandler(AppEvent * aEvent) { if (aEvent->ButtonEvent.PinNo != BLE_BUTTON) @@ -523,9 +544,28 @@ void AppTask::BleHandler(AppEvent * aEvent) } } -#if CONFIG_CHIP_NFC_COMMISSIONING void AppTask::ThreadProvisioningHandler(const ChipDeviceEvent * event, intptr_t) { + if (event->Type == DeviceEventType::kServiceProvisioningChange && event->ServiceProvisioningChange.IsServiceProvisioned) + { + if (event->ServiceProvisioningChange.IsServiceProvisioned) + { + sIsThreadProvisioned = TRUE; + } + else + { + sIsThreadProvisioned = FALSE; + } + } + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + if (event->Type == DeviceEventType::kOtaStateChanged && event->OtaStateChanged.newState == kOtaSpaceAvailable) + { + sAppTask.PostOTAResume(); + } +#endif + +#if CONFIG_CHIP_NFC_COMMISSIONING if (event->Type == DeviceEventType::kCHIPoBLEAdvertisingChange && event->CHIPoBLEAdvertisingChange.Result == kActivity_Stopped) { if (!NFCMgr().IsTagEmulationStarted()) @@ -551,8 +591,8 @@ void AppTask::ThreadProvisioningHandler(const ChipDeviceEvent * event, intptr_t) K32W_LOG("Started NFC Tag Emulation!"); } } -} #endif +} void AppTask::CancelTimer() { @@ -637,6 +677,26 @@ void AppTask::PostTurnOnActionRequest(int32_t aActor, LightingManager::Action_t PostEvent(&event); } +void AppTask::OTAResumeEventHandler(AppEvent * aEvent) +{ + if (aEvent->Type == AppEvent::kEventType_OTAResume) + { +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + if (gDownloader.GetState() == OTADownloader::State::kInProgress) + { + gImageProcessor.TriggerNewRequestForData(); + } +#endif + } +} + +extern "C" void vApplicationIdleHook(void) +{ +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + OTA_TransactionResume(); +#endif +} + void AppTask::PostEvent(const AppEvent * aEvent) { if (sAppEventQueue != NULL) @@ -661,6 +721,11 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } void AppTask::UpdateClusterState(void) +{ + PlatformMgr().ScheduleWork(UpdateClusterStateInternal, 0); +} + +void AppTask::UpdateClusterStateInternal(intptr_t arg) { uint8_t newValue = !LightingMgr().IsTurnedOff(); @@ -672,3 +737,20 @@ void AppTask::UpdateClusterState(void) ChipLogError(NotSpecified, "ERR: updating on/off %x", status); } } + +void AppTask::UpdateDeviceState(void) +{ + PlatformMgr().ScheduleWork(UpdateDeviceStateInternal, 0); +} + +void AppTask::UpdateDeviceStateInternal(intptr_t arg) +{ + bool onoffAttrValue = 0; + + /* get onoff attribute value */ + (void) emberAfReadAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, (uint8_t *) &onoffAttrValue, + 1, NULL); + + /* set the device state */ + sLightLED.Set(onoffAttrValue); +} diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/LightingManager.cpp b/examples/lighting-app/nxp/k32w/k32w0/main/LightingManager.cpp index 135df61442d050..af2dae0f3ff062 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/LightingManager.cpp +++ b/examples/lighting-app/nxp/k32w/k32w0/main/LightingManager.cpp @@ -28,7 +28,7 @@ LightingManager LightingManager::sLight; int LightingManager::Init() { - mState = kState_Off; + mState = kState_On; return 0; } diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h b/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h index 0e49456b8addd7..f067c2ed86368c 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h +++ b/examples/lighting-app/nxp/k32w/k32w0/main/include/AppEvent.h @@ -29,6 +29,7 @@ struct AppEvent kEventType_Timer, kEventType_TurnOn, kEventType_Install, + kEventType_OTAResume, }; AppEventTypes Type; diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/include/AppTask.h b/examples/lighting-app/nxp/k32w/k32w0/main/include/AppTask.h index 73ad95aebd50bc..d0ef272e00350c 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/include/AppTask.h +++ b/examples/lighting-app/nxp/k32w/k32w0/main/include/AppTask.h @@ -47,6 +47,7 @@ class AppTask void PostEvent(const AppEvent * event); void UpdateClusterState(void); + void UpdateDeviceState(void); private: friend AppTask & GetAppTask(void); @@ -66,6 +67,7 @@ class AppTask static void OTAHandler(AppEvent * aEvent); static void BleHandler(AppEvent * aEvent); static void LightActionEventHandler(AppEvent * aEvent); + static void OTAResumeEventHandler(AppEvent * aEvent); static void ResetActionEventHandler(AppEvent * aEvent); static void InstallEventHandler(AppEvent * aEvent); @@ -75,6 +77,16 @@ class AppTask static void ThreadProvisioningHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); void StartTimer(uint32_t aTimeoutInMs); +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + static void InitOTA(intptr_t arg); + static void StartOTAQuery(intptr_t arg); + static void PostOTAResume(); +#endif + + static void UpdateClusterStateInternal(intptr_t arg); + static void UpdateDeviceStateInternal(intptr_t arg); + static void InitServer(intptr_t arg); + enum Function_t { kFunction_NoneSelected = 0, diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/main.cpp b/examples/lighting-app/nxp/k32w/k32w0/main/main.cpp index bb1322e62cadc5..f3c4096c4d5a8a 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/main.cpp +++ b/examples/lighting-app/nxp/k32w/k32w0/main/main.cpp @@ -20,32 +20,22 @@ // Main Code // ================================================================================ -#include "openthread/platform/logging.h" #include -#include -#include -#include -#include +#include #include -#include #include -#include #include #include #include "FreeRtosHooks.h" #include "app_config.h" -#include "radio.h" - using namespace ::chip; using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; using namespace ::chip::Logging; -#include - typedef void (*InitFunc)(void); extern InitFunc __init_array_start; extern InitFunc __init_array_end; @@ -55,6 +45,8 @@ uint8_t __attribute__((section(".heap"))) ucHeap[HEAP_SIZE]; extern "C" void main_task(void const * argument) { + CHIP_ERROR err = CHIP_NO_ERROR; + /* Call C++ constructors */ InitFunc * pFunc = &__init_array_start; for (; pFunc < &__init_array_end; ++pFunc) @@ -62,59 +54,60 @@ extern "C" void main_task(void const * argument) (*pFunc)(); } - SHA_ClkInit(SHA_INSTANCE); - mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); - /* Used for HW initializations */ - otSysInit(0, NULL); + err = PlatformMgrImpl().InitBoardFwk(); + if (err != CHIP_NO_ERROR) + { + return; + } K32W_LOG("Welcome to NXP Lighting Demo App"); /* Mbedtls Threading support is needed because both - * Thread and Weave tasks are using it */ + * Thread and Matter tasks are using it */ freertos_mbedtls_mutex_init(); // Init Chip memory management before the stack chip::Platform::MemoryInit(); - CHIP_ERROR ret = PlatformMgr().InitChipStack(); - if (ret != CHIP_NO_ERROR) + err = PlatformMgr().InitChipStack(); + if (err != CHIP_NO_ERROR) { - K32W_LOG("Error during PlatformMgr().InitWeaveStack()"); + K32W_LOG("Error during PlatformMgr().InitMatterStack()"); goto exit; } - ret = ThreadStackMgr().InitThreadStack(); - if (ret != CHIP_NO_ERROR) + err = ThreadStackMgr().InitThreadStack(); + if (err != CHIP_NO_ERROR) { K32W_LOG("Error during ThreadStackMgr().InitThreadStack()"); goto exit; } - ret = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); - if (ret != CHIP_NO_ERROR) + err = ConnectivityMgr().SetThreadDeviceType(ConnectivityManager::kThreadDeviceType_MinimalEndDevice); + if (err != CHIP_NO_ERROR) { goto exit; } - ret = PlatformMgr().StartEventLoopTask(); - if (ret != CHIP_NO_ERROR) + err = PlatformMgr().StartEventLoopTask(); + if (err != CHIP_NO_ERROR) { K32W_LOG("Error during PlatformMgr().StartEventLoopTask();"); goto exit; } // Start OpenThread task - ret = ThreadStackMgrImpl().StartThreadTask(); - if (ret != CHIP_NO_ERROR) + err = ThreadStackMgrImpl().StartThreadTask(); + if (err != CHIP_NO_ERROR) { K32W_LOG("Error during ThreadStackMgrImpl().StartThreadTask()"); goto exit; } - ret = GetAppTask().StartAppTask(); - if (ret != CHIP_NO_ERROR) + err = GetAppTask().StartAppTask(); + if (err != CHIP_NO_ERROR) { K32W_LOG("Error during GetAppTask().StartAppTask()"); goto exit; diff --git a/examples/lock-app/nxp/k32w/k32w0/args.gni b/examples/lock-app/nxp/k32w/k32w0/args.gni index 0f921756420fce..aac1d79a737a71 100644 --- a/examples/lock-app/nxp/k32w/k32w0/args.gni +++ b/examples/lock-app/nxp/k32w/k32w0/args.gni @@ -17,3 +17,8 @@ import("${chip_root}/examples/platform/nxp/k32w/k32w0/args.gni") # SDK target. This is overridden to add our SDK app_config.h & defines. k32w0_sdk_target = get_label_info(":sdk", "label_no_toolchain") + +declare_args() { + chip_stack_lock_tracking = "fatal" + chip_enable_ble = true +} diff --git a/examples/lock-app/nxp/k32w/k32w0/data.bin b/examples/lock-app/nxp/k32w/k32w0/data.bin deleted file mode 100644 index 2bbd19d1429608..00000000000000 Binary files a/examples/lock-app/nxp/k32w/k32w0/data.bin and /dev/null differ diff --git a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h index ab177e86b699d4..e7529327edf259 100644 --- a/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/lock-app/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -86,7 +86,7 @@ * {MAJOR_VERSION}.0d{MINOR_VERSION} */ #ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING -#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "04-2020-te2" +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "03-2022-te8" #endif #ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION @@ -101,13 +101,6 @@ #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "NXP Demo App" #endif -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for CHIP-over-BLE (CHIPOBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - /** * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC * diff --git a/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp b/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp index 1d0173d97be8dc..837c18b4d210ff 100644 --- a/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp @@ -36,7 +36,6 @@ #include "Keyboard.h" #include "LED.h" #include "LEDWidget.h" -#include "TimersManager.h" #include "app_config.h" constexpr uint32_t kFactoryResetTriggerTimeout = 6000; @@ -53,7 +52,6 @@ static LEDWidget sLockLED; #endif static bool sIsThreadProvisioned = false; -static bool sIsThreadEnabled = false; static bool sHaveBLEConnections = false; static uint32_t eventMask = 0; @@ -86,9 +84,7 @@ CHIP_ERROR AppTask::Init() CHIP_ERROR err = CHIP_NO_ERROR; // Init ZCL Data Model and start server - static chip::CommonCaseDeviceServerInitParams initParams; - (void) initParams.InitializeStaticResourcesBeforeServerInit(); - chip::Server::GetInstance().Init(initParams); + PlatformMgr().ScheduleWork(InitServer, 0); // Initialize device attestation config SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); @@ -96,8 +92,6 @@ CHIP_ERROR AppTask::Init() // QR code will be used with CHIP Tool PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); - TMR_Init(); - /* HW init leds */ #if !cPWR_UsePowerDownMode LED_Init(); @@ -151,14 +145,21 @@ CHIP_ERROR AppTask::Init() assert(err == CHIP_NO_ERROR); } -#if CONFIG_CHIP_NFC_COMMISSIONING PlatformMgr().AddEventHandler(ThreadProvisioningHandler, 0); -#endif K32W_LOG("Current Software Version: %s", currentSoftwareVer); return err; } +void AppTask::InitServer(intptr_t arg) +{ + static chip::CommonCaseDeviceServerInitParams initParams; + (void) initParams.InitializeStaticResourcesBeforeServerInit(); + + // Init ZCL Data Model and start server + VerifyOrDie((chip::Server::GetInstance().Init(initParams)) == CHIP_NO_ERROR); +} + void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; @@ -195,10 +196,7 @@ void AppTask::AppTaskMain(void * pvParameter) #if CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI K32WUartProcess(); #endif - - sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); - sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled(); - sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); + sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); PlatformMgr().UnlockChipStack(); } @@ -218,7 +216,7 @@ void AppTask::AppTaskMain(void * pvParameter) #if !cPWR_UsePowerDownMode if (sAppTask.mFunction != kFunction_FactoryReset) { - if (sIsThreadProvisioned && sIsThreadEnabled) + if (sIsThreadProvisioned) { sStatusLED.Blink(950, 50); } @@ -535,9 +533,21 @@ void AppTask::BleHandler(void * aGenericEvent) } } -#if CONFIG_CHIP_NFC_COMMISSIONING void AppTask::ThreadProvisioningHandler(const ChipDeviceEvent * event, intptr_t) { + if (event->Type == DeviceEventType::kServiceProvisioningChange && event->ServiceProvisioningChange.IsServiceProvisioned) + { + if (event->ServiceProvisioningChange.IsServiceProvisioned) + { + sIsThreadProvisioned = TRUE; + } + else + { + sIsThreadProvisioned = FALSE; + } + } + +#if CONFIG_CHIP_NFC_COMMISSIONING if (event->Type == DeviceEventType::kCHIPoBLEAdvertisingChange && event->CHIPoBLEAdvertisingChange.Result == kActivity_Stopped) { if (!NFCMgr().IsTagEmulationStarted()) @@ -563,8 +573,8 @@ void AppTask::ThreadProvisioningHandler(const ChipDeviceEvent * event, intptr_t) K32W_LOG("Started NFC Tag Emulation!"); } } -} #endif +} void AppTask::CancelTimer() { @@ -703,6 +713,10 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } void AppTask::UpdateClusterState(void) +{ + PlatformMgr().ScheduleWork(UpdateClusterStateInternal, 0); +} +void AppTask::UpdateClusterStateInternal(intptr_t arg) { uint8_t newValue = !BoltLockMgr().IsUnlocked(); diff --git a/examples/lock-app/nxp/k32w/k32w0/main/include/AppTask.h b/examples/lock-app/nxp/k32w/k32w0/main/include/AppTask.h index 6ea8303d1934db..9e0116cacf7e8d 100644 --- a/examples/lock-app/nxp/k32w/k32w0/main/include/AppTask.h +++ b/examples/lock-app/nxp/k32w/k32w0/main/include/AppTask.h @@ -65,8 +65,9 @@ class AppTask static void TimerEventHandler(TimerHandle_t xTimer); static void ThreadProvisioningHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); - + static void UpdateClusterStateInternal(intptr_t arg); static void ThreadStart(); + static void InitServer(intptr_t arg); void StartTimer(uint32_t aTimeoutInMs); enum Function_t diff --git a/examples/lock-app/nxp/k32w/k32w0/main/main.cpp b/examples/lock-app/nxp/k32w/k32w0/main/main.cpp index 0552507b285282..216f98328503ee 100644 --- a/examples/lock-app/nxp/k32w/k32w0/main/main.cpp +++ b/examples/lock-app/nxp/k32w/k32w0/main/main.cpp @@ -20,16 +20,11 @@ // Main Code // ================================================================================ -#include "openthread/platform/logging.h" #include -#include -#include -#include +#include #include -#include #include -#include #include #include @@ -41,8 +36,6 @@ using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; using namespace ::chip::Logging; -#include - #if defined(cPWR_UsePowerDownMode) && (cPWR_UsePowerDownMode) #include "Keyboard.h" #include "PWR_Configuration.h" @@ -89,6 +82,8 @@ uint8_t __attribute__((section(".heap"))) ucHeap[HEAP_SIZE]; extern "C" void main_task(void const * argument) { + CHIP_ERROR err = CHIP_NO_ERROR; + /* Call C++ constructors */ InitFunc * pFunc = &__init_array_start; for (; pFunc < &__init_array_end; ++pFunc) @@ -96,7 +91,11 @@ extern "C" void main_task(void const * argument) (*pFunc)(); } - SHA_ClkInit(SHA_INSTANCE); + err = PlatformMgrImpl().InitBoardFwk(); + if (err != CHIP_NO_ERROR) + { + return; + } #if defined(cPWR_UsePowerDownMode) && (cPWR_UsePowerDownMode) PWR_Init(); @@ -110,13 +109,10 @@ extern "C" void main_task(void const * argument) mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); - /* Used for HW initializations */ - otSysInit(0, NULL); - K32W_LOG("Welcome to NXP ELock Demo App"); /* Mbedtls Threading support is needed because both - * Thread and Weave tasks are using it */ + * Thread and Matter tasks are using it */ freertos_mbedtls_mutex_init(); // Init Chip memory management before the stack @@ -125,7 +121,7 @@ extern "C" void main_task(void const * argument) CHIP_ERROR ret = PlatformMgr().InitChipStack(); if (ret != CHIP_NO_ERROR) { - K32W_LOG("Error during PlatformMgr().InitWeaveStack()"); + K32W_LOG("Error during PlatformMgr().InitMatterStack()"); goto exit; } @@ -324,4 +320,5 @@ static void BOARD_SetClockForWakeup(void) /* Enables the clock for the GPIO0 module */ CLOCK_EnableClock(kCLOCK_Gpio0); } + #endif diff --git a/examples/platform/nxp/k32w/k32w0/BUILD.gn b/examples/platform/nxp/k32w/k32w0/BUILD.gn index dfe84cc8a14499..8abd38f2a250eb 100644 --- a/examples/platform/nxp/k32w/k32w0/BUILD.gn +++ b/examples/platform/nxp/k32w/k32w0/BUILD.gn @@ -18,7 +18,10 @@ import("//build_overrides/k32w0_sdk.gni") import("${k32w0_sdk_build_root}/k32w0_sdk.gni") config("chip_examples_project_config") { - include_dirs = [ "app/project_include" ] + include_dirs = [ + "app/project_include", + "${chip_root}", + ] } source_set("openthread_core_config_k32w0_chip_examples") { diff --git a/examples/platform/nxp/k32w/k32w0/app/ldscripts/chip-k32w061-linker.ld b/examples/platform/nxp/k32w/k32w0/app/ldscripts/chip-k32w061-linker.ld index c4913037e98cf3..c880b29ec2b843 100644 --- a/examples/platform/nxp/k32w/k32w0/app/ldscripts/chip-k32w061-linker.ld +++ b/examples/platform/nxp/k32w/k32w0/app/ldscripts/chip-k32w061-linker.ld @@ -47,11 +47,22 @@ MEM_RAM0_SIZE = 0x0015c00; MEM_RAM1_BASE = 0x4020000; MEM_RAM1_SIZE = 0x10000; +/* internal flash size: 640K */ +m_int_flash_size = 0xA0000; +m_int_sector_size = 512; + +/* first 8K: SSBL, next 8K: SSBL update region */ +m_app_start = DEFINED(__app_load_address__) ? __app_load_address__ : 0x0; + +/* sizeof(BOOT_BLOCK_T) + sizeof(IMAGE_CERT_T) + SIGNATURE_LEN + alignment = 1024 bytes */ +m_app_meta_data = 0x400; + +/* 640K (Total Flash size) - 16K (SSBL + SSBL update region) - 8.5K (PSECT) - m_app_meta_data */ +m_app_size = DEFINED(__app_stated_size__) ? __app_stated_size__ : 0x9FC00; + MEMORY { - /* Define each memory region. RAM0 definition leaves the first 1kB for the - boot code */ - Flash640 (rx) : ORIGIN = 0, LENGTH = 0x00a0000 /* 640K bytes (alias Flash) */ + Flash640 (rx) : ORIGIN = m_app_start, LENGTH = m_app_size RAM0 (rwx) : ORIGIN = 0x4000400, LENGTH = 0x0015c00 /* 87K bytes (alias RAM) */ RAM1 (rwx) : ORIGIN = 0x4020000, LENGTH = 0x10000 /* 64K bytes (alias RAM2) */ } @@ -60,7 +71,7 @@ MEMORY __top_RAM1 = MEM_RAM1_BASE + MEM_RAM1_SIZE; /* 64K bytes */ /* To be improved. At this moment the second RAM bank is dedicated entirely to heap + stack. */ -HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : 0xF000; +HEAP_SIZE = DEFINED(HEAP_SIZE) ? HEAP_SIZE : 0x10000; /* set external flash properties - external flash is present on the DK6 board */ m_ext_flash_size = 0x00100000; @@ -75,7 +86,9 @@ NV_STORAGE_SECTOR_SIZE = m_ext_flash_sector_size; NV_STORAGE_START_ADDRESS = m_ext_flash_size - 1; NV_STORAGE_END_ADDRESS = NV_STORAGE_START_ADDRESS - NV_STORAGE_SIZE + 1; -m_app_size = 0x00a0000; /* 640K */ +INT_STORAGE_START = m_int_flash_size - 17 * m_int_sector_size - 1; +INT_STORAGE_END = INT_STORAGE_START; +INT_STORAGE_SIZE = INT_STORAGE_START - INT_STORAGE_END; __ram_vector_table__ = 1; vector_table_size = 0x120; @@ -328,5 +341,4 @@ SECTIONS PROVIDE(_pvHeapLimit = _pvHeapStart + (HEAP_SIZE)); __StackLimit = _vStackTop - STACK_SIZE; - ASSERT (LENGTH(Flash640) >= (_etext + SIZEOF(.data)), "Application does not fit into flash!") } diff --git a/examples/platform/nxp/k32w/k32w0/app/support/BUILD.gn b/examples/platform/nxp/k32w/k32w0/app/support/BUILD.gn index ca8fabba7e2dea..014199c60a7619 100644 --- a/examples/platform/nxp/k32w/k32w0/app/support/BUILD.gn +++ b/examples/platform/nxp/k32w/k32w0/app/support/BUILD.gn @@ -44,8 +44,7 @@ source_set("freertos_mbedtls_utils") { "Memconfig.cpp", ] - #TODO: not sure this is required, maybe we should make this dependant on mbedtls - public_deps = [ "${k32w0_sdk_build_root}:k32w0_sdk" ] + deps = [ "${chip_root}/src/lib/support" ] cflags = [ "-Wconversion" ] diff --git a/examples/platform/nxp/k32w/k32w0/app/support/Memconfig.cpp b/examples/platform/nxp/k32w/k32w0/app/support/Memconfig.cpp index 87c8639f214298..8bcd4551bb300d 100644 --- a/examples/platform/nxp/k32w/k32w0/app/support/Memconfig.cpp +++ b/examples/platform/nxp/k32w/k32w0/app/support/Memconfig.cpp @@ -33,6 +33,8 @@ #include #endif +#include + #if CHIP_CONFIG_MEMORY_DEBUG_DMALLOC #include #include @@ -123,6 +125,10 @@ void * __wrap_calloc(size_t num, size_t size) { memset(ptr, 0, total_size); } + else + { + ChipLogError(DeviceLayer, "__wrap_calloc: Could not allocate memory!"); + } return ptr; } @@ -147,6 +153,7 @@ void * __wrap_realloc(void * ptr, size_t new_size) if (!new_ptr) { + ChipLogError(DeviceLayer, "__wrap_realloc: Could not allocate memory!"); return NULL; } diff --git a/examples/platform/nxp/k32w/k32w0/doc/images/flash_location.JPG b/examples/platform/nxp/k32w/k32w0/doc/images/flash_location.JPG new file mode 100644 index 00000000000000..9ee50ba61173c5 Binary files /dev/null and b/examples/platform/nxp/k32w/k32w0/doc/images/flash_location.JPG differ diff --git a/examples/platform/nxp/k32w/k32w0/doc/images/ota_topology.JPG b/examples/platform/nxp/k32w/k32w0/doc/images/ota_topology.JPG new file mode 100644 index 00000000000000..75fc40a70e3b27 Binary files /dev/null and b/examples/platform/nxp/k32w/k32w0/doc/images/ota_topology.JPG differ diff --git a/examples/platform/nxp/k32w/k32w0/doc/images/pdm_ext_flash.JPG b/examples/platform/nxp/k32w/k32w0/doc/images/pdm_ext_flash.JPG new file mode 100644 index 00000000000000..00ceab4d6d0bff Binary files /dev/null and b/examples/platform/nxp/k32w/k32w0/doc/images/pdm_ext_flash.JPG differ diff --git a/examples/platform/nxp/k32w/k32w0/doc/images/ssbl_bin.JPG b/examples/platform/nxp/k32w/k32w0/doc/images/ssbl_bin.JPG new file mode 100644 index 00000000000000..fb871d45aeb5f9 Binary files /dev/null and b/examples/platform/nxp/k32w/k32w0/doc/images/ssbl_bin.JPG differ diff --git a/examples/platform/nxp/k32w/k32w0/doc/images/ssbl_select.JPG b/examples/platform/nxp/k32w/k32w0/doc/images/ssbl_select.JPG new file mode 100644 index 00000000000000..79ea51b62698e8 Binary files /dev/null and b/examples/platform/nxp/k32w/k32w0/doc/images/ssbl_select.JPG differ diff --git a/examples/shell/nxp/k32w/k32w0/args.gni b/examples/shell/nxp/k32w/k32w0/args.gni index 788b29c6c8fb3e..5f68faa6512372 100644 --- a/examples/shell/nxp/k32w/k32w0/args.gni +++ b/examples/shell/nxp/k32w/k32w0/args.gni @@ -18,3 +18,7 @@ import("${chip_root}/examples/platform/nxp/k32w/k32w0/args.gni") import("${chip_root}/src/platform/nxp/k32w/k32w0/args.gni") k32w0_sdk_target = get_label_info(":sdk", "label_no_toolchain") + +declare_args() { + chip_enable_ble = true +} diff --git a/examples/shell/nxp/k32w/k32w0/data.bin b/examples/shell/nxp/k32w/k32w0/data.bin deleted file mode 100644 index 7fbde80387a55d..00000000000000 Binary files a/examples/shell/nxp/k32w/k32w0/data.bin and /dev/null differ diff --git a/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h b/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h index e3075bbce62e0b..a5f5b04740b222 100644 --- a/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h +++ b/examples/shell/nxp/k32w/k32w0/include/CHIPProjectConfig.h @@ -101,13 +101,6 @@ #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME "NXP Demo App" #endif -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for CHIP-over-BLE (CHIPOBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - /** * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC * diff --git a/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp b/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp index 383dbdb1f9b19d..89b0e14eb59717 100644 --- a/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp @@ -31,7 +31,6 @@ #include "Keyboard.h" #include "LED.h" #include "LEDWidget.h" -#include "TimersManager.h" #include "app_config.h" #define FACTORY_RESET_TRIGGER_TIMEOUT 6000 @@ -85,8 +84,6 @@ CHIP_ERROR AppTask::Init() // QR code will be used with CHIP Tool PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); - TMR_Init(); - /* HW init leds */ LED_Init(); diff --git a/examples/shell/nxp/k32w/k32w0/main/main.cpp b/examples/shell/nxp/k32w/k32w0/main/main.cpp index da20f798e4cca7..196623359aaffd 100644 --- a/examples/shell/nxp/k32w/k32w0/main/main.cpp +++ b/examples/shell/nxp/k32w/k32w0/main/main.cpp @@ -20,12 +20,8 @@ // Main Code // ================================================================================ -#include "openthread/platform/logging.h" +#include #include -#include -#include -#include -#include #include #include @@ -40,10 +36,6 @@ #include "FreeRtosHooks.h" #include "app_config.h" -#include "radio.h" - -#include - const uint16_t shell_task_size = 3096; const uint8_t shell_task_priority = 0; @@ -74,8 +66,10 @@ static void shell_task(void * args) extern "C" void main_task(void const * argument) { - int status = 0; + int status = 0; + char * argv[1] = { 0 }; BaseType_t shellTaskHandle; + CHIP_ERROR err = CHIP_NO_ERROR; /* Call C++ constructors */ InitFunc * pFunc = &__init_array_start; @@ -84,15 +78,18 @@ extern "C" void main_task(void const * argument) (*pFunc)(); } - mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); + err = PlatformMgrImpl().InitBoardFwk(); + if (err != CHIP_NO_ERROR) + { + return; + } - /* Used for HW initializations */ - otSysInit(0, NULL); + mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); K32W_LOG("Welcome to NXP Shell Demo App"); /* Mbedtls Threading support is needed because both - * Thread and Weave tasks are using it */ + * Thread and Matter tasks are using it */ freertos_mbedtls_mutex_init(); // Init Chip memory management before the stack @@ -101,7 +98,7 @@ extern "C" void main_task(void const * argument) CHIP_ERROR ret = PlatformMgr().InitChipStack(); if (ret != CHIP_NO_ERROR) { - K32W_LOG("Error during PlatformMgr().InitWeaveStack()"); + K32W_LOG("Error during PlatformMgr().InitMatterStack()"); goto exit; } diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index ec310f80a7b489..de3e94538ade28 100644 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -460,15 +460,8 @@ def AmebaTargets(): def K32WTargets(): target = Target('k32w', K32WBuilder) - # This is for testing only in case debug builds are to be fixed - # Error is LWIP_DEBUG being redefined between 0 and 1 in debug builds in: - # third_party/connectedhomeip/src/lwip/k32w0/lwipopts.h - # gen/include/lwip/lwip_buildconfig.h - yield target.Extend('light', app=K32WApp.LIGHT).GlobBlacklist("Debug builds broken due to LWIP_DEBUG redefition") - - yield target.Extend('light-release', app=K32WApp.LIGHT, release=True) - yield target.Extend('light-tokenizer-release', app=K32WApp.LIGHT, - tokenizer=True, release=True).GlobBlacklist("Only on demand build") + yield target.Extend('light-ota-se', app=K32WApp.LIGHT, release=True, disable_ble=True, se05x=True).GlobBlacklist("Only on demand build") + yield target.Extend('light-release-no-ota', app=K32WApp.LIGHT, tokenizer=True, disable_ota=True, release=True) yield target.Extend('shell-release', app=K32WApp.SHELL, release=True) yield target.Extend('lock-release', app=K32WApp.LOCK, release=True) yield target.Extend('lock-low-power-release', app=K32WApp.LOCK, diff --git a/scripts/build/builders/k32w.py b/scripts/build/builders/k32w.py index e5624ca621ff66..ea446ec8a40e88 100644 --- a/scripts/build/builders/k32w.py +++ b/scripts/build/builders/k32w.py @@ -55,7 +55,10 @@ def __init__(self, app: K32WApp = K32WApp.LIGHT, release: bool = False, low_power: bool = False, - tokenizer: bool = False): + tokenizer: bool = False, + disable_ble: bool = False, + disable_ota: bool = False, + se05x: bool = False): super(K32WBuilder, self).__init__( root=app.BuildRoot(root), runner=runner) @@ -64,6 +67,9 @@ def __init__(self, self.low_power = low_power self.tokenizer = tokenizer self.release = release + self.disable_ble = disable_ble + self.disable_ota = disable_ota + self.se05x = se05x def GnBuildArgs(self): args = [ @@ -81,6 +87,15 @@ def GnBuildArgs(self): if self.release: args.append('is_debug=false') + if self.disable_ble: + args.append('chip_enable_ble=false') + + if self.disable_ota: + args.append('chip_enable_ota_requestor=false') + + if self.se05x: + args.append('chip_with_se05x=true') + return args def generate(self): diff --git a/scripts/build/testdata/all_targets_except_host.txt b/scripts/build/testdata/all_targets_except_host.txt index 647e0b0a02bfc3..a25205367182fa 100644 --- a/scripts/build/testdata/all_targets_except_host.txt +++ b/scripts/build/testdata/all_targets_except_host.txt @@ -152,9 +152,8 @@ esp32-qemu-tests infineon-p6-all-clusters infineon-p6-light infineon-p6-lock -k32w-light (NOGLOB: Debug builds broken due to LWIP_DEBUG redefition) -k32w-light-release -k32w-light-tokenizer-release (NOGLOB: Only on demand build) +k32w-light-ota-se (NOGLOB: Only on demand build) +k32w-light-release-no-ota k32w-lock-low-power-release (NOGLOB: Only on demand build) k32w-lock-release k32w-shell-release diff --git a/scripts/build/testdata/build_all_except_host.txt b/scripts/build/testdata/build_all_except_host.txt index 552aea9f5efdae..81ae8a8de857b0 100644 --- a/scripts/build/testdata/build_all_except_host.txt +++ b/scripts/build/testdata/build_all_except_host.txt @@ -700,18 +700,13 @@ gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/exa {root}/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh -# Generating k32w-light -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/nxp/k32w/k32w0 '--args=k32w0_sdk_root="TEST_NXP_K32W061_SDK_ROOT" chip_with_low_power=0' {out}/k32w-light +# Generating k32w-light-ota-se +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/nxp/k32w/k32w0 '--args=k32w0_sdk_root="TEST_NXP_K32W061_SDK_ROOT" chip_with_low_power=0 is_debug=false chip_enable_ble=false chip_with_se05x=true' {out}/k32w-light-ota-se {root}/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh -# Generating k32w-light-release -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/nxp/k32w/k32w0 '--args=k32w0_sdk_root="TEST_NXP_K32W061_SDK_ROOT" chip_with_low_power=0 is_debug=false' {out}/k32w-light-release - -{root}/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh - -# Generating k32w-light-tokenizer-release -gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/nxp/k32w/k32w0 '--args=k32w0_sdk_root="TEST_NXP_K32W061_SDK_ROOT" chip_with_low_power=0 chip_pw_tokenizer_logging=true is_debug=false' {out}/k32w-light-tokenizer-release +# Generating k32w-light-release-no-ota +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/nxp/k32w/k32w0 '--args=k32w0_sdk_root="TEST_NXP_K32W061_SDK_ROOT" chip_with_low_power=0 chip_pw_tokenizer_logging=true is_debug=false chip_enable_ota_requestor=false' {out}/k32w-light-release-no-ota {root}/third_party/nxp/k32w0_sdk/sdk_fixes/patch_k32w_sdk.sh @@ -1619,14 +1614,11 @@ ninja -C {out}/infineon-p6-light # Building infineon-p6-lock ninja -C {out}/infineon-p6-lock -# Building k32w-light -ninja -C {out}/k32w-light - -# Building k32w-light-release -ninja -C {out}/k32w-light-release +# Building k32w-light-ota-se +ninja -C {out}/k32w-light-ota-se -# Building k32w-light-tokenizer-release -ninja -C {out}/k32w-light-tokenizer-release +# Building k32w-light-release-no-ota +ninja -C {out}/k32w-light-release-no-ota # Building k32w-lock-low-power-release ninja -C {out}/k32w-lock-low-power-release diff --git a/scripts/build/testdata/glob_star_targets_except_host.txt b/scripts/build/testdata/glob_star_targets_except_host.txt index 3adfb5b384ab2e..b28e45f29b39e9 100644 --- a/scripts/build/testdata/glob_star_targets_except_host.txt +++ b/scripts/build/testdata/glob_star_targets_except_host.txt @@ -46,7 +46,7 @@ esp32-qemu-tests infineon-p6-all-clusters infineon-p6-light infineon-p6-lock -k32w-light-release +k32w-light-release-no-ota k32w-lock-release k32w-shell-release mbed-CY8CPROTO_062_4343W-all-clusters-release diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp index e5158a9905f7eb..7e44dcbaba1b9a 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.cpp @@ -99,6 +99,11 @@ uint16_t DefaultOTARequestorDriver::GetMaxDownloadBlockSize() return 1024; } +void DefaultOTARequestorDriver::SetMaxDownloadBlockSize(uint16_t blockSize) +{ + maxDownloadBlockSize = blockSize; +} + void StartDelayTimerHandler(System::Layer * systemLayer, void * appState) { ToDriver(appState)->SendQueryImage(); diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h index 87c66a5f775922..f0948dd3d22a96 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h @@ -64,6 +64,7 @@ class DefaultOTARequestorDriver : public OTARequestorDriver //// Virtual methods from OTARequestorDriver bool CanConsent() override; uint16_t GetMaxDownloadBlockSize() override; + void SetMaxDownloadBlockSize(uint16_t maxDownloadBlockSize) override; void HandleError(UpdateFailureState state, CHIP_ERROR error) override; void HandleIdleStateExit() override; void HandleIdleState(IdleStateReason reason) override; @@ -99,6 +100,7 @@ class DefaultOTARequestorDriver : public OTARequestorDriver uint32_t mPeriodicQueryTimeInterval = (24 * 60 * 60); // Timeout (in seconds) for checking if current OTA download is stuck and requires a reset uint32_t mWatchdogTimeInterval = (6 * 60 * 60); + uint16_t maxDownloadBlockSize = 1024; // Maximum number of times to retry a BUSY OTA provider before moving to the next available one static constexpr uint8_t kMaxBusyProviderRetryCount = 3; uint8_t mProviderRetryCount; // Track retry count for the current provider diff --git a/src/app/clusters/ota-requestor/OTARequestorDriver.h b/src/app/clusters/ota-requestor/OTARequestorDriver.h index bcdc58b8010d81..d3856d17543e12 100644 --- a/src/app/clusters/ota-requestor/OTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/OTARequestorDriver.h @@ -91,6 +91,9 @@ class OTARequestorDriver /// Return maximum supported download block size virtual uint16_t GetMaxDownloadBlockSize() { return 1024; } + /// Set maximum supported download block size + virtual void SetMaxDownloadBlockSize(uint16_t maxDownloadBlockSize) = 0; + /// Called when an error occurs at any OTA requestor operation virtual void HandleError(UpdateFailureState state, CHIP_ERROR error) = 0; diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 0b935ff471c4d0..f5988a7a4ffc4d 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -240,6 +240,11 @@ enum PublicEventTypes * Signals that bindings were updated. */ kBindingsChangedViaCluster, + + /** + * Signals that the state of the OTA engine changed. + */ + kOtaStateChanged, }; /** @@ -299,6 +304,11 @@ enum ActivityChange kActivity_Stopped = -1, }; +enum OtaState +{ + kOtaSpaceAvailable = 0, +}; + inline ConnectivityChange GetConnectivityChange(bool prevState, bool newState) { if (prevState == newState) @@ -468,6 +478,11 @@ struct ChipDeviceEvent final // TODO(cecille): This should just specify wifi or thread since we assume at most 1. int network; } OperationalNetwork; + + struct + { + OtaState newState; + } OtaStateChanged; }; void Clear() { memset(this, 0, sizeof(*this)); } diff --git a/src/lwip/k32w0/lwipopts.h b/src/lwip/k32w0/lwipopts.h index daeb6afb17c035..1ecec9f14f0a70 100644 --- a/src/lwip/k32w0/lwipopts.h +++ b/src/lwip/k32w0/lwipopts.h @@ -113,7 +113,7 @@ #define PBUF_LINK_HLEN (0) #define TCPIP_THREAD_STACKSIZE (2048) -#define TCPIP_THREAD_PRIO (2) +#define TCPIP_THREAD_PRIO (3) #define NETIF_MAX_HWADDR_LEN 8U diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index f5e87a8b13deb7..ccacf2ccd87063 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -111,7 +111,8 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { ] if (chip_device_platform == "linux" || chip_device_platform == "darwin" || - chip_device_platform == "tizen" || chip_device_platform == "android") { + chip_device_platform == "tizen" || chip_device_platform == "android" || + chip_device_platform == "k32w0") { defines += [ "CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE=${chip_enable_ble}" ] } diff --git a/src/platform/nxp/k32w/k32w0/BLEManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/BLEManagerImpl.cpp index 00229438b1616c..d96c3c0e1ed6cc 100644 --- a/src/platform/nxp/k32w/k32w0/BLEManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/BLEManagerImpl.cpp @@ -41,8 +41,6 @@ #include "stdio.h" #include "timers.h" -#include "RNG_Interface.h" - #if defined(cPWR_UsePowerDownMode) && (cPWR_UsePowerDownMode) #include "PWR_Configuration.h" #endif @@ -100,7 +98,7 @@ namespace { #define CONTROLLER_TASK_STACK_SIZE (gControllerTaskStackSize_c / sizeof(StackType_t)) /* host task configuration */ -#define HOST_TASK_PRIORITY (3U) +#define HOST_TASK_PRIORITY (4U) #define HOST_TASK_STACK_SIZE (gHost_TaskStackSize_c / sizeof(StackType_t)) /* ble app task configuration */ @@ -160,9 +158,6 @@ CHIP_ERROR BLEManagerImpl::_Init() err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer()); SuccessOrExit(err); - (void) RNG_Init(); - RNG_SetPseudoRandomNoSeed(NULL); - /* Initialization of message wait events - * used for receiving BLE Stack events */ event_msg = OSA_EventCreate(TRUE); diff --git a/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h b/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h index 13232a2819b4d2..7a5778406aefa2 100644 --- a/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h +++ b/src/platform/nxp/k32w/k32w0/CHIPDevicePlatformConfig.h @@ -33,10 +33,6 @@ #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 0 #define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 0 -#ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 -#endif - #ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #define CHIP_DEVICE_CHIP0BLE_DEBUG 0 #endif @@ -94,9 +90,15 @@ #define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART 0 +#define CHIP_DEVICE_CONFIG_THREAD_TASK_PRIORITY 3 + +#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY 2 + #if CHIP_ENABLE_OPENTHREAD #define CHIP_DEVICE_CONFIG_ENABLE_THREAD 1 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 1 #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 1 #define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 #endif + +#define CHIP_DEVICE_CONFIG_ENABLE_TEST_SETUP_PARAMS 1 diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp index 8819a8d3ca5dde..ec29b04d2e81a8 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.cpp @@ -52,6 +52,13 @@ CHIP_ERROR ConfigurationManagerImpl::Init() CHIP_ERROR err; uint32_t rebootCount = 0; + // Save out software version on first boot + if (!K32WConfig::ConfigValueExists(K32WConfig::kConfigKey_SoftwareVersion)) + { + err = StoreSoftwareVersion(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION); + SuccessOrExit(err); + } + if (K32WConfig::ConfigValueExists(K32WConfig::kCounterKey_RebootCount)) { err = GetRebootCount(rebootCount); @@ -111,6 +118,16 @@ CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOp return WriteConfigValue(K32WConfig::kCounterKey_TotalOperationalHours, totalOperationalHours); } +CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersion(uint32_t & softwareVer) +{ + return ReadConfigValue(K32WConfig::kConfigKey_SoftwareVersion, softwareVer); +} + +CHIP_ERROR ConfigurationManagerImpl::StoreSoftwareVersion(uint32_t softwareVer) +{ + return WriteConfigValue(K32WConfig::kConfigKey_SoftwareVersion, softwareVer); +} + CHIP_ERROR ConfigurationManagerImpl::GetBootReason(uint32_t & bootReason) { bootReason = to_underlying(BootReasonType::kUnspecified); diff --git a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h index e7825239474125..bdceee20899ace 100644 --- a/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h +++ b/src/platform/nxp/k32w/k32w0/ConfigurationManagerImpl.h @@ -51,6 +51,8 @@ class ConfigurationManagerImpl final : public Internal::GenericConfigurationMana CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override; CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; + CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override; + CHIP_ERROR StoreSoftwareVersion(uint32_t softwareVer) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override; CHIP_ERROR GetBootReason(uint32_t & bootReasons) override; diff --git a/src/platform/nxp/k32w/k32w0/K32W0Config.cpp b/src/platform/nxp/k32w/k32w0/K32W0Config.cpp index bf4910285160c4..6c8e4f9c1f2ad7 100644 --- a/src/platform/nxp/k32w/k32w0/K32W0Config.cpp +++ b/src/platform/nxp/k32w/k32w0/K32W0Config.cpp @@ -287,8 +287,20 @@ CHIP_ERROR K32WConfig::WriteConfigValueStr(Key key, const char * str, size_t str if (str != NULL) { - pdmStatus = PDM_eSaveRecordData((uint16_t) key, (void *) str, strLen); - SuccessOrExit(err = MapPdmStatus(pdmStatus)); + 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; + } } else { diff --git a/src/platform/nxp/k32w/k32w0/K32W0Config.h b/src/platform/nxp/k32w/k32w0/K32W0Config.h index 08dcb907d999cc..f02bd367036f1a 100644 --- a/src/platform/nxp/k32w/k32w0/K32W0Config.h +++ b/src/platform/nxp/k32w/k32w0/K32W0Config.h @@ -28,7 +28,6 @@ #include -#include "MemManager.h" #include "PDM.h" namespace chip { @@ -92,6 +91,8 @@ class K32WConfig static constexpr Key kConfigKey_CountryCode = K32WConfigKey(kPDMId_ChipConfig, 0x08); static constexpr Key kConfigKey_Breadcrumb = K32WConfigKey(kPDMId_ChipConfig, 0x09); static constexpr Key kConfigKey_UniqueId = K32WConfigKey(kPDMId_ChipConfig, 0x0A); + static constexpr Key kConfigKey_SoftwareVersion = K32WConfigKey(kPDMId_ChipConfig, 0x0B); + static constexpr Key kConfigKey_FirstRunOfOTAImage = K32WConfigKey(kPDMId_ChipConfig, 0x0C); // CHIP Counter Keys static constexpr Key kCounterKey_RebootCount = K32WConfigKey(kPDMId_ChipCounter, 0x00); @@ -101,11 +102,11 @@ class K32WConfig // Set key id limits for each group. static constexpr Key kMinConfigKey_ChipFactory = K32WConfigKey(kPDMId_ChipFactory, 0x00); - static constexpr Key kMaxConfigKey_ChipFactory = K32WConfigKey(kPDMId_ChipFactory, 0x0B); + static constexpr Key kMaxConfigKey_ChipFactory = K32WConfigKey(kPDMId_ChipFactory, 0xFF); static constexpr Key kMinConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0x00); - static constexpr Key kMaxConfigKey_ChipConfig = K32WConfigKey(kPDMId_ChipConfig, 0x1E); + 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, 0x1F); // Allows 32 Counters to be created. + 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); diff --git a/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp index 5753f614a0550a..09fe21772150b4 100644 --- a/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/KeyValueStoreManagerImpl.cpp @@ -38,7 +38,7 @@ namespace DeviceLayer { namespace PersistedStorage { /* TODO: adjust these values */ -constexpr size_t kMaxNumberOfKeys = 20; +constexpr size_t kMaxNumberOfKeys = 30; constexpr size_t kMaxKeyValueBytes = 255; KeyValueStoreManagerImpl KeyValueStoreManagerImpl::sInstance; @@ -118,7 +118,7 @@ CHIP_ERROR RestoreFromFlash() 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_DEVICE_ERROR_CONFIG_NOT_FOUND; + 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; @@ -194,7 +194,8 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, 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); - err = chip::DeviceLayer::Internal::K32WConfig::WriteConfigValueStr(pdm_internal_id, key, strlen(key)); + /* 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); if (err != CHIP_NO_ERROR) { diff --git a/src/platform/nxp/k32w/k32w0/NFCManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/NFCManagerImpl.cpp index 90267ff0aff148..f6254515312d5b 100644 --- a/src/platform/nxp/k32w/k32w0/NFCManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/NFCManagerImpl.cpp @@ -25,6 +25,8 @@ #include #include +#include "FunctionLib.h" + namespace chip { namespace DeviceLayer { diff --git a/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.cpp b/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.cpp index 895f116bc0d11c..27deee3fece95f 100644 --- a/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.cpp @@ -16,7 +16,9 @@ * limitations under the License. */ +#include #include +#include #include "OTAImageProcessorImpl.h" #include "OtaSupport.h" @@ -24,16 +26,13 @@ extern "C" void ResetMCU(void); +using namespace chip::DeviceLayer; +using namespace ::chip::DeviceLayer::Internal; + namespace chip { CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() { - if (mImageFile == nullptr) - { - ChipLogError(SoftwareUpdate, "Invalid output image file supplied"); - return CHIP_ERROR_INTERNAL; - } - DeviceLayer::PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast(this)); return CHIP_NO_ERROR; } @@ -46,6 +45,7 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize() CHIP_ERROR OTAImageProcessorImpl::Apply() { + DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast(this)); return CHIP_NO_ERROR; } @@ -79,6 +79,14 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) return CHIP_NO_ERROR; } +void OTAImageProcessorImpl::TriggerNewRequestForData() +{ + if (mDownloader) + { + this->mDownloader->FetchNextData(); + } +} + void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) { auto * imageProcessor = reinterpret_cast(context); @@ -95,13 +103,26 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) if (gOtaSuccess_c == OTA_ClientInit()) { - if (gOtaSuccess_c == OTA_StartImage(strlen(imageProcessor->mImageFile))) - { - imageProcessor->mDownloader->OnPreparedForDownload(CHIP_NO_ERROR); - } + imageProcessor->mHeaderParser.Init(); + imageProcessor->mDownloader->OnPreparedForDownload(CHIP_NO_ERROR); } } +CHIP_ERROR OTAImageProcessorImpl::ProcessHeader(ByteSpan & block) +{ + OTAImageHeader header; + CHIP_ERROR error = mHeaderParser.AccumulateAndDecode(block, header); + + // Needs more data to decode the header + ReturnErrorCodeIf(error == CHIP_ERROR_BUFFER_TOO_SMALL, CHIP_NO_ERROR); + ReturnErrorOnFailure(error); + mParams.totalFileBytes = header.mPayloadSize; + mSoftwareVersion = header.mSoftwareVersion; + mHeaderParser.Clear(); + + return CHIP_NO_ERROR; +} + void OTAImageProcessorImpl::HandleAbort(intptr_t context) { auto * imageProcessor = reinterpret_cast(context); @@ -116,6 +137,8 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) { + CHIP_ERROR error = CHIP_NO_ERROR; + auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { @@ -128,8 +151,50 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) return; } + /* process OTA header if not already did */ + if (imageProcessor->mHeaderParser.IsInitialized()) + { + ByteSpan block = ByteSpan(imageProcessor->mBlock.data(), imageProcessor->mBlock.size()); + + error = imageProcessor->ProcessHeader(block); + if (error == CHIP_NO_ERROR) + { + if (gOtaSuccess_c == OTA_StartImage(imageProcessor->mParams.totalFileBytes)) + { + uint8_t * ptr = static_cast(chip::Platform::MemoryAlloc(block.size())); + + if (ptr != nullptr) + { + MutableByteSpan mutableBlock = MutableByteSpan(ptr, block.size()); + error = CopySpanToMutableSpan(block, mutableBlock); + + if (error == CHIP_NO_ERROR) + { + imageProcessor->ReleaseBlock(); + imageProcessor->mBlock = MutableByteSpan(mutableBlock.data(), mutableBlock.size()); + } + } + else + { + error = CHIP_ERROR_NO_MEMORY; + } + } + else + { + error = CHIP_ERROR_INTERNAL; + } + } + } + + if (error != CHIP_NO_ERROR) + { + ChipLogError(SoftwareUpdate, "Failed to process OTA image header"); + imageProcessor->mDownloader->EndDownload(error); + return; + } + /* Will start an erase of 4K if necessary */ - if (gOtaSuccess_c == OTA_MakeHeadRoomForNextBlock(imageProcessor->mBlock.size(), NULL, 0)) + if (gOtaSuccess_c == OTA_MakeHeadRoomForNextBlock(imageProcessor->mBlock.size(), HandleBlockEraseComplete, 0)) { if (gOtaSuccess_c == OTA_PushImageChunk(imageProcessor->mBlock.data(), (uint16_t) imageProcessor->mBlock.size(), NULL, NULL)) @@ -140,6 +205,25 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) } } +bool OTAImageProcessorImpl::IsFirstImageRun() +{ + bool firstRun = false; + + if (CHIP_NO_ERROR == (K32WConfig::ReadConfigValue(K32WConfig::kConfigKey_FirstRunOfOTAImage, firstRun))) + { + return firstRun; + } + + return false; +} + +CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() +{ + bool firstRun = false; + + return K32WConfig::WriteConfigValue(K32WConfig::kConfigKey_FirstRunOfOTAImage, firstRun); +} + CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) { if (!IsSpanUsable(block)) @@ -176,15 +260,37 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) return; } + imageProcessor->ReleaseBlock(); +} + +void OTAImageProcessorImpl::HandleApply(intptr_t context) +{ + auto * imageProcessor = reinterpret_cast(context); + bool firstRun = true; + + if (imageProcessor == nullptr) + { + return; + } + OTA_CommitImage(NULL); if (OTA_ImageAuthenticate() == gOtaImageAuthPass_c) { - /* Set the necessary information to inform the SSBL that a new image is available */ - OTA_SetNewImageFlag(); - ResetMCU(); - } - imageProcessor->ReleaseBlock(); + /* TODO internal: MATTER-126 */ + /*if (CHIP_NO_ERROR == K32WConfig::WriteConfigValue(K32WConfig::kConfigKey_FirstRunOfOTAImage, firstRun)) */ + { + /* Set the necessary information to inform the SSBL that a new image is available */ + DeviceLayer::ConfigurationMgr().StoreSoftwareVersion(imageProcessor->mSoftwareVersion); + OTA_SetNewImageFlag(); + ChipLogProgress(SoftwareUpdate, "OTA image authentication success. Device will reboot with the new image!"); + ResetMCU(); + } + } + else + { + ChipLogError(SoftwareUpdate, "Image authentication error"); + } } CHIP_ERROR OTAImageProcessorImpl::ReleaseBlock() @@ -198,4 +304,19 @@ CHIP_ERROR OTAImageProcessorImpl::ReleaseBlock() return CHIP_NO_ERROR; } +void OTAImageProcessorImpl::HandleBlockEraseComplete(uint32_t) +{ + CHIP_ERROR error = CHIP_NO_ERROR; + + ChipDeviceEvent otaChange; + otaChange.Type = DeviceEventType::kOtaStateChanged; + otaChange.OtaStateChanged.newState = kOtaSpaceAvailable; + error = PlatformMgr().PostEvent(&otaChange); + + if (error != CHIP_NO_ERROR) + { + ChipLogError(SoftwareUpdate, "Error while posting OtaChange event"); + } +} + } // namespace chip diff --git a/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.h b/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.h index 845c43bfc85eea..e431f538c5e984 100644 --- a/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.h +++ b/src/platform/nxp/k32w/k32w0/OTAImageProcessorImpl.h @@ -18,6 +18,7 @@ #pragma once +#include #include #include #include @@ -33,18 +34,21 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface CHIP_ERROR Apply() override; CHIP_ERROR Abort() override; CHIP_ERROR ProcessBlock(ByteSpan & block) override; - bool IsFirstImageRun() override { return false; } - CHIP_ERROR ConfirmCurrentImage() override { return CHIP_NO_ERROR; } - + bool IsFirstImageRun() override; + CHIP_ERROR ConfirmCurrentImage() override; + void TriggerNewRequestForData(); void SetOTADownloader(OTADownloader * downloader) { mDownloader = downloader; } void SetOTAImageFile(const char * imageFile) { mImageFile = imageFile; } private: //////////// Actual handlers for the OTAImageProcessorInterface /////////////// static void HandlePrepareDownload(intptr_t context); + CHIP_ERROR ProcessHeader(ByteSpan & block); static void HandleFinalize(intptr_t context); + static void HandleApply(intptr_t context); static void HandleAbort(intptr_t context); static void HandleProcessBlock(intptr_t context); + static void HandleBlockEraseComplete(uint32_t); /** * Called to allocate memory for mBlock if necessary and set it to block @@ -57,8 +61,10 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface CHIP_ERROR ReleaseBlock(); OTADownloader * mDownloader; + OTAImageHeaderParser mHeaderParser; MutableByteSpan mBlock; const char * mImageFile = nullptr; + uint32_t mSoftwareVersion; }; } // namespace chip diff --git a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp index 9b928dea89aa86..ef6c5c3556d1dd 100644 --- a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp +++ b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -35,12 +36,48 @@ #include #include "K32W061.h" +#include "MemManager.h" +#include "RNG_Interface.h" +#include "TimersManager.h" +#include "fsl_sha.h" +#include "k32w0-chip-mbedtls-config.h" namespace chip { namespace DeviceLayer { PlatformManagerImpl PlatformManagerImpl::sInstance; +CHIP_ERROR PlatformManagerImpl::InitBoardFwk(void) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + char initString[] = "app"; + char * argv[1] = { 0 }; + argv[0] = &initString[0]; + + SHA_ClkInit(SHA_INSTANCE); + + if (MEM_Init() != MEM_SUCCESS_c) + { + err = CHIP_ERROR_NO_MEMORY; + goto exit; + } + + if (RNG_Init() != gRngSuccess_d) + { + err = CHIP_ERROR_RANDOM_DATA_UNAVAILABLE; + goto exit; + } + RNG_SetPseudoRandomNoSeed(NULL); + + TMR_Init(); + + /* Used for OT initializations */ + otSysInit(1, argv); + +exit: + return err; +} + static int app_entropy_source(void * data, unsigned char * output, size_t len, size_t * olen) { otError otErr = otPlatEntropyGet(output, (uint16_t) len); @@ -56,13 +93,15 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { - CHIP_ERROR err; + uint32_t chipType; + CHIP_ERROR err = CHIP_NO_ERROR; // Initialize the configuration system. err = Internal::K32WConfig::Init(); SuccessOrExit(err); - if (Chip_GetType() != CHIP_K32W061) + chipType = Chip_GetType(); + if ((chipType != CHIP_K32W061) && (chipType != CHIP_K32W041) && (chipType != CHIP_K32W041A) && (chipType != CHIP_K32W041AM)) { err = CHIP_ERROR_INTERNAL; ChipLogError(DeviceLayer, "Invalid chip type, expected K32W061"); diff --git a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.h b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.h index c3fa03ac8fa3ce..b9452e0f5c92e8 100644 --- a/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.h +++ b/src/platform/nxp/k32w/k32w0/PlatformManagerImpl.h @@ -49,6 +49,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener // ===== Platform-specific members that may be accessed directly by the application. System::Clock::Timestamp GetStartTime() { return mStartTime; } + CHIP_ERROR InitBoardFwk(void); private: // ===== Methods that implement the PlatformManager abstract interface. diff --git a/src/platform/nxp/k32w/k32w0/args.gni b/src/platform/nxp/k32w/k32w0/args.gni index 5bfab05ecaff7e..d6ccbd8bb86e29 100644 --- a/src/platform/nxp/k32w/k32w0/args.gni +++ b/src/platform/nxp/k32w/k32w0/args.gni @@ -29,7 +29,7 @@ chip_build_tests = false chip_mdns = "platform" # Trying to fit into the available flash by disabling optional logging for now -chip_detail_logging = true +chip_detail_logging = false chip_progress_logging = true mbedtls_target = "${chip_root}/third_party/nxp/k32w0_sdk:mbedtls" diff --git a/third_party/nxp/k32w0_sdk/BUILD.gn b/third_party/nxp/k32w0_sdk/BUILD.gn index 2bad31f2060c9d..2019a2c2a55f36 100644 --- a/third_party/nxp/k32w0_sdk/BUILD.gn +++ b/third_party/nxp/k32w0_sdk/BUILD.gn @@ -42,7 +42,6 @@ config("mbedtls_k32w0_config") { "MBEDTLS_X509_CREATE_C", "MBEDTLS_PEM_WRITE_C", "MBEDTLS_HKDF_C", - "MBEDTLS_ERROR_C", "MBEDTLS_PKCS5_C", ] diff --git a/third_party/nxp/k32w0_sdk/k32w0_sdk.gni b/third_party/nxp/k32w0_sdk/k32w0_sdk.gni index c08806190eda51..4206ceded05c79 100644 --- a/third_party/nxp/k32w0_sdk/k32w0_sdk.gni +++ b/third_party/nxp/k32w0_sdk/k32w0_sdk.gni @@ -21,6 +21,7 @@ import("${chip_root}/src/platform/nxp/k32w/k32w0/args.gni") declare_args() { # Location of the k32w0 SDK. k32w0_sdk_root = getenv("NXP_K32W061_SDK_ROOT") + chip_with_DK6 = true chip_with_OM15082 = 0 chip_with_ot_cli = 0 chip_with_low_power = 0 @@ -38,7 +39,13 @@ template("k32w0_sdk") { k32w0_sdk_root = invoker.k32w0_sdk_root } + if (defined(invoker.override_is_DK6)) { + chip_with_DK6 = invoker.override_is_DK6 + } + assert(k32w0_sdk_root != "", "k32w0_sdk_root must be specified") + assert(chip_with_OM15082 == 0 || chip_with_DK6, + "OM15082 expansion board is only supported on DK6 board") assert( chip_with_low_power == 0 || (chip_with_low_power == 1 && chip_with_OM15082 == 0 && @@ -56,10 +63,21 @@ template("k32w0_sdk") { # We want to treat SDK headers as system headers, so that warnings in those # headers are not fatal. Therefore don't add them directly to include_dirs; # we will add them to cflags below instead. - _sdk_include_dirs = [ - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm", - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/enablement", - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common", + _sdk_include_dirs = [] + + if (chip_with_DK6) { + if (chip_with_low_power != 0) { + _sdk_include_dirs += [ "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/lped/bm" ] + } else { + _sdk_include_dirs += [ "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm" ] + } + } + + if (chip_with_low_power != 0) { + _sdk_include_dirs += [ "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common" ] + } + + _sdk_include_dirs += [ "${chip_root}/src/platform/nxp/k32w/k32w0", "${k32w0_sdk_root}/CMSIS/Include", "${k32w0_sdk_root}/components/serial_manager", @@ -130,7 +148,7 @@ template("k32w0_sdk") { "CPU_JN518X_REV=2", "JENNIC_CHIP_FAMILY_NAME=_JN518x", "gPWR_LDOMEM_0_9V_PD=0", - "SDK_DEBUGCONSOLE=1", + "SDK_DEBUGCONSOLE=DEBUGCONSOLE_REDIRECT_TO_SDK", "NO_SYSCORECLK_UPD=0", "USE_RTOS=1", "USE_SDK_OSA=0", @@ -140,26 +158,22 @@ template("k32w0_sdk") { "gUartDebugConsole_d=1", "DEBUG_SERIAL_INTERFACE_INSTANCE=0", "APP_SERIAL_INTERFACE_INSTANCE=1", - "gUsePdm_d=1", - "PDM_EXT_FLASH=1", - "gEepromType_d=gEepromDevice_MX25R8035F_c", "gOTA_externalFlash_d=1", "gEepromPostedOperations_d=1", "gOtaEepromPostedOperations_d=1", + "gOtaVerifyWrite_d=0", + "gExternalFlashIsCiphered_d=1", + "gBootData_None_c=1", "PROGRAM_PAGE_SZ=256", - "gKeyBoardSupported_d", - "gPdmNbSegments=63", "configFRTOS_MEMORY_SCHEME=4", "osCustomStartup=1", - "gLEDsOnTargetBoardCnt_c=2", - "gLED_InvertedMode_d=1", "ENABLE_RAM_VECTOR_TABLE=1", "gTMR_Enabled_d=1", "gTimestamp_Enabled_d=0", "K32W_LOG_ENABLED=1", "CHIP_ENABLE_OPENTHREAD=1", "gOtaMemPoolId_c=1", - "PoolsDetails_c=_block_size_ 32 _number_of_blocks_ 6 _pool_id_(0) _eol_ _block_size_ 256 _number_of_blocks_ 3 _pool_id_(0) _eol_ _block_size_ 512 _number_of_blocks_ 2 _pool_id_(0) _eol_ _block_size_ 768 _number_of_blocks_ 1 _pool_id_(0) _eol_ _block_size_ 268 _number_of_blocks_ 4 _pool_id_(gOtaMemPoolId_c) _eol_", + "PoolsDetails_c=_block_size_ 32 _number_of_blocks_ 6 _pool_id_(0) _eol_ _block_size_ 256 _number_of_blocks_ 3 _pool_id_(0) _eol_ _block_size_ 512 _number_of_blocks_ 2 _pool_id_(0) _eol_ _block_size_ 768 _number_of_blocks_ 1 _pool_id_(0) _eol_ _block_size_ 268 _number_of_blocks_ 8 _pool_id_(gOtaMemPoolId_c) _eol_", "SUPPORT_FOR_15_4=1", "gAppMaxConnections_c=1", "gAppUseBonding_d=0", @@ -192,13 +206,34 @@ template("k32w0_sdk") { ] } - if (chip_with_OM15082 == 1) { + if (chip_with_DK6) { defines += [ - "gKBD_KeysCount_c=4", - "OM15082=1", + "gUsePdm_d=1", + "PDM_EXT_FLASH=1", + "gEepromType_d=gEepromDevice_MX25R8035F_c", + "gPdmNbSegments=63", ] - } else { - defines += [ "gKBD_KeysCount_c=1" ] + + if (chip_with_OM15082 != 0) { + defines += [ + "OM15082=1", + "gKeyBoardSupported_d=1", + "gKBD_KeysCount_c=4", + ] + } else { + defines += [ + "gKeyBoardSupported_d=1", + "gKBD_KeysCount_c=1", + ] + } + + if (chip_with_low_power == 0) { + defines += [ + "gLEDSupported_d=1", + "gLEDsOnTargetBoardCnt_c=2", + "gLED_InvertedMode_d=1", + ] + } } if (chip_with_ot_cli == 1) { @@ -218,9 +253,6 @@ template("k32w0_sdk") { ] } else { defines += [ - "gLEDSupported_d", - "gLED_InvertedMode_d=1", - "gLEDsOnTargetBoardCnt_c=2", "cPWR_UsePowerDownMode=0", "cPWR_FullPowerDownMode=0", ] @@ -257,9 +289,6 @@ template("k32w0_sdk") { } sources += [ - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/board.c", - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/board_utility.c", - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/hardware_init.c", "${k32w0_sdk_root}/components/serial_manager/serial_manager.c", "${k32w0_sdk_root}/components/serial_manager/serial_port_uart.c", "${k32w0_sdk_root}/components/uart/usart_adapter.c", @@ -332,19 +361,37 @@ template("k32w0_sdk") { "${k32w0_sdk_root}/rtos/amazon-freertos/lib/FreeRTOS/timers.c", ] - if (chip_with_se05x == 1) { - sources += [ - "${chip_root}/third_party/simw-top-mini/repo/demos/ksdk/common/boards/DK6/wireless_examples/chip/clock_config.c", - "${chip_root}/third_party/simw-top-mini/repo/demos/ksdk/common/boards/DK6/wireless_examples/chip/pin_mux.c", - ] - } else { - sources += [ - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/enablement/clock_config.c", - "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/enablement/pin_mux.c", - ] + if (chip_with_DK6) { + if (chip_with_low_power != 0) { + sources += [ + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/lped/bm/board.c", + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/lped/bm/board_utility.c", + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/lped/bm/clock_config.c", + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/lped/bm/hardware_init.c", + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/lped/bm/pin_mux.c", + ] + } else { + sources += [ + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/board.c", + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/board_utility.c", + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/hardware_init.c", + ] + + if (chip_with_se05x != 0) { + sources += [ + "${chip_root}/third_party/simw-top-mini/repo/demos/ksdk/common/boards/DK6/wireless_examples/chip/clock_config.c", + "${chip_root}/third_party/simw-top-mini/repo/demos/ksdk/common/boards/DK6/wireless_examples/chip/pin_mux.c", + ] + } else { + sources += [ + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/clock_config.c", + "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/openthread/reed/bm/pin_mux.c", + ] + } + } } - if (chip_with_low_power == 1) { + if (chip_with_low_power != 0) { sources += [ "${k32w0_sdk_root}/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common/app_dual_mode_low_power.c" ] } diff --git a/third_party/nxp/k32w0_sdk/sdk_fixes/Eeprom_MX25R8035F_c.patch b/third_party/nxp/k32w0_sdk/sdk_fixes/Eeprom_MX25R8035F_c.patch new file mode 100644 index 00000000000000..c017836bfa83aa --- /dev/null +++ b/third_party/nxp/k32w0_sdk/sdk_fixes/Eeprom_MX25R8035F_c.patch @@ -0,0 +1,112 @@ +--- a/Eeprom_MX25R8035F.c ++++ b//Eeprom_MX25R8035F.c +@@ -146,7 +146,7 @@ static uint32_t EEPROM_ReadStatusReq(void); + static uint32_t EEPROM_ReadIDReq(void); + static uint32_t EEPROM_ReadResReq(void); + +- ++static uint8_t EEPROM_isBusyPrivate(void); + + #define MX25_SR_WIP_POS 0 /* Write In Progress */ + #define MX25_SR_WEL_POS 1 /* Write Enable Latch */ +@@ -316,7 +316,7 @@ ee_err_t EEPROM_Init(void) + { + initialized = 1; + } +- while (EEPROM_isBusy()); ++ while (EEPROM_isBusyPrivate()); + } + + return status; +@@ -366,7 +366,7 @@ ee_err_t EEPROM_ChipErase(void) + + /* Wait for idle state : check before operation in order to let previous + * operation terminate rather than blocking */ +- while (EEPROM_isBusy()); ++ while (EEPROM_isBusyPrivate()); + + /* Enable write */ + EEPROM_WriteEnable(); +@@ -410,7 +410,7 @@ ee_err_t EEPROM_EraseBlock(uint32_t Addr, uint32_t block_size) + + OSA_SemaphoreWait(mExtEepromSemaphoreId, osaWaitForever_c); + +- while (EEPROM_isBusy()); ++ while (EEPROM_isBusyPrivate()); + + EEPROM_WriteEnable(); + +@@ -485,7 +485,7 @@ ee_err_t EEPROM_EraseArea(uint32_t *Addr, int32_t *size, bool non_blocking) + { + OSA_SemaphoreWait(mExtEepromSemaphoreId, osaWaitForever_c); + +- if (non_blocking && EEPROM_isBusy()) ++ if (non_blocking && EEPROM_isBusyPrivate()) + { + status = ee_busy; + OSA_SemaphorePost(mExtEepromSemaphoreId); +@@ -679,7 +679,7 @@ void EEPROM_SetRead(void) + + OSA_SemaphoreWait(mExtEepromSemaphoreId, osaWaitForever_c); + +- while (EEPROM_isBusy()); ++ while (EEPROM_isBusyPrivate()); + + /* Set start address */ + SPIFI_SetCommandAddress(SPIFI, FSL_FEATURE_SPIFI_START_ADDR ); +@@ -714,7 +714,7 @@ ee_err_t EEPROM_ReadData(uint16_t NoOfBytes, uint32_t Addr, uint8_t *inbuf) + + OSA_SemaphoreWait(mExtEepromSemaphoreId, osaWaitForever_c); + +- while (EEPROM_isBusy()); ++ while (EEPROM_isBusyPrivate()); + + /* Set start address */ + SPIFI_SetCommandAddress(SPIFI, FSL_FEATURE_SPIFI_START_ADDR + Addr); +@@ -750,7 +750,12 @@ ee_err_t EEPROM_ReadData(uint16_t NoOfBytes, uint32_t Addr, uint8_t *inbuf) + ********************************************************************************** */ + uint8_t EEPROM_isBusy(void) + { +- return (EEPROM_ReadStatusReq() & EEPROM_BUSY_FLAG_MASK) == EEPROM_BUSY_FLAG_MASK; ++ uint8_t res = 0; ++ ++ OSA_SemaphoreWait(mExtEepromSemaphoreId, osaWaitForever_c); ++ res = EEPROM_isBusyPrivate(); ++ OSA_SemaphorePost(mExtEepromSemaphoreId); ++ return res; + } + + /*! ********************************************************************************* +@@ -759,6 +764,11 @@ uint8_t EEPROM_isBusy(void) + ************************************************************************************* + ********************************************************************************** */ + ++static uint8_t EEPROM_isBusyPrivate(void) ++{ ++ return (EEPROM_ReadStatusReq() & EEPROM_BUSY_FLAG_MASK) == EEPROM_BUSY_FLAG_MASK; ++} ++ + /*! ********************************************************************************* + * \brief Read the memory controller status register + * +@@ -882,6 +892,7 @@ void EepromWritePage(uint32_t NoOfBytes, uint32_t Addr, uint8_t *Outbuf) + #endif /* gFlashBlockBitmap_d */ + + OSA_SemaphoreWait(mExtEepromSemaphoreId, osaWaitForever_c); ++ while (EEPROM_isBusyPrivate()); + + EEPROM_WriteEnable(); + SPIFI_SetCommandAddress(SPIFI, Addr + FSL_FEATURE_SPIFI_START_ADDR); +@@ -917,12 +928,6 @@ static ee_err_t EEPROM_WritePage(uint32_t NoOfBytes, uint32_t Addr, uint8_t *Out + + if (NoOfBytes > 0) + { +- OSA_SemaphoreWait(mExtEepromSemaphoreId, osaWaitForever_c); +- +- while (EEPROM_isBusy()); +- +- OSA_SemaphorePost(mExtEepromSemaphoreId); +- + EepromWritePage(NoOfBytes, Addr, Outbuf); + } + diff --git a/third_party/nxp/k32w0_sdk/sdk_fixes/MemManager_h.patch b/third_party/nxp/k32w0_sdk/sdk_fixes/MemManager_h.patch new file mode 100644 index 00000000000000..49ed7e803738cd --- /dev/null +++ b/third_party/nxp/k32w0_sdk/sdk_fixes/MemManager_h.patch @@ -0,0 +1,22 @@ +--- a/MemManager.h ++++ b/MemManager.h +@@ -24,6 +24,9 @@ + #include "EmbeddedTypes.h" + #include "GenericList.h" + ++#ifdef __cplusplus ++extern "C" { ++#endif + + /*! ********************************************************************************* + ************************************************************************************* +@@ -220,4 +223,8 @@ extern __attribute__((weak)) uint32_t MEM_GetTimeStamp(void); + + #endif /*MEM_TRACKING*/ + ++#ifdef __cplusplus ++} ++#endif ++ + #endif /* _MEM_MANAGER_H_ */ + diff --git a/third_party/nxp/k32w0_sdk/sdk_fixes/OtaSupport_c.patch b/third_party/nxp/k32w0_sdk/sdk_fixes/OtaSupport_c.patch new file mode 100644 index 00000000000000..0ff1c9ec118651 --- /dev/null +++ b/third_party/nxp/k32w0_sdk/sdk_fixes/OtaSupport_c.patch @@ -0,0 +1,144 @@ +--- a/OtaSupport.c ++++ b/OtaSupport.c +@@ -116,10 +116,9 @@ typedef bool (*efuse_AESKeyPresent_t)(void); + typedef int (*efuse_LoadUniqueKey_t)(void); + typedef uint32_t (*aesLoadKeyFromOTP_t)(AES_KEY_SIZE_T keySize); + +-const static efuse_LoadUniqueKey_t efuse_LoadUniqueKey = (efuse_LoadUniqueKey_t)ROM_API_efuse_LoadUniqueKey; +-const static aesLoadKeyFromOTP_t aesLoadKeyFromOTP = (aesLoadKeyFromOTP_t)ROM_API_aesLoadKeyFromOTP; +-const static efuse_AESKeyPresent_t efuse_AESKeyPresent = (efuse_AESKeyPresent_t)ROM_API_efuse_AESKeyPresent; +- ++static const efuse_LoadUniqueKey_t efuse_LoadUniqueKey = (efuse_LoadUniqueKey_t)ROM_API_efuse_LoadUniqueKey; ++static const aesLoadKeyFromOTP_t aesLoadKeyFromOTP = (aesLoadKeyFromOTP_t)ROM_API_aesLoadKeyFromOTP; ++static const efuse_AESKeyPresent_t efuse_AESKeyPresent = (efuse_AESKeyPresent_t)ROM_API_efuse_AESKeyPresent; + + #if gUsePasswordCiphering_d + const static uint32_t (*aesLoadKeyFromSW)(AES_KEY_SIZE_T keySize, +@@ -187,6 +186,7 @@ typedef struct { + int max_cnt_idle; + int q_sz; + int q_max; ++ osaMutexId_t msgQueueMutex; + #endif + eEncryptionKeyType ciphered_mode; + #if gExternalFlashIsCiphered_d +@@ -207,6 +207,7 @@ typedef struct { + #if ( gEepromParams_bufferedWrite_c == 1) + bool_t gOtaInvalidateHeader; + #endif ++ bool_t isInitialized; + } OtaFlashTaskContext_t; + + /****************************************************************************** +@@ -287,6 +288,7 @@ static OtaFlashTaskContext_t mHandle = { + #if ( gEepromParams_bufferedWrite_c == 1) + .gOtaInvalidateHeader = FALSE, + #endif ++ .isInitialized = FALSE, + }; + + +@@ -460,6 +462,11 @@ otaResult_t OTA_StartImageWithMaxSize(uint32_t length, uint32_t maxAllowedArchSi + int OTA_TransactionResume(void) + { + int nb_treated = 0; ++ ++ if (mHandle.isInitialized) ++ { ++ OSA_MutexLock(mHandle.msgQueueMutex, osaWaitForever_c); ++ + while ( OTA_IsTransactionPending() /* There are queued flash operations pending in queue */ + && (nb_treated < MAX_CONSECUTIVE_TRANSACTIONS)) /* ... but do not schedule too many in a same pass */ + { +@@ -553,6 +560,9 @@ int OTA_TransactionResume(void) + /* There were transactions pending but we consumed some */ + mHandle.cnt_idle_op = 0; + ++ OSA_MutexUnlock(mHandle.msgQueueMutex); ++ } ++ + return nb_treated; + } + /***************************************************************************** +@@ -578,7 +588,11 @@ void OTA_WritePendingData(void) + + while (EEPROM_isBusy()); + /* Always take head of queue : we just queued something so we know it is not empty */ +- OTA_TransactionResume(); ++ while (OTA_IsTransactionPending()) ++ { ++ OTA_TransactionResume(); ++ } ++ + while (EEPROM_isBusy()); + + } while (0); +@@ -877,7 +891,14 @@ otaResult_t OTA_PushImageChunk(uint8_t* pData, uint16_t length, uint32_t* pImage + OTA_MsgQueue(pMsg); + + OTA_DBG_LOG("Submitted page Addr=%x", pMsg->flash_addr); +- mHandle.cur_transaction = NULL; ++ if (mHandle.cur_transaction != NULL) ++ { ++ mHandle.cur_transaction = NULL; ++ } ++ else ++ { ++ Addr += PROGRAM_PAGE_SZ; ++ } + } + else + { +@@ -1229,6 +1250,9 @@ otaResult_t OTA_ClientInit(void) + OTA_DEBUG_TRACE("%s\r\n", __FUNCTION__); + otaResult_t res = gOtaSuccess_c; + ++ if (!mHandle.isInitialized) ++ { ++ + mHandle.LoadOtaImageInEepromInProgress = FALSE; + mHandle.OtaImageTotalLength = 0; + mHandle.OtaImageCurrentLength = 0; +@@ -1255,6 +1279,7 @@ otaResult_t OTA_ClientInit(void) + + #if gOtaEepromPostedOperations_d + MSG_InitQueue(&mHandle.op_queue); ++ mHandle.msgQueueMutex = OSA_MutexCreate(); + #endif + #if gExternalFlashIsCiphered_d + mHandle.ciphered_mode = (efuse_AESKeyPresent()) ? eEfuseKey : eSoftwareKey; +@@ -1262,6 +1287,9 @@ otaResult_t OTA_ClientInit(void) + mHandle.ciphered_mode = eCipherKeyNone; + #endif + res = OTA_InitExternalMemory(); ++ ++ mHandle.isInitialized = TRUE; ++ } + return res; + } + +@@ -1645,7 +1673,7 @@ static uint32_t OTA_GetMaxAllowedArchSize(void) + return gFlashMaxStatedSize*2 - current_app_stated_size; + #else + /* Read the value from the psector img directory */ +- uint32_t allowedSize = 0; ++ uint32_t maxImgPages = 0; + uint8_t i; + psector_page_data_t * mPage0Hdl = psector_GetPage0Handle(); + if (mPage0Hdl != NULL) +@@ -1653,12 +1681,12 @@ static uint32_t OTA_GetMaxAllowedArchSize(void) + image_directory_entry_t * currentEntry = mPage0Hdl->page0_v3.img_directory; + for (i=0; iimg_nb_pages > allowedSize) +- allowedSize = currentEntry->img_nb_pages*512; ++ if (currentEntry->img_nb_pages > maxImgPages) ++ maxImgPages = currentEntry->img_nb_pages; + currentEntry++; + } + } +- return allowedSize; ++ return maxImgPages*512; /* 512 corresponding to the size of one page in the internal flash */ + #endif + + } 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 4737db6534e45e..49a18592d4a5a2 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 @@ -7,29 +7,43 @@ fi convert_to_dos() { - [[ $(file -b - <$1) != *"CRLF"* ]] && unix2dos "$1" + [[ $(file -b - <$1) != *"CRLF"* ]] && sed -i 's/$/\r/' "$1" } SOURCE=${BASH_SOURCE[0]} SOURCE_DIR=$(cd "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd) convert_to_dos "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/openthread/reed/bm/gpio_pins.h -patch --binary -d "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/openthread/reed/bm -p1 <"$SOURCE_DIR/gpio_pins_h.patch" +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/openthread/reed/bm -p1 <"$SOURCE_DIR/gpio_pins_h.patch" convert_to_dos "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common/app_dual_mode_low_power.h -patch --binary -d "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common -p1 <"$SOURCE_DIR/app_dual_mode_low_power_h.patch" +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common -p1 <"$SOURCE_DIR/app_dual_mode_low_power_h.patch" convert_to_dos "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common/app_dual_mode_switch.h -patch --binary -d "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common -p1 <"$SOURCE_DIR/app_dual_mode_switch_h.patch" +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/boards/k32w061dk6/wireless_examples/hybrid/ble_ot/lped_ble_wuart/ble_802_15_4_common -p1 <"$SOURCE_DIR/app_dual_mode_switch_h.patch" convert_to_dos "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/SecLib/SecLib.h -patch --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/SecLib -p1 <"$SOURCE_DIR/SecLib_h.patch" +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/SecLib -p1 <"$SOURCE_DIR/SecLib_h.patch" convert_to_dos "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/OtaSupport/Source/OtaUtils.c -patch --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/OtaSupport/Source -p1 <"$SOURCE_DIR/OtaUtils_c.patch" +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/OtaSupport/Source -p1 <"$SOURCE_DIR/OtaUtils_c.patch" + +convert_to_dos "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/OtaSupport/Source/OtaSupport.c +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/OtaSupport/Source -p1 <"$SOURCE_DIR/OtaSupport_c.patch" convert_to_dos "$NXP_K32W061_SDK_ROOT"/middleware/wireless/bluetooth/host/interface/ble_utils.h -patch --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/bluetooth/host/interface -p1 <"$SOURCE_DIR/ble_utils_h.patch" +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/bluetooth/host/interface -p1 <"$SOURCE_DIR/ble_utils_h.patch" + +convert_to_dos "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/Flash/External/Source/Eeprom_MX25R8035F.c +patch -N --binary -d "$NXP_K32W061_SDK_ROOT"/middleware/wireless/framework/Flash/External/Source -p1 <"$SOURCE_DIR/Eeprom_MX25R8035F_c.patch" + +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" + +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" +sed -i 's/\r$//' "$SIGN_FILE_PATH" echo "K32W SDK MR3 QP1 was patched!" exit 0 diff --git a/third_party/nxp/k32w0_sdk/sdk_fixes/sign_images_sh.patch b/third_party/nxp/k32w0_sdk/sdk_fixes/sign_images_sh.patch new file mode 100644 index 00000000000000..43ebc1ed8023b1 --- /dev/null +++ b/third_party/nxp/k32w0_sdk/sdk_fixes/sign_images_sh.patch @@ -0,0 +1,18 @@ +--- a/sign_images.sh ++++ b/sign_images.sh +@@ -56,7 +56,14 @@ if [ "$#" -gt 0 ]; then + MIME_SET="$(file -ib $FILENAME)" + + if [[ $MIME_SET == *"$MIME_PATTERN"* ]]; then +- python3 $SIGNING_TOOL $FILENAME ++ OTA_ENABLED=0 ++ APP_START=`arm-none-eabi-nm $FILENAME | grep -i m_app_start | cut -d " " -f 1` ++ ++ if [ "$APP_START" -gt 0 ]; then ++ OTA_ENABLED=1 ++ fi ++ ++ python3 $SIGNING_TOOL -i="$OTA_ENABLED" $FILENAME + arm-none-eabi-objcopy -O binary $FILENAME $FILENAME.bin + fi + done