From 83a7765f1dd17e45f9ef54c8128b708329bea643 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 30 Dec 2021 15:10:36 -0500 Subject: [PATCH 1/9] Code for testing bootloader integration --- .../ota-requestor-app/efr32/src/AppTask.cpp | 26 ++++++++++++ examples/ota-requestor-app/efr32/src/main.cpp | 40 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/examples/ota-requestor-app/efr32/src/AppTask.cpp b/examples/ota-requestor-app/efr32/src/AppTask.cpp index 2b6d5e39bd2c2c..0ad03bd5845975 100644 --- a/examples/ota-requestor-app/efr32/src/AppTask.cpp +++ b/examples/ota-requestor-app/efr32/src/AppTask.cpp @@ -51,6 +51,11 @@ #include #endif +// Bootloader +extern "C" { +#include "platform/bootloader/api/btl_interface.h" +} + #define FACTORY_RESET_TRIGGER_TIMEOUT 3000 #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 #define APP_TASK_STACK_SIZE (4096) @@ -437,6 +442,8 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor) } } +#define STORAGE_SLOT 0 + void AppTask::ActionCompleted(LightingManager::Action_t aAction) { // action has been completed bon the light @@ -454,6 +461,25 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction) UpdateClusterState(); sAppTask.mSyncClusterToButtonAction = false; } + + // The rest of this function is temporary test code, trying to get + // bootloader to work + // !!!!! DO NOT MERGE INTO MASTER !!!!!!!!!!! + static bool firstTime = true; + + if(firstTime == true) { + bootloader_init(); + firstTime = false; + } + + BootloaderStorageSlot_t slotInfo; + bootloader_getStorageSlotInfo(STORAGE_SLOT, &slotInfo); + EFR32_LOG("Boot slot info: image addr: 0x%x size: %d", slotInfo.address, slotInfo.length); + + // This call to bootloader_getStorageInfo() corrupts the stack + BootloaderStorageInformation_t bootInfo; + bootloader_getStorageInfo(&bootInfo); + EFR32_LOG("Boot info: storageType %d, numStorageSlots %d info 0x%x", bootInfo.storageType, bootInfo.numStorageSlots,bootInfo.info ); } void AppTask::PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction) diff --git a/examples/ota-requestor-app/efr32/src/main.cpp b/examples/ota-requestor-app/efr32/src/main.cpp index 4e54e423633fbb..84d8e4755dd10e 100644 --- a/examples/ota-requestor-app/efr32/src/main.cpp +++ b/examples/ota-requestor-app/efr32/src/main.cpp @@ -88,6 +88,46 @@ BDXDownloader gDownloader; OTAImageProcessorImpl gImageProcessor; volatile int apperror_cnt; + +#include "platform/bootloader/api/application_properties.h" + +// Header used for building the image GBL file + +#define APP_PROPERTIES_VERSION 1 +#define APP_PROPERTIES_ID { 0 } + +__attribute__((used)) ApplicationProperties_t sl_app_properties = { + /// @brief Magic value indicating that this is an ApplicationProperties_t + /// Must equal @ref APPLICATION_PROPERTIES_MAGIC + .magic = APPLICATION_PROPERTIES_MAGIC, + + /// Version number of this struct + .structVersion = APPLICATION_PROPERTIES_VERSION, + + /// Type of signature this application is signed with + .signatureType = APPLICATION_SIGNATURE_NONE, + + /// Location of the signature. Typically a pointer to the end of application + .signatureLocation = 0, + + /// Information about the application + .app = { + + /// Bitfield representing type of application + /// e.g. @ref APPLICATION_TYPE_BLUETOOTH_APP + .type = APPLICATION_TYPE_ZIGBEE, + + /// Version number for this application + .version = APP_PROPERTIES_VERSION, + + /// Capabilities of this application + .capabilities = 0, + + /// Unique ID (e.g. UUID/GUID) for the product this application is built for + .productId = APP_PROPERTIES_ID, + }, +}; + // ================================================================================ // App Error //================================================================================= From c746890d9a6a98970dd2bfb3127968416c76df53 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Mon, 3 Jan 2022 17:32:22 -0500 Subject: [PATCH 2/9] Add bootloader API calls --- .../ota-requestor-app/efr32/src/AppTask.cpp | 2 + src/platform/EFR32/OTAImageProcessorImpl.cpp | 48 ++++++++++--------- src/platform/EFR32/OTAImageProcessorImpl.h | 7 +-- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/examples/ota-requestor-app/efr32/src/AppTask.cpp b/examples/ota-requestor-app/efr32/src/AppTask.cpp index 0ad03bd5845975..978d52c3e50934 100644 --- a/examples/ota-requestor-app/efr32/src/AppTask.cpp +++ b/examples/ota-requestor-app/efr32/src/AppTask.cpp @@ -480,6 +480,8 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction) BootloaderStorageInformation_t bootInfo; bootloader_getStorageInfo(&bootInfo); EFR32_LOG("Boot info: storageType %d, numStorageSlots %d info 0x%x", bootInfo.storageType, bootInfo.numStorageSlots,bootInfo.info ); + + EFR32_LOG("Sorage info: descr: %s version: %d size %d", bootInfo.info->partDescription, bootInfo.info->version, bootInfo.info->partSize); } void AppTask::PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction) diff --git a/src/platform/EFR32/OTAImageProcessorImpl.cpp b/src/platform/EFR32/OTAImageProcessorImpl.cpp index 14a061484b680e..ddf077fbdfadbf 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.cpp +++ b/src/platform/EFR32/OTAImageProcessorImpl.cpp @@ -82,7 +82,9 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) { + int32_t err = BOOTLOADER_OK; auto * imageProcessor = reinterpret_cast(context); + if (imageProcessor == nullptr) { ChipLogError(SoftwareUpdate, "ImageProcessor context is null"); @@ -94,17 +96,11 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) return; } - imageProcessor->mOfs.open(imageProcessor->mParams.imageFile.data(), - std::ofstream::out | std::ofstream::ate | std::ofstream::app); - if (!imageProcessor->mOfs.good()) - { - imageProcessor->mDownloader->OnPreparedForDownload(CHIP_ERROR_OPEN_FAILED); - return; - } + bootloader_init(); + mWriteOffset = 0; + err = bootloader_eraseStorageSlot(mSlotId); - // TODO: if file already exists and is not empty, erase previous contents - - imageProcessor->mDownloader->OnPreparedForDownload(CHIP_NO_ERROR); + imageProcessor->mDownloader->OnPreparedForDownload(err == BOOTLOADER_OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); } void OTAImageProcessorImpl::HandleFinalize(intptr_t context) @@ -150,17 +146,21 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) // TODO: Process block header if any - if (!imageProcessor->mOfs.write(reinterpret_cast(imageProcessor->mBlock.data()), - static_cast(imageProcessor->mBlock.size()))) - { - imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - return; - } + err = bootloader_writeStorage(mSlotId, imageProcessor->mBlock.size(), + reinterpret_cast(imageProcessor->mBlock.data()), mWriteOffset); + + if (err) + { + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + return; + } + mWriteOffset += imageProcessor->mBlock.size(); // Keep our own track of how far we've written imageProcessor->mParams.downloadedBytes += imageProcessor->mBlock.size(); imageProcessor->mDownloader->FetchNextData(); } +// Store block data for HandleProcessBlock to access CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) { if ((block.data() == nullptr) || block.empty()) @@ -168,15 +168,17 @@ CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) return CHIP_NO_ERROR; } - // Allocate memory for block data if it has not been done yet - if (mBlock.empty()) - { - mBlock = MutableByteSpan(static_cast(chip::Platform::MemoryAlloc(block.size())), block.size()); - if (mBlock.data() == nullptr) + // Allocate memory for block data if we don't have enough already + if(mBlock.size() < block.size()) { - return CHIP_ERROR_NO_MEMORY; + ReleaseBlock(); + + mBlock = MutableByteSpan(static_cast(chip::Platform::MemoryAlloc(block.size())), block.size()); + if (mBlock.data() == nullptr) + { + return CHIP_ERROR_NO_MEMORY; + } } - } // Store the actual block data CHIP_ERROR err = CopySpanToMutableSpan(block, mBlock); diff --git a/src/platform/EFR32/OTAImageProcessorImpl.h b/src/platform/EFR32/OTAImageProcessorImpl.h index 77a13ca36e890c..5c009817e61c05 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.h +++ b/src/platform/EFR32/OTAImageProcessorImpl.h @@ -54,10 +54,11 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface * Called to release allocated memory for mBlock */ CHIP_ERROR ReleaseBlock(); - - std::ofstream mOfs; + + uint16_t mWriteOffset = 0; // End of last written block + uint8_t mSlotId = 0; // Bootloader storage slot MutableByteSpan mBlock; - OTADownloader * mDownloader; + OTADownloader *mDownloader; }; } // namespace chip From 1e1f7b2237dfba0fb2b1472dfbd4635cbc5309ef Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Tue, 4 Jan 2022 13:45:03 -0500 Subject: [PATCH 3/9] Add the rest of booloader calls to EFR32 OTA Requestor --- src/platform/EFR32/OTAImageProcessorImpl.cpp | 48 +++++++++++++++----- src/platform/EFR32/OTAImageProcessorImpl.h | 6 +-- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/platform/EFR32/OTAImageProcessorImpl.cpp b/src/platform/EFR32/OTAImageProcessorImpl.cpp index ddf077fbdfadbf..d078edd78db9c6 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.cpp +++ b/src/platform/EFR32/OTAImageProcessorImpl.cpp @@ -17,11 +17,21 @@ */ #include - #include "OTAImageProcessorImpl.h" +extern "C" { +#include "platform/bootloader/api/btl_interface.h" +} + +/// No error, operation OK +#define SL_BOOTLOADER_OK 0L + namespace chip { +// Define static memebers +uint8_t OTAImageProcessorImpl::mSlotId; +uint16_t OTAImageProcessorImpl::mWriteOffset; + CHIP_ERROR OTAImageProcessorImpl::PrepareDownload() { if (mParams.imageFile.empty()) @@ -42,6 +52,25 @@ CHIP_ERROR OTAImageProcessorImpl::Finalize() CHIP_ERROR OTAImageProcessorImpl::Apply() { + uint32_t err = SL_BOOTLOADER_OK; + + // Assuming that bootloader_verifyImage() call is not too expensive and + // doesn't need to be offladed to a different task + err = bootloader_verifyImage(mSlotId, NULL); + if (err != SL_BOOTLOADER_OK) + { + return CHIP_ERROR_INTERNAL; + } + + err = bootloader_setImageToBootload(mSlotId); + if (err != SL_BOOTLOADER_OK) + { + return CHIP_ERROR_INTERNAL; + } + + // This reboots the device + bootloader_rebootAndInstall(); + return CHIP_NO_ERROR; } @@ -59,11 +88,6 @@ CHIP_ERROR OTAImageProcessorImpl::Abort() CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) { - if (!mOfs.is_open() || !mOfs.good()) - { - return CHIP_ERROR_INTERNAL; - } - if ((block.data() == nullptr) || block.empty()) { return CHIP_ERROR_INVALID_ARGUMENT; @@ -82,7 +106,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) { - int32_t err = BOOTLOADER_OK; + int32_t err = SL_BOOTLOADER_OK; auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) @@ -97,10 +121,11 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) } bootloader_init(); + mSlotId = 0; // Single slot unless we support multiple images mWriteOffset = 0; err = bootloader_eraseStorageSlot(mSlotId); - imageProcessor->mDownloader->OnPreparedForDownload(err == BOOTLOADER_OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); + imageProcessor->mDownloader->OnPreparedForDownload(err == SL_BOOTLOADER_OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); } void OTAImageProcessorImpl::HandleFinalize(intptr_t context) @@ -111,7 +136,6 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context) return; } - imageProcessor->mOfs.close(); imageProcessor->ReleaseBlock(); ChipLogProgress(SoftwareUpdate, "OTA image downloaded to %s", imageProcessor->mParams.imageFile.data()); @@ -125,13 +149,13 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) return; } - imageProcessor->mOfs.close(); - remove(imageProcessor->mParams.imageFile.data()); + // Not clearing the imag storage area as it will be done during preparation for the next download imageProcessor->ReleaseBlock(); } void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) { + uint32_t err = SL_BOOTLOADER_OK; auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { @@ -146,7 +170,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) // TODO: Process block header if any - err = bootloader_writeStorage(mSlotId, imageProcessor->mBlock.size(), + err = bootloader_writeStorage(mSlotId, imageProcessor->mBlock.size(), reinterpret_cast(imageProcessor->mBlock.data()), mWriteOffset); if (err) diff --git a/src/platform/EFR32/OTAImageProcessorImpl.h b/src/platform/EFR32/OTAImageProcessorImpl.h index 5c009817e61c05..f2c1c0f5b1bb03 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.h +++ b/src/platform/EFR32/OTAImageProcessorImpl.h @@ -54,9 +54,9 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface * Called to release allocated memory for mBlock */ CHIP_ERROR ReleaseBlock(); - - uint16_t mWriteOffset = 0; // End of last written block - uint8_t mSlotId = 0; // Bootloader storage slot + + static uint16_t mWriteOffset; // End of last written block + static uint8_t mSlotId; // Bootloader storage slot MutableByteSpan mBlock; OTADownloader *mDownloader; }; From 5adcb365e8c41a0549e01bd59aa0d57bec791deb Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Mon, 10 Jan 2022 16:36:05 -0500 Subject: [PATCH 4/9] Call the OTARequestor Init() method --- examples/ota-requestor-app/efr32/src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/ota-requestor-app/efr32/src/main.cpp b/examples/ota-requestor-app/efr32/src/main.cpp index 84d8e4755dd10e..c43e6e80bc8dcb 100644 --- a/examples/ota-requestor-app/efr32/src/main.cpp +++ b/examples/ota-requestor-app/efr32/src/main.cpp @@ -219,6 +219,8 @@ int main(void) // Connect the Requestor and Requestor Driver objects gRequestorCore.SetOtaRequestorDriver(&gRequestorUser); + gRequestorUser.Init(&gRequestorCore, &gImageProcessor); + OTAImageProcessorParams ipParams; ipParams.imageFile = CharSpan("test.txt"); gImageProcessor.SetOTAImageProcessorParams(ipParams); From 1265e6157eca17eca175accec632bad9ca316e4b Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Tue, 11 Jan 2022 17:05:50 -0500 Subject: [PATCH 5/9] Use correct booloader API --- src/platform/EFR32/OTAImageProcessorImpl.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/platform/EFR32/OTAImageProcessorImpl.cpp b/src/platform/EFR32/OTAImageProcessorImpl.cpp index d078edd78db9c6..c3cc695485daf0 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.cpp +++ b/src/platform/EFR32/OTAImageProcessorImpl.cpp @@ -54,17 +54,20 @@ CHIP_ERROR OTAImageProcessorImpl::Apply() { uint32_t err = SL_BOOTLOADER_OK; + ChipLogError(SoftwareUpdate, "LISS Apply() is called "); // Assuming that bootloader_verifyImage() call is not too expensive and - // doesn't need to be offladed to a different task + // doesn't need to be offloaded to a different task err = bootloader_verifyImage(mSlotId, NULL); if (err != SL_BOOTLOADER_OK) { + ChipLogError(SoftwareUpdate, "bootloader_verifyImage error %ld", err); return CHIP_ERROR_INTERNAL; } err = bootloader_setImageToBootload(mSlotId); if (err != SL_BOOTLOADER_OK) { + ChipLogError(SoftwareUpdate, "setImageToBootload error %ld", err); return CHIP_ERROR_INTERNAL; } @@ -123,7 +126,7 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) bootloader_init(); mSlotId = 0; // Single slot unless we support multiple images mWriteOffset = 0; - err = bootloader_eraseStorageSlot(mSlotId); + // err = bootloader_eraseStorageSlot(mSlotId); imageProcessor->mDownloader->OnPreparedForDownload(err == SL_BOOTLOADER_OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); } @@ -170,11 +173,13 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) // TODO: Process block header if any - err = bootloader_writeStorage(mSlotId, imageProcessor->mBlock.size(), - reinterpret_cast(imageProcessor->mBlock.data()), mWriteOffset); + err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, + reinterpret_cast(imageProcessor->mBlock.data()), imageProcessor->mBlock.size()); if (err) - { + { + ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage err %ld", err); + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); return; } From b3c09d8b2deeba1bdd7f590d17f367709a1e8288 Mon Sep 17 00:00:00 2001 From: Zang MingJie Date: Wed, 12 Jan 2022 05:44:03 +0800 Subject: [PATCH 6/9] Close exchange when session is released (#13448) * Close exchange when session is released * Add clearRetransTable parameter to DoClose call Co-authored-by: Andrei Litvin --- src/messaging/ExchangeContext.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 3a5cfb477ee7c7..8ec3b67989aff8 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -317,17 +317,18 @@ bool ExchangeContext::MatchExchange(const SessionHandle & session, const PacketH void ExchangeContext::OnSessionReleased() { - if (!IsResponseExpected()) + ExchangeHandle ref(*this); + + if (IsResponseExpected()) { - // Nothing to do in this case - return; + // If we're waiting on a response, we now know it's never going to show up + // and we should notify our delegate accordingly. + CancelResponseTimer(); + SetResponseExpected(false); + NotifyResponseTimeout(); } - // If we're waiting on a response, we now know it's never going to show up - // and we should notify our delegate accordingly. - CancelResponseTimer(); - SetResponseExpected(false); - NotifyResponseTimeout(); + DoClose(true /* clearRetransTable */); } CHIP_ERROR ExchangeContext::StartResponseTimer() From 4b4a5a46816216537083b42167f577b354b90e87 Mon Sep 17 00:00:00 2001 From: Sergei Lissianoi Date: Thu, 13 Jan 2022 09:37:44 -0500 Subject: [PATCH 7/9] Clean up comments and debug code --- .../ota-requestor-app/efr32/src/AppTask.cpp | 28 ------------------- examples/ota-requestor-app/efr32/src/main.cpp | 1 - src/platform/EFR32/OTAImageProcessorImpl.cpp | 12 ++++---- 3 files changed, 7 insertions(+), 34 deletions(-) diff --git a/examples/ota-requestor-app/efr32/src/AppTask.cpp b/examples/ota-requestor-app/efr32/src/AppTask.cpp index 978d52c3e50934..2b6d5e39bd2c2c 100644 --- a/examples/ota-requestor-app/efr32/src/AppTask.cpp +++ b/examples/ota-requestor-app/efr32/src/AppTask.cpp @@ -51,11 +51,6 @@ #include #endif -// Bootloader -extern "C" { -#include "platform/bootloader/api/btl_interface.h" -} - #define FACTORY_RESET_TRIGGER_TIMEOUT 3000 #define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 #define APP_TASK_STACK_SIZE (4096) @@ -442,8 +437,6 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor) } } -#define STORAGE_SLOT 0 - void AppTask::ActionCompleted(LightingManager::Action_t aAction) { // action has been completed bon the light @@ -461,27 +454,6 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction) UpdateClusterState(); sAppTask.mSyncClusterToButtonAction = false; } - - // The rest of this function is temporary test code, trying to get - // bootloader to work - // !!!!! DO NOT MERGE INTO MASTER !!!!!!!!!!! - static bool firstTime = true; - - if(firstTime == true) { - bootloader_init(); - firstTime = false; - } - - BootloaderStorageSlot_t slotInfo; - bootloader_getStorageSlotInfo(STORAGE_SLOT, &slotInfo); - EFR32_LOG("Boot slot info: image addr: 0x%x size: %d", slotInfo.address, slotInfo.length); - - // This call to bootloader_getStorageInfo() corrupts the stack - BootloaderStorageInformation_t bootInfo; - bootloader_getStorageInfo(&bootInfo); - EFR32_LOG("Boot info: storageType %d, numStorageSlots %d info 0x%x", bootInfo.storageType, bootInfo.numStorageSlots,bootInfo.info ); - - EFR32_LOG("Sorage info: descr: %s version: %d size %d", bootInfo.info->partDescription, bootInfo.info->version, bootInfo.info->partSize); } void AppTask::PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction) diff --git a/examples/ota-requestor-app/efr32/src/main.cpp b/examples/ota-requestor-app/efr32/src/main.cpp index c43e6e80bc8dcb..f0f88958219dcb 100644 --- a/examples/ota-requestor-app/efr32/src/main.cpp +++ b/examples/ota-requestor-app/efr32/src/main.cpp @@ -92,7 +92,6 @@ volatile int apperror_cnt; #include "platform/bootloader/api/application_properties.h" // Header used for building the image GBL file - #define APP_PROPERTIES_VERSION 1 #define APP_PROPERTIES_ID { 0 } diff --git a/src/platform/EFR32/OTAImageProcessorImpl.cpp b/src/platform/EFR32/OTAImageProcessorImpl.cpp index c3cc695485daf0..470a9017666da6 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.cpp +++ b/src/platform/EFR32/OTAImageProcessorImpl.cpp @@ -54,9 +54,10 @@ CHIP_ERROR OTAImageProcessorImpl::Apply() { uint32_t err = SL_BOOTLOADER_OK; - ChipLogError(SoftwareUpdate, "LISS Apply() is called "); + ChipLogError(SoftwareUpdate, "OTAImageProcessorImpl::Apply()"); + // Assuming that bootloader_verifyImage() call is not too expensive and - // doesn't need to be offloaded to a different task + // doesn't need to be offloaded to a different task. Revisit if necessary. err = bootloader_verifyImage(mSlotId, NULL); if (err != SL_BOOTLOADER_OK) { @@ -124,9 +125,10 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) } bootloader_init(); - mSlotId = 0; // Single slot unless we support multiple images + mSlotId = 0; // Single slot until we support multiple images mWriteOffset = 0; - // err = bootloader_eraseStorageSlot(mSlotId); + + // Not calling bootloader_eraseStorageSlot(mSlotId) here because we erase during each write imageProcessor->mDownloader->OnPreparedForDownload(err == SL_BOOTLOADER_OK ? CHIP_NO_ERROR : CHIP_ERROR_INTERNAL); } @@ -152,7 +154,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) return; } - // Not clearing the imag storage area as it will be done during preparation for the next download + // Not clearing the image storage area as it is done during each write imageProcessor->ReleaseBlock(); } From 06ea1a3e940d9984ea9f5805118cd7f1e59d5643 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 13 Jan 2022 14:38:17 +0000 Subject: [PATCH 8/9] Restyled by whitespace --- src/platform/EFR32/OTAImageProcessorImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/EFR32/OTAImageProcessorImpl.cpp b/src/platform/EFR32/OTAImageProcessorImpl.cpp index 470a9017666da6..162bc1a530f72b 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.cpp +++ b/src/platform/EFR32/OTAImageProcessorImpl.cpp @@ -179,7 +179,7 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) reinterpret_cast(imageProcessor->mBlock.data()), imageProcessor->mBlock.size()); if (err) - { + { ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage err %ld", err); imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); From cd5c3993610d7f5da3394fce96d90300ecfa6c97 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 13 Jan 2022 14:38:19 +0000 Subject: [PATCH 9/9] Restyled by clang-format --- examples/ota-requestor-app/efr32/src/main.cpp | 5 +- src/platform/EFR32/OTAImageProcessorImpl.cpp | 56 +++++++++---------- src/platform/EFR32/OTAImageProcessorImpl.h | 6 +- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/examples/ota-requestor-app/efr32/src/main.cpp b/examples/ota-requestor-app/efr32/src/main.cpp index f0f88958219dcb..ad6869533b2374 100644 --- a/examples/ota-requestor-app/efr32/src/main.cpp +++ b/examples/ota-requestor-app/efr32/src/main.cpp @@ -93,7 +93,10 @@ volatile int apperror_cnt; // Header used for building the image GBL file #define APP_PROPERTIES_VERSION 1 -#define APP_PROPERTIES_ID { 0 } +#define APP_PROPERTIES_ID \ + { \ + 0 \ + } __attribute__((used)) ApplicationProperties_t sl_app_properties = { /// @brief Magic value indicating that this is an ApplicationProperties_t diff --git a/src/platform/EFR32/OTAImageProcessorImpl.cpp b/src/platform/EFR32/OTAImageProcessorImpl.cpp index 162bc1a530f72b..165ccb8b8f3390 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.cpp +++ b/src/platform/EFR32/OTAImageProcessorImpl.cpp @@ -16,15 +16,15 @@ * limitations under the License. */ -#include #include "OTAImageProcessorImpl.h" +#include extern "C" { #include "platform/bootloader/api/btl_interface.h" } /// No error, operation OK -#define SL_BOOTLOADER_OK 0L +#define SL_BOOTLOADER_OK 0L namespace chip { @@ -60,17 +60,17 @@ CHIP_ERROR OTAImageProcessorImpl::Apply() // doesn't need to be offloaded to a different task. Revisit if necessary. err = bootloader_verifyImage(mSlotId, NULL); if (err != SL_BOOTLOADER_OK) - { - ChipLogError(SoftwareUpdate, "bootloader_verifyImage error %ld", err); - return CHIP_ERROR_INTERNAL; - } + { + ChipLogError(SoftwareUpdate, "bootloader_verifyImage error %ld", err); + return CHIP_ERROR_INTERNAL; + } err = bootloader_setImageToBootload(mSlotId); if (err != SL_BOOTLOADER_OK) - { - ChipLogError(SoftwareUpdate, "setImageToBootload error %ld", err); - return CHIP_ERROR_INTERNAL; - } + { + ChipLogError(SoftwareUpdate, "setImageToBootload error %ld", err); + return CHIP_ERROR_INTERNAL; + } // This reboots the device bootloader_rebootAndInstall(); @@ -110,7 +110,7 @@ CHIP_ERROR OTAImageProcessorImpl::ProcessBlock(ByteSpan & block) void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) { - int32_t err = SL_BOOTLOADER_OK; + int32_t err = SL_BOOTLOADER_OK; auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) @@ -125,7 +125,7 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context) } bootloader_init(); - mSlotId = 0; // Single slot until we support multiple images + mSlotId = 0; // Single slot until we support multiple images mWriteOffset = 0; // Not calling bootloader_eraseStorageSlot(mSlotId) here because we erase during each write @@ -160,7 +160,7 @@ void OTAImageProcessorImpl::HandleAbort(intptr_t context) void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) { - uint32_t err = SL_BOOTLOADER_OK; + uint32_t err = SL_BOOTLOADER_OK; auto * imageProcessor = reinterpret_cast(context); if (imageProcessor == nullptr) { @@ -175,16 +175,16 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context) // TODO: Process block header if any - err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, - reinterpret_cast(imageProcessor->mBlock.data()), imageProcessor->mBlock.size()); + err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, reinterpret_cast(imageProcessor->mBlock.data()), + imageProcessor->mBlock.size()); if (err) - { - ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage err %ld", err); + { + ChipLogError(SoftwareUpdate, "bootloader_eraseWriteStorage err %ld", err); - imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); - return; - } + imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED); + return; + } mWriteOffset += imageProcessor->mBlock.size(); // Keep our own track of how far we've written imageProcessor->mParams.downloadedBytes += imageProcessor->mBlock.size(); @@ -200,16 +200,16 @@ CHIP_ERROR OTAImageProcessorImpl::SetBlock(ByteSpan & block) } // Allocate memory for block data if we don't have enough already - if(mBlock.size() < block.size()) - { - ReleaseBlock(); + if (mBlock.size() < block.size()) + { + ReleaseBlock(); - mBlock = MutableByteSpan(static_cast(chip::Platform::MemoryAlloc(block.size())), block.size()); - if (mBlock.data() == nullptr) - { - return CHIP_ERROR_NO_MEMORY; - } + mBlock = MutableByteSpan(static_cast(chip::Platform::MemoryAlloc(block.size())), block.size()); + if (mBlock.data() == nullptr) + { + return CHIP_ERROR_NO_MEMORY; } + } // Store the actual block data CHIP_ERROR err = CopySpanToMutableSpan(block, mBlock); diff --git a/src/platform/EFR32/OTAImageProcessorImpl.h b/src/platform/EFR32/OTAImageProcessorImpl.h index f2c1c0f5b1bb03..6f60ea0001d8ec 100644 --- a/src/platform/EFR32/OTAImageProcessorImpl.h +++ b/src/platform/EFR32/OTAImageProcessorImpl.h @@ -55,10 +55,10 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface */ CHIP_ERROR ReleaseBlock(); - static uint16_t mWriteOffset; // End of last written block - static uint8_t mSlotId; // Bootloader storage slot + static uint16_t mWriteOffset; // End of last written block + static uint8_t mSlotId; // Bootloader storage slot MutableByteSpan mBlock; - OTADownloader *mDownloader; + OTADownloader * mDownloader; }; } // namespace chip