From a5eb912ded25cc2599847a365f4eeefc9c30f46c Mon Sep 17 00:00:00 2001 From: kirankha Date: Tue, 19 Dec 2023 10:25:34 +0530 Subject: [PATCH] Added fix for NotifyupdateApplied command and TA alone image upgrade reset issue --- src/platform/silabs/OTAImageProcessorImpl.h | 3 +- .../silabs/SiWx917/OTAImageProcessorImpl.cpp | 41 +++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/platform/silabs/OTAImageProcessorImpl.h b/src/platform/silabs/OTAImageProcessorImpl.h index 30709bd7f32f3a..d54c17a031d540 100644 --- a/src/platform/silabs/OTAImageProcessorImpl.h +++ b/src/platform/silabs/OTAImageProcessorImpl.h @@ -75,6 +75,7 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))); // Offset indicates how far the write buffer has been filled static uint16_t writeBufOffset; + static bool mReset; }; -} // namespace chip +} // namespace chip \ No newline at end of file diff --git a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp index b6e3f6bc00eb34..30d78a4b8b9472 100644 --- a/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp +++ b/src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp @@ -37,12 +37,13 @@ extern "C" { #define RPS_DATA 2 /// No error, operation OK #define SL_BOOTLOADER_OK 0L -#define SL_STATUS_FW_UPDATE_DONE ((sl_status_t) 0x10003) +#define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND uint8_t flag = RPS_HEADER; namespace chip { // Define static memebers +bool OTAImageProcessorImpl::mReset = false; uint8_t OTAImageProcessorImpl::mSlotId = 0; uint32_t OTAImageProcessorImpl::mWriteOffset = 0; uint16_t OTAImageProcessorImpl::writeBufOffset = 0; @@ -139,6 +140,7 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload"); + mReset = false; mSlotId = 0; // Single slot until we support multiple images writeBufOffset = 0; mWriteOffset = 0; @@ -167,14 +169,11 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) status = sl_si91x_fwup_load(writeBuffer, writeBufOffset); ChipLogProgress(SoftwareUpdate, "status: 0x%lX", status); - if (status != 0) + if (status != SL_STATUS_OK) { if (status == SL_STATUS_FW_UPDATE_DONE) { - 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!"); - sl_si91x_soc_soft_reset(); + mReset = true; } else { @@ -185,7 +184,8 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) } } imageProcessor->ReleaseBlock(); - ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully in HandleFinalize"); + + ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully"); } void OTAImageProcessorImpl::HandleApply(intptr_t context) @@ -198,6 +198,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave(); ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully in HandleApply"); + + 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(); + } } void OTAImageProcessorImpl::HandleAbort(intptr_t context) @@ -242,7 +251,6 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) // Copy data into the word-aligned writeBuffer, once it fills write its contents to the bootloader storage // Final data block is handled in HandleFinalize(). uint32_t blockReadOffset = 0; - while (blockReadOffset < block.size()) { writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset); @@ -262,7 +270,22 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) { // 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 HandleFinalize for last chunk rsi_fwup() error %ld", status); + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + return; + } + } } + // ChipLogProgress(SoftwareUpdate, "HandleProcessBlock status: 0x%lX", status); imageProcessor->mParams.downloadedBytes += kAlignmentBytes; } } @@ -331,4 +354,4 @@ CHIP_ERROR OTAImageProcessorImpl::ReleaseBlock() return CHIP_NO_ERROR; } -} // namespace chip +} // namespace chip \ No newline at end of file