Skip to content

Commit

Permalink
[EFR32] [sve-cherry-pick] Force key value store to save pending keys …
Browse files Browse the repository at this point in the history
…before reboot (project-chip#20506)

* Test added march 8 (project-chip#15957)

* Added new manual scripts

* Added Auto generated File

* [OTA] Fix OTARequestorDriverImpl inclusion (project-chip#15981)

* Regen to fix CI failures (project-chip#15990)

* [ota] Store Default OTA Providers in flash (project-chip#15970)

* [ota] Store Default OTA Providers in flash

Store Default OTA Providers in flash each time the attribute
is modified and load it back on the application startup.

* Restyled by clang-format

* Fix build and reduce flash usage

Co-authored-by: Restyled.io <[email protected]>

* Force EFR32 key value store to save pending keys before reboot

* Remove merge artifacts

* Restyled by clang-format

Co-authored-by: kowsisoundhar12 <[email protected]>
Co-authored-by: Carol Yang <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Damian Królik <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
6 people authored Jul 9, 2022
1 parent b8b5ced commit a3536cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/platform/EFR32/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ CHIP_ERROR KeyValueStoreManagerImpl::MapKvsKeyToNvm3(const char * key, uint32_t
return err;
}

void KeyValueStoreManagerImpl::ForceKeyMapSave()
{
OnScheduledKeyMapSave(nullptr, nullptr);
}

void KeyValueStoreManagerImpl::OnScheduledKeyMapSave(System::Layer * systemLayer, void * appState)
{
EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_KvsStringKeyMap,
Expand Down
3 changes: 3 additions & 0 deletions src/platform/EFR32/KeyValueStoreManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager

static constexpr size_t kMaxEntries = KVS_MAX_ENTRIES;

static void ForceKeyMapSave();

private:
static void OnScheduledKeyMapSave(System::Layer * systemLayer, void * appState);

void ScheduleKeyMapSave(void);
bool IsValidKvsNvm3Key(const uint32_t nvm3Key) const;
CHIP_ERROR MapKvsKeyToNvm3(const char * key, uint32_t & nvm3Key, bool isSlotNeeded = false) const;
Expand Down
13 changes: 7 additions & 6 deletions src/platform/EFR32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()
}
CHIP_ERROR OTAImageProcessorImpl::Apply()
{
// Delay HandleApply() to give KVS time to store the data in StoreCurrentUpdateInfo()
ChipLogError(SoftwareUpdate, "Scheduling HandleApply");
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(EFR32_KVS_SAVE_DELAY_SECONDS + 1), HandleApply,
nullptr);
DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -180,24 +177,28 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
}

void OTAImageProcessorImpl::HandleApply(chip::System::Layer * systemLayer, void * context)
void OTAImageProcessorImpl::HandleApply(intptr_t context)
{
uint32_t err = SL_BOOTLOADER_OK;

ChipLogProgress(SoftwareUpdate, "OTAImageProcessorImpl::HandleApply()");

CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);)
// Force KVS to store pending keys such as data from StoreCurrentUpdateInfo()
chip::DeviceLayer::PersistedStorage::KeyValueStoreMgrImpl().ForceKeyMapSave();

CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);)
if (err != SL_BOOTLOADER_OK)
{
ChipLogError(SoftwareUpdate, "ERROR: bootloader_verifyImage() error %ld", err);

return;
}

CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);)
if (err != SL_BOOTLOADER_OK)
{
ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err);

return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/EFR32/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
//////////// Actual handlers for the OTAImageProcessorInterface ///////////////
static void HandlePrepareDownload(intptr_t context);
static void HandleFinalize(intptr_t context);
static void HandleApply(chip::System::Layer * systemLayer, void *);
static void HandleApply(intptr_t context);
static void HandleAbort(intptr_t context);
static void HandleProcessBlock(intptr_t context);
CHIP_ERROR ProcessHeader(ByteSpan & block);
Expand Down

0 comments on commit a3536cb

Please sign in to comment.