Skip to content

Commit 8a872fd

Browse files
selissiakowsisoundhar12carol-applebzbarsky-appleDamian-Nordic
authored
[EFR32] Implement methods for NotifyUpdateApplied after an OTA update (#18584)
* 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> * Changes for transmitting UpdateApplied for EFR32 * Delay HandleApply by EFR32_KVS_SAVE_DELAY_SECONDS + 1 Delay HandleApply() to give KVS time to store the data in StoreCurrentUpdateInfo(). Introduce EFR32_KVS_SAVE_DELAY_SECONDS to represent the delay amount KeyValueStoreManagerImpl uses before saving the key/vaule pair * 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 81ed47c commit 8a872fd

File tree

5 files changed

+72
-7
lines changed

5 files changed

+72
-7
lines changed

examples/platform/efr32/OTAConfig.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
#include "platform/bootloader/api/application_properties.h"
2222
#include <app/server/Server.h>
2323

24+
#define BOOTLOADER_SUPPORT_CERTIFICATES 1
25+
#define APPLICATION_CERTIFICATE_VERSION (1UL)
26+
27+
#if defined(BOOTLOADER_SUPPORT_CERTIFICATES)
28+
const ApplicationCertificate_t sl_app_certificate = {
29+
.structVersion = APPLICATION_CERTIFICATE_VERSION,
30+
.flags = { 0U },
31+
.key = { 0U },
32+
.version = 0,
33+
.signature = { 0U },
34+
};
35+
#endif
36+
2437
// Header used for building the image GBL file
2538
#define APP_PROPERTIES_VERSION 1
2639
#define APP_PROPERTIES_ID \
@@ -58,6 +71,16 @@ __attribute__((used)) ApplicationProperties_t sl_app_properties = {
5871
/// Unique ID (e.g. UUID/GUID) for the product this application is built for
5972
.productId = APP_PROPERTIES_ID,
6073
},
74+
#if defined(BOOTLOADER_SUPPORT_CERTIFICATES)
75+
// If certificate based boot chain is enabled, the bootloader binary will be provided with
76+
// a certificate that does not contain any key.
77+
// A valid certificate needs to be injected to the bootloader images using Simplicity Commander.
78+
// Simplicity Commander will replace this certificate.
79+
.cert = (ApplicationCertificate_t *)&sl_app_certificate,
80+
#else
81+
.cert = NULL,
82+
#endif
83+
.longTokenSectionAddress = NULL,
6184
};
6285

6386
// Global OTA objects

src/platform/EFR32/EFR32Config.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#define KVS_MAX_ENTRIES 75 // Available key slot count for Kvs Key mapping.
3636
#endif
3737

38+
// Delay before Key/Value is actually saved in NVM
39+
#define EFR32_KVS_SAVE_DELAY_SECONDS 5
40+
3841
static_assert((KVS_MAX_ENTRIES <= 255), "Implementation supports up to 255 Kvs entries");
3942
static_assert((KVS_MAX_ENTRIES >= 30), "Mininimal Kvs entries requirement is not met");
4043

src/platform/EFR32/KeyValueStoreManagerImpl.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void)
117117
During commissioning, the key map will be modified multiples times subsequently.
118118
Commit the key map in nvm once it as stabilized.
119119
*/
120-
SystemLayer().StartTimer(std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(5)),
121-
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
120+
SystemLayer().StartTimer(
121+
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(EFR32_KVS_SAVE_DELAY_SECONDS)),
122+
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
122123
}
123124

124125
CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size,

src/platform/EFR32/OTAImageProcessorImpl.cpp

+40-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
#include "OTAImageProcessorImpl.h"
2020
#include <app/clusters/ota-requestor/OTADownloader.h>
21+
#include <app/clusters/ota-requestor/OTARequestorInterface.h>
2122

2223
extern "C" {
2324
#include "platform/bootloader/api/btl_interface.h"
2425
#include "platform/emlib/inc/em_bus.h" // For CORE_CRITICAL_SECTION
2526
}
2627

28+
#include "EFR32Config.h"
29+
2730
/// No error, operation OK
2831
#define SL_BOOTLOADER_OK 0L
2932

@@ -48,7 +51,10 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()
4851
}
4952
CHIP_ERROR OTAImageProcessorImpl::Apply()
5053
{
51-
DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
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);
5258
return CHIP_NO_ERROR;
5359
}
5460

@@ -76,6 +82,38 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block)
7682
return CHIP_NO_ERROR;
7783
}
7884

85+
bool OTAImageProcessorImpl::IsFirstImageRun()
86+
{
87+
OTARequestorInterface * requestor = chip::GetRequestorInstance();
88+
if (requestor == nullptr)
89+
{
90+
return false;
91+
}
92+
93+
return requestor->GetCurrentUpdateState() == OTARequestorInterface::OTAUpdateStateEnum::kApplying;
94+
}
95+
96+
CHIP_ERROR OTAImageProcessorImpl::ConfirmCurrentImage()
97+
{
98+
OTARequestorInterface * requestor = chip::GetRequestorInstance();
99+
if (requestor == nullptr)
100+
{
101+
return CHIP_ERROR_INTERNAL;
102+
}
103+
104+
uint32_t currentVersion;
105+
uint32_t targetVersion = requestor->GetTargetVersion();
106+
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(currentVersion));
107+
if (currentVersion != targetVersion)
108+
{
109+
ChipLogError(SoftwareUpdate, "Current software version = %" PRIu32 ", expected software version = %" PRIu32, currentVersion,
110+
targetVersion);
111+
return CHIP_ERROR_INCORRECT_STATE;
112+
}
113+
114+
return CHIP_NO_ERROR;
115+
}
116+
79117
void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
80118
{
81119
int32_t err = SL_BOOTLOADER_OK;
@@ -142,7 +180,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
142180
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
143181
}
144182

145-
void OTAImageProcessorImpl::HandleApply(intptr_t context)
183+
void OTAImageProcessorImpl::HandleApply(chip::System::Layer * systemLayer, void * context)
146184
{
147185
uint32_t err = SL_BOOTLOADER_OK;
148186

src/platform/EFR32/OTAImageProcessorImpl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
3636
CHIP_ERROR Apply() override;
3737
CHIP_ERROR Abort() override;
3838
CHIP_ERROR ProcessBlock(ByteSpan & block) override;
39-
bool IsFirstImageRun() override { return false; }
40-
CHIP_ERROR ConfirmCurrentImage() override { return CHIP_NO_ERROR; }
39+
bool IsFirstImageRun() override;
40+
CHIP_ERROR ConfirmCurrentImage() override;
4141

4242
void SetOTADownloader(OTADownloader * downloader) { mDownloader = downloader; }
4343
void SetOTAImageFile(const char * imageFile) { mImageFile = imageFile; }
@@ -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(intptr_t context);
49+
static void HandleApply(chip::System::Layer * systemLayer, void *);
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)