[nrfconnect][ota] Change image checking condition for OTA. (#28983)
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.
diff --git a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp
index 7f9b4f8..217748c 100644
--- a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp
+++ b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp
@@ -180,11 +180,7 @@
#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
diff --git a/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp
index 783096c..6ec81df 100644
--- a/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp
+++ b/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp
@@ -139,11 +139,7 @@
#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
diff --git a/examples/light-switch-app/nrfconnect/main/AppTask.cpp b/examples/light-switch-app/nrfconnect/main/AppTask.cpp
index 6bc4138..b64f704 100644
--- a/examples/light-switch-app/nrfconnect/main/AppTask.cpp
+++ b/examples/light-switch-app/nrfconnect/main/AppTask.cpp
@@ -181,11 +181,7 @@
#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
diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp
index a2ad1d6..8bbddd6 100644
--- a/examples/lighting-app/nrfconnect/main/AppTask.cpp
+++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp
@@ -203,6 +203,11 @@
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);
@@ -217,15 +222,6 @@
}
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());
diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp
index ab5df56..17fa9e3 100644
--- a/examples/lock-app/nrfconnect/main/AppTask.cpp
+++ b/examples/lock-app/nrfconnect/main/AppTask.cpp
@@ -189,11 +189,7 @@
#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
diff --git a/examples/platform/nrfconnect/util/OTAUtil.cpp b/examples/platform/nrfconnect/util/OTAUtil.cpp
index f1c1c91..c642a90 100644
--- a/examples/platform/nrfconnect/util/OTAUtil.cpp
+++ b/examples/platform/nrfconnect/util/OTAUtil.cpp
@@ -66,20 +66,30 @@
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
diff --git a/examples/platform/nrfconnect/util/include/OTAUtil.h b/examples/platform/nrfconnect/util/include/OTAUtil.h
index 2e120f6..9c4c6d8 100644
--- a/examples/platform/nrfconnect/util/include/OTAUtil.h
+++ b/examples/platform/nrfconnect/util/include/OTAUtil.h
@@ -54,7 +54,7 @@
* 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
diff --git a/examples/pump-app/nrfconnect/main/AppTask.cpp b/examples/pump-app/nrfconnect/main/AppTask.cpp
index d21908b..b2406ed 100644
--- a/examples/pump-app/nrfconnect/main/AppTask.cpp
+++ b/examples/pump-app/nrfconnect/main/AppTask.cpp
@@ -162,11 +162,7 @@
#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
diff --git a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp
index f1b0fb1..9b00a54 100644
--- a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp
+++ b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp
@@ -160,11 +160,7 @@
#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
diff --git a/examples/window-app/nrfconnect/main/AppTask.cpp b/examples/window-app/nrfconnect/main/AppTask.cpp
index 5b80507..ed16dc1 100644
--- a/examples/window-app/nrfconnect/main/AppTask.cpp
+++ b/examples/window-app/nrfconnect/main/AppTask.cpp
@@ -167,11 +167,7 @@
#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