Skip to content

Commit

Permalink
[Ameba] NotifyUpdateApplied sent after rebooting into new OTA image (#…
Browse files Browse the repository at this point in the history
…18079)

* [OTA] NotifyUpdateApplied to be sent after device first reboot into new image
- Added IsFirstRun and ConfirmCurrentImage checks
- Currently added delay of 15seconds in example_matter to give time for
  ameba to obtain ipv6 address
- TODO: Need to move wlan fast connect into matter using DCT

* Restyled by clang-format

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Aug 24, 2023
1 parent ff999c2 commit 3114537
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
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

0 comments on commit 3114537

Please sign in to comment.