Skip to content

Commit 7a6eddd

Browse files
[NXP][platform][common] Avoid using static state variables in OTA firmware processor (project-chip#41944)
Using function local static state variables such as "ulCrtAddr" and "ulEraseLen" in the OTAFirmwareProcessor::ProcessInternal method causes issues when OTA transfers are interrupted and then resumed because the function local variables cannot be accessed (and reset) by other class methods (such as OTAFirmwareProcessor::Clear or OTAFirmwareProcessor::AbortAction). The use of function local state variables was dropped and the SDK wireless framework OTA support layer is now in charge of managing block addresses and erases. Reviewed-by: Dina Benamar <[email protected]> Signed-off-by: Marian Chereji <[email protected]>
1 parent acbbe92 commit 7a6eddd

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/platform/nxp/common/ota/OTAFirmwareProcessor.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ CHIP_ERROR OTAFirmwareProcessor::Clear()
6868
CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block)
6969
{
7070
otaResult_t status;
71-
static uint32_t ulEraseLen = 0;
72-
static uint32_t ulCrtAddr = 0;
7371

7472
if (!mDescriptorProcessed)
7573
{
@@ -102,22 +100,11 @@ CHIP_ERROR OTAFirmwareProcessor::ProcessInternal(ByteSpan & block)
102100
OTATlvProcessor::vOtaProcessInternalEncryption(mBlock);
103101
#endif
104102

105-
ulCrtAddr += block.size();
106-
107-
if (ulCrtAddr >= ulEraseLen)
108-
{
109-
ulEraseLen += 0x1000; // flash sector size
110-
111-
status = OTA_MakeHeadRoomForNextBlock(block.size(), OTAImageProcessorImpl::FetchNextData, 0);
112-
if (gOtaSuccess_c != status)
113-
{
114-
ChipLogError(SoftwareUpdate, "Failed to make room for next block. Status: %d", status);
115-
return CHIP_ERROR_OTA_PROCESSOR_MAKE_ROOM;
116-
}
117-
}
118-
else
103+
status = OTA_MakeHeadRoomForNextBlock(block.size(), OTAImageProcessorImpl::FetchNextData, 0);
104+
if (gOtaSuccess_c != status)
119105
{
120-
OTAImageProcessorImpl::FetchNextData(0);
106+
ChipLogError(SoftwareUpdate, "Failed to make room for next block. Status: %d", status);
107+
return CHIP_ERROR_OTA_PROCESSOR_MAKE_ROOM;
121108
}
122109

123110
#if OTA_ENCRYPTION_ENABLE

0 commit comments

Comments
 (0)