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

Add OTA state changes to nordic OTAImageProcessorImpl #24815

Merged
merged 3 commits into from
Feb 23, 2023
Merged
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
26 changes: 23 additions & 3 deletions src/platform/nrfconnect/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,28 @@
#include <zephyr/logging/log.h>
#include <zephyr/pm/device.h>

namespace chip {
namespace {
#if CONFIG_CHIP_CERTIFICATION_DECLARATION_STORAGE
// Cd globals are needed to be accessed from dfu image writer lambdas
namespace {
uint8_t sCdBuf[chip::Credentials::kMaxCMSSignedCDMessage] = { 0 };
size_t sCdSavedBytes = 0;
} // namespace
#endif

namespace chip {
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 @@ -92,11 +105,13 @@ CHIP_ERROR OTAImageProcessorImpl::PrepareDownloadImpl()
ReturnErrorOnFailure(System::MapErrorZephyr(dfu_multi_image_register_writer(&cdWriter)));
#endif

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

CHIP_ERROR OTAImageProcessorImpl::Finalize()
{
PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadComplete);
return System::MapErrorZephyr(dfu_multi_image_done(true));
}

Expand All @@ -105,12 +120,14 @@ CHIP_ERROR OTAImageProcessorImpl::Abort()
CHIP_ERROR error = System::MapErrorZephyr(dfu_multi_image_done(false));

TriggerFlashAction(ExternalFlashManager::Action::SLEEP);
PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadAborted);

return error;
}

CHIP_ERROR OTAImageProcessorImpl::Apply()
{
PostOTAStateChangeEvent(DeviceLayer::kOtaApplyInProgress);
// Schedule update of all images
int err = dfu_target_schedule_update(-1);

Expand All @@ -130,6 +147,7 @@ CHIP_ERROR OTAImageProcessorImpl::Apply()
}
else
{
PostOTAStateChangeEvent(DeviceLayer::kOtaApplyFailed);
return System::MapErrorZephyr(err);
}
#else
Expand Down Expand Up @@ -161,6 +179,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & aBlock)
else
{
mDownloader->EndDownload(error);
PostOTAStateChangeEvent(DeviceLayer::kOtaDownloadFailed);
}
});
}
Expand All @@ -179,6 +198,7 @@ bool OTAImageProcessorImpl::IsFirstImageRun()

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

Expand Down