Skip to content

Commit

Permalink
riscv: telink: add ota event. (#35118)
Browse files Browse the repository at this point in the history
- add all the ota event in ota impl.

Signed-off-by: Haiwen Xia <[email protected]>
Co-authored-by: Haiwen Xia <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 4, 2024
1 parent 30e02a1 commit 1702945
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/platform/telink/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@
static struct stream_flash_ctx stream;

namespace chip {
namespace {

void PostOTAStateChangeEvent(DeviceLayer::OtaState newState)
{
DeviceLayer::ChipDeviceEvent otaChange;
otaChange.Type = DeviceLayer::DeviceEventType::kOtaStateChanged;
otaChange.OtaStateChanged.newState = newState;
CHIP_ERROR error = DeviceLayer::PlatformMgr().PostEvent(&otaChange);

if (error != CHIP_NO_ERROR)
{
ChipLogError(SoftwareUpdate, "Error while posting OtaChange event %" CHIP_ERROR_FORMAT, error.Format());
}
}
} // namespace

namespace DeviceLayer {

CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
Expand Down Expand Up @@ -60,6 +76,7 @@ CHIP_ERROR OTAImageProcessorImpl::PrepareDownloadImpl()
ChipLogError(SoftwareUpdate, "stream_flash_init failed (err %d)", err);
}

PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadInProgress);
return System::MapErrorZephyr(err);
}

Expand All @@ -72,13 +89,14 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()
ChipLogError(SoftwareUpdate, "stream_flash_buffered_write failed (err %d)", err);
}

PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadComplete);
return System::MapErrorZephyr(err);
}

CHIP_ERROR OTAImageProcessorImpl::Abort()
{
ChipLogError(SoftwareUpdate, "Image upgrade aborted");

PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadAborted);
return CHIP_NO_ERROR;
}

Expand All @@ -87,6 +105,7 @@ CHIP_ERROR OTAImageProcessorImpl::Apply()
// Schedule update of image
int err = boot_request_upgrade(BOOT_UPGRADE_PERMANENT);

PostOTAStateChangeEvent(DeviceLayer::kOtaApplyInProgress);
#ifdef CONFIG_CHIP_OTA_REQUESTOR_REBOOT_ON_APPLY
if (!err)
{
Expand All @@ -101,6 +120,7 @@ CHIP_ERROR OTAImageProcessorImpl::Apply()
}
else
{
PostOTAStateChangeEvent(DeviceLayer::kOtaApplyFailed);
return System::MapErrorZephyr(err);
}
#else
Expand Down Expand Up @@ -131,6 +151,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock)
else
{
mDownloader->EndDownload(error);
PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadFailed);
}
});
}
Expand All @@ -149,6 +170,7 @@ bool OTAImageProcessorImpl::IsFirstImageRun()

CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage()
{
PostOTAStateChangeEvent(DeviceLayer::kOtaApplyComplete);
return System::MapErrorZephyr(boot_write_img_confirmed());
}

Expand Down

0 comments on commit 1702945

Please sign in to comment.