Skip to content

Commit

Permalink
Adds changes for the updated wifi firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
shgutte committed Feb 20, 2025
1 parent db87cd5 commit 61e095a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
11 changes: 10 additions & 1 deletion src/platform/silabs/multi-ota/OTAHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::ProcessDescriptor(void * descriptor

CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit()
{
auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance();

#ifndef SLI_SI91X_MCU_INTERFACE
static chip::OTAFirmwareProcessor sApplicationProcessor;
static chip::OTAFactoryDataProcessor sFactoryDataProcessor;

sApplicationProcessor.RegisterDescriptorCallback(ProcessDescriptor);
sFactoryDataProcessor.RegisterDescriptorCallback(ProcessDescriptor);

auto & imageProcessor = chip::OTAMultiImageProcessorImpl::GetDefaultInstance();
ReturnErrorOnFailure(
imageProcessor.RegisterProcessor(static_cast<uint32_t>(OTAProcessorTag::kApplicationProcessor), &sApplicationProcessor));
ReturnErrorOnFailure(
imageProcessor.RegisterProcessor(static_cast<uint32_t>(OTAProcessorTag::kFactoryDataProcessor), &sFactoryDataProcessor));
#endif

#if OTA_TEST_CUSTOM_TLVS
static chip::OTACustomProcessor customProcessor1;
Expand All @@ -75,5 +78,11 @@ CHIP_ERROR chip::OTAMultiImageProcessorImpl::OtaHookInit()
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(9, &customProcessor2));
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(10, &customProcessor3));
#endif

#ifdef SL_WIFI
static chip::OTAWiFiFirmwareProcessor sWifiFirmwareProcessor;
sWifiFirmwareProcessor.RegisterDescriptorCallback(ProcessDescriptor);
ReturnErrorOnFailure(imageProcessor.RegisterProcessor(static_cast<uint32_t>(OTAProcessorTag::kWiFiProcessor), &sWifiFirmwareProcessor));
#endif
return CHIP_NO_ERROR;
}
2 changes: 2 additions & 0 deletions src/platform/silabs/multi-ota/OTAMultiImageProcessorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ void OTAMultiImageProcessorImpl::HandlePrepareDownload(intptr_t context)

ChipLogProgress(SoftwareUpdate, "HandlePrepareDownload: started");

#ifndef SLI_SI91X_MCU_INTERFACE // required for 917 NCP
CORE_CRITICAL_SECTION(bootloader_init();)
#endif

imageProcessor->mParams.downloadedBytes = 0;

Expand Down
39 changes: 18 additions & 21 deletions src/platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h>

#include <app/clusters/ota-requestor/OTARequestorInterface.h>
#include "wfx_host_events.h"
#include <platform/silabs/SilabsConfig.h>
#ifdef __cplusplus
extern "C" {
Expand All @@ -37,7 +36,7 @@
#define RPS_HEADER 1
#define RPS_DATA 2

#define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND
#define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_FW_UPDATE_DONE
uint8_t flag = RPS_HEADER;

namespace chip {
Expand All @@ -47,8 +46,8 @@

CHIP_ERROR OTAWiFiFirmwareProcessor::Init()
{
ReturnErrorCodeIf(mCallbackProcessDescriptor == nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED);
mAccumulator.Init(sizeof(Descriptor));
VerifyOrReturnError(mCallbackProcessDescriptor != nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED);
mAccumulator.Init(sizeof(Descriptor));
#if OTA_ENCRYPTION_ENABLE
mUnalignmentNum = 0;
#endif
Expand All @@ -70,31 +69,30 @@

CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block)
{
int32_t status = SL_STATUS_OK;
int32_t status = SL_STATUS_OK;
// Store the header of the OTA file
static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 };
// Used to tranfer other block to processor
// Used to transfer other blocks to the processor
static uint8_t writeDataBuffer[1024] __attribute__((aligned(4))) = { 0 };

if (!mDescriptorProcessed)
{
ReturnErrorOnFailure(ProcessDescriptor(block));
#if OTA_ENCRYPTION_ENABLE
/* 16 bytes to used to store undecrypted data because of unalignment */
// 16 bytes used to store undecrypted data due to unalignment
mAccumulator.Init(requestedOtaMaxBlockSize + 16);
#endif
}

#if OTA_ENCRYPTION_ENABLE
MutableByteSpan mBlock = MutableByteSpan(mAccumulator.data(), mAccumulator.GetThreshold());
MutableByteSpan mBlock(mAccumulator.data(), mAccumulator.GetThreshold());
memcpy(&mBlock[0], &mBlock[requestedOtaMaxBlockSize], mUnalignmentNum);
memcpy(&mBlock[mUnalignmentNum], block.data(), block.size());

if (mUnalignmentNum + block.size() < requestedOtaMaxBlockSize)
{
uint32_t mAlignmentNum = (mUnalignmentNum + block.size()) / 16;
mAlignmentNum = mAlignmentNum * 16;
mUnalignmentNum = (mUnalignmentNum + block.size()) % 16;
uint32_t mAlignmentNum = (mUnalignmentNum + block.size()) / 16 * 16;
mUnalignmentNum = (mUnalignmentNum + block.size()) % 16;
memcpy(&mBlock[requestedOtaMaxBlockSize], &mBlock[mAlignmentNum], mUnalignmentNum);
mBlock.reduce_size(mAlignmentNum);
}
Expand All @@ -109,23 +107,22 @@
#endif

if (flag == RPS_HEADER)
{
memcpy(&writeBuffer, block.data(), kAlignmentBytes);
// Send RPS header which is received as first chunk
{
memcpy(writeBuffer, block.data(), kAlignmentBytes);
// Send RPS header received as the first chunk
status = sl_si91x_fwup_start(writeBuffer);
status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes);
flag = RPS_DATA;
memcpy(&writeDataBuffer, block.data() + kAlignmentBytes, (block.size() - kAlignmentBytes));
status = sl_si91x_fwup_load(writeDataBuffer, (block.size() - kAlignmentBytes));
}
flag = RPS_DATA;
memcpy(writeDataBuffer, block.data() + kAlignmentBytes, block.size() - kAlignmentBytes);
status = sl_si91x_fwup_load(writeDataBuffer, block.size() - kAlignmentBytes);
}
else if (flag == RPS_DATA)
{
memcpy(&writeDataBuffer, block.data(), block.size());
memcpy(writeDataBuffer, block.data(), block.size());
// Send RPS content
status = sl_si91x_fwup_load(writeDataBuffer, block.size());
if (status != SL_STATUS_OK)
{
// When TA recived all the blocks it will return SL_STATUS_FW_UPDATE_DONE status
if (status == SL_STATUS_FW_UPDATE_DONE)
{
mReset = true;
Expand Down Expand Up @@ -162,7 +159,7 @@
// send system reset request to reset the MCU and upgrade the m4 image
ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!");
// Reboots the device
sl_si91x_soc_soft_reset();
sl_si91x_soc_nvic_reset();
#endif
}
return CHIP_NO_ERROR;
Expand Down

0 comments on commit 61e095a

Please sign in to comment.