From 134821696b6b96d169a51ca25fb146de58541c7d Mon Sep 17 00:00:00 2001 From: yeaissa <133245269+yeaissa@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:40:26 +0100 Subject: [PATCH] [NXP][ZEPHYR] Add option to mark OTA image as permanent or as a test (#32721) * [NXP][ZEPHYR] Remove deprecated Kconfigs * [NXP][ZEPHYR] Add option to mark OTA image as permanent or as a test * [NXP][DOC] Update zephyr_ota doc * Restyled by prettier-markdown --------- Co-authored-by: Restyled.io --- config/nxp/chip-module/Kconfig | 20 +++++++++++++++++++ config/nxp/chip-module/Kconfig.defaults | 5 +---- docs/guides/nxp_zephyr_ota_software_update.md | 18 ++++++++++++++++- .../nxp/zephyr/ota/OTAImageProcessorImpl.cpp | 8 +++++++- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/config/nxp/chip-module/Kconfig b/config/nxp/chip-module/Kconfig index 7ee0917ebec555..ae95e1ce348f57 100644 --- a/config/nxp/chip-module/Kconfig +++ b/config/nxp/chip-module/Kconfig @@ -256,3 +256,23 @@ config CHIP_OTA_REQUESTOR_REBOOT_ON_APPLY Reboots the device automatically after downloading a new firmware update to swap the old and the new firmware images. The reboot happens only when a user consents to apply the firmware update. + +choice CHIP_OTA_REQUEST_UPGRADE_TYPE + prompt "Type of the upgrade to apply on new images" + default CHIP_OTA_REQUEST_UPGRADE_TEST + depends on CHIP_OTA_REQUESTOR + + config CHIP_OTA_REQUEST_UPGRADE_PERMANENT + bool "Mark the image as permanent" + help + The upgrade will be permanent on the next reboot. + No coming back to the old image. + + config CHIP_OTA_REQUEST_UPGRADE_TEST + bool "Mark the image as a test" + help + The upgrade will be marked as a test. + Image will be run on the next reboot, if confirmed it + becomes permanent, otherwise the new image is reverted. + +endchoice diff --git a/config/nxp/chip-module/Kconfig.defaults b/config/nxp/chip-module/Kconfig.defaults index 531a3f38245aad..178a9eddd6b057 100644 --- a/config/nxp/chip-module/Kconfig.defaults +++ b/config/nxp/chip-module/Kconfig.defaults @@ -127,7 +127,7 @@ choice NET_TC_THREAD_TYPE default NET_TC_THREAD_PREEMPTIVE endchoice -config NET_TCP_WORK_QUEUE_THREAD_PRIO +config NET_TCP_WORKER_PRIO default -16 config NET_TC_TX_THREAD_BASE_PRIO @@ -406,6 +406,3 @@ config FLASH_SHELL endif # SHELL endif - -config NXP_FW_LOADER_MONOLITHIC - default y if NXP_FW_LOADER diff --git a/docs/guides/nxp_zephyr_ota_software_update.md b/docs/guides/nxp_zephyr_ota_software_update.md index 430e0bfd81e694..a36ac3281cb116 100644 --- a/docs/guides/nxp_zephyr_ota_software_update.md +++ b/docs/guides/nxp_zephyr_ota_software_update.md @@ -114,7 +114,7 @@ and `CONFIG_MCUBOOT_SIGNATURE_KEY_FILE` needs to point to that same key. paths starts from the MCUBoot repository root. This option can be changed in: `config/nxp/app/bootloader.conf` -- `CONFIG_BOOT_SIGNATURE_KEY_FILE`: This is used for the application to be +- `CONFIG_MCUBOOT_SIGNATURE_KEY_FILE`: This is used for the application to be loaded by the bootloader. The path can be either absolute or relative. Relative paths starts from the west workspace location. This option can be changed in the application .conf files. @@ -124,6 +124,22 @@ Refer to those two files for more information: - [MCUBoot Config used for the MCUBoot Image](https://github.com/zephyrproject-rtos/mcuboot/blob/main/boot/zephyr/Kconfig) - [MCUBoot Config used for the application](https://github.com/zephyrproject-rtos/zephyr/blob/main/modules/Kconfig.mcuboot) +When an OTA image is received it can either be marked as permanent or as a test, +The Kconfig `CONFIG_CHIP_OTA_REQUEST_UPGRADE_TYPE` can choose one of those +configurations (Defined in `/config/nxp/chip-module/Kconfig`): + +- `CONFIG_CHIP_OTA_REQUEST_UPGRADE_PERMANENT`: From the next reboot, this + image will be run permanently. +- `CONFIG_CHIP_OTA_REQUEST_UPGRADE_TEST`: The image will be run on the next + reboot, but it will be reverted if it doesn't get confirmed. The image needs + to confirm itself to become permanent. + +By default, the upgrade type used is `CONFIG_CHIP_OTA_REQUEST_UPGRADE_TEST`, and +OTA image confirms itself during the initialization stage after the fundamental +parts of the application are initialized properly to make sure this new image +boots correctly. This confirmation is done by +`chip::NXP::App::OTARequestorInitiator::HandleSelfTest()`. + JLink can be used to flash the mixed binary at the base address 0x8000000, using the command : diff --git a/src/platform/nxp/zephyr/ota/OTAImageProcessorImpl.cpp b/src/platform/nxp/zephyr/ota/OTAImageProcessorImpl.cpp index 0d027b0407a5b8..59718e2fcc3919 100644 --- a/src/platform/nxp/zephyr/ota/OTAImageProcessorImpl.cpp +++ b/src/platform/nxp/zephyr/ota/OTAImageProcessorImpl.cpp @@ -28,6 +28,12 @@ static struct stream_flash_ctx stream; +#ifdef CONFIG_CHIP_OTA_REQUEST_UPGRADE_PERMANENT +#define UPDATE_TYPE BOOT_UPGRADE_PERMANENT +#else +#define UPDATE_TYPE BOOT_UPGRADE_TEST +#endif + namespace chip { namespace DeviceLayer { @@ -85,7 +91,7 @@ CHIP_ERROR OTAImageProcessorImpl::Abort() CHIP_ERROR OTAImageProcessorImpl::Apply() { // Schedule update of image - int err = boot_request_upgrade(BOOT_UPGRADE_PERMANENT); + int err = boot_request_upgrade(UPDATE_TYPE); #ifdef CONFIG_CHIP_OTA_REQUESTOR_REBOOT_ON_APPLY if (!err)