From f62e79dd1684c23cb63fe2e55115b41fdd7915bf Mon Sep 17 00:00:00 2001 From: jepenven-silabs Date: Thu, 27 Jan 2022 13:25:15 -0500 Subject: [PATCH 1/4] Implement OTA to all EFR32 examples --- examples/lighting-app/efr32/BUILD.gn | 6 ++ examples/lighting-app/efr32/args.gni | 4 ++ examples/lighting-app/efr32/src/main.cpp | 7 ++ examples/lock-app/efr32/BUILD.gn | 7 ++ examples/lock-app/efr32/args.gni | 4 ++ examples/lock-app/efr32/src/main.cpp | 8 ++- examples/platform/efr32/OTAConfig.cpp | 89 ++++++++++++++++++++++++ examples/platform/efr32/OTAConfig.h | 33 +++++++++ examples/window-app/efr32/BUILD.gn | 5 ++ examples/window-app/efr32/args.gni | 4 ++ examples/window-app/efr32/src/main.cpp | 8 ++- 11 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 examples/platform/efr32/OTAConfig.cpp create mode 100644 examples/platform/efr32/OTAConfig.h diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 2732127491fa16..0f52becb1c5a3d 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -175,6 +175,12 @@ efr32_executable("lighting_app") { ] } } + + if (chip_enable_ota_requestor) { + defines += ["EFR32_OTA_ENABLED"] + sources += ["${examples_plat_dir}/OTAConfig.cpp"] + } + if (use_rs911x) { sources += rs911x_src_plat diff --git a/examples/lighting-app/efr32/args.gni b/examples/lighting-app/efr32/args.gni index 42061052611489..076cf81f31943a 100644 --- a/examples/lighting-app/efr32/args.gni +++ b/examples/lighting-app/efr32/args.gni @@ -18,6 +18,10 @@ import("${chip_root}/src/platform/EFR32/args.gni") efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") +declare_args() { + chip_enable_ota_requestor = true +} + pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" chip_enable_openthread = true diff --git a/examples/lighting-app/efr32/src/main.cpp b/examples/lighting-app/efr32/src/main.cpp index 44d958f2588377..259a4b29bb9591 100644 --- a/examples/lighting-app/efr32/src/main.cpp +++ b/examples/lighting-app/efr32/src/main.cpp @@ -40,6 +40,10 @@ #include "sl_system_kernel.h" #include +#ifdef EFR32_OTA_ENABLED +#include "OTAConfig.h" +#endif // EFR32_OTA_ENABLED + #ifdef HEAP_MONITORING #include "MemMonitoring.h" #endif @@ -198,6 +202,9 @@ int main(void) * starting up a rsi task - which will initialize the SPI interface. */ #endif +#ifdef EFR32_OTA_ENABLED + OTAConfig::Init(); +#endif // EFR32_OTA_ENABLED EFR32_LOG("Starting App Task"); ret = GetAppTask().StartAppTask(); diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 79abd39e092270..463cc33928148c 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -177,6 +177,13 @@ efr32_executable("lock_app") { ] } } + + if (chip_enable_ota_requestor) { + defines += ["EFR32_OTA_ENABLED"] + sources += ["${examples_plat_dir}/OTAConfig.cpp"] + } + + if (use_rs911x) { sources += rs911x_src_plat diff --git a/examples/lock-app/efr32/args.gni b/examples/lock-app/efr32/args.gni index 5e298bdae486b6..a32b60b7164b44 100644 --- a/examples/lock-app/efr32/args.gni +++ b/examples/lock-app/efr32/args.gni @@ -18,6 +18,10 @@ import("${chip_root}/src/platform/EFR32/args.gni") efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") +declare_args() { + chip_enable_ota_requestor = true +} + chip_enable_openthread = true pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" diff --git a/examples/lock-app/efr32/src/main.cpp b/examples/lock-app/efr32/src/main.cpp index bbee37bd7c7a9e..487cff62f3aba0 100644 --- a/examples/lock-app/efr32/src/main.cpp +++ b/examples/lock-app/efr32/src/main.cpp @@ -56,6 +56,10 @@ #include "matter_shell.h" #endif +#ifdef EFR32_OTA_ENABLED +#include "OTAConfig.h" +#endif // EFR32_OTA_ENABLED + #include #if CHIP_ENABLE_OPENTHREAD #include @@ -187,7 +191,9 @@ int main(void) wfx_securelink_task_start(); // start securelink key renegotiation task #endif // SL_WFX_USE_SECURE_LINK #endif /* WF200_WIFI */ - +#ifdef EFR32_OTA_ENABLED + OTAConfig::Init(); +#endif // EFR32_OTA_ENABLED EFR32_LOG("Starting App Task"); ret = GetAppTask().StartAppTask(); if (ret != CHIP_NO_ERROR) diff --git a/examples/platform/efr32/OTAConfig.cpp b/examples/platform/efr32/OTAConfig.cpp new file mode 100644 index 00000000000000..b84866d9ab4f4f --- /dev/null +++ b/examples/platform/efr32/OTAConfig.cpp @@ -0,0 +1,89 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "OTAConfig.h" + +#include "platform/bootloader/api/application_properties.h" +#include + +// Header used for building the image GBL file +#define APP_PROPERTIES_VERSION 1 +#define APP_PROPERTIES_ID \ + { \ + 0 \ + } + +__attribute__((used)) ApplicationProperties_t sl_app_properties = { + /// @brief Magic value indicating that this is an ApplicationProperties_t + /// Must equal @ref APPLICATION_PROPERTIES_MAGIC + .magic = APPLICATION_PROPERTIES_MAGIC, + + /// Version number of this struct + .structVersion = APPLICATION_PROPERTIES_VERSION, + + /// Type of signature this application is signed with + .signatureType = APPLICATION_SIGNATURE_NONE, + + /// Location of the signature. Typically a pointer to the end of application + .signatureLocation = 0, + + /// Information about the application + .app = { + + /// Bitfield representing type of application + /// e.g. @ref APPLICATION_TYPE_BLUETOOTH_APP + .type = APPLICATION_TYPE_THREAD, + + /// Version number for this application + .version = APP_PROPERTIES_VERSION, + + /// Capabilities of this application + .capabilities = 0, + + /// Unique ID (e.g. UUID/GUID) for the product this application is built for + .productId = APP_PROPERTIES_ID, + }, +}; + + +// Global OTA objects +chip::OTARequestor gRequestorCore; +chip::DeviceLayer::GenericOTARequestorDriver gRequestorUser; +chip::BDXDownloader gDownloader; +chip::OTAImageProcessorImpl gImageProcessor; + + +void OTAConfig::Init() +{ + // Initialize and interconnect the Requestor and Image Processor objects -- START + SetRequestorInstance(&gRequestorCore); + + gRequestorCore.Init(&(chip::Server::GetInstance()), &gRequestorUser, &gDownloader); + + gRequestorUser.Init(&gRequestorCore, &gImageProcessor); + + chip::OTAImageProcessorParams ipParams; + ipParams.imageFile = chip::CharSpan("test.txt"); + gImageProcessor.SetOTAImageProcessorParams(ipParams); + gImageProcessor.SetOTADownloader(&gDownloader); + + // Connect the Downloader and Image Processor objects + gDownloader.SetImageProcessorDelegate(&gImageProcessor); + // Initialize and interconnect the Requestor and Image Processor objects -- END +} \ No newline at end of file diff --git a/examples/platform/efr32/OTAConfig.h b/examples/platform/efr32/OTAConfig.h new file mode 100644 index 00000000000000..42673d960bfed0 --- /dev/null +++ b/examples/platform/efr32/OTAConfig.h @@ -0,0 +1,33 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "app/clusters/ota-requestor/BDXDownloader.h" +#include "app/clusters/ota-requestor/OTARequestor.h" +#include "platform/EFR32/OTAImageProcessorImpl.h" +#include "platform/GenericOTARequestorDriver.h" + +class OTAConfig +{ +public: + OTAConfig(){}; + + static void Init(); + +}; \ No newline at end of file diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index 50cba8f89afd9b..dab0f9ef08be49 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -139,6 +139,11 @@ efr32_executable("window_app") { "src/main.cpp", ] + if (chip_enable_ota_requestor) { + defines += ["EFR32_OTA_ENABLED"] + sources += ["${examples_plat_dir}/OTAConfig.cpp"] + } + if (use_rs911x) { sources += rs911x_src_plat diff --git a/examples/window-app/efr32/args.gni b/examples/window-app/efr32/args.gni index 3061e39359d252..1a0052682125a4 100644 --- a/examples/window-app/efr32/args.gni +++ b/examples/window-app/efr32/args.gni @@ -18,6 +18,10 @@ import("${chip_root}/src/platform/EFR32/args.gni") efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") +declare_args() { + chip_enable_ota_requestor = true +} + pw_log_BACKEND = "${chip_root}/src/lib/support/pw_log_chip" pw_assert_BACKEND = "$dir_pw_assert_log" chip_enable_openthread = true diff --git a/examples/window-app/efr32/src/main.cpp b/examples/window-app/efr32/src/main.cpp index de64dab6cec4b7..e760732cd4b4be 100644 --- a/examples/window-app/efr32/src/main.cpp +++ b/examples/window-app/efr32/src/main.cpp @@ -54,6 +54,10 @@ #include "matter_shell.h" #endif +#ifdef EFR32_OTA_ENABLED +#include "OTAConfig.h" +#endif // EFR32_OTA_ENABLED + #define BLE_DEV_NAME "EFR32_WINDOW" using namespace ::chip::DeviceLayer; @@ -167,7 +171,9 @@ int main(void) #ifdef ENABLE_CHIP_SHELL chip::startShellTask(); #endif - +#ifdef EFR32_OTA_ENABLED + OTAConfig::Init(); +#endif // EFR32_OTA_ENABLED WindowApp & app = WindowApp::Instance(); EFR32_LOG("Starting App"); From 984a544a442c79a0c6c51445599512cede4f961f Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 9 Feb 2022 01:57:04 +0000 Subject: [PATCH 2/4] Restyled by whitespace --- examples/platform/efr32/OTAConfig.cpp | 2 +- examples/platform/efr32/OTAConfig.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/platform/efr32/OTAConfig.cpp b/examples/platform/efr32/OTAConfig.cpp index b84866d9ab4f4f..ef1d72acabf224 100644 --- a/examples/platform/efr32/OTAConfig.cpp +++ b/examples/platform/efr32/OTAConfig.cpp @@ -86,4 +86,4 @@ void OTAConfig::Init() // Connect the Downloader and Image Processor objects gDownloader.SetImageProcessorDelegate(&gImageProcessor); // Initialize and interconnect the Requestor and Image Processor objects -- END -} \ No newline at end of file +} diff --git a/examples/platform/efr32/OTAConfig.h b/examples/platform/efr32/OTAConfig.h index 42673d960bfed0..73927ccd02f8e6 100644 --- a/examples/platform/efr32/OTAConfig.h +++ b/examples/platform/efr32/OTAConfig.h @@ -30,4 +30,4 @@ class OTAConfig static void Init(); -}; \ No newline at end of file +}; From c1f4158e4601fa9e376ffc92085ca70ff4b3e46d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 9 Feb 2022 01:57:05 +0000 Subject: [PATCH 3/4] Restyled by clang-format --- examples/platform/efr32/OTAConfig.cpp | 3 --- examples/platform/efr32/OTAConfig.h | 1 - 2 files changed, 4 deletions(-) diff --git a/examples/platform/efr32/OTAConfig.cpp b/examples/platform/efr32/OTAConfig.cpp index ef1d72acabf224..6584cde832ea39 100644 --- a/examples/platform/efr32/OTAConfig.cpp +++ b/examples/platform/efr32/OTAConfig.cpp @@ -16,7 +16,6 @@ * limitations under the License. */ - #include "OTAConfig.h" #include "platform/bootloader/api/application_properties.h" @@ -61,14 +60,12 @@ __attribute__((used)) ApplicationProperties_t sl_app_properties = { }, }; - // Global OTA objects chip::OTARequestor gRequestorCore; chip::DeviceLayer::GenericOTARequestorDriver gRequestorUser; chip::BDXDownloader gDownloader; chip::OTAImageProcessorImpl gImageProcessor; - void OTAConfig::Init() { // Initialize and interconnect the Requestor and Image Processor objects -- START diff --git a/examples/platform/efr32/OTAConfig.h b/examples/platform/efr32/OTAConfig.h index 73927ccd02f8e6..41dd739b100eca 100644 --- a/examples/platform/efr32/OTAConfig.h +++ b/examples/platform/efr32/OTAConfig.h @@ -29,5 +29,4 @@ class OTAConfig OTAConfig(){}; static void Init(); - }; From e30ef4ad8f4cf3df0fa36b6c1511ad15d0257a28 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 9 Feb 2022 01:57:06 +0000 Subject: [PATCH 4/4] Restyled by gn --- examples/lighting-app/efr32/BUILD.gn | 4 ++-- examples/lock-app/efr32/BUILD.gn | 5 ++--- examples/window-app/efr32/BUILD.gn | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 0f52becb1c5a3d..9494a726f1fe86 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -177,8 +177,8 @@ efr32_executable("lighting_app") { } if (chip_enable_ota_requestor) { - defines += ["EFR32_OTA_ENABLED"] - sources += ["${examples_plat_dir}/OTAConfig.cpp"] + defines += [ "EFR32_OTA_ENABLED" ] + sources += [ "${examples_plat_dir}/OTAConfig.cpp" ] } if (use_rs911x) { diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index 463cc33928148c..0dfd33639c1d67 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -179,11 +179,10 @@ efr32_executable("lock_app") { } if (chip_enable_ota_requestor) { - defines += ["EFR32_OTA_ENABLED"] - sources += ["${examples_plat_dir}/OTAConfig.cpp"] + defines += [ "EFR32_OTA_ENABLED" ] + sources += [ "${examples_plat_dir}/OTAConfig.cpp" ] } - if (use_rs911x) { sources += rs911x_src_plat diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index dab0f9ef08be49..9cbc1157611a95 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -140,8 +140,8 @@ efr32_executable("window_app") { ] if (chip_enable_ota_requestor) { - defines += ["EFR32_OTA_ENABLED"] - sources += ["${examples_plat_dir}/OTAConfig.cpp"] + defines += [ "EFR32_OTA_ENABLED" ] + sources += [ "${examples_plat_dir}/OTAConfig.cpp" ] } if (use_rs911x) {