Skip to content

Commit a3536cb

Browse files
selissiakowsisoundhar12carol-applebzbarsky-appleDamian-Nordic
authored
[EFR32] [sve-cherry-pick] Force key value store to save pending keys before reboot (#20506)
* Test added march 8 (#15957) * Added new manual scripts * Added Auto generated File * [OTA] Fix OTARequestorDriverImpl inclusion (#15981) * Regen to fix CI failures (#15990) * [ota] Store Default OTA Providers in flash (#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 <commits@restyled.io> * Force EFR32 key value store to save pending keys before reboot * Remove merge artifacts * Restyled by clang-format Co-authored-by: kowsisoundhar12 <57476670+kowsisoundhar12@users.noreply.github.com> Co-authored-by: Carol Yang <clyang@apple.com> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> Co-authored-by: Damian Królik <66667989+Damian-Nordic@users.noreply.github.com> Co-authored-by: Restyled.io <commits@restyled.io>
1 parent b8b5ced commit a3536cb

4 files changed

+16
-7
lines changed

src/platform/EFR32/KeyValueStoreManagerImpl.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ CHIP_ERROR KeyValueStoreManagerImpl::MapKvsKeyToNvm3(const char * key, uint32_t
105105
return err;
106106
}
107107

108+
void KeyValueStoreManagerImpl::ForceKeyMapSave()
109+
{
110+
OnScheduledKeyMapSave(nullptr, nullptr);
111+
}
112+
108113
void KeyValueStoreManagerImpl::OnScheduledKeyMapSave(System::Layer * systemLayer, void * appState)
109114
{
110115
EFR32Config::WriteConfigValueBin(EFR32Config::kConfigKey_KvsStringKeyMap,

src/platform/EFR32/KeyValueStoreManagerImpl.h

+3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager
4646

4747
static constexpr size_t kMaxEntries = KVS_MAX_ENTRIES;
4848

49+
static void ForceKeyMapSave();
50+
4951
private:
5052
static void OnScheduledKeyMapSave(System::Layer * systemLayer, void * appState);
53+
5154
void ScheduleKeyMapSave(void);
5255
bool IsValidKvsNvm3Key(const uint32_t nvm3Key) const;
5356
CHIP_ERROR MapKvsKeyToNvm3(const char * key, uint32_t & nvm3Key, bool isSlotNeeded = false) const;

src/platform/EFR32/OTAImageProcessorImpl.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()
5151
}
5252
CHIP_ERROR OTAImageProcessorImpl::Apply()
5353
{
54-
// Delay HandleApply() to give KVS time to store the data in StoreCurrentUpdateInfo()
55-
ChipLogError(SoftwareUpdate, "Scheduling HandleApply");
56-
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds32(EFR32_KVS_SAVE_DELAY_SECONDS + 1), HandleApply,
57-
nullptr);
54+
DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
5855
return CHIP_NO_ERROR;
5956
}
6057

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

183-
void OTAImageProcessorImpl::HandleApply(chip::System::Layer * systemLayer, void * context)
180+
void OTAImageProcessorImpl::HandleApply(intptr_t context)
184181
{
185182
uint32_t err = SL_BOOTLOADER_OK;
186183

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

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

189+
CORE_CRITICAL_SECTION(err = bootloader_verifyImage(mSlotId, NULL);)
191190
if (err != SL_BOOTLOADER_OK)
192191
{
193192
ChipLogError(SoftwareUpdate, "ERROR: bootloader_verifyImage() error %ld", err);
193+
194194
return;
195195
}
196196

197197
CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);)
198198
if (err != SL_BOOTLOADER_OK)
199199
{
200200
ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err);
201+
201202
return;
202203
}
203204

src/platform/EFR32/OTAImageProcessorImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
4646
//////////// Actual handlers for the OTAImageProcessorInterface ///////////////
4747
static void HandlePrepareDownload(intptr_t context);
4848
static void HandleFinalize(intptr_t context);
49-
static void HandleApply(chip::System::Layer * systemLayer, void *);
49+
static void HandleApply(intptr_t context);
5050
static void HandleAbort(intptr_t context);
5151
static void HandleProcessBlock(intptr_t context);
5252
CHIP_ERROR ProcessHeader(ByteSpan & block);

0 commit comments

Comments
 (0)