Skip to content

Commit

Permalink
[k32w] Replace boolean mShouldNotApply with an enum class
Browse files Browse the repository at this point in the history
Signed-off-by: marius-alex-tache <[email protected]>
  • Loading branch information
marius-alex-tache committed May 8, 2024
1 parent bad31e9 commit e3211ff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/platform/nxp/k32w/common/OTATlvProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ constexpr uint8_t au8Iv[] = { 0x00, 0x00, 0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x

CHIP_ERROR OTATlvProcessor::ApplyAction()
{
return mShouldNotApply ? CHIP_ERROR_OTA_PROCESSOR_SHOULD_NOT_APPLY : CHIP_NO_ERROR;
return mApplyState == ApplyState::kApply ? CHIP_NO_ERROR : CHIP_ERROR_OTA_PROCESSOR_DO_NOT_APPLY;
}

CHIP_ERROR OTATlvProcessor::Process(ByteSpan & block)
Expand Down Expand Up @@ -69,7 +69,7 @@ void OTATlvProcessor::ClearInternal()
mLength = 0;
mProcessedLength = 0;
mWasSelected = false;
mShouldNotApply = false;
mApplyState = ApplyState::kApply;
#if OTA_ENCRYPTION_ENABLE
mIVOffset = 0;
#endif
Expand Down
12 changes: 9 additions & 3 deletions src/platform/nxp/k32w/common/OTATlvProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace chip {
#define CHIP_ERROR_OTA_PROCESSOR_EEPROM_OFFSET CHIP_ERROR_TLV_PROCESSOR(0x0C)
#define CHIP_ERROR_OTA_PROCESSOR_EXTERNAL_STORAGE CHIP_ERROR_TLV_PROCESSOR(0x0D)
#define CHIP_ERROR_OTA_PROCESSOR_START_IMAGE CHIP_ERROR_TLV_PROCESSOR(0x0E)
#define CHIP_ERROR_OTA_PROCESSOR_SHOULD_NOT_APPLY CHIP_ERROR_TLV_PROCESSOR(0x0F)
#define CHIP_ERROR_OTA_PROCESSOR_DO_NOT_APPLY CHIP_ERROR_TLV_PROCESSOR(0x0F)

// Descriptor constants
constexpr size_t kVersionStringSize = 64;
Expand Down Expand Up @@ -77,6 +77,12 @@ struct OTATlvHeader
class OTATlvProcessor
{
public:
enum class ApplyState : uint8_t
{
kApply = 0,
kDoNotApply
};

virtual ~OTATlvProcessor() {}

virtual CHIP_ERROR Init() = 0;
Expand Down Expand Up @@ -140,13 +146,13 @@ class OTATlvProcessor
* Used by the default ApplyAction implementation.
*
* If something goes wrong during ExitAction of the TLV processor,
* then mShouldNotApply should be set to true and the image processor
* then mApplyState should be set to kDoNotApply and the image processor
* should abort. In this case, the BDX transfer was already finished
* and calling CancelImageUpdate will not abort the transfer, hence
* the device will reboot even though it should not have. If ApplyAction
* fails during HandleApply, then the process will be aborted.
*/
bool mShouldNotApply = false;
ApplyState mApplyState = ApplyState::kApply;
ProcessDescriptor mCallbackProcessDescriptor = nullptr;
};

Expand Down
4 changes: 2 additions & 2 deletions src/platform/nxp/k32w/k32w0/OTAFirmwareProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ CHIP_ERROR OTAFirmwareProcessor::ExitAction()
if (OTA_CommitImage(NULL) != gOtaSuccess_c)
{
ChipLogError(SoftwareUpdate, "Failed to commit firmware image.");
mShouldNotApply = true;
mApplyState = ApplyState::kDoNotApply;
return CHIP_ERROR_OTA_PROCESSOR_IMG_COMMIT;
}

if (OTA_ImageAuthenticate() != gOtaImageAuthPass_c)
{
ChipLogError(SoftwareUpdate, "Failed to authenticate firmware image.");
mShouldNotApply = true;
mApplyState = ApplyState::kDoNotApply;
return CHIP_ERROR_OTA_PROCESSOR_IMG_AUTH;
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/nxp/k32w/k32w1/OTAFirmwareProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ CHIP_ERROR OTAFirmwareProcessor::ExitAction()
if (OTA_CommitImage(NULL) != gOtaSuccess_c)
{
ChipLogError(SoftwareUpdate, "Failed to commit firmware image.");
mShouldNotApply = true;
mApplyState = ApplyState::kDoNotApply;
return CHIP_ERROR_OTA_PROCESSOR_IMG_COMMIT;
}

Expand Down

0 comments on commit e3211ff

Please sign in to comment.