Skip to content

Commit

Permalink
[BL602]fix problems to generate the OTA StateTransition and VersionAp…
Browse files Browse the repository at this point in the history
…plied event (#21875)

* [BL602]fix problems to generate the OTA StateTransition and VersionApplied event

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Oct 17, 2022
1 parent b39e5b3 commit 2300855
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
44 changes: 43 additions & 1 deletion src/platform/bouffalolab/BL602/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,51 @@
*/

#include <app/clusters/ota-requestor/OTADownloader.h>
#include <app/clusters/ota-requestor/OTARequestorInterface.h>

#include "OTAImageProcessorImpl.h"
extern "C" {
#include <hal_sys.h>
#include <hosal_ota.h>
}

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<intptr_t>(this));
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/platform/bouffalolab/BL602/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down

0 comments on commit 2300855

Please sign in to comment.