Skip to content

Commit

Permalink
[nrfconnect][ota] Change image checking condition for OTA.
Browse files Browse the repository at this point in the history
If we want to use confirming the new firmware update in the AppTask
Init method we cannot relay on the imageProcessor and instead of
that we need to call the mcuboot_swap_type function to verify
whether the swapping type is equal to REVERT.
  • Loading branch information
ArekBalysNordic committed Aug 31, 2023
1 parent c23665d commit 105fb22
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 55 deletions.
6 changes: 1 addition & 5 deletions examples/all-clusters-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
OtaConfirmNewImage();
#endif

// Initialize CHIP server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
OtaConfirmNewImage();
#endif

// Initialize CHIP server
Expand Down
6 changes: 1 addition & 5 deletions examples/light-switch-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
OtaConfirmNewImage();
#endif

// Initialize Timers
Expand Down
14 changes: 5 additions & 9 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ CHIP_ERROR AppTask::Init()
GetDFUOverSMP().ConfirmNewImage();
#endif

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
OtaConfirmNewImage();
#endif

// Initialize lighting device (PWM)
uint8_t minLightLevel = kDefaultMinLevel;
Clusters::LevelControl::Attributes::MinLevel::Get(kLightEndpointId, &minLightLevel);
Expand All @@ -217,15 +222,6 @@ CHIP_ERROR AppTask::Init()
}
mPWMDevice.SetCallbacks(ActionInitiated, ActionCompleted);

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
#endif

// Initialize CHIP server
#if CONFIG_CHIP_FACTORY_DATA
ReturnErrorOnFailure(mFactoryDataProvider.Init());
Expand Down
6 changes: 1 addition & 5 deletions examples/lock-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
OtaConfirmNewImage();
#endif

// Initialize CHIP server
Expand Down
23 changes: 13 additions & 10 deletions examples/platform/nrfconnect/util/OTAUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,23 @@ void InitBasicOTARequestor()
imageProcessor.TriggerFlashAction(ExternalFlashManager::Action::SLEEP);
}

CHIP_ERROR OtaConfirmNewImage()
void OtaConfirmNewImage()
{
CHIP_ERROR err = CHIP_NO_ERROR;
/* Check if the image is run in the REVERT mode and eventually */
/* confirm it to prevent reverting on the next boot. */
VerifyOrReturn(mcuboot_swap_type() == BOOT_SWAP_TYPE_REVERT);

OTAImageProcessorImpl & imageProcessor = GetOTAImageProcessor();
if (imageProcessor.IsFirstImageRun())
CHIP_ERROR err = System::MapErrorZephyr(boot_write_img_confirmed());
if (CHIP_NO_ERROR == err)
{
imageProcessor.SetImageConfirmed();
ChipLogProgress(SoftwareUpdate, "New firmware image confirmed");
}
else
{
CHIP_ERROR err = System::MapErrorZephyr(boot_write_img_confirmed());
if (CHIP_NO_ERROR == err)
{
imageProcessor.SetImageConfirmed();
}
ChipLogError(SoftwareUpdate, "Failed to confirm firmware image, it will be reverted on the next boot");
}
ChipLogError(SoftwareUpdate, "Failed to confirm firmware image, it will be reverted on the next boot");
return err;
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/nrfconnect/util/include/OTAUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void InitBasicOTARequestor();
* boot after the OTA update.
* Other CHIP_ERROR codes if the image could not be confirmed.
*/
CHIP_ERROR OtaConfirmNewImage();
void OtaConfirmNewImage();

#endif // CONFIG_CHIP_OTA_REQUESTOR

Expand Down
6 changes: 1 addition & 5 deletions examples/pump-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
OtaConfirmNewImage();
#endif

// Initialize CHIP server
Expand Down
6 changes: 1 addition & 5 deletions examples/pump-controller-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
OtaConfirmNewImage();
#endif

// Initialize CHIP server
Expand Down
6 changes: 1 addition & 5 deletions examples/window-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ CHIP_ERROR AppTask::Init()

#ifdef CONFIG_CHIP_OTA_REQUESTOR
/* OTA image confirmation must be done before the factory data init. */
err = OtaConfirmNewImage();
if (err != CHIP_NO_ERROR)
{
return err;
}
OtaConfirmNewImage();
#endif

// Initialize CHIP server
Expand Down

0 comments on commit 105fb22

Please sign in to comment.