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] OTA: Use word-aligned buffer in bootloader storage APIs #17281

Merged
merged 31 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 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
ce57ef5
Use an intermediate buffer for writing the image to the booloader sto…
selissia Apr 11, 2022
c6463f3
Use critical section in the bootloader API call
selissia Apr 12, 2022
a9970c2
Cleanup log messages, move variables into a class
selissia Apr 12, 2022
23c99a9
Remove merge artifacts
selissia Apr 12, 2022
df6bb72
Update EFR32 documentation
selissia Apr 12, 2022
a9b9a92
Fix typo
selissia Apr 12, 2022
df33dd5
Restyled by whitespace
restyled-commits Apr 12, 2022
74bc0cc
Restyled by clang-format
restyled-commits Apr 12, 2022
2714cbe
Restyled by prettier-markdown
restyled-commits Apr 12, 2022
63bf1fa
Rename array size parameter, add aligned attribute
selissia Apr 12, 2022
0b813ec
Trivial change to restart the CI (restyle job need to be kicked)
selissia Apr 12, 2022
40b3412
Merge branch 'project-chip:master' into master
selissia Apr 12, 2022
bfbd6e6
Merge branch 'master' of github.com:selissia/connectedhomeip into int…
selissia Apr 12, 2022
f8f961f
Restyled by clang-format
restyled-commits Apr 12, 2022
d197cb5
Merge branch 'project-chip:master' into master
selissia Apr 13, 2022
86310c3
Merge branch 'master' of github.com:selissia/connectedhomeip into int…
selissia Apr 13, 2022
bbf022d
Update comments
selissia Apr 13, 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
Prev Previous commit
Next Next commit
Cleanup log messages, move variables into a class
  • Loading branch information
selissia committed Apr 12, 2022
commit a9970c2153a6c900c852e07b02f7a6d06f20b8a6
54 changes: 11 additions & 43 deletions src/platform/EFR32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@

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

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

#define ALIGNMENT_BYTES 64
uint8_t writeBuffer[ALIGNMENT_BYTES] = {0};
uint16_t writeBufOffset = 0;

namespace chip {

// Define static memebers
uint8_t OTAImageProcessorImpl::mSlotId;
uint32_t OTAImageProcessorImpl::mWriteOffset;
uint8_t OTAImageProcessorImpl::mSlotId = 0;
uint32_t OTAImageProcessorImpl::mWriteOffset = 0;
uint16_t OTAImageProcessorImpl::writeBufOffset= 0;
uint8_t OTAImageProcessorImpl::writeBuffer[ALIGNMENT_BYTES] = {0};

CHIP_ERROR OTAImageProcessorImpl::PrepareDownload()
{
Expand Down Expand Up @@ -95,7 +94,7 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)

ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload");

bootloader_init();
CORE_CRITICAL_SECTION(bootloader_init();)
mSlotId = 0; // Single slot until we support multiple images
writeBufOffset = 0;
mWriteOffset = 0;
Expand All @@ -117,20 +116,19 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
return;
}

// Pad the rest of the write buffer with zeros and write it to bootloader storage
// Pad the remainder of the write buffer with zeros and write it to bootloader storage
if(writeBufOffset != 0)
{
// Account for last bytes of the image not yet written to storage
imageProcessor->mParams.downloadedBytes += writeBufOffset;
ChipLogProgress(SoftwareUpdate, "HandleFinalize: mWriteOffset %lu writeBufOffset %u writeBuffer %p", mWriteOffset, writeBufOffset, writeBuffer);

while(writeBufOffset != ALIGNMENT_BYTES)
{
writeBuffer[writeBufOffset] = 0;
writeBufOffset++;
}

err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);)
if (err)
{
ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize bootloader_eraseWriteStorage() error %ld", err);
Expand All @@ -144,8 +142,6 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
ChipLogProgress(SoftwareUpdate, "OTA image downloaded successfully");
}

#include "sl_simple_button_instances.h"

