From 17c56114f719c9a66548c0d4db3f46dffc1e0e97 Mon Sep 17 00:00:00 2001 From: shgutte Date: Tue, 26 Mar 2024 16:28:28 +0530 Subject: [PATCH 01/35] Added changes for the multi ota 917 soc --- .../tools/silabs/ota/ota_multi_image_tool.py | 4 +- src/platform/silabs/SiWx917/BUILD.gn | 12 +- .../silabs/multi-ota/OTATlvProcessor.cpp | 13 +- .../SiWx917/OTAFirmwareProcessor.cpp | 207 ++++++++++++++++++ .../multi-ota/SiWx917/OTAFirmwareProcessor.h | 59 +++++ .../silabs/multi-ota/SiWx917/OTAHooks.cpp | 44 ++++ 6 files changed, 335 insertions(+), 4 deletions(-) create mode 100644 src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp create mode 100644 src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h create mode 100644 src/platform/silabs/multi-ota/SiWx917/OTAHooks.cpp diff --git a/scripts/tools/silabs/ota/ota_multi_image_tool.py b/scripts/tools/silabs/ota/ota_multi_image_tool.py index 280c80ea516a5d..28e3edb663b882 100755 --- a/scripts/tools/silabs/ota/ota_multi_image_tool.py +++ b/scripts/tools/silabs/ota/ota_multi_image_tool.py @@ -62,7 +62,9 @@ class TAG: APPLICATION = 1 BOOTLOADER = 2 FACTORY_DATA = 3 - + WIFI_917_NCP_TA = 4 + WIFI_917_SOC_COMBINED = 5 + WIFI_917_NCP_COMBINED = 6 def set_logger(): stdout_handler = logging.StreamHandler(stream=sys.stdout) diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index 66e464b0b2d9a2..53dbc176d87d85 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -77,7 +77,17 @@ static_library("SiWx917") { "SiWxPlatformInterface.h", ] - if (chip_enable_ota_requestor) { + if (chip_enable_multi_ota_requestor) { + sources += [ + "${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.cpp", + "${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.h", + "${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp", + "${silabs_platform_dir}/multi-ota/OTATlvProcessor.h", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor.cpp", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor.h", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAHooks.cpp", + ] + } else if (chip_enable_ota_requestor) { sources += [ "${silabs_platform_dir}/OTAImageProcessorImpl.h", "OTAImageProcessorImpl.cpp", diff --git a/src/platform/silabs/multi-ota/OTATlvProcessor.cpp b/src/platform/silabs/multi-ota/OTATlvProcessor.cpp index 6b679eb9c09b3d..3e2d656f2761ab 100644 --- a/src/platform/silabs/multi-ota/OTATlvProcessor.cpp +++ b/src/platform/silabs/multi-ota/OTATlvProcessor.cpp @@ -31,7 +31,17 @@ using namespace ::chip::DeviceLayer::Internal; namespace chip { -#ifdef SL_MATTER_ENABLE_OTA_ENCRYPTION +typedef enum +{ + APPLICATION, + BOOTLOADER, + FACTORY_DATA, + WIFI_917_NCP_TA, + WIFI_917_SOC_TA, /* This is used as scan result and start */ + WIFI_917_NCP_COMBINED +} OTAImageType; + +#if SL_MATTER_ENABLE_OTA_ENCRYPTION constexpr uint8_t au8Iv[] = { 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x00, 0x00, 0x00, 0x00 }; #endif CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block) @@ -57,7 +67,6 @@ CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block) } } } - return status; } diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp new file mode 100644 index 00000000000000..8c9f1c792ac180 --- /dev/null +++ b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp @@ -0,0 +1,207 @@ +/* + * + * Copyright (c) 2023 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 +#include +#include + +#include +#include "wfx_host_events.h" +#include +#ifdef __cplusplus +extern "C" { +#endif +#include "sl_si91x_driver.h" +#ifdef SLI_SI91X_MCU_INTERFACE +#include "sl_si91x_hal_soc_soft_reset.h" +#endif +#ifdef __cplusplus +} +#endif + +#define RPS_HEADER 1 +#define RPS_DATA 2 + +#define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND +uint8_t flag = RPS_HEADER; + +// TODO: more descriptive error codes +#define SL_OTA_ERROR 1L + +namespace chip { + +// Define static memebers +uint8_t OTAFirmwareProcessor::mReset = false; +uint32_t OTAFirmwareProcessor::mWriteOffset = 0; +uint16_t OTAFirmwareProcessor::writeBufOffset = 0; +uint8_t OTAFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; + +CHIP_ERROR OTAFirmwareProcessor::Init() +{ + ReturnErrorCodeIf(mCallbackProcessDescriptor == nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED); + mAccumulator.Init(sizeof(Descriptor)); +#if OTA_ENCRYPTION_ENABLE + mUnalignmentNum = 0; +#endif + + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAFirmwareProcessor::Clear() +{ + OTATlvProcessor::ClearInternal(); + mAccumulator.Clear(); + mDescriptorProcessed = false; +#if OTA_ENCRYPTION_ENABLE + mUnalignmentNum = 0; +#endif + + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block) +{ + int32_t status = SL_STATUS_OK; + if (!mDescriptorProcessed) + { + ReturnErrorOnFailure(ProcessDescriptor(block)); + } + + uint32_t blockReadOffset = 0; + while (blockReadOffset < block.size()) + { + writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset); + writeBufOffset++; + blockReadOffset++; + if (writeBufOffset == kAlignmentBytes) + { + writeBufOffset = 0; + + if (flag == RPS_HEADER) + { + // Send RPS header which is received as first chunk + status = sl_si91x_fwup_start(writeBuffer); + status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); + flag = RPS_DATA; + } + else if (flag == RPS_DATA) + { + // Send RPS content + status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); + if (status != SL_STATUS_OK) + { + // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value + // should be set to true in HandleProcessBlock + if (status == SL_STATUS_FW_UPDATE_DONE) + { + mReset = true; + } + else + { + ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + return; + } + } + } + if (err) + { + ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage() error: %ld", err); + // TODO: add this somewhere + // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + // TODO: Replace CHIP_ERROR_CANCELLED with new error statement + return CHIP_ERROR_CANCELLED; + } + mWriteOffset += kAlignmentBytes; + } + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAFirmwareProcessor::ProcessDescriptor(ByteSpan & block) +{ + ReturnErrorOnFailure(mAccumulator.Accumulate(block)); + ReturnErrorOnFailure(mCallbackProcessDescriptor(static_cast(mAccumulator.data()))); + + mDescriptorProcessed = true; + mAccumulator.Clear(); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAFirmwareProcessor::ApplyAction() +{ + uint32_t err = SL_BOOTLOADER_OK; + if (err != SL_BOOTLOADER_OK) + { + ChipLogError(SoftwareUpdate, "bootloader_verifyImage() error: %ld", err); + // Call the OTARequestor API to reset the state + GetRequestorInstance()->CancelImageUpdate(); + + return SL_GENERIC_OTA_ERROR; + } + + CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);) + if (err != SL_BOOTLOADER_OK) + { + ChipLogError(SoftwareUpdate, "bootloader_setImageToBootload() error: %ld", err); + // Call the OTARequestor API to reset the state + GetRequestorInstance()->CancelImageUpdate(); + return SL_GENERIC_OTA_ERROR; + } + + return CHIP_NO_ERROR; +} + +CHIP_ERROR OTAFirmwareProcessor::FinalizeAction() +{ + int32_t status = SL_STATUS_OK; + + // Pad the remainder of the write buffer with zeros and write it to bootloader storage + if (writeBufOffset != 0) + { + + while (writeBufOffset != kAlignmentBytes) + { + writeBuffer[writeBufOffset] = 0; + writeBufOffset++; + } + status = sl_si91x_fwup_load(writeBuffer, writeBufOffset); + ChipLogProgress(SoftwareUpdate, "status: 0x%lX", status); + + if (status != SL_STATUS_OK) + { + if (status == SL_STATUS_FW_UPDATE_DONE) + { + mReset = true; + } + else + { + ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize for last chunk sl_si91x_fwup_load() error %ld", status); + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + return; + } + } + + } + + return err ? CHIP_ERROR_WRITE_FAILED : CHIP_NO_ERROR; +} + +} // namespace chip diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h new file mode 100644 index 00000000000000..c383e7497b8b1a --- /dev/null +++ b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2023 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 + +namespace chip { + +class OTAFirmwareProcessor : public OTATlvProcessor +{ +public: + struct Descriptor + { + uint32_t version; + char versionString[kVersionStringSize]; + char buildDate[kBuildDateSize]; + }; + + CHIP_ERROR Init() override; + CHIP_ERROR Clear() override; + CHIP_ERROR ApplyAction() override; + CHIP_ERROR FinalizeAction() override; + +private: + CHIP_ERROR ProcessInternal(ByteSpan & block) override; + CHIP_ERROR ProcessDescriptor(ByteSpan & block); + + OTADataAccumulator mAccumulator; + bool mDescriptorProcessed = false; +#if OTA_ENCRYPTION_ENABLE + uint32_t mUnalignmentNum; +#endif + static constexpr size_t kAlignmentBytes = 64; + static uint32_t mWriteOffset; // End of last written block + static uint8_t mSlotId; // Bootloader storage slot + // 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 diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAHooks.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAHooks.cpp new file mode 100644 index 00000000000000..cddb66980c27f9 --- /dev/null +++ b/src/platform/silabs/multi-ota/SiWx917/OTAHooks.cpp @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2023 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 +#include + +#include + +#include + +CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor) +{ + auto desc = static_cast(descriptor); + ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit() +{ + static chip::OTAFirmwareProcessor sApplicationProcessor; + + sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor); + + auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance(); + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(1, &sApplicationProcessor)); + + return CHIP_NO_ERROR; +} From 5eef7f61b66f654e01f9a61fc8a42fba46dd3c2f Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 27 Mar 2024 16:37:43 +0530 Subject: [PATCH 02/35] Added changes for the build errores --- examples/platform/silabs/SiWx917/BUILD.gn | 37 ++++++++++++ src/platform/silabs/SiWx917/BUILD.gn | 3 +- .../multi-ota/OTAMultiImageProcessorImpl.cpp | 16 +++++- .../SiWx917/OTAFirmwareProcessor.cpp | 57 +++++++------------ .../multi-ota/SiWx917/OTAFirmwareProcessor.h | 16 +++--- 5 files changed, 83 insertions(+), 46 deletions(-) diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 41ab6b62573fd3..65dbbc5694987e 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -94,6 +94,43 @@ config("siwx917-common-config") { ldflags = [ "-Wl,--no-warn-rwx-segment" ] } +config("silabs-wifi-config") { + defines = [] + include_dirs = [] + + if (chip_default_wifi_ssid != "") { + defines += [ + "SL_ONNETWORK_PAIRING=1", + "SL_WIFI_SSID=\"${chip_default_wifi_ssid}\"", + ] + } + if (chip_default_wifi_psk != "") { + assert(chip_default_wifi_ssid != "", + "ssid can't be null if psk is provided") + defines += [ "SL_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] + } + + if (sl_wfx_config_softap) { + defines += [ "SL_WFX_CONFIG_SOFTAP" ] + } + + if (sl_wfx_config_scan) { + defines += [ "SL_WFX_CONFIG_SCAN" ] + } + + if (chip_enable_wifi_ipv4) { + defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4" ] + } + + if (rs91x_wpa3_transition) { + defines += [ "WIFI_ENABLE_SECURITY_WPA3_TRANSITION=1" ] + } + + if (chip_enable_multi_ota_requestor) { + defines += [ "CHIP_DEVICE_CONFIG_ENABLE_MULTI_OTA_REQUESTOR=1" ] + } +} + source_set("siwx917-common") { deps = [ "${silabs_common_plat_dir}/provision:storage" ] defines = [] diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index 53dbc176d87d85..ea24dea6c5df18 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -13,9 +13,8 @@ # limitations under the License. import("//build_overrides/chip.gni") - import("${chip_root}/src/platform/device.gni") - +import("${chip_root}/third_party/silabs/efr32_sdk.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/crypto/crypto.gni") import("${chip_root}/src/platform/silabs/wifi/args.gni") diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index a0028541725c69..0e4015f7773a5e 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -22,7 +22,6 @@ #include #include #include - #include using namespace chip::DeviceLayer; @@ -35,8 +34,14 @@ static chip::OTAMultiImageProcessorImpl gImageProcessor; #endif // SL_WIFI extern "C" { +#if SL_BTLCTRL_MUX #include "btl_interface.h" #include "sl_core.h" +#endif // SL_BTLCTRL_MUX +#include "em_bus.h" // For CORE_CRITICAL_SECTION +#ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP +#include "spi_multiplex.h" +#endif // SL_WIFI } namespace chip { @@ -115,7 +120,9 @@ void OTAMultiImageProcessorImpl::HandlePrepareDownload(intptr_t context) ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started"); +#ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP CORE_CRITICAL_SECTION(bootloader_init();) +#endif imageProcessor->mParams.downloadedBytes = 0; @@ -421,8 +428,15 @@ void OTAMultiImageProcessorImpl::HandleApply(intptr_t context) ChipLogProgress(SoftwareUpdate, "HandleApply: Finished"); +<<<<<<< HEAD // This reboots the device +======= + // TODO: check where to put this + // ConfigurationManagerImpl().StoreSoftwareUpdateCompleted(); +#ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP +>>>>>>> ac92393594 (Added changes for the build errores) CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) +#endif } CHIP_ERROR OTAMultiImageProcessorImpl::ReleaseBlock() diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp index 8c9f1c792ac180..865991e7dea877 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp @@ -46,7 +46,7 @@ uint8_t flag = RPS_HEADER; namespace chip { // Define static memebers -uint8_t OTAFirmwareProcessor::mReset = false; +//bool OTAFirmwareProcessor::mReset = false; uint32_t OTAFirmwareProcessor::mWriteOffset = 0; uint16_t OTAFirmwareProcessor::writeBufOffset = 0; uint8_t OTAFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; @@ -109,24 +109,18 @@ CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block) // should be set to true in HandleProcessBlock if (status == SL_STATUS_FW_UPDATE_DONE) { - mReset = true; + //mReset = true; } else { ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); - imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - return; + // TODO: add this somewhere + // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + // TODO: Replace CHIP_ERROR_CANCELLED with new error statement + return CHIP_ERROR_CANCELLED; } } } - if (err) - { - ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage() error: %ld", err); - // TODO: add this somewhere - // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - // TODO: Replace CHIP_ERROR_CANCELLED with new error statement - return CHIP_ERROR_CANCELLED; - } mWriteOffset += kAlignmentBytes; } } @@ -147,25 +141,15 @@ CHIP_ERROR OTAFirmwareProcessor::ProcessDescriptor(ByteSpan & block) CHIP_ERROR OTAFirmwareProcessor::ApplyAction() { - uint32_t err = SL_BOOTLOADER_OK; - if (err != SL_BOOTLOADER_OK) - { - ChipLogError(SoftwareUpdate, "bootloader_verifyImage() error: %ld", err); - // Call the OTARequestor API to reset the state - GetRequestorInstance()->CancelImageUpdate(); - - return SL_GENERIC_OTA_ERROR; - } - - CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);) - if (err != SL_BOOTLOADER_OK) - { - ChipLogError(SoftwareUpdate, "bootloader_setImageToBootload() error: %ld", err); - // Call the OTARequestor API to reset the state - GetRequestorInstance()->CancelImageUpdate(); - return SL_GENERIC_OTA_ERROR; - } - + // This reboots the device + // if (mReset) + // { + // ChipLogProgress(SoftwareUpdate, "M4 Firmware update complete"); + // // send system reset request to reset the MCU and upgrade the m4 image + // ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!"); + // // Reboots the device + // sl_si91x_soc_soft_reset(); + // } return CHIP_NO_ERROR; } @@ -189,19 +173,22 @@ CHIP_ERROR OTAFirmwareProcessor::FinalizeAction() { if (status == SL_STATUS_FW_UPDATE_DONE) { - mReset = true; + // mReset = true; } else { ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize for last chunk sl_si91x_fwup_load() error %ld", status); - imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - return; + + // TODO: add this somewhere + // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + // TODO: Replace CHIP_ERROR_CANCELLED with new error statement + return CHIP_ERROR_CANCELLED; } } } - return err ? CHIP_ERROR_WRITE_FAILED : CHIP_NO_ERROR; + return status ? CHIP_ERROR_CANCELLED : CHIP_NO_ERROR; } } // namespace chip diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h index c383e7497b8b1a..5967b5506abc7c 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h +++ b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h @@ -37,7 +37,13 @@ class OTAFirmwareProcessor : public OTATlvProcessor CHIP_ERROR Clear() override; CHIP_ERROR ApplyAction() override; CHIP_ERROR FinalizeAction() override; - + static constexpr size_t kAlignmentBytes = 64; + static bool mReset = false; + static uint32_t mWriteOffset; // End of last written block + // 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; private: CHIP_ERROR ProcessInternal(ByteSpan & block) override; CHIP_ERROR ProcessDescriptor(ByteSpan & block); @@ -47,13 +53,7 @@ class OTAFirmwareProcessor : public OTATlvProcessor #if OTA_ENCRYPTION_ENABLE uint32_t mUnalignmentNum; #endif - static constexpr size_t kAlignmentBytes = 64; - static uint32_t mWriteOffset; // End of last written block - static uint8_t mSlotId; // Bootloader storage slot - // 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 From 5b07de3cc75486d4f60f20c69554a2579bff878d Mon Sep 17 00:00:00 2001 From: shgutte Date: Sun, 7 Apr 2024 15:47:13 +0530 Subject: [PATCH 03/35] Added changes for 917 soc --- src/platform/silabs/efr32/BUILD.gn | 9 +++++++++ ...FirmwareProcessor.cpp => OTAFirmwareProcessor917.cpp} | 0 ...{OTAFirmwareProcessor.h => OTAFirmwareProcessor917.h} | 0 .../multi-ota/SiWx917/{OTAHooks.cpp => OTAHooks.917cpp} | 0 4 files changed, 9 insertions(+) rename src/platform/silabs/multi-ota/SiWx917/{OTAFirmwareProcessor.cpp => OTAFirmwareProcessor917.cpp} (100%) rename src/platform/silabs/multi-ota/SiWx917/{OTAFirmwareProcessor.h => OTAFirmwareProcessor917.h} (100%) rename src/platform/silabs/multi-ota/SiWx917/{OTAHooks.cpp => OTAHooks.917cpp} (100%) diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index d0bf04d83b4620..d875e337d67e4e 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -104,6 +104,15 @@ static_library("efr32") { "${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp", "${silabs_platform_dir}/multi-ota/OTATlvProcessor.h", ] + + if (chip_enable_wifi) { + sources += [ + "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.h", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAHooks917.cpp", + ] + } + } else if (chip_enable_ota_requestor) { sources += [ "${silabs_platform_dir}/OTAImageProcessorImpl.h", diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp similarity index 100% rename from src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.cpp rename to src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h similarity index 100% rename from src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor.h rename to src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAHooks.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAHooks.917cpp similarity index 100% rename from src/platform/silabs/multi-ota/SiWx917/OTAHooks.cpp rename to src/platform/silabs/multi-ota/SiWx917/OTAHooks.917cpp From ea8c80feab965a243bf1cae878c03973bc3f1f29 Mon Sep 17 00:00:00 2001 From: shgutte Date: Mon, 8 Apr 2024 12:04:39 +0530 Subject: [PATCH 04/35] Added changes for the name for 917 NCP --- .../silabs/multi-ota/SiWx917/OTAHooks917.cpp | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp new file mode 100644 index 00000000000000..cddb66980c27f9 --- /dev/null +++ b/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2023 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 +#include + +#include + +#include + +CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor) +{ + auto desc = static_cast(descriptor); + ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit() +{ + static chip::OTAFirmwareProcessor sApplicationProcessor; + + sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor); + + auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance(); + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(1, &sApplicationProcessor)); + + return CHIP_NO_ERROR; +} From ad4dd34160a58aece019e29099b031cbd96cb3ee Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 10 Apr 2024 09:18:19 +0530 Subject: [PATCH 05/35] Deleted the 917 NCP file --- .../silabs/multi-ota/SiWx917/OTAHooks.917cpp | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 src/platform/silabs/multi-ota/SiWx917/OTAHooks.917cpp diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAHooks.917cpp b/src/platform/silabs/multi-ota/SiWx917/OTAHooks.917cpp deleted file mode 100644 index cddb66980c27f9..00000000000000 --- a/src/platform/silabs/multi-ota/SiWx917/OTAHooks.917cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Copyright (c) 2023 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 -#include - -#include - -#include - -CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor) -{ - auto desc = static_cast(descriptor); - ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit() -{ - static chip::OTAFirmwareProcessor sApplicationProcessor; - - sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor); - - auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance(); - ReturnErrorOnFailure(imageProcessor.RegisterProcessor(1, &sApplicationProcessor)); - - return CHIP_NO_ERROR; -} From 7762e372689a2d6470f79f2d2a891f4d222b9bb7 Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 10 Apr 2024 22:01:20 +0530 Subject: [PATCH 06/35] Added fixed for 917 SoC build changes --- src/platform/silabs/SiWx917/BUILD.gn | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index ea24dea6c5df18..08184c17cada13 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -82,9 +82,9 @@ static_library("SiWx917") { "${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.h", "${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp", "${silabs_platform_dir}/multi-ota/OTATlvProcessor.h", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor.cpp", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor.h", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAHooks.cpp", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.h", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAHooks917.cpp", ] } else if (chip_enable_ota_requestor) { sources += [ From 5949e9fe14461e37bf122ce36299df44030627d5 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 12 Apr 2024 00:42:38 +0530 Subject: [PATCH 07/35] Added changes for 917 SOC --- src/platform/silabs/multi-ota/OTATlvProcessor.h | 8 ++++++++ .../silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp | 2 +- .../silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h | 2 +- src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/platform/silabs/multi-ota/OTATlvProcessor.h b/src/platform/silabs/multi-ota/OTATlvProcessor.h index a14c2f2442c07c..56ab89d739f730 100644 --- a/src/platform/silabs/multi-ota/OTATlvProcessor.h +++ b/src/platform/silabs/multi-ota/OTATlvProcessor.h @@ -24,6 +24,14 @@ namespace chip { +typedef enum +{ + APPLICATION = 1, + BOOTLOADER = 2, + FACTORY_DATA = 3, + WIFI_917_TA_M4 = 4, +} OTAImageType; + #define CHIP_ERROR_TLV_PROCESSOR(e) \ ChipError(ChipError::Range::kLastRange, ((uint8_t) ChipError::Range::kLastRange << 3) | e, __FILE__, __LINE__) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp index 865991e7dea877..a921b66e820743 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include "wfx_host_events.h" diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h index 5967b5506abc7c..a321eb0565ba37 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h +++ b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h @@ -37,8 +37,8 @@ class OTAFirmwareProcessor : public OTATlvProcessor CHIP_ERROR Clear() override; CHIP_ERROR ApplyAction() override; CHIP_ERROR FinalizeAction() override; + static bool mReset; static constexpr size_t kAlignmentBytes = 64; - static bool mReset = false; static uint32_t mWriteOffset; // End of last written block // Bootloader storage API requires the buffer size to be a multiple of 4. static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))); diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp index cddb66980c27f9..bc35b1bc8bed2c 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp @@ -21,7 +21,7 @@ #include -#include +#include CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor) { From 6e80e031b43b050d7b71e277b286a18743dfc440 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 12 Apr 2024 01:26:03 +0530 Subject: [PATCH 08/35] Added changes for the 917 SOC build error --- src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp index bc35b1bc8bed2c..f06d7c6a4b8a0e 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAHooks917.cpp @@ -22,6 +22,9 @@ #include #include +#if OTA_TEST_CUSTOM_TLVS +#include +#endif CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor) { From 4cfdfd544733dfe6c68a2701767a0e07fe1ea8b3 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 12 Apr 2024 01:54:45 +0530 Subject: [PATCH 09/35] Added changes for the 917 SoC ota reset --- .../SiWx917/OTAFirmwareProcessor917.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp index a921b66e820743..867f08005dfaa1 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp @@ -46,7 +46,7 @@ uint8_t flag = RPS_HEADER; namespace chip { // Define static memebers -//bool OTAFirmwareProcessor::mReset = false; +bool OTAFirmwareProcessor::mReset = false; uint32_t OTAFirmwareProcessor::mWriteOffset = 0; uint16_t OTAFirmwareProcessor::writeBufOffset = 0; uint8_t OTAFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; @@ -109,7 +109,7 @@ CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block) // should be set to true in HandleProcessBlock if (status == SL_STATUS_FW_UPDATE_DONE) { - //mReset = true; + mReset = true; } else { @@ -142,14 +142,14 @@ CHIP_ERROR OTAFirmwareProcessor::ProcessDescriptor(ByteSpan & block) CHIP_ERROR OTAFirmwareProcessor::ApplyAction() { // This reboots the device - // if (mReset) - // { - // ChipLogProgress(SoftwareUpdate, "M4 Firmware update complete"); - // // send system reset request to reset the MCU and upgrade the m4 image - // ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!"); - // // Reboots the device - // sl_si91x_soc_soft_reset(); - // } + if (mReset) + { + ChipLogProgress(SoftwareUpdate, "M4 Firmware update complete"); + // send system reset request to reset the MCU and upgrade the m4 image + ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!"); + // Reboots the device + sl_si91x_soc_soft_reset(); + } return CHIP_NO_ERROR; } @@ -173,7 +173,7 @@ CHIP_ERROR OTAFirmwareProcessor::FinalizeAction() { if (status == SL_STATUS_FW_UPDATE_DONE) { - // mReset = true; + mReset = true; } else { From 627f9baff0310ceb44bde95430a20704784c34e2 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 12 Apr 2024 03:17:45 +0530 Subject: [PATCH 10/35] Added changes for OTA 917 SoC script --- .../tools/silabs/ota/ota_multi_image_tool.py | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/scripts/tools/silabs/ota/ota_multi_image_tool.py b/scripts/tools/silabs/ota/ota_multi_image_tool.py index 28e3edb663b882..66c32592e48bdd 100755 --- a/scripts/tools/silabs/ota/ota_multi_image_tool.py +++ b/scripts/tools/silabs/ota/ota_multi_image_tool.py @@ -50,6 +50,7 @@ from chip.tlv import TLVWriter # noqa: E402 isort:skip from custom import CertDeclaration, DacCert, DacPKey, PaiCert # noqa: E402 isort:skip from default import InputArgument # noqa: E402 isort:skip +from generate import set_logger # noqa: E402 isort:skip OTA_APP_TLV_TEMP = os.path.join(os.path.dirname(__file__), "ota_temp_app_tlv.bin") OTA_BOOTLOADER_TLV_TEMP = os.path.join(os.path.dirname(__file__), "ota_temp_ssbl_tlv.bin") @@ -66,15 +67,6 @@ class TAG: WIFI_917_SOC_COMBINED = 5 WIFI_917_NCP_COMBINED = 6 -def set_logger(): - stdout_handler = logging.StreamHandler(stream=sys.stdout) - logging.basicConfig( - level=logging.DEBUG, - format='[%(levelname)s] %(message)s', - handlers=[stdout_handler] - ) - - def write_to_temp(path: str, payload: bytearray): with open(path, "wb") as _handle: _handle.write(payload) @@ -165,6 +157,32 @@ def generate_app(args: object): return [OTA_APP_TLV_TEMP, args.app_input_file] +def generate_wifi_image(args: object): + """ + Generate app payload with descriptor. If a certain option is not specified, use the default values. + """ + logging.info("App descriptor information:") + + descriptor = generate_descriptor(args.app_version, args.app_version_str, args.app_build_date) + logging.info(f"App encryption enable: {args.enc_enable}") + if args.enc_enable: + inputFile = open(args.wifi_input_file, "rb") + enc_file = crypto_utils.encryptData(inputFile.read(), args.input_ota_key, INITIALIZATION_VECTOR) + enc_file1 = bytes([ord(x) for x in enc_file]) + file_size = len(enc_file1) + payload = generate_header(TAG.WIFI_917_TA_M4, len(descriptor) + file_size) + descriptor + enc_file1 + else: + file_size = os.path.getsize(args.wifi_input_file) + logging.info(f"file size: {file_size}") + payload = generate_header(TAG.WIFI_917_TA_M4, len(descriptor) + file_size) + descriptor + + write_to_temp(OTA_APP_TLV_TEMP, payload) + if args.enc_enable: + return [OTA_APP_TLV_TEMP] + else: + return [OTA_APP_TLV_TEMP, args.wifi_input_file] + + def generate_bootloader(args: object): """ Generate SSBL payload with descriptor. If a certain option is not specified, use the default values. @@ -259,7 +277,10 @@ def create_image(args: object): input_files += generate_bootloader(args) if args.app_input_file: - input_files += generate_app(args) + input_files += generate_app(args) + + if args.wifi_input_file: + input_files += generate_wifi_image(args) if len(input_files) == 0: print("Please specify an input option.") @@ -314,6 +335,8 @@ def any_base_int(s): return int(s, 0) create_parser.add_argument('-app', "--app-input-file", help='Path to application input file') + create_parser.add_argument('-wifi', "--wifi-input-file", + help='Path to 917 wifi OTA either TA, application o r combined input file') create_parser.add_argument('--app-version', type=any_base_int, help='Application Software version (numeric)') create_parser.add_argument('--app-version-str', type=str, From 5a7d83ba3706e463835377300538edcecc8ba4fa Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 12 Apr 2024 04:55:07 +0530 Subject: [PATCH 11/35] Added changes for 917 build --- src/platform/silabs/SiWx917/BUILD.gn | 6 +-- src/platform/silabs/efr32/BUILD.gn | 1 - src/platform/silabs/multi-ota/OTAHooks.cpp | 37 ++++++++++++++----- .../multi-ota/OTAMultiImageProcessorImpl.cpp | 2 + ...or917.cpp => OTAWiFiFirmwareProcessor.cpp} | 22 +++++------ ...cessor917.h => OTAWiFiFirmwareProcessor.h} | 2 +- 6 files changed, 44 insertions(+), 26 deletions(-) rename src/platform/silabs/multi-ota/SiWx917/{OTAFirmwareProcessor917.cpp => OTAWiFiFirmwareProcessor.cpp} (87%) rename src/platform/silabs/multi-ota/SiWx917/{OTAFirmwareProcessor917.h => OTAWiFiFirmwareProcessor.h} (96%) diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index 08184c17cada13..24f628e2d0bfcb 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -82,9 +82,9 @@ static_library("SiWx917") { "${silabs_platform_dir}/multi-ota/OTAMultiImageProcessorImpl.h", "${silabs_platform_dir}/multi-ota/OTATlvProcessor.cpp", "${silabs_platform_dir}/multi-ota/OTATlvProcessor.h", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.h", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAHooks917.cpp", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h", + "${silabs_platform_dir}/multi-ota/OTAHooks.cpp", ] } else if (chip_enable_ota_requestor) { sources += [ diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index d875e337d67e4e..484f81016b8ce8 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -109,7 +109,6 @@ static_library("efr32") { sources += [ "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp", "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.h", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAHooks917.cpp", ] } diff --git a/src/platform/silabs/multi-ota/OTAHooks.cpp b/src/platform/silabs/multi-ota/OTAHooks.cpp index 04c6f23edd0b7c..7c95b9cc2e3b1b 100644 --- a/src/platform/silabs/multi-ota/OTAHooks.cpp +++ b/src/platform/silabs/multi-ota/OTAHooks.cpp @@ -22,7 +22,13 @@ #include #include +#ifndef SLI_SI91X_MCU_INTERFACE #include +#endif + +#if SL_WIFI +#include +#endif #if OTA_TEST_CUSTOM_TLVS #include @@ -30,25 +36,29 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor) { +#ifndef SLI_SI91X_MCU_INTERFACE [[maybe_unused]] auto desc = static_cast(descriptor); ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate); +#endif + +#if SL_WIFI + auto desc = static_cast(descriptor); + ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate); +#endif return CHIP_NO_ERROR; } CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit() { - static chip::OTAFirmwareProcessor sApplicationProcessor; - static chip::OTAFactoryDataProcessor sFactoryDataProcessor; - - sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor); - sFactoryDataProcessor.RegisterDescriptorCallback(ProcessDescriptor); auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance(); - ReturnErrorOnFailure( - imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kApplicationProcessor), &sApplicationProcessor)); - ReturnErrorOnFailure( - imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kFactoryDataProcessor), &sFactoryDataProcessor)); + +#ifndef SLI_SI91X_MCU_INTERFACE + static chip::OTAFirmwareProcessor sApplicationProcessor; + sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor); + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(APPLICATION, &sApplicationProcessor)); +#endif #if OTA_TEST_CUSTOM_TLVS static chip::OTACustomProcessor customProcessor1; @@ -63,5 +73,12 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit() ReturnErrorOnFailure(imageProcessor.RegisterProcessor(9, &customProcessor2)); ReturnErrorOnFailure(imageProcessor.RegisterProcessor(10, &customProcessor3)); #endif + +#ifdef SL_WIFI + static chip::OTAWiFiFirmwareProcessor sWifiFirmwareProcessor; + sWifiFirmwareProcessor.RegisterDescriptorCallback(ProcessDescriptor); + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(WIFI_917_TA_M4), &sWifiFirmwareProcessor)); +#endif + return CHIP_NO_ERROR; -} +} diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index 0e4015f7773a5e..b8a40228301ee3 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -209,6 +209,8 @@ CHIP_ERROR OTAMultiImageProcessorImpl::SelectProcessor(ByteSpan & block) CHIP_ERROR OTAMultiImageProcessorImpl::RegisterProcessor(uint32_t tag, OTATlvProcessor * processor) { + + ChipLogDetail(SoftwareUpdate, "RegisterProcessor with tag: %ld", tag); auto pair = mProcessorMap.find(tag); if (pair != mProcessorMap.end()) { diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp similarity index 87% rename from src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp rename to src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index 867f08005dfaa1..a102d66184e344 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include "wfx_host_events.h" @@ -46,12 +46,12 @@ uint8_t flag = RPS_HEADER; namespace chip { // Define static memebers -bool OTAFirmwareProcessor::mReset = false; -uint32_t OTAFirmwareProcessor::mWriteOffset = 0; -uint16_t OTAFirmwareProcessor::writeBufOffset = 0; -uint8_t OTAFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; +bool OTAWiFiFirmwareProcessor::mReset = false; +uint32_t OTAWiFiFirmwareProcessor::mWriteOffset = 0; +uint16_t OTAWiFiFirmwareProcessor::writeBufOffset = 0; +uint8_t OTAWiFiFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; -CHIP_ERROR OTAFirmwareProcessor::Init() +CHIP_ERROR OTAWiFiFirmwareProcessor::Init() { ReturnErrorCodeIf(mCallbackProcessDescriptor == nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED); mAccumulator.Init(sizeof(Descriptor)); @@ -62,7 +62,7 @@ CHIP_ERROR OTAFirmwareProcessor::Init() return CHIP_NO_ERROR; } -CHIP_ERROR OTAFirmwareProcessor::Clear() +CHIP_ERROR OTAWiFiFirmwareProcessor::Clear() { OTATlvProcessor::ClearInternal(); mAccumulator.Clear(); @@ -74,7 +74,7 @@ CHIP_ERROR OTAFirmwareProcessor::Clear() return CHIP_NO_ERROR; } -CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block) +CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) { int32_t status = SL_STATUS_OK; if (!mDescriptorProcessed) @@ -128,7 +128,7 @@ CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block) return CHIP_NO_ERROR; } -CHIP_ERROR OTAFirmwareProcessor::ProcessDescriptor(ByteSpan & block) +CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessDescriptor(ByteSpan & block) { ReturnErrorOnFailure(mAccumulator.Accumulate(block)); ReturnErrorOnFailure(mCallbackProcessDescriptor(static_cast(mAccumulator.data()))); @@ -139,7 +139,7 @@ CHIP_ERROR OTAFirmwareProcessor::ProcessDescriptor(ByteSpan & block) return CHIP_NO_ERROR; } -CHIP_ERROR OTAFirmwareProcessor::ApplyAction() +CHIP_ERROR OTAWiFiFirmwareProcessor::ApplyAction() { // This reboots the device if (mReset) @@ -153,7 +153,7 @@ CHIP_ERROR OTAFirmwareProcessor::ApplyAction() return CHIP_NO_ERROR; } -CHIP_ERROR OTAFirmwareProcessor::FinalizeAction() +CHIP_ERROR OTAWiFiFirmwareProcessor::FinalizeAction() { int32_t status = SL_STATUS_OK; diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h similarity index 96% rename from src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h rename to src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h index a321eb0565ba37..82517a1130433e 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAFirmwareProcessor917.h +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h @@ -23,7 +23,7 @@ namespace chip { -class OTAFirmwareProcessor : public OTATlvProcessor +class OTAWiFiFirmwareProcessor : public OTATlvProcessor { public: struct Descriptor From 08bab24316e42ad9ad32bc502f289973a89e4b64 Mon Sep 17 00:00:00 2001 From: shgutte Date: Sun, 14 Apr 2024 23:03:05 +0530 Subject: [PATCH 12/35] Added debugging logs for the files --- .../silabs/multi-ota/OTAMultiImageProcessorImpl.cpp | 3 +++ .../silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index b8a40228301ee3..36d9571619f38b 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -379,6 +379,7 @@ void OTAMultiImageProcessorImpl::HandleFinalize(intptr_t context) CHIP_ERROR OTAMultiImageProcessorImpl::ProcessFinalize() { + ChipLogProgress(SoftwareUpdate, "OTA MultiImage Processor Implementation"); for (auto const & pair : this->mProcessorMap) { pair.second->FinalizeAction(); @@ -438,6 +439,8 @@ void OTAMultiImageProcessorImpl::HandleApply(intptr_t context) #ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP >>>>>>> ac92393594 (Added changes for the build errores) CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) +#else + #endif } diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index a102d66184e344..fc2064128a7679 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -141,6 +141,7 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessDescriptor(ByteSpan & block) CHIP_ERROR OTAWiFiFirmwareProcessor::ApplyAction() { + ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Apply Action started"); // This reboots the device if (mReset) { @@ -149,14 +150,15 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ApplyAction() ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!"); // Reboots the device sl_si91x_soc_soft_reset(); - } + } + ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Apply Action completed"); return CHIP_NO_ERROR; } CHIP_ERROR OTAWiFiFirmwareProcessor::FinalizeAction() { int32_t status = SL_STATUS_OK; - + ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Finalize Action started"); // Pad the remainder of the write buffer with zeros and write it to bootloader storage if (writeBufOffset != 0) { @@ -188,6 +190,7 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::FinalizeAction() } + ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Finalize Action completed"); return status ? CHIP_ERROR_CANCELLED : CHIP_NO_ERROR; } From f4bf6109e39749b30f449c1a57b99b7a6a86ef67 Mon Sep 17 00:00:00 2001 From: shgutte Date: Sun, 14 Apr 2024 23:15:56 +0530 Subject: [PATCH 13/35] Removed the duplicate code From e6c3a136add908a615be2fef37482b258fbbd840 Mon Sep 17 00:00:00 2001 From: shgutte Date: Mon, 15 Apr 2024 16:37:34 +0530 Subject: [PATCH 14/35] Added changes for the SoC Application --- .../silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index fc2064128a7679..3aced5a87ffc71 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -159,16 +159,17 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::FinalizeAction() { int32_t status = SL_STATUS_OK; ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Finalize Action started"); + // Pad the remainder of the write buffer with zeros and write it to bootloader storage if (writeBufOffset != 0) { + status = sl_si91x_fwup_load(writeBuffer, writeBufOffset); while (writeBufOffset != kAlignmentBytes) { writeBuffer[writeBufOffset] = 0; writeBufOffset++; } - status = sl_si91x_fwup_load(writeBuffer, writeBufOffset); ChipLogProgress(SoftwareUpdate, "status: 0x%lX", status); if (status != SL_STATUS_OK) From cdc63eddddc3f7e948244191a25564180c773882 Mon Sep 17 00:00:00 2001 From: shgutte Date: Tue, 16 Apr 2024 16:03:39 +0530 Subject: [PATCH 15/35] Added changes for builkd issue with EFR32 multi OTA --- src/platform/silabs/efr32/BUILD.gn | 1 - src/platform/silabs/multi-ota/OTAHooks.cpp | 8 +++++++- .../silabs/multi-ota/OTATlvProcessor.h | 18 +++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index 484f81016b8ce8..19dba981cf4bd1 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -111,7 +111,6 @@ static_library("efr32") { "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.h", ] } - } else if (chip_enable_ota_requestor) { sources += [ "${silabs_platform_dir}/OTAImageProcessorImpl.h", diff --git a/src/platform/silabs/multi-ota/OTAHooks.cpp b/src/platform/silabs/multi-ota/OTAHooks.cpp index 7c95b9cc2e3b1b..72d1d744bd3c26 100644 --- a/src/platform/silabs/multi-ota/OTAHooks.cpp +++ b/src/platform/silabs/multi-ota/OTAHooks.cpp @@ -69,15 +69,21 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit() customProcessor2.RegisterDescriptorCallback(ProcessDescriptor); customProcessor3.RegisterDescriptorCallback(ProcessDescriptor); +<<<<<<< HEAD ReturnErrorOnFailure(imageProcessor.RegisterProcessor(8, &customProcessor1)); ReturnErrorOnFailure(imageProcessor.RegisterProcessor(9, &customProcessor2)); ReturnErrorOnFailure(imageProcessor.RegisterProcessor(10, &customProcessor3)); +======= + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kCustomProcessor1), &customProcessor1)); + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kCustomProcessor2), &customProcessor2)); + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kCustomProcessor3), &customProcessor3)); +>>>>>>> d7d9418cbb (Added changes for builkd issue with EFR32 multi OTA) #endif #ifdef SL_WIFI static chip::OTAWiFiFirmwareProcessor sWifiFirmwareProcessor; sWifiFirmwareProcessor.RegisterDescriptorCallback(ProcessDescriptor); - ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(WIFI_917_TA_M4), &sWifiFirmwareProcessor)); + ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kWiFiProcessor), &sWifiFirmwareProcessor)); #endif return CHIP_NO_ERROR; diff --git a/src/platform/silabs/multi-ota/OTATlvProcessor.h b/src/platform/silabs/multi-ota/OTATlvProcessor.h index 56ab89d739f730..49829d32484e02 100644 --- a/src/platform/silabs/multi-ota/OTATlvProcessor.h +++ b/src/platform/silabs/multi-ota/OTATlvProcessor.h @@ -24,14 +24,6 @@ namespace chip { -typedef enum -{ - APPLICATION = 1, - BOOTLOADER = 2, - FACTORY_DATA = 3, - WIFI_917_TA_M4 = 4, -} OTAImageType; - #define CHIP_ERROR_TLV_PROCESSOR(e) \ ChipError(ChipError::Range::kLastRange, ((uint8_t) ChipError::Range::kLastRange << 3) | e, __FILE__, __LINE__) @@ -73,9 +65,13 @@ struct OTATlvHeader // TLV tags synced with ota files generate by scripts/tools/silabs/ota/ota_image_tool.py enum class OTAProcessorTag { - kApplicationProcessor = 1, - kBootloaderProcessor = 2, - kFactoryDataProcessor = 3 + kApplicationProcessor = 1, + kBootloaderProcessor = 2 , + kFactoryDataProcessor = 3, + kWiFiProcessor = 4, + kCustomProcessor1 = 8, + kCustomProcessor2 = 9, + kCustomProcessor3 = 10, }; /** From 593eaf356e1c5a6a2bf04b9db5f432854c45bcb0 Mon Sep 17 00:00:00 2001 From: shgutte Date: Tue, 16 Apr 2024 16:44:20 +0530 Subject: [PATCH 16/35] Added changes for the OTA 917 NCP --- src/platform/silabs/efr32/BUILD.gn | 4 ++-- src/platform/silabs/multi-ota/OTAHooks.cpp | 4 ++-- .../silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp | 2 ++ third_party/silabs/efr32_sdk.gni | 7 +++++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/platform/silabs/efr32/BUILD.gn b/src/platform/silabs/efr32/BUILD.gn index 19dba981cf4bd1..50c543f20f3ff6 100644 --- a/src/platform/silabs/efr32/BUILD.gn +++ b/src/platform/silabs/efr32/BUILD.gn @@ -107,8 +107,8 @@ static_library("efr32") { if (chip_enable_wifi) { sources += [ - "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.cpp", - "${silabs_platform_dir}/multi-ota/SiWx917/OTAFirmwareProcessor917.h", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp", + "${silabs_platform_dir}/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h", ] } } else if (chip_enable_ota_requestor) { diff --git a/src/platform/silabs/multi-ota/OTAHooks.cpp b/src/platform/silabs/multi-ota/OTAHooks.cpp index 72d1d744bd3c26..08e41c9283a050 100644 --- a/src/platform/silabs/multi-ota/OTAHooks.cpp +++ b/src/platform/silabs/multi-ota/OTAHooks.cpp @@ -42,8 +42,8 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor #endif #if SL_WIFI - auto desc = static_cast(descriptor); - ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", desc->version, desc->versionString, desc->buildDate); + auto descWiFi = static_cast(descriptor); + ChipLogDetail(SoftwareUpdate, "Descriptor: %ld, %s, %s", descWiFi->version, descWiFi->versionString, descWiFi->buildDate); #endif return CHIP_NO_ERROR; diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index 3aced5a87ffc71..f13d46a842c532 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -148,8 +148,10 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ApplyAction() ChipLogProgress(SoftwareUpdate, "M4 Firmware update complete"); // send system reset request to reset the MCU and upgrade the m4 image ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!"); +#ifdef SLI_SI91X_MCU_INTERFACE //only for SoC // Reboots the device sl_si91x_soc_soft_reset(); +#endif } ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Apply Action completed"); return CHIP_NO_ERROR; diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index a3188df040cfd4..432f2fd1343c58 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -882,6 +882,13 @@ template("efr32_sdk") { "${silabs_gen_folder}/autogen/sl_event_handler.c", "${silabs_gen_folder}/autogen/sl_iostream_handles.c", ] + + if (chip_enable_multi_ota_requestor && use_SiWx917) { + sources += [ + "${wifi_sdk_root}/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c", + ] + } + if (enable_dic) { sources += [ "${chip_root}/third_party/silabs/mqtt/stack/mqtt.c", From 14ed08eb35c8e511ea3c769dde2b78430a0c66c4 Mon Sep 17 00:00:00 2001 From: shgutte Date: Tue, 16 Apr 2024 16:46:31 +0530 Subject: [PATCH 17/35] Added changes for the OTA tlv From 479d2a2d6d7b84889aa6775e9aee6ae343ef3991 Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 17 Apr 2024 21:32:07 +0530 Subject: [PATCH 18/35] Added changes for the comment --- .../silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index f13d46a842c532..a5160a6881e1f3 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -162,11 +162,13 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::FinalizeAction() int32_t status = SL_STATUS_OK; ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Finalize Action started"); - // Pad the remainder of the write buffer with zeros and write it to bootloader storage + if (writeBufOffset != 0) { status = sl_si91x_fwup_load(writeBuffer, writeBufOffset); + + // Pad the remainder of the write buffer with zeros and write it to bootloader storage while (writeBufOffset != kAlignmentBytes) { writeBuffer[writeBufOffset] = 0; From 4cf6b091c7097d92836d18ca6e24a4942e63ed68 Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 17 Apr 2024 21:33:07 +0530 Subject: [PATCH 19/35] Added changes for the process block for WIfi --- .../SiWx917/OTAWiFiFirmwareProcessor.cpp | 62 ++++++++----------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index a5160a6881e1f3..ff1f2d3a68ff0a 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -40,14 +40,10 @@ extern "C" { #define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND uint8_t flag = RPS_HEADER; -// TODO: more descriptive error codes -#define SL_OTA_ERROR 1L - namespace chip { // Define static memebers bool OTAWiFiFirmwareProcessor::mReset = false; -uint32_t OTAWiFiFirmwareProcessor::mWriteOffset = 0; uint16_t OTAWiFiFirmwareProcessor::writeBufOffset = 0; uint8_t OTAWiFiFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; @@ -83,45 +79,39 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) } uint32_t blockReadOffset = 0; + while (blockReadOffset < block.size()) { - writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset); - writeBufOffset++; - blockReadOffset++; - if (writeBufOffset == kAlignmentBytes) + memcpy(&writeBuffer, block.data(), kAlignmentBytes); + blockReadOffset += kAlignmentBytes; + if (flag == RPS_HEADER) { - writeBufOffset = 0; - - if (flag == RPS_HEADER) - { - // Send RPS header which is received as first chunk - status = sl_si91x_fwup_start(writeBuffer); - status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); - flag = RPS_DATA; - } - else if (flag == RPS_DATA) + // Send RPS header which is received as first chunk + status = sl_si91x_fwup_start(writeBuffer); + status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); + flag = RPS_DATA; + } + else if (flag == RPS_DATA) + { + // Send RPS content + status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); + if (status != SL_STATUS_OK) { - // Send RPS content - status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); - if (status != SL_STATUS_OK) + // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value + // should be set to true in HandleProcessBlock + if (status == SL_STATUS_FW_UPDATE_DONE) + { + mReset = true; + } + else { - // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value - // should be set to true in HandleProcessBlock - if (status == SL_STATUS_FW_UPDATE_DONE) - { - mReset = true; - } - else - { - ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); - // TODO: add this somewhere - // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - // TODO: Replace CHIP_ERROR_CANCELLED with new error statement - return CHIP_ERROR_CANCELLED; - } + ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); + // TODO: add this somewhere + // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + // TODO: Replace CHIP_ERROR_CANCELLED with new error statement + return CHIP_ERROR_CANCELLED; } } - mWriteOffset += kAlignmentBytes; } } From 23cea7222b6b96758f1151f264cb90e17315261f Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 17 Apr 2024 21:34:06 +0530 Subject: [PATCH 20/35] Removed the mWriteOffset in firmware processor --- src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h index 82517a1130433e..9a194eda0a9978 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h @@ -39,7 +39,6 @@ class OTAWiFiFirmwareProcessor : public OTATlvProcessor CHIP_ERROR FinalizeAction() override; static bool mReset; static constexpr size_t kAlignmentBytes = 64; - static uint32_t mWriteOffset; // End of last written block // 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 From 47d37f09537ba7c0857427845e75e82c40bf6c68 Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 17 Apr 2024 21:34:40 +0530 Subject: [PATCH 21/35] Removed unessory comment --- src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index 36d9571619f38b..a7aeb8e08171e6 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -379,7 +379,6 @@ void OTAMultiImageProcessorImpl::HandleFinalize(intptr_t context) CHIP_ERROR OTAMultiImageProcessorImpl::ProcessFinalize() { - ChipLogProgress(SoftwareUpdate, "OTA MultiImage Processor Implementation"); for (auto const & pair : this->mProcessorMap) { pair.second->FinalizeAction(); From f9934daba32daeb3e997084db00616244371d6bb Mon Sep 17 00:00:00 2001 From: shgutte Date: Thu, 18 Apr 2024 01:58:04 +0530 Subject: [PATCH 22/35] Added changes for the ProcessInternal OTA WiFi --- .../SiWx917/OTAWiFiFirmwareProcessor.cpp | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index ff1f2d3a68ff0a..fb12a39f0a44b8 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -82,34 +82,40 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) while (blockReadOffset < block.size()) { - memcpy(&writeBuffer, block.data(), kAlignmentBytes); - blockReadOffset += kAlignmentBytes; - if (flag == RPS_HEADER) + writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset); + writeBufOffset++; + blockReadOffset++; + if (writeBufOffset == kAlignmentBytes) { - // Send RPS header which is received as first chunk - status = sl_si91x_fwup_start(writeBuffer); - status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); - flag = RPS_DATA; - } - else if (flag == RPS_DATA) - { - // Send RPS content - status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); - if (status != SL_STATUS_OK) + writeBufOffset = 0; + + if (flag == RPS_HEADER) { - // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value - // should be set to true in HandleProcessBlock - if (status == SL_STATUS_FW_UPDATE_DONE) - { - mReset = true; - } - else + // Send RPS header which is received as first chunk + status = sl_si91x_fwup_start(writeBuffer); + status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); + flag = RPS_DATA; + } + else if (flag == RPS_DATA) + { + // Send RPS content + status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); + if (status != SL_STATUS_OK) { - ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); - // TODO: add this somewhere - // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - // TODO: Replace CHIP_ERROR_CANCELLED with new error statement - return CHIP_ERROR_CANCELLED; + // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value + // should be set to true in HandleProcessBlock + if (status == SL_STATUS_FW_UPDATE_DONE) + { + mReset = true; + } + else + { + ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); + // TODO: add this somewhere + // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + // TODO: Replace CHIP_ERROR_CANCELLED with new error statement + return CHIP_ERROR_CANCELLED; + } } } } From 14bc689cfc3f4aeba254fe41fb8aef1565adc4d4 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 19 Apr 2024 18:11:51 +0530 Subject: [PATCH 23/35] Added changes for WiFi OTA processor --- .../SiWx917/OTAWiFiFirmwareProcessor.cpp | 63 +++++++++---------- .../SiWx917/OTAWiFiFirmwareProcessor.h | 4 +- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index fb12a39f0a44b8..c106d6cf66f2f8 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -40,12 +40,16 @@ extern "C" { #define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND uint8_t flag = RPS_HEADER; +// TODO: more descriptive error codes +#define SL_OTA_ERROR 1L + namespace chip { // Define static memebers bool OTAWiFiFirmwareProcessor::mReset = false; uint16_t OTAWiFiFirmwareProcessor::writeBufOffset = 0; uint8_t OTAWiFiFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; +uint8_t OTAWiFiFirmwareProcessor::writeDataBuffer[1024] __attribute__((aligned(4))) = { 0 }; CHIP_ERROR OTAWiFiFirmwareProcessor::Init() { @@ -78,45 +82,36 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) ReturnErrorOnFailure(ProcessDescriptor(block)); } - uint32_t blockReadOffset = 0; - - while (blockReadOffset < block.size()) + if (flag == RPS_HEADER) + { + memcpy(&writeBuffer, block.data(), kAlignmentBytes); + // Send RPS header which is received as first chunk + status = sl_si91x_fwup_start(writeBuffer); + status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); + flag = RPS_DATA; + memcpy(&writeDataBuffer, block.data() + kAlignmentBytes, (block.size() - kAlignmentBytes)); + status = sl_si91x_fwup_load(writeDataBuffer, (block.size() - kAlignmentBytes)); + } + else if (flag == RPS_DATA) { - writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset); - writeBufOffset++; - blockReadOffset++; - if (writeBufOffset == kAlignmentBytes) + memcpy(&writeDataBuffer, block.data(), block.size()); + // Send RPS content + status = sl_si91x_fwup_load(writeDataBuffer, block.size()); + if (status != SL_STATUS_OK) { - writeBufOffset = 0; - - if (flag == RPS_HEADER) + // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value + // should be set to true in HandleProcessBlock + if (status == SL_STATUS_FW_UPDATE_DONE) { - // Send RPS header which is received as first chunk - status = sl_si91x_fwup_start(writeBuffer); - status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); - flag = RPS_DATA; + mReset = true; } - else if (flag == RPS_DATA) + else { - // Send RPS content - status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes); - if (status != SL_STATUS_OK) - { - // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value - // should be set to true in HandleProcessBlock - if (status == SL_STATUS_FW_UPDATE_DONE) - { - mReset = true; - } - else - { - ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); - // TODO: add this somewhere - // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - // TODO: Replace CHIP_ERROR_CANCELLED with new error statement - return CHIP_ERROR_CANCELLED; - } - } + ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); + // TODO: add this somewhere + // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + // TODO: Replace CHIP_ERROR_CANCELLED with new error statement + return CHIP_ERROR_CANCELLED; } } } diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h index 9a194eda0a9978..d9d3440ab7b2b9 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h @@ -39,8 +39,10 @@ class OTAWiFiFirmwareProcessor : public OTATlvProcessor CHIP_ERROR FinalizeAction() override; static bool mReset; static constexpr size_t kAlignmentBytes = 64; - // Bootloader storage API requires the buffer size to be a multiple of 4. + // Store the header of the OTA file static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))); + // Used to tranfer other block to processor + static uint8_t writeDataBuffer[1024] __attribute__((aligned(4))); // Offset indicates how far the write buffer has been filled static uint16_t writeBufOffset; private: From d855d6418455aca45c6927c21697d42a904c0388 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 19 Apr 2024 18:34:29 +0530 Subject: [PATCH 24/35] Removed the unwanted line --- src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index a7aeb8e08171e6..f74c81900d56cf 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -64,7 +64,6 @@ void OTAMultiImageProcessorImpl::Clear() mParams.totalFileBytes = 0; mParams.downloadedBytes = 0; mCurrentProcessor = nullptr; - ReleaseBlock(); } From f799676f515b5035f9ef9e98a2e58730ac882963 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 19 Apr 2024 19:41:46 +0530 Subject: [PATCH 25/35] Cleanup of the code --- .../multi-ota/OTAMultiImageProcessorImpl.cpp | 7 +++ .../SiWx917/OTAWiFiFirmwareProcessor.cpp | 63 +++---------------- .../SiWx917/OTAWiFiFirmwareProcessor.h | 6 -- 3 files changed, 17 insertions(+), 59 deletions(-) diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index f74c81900d56cf..6d54780196e68a 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -41,7 +41,11 @@ extern "C" { #include "em_bus.h" // For CORE_CRITICAL_SECTION #ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP #include "spi_multiplex.h" +#include "btl_interface.h" #endif // SL_WIFI +#ifdef CHIP_9117 +#include "spi_multiplex.h" +#endif // CHIP_9117 } namespace chip { @@ -429,11 +433,14 @@ void OTAMultiImageProcessorImpl::HandleApply(intptr_t context) ChipLogProgress(SoftwareUpdate, "HandleApply: Finished"); +<<<<<<< HEAD <<<<<<< HEAD // This reboots the device ======= // TODO: check where to put this // ConfigurationManagerImpl().StoreSoftwareUpdateCompleted(); +======= +>>>>>>> 306094209f (Cleanup of the code) #ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP >>>>>>> ac92393594 (Added changes for the build errores) CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index c106d6cf66f2f8..c943f0ced85917 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -40,16 +40,10 @@ extern "C" { #define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND uint8_t flag = RPS_HEADER; -// TODO: more descriptive error codes -#define SL_OTA_ERROR 1L - namespace chip { // Define static memebers bool OTAWiFiFirmwareProcessor::mReset = false; -uint16_t OTAWiFiFirmwareProcessor::writeBufOffset = 0; -uint8_t OTAWiFiFirmwareProcessor::writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; -uint8_t OTAWiFiFirmwareProcessor::writeDataBuffer[1024] __attribute__((aligned(4))) = { 0 }; CHIP_ERROR OTAWiFiFirmwareProcessor::Init() { @@ -77,6 +71,11 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::Clear() CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) { int32_t status = SL_STATUS_OK; + // Store the header of the OTA file + static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 }; + // Used to tranfer other block to processor + static uint8_t writeDataBuffer[1024] __attribute__((aligned(4))) = { 0 }; + if (!mDescriptorProcessed) { ReturnErrorOnFailure(ProcessDescriptor(block)); @@ -99,8 +98,7 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) status = sl_si91x_fwup_load(writeDataBuffer, block.size()); if (status != SL_STATUS_OK) { - // If the last chunk of last block-writeBufOffset length is exactly kAlignmentBytes(64) bytes then mReset value - // should be set to true in HandleProcessBlock + // When TA recived all the blocks it will return SL_STATUS_FW_UPDATE_DONE status if (status == SL_STATUS_FW_UPDATE_DONE) { mReset = true; @@ -108,9 +106,6 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) else { ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock sl_si91x_fwup_load() error %ld", status); - // TODO: add this somewhere - // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - // TODO: Replace CHIP_ERROR_CANCELLED with new error statement return CHIP_ERROR_CANCELLED; } } @@ -132,62 +127,24 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessDescriptor(ByteSpan & block) CHIP_ERROR OTAWiFiFirmwareProcessor::ApplyAction() { - ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Apply Action started"); // This reboots the device if (mReset) { - ChipLogProgress(SoftwareUpdate, "M4 Firmware update complete"); + ChipLogProgress(SoftwareUpdate, "WiFi Device OTA update complete"); +#ifdef SLI_SI91X_MCU_INTERFACE //only for SoC // send system reset request to reset the MCU and upgrade the m4 image ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!"); -#ifdef SLI_SI91X_MCU_INTERFACE //only for SoC // Reboots the device sl_si91x_soc_soft_reset(); #endif } - ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Apply Action completed"); return CHIP_NO_ERROR; } CHIP_ERROR OTAWiFiFirmwareProcessor::FinalizeAction() { - int32_t status = SL_STATUS_OK; - ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Finalize Action started"); - - - if (writeBufOffset != 0) - { - - status = sl_si91x_fwup_load(writeBuffer, writeBufOffset); - - // Pad the remainder of the write buffer with zeros and write it to bootloader storage - while (writeBufOffset != kAlignmentBytes) - { - writeBuffer[writeBufOffset] = 0; - writeBufOffset++; - } - ChipLogProgress(SoftwareUpdate, "status: 0x%lX", status); - - if (status != SL_STATUS_OK) - { - if (status == SL_STATUS_FW_UPDATE_DONE) - { - mReset = true; - } - else - { - ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize for last chunk sl_si91x_fwup_load() error %ld", status); - - // TODO: add this somewhere - // imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - // TODO: Replace CHIP_ERROR_CANCELLED with new error statement - return CHIP_ERROR_CANCELLED; - } - } - - } - - ChipLogProgress(SoftwareUpdate, "OTA WiFi Firmware Finalize Action completed"); - return status ? CHIP_ERROR_CANCELLED : CHIP_NO_ERROR; + // TODO: Not requied by 917 OTA updated keeping this function to execute any other command before soft reset of the TA + return CHIP_NO_ERROR; } } // namespace chip diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h index d9d3440ab7b2b9..d74bda89631430 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h @@ -39,12 +39,6 @@ class OTAWiFiFirmwareProcessor : public OTATlvProcessor CHIP_ERROR FinalizeAction() override; static bool mReset; static constexpr size_t kAlignmentBytes = 64; - // Store the header of the OTA file - static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))); - // Used to tranfer other block to processor - static uint8_t writeDataBuffer[1024] __attribute__((aligned(4))); - // Offset indicates how far the write buffer has been filled - static uint16_t writeBufOffset; private: CHIP_ERROR ProcessInternal(ByteSpan & block) override; CHIP_ERROR ProcessDescriptor(ByteSpan & block); From 298adc87ecc8a8fddced2fb5c20b082f51a53b97 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 19 Apr 2024 19:53:36 +0530 Subject: [PATCH 26/35] Corrected #ifdef comments --- src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index 6d54780196e68a..69450dc4bb3a19 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -42,7 +42,7 @@ extern "C" { #ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP #include "spi_multiplex.h" #include "btl_interface.h" -#endif // SL_WIFI +#endif // SLI_SI91X_MCU_INTERFACE #ifdef CHIP_9117 #include "spi_multiplex.h" #endif // CHIP_9117 From a672c7b3ccb705f3d07b1895e883efdb46c45669 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 19 Apr 2024 19:56:23 +0530 Subject: [PATCH 27/35] Removed unwanted comment From ec02a693cb3a6c366e3d50f552965822686c6f60 Mon Sep 17 00:00:00 2001 From: shgutte Date: Fri, 19 Apr 2024 20:43:05 +0530 Subject: [PATCH 28/35] Added back the set_logger function --- scripts/tools/silabs/ota/ota_multi_image_tool.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/tools/silabs/ota/ota_multi_image_tool.py b/scripts/tools/silabs/ota/ota_multi_image_tool.py index 66c32592e48bdd..7c67f1cb239750 100755 --- a/scripts/tools/silabs/ota/ota_multi_image_tool.py +++ b/scripts/tools/silabs/ota/ota_multi_image_tool.py @@ -67,6 +67,14 @@ class TAG: WIFI_917_SOC_COMBINED = 5 WIFI_917_NCP_COMBINED = 6 +def set_logger(): + stdout_handler = logging.StreamHandler(stream=sys.stdout) + logging.basicConfig( + level=logging.DEBUG, + format='[%(levelname)s] %(message)s', + handlers=[stdout_handler] + ) + def write_to_temp(path: str, payload: bytearray): with open(path, "wb") as _handle: _handle.write(payload) From d09abe5904a4251785b8019df9555d54e116ea4b Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Fri, 19 Apr 2024 18:30:10 +0000 Subject: [PATCH 29/35] Applied suggestion --- src/platform/silabs/multi-ota/OTATlvProcessor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/multi-ota/OTATlvProcessor.h b/src/platform/silabs/multi-ota/OTATlvProcessor.h index 49829d32484e02..7b3014a86f4fb1 100644 --- a/src/platform/silabs/multi-ota/OTATlvProcessor.h +++ b/src/platform/silabs/multi-ota/OTATlvProcessor.h @@ -62,7 +62,7 @@ struct OTATlvHeader uint32_t length; }; -// TLV tags synced with ota files generate by scripts/tools/silabs/ota/ota_image_tool.py +// TLV tags synced with ota files generated by scripts/tools/silabs/ota/ota_image_tool.py enum class OTAProcessorTag { kApplicationProcessor = 1, From d76ef10895d284fac89a350d14ec9c98a1eec664 Mon Sep 17 00:00:00 2001 From: shgutte Date: Mon, 22 Apr 2024 16:22:58 +0530 Subject: [PATCH 30/35] Added changes realted to comment --- .../multi-ota/OTAMultiImageProcessorImpl.cpp | 2 -- third_party/silabs/efr32_sdk.gni | 20 ++++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index 69450dc4bb3a19..5f87c12a840f9c 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -444,8 +444,6 @@ void OTAMultiImageProcessorImpl::HandleApply(intptr_t context) #ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP >>>>>>> ac92393594 (Added changes for the build errores) CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) -#else - #endif } diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 432f2fd1343c58..9e1a8a8a4950ef 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -547,12 +547,14 @@ template("efr32_sdk") { ] } - if (chip_enable_multi_ota_encryption && chip_enable_multi_ota_requestor) { - defines += [ "SL_MATTER_ENABLE_OTA_ENCRYPTION=1" ] - } + if (chip_enable_multi_ota_requestor) { + if (chip_enable_multi_ota_encryption) { + defines += [ "OTA_ENCRYPTION_ENABLE=1" ] + } - if (chip_enable_ota_custom_tlv_testing && chip_enable_multi_ota_requestor) { - defines += [ "OTA_TEST_CUSTOM_TLVS=1" ] + if (chip_enable_ota_custom_tlv_testing) { + defines += [ "OTA_TEST_CUSTOM_TLVS=1" ] + } } if (defined(invoker.chip_enable_wifi) && invoker.chip_enable_wifi) { @@ -883,10 +885,10 @@ template("efr32_sdk") { "${silabs_gen_folder}/autogen/sl_iostream_handles.c", ] - if (chip_enable_multi_ota_requestor && use_SiWx917) { - sources += [ - "${wifi_sdk_root}/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c", - ] + if (chip_enable_multi_ota_requestor) { + if (use_SiWx917) { + sources += [ "${wifi_sdk_root}/components/device/silabs/si91x/wireless/firmware_upgrade/firmware_upgradation.c" ] + } } if (enable_dic) { From cae741aa197d556b52acc53bde42aa107433e993 Mon Sep 17 00:00:00 2001 From: shgutte Date: Mon, 22 Apr 2024 16:30:22 +0530 Subject: [PATCH 31/35] Discription for input command is updated --- scripts/tools/silabs/ota/ota_multi_image_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tools/silabs/ota/ota_multi_image_tool.py b/scripts/tools/silabs/ota/ota_multi_image_tool.py index 7c67f1cb239750..bdd53e64794ba3 100755 --- a/scripts/tools/silabs/ota/ota_multi_image_tool.py +++ b/scripts/tools/silabs/ota/ota_multi_image_tool.py @@ -344,7 +344,7 @@ def any_base_int(s): return int(s, 0) create_parser.add_argument('-app', "--app-input-file", help='Path to application input file') create_parser.add_argument('-wifi', "--wifi-input-file", - help='Path to 917 wifi OTA either TA, application o r combined input file') + help='Path to OTA image for SiWx917 (TA/M4/Combined file)') create_parser.add_argument('--app-version', type=any_base_int, help='Application Software version (numeric)') create_parser.add_argument('--app-version-str', type=str, From df781e74e6b20d766298c25a4dcd8cf759b5f327 Mon Sep 17 00:00:00 2001 From: shgutte Date: Wed, 24 Apr 2024 13:05:51 +0530 Subject: [PATCH 32/35] Added changes for build file of 917 SoC --- src/platform/silabs/SiWx917/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/silabs/SiWx917/BUILD.gn b/src/platform/silabs/SiWx917/BUILD.gn index 24f628e2d0bfcb..a19ca85492d22f 100644 --- a/src/platform/silabs/SiWx917/BUILD.gn +++ b/src/platform/silabs/SiWx917/BUILD.gn @@ -14,7 +14,6 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/platform/device.gni") -import("${chip_root}/third_party/silabs/efr32_sdk.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/crypto/crypto.gni") import("${chip_root}/src/platform/silabs/wifi/args.gni") From a3dd261ce210ef7b8ed716b559a787fc36be7e1e Mon Sep 17 00:00:00 2001 From: shgutte Date: Thu, 25 Apr 2024 04:33:54 +0530 Subject: [PATCH 33/35] Added changes for encryption --- .../SiWx917/OTAWiFiFirmwareProcessor.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index c943f0ced85917..59186d6a4deeb3 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -79,8 +79,35 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block) if (!mDescriptorProcessed) { ReturnErrorOnFailure(ProcessDescriptor(block)); +#if OTA_ENCRYPTION_ENABLE + /* 16 bytes to used to store undecrypted data because of unalignment */ + mAccumulator.Init(requestedOtaMaxBlockSize + 16); +#endif } +#if OTA_ENCRYPTION_ENABLE + MutableByteSpan mBlock = MutableByteSpan(mAccumulator.data(), mAccumulator.GetThreshold()); + memcpy(&mBlock[0], &mBlock[requestedOtaMaxBlockSize], mUnalignmentNum); + memcpy(&mBlock[mUnalignmentNum], block.data(), block.size()); + + if (mUnalignmentNum + block.size() < requestedOtaMaxBlockSize) + { + uint32_t mAlignmentNum = (mUnalignmentNum + block.size()) / 16; + mAlignmentNum = mAlignmentNum * 16; + mUnalignmentNum = (mUnalignmentNum + block.size()) % 16; + memcpy(&mBlock[requestedOtaMaxBlockSize], &mBlock[mAlignmentNum], mUnalignmentNum); + mBlock.reduce_size(mAlignmentNum); + } + else + { + mUnalignmentNum = mUnalignmentNum + block.size() - requestedOtaMaxBlockSize; + mBlock.reduce_size(requestedOtaMaxBlockSize); + } + + OTATlvProcessor::vOtaProcessInternalEncryption(mBlock); + block = mBlock; +#endif + if (flag == RPS_HEADER) { memcpy(&writeBuffer, block.data(), kAlignmentBytes); From 293f69c4ca774e2ba10f4ad3963116d3b16cd0a5 Mon Sep 17 00:00:00 2001 From: shgutte Date: Mon, 24 Feb 2025 12:50:11 +0530 Subject: [PATCH 34/35] Adds changes for the multi-ota updated --- examples/platform/silabs/SiWx917/BUILD.gn | 37 +------------------ .../multi-ota/OTAMultiImageProcessorImpl.cpp | 9 +---- .../SiWx917/OTAWiFiFirmwareProcessor.cpp | 7 ++-- 3 files changed, 6 insertions(+), 47 deletions(-) diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 65dbbc5694987e..66504e144c36e3 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -91,44 +91,11 @@ config("siwx917-common-config") { defines += [ "HEAP_MONITORING" ] } - ldflags = [ "-Wl,--no-warn-rwx-segment" ] -} - -config("silabs-wifi-config") { - defines = [] - include_dirs = [] - - if (chip_default_wifi_ssid != "") { - defines += [ - "SL_ONNETWORK_PAIRING=1", - "SL_WIFI_SSID=\"${chip_default_wifi_ssid}\"", - ] - } - if (chip_default_wifi_psk != "") { - assert(chip_default_wifi_ssid != "", - "ssid can't be null if psk is provided") - defines += [ "SL_WIFI_PSK=\"${chip_default_wifi_psk}\"" ] - } - - if (sl_wfx_config_softap) { - defines += [ "SL_WFX_CONFIG_SOFTAP" ] - } - - if (sl_wfx_config_scan) { - defines += [ "SL_WFX_CONFIG_SCAN" ] - } - - if (chip_enable_wifi_ipv4) { - defines += [ "CHIP_DEVICE_CONFIG_ENABLE_IPV4" ] - } - - if (rs91x_wpa3_transition) { - defines += [ "WIFI_ENABLE_SECURITY_WPA3_TRANSITION=1" ] - } - if (chip_enable_multi_ota_requestor) { defines += [ "CHIP_DEVICE_CONFIG_ENABLE_MULTI_OTA_REQUESTOR=1" ] } + + ldflags = [ "-Wl,--no-warn-rwx-segment" ] } source_set("siwx917-common") { diff --git a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp index 5f87c12a840f9c..af73f924876fdc 100644 --- a/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp +++ b/src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp @@ -432,19 +432,12 @@ void OTAMultiImageProcessorImpl::HandleApply(intptr_t context) imageProcessor->mAccumulator.Clear(); ChipLogProgress(SoftwareUpdate, "HandleApply: Finished"); - -<<<<<<< HEAD -<<<<<<< HEAD // This reboots the device -======= // TODO: check where to put this - // ConfigurationManagerImpl().StoreSoftwareUpdateCompleted(); -======= ->>>>>>> 306094209f (Cleanup of the code) #ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP ->>>>>>> ac92393594 (Added changes for the build errores) CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();) #endif + // ConfigurationManagerImpl().StoreSoftwareUpdateCompleted(); } CHIP_ERROR OTAMultiImageProcessorImpl::ReleaseBlock() diff --git a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp index 59186d6a4deeb3..90b25796c5a36f 100644 --- a/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp +++ b/src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp @@ -21,7 +21,6 @@ #include #include -#include "wfx_host_events.h" #include #ifdef __cplusplus extern "C" { @@ -37,7 +36,7 @@ extern "C" { #define RPS_HEADER 1 #define RPS_DATA 2 -#define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND +#define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_FW_UPDATE_DONE uint8_t flag = RPS_HEADER; namespace chip { @@ -47,7 +46,7 @@ bool OTAWiFiFirmwareProcessor::mReset CHIP_ERROR OTAWiFiFirmwareProcessor::Init() { - ReturnErrorCodeIf(mCallbackProcessDescriptor == nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED); + VerifyOrReturnError(mCallbackProcessDescriptor != nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED); mAccumulator.Init(sizeof(Descriptor)); #if OTA_ENCRYPTION_ENABLE mUnalignmentNum = 0; @@ -162,7 +161,7 @@ CHIP_ERROR OTAWiFiFirmwareProcessor::ApplyAction() // send system reset request to reset the MCU and upgrade the m4 image ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!"); // Reboots the device - sl_si91x_soc_soft_reset(); + sl_si91x_soc_nvic_reset(); #endif } return CHIP_NO_ERROR; From 66e2d0cf867f1805123878b00792dbd30351bcad Mon Sep 17 00:00:00 2001 From: shgutte Date: Mon, 24 Feb 2025 13:15:13 +0530 Subject: [PATCH 35/35] Adds changes for the customProcessor --- src/platform/silabs/multi-ota/OTAHooks.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/platform/silabs/multi-ota/OTAHooks.cpp b/src/platform/silabs/multi-ota/OTAHooks.cpp index 08e41c9283a050..d7cd511fa1ec91 100644 --- a/src/platform/silabs/multi-ota/OTAHooks.cpp +++ b/src/platform/silabs/multi-ota/OTAHooks.cpp @@ -69,15 +69,9 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit() customProcessor2.RegisterDescriptorCallback(ProcessDescriptor); customProcessor3.RegisterDescriptorCallback(ProcessDescriptor); -<<<<<<< HEAD ReturnErrorOnFailure(imageProcessor.RegisterProcessor(8, &customProcessor1)); ReturnErrorOnFailure(imageProcessor.RegisterProcessor(9, &customProcessor2)); ReturnErrorOnFailure(imageProcessor.RegisterProcessor(10, &customProcessor3)); -======= - ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kCustomProcessor1), &customProcessor1)); - ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kCustomProcessor2), &customProcessor2)); - ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast(OTAProcessorTag::kCustomProcessor3), &customProcessor3)); ->>>>>>> d7d9418cbb (Added changes for builkd issue with EFR32 multi OTA) #endif #ifdef SL_WIFI