Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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