Skip to content

Commit

Permalink
[nrfconnect][ota] Change image checking condition for OTA. (#28983)
Browse files Browse the repository at this point in the history
If we want to confirm the new firmware update in the AppTask Init
method we cannot rely on the imageProcessor. Instead, for the nRF53
target we should check if the image has been confirmed already,
and if not, confirm it, for targets other than nRF53
we should use the  mcuboot_swap_type function to verify whether
the swapping type is equal to REVERT before verifying the image.
  • Loading branch information
ArekBalysNordic authored and pull[bot] committed Oct 24, 2023
1 parent 7f82997 commit 2356280
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 50 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
20 changes: 15 additions & 5 deletions examples/platform/nrfconnect/util/OTAUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,30 @@ void InitBasicOTARequestor()
imageProcessor.TriggerFlashAction(ExternalFlashManager::Action::SLEEP);
}

CHIP_ERROR OtaConfirmNewImage()
void OtaConfirmNewImage()
{
CHIP_ERROR err = CHIP_NO_ERROR;
#ifndef CONFIG_SOC_SERIES_NRF53X
/* Check if the image is run in the REVERT mode and eventually
confirm it to prevent reverting on the next boot.
On nRF53 target there is not way to verify current swap type
because we use permanent swap so we can skip it. */
VerifyOrReturn(mcuboot_swap_type() == BOOT_SWAP_TYPE_REVERT);
#endif

OTAImageProcessorImpl & imageProcessor = GetOTAImageProcessor();
if (imageProcessor.IsFirstImageRun())
if (!boot_is_img_confirmed())
{
CHIP_ERROR err = System::MapErrorZephyr(boot_write_img_confirmed());
if (CHIP_NO_ERROR == err)
{
imageProcessor.SetImageConfirmed();
ChipLogProgress(SoftwareUpdate, "New firmware image confirmed");
}
else
{
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 2356280

Please sign in to comment.