|
21 | 21 | #include <platform/silabs/multi-ota/SiWx917/OTAWiFiFirmwareProcessor.h>
|
22 | 22 |
|
23 | 23 | #include <app/clusters/ota-requestor/OTARequestorInterface.h>
|
24 |
| - #include "wfx_host_events.h" |
25 | 24 | #include <platform/silabs/SilabsConfig.h>
|
26 | 25 | #ifdef __cplusplus
|
27 | 26 | extern "C" {
|
|
37 | 36 | #define RPS_HEADER 1
|
38 | 37 | #define RPS_DATA 2
|
39 | 38 |
|
40 |
| - #define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_NO_AP_FOUND |
| 39 | + #define SL_STATUS_FW_UPDATE_DONE SL_STATUS_SI91X_FW_UPDATE_DONE |
41 | 40 | uint8_t flag = RPS_HEADER;
|
42 | 41 |
|
43 | 42 | namespace chip {
|
|
47 | 46 |
|
48 | 47 | CHIP_ERROR OTAWiFiFirmwareProcessor::Init()
|
49 | 48 | {
|
50 |
| - ReturnErrorCodeIf(mCallbackProcessDescriptor == nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED); |
51 |
| - mAccumulator.Init(sizeof(Descriptor)); |
| 49 | + VerifyOrReturnError(mCallbackProcessDescriptor != nullptr, CHIP_OTA_PROCESSOR_CB_NOT_REGISTERED); |
| 50 | + mAccumulator.Init(sizeof(Descriptor)); |
52 | 51 | #if OTA_ENCRYPTION_ENABLE
|
53 | 52 | mUnalignmentNum = 0;
|
54 | 53 | #endif
|
|
70 | 69 |
|
71 | 70 | CHIP_ERROR OTAWiFiFirmwareProcessor::ProcessInternal(ByteSpan & block)
|
72 | 71 | {
|
73 |
| - int32_t status = SL_STATUS_OK; |
| 72 | + int32_t status = SL_STATUS_OK; |
74 | 73 | // Store the header of the OTA file
|
75 | 74 | static uint8_t writeBuffer[kAlignmentBytes] __attribute__((aligned(4))) = { 0 };
|
76 |
| - // Used to tranfer other block to processor |
| 75 | + // Used to transfer other blocks to the processor |
77 | 76 | static uint8_t writeDataBuffer[1024] __attribute__((aligned(4))) = { 0 };
|
78 | 77 |
|
79 | 78 | if (!mDescriptorProcessed)
|
80 | 79 | {
|
81 | 80 | ReturnErrorOnFailure(ProcessDescriptor(block));
|
82 | 81 | #if OTA_ENCRYPTION_ENABLE
|
83 |
| - /* 16 bytes to used to store undecrypted data because of unalignment */ |
| 82 | + // 16 bytes used to store undecrypted data due to unalignment |
84 | 83 | mAccumulator.Init(requestedOtaMaxBlockSize + 16);
|
85 | 84 | #endif
|
86 | 85 | }
|
87 | 86 |
|
88 | 87 | #if OTA_ENCRYPTION_ENABLE
|
89 |
| - MutableByteSpan mBlock = MutableByteSpan(mAccumulator.data(), mAccumulator.GetThreshold()); |
| 88 | + MutableByteSpan mBlock(mAccumulator.data(), mAccumulator.GetThreshold()); |
90 | 89 | memcpy(&mBlock[0], &mBlock[requestedOtaMaxBlockSize], mUnalignmentNum);
|
91 | 90 | memcpy(&mBlock[mUnalignmentNum], block.data(), block.size());
|
92 | 91 |
|
93 | 92 | if (mUnalignmentNum + block.size() < requestedOtaMaxBlockSize)
|
94 | 93 | {
|
95 |
| - uint32_t mAlignmentNum = (mUnalignmentNum + block.size()) / 16; |
96 |
| - mAlignmentNum = mAlignmentNum * 16; |
97 |
| - mUnalignmentNum = (mUnalignmentNum + block.size()) % 16; |
| 94 | + uint32_t mAlignmentNum = (mUnalignmentNum + block.size()) / 16 * 16; |
| 95 | + mUnalignmentNum = (mUnalignmentNum + block.size()) % 16; |
98 | 96 | memcpy(&mBlock[requestedOtaMaxBlockSize], &mBlock[mAlignmentNum], mUnalignmentNum);
|
99 | 97 | mBlock.reduce_size(mAlignmentNum);
|
100 | 98 | }
|
|
109 | 107 | #endif
|
110 | 108 |
|
111 | 109 | if (flag == RPS_HEADER)
|
112 |
| - { |
113 |
| - memcpy(&writeBuffer, block.data(), kAlignmentBytes); |
114 |
| - // Send RPS header which is received as first chunk |
| 110 | + { |
| 111 | + memcpy(writeBuffer, block.data(), kAlignmentBytes); |
| 112 | + // Send RPS header received as the first chunk |
115 | 113 | status = sl_si91x_fwup_start(writeBuffer);
|
116 | 114 | status = sl_si91x_fwup_load(writeBuffer, kAlignmentBytes);
|
117 |
| - flag = RPS_DATA; |
118 |
| - memcpy(&writeDataBuffer, block.data() + kAlignmentBytes, (block.size() - kAlignmentBytes)); |
119 |
| - status = sl_si91x_fwup_load(writeDataBuffer, (block.size() - kAlignmentBytes)); |
120 |
| - } |
| 115 | + flag = RPS_DATA; |
| 116 | + memcpy(writeDataBuffer, block.data() + kAlignmentBytes, block.size() - kAlignmentBytes); |
| 117 | + status = sl_si91x_fwup_load(writeDataBuffer, block.size() - kAlignmentBytes); |
| 118 | + } |
121 | 119 | else if (flag == RPS_DATA)
|
122 | 120 | {
|
123 |
| - memcpy(&writeDataBuffer, block.data(), block.size()); |
| 121 | + memcpy(writeDataBuffer, block.data(), block.size()); |
124 | 122 | // Send RPS content
|
125 | 123 | status = sl_si91x_fwup_load(writeDataBuffer, block.size());
|
126 | 124 | if (status != SL_STATUS_OK)
|
127 | 125 | {
|
128 |
| - // When TA recived all the blocks it will return SL_STATUS_FW_UPDATE_DONE status |
129 | 126 | if (status == SL_STATUS_FW_UPDATE_DONE)
|
130 | 127 | {
|
131 | 128 | mReset = true;
|
|
162 | 159 | // send system reset request to reset the MCU and upgrade the m4 image
|
163 | 160 | ChipLogProgress(SoftwareUpdate, "SoC Soft Reset initiated!");
|
164 | 161 | // Reboots the device
|
165 |
| - sl_si91x_soc_soft_reset(); |
| 162 | + sl_si91x_soc_nvic_reset(); |
166 | 163 | #endif
|
167 | 164 | }
|
168 | 165 | return CHIP_NO_ERROR;
|
|
0 commit comments