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
Restyled by clang-format
  • Loading branch information
restyled-commits committed Apr 12, 2022
commit 74bc0cc8d752246da7b53d0748a068f1684e3703
80 changes: 40 additions & 40 deletions src/platform/EFR32/OTAImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ extern "C" {
namespace chip {

// Define static memebers
uint8_t OTAImageProcessorImpl::mSlotId = 0;
uint32_t OTAImageProcessorImpl::mWriteOffset = 0;
uint16_t OTAImageProcessorImpl::writeBufOffset= 0;
uint8_t OTAImageProcessorImpl::writeBuffer[ALIGNMENT_BYTES] = {0};
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,9 +95,9 @@ void OTAImageProcessorImpl::HandlePrepareDownload(intptr_t context)
ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload");

CORE_CRITICAL_SECTION(bootloader_init();)
mSlotId = 0; // Single slot until we support multiple images
writeBufOffset = 0;
mWriteOffset = 0;
mSlotId = 0; // Single slot until we support multiple images
writeBufOffset = 0;
mWriteOffset = 0;
imageProcessor->mParams.downloadedBytes = 0;

imageProcessor->mHeaderParser.Init();
Expand All @@ -117,25 +117,25 @@ void OTAImageProcessorImpl::HandleFinalize(intptr_t context)
}

// 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;
if (writeBufOffset != 0)
{
// Account for last bytes of the image not yet written to storage
imageProcessor->mParams.downloadedBytes += writeBufOffset;

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

CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);)
if (err)
{
ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize bootloader_eraseWriteStorage() error %ld", err);
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
return;
}
CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);)
if (err)
{
ChipLogError(SoftwareUpdate, "ERROR: In HandleFinalize bootloader_eraseWriteStorage() error %ld", err);
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
return;
}
}

imageProcessor->ReleaseBlock();

Expand Down Expand Up @@ -207,25 +207,25 @@ void OTAImageProcessorImpl::HandleProcessBlock(intptr_t context)
// 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;
while (blockReadOffset < block.size())
selissia marked this conversation as resolved.
Show resolved Hide resolved
{
writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset);
writeBufOffset++;
blockReadOffset++;
if (writeBufOffset == ALIGNMENT_BYTES)
{
writeBuffer[writeBufOffset] = *((block.data()) + blockReadOffset);
writeBufOffset++;
blockReadOffset++;
if(writeBufOffset == ALIGNMENT_BYTES)
{
writeBufOffset = 0;

CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);)
if (err)
{
ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock bootloader_eraseWriteStorage() error %ld", err);
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
return;
}
mWriteOffset += ALIGNMENT_BYTES;
imageProcessor->mParams.downloadedBytes += ALIGNMENT_BYTES;
}
writeBufOffset = 0;

CORE_CRITICAL_SECTION(err = bootloader_eraseWriteStorage(mSlotId, mWriteOffset, writeBuffer, ALIGNMENT_BYTES);)
if (err)
{
ChipLogError(SoftwareUpdate, "ERROR: In HandleProcessBlock bootloader_eraseWriteStorage() error %ld", err);
imageProcessor->mDownloader->EndDownload(CHIP_ERROR_WRITE_FAILED);
return;
}
mWriteOffset += ALIGNMENT_BYTES;
imageProcessor->mParams.downloadedBytes += ALIGNMENT_BYTES;
}
}

imageProcessor->mDownloader->FetchNextData();
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/EFR32/OTAImageProcessorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class OTAImageProcessorImpl : public OTAImageProcessorInterface

#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];
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
};
Expand Down