diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index 2732127491fa16..9494a726f1fe86 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..0dfd33639c1d67 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -177,6 +177,12 @@ 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..6584cde832ea39 --- /dev/null +++ b/examples/platform/efr32/OTAConfig.cpp @@ -0,0 +1,86 @@ +/* + * + * 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 +} diff --git a/examples/platform/efr32/OTAConfig.h b/examples/platform/efr32/OTAConfig.h new file mode 100644 index 00000000000000..41dd739b100eca --- /dev/null +++ b/examples/platform/efr32/OTAConfig.h @@ -0,0 +1,32 @@ +/* + * + * 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(); +}; diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index 50cba8f89afd9b..9cbc1157611a95 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..8db1cfbfb54ef0 100644 --- a/examples/window-app/efr32/args.gni +++ b/examples/window-app/efr32/args.gni @@ -18,6 +18,11 @@ import("${chip_root}/src/platform/EFR32/args.gni") efr32_sdk_target = get_label_info(":sdk", "label_no_toolchain") +declare_args() { + # TODO fix me + chip_enable_ota_requestor = false +} + 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");