Skip to content

Commit

Permalink
Fix restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
pankore committed Feb 21, 2022
1 parent 76741f9 commit bd25574
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/platform/Ameba/AmebaOTAImageProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ void AmebaOTAImageProcessor::HandleProcessBlock(intptr_t context)
return;
}

ByteSpan block = imageProcessor->mBlock;
CHIP_ERROR error = imageProcessor->ProcessHeader(block);
ByteSpan block = imageProcessor->mBlock;
CHIP_ERROR error = imageProcessor->ProcessHeader(block);
uint8_t HeaderOffset = 32 - imageProcessor->RemainHeader;

#if defined(CONFIG_PLATFORM_8721D)
Expand All @@ -193,9 +193,10 @@ void AmebaOTAImageProcessor::HandleProcessBlock(intptr_t context)
memcpy(imageProcessor->AmebaHeader + HeaderOffset, block.data(), imageProcessor->RemainHeader);
imageProcessor->pOtaTgtHdr = (update_ota_target_hdr *) ota_update_malloc(sizeof(update_ota_target_hdr));

memcpy(imageProcessor->pOtaTgtHdr, imageProcessor->AmebaHeader, 8); // Store FwVer, HdrNum
memcpy(imageProcessor->pOtaTgtHdr, imageProcessor->AmebaHeader, 8); // Store FwVer, HdrNum
memcpy(&(imageProcessor->pOtaTgtHdr->FileImgHdr[0].ImgId), imageProcessor->AmebaHeader + 8, 4); // Store OTA id
memcpy(&(imageProcessor->pOtaTgtHdr->FileImgHdr[0].ImgHdrLen), imageProcessor->AmebaHeader + 12, 16); // Store ImgHdrLen, Checksum, ImgLen, Offset
memcpy(&(imageProcessor->pOtaTgtHdr->FileImgHdr[0].ImgHdrLen), imageProcessor->AmebaHeader + 12,
16); // Store ImgHdrLen, Checksum, ImgLen, Offset

if (imageProcessor->ota_target_index == OTA_INDEX_1)
imageProcessor->pOtaTgtHdr->FileImgHdr[0].FlashAddr = LS_IMG2_OTA1_ADDR;
Expand All @@ -222,7 +223,8 @@ void AmebaOTAImageProcessor::HandleProcessBlock(intptr_t context)

// Erase update partition
ChipLogProgress(SoftwareUpdate, "Erasing target partition...");
erase_ota_target_flash(imageProcessor->pOtaTgtHdr->FileImgHdr[0].FlashAddr, imageProcessor->pOtaTgtHdr->FileImgHdr[0].ImgLen);
erase_ota_target_flash(imageProcessor->pOtaTgtHdr->FileImgHdr[0].FlashAddr,
imageProcessor->pOtaTgtHdr->FileImgHdr[0].ImgLen);
ChipLogProgress(SoftwareUpdate, "Erased partition OTA%d", imageProcessor->ota_target_index + 1);

// Set RemainBytes to image length, excluding 8bytes of signature
Expand All @@ -235,7 +237,7 @@ void AmebaOTAImageProcessor::HandleProcessBlock(intptr_t context)
imageProcessor->signature = &(imageProcessor->pOtaTgtHdr->Sign[0][0]);

// Store the signature temporarily
uint8_t * tempbufptr = const_cast<uint8_t*> (block.data() + imageProcessor->pOtaTgtHdr->FileImgHdr[0].Offset);
uint8_t * tempbufptr = const_cast<uint8_t *>(block.data() + imageProcessor->pOtaTgtHdr->FileImgHdr[0].Offset);
memcpy(imageProcessor->signature, tempbufptr, 8);
tempbufptr += 8;

Expand Down Expand Up @@ -299,7 +301,8 @@ void AmebaOTAImageProcessor::HandleProcessBlock(intptr_t context)
if (imageProcessor->block_len > 0)
{
device_mutex_lock(RT_DEV_LOCK_FLASH);
if (flash_burst_write(&flash_ota, imageProcessor->flash_addr + 32, imageProcessor->block_len, block.data() + 32) < 0)
if (flash_burst_write(&flash_ota, imageProcessor->flash_addr + 32, imageProcessor->block_len, block.data() + 32) <
0)
{
device_mutex_unlock(RT_DEV_LOCK_FLASH);
ChipLogError(SoftwareUpdate, "Write to flash failed");
Expand Down Expand Up @@ -334,7 +337,8 @@ void AmebaOTAImageProcessor::HandleProcessBlock(intptr_t context)
if (imageProcessor->block_len > 0)
{
device_mutex_lock(RT_DEV_LOCK_FLASH);
if (flash_burst_write(&flash_ota, imageProcessor->flash_addr + 32 + imageProcessor->size, imageProcessor->block_len, block.data()) < 0)
if (flash_burst_write(&flash_ota, imageProcessor->flash_addr + 32 + imageProcessor->size, imageProcessor->block_len,
block.data()) < 0)
{
device_mutex_unlock(RT_DEV_LOCK_FLASH);
ChipLogError(SoftwareUpdate, "Write to flash failed");
Expand Down
8 changes: 4 additions & 4 deletions src/platform/Ameba/AmebaOTAImageProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#include <app/clusters/ota-requestor/OTADownloader.h>
#include <cstring>
#include <device_lock.h>
#include <lib/core/OTAImageHeader.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/OTAImageProcessor.h>
#include <lib/core/OTAImageHeader.h>

#if defined(CONFIG_PLATFORM_8710C)
#include "ota_8710c.h"
Expand Down Expand Up @@ -79,9 +79,9 @@ class AmebaOTAImageProcessor : public OTAImageProcessorInterface
#endif
MutableByteSpan mBlock;
OTADownloader * mDownloader;
uint32_t size = 0;
uint8_t RemainHeader = 32;
uint8_t AmebaHeader[32] = {0};
uint32_t size = 0;
uint8_t RemainHeader = 32;
uint8_t AmebaHeader[32] = { 0 };
uint32_t flash_addr;
OTAImageHeaderParser mHeaderParser;
uint32_t mSoftwareVersion;
Expand Down

0 comments on commit bd25574

Please sign in to comment.