From 2708552405ea691d7bddebf49256cfe4c7d08a1b Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Tue, 18 Apr 2023 11:39:37 -0400 Subject: [PATCH] Unify OTA for silabs platform (#26131) --- .../silabs/{SiWx917 => }/OTAConfig.cpp | 0 .../platform/silabs/{SiWx917 => }/OTAConfig.h | 2 +- examples/platform/silabs/SiWx917/BUILD.gn | 2 +- .../platform/silabs/SiWx917/matter_config.cpp | 2 +- examples/platform/silabs/efr32/BUILD.gn | 4 +- examples/platform/silabs/efr32/OTAConfig.cpp | 94 ------------------- examples/platform/silabs/efr32/OTAConfig.h | 34 ------- .../platform/silabs/efr32/matter_config.cpp | 4 +- .../{SiWx917 => }/OTAImageProcessorImpl.h | 0 src/platform/silabs/SiWx917/BUILD.gn | 2 +- .../silabs/SiWx917/OTAImageProcessorImpl.cpp | 2 +- src/platform/silabs/efr32/BUILD.gn | 2 +- .../silabs/efr32/OTAImageProcessorImpl.cpp | 2 +- .../silabs/efr32/OTAImageProcessorImpl.h | 80 ---------------- 14 files changed, 11 insertions(+), 219 deletions(-) rename examples/platform/silabs/{SiWx917 => }/OTAConfig.cpp (100%) rename examples/platform/silabs/{SiWx917 => }/OTAConfig.h (94%) delete mode 100644 examples/platform/silabs/efr32/OTAConfig.cpp delete mode 100644 examples/platform/silabs/efr32/OTAConfig.h rename src/platform/silabs/{SiWx917 => }/OTAImageProcessorImpl.h (100%) delete mode 100644 src/platform/silabs/efr32/OTAImageProcessorImpl.h diff --git a/examples/platform/silabs/SiWx917/OTAConfig.cpp b/examples/platform/silabs/OTAConfig.cpp similarity index 100% rename from examples/platform/silabs/SiWx917/OTAConfig.cpp rename to examples/platform/silabs/OTAConfig.cpp diff --git a/examples/platform/silabs/SiWx917/OTAConfig.h b/examples/platform/silabs/OTAConfig.h similarity index 94% rename from examples/platform/silabs/SiWx917/OTAConfig.h rename to examples/platform/silabs/OTAConfig.h index cdd2163a10084e..2d5dbcf3635223 100644 --- a/examples/platform/silabs/SiWx917/OTAConfig.h +++ b/examples/platform/silabs/OTAConfig.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include class OTAConfig { diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index ae115f49b9fb98..098829c4cde527 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -176,7 +176,7 @@ config("siwx917-common-config") { } if (chip_enable_ota_requestor) { - defines += [ "EFR32_OTA_ENABLED" ] + defines += [ "SILABS_OTA_ENABLED" ] } if (enable_heap_monitoring) { diff --git a/examples/platform/silabs/SiWx917/matter_config.cpp b/examples/platform/silabs/SiWx917/matter_config.cpp index c41e008dea7ae5..9d6344132ce8f1 100644 --- a/examples/platform/silabs/SiWx917/matter_config.cpp +++ b/examples/platform/silabs/SiWx917/matter_config.cpp @@ -56,7 +56,7 @@ using namespace ::chip::DeviceLayer; #include "SilabsDeviceDataProvider.h" -#if EFR32_OTA_ENABLED +#if SILABS_OTA_ENABLED void SilabsMatterConfig::InitOTARequestorHandler(System::Layer * systemLayer, void * appState) { #if 0 // TODO : OTA is not planned now for CCP diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 3c2059a3f77c5e..fd33406f6911b1 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -221,7 +221,7 @@ config("efr32-common-config") { } if (chip_enable_ota_requestor) { - defines += [ "EFR32_OTA_ENABLED" ] + defines += [ "SILABS_OTA_ENABLED" ] } if (enable_heap_monitoring) { @@ -302,7 +302,7 @@ source_set("efr32-common") { } if (chip_enable_ota_requestor) { - sources += [ "OTAConfig.cpp" ] + sources += [ "${silabs_common_plat_dir}/OTAConfig.cpp" ] } if (!disable_lcd) { diff --git a/examples/platform/silabs/efr32/OTAConfig.cpp b/examples/platform/silabs/efr32/OTAConfig.cpp deleted file mode 100644 index 91c84054220b9c..00000000000000 --- a/examples/platform/silabs/efr32/OTAConfig.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * 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 "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, - }, - - /// Pointer to information about the certificate - .cert = NULL, - - /// Pointer to Long Token Data Section - .longTokenSectionAddress = NULL, -}; - -// Global OTA objects -chip::DefaultOTARequestor gRequestorCore; -chip::DefaultOTARequestorStorage gRequestorStorage; -chip::DeviceLayer::DefaultOTARequestorDriver gRequestorUser; -chip::BDXDownloader gDownloader; -chip::OTAImageProcessorImpl gImageProcessor; - -void OTAConfig::Init() -{ - // 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); - - // Periodic query timeout must be set prior to requestor being initialized - gRequestorUser.SetPeriodicQueryTimeout(OTA_PERIODIC_TIMEOUT); - gRequestorUser.Init(&gRequestorCore, &gImageProcessor); - - gImageProcessor.SetOTAImageFile("test.txt"); - 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/silabs/efr32/OTAConfig.h b/examples/platform/silabs/efr32/OTAConfig.h deleted file mode 100644 index cdd2163a10084e..00000000000000 --- a/examples/platform/silabs/efr32/OTAConfig.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * - * 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 -#include -#include -#include -#include - -class OTAConfig -{ -public: - OTAConfig(){}; - - static void Init(); - static constexpr uint32_t kInitOTARequestorDelaySec = 3; -}; diff --git a/examples/platform/silabs/efr32/matter_config.cpp b/examples/platform/silabs/efr32/matter_config.cpp index 3ffabe436c9871..14118d071e892b 100644 --- a/examples/platform/silabs/efr32/matter_config.cpp +++ b/examples/platform/silabs/efr32/matter_config.cpp @@ -110,7 +110,7 @@ CHIP_ERROR SilabsMatterConfig::InitOpenThread(void) } #endif // CHIP_ENABLE_OPENTHREAD -#if EFR32_OTA_ENABLED +#if SILABS_OTA_ENABLED void SilabsMatterConfig::InitOTARequestorHandler(System::Layer * systemLayer, void * appState) { OTAConfig::Init(); @@ -125,7 +125,7 @@ void SilabsMatterConfig::ConnectivityEventCallback(const ChipDeviceEvent * event ((event->Type == DeviceEventType::kInternetConnectivityChange) && (event->InternetConnectivityChange.IPv6 == kConnectivity_Established))) { -#if EFR32_OTA_ENABLED +#if SILABS_OTA_ENABLED SILABS_LOG("Scheduling OTA Requestor initialization") chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(OTAConfig::kInitOTARequestorDelaySec), InitOTARequestorHandler, nullptr); diff --git a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.h b/src/platform/silabs/OTAImageProcessorImpl.h similarity index 100% rename from src/platform/silabs/SiWx917/OTAImageProcessorImpl.h rename to src/platform/silabs/OTAImageProcessorImpl.h diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index 53932e5df42761..fadfbbd1177f39 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -67,7 +67,7 @@ static_library("SiWx917") { if (chip_enable_ota_requestor) { sources += [ #"OTAImageProcessorImpl.cpp", - #"OTAImageProcessorImpl.h", + #"${silabs_platform_dir}/OTAImageProcessorImpl.h", ] } diff --git a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp index f07fd947d03c17..a838564d919520 100644 --- a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp @@ -16,9 +16,9 @@ * limitations under the License. */ -#include "OTAImageProcessorImpl.h" #include #include +#include extern "C" { #include "btl_interface.h" diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index 1f43416c8013bb..61a1ddc26fc7e2 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -76,8 +76,8 @@ static_library("efr32") { if (chip_enable_ota_requestor) { sources += [ + "${silabs_platform_dir}/OTAImageProcessorImpl.h", "OTAImageProcessorImpl.cpp", - "OTAImageProcessorImpl.h", ] } diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp index 82150a28c397a7..83b815568b24fa 100644 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/efr32/OTAImageProcessorImpl.cpp @@ -16,9 +16,9 @@ * limitations under the License. */ -#include "OTAImageProcessorImpl.h" #include #include +#include extern "C" { #include "btl_interface.h" diff --git a/src/platform/silabs/efr32/OTAImageProcessorImpl.h b/src/platform/silabs/efr32/OTAImageProcessorImpl.h deleted file mode 100644 index 30709bd7f32f3a..00000000000000 --- a/src/platform/silabs/efr32/OTAImageProcessorImpl.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * 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 -#include -#include -#include - -#include - -namespace chip { - -class OTAImageProcessorImpl : public OTAImageProcessorInterface -{ -public: - //////////// OTAImageProcessorInterface Implementation /////////////// - CHIP_ERROR PrepareDownload() override; - CHIP_ERROR Finalize() override; - CHIP_ERROR Apply() override; - CHIP_ERROR Abort() override; - CHIP_ERROR ProcessBlock(ByteSpan & block) override; - bool IsFirstImageRun() override; - CHIP_ERROR ConfirmCurrentImage() override; - - 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); - static void HandleFinalize(intptr_t context); - static void HandleApply(intptr_t context); - static void HandleAbort(intptr_t context); - static void HandleProcessBlock(intptr_t context); - CHIP_ERROR ProcessHeader(ByteSpan & block); - - /** - * Called to allocate memory for mBlock if necessary and set it to block - */ - CHIP_ERROR SetBlock(ByteSpan & block); - - /** - * Called to release allocated memory for mBlock - */ - CHIP_ERROR ReleaseBlock(); - - // EFR32 platform creates a single instance of OTAImageProcessorImpl class. - // If that changes then the use of static members and functions must be revisited - static uint32_t mWriteOffset; // End of last written block - static uint8_t mSlotId; // Bootloader storage slot - MutableByteSpan mBlock; - OTADownloader * mDownloader; - OTAImageHeaderParser mHeaderParser; - const char * mImageFile = nullptr; - static constexpr size_t kAlignmentBytes = 64; - // Intermediate, word-aligned buffer for writing to the bootloader storage. - // Bootloader storage API requires the buffer size to be a multiple of 4. - static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))); - // Offset indicates how far the write buffer has been filled - static uint16_t writeBufOffset; -}; - -} // namespace chip