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

[EFR32] Implement methods for NotifyUpdateApplied after an OTA update #18584

Merged
merged 30 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
35fad7d
Test added march 8 (#15957)
kowsisoundhar12 Mar 9, 2022
d5f4b0b
[OTA] Fix OTARequestorDriverImpl inclusion (#15981)
carol-apple Mar 9, 2022
9bee828
Regen to fix CI failures (#15990)
bzbarsky-apple Mar 9, 2022
b942392
[ota] Store Default OTA Providers in flash (#15970)
Damian-Nordic Mar 9, 2022
c219807
Merge branch 'master' of github.com:project-chip/connectedhomeip
selissia Mar 11, 2022
fa279bc
Merge branch 'project-chip:master' into master
selissia Mar 11, 2022
9e18f9b
Merge branch 'project-chip:master' into master
selissia Mar 14, 2022
b6ca5ca
Merge branch 'project-chip:master' into master
selissia Mar 15, 2022
135dc25
Merge branch 'project-chip:master' into master
selissia Mar 18, 2022
0446c67
Merge branch 'project-chip:master' into master
selissia Mar 22, 2022
e69e63c
Merge branch 'project-chip:master' into master
selissia Mar 23, 2022
a40f6df
Merge branch 'project-chip:master' into master
selissia Mar 24, 2022
e5925ba
Merge branch 'project-chip:master' into master
selissia Mar 30, 2022
0435362
Merge branch 'project-chip:master' into master
selissia Apr 5, 2022
40b3412
Merge branch 'project-chip:master' into master
selissia Apr 12, 2022
d197cb5
Merge branch 'project-chip:master' into master
selissia Apr 13, 2022
e9b685d
Merge branch 'project-chip:master' into master
selissia Apr 15, 2022
ef11df2
Merge branch 'project-chip:master' into master
selissia Apr 18, 2022
b088f83
Merge branch 'project-chip:master' into master
selissia Apr 27, 2022
8530810
Merge branch 'project-chip:master' into master
selissia Apr 29, 2022
87a9581
Merge branch 'project-chip:master' into master
selissia May 4, 2022
d9b496d
Merge branch 'project-chip:master' into master
selissia May 10, 2022
2d283df
Merge branch 'project-chip:master' into master
selissia May 12, 2022
2639213
Merge branch 'project-chip:master' into master
selissia May 13, 2022
a55086f
Changes for transmitting UpdateApplied for EFR32
selissia May 17, 2022
e312dcd
Delay HandleApply by EFR32_KVS_SAVE_DELAY_SECONDS + 1
selissia May 18, 2022
6f9e50c
Remove merge artifacts
selissia May 18, 2022
995a07e
Merge branch 'project-chip:master' into master
selissia May 18, 2022
8766890
Merge branch 'master' of github.com:selissia/connectedhomeip into sil…
selissia May 18, 2022
cd3e78b
Restyled by clang-format
restyled-commits May 18, 2022
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
23 changes: 23 additions & 0 deletions examples/platform/efr32/OTAConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
#include "platform/bootloader/api/application_properties.h"
#include <app/server/Server.h>

#define BOOTLOADER_SUPPORT_CERTIFICATES 1
#define APPLICATION_CERTIFICATE_VERSION (1UL)

#if defined(BOOTLOADER_SUPPORT_CERTIFICATES)
const ApplicationCertificate_t sl_app_certificate = {
.structVersion = APPLICATION_CERTIFICATE_VERSION,
.flags = { 0U },
.key = { 0U },
.version = 0,
.signature = { 0U },
};
#endif

// Header used for building the image GBL file
#define APP_PROPERTIES_VERSION 1
#define APP_PROPERTIES_ID \
Expand Down Expand Up @@ -58,6 +71,16 @@ __attribute__((used)) ApplicationProperties_t sl_app_properties = {
/// Unique ID (e.g. UUID/GUID) for the product this application is built for
.productId = APP_PROPERTIES_ID,
},
#if defined(BOOTLOADER_SUPPORT_CERTIFICATES)
// If certificate based boot chain is enabled, the bootloader binary will be provided with
// a certificate that does not contain any key.
// A valid certificate needs to be injected to the bootloader images using Simplicity Commander.
// Simplicity Commander will replace this certificate.
.cert = (ApplicationCertificate_t *)&sl_app_certificate,
#else
.cert = NULL,
#endif
.longTokenSectionAddress = NULL,
};

// Global OTA objects
Expand Down
3 changes: 3 additions & 0 deletions src/platform/EFR32/EFR32Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#define KVS_MAX_ENTRIES 75 // Available key slot count for Kvs Key mapping.
#endif

// Delay before Key/Value is actually saved in NVM
#define EFR32_KVS_SAVE_DELAY_SECONDS 5

static_assert((KVS_MAX_ENTRIES <= 255), "Implementation supports up to 255 Kvs entries");
static_assert((KVS_MAX_ENTRIES >= 30), "Mininimal Kvs entries requirement is not met");

Expand Down
5 changes: 3 additions & 2 deletions src/platform/EFR32/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void)
During commissioning, the key map will be modified multiples times subsequently.
Commit the key map in nvm once it as stabilized.
*/
SystemLayer().StartTimer(std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(5)),
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
SystemLayer().StartTimer(
std::chrono::duration_cast<System::Clock::Timeout>(System::Clock::Seconds32(EFR32_KVS_SAVE_DELAY_SECONDS)),
KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL);
}

CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t value_size, size_t * read_bytes_size,
Expand Down
42 changes: 40 additions & 2 deletions src/platform/EFR32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

#include "OTAImageProcessorImpl.h"
#include <app/clusters/ota-requestor/OTADownloader.h>
#include <app/clusters/ota-requestor/OTARequestorInterface.h>

extern "C" {
#include "platform/bootloader/api/btl_interface.h"
#include "platform/emlib/inc/em_bus.h" // For CORE_CRITICAL_SECTION
}

#include "EFR32Config.h"

/// No error, operation OK
#define SL_BOOTLOADER_OK 0L

Expand All @@ -48,7 +51,10 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize()
}
CHIP_ERROR OTAImageProcessorImpl::Apply()
{
DeviceLayer::PlatformMgr().ScheduleWork(HandleApply, reinterpret_cast<intptr_t>(this));
// 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);
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -76,6 +82,38 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block)
return CHIP_NO_ERROR;
}

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

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

CHIP_ERROR OTAImageProcessorImpl::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 OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
{
int32_t err = SL_BOOTLOADER_OK;
Expand Down Expand Up @@ -142,7 +180,7 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
}

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

Expand Down
6 changes: 3 additions & 3 deletions src/platform/EFR32/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class OTAImageProcessorImpl : 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; }
void SetOTAImageFile(const char * imageFile) { mImageFile = imageFile; }
Expand All @@ -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(intptr_t context);
static void HandleApply(chip::System::Layer * systemLayer, void *);
static void HandleAbort(intptr_t context);
static void HandleProcessBlock(intptr_t context);
CHIP_ERROR ProcessHeader(ByteSpan & block);
Expand Down