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

[Ameba] NotifyUpdateApplied sent after rebooting into new OTA image #18079

Merged
merged 2 commits into from
May 10, 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
47 changes: 39 additions & 8 deletions src/platform/Ameba/AmebaOTAImageProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ CHIP_ERROR AmebaOTAImageProcessor::ProcessBlock(ByteSpan & block)
return CHIP_NO_ERROR;
}

bool AmebaOTAImageProcessor::IsFirstImageRun()
{
OTARequestorInterface * requestor = chip::GetRequestorInstance();
if (requestor == nullptr)
{
return false;
}

return requestor->GetCurrentUpdateState() == OTARequestorInterface::OTAUpdateStateEnum::kApplying;
}

CHIP_ERROR AmebaOTAImageProcessor::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;
}

void AmebaOTAImageProcessor::HandlePrepareDownload(intptr_t context)
{
auto * imageProcessor = reinterpret_cast<AmebaOTAImageProcessor *>(context);
Expand Down Expand Up @@ -371,15 +403,14 @@ void AmebaOTAImageProcessor::HandleApply(intptr_t context)
return;
}

OTARequestorInterface * requestor = chip::GetRequestorInstance();
if (requestor != nullptr)
{
// TODO: Implement restarting into new image instead of changing the version
DeviceLayer::ConfigurationMgr().StoreSoftwareVersion(imageProcessor->mSoftwareVersion);
requestor->NotifyUpdateApplied();
}
ChipLogProgress(SoftwareUpdate, "Rebooting in 2 seconds...");

// Reboot
// Delay action time before calling HandleRestart
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Milliseconds32(2 * 1000), HandleRestart, nullptr);
}

void AmebaOTAImageProcessor::HandleRestart(chip::System::Layer * systemLayer, void * appState)
{
ota_platform_reset();
}

Expand Down
5 changes: 3 additions & 2 deletions src/platform/Ameba/AmebaOTAImageProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class AmebaOTAImageProcessor : 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; }

private:
Expand All @@ -55,6 +55,7 @@ class AmebaOTAImageProcessor : public OTAImageProcessorInterface
static void HandleAbort(intptr_t context);
static void HandleProcessBlock(intptr_t context);
static void HandleApply(intptr_t context);
static void HandleRestart(chip::System::Layer * systemLayer, void * appState);

CHIP_ERROR ProcessHeader(ByteSpan & block);

Expand Down
12 changes: 6 additions & 6 deletions src/platform/Ameba/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
public:
// This returns an instance of this class.
static ConfigurationManagerImpl & GetDefaultInstance();
CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override;
CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override;
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
CHIP_ERROR GetBootReason(uint32_t & bootReason) override;
CHIP_ERROR StoreBootReason(uint32_t bootReason) override;

private:
// ===== Members that implement the ConfigurationManager public interface.
Expand All @@ -49,12 +55,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
void InitiateFactoryReset(void) override;
CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) override;
CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) override;
CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override;
CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override;
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
CHIP_ERROR GetBootReason(uint32_t & bootReason) override;
CHIP_ERROR StoreBootReason(uint32_t bootReason) override;
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
// NOTE: Other public interface methods are implemented by GenericConfigurationManagerImpl<>.

Expand Down