From 230085544c7ac7c27a4e4732cf718819dcbd1e9c Mon Sep 17 00:00:00 2001 From: stoneM2017 Date: Tue, 16 Aug 2022 10:51:40 +0800 Subject: [PATCH] [BL602]fix problems to generate the OTA StateTransition and VersionApplied event (#21875) * [BL602]fix problems to generate the OTA StateTransition and VersionApplied event * Restyled by clang-format Co-authored-by: Restyled.io --- .../BL602/OTAImageProcessorImpl.cpp | 44 ++++++++++++++++++- .../bouffalolab/BL602/OTAImageProcessorImpl.h | 4 +- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp index 5d014eea06216d..6a94570ac2abb5 100644 --- a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp +++ b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp @@ -17,6 +17,7 @@ */ #include +#include #include "OTAImageProcessorImpl.h" extern "C" { @@ -24,8 +25,43 @@ extern "C" { #include } +using namespace chip::System; +using namespace ::chip::DeviceLayer::Internal; + namespace chip { +bool OTAImageProcessorImpl::IsFirstImageRun() +{ + OTARequestorInterface * requestor = chip::GetRequestorInstance(); + if (requestor == nullptr) + { + return false; + } + + return requestor->GetCurrentUpdateState() == OTARequestorInterface::OTAUpdateStateEnum::kApplying; +} + +CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage() +{ + OTARequestorInterface * requestor = chip::GetRequestorInstance(); + if (requestor == nullptr) + { + return CHIP_ERROR_INTERNAL; + } + + uint32_t currentVersion; + uint32_t targetVersion = requestor->GetTargetVersion(); + ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(currentVersion)); + if (currentVersion != targetVersion) + { + ChipLogError(SoftwareUpdate, "Current software version = %" PRIu32 ", expected software version = %" PRIu32, currentVersion, + targetVersion); + return CHIP_ERROR_INCORRECT_STATE; + } + + return CHIP_NO_ERROR; +} + CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() { DeviceLayer::PlatformMgr().ScheduleWork(HandlePrepareDownload, reinterpret_cast(this)); @@ -121,7 +157,13 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context) return; } - hal_reboot(); + DeviceLayer::SystemLayer().StartTimer( + System::Clock::Seconds32(2), + [](Layer *, void *) { + ChipLogProgress(SoftwareUpdate, "Rebooting..."); + hal_reboot(); + }, + nullptr); } void OTAImageProcessorImpl::HandleAbort(intptr_t context) diff --git a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.h b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.h index 6ecf3e43c778c4..c2cd9fa5607d9f 100644 --- a/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.h +++ b/src/platform/bouffalolab/BL602/OTAImageProcessorImpl.h @@ -34,8 +34,8 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface CHIP_ERROR Apply() override; CHIP_ERROR Abort() override; CHIP_ERROR ProcessBlock(ByteSpan & block) override; - bool IsFirstImageRun() override { return false; } - CHIP_ERROR ConfirmCurrentImage() override { return CHIP_NO_ERROR; } + bool IsFirstImageRun() override; + CHIP_ERROR ConfirmCurrentImage() override; void SetOTADownloader(OTADownloader * downloader) { mDownloader = downloader; }