void OTAImageProcessorImpl::HandleApply(intptr_t context)
{
uint32_t err = SL_BOOTLOADER_OK;
Expand All @@ -157,35 +153,15 @@ void OTAImageProcessorImpl::HandleApply(intptr_t context)
if (err != SL_BOOTLOADER_OK)
{
ChipLogError(SoftwareUpdate, "ERROR: bootloader_verifyImage() error %ld", err);
// ChipLogError(SoftwareUpdate, "ERROR: bootloader_verifyImage() error %ld", err);
// ChipLogError(SoftwareUpdate, "ERROR: bootloader_verifyImage() error %ld", err);
// ChipLogError(SoftwareUpdate, "ERROR: bootloader_verifyImage() error %ld", err);
return;
}
else
{
ChipLogProgress(SoftwareUpdate, "bootloader_verifyImage SUCCESS");
// ChipLogProgress(SoftwareUpdate, "bootloader_verifyImage SUCCESS");
// ChipLogProgress(SoftwareUpdate, "bootloader_verifyImage SUCCESS");
// ChipLogProgress(SoftwareUpdate, "bootloader_verifyImage SUCCESS");
}

CORE_CRITICAL_SECTION(err = bootloader_setImageToBootload(mSlotId);)
if (err != SL_BOOTLOADER_OK)
{
ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err);
// ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err);
// ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err);
// ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err);
ChipLogError(SoftwareUpdate, "ERROR: bootloader_setImageToBootload() error %ld", err);
return;
}
else
{
ChipLogProgress(SoftwareUpdate, "bootloader_setImageToBootload SUCCESS");
// ChipLogProgress(SoftwareUpdate, "bootloader_setImageToBootload SUCCESS");
// ChipLogProgress(SoftwareUpdate, "bootloader_setImageToBootload SUCCESS");
// ChipLogProgress(SoftwareUpdate, "bootloader_setImageToBootload SUCCESS");
}

// This reboots the device
CORE_CRITICAL_SECTION(bootloader_rebootAndInstall();)
Expand Down Expand Up @@ -228,11 +204,8 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
return;
}

// Copy data into the word-aligned writeBuffer and once it fills write its contents to the bootloader storage
selissia marked this conversation as resolved.
Show resolved Hide resolved
uint32_t blockReadOffset = 0;

// LISS debug, do not commit !!!!
ChipLogProgress(SoftwareUpdate, "HandleProcessBlock: mWriteOffset %lu writeBufOffset %u block.size() %u", mWriteOffset, writeBufOffset, block.size());

while (blockReadOffset < block.size())
selissia marked this conversation as resolved.
Show resolved Hide resolved
{
writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset);
Expand All @@ -242,11 +215,10 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
{
writeBufOffset = 0;

err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);)
if (err)
{
ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock bootloader_eraseWriteStorage() error %ld", err);
ChipLogProgress(SoftwareUpdate, "HandleProcessBlock: mWriteOffset %lu writeBuffer %p", mWriteOffset, writeBuffer);
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
return;
}
Expand All @@ -255,10 +227,6 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
}
}

// LISS debug, do not commit !!!!
ChipLogProgress(SoftwareUpdate, ": mWriteOffset %lu writeBufOffset %u blockReadOffset %lu", mWriteOffset, writeBufOffset, blockReadOffset);


imageProcessor->mDownloader->FetchNextData();
}

Expand Down
6 changes: 6 additions & 0 deletions src/platform/EFR32/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface
OTADownloader * mDownloader;
OTAImageHeaderParser mHeaderParser;
const char * mImageFile = nullptr;

#define ALIGNMENT_BYTES 64
selissia marked this conversation as resolved.
Show resolved Hide resolved
// Intermediate, word-aligned buffer for writing to the bootloader storage
selissia marked this conversation as resolved.
Show resolved Hide resolved
static uint8_t writeBuffer[ALIGNMENT_BYTES];
// Offset indicates how far the write buffer has been filled
static uint16_t writeBufOffset;
selissia marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace chip