From 905a79f4c14ec757e668540d948c0df94d686836 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 20 Feb 2025 13:27:32 +0000 Subject: [PATCH 1/7] boards: nordic: Add boot mode chosen nodes Adds boot mode chosen nodes to the nrf5340dk, nrf52840dk and nrf54l15dk boards Signed-off-by: Jamie McCrae --- boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts | 11 +++++++++++ boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts | 11 +++++++++++ .../nrf54l15dk/nrf54l_05_10_15_cpuapp_common.dtsi | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts b/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts index 03a74b760020..0e61ee5654ca 100644 --- a/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts +++ b/boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts @@ -21,6 +21,7 @@ zephyr,bt-mon-uart = &uart0; zephyr,bt-c2h-uart = &uart0; zephyr,ieee802154 = &ieee802154; + zephyr,boot-mode = &boot_mode0; }; leds { @@ -276,3 +277,13 @@ zephyr_udc0: &usbd { compatible = "nordic,nrf-usbd"; status = "okay"; }; + +&gpregret1 { + status = "okay"; + + boot_mode0: boot_mode@0 { + compatible = "zephyr,retention"; + status = "okay"; + reg = <0x0 0x1>; + }; +}; diff --git a/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts b/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts index cf21413ede41..c459033b46ac 100644 --- a/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts +++ b/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts @@ -18,5 +18,16 @@ zephyr,code-partition = &slot0_partition; zephyr,sram-secure-partition = &sram0_s; zephyr,sram-non-secure-partition = &sram0_ns; + zephyr,boot-mode = &boot_mode0; + }; +}; + +&gpregret1 { + status = "okay"; + + boot_mode0: boot_mode@0 { + compatible = "zephyr,retention"; + status = "okay"; + reg = <0x0 0x1>; }; }; diff --git a/boards/nordic/nrf54l15dk/nrf54l_05_10_15_cpuapp_common.dtsi b/boards/nordic/nrf54l15dk/nrf54l_05_10_15_cpuapp_common.dtsi index 323ebfd1a1b7..eade6178a6a5 100644 --- a/boards/nordic/nrf54l15dk/nrf54l_05_10_15_cpuapp_common.dtsi +++ b/boards/nordic/nrf54l15dk/nrf54l_05_10_15_cpuapp_common.dtsi @@ -18,6 +18,7 @@ zephyr,flash-controller = &rram_controller; zephyr,flash = &cpuapp_rram; zephyr,ieee802154 = &ieee802154; + zephyr,boot-mode = &boot_mode0; }; }; @@ -91,6 +92,16 @@ status = "okay"; }; +&gpregret1 { + status = "okay"; + + boot_mode0: boot_mode@0 { + compatible = "zephyr,retention"; + status = "okay"; + reg = <0x0 0x1>; + }; +}; + &spi00 { status = "okay"; cs-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>; From 91df0aef0dc31dabee96e1ac5ff46f4cbfa666b7 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 20 Feb 2025 13:28:12 +0000 Subject: [PATCH 2/7] tests: boot: mcuboot_recovery_retention: Remove boot mode overlay Removes setting the boot mode device in the default test overlay file as this is now set by the board Signed-off-by: Jamie McCrae --- .../boards/nrf52840dk_nrf52840.overlay | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/tests/boot/mcuboot_recovery_retention/boards/nrf52840dk_nrf52840.overlay b/tests/boot/mcuboot_recovery_retention/boards/nrf52840dk_nrf52840.overlay index bd69d21527d9..425ac4ec0714 100644 --- a/tests/boot/mcuboot_recovery_retention/boards/nrf52840dk_nrf52840.overlay +++ b/tests/boot/mcuboot_recovery_retention/boards/nrf52840dk_nrf52840.overlay @@ -2,21 +2,10 @@ / { chosen { - zephyr,boot-mode = &boot_mode0; zephyr,uart-mcumgr = &cdc_acm_uart; }; }; -&gpregret1 { - status = "okay"; - - boot_mode0: boot_mode@0 { - compatible = "zephyr,retention"; - status = "okay"; - reg = <0x0 0x1>; - }; -}; - &zephyr_udc0 { status = "okay"; From 5211609b819ac865f0820db2e3e989d114c487a4 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 21 Feb 2025 07:49:53 +0000 Subject: [PATCH 3/7] tests: boot: mcuboot_data_sharing: Remove boot_info node Removes a node from the devicetree overlay for a board for this test Signed-off-by: Jamie McCrae --- .../mcuboot_data_sharing/boards/nrf52840dk_nrf52840.overlay | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/boot/mcuboot_data_sharing/boards/nrf52840dk_nrf52840.overlay b/tests/boot/mcuboot_data_sharing/boards/nrf52840dk_nrf52840.overlay index fe47e1cd4053..dec5e057941c 100644 --- a/tests/boot/mcuboot_data_sharing/boards/nrf52840dk_nrf52840.overlay +++ b/tests/boot/mcuboot_data_sharing/boards/nrf52840dk_nrf52840.overlay @@ -1,6 +1,10 @@ /* SPDX-License-Identifier: Apache-2.0 */ / { + chosen { + /delete-property/ zephyr,boot-mode; + }; + sram@2003FC00 { compatible = "zephyr,memory-region", "mmio-sram"; reg = <0x2003FC00 DT_SIZE_K(1)>; From 720c5747ecef82fa16cb385f531380ed24942b08 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Fri, 21 Feb 2025 07:50:38 +0000 Subject: [PATCH 4/7] samples: mgmt: mcumgr: smp_svr: Remove boot_info node Removes a node from the devicetree overlay for a board for this sample Signed-off-by: Jamie McCrae --- .../sysbuild/nrf52840dk_nrf52840_mcuboot_ram_load.overlay | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf52840dk_nrf52840_mcuboot_ram_load.overlay b/samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf52840dk_nrf52840_mcuboot_ram_load.overlay index fbd19b0b74de..90d209ddfe84 100644 --- a/samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf52840dk_nrf52840_mcuboot_ram_load.overlay +++ b/samples/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf52840dk_nrf52840_mcuboot_ram_load.overlay @@ -1,4 +1,12 @@ +&gpregret1 { + /delete-node/ boot_mode@0; +}; + / { + chosen { + /delete-property/ zephyr,boot-mode; + }; + sram@2003FC00 { compatible = "zephyr,memory-region", "mmio-sram"; reg = <0x2003FC00 DT_SIZE_K(1)>; From 9e818b2214a95917b5f85814d4ae991d019abe46 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 20 Feb 2025 13:39:30 +0000 Subject: [PATCH 5/7] sysbuild: Add firmware loader application type support Adds support for setting up a firmware loader image in a build, which can also optionally automatically configure MCUboot and the application image to be able to boot the firmware loader image using the retention subsystem Signed-off-by: Jamie McCrae --- .../cmake/modules/sysbuild_extensions.cmake | 2 +- .../BOOTLOADER_image_default.cmake | 11 +++++- .../FIRMWARE_LOADER_image_default.cmake | 22 +++++++++++ .../MAIN_image_default.cmake | 11 +++++- share/sysbuild/images/CMakeLists.txt | 1 + share/sysbuild/images/Kconfig | 1 + share/sysbuild/images/bootloader/Kconfig | 8 ++++ .../images/firmware_loader/CMakeLists.txt | 11 ++++++ share/sysbuild/images/firmware_loader/Kconfig | 37 +++++++++++++++++++ 9 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 share/sysbuild/image_configurations/FIRMWARE_LOADER_image_default.cmake create mode 100644 share/sysbuild/images/firmware_loader/CMakeLists.txt create mode 100644 share/sysbuild/images/firmware_loader/Kconfig diff --git a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake index a0ca87c4253c..ec45fbdef5de 100644 --- a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake @@ -216,7 +216,7 @@ endfunction() # and debugging. # function(ExternalZephyrProject_Add) - set(app_types MAIN BOOTLOADER) + set(app_types MAIN BOOTLOADER FIRMWARE_LOADER) cmake_parse_arguments(ZBUILD "" "APPLICATION;BOARD;BOARD_REVISION;SOURCE_DIR;APP_TYPE;BUILD_ONLY" "" ${ARGN}) if(ZBUILD_UNPARSED_ARGUMENTS) diff --git a/share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake b/share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake index 75b0bc3668aa..9125de71fac6 100644 --- a/share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake +++ b/share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake @@ -29,10 +29,17 @@ elseif(SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP OR SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WI set(bootmode CONFIG_BOOT_DIRECT_XIP) elseif(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD) set(bootmode CONFIG_BOOT_RAM_LOAD) -elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER) - set(bootmode CONFIG_BOOT_FIRMWARE_LOADER) elseif(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP_RAM_LOAD) set(bootmode CONFIG_SINGLE_APPLICATION_SLOT_RAM_LOAD) +elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER) + set(bootmode CONFIG_BOOT_FIRMWARE_LOADER) + + if(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER_BOOT_MODE_ENTRANCE) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETAINED_MEM y) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION y) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION_BOOT_MODE y) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_FIRMWARE_LOADER_BOOT_MODE y) + endif() endif() foreach(loopbootmode ${bootmodes}) diff --git a/share/sysbuild/image_configurations/FIRMWARE_LOADER_image_default.cmake b/share/sysbuild/image_configurations/FIRMWARE_LOADER_image_default.cmake new file mode 100644 index 000000000000..c4edc7e3daf5 --- /dev/null +++ b/share/sysbuild/image_configurations/FIRMWARE_LOADER_image_default.cmake @@ -0,0 +1,22 @@ +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +# This sysbuild CMake file sets the sysbuild controlled settings as properties +# on a firmware updater image. + +set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOOTLOADER_MCUBOOT}") +set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE + "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}" +) +set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE + "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}" +) + +if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE") + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y) +else() + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n) +endif() + +set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER y) diff --git a/share/sysbuild/image_configurations/MAIN_image_default.cmake b/share/sysbuild/image_configurations/MAIN_image_default.cmake index 653f7328892f..a6c29c8d7569 100644 --- a/share/sysbuild/image_configurations/MAIN_image_default.cmake +++ b/share/sysbuild/image_configurations/MAIN_image_default.cmake @@ -39,9 +39,16 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT) set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD y) set_config_bool(${ZCMAKE_APPLICATION} CONFIG_XIP n) set_config_int(${ZCMAKE_APPLICATION} CONFIG_FLASH_SIZE 0) - elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER) - set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER y) elseif(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP_RAM_LOAD) set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP_RAM_LOAD y) + elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER y) + + if(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER_BOOT_MODE_ENTRANCE) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_REBOOT y) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETAINED_MEM y) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION y) + set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION_BOOT_MODE y) + endif() endif() endif() diff --git a/share/sysbuild/images/CMakeLists.txt b/share/sysbuild/images/CMakeLists.txt index 1d9e381fa5c4..b6276a311c40 100644 --- a/share/sysbuild/images/CMakeLists.txt +++ b/share/sysbuild/images/CMakeLists.txt @@ -12,6 +12,7 @@ ExternalZephyrProject_Add( # This allows for MCUboot to be included. sysbuild_add_subdirectory(bootloader) +sysbuild_add_subdirectory(firmware_loader) # Include zephyr modules generated sysbuild CMake file. foreach(SYSBUILD_CURRENT_MODULE_NAME ${SYSBUILD_MODULE_NAMES}) diff --git a/share/sysbuild/images/Kconfig b/share/sysbuild/images/Kconfig index 616b0a7c23d4..f247a0bd64a0 100644 --- a/share/sysbuild/images/Kconfig +++ b/share/sysbuild/images/Kconfig @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Apache-2.0 rsource "bootloader/Kconfig" +rsource "firmware_loader/Kconfig" diff --git a/share/sysbuild/images/bootloader/Kconfig b/share/sysbuild/images/bootloader/Kconfig index 54e429fcc97e..7a416f2fe239 100644 --- a/share/sysbuild/images/bootloader/Kconfig +++ b/share/sysbuild/images/bootloader/Kconfig @@ -141,6 +141,14 @@ config MCUBOOT_MODE_SINGLE_APP_RAM_LOAD endchoice +config MCUBOOT_MODE_FIRMWARE_UPDATER_BOOT_MODE_ENTRANCE + bool "Firmware updater retention boot mode entrance" + depends on MCUBOOT_MODE_FIRMWARE_UPDATER + help + Will enable retained memory, retention and the boot mode module in MCUboot and the main + application so that it can be used to force booting the firmware loader application + image. This needs the ``zephyr,boot-mode`` chosen node to be correctly configured. + config SIGNATURE_TYPE string default "NONE" if BOOT_SIGNATURE_TYPE_NONE diff --git a/share/sysbuild/images/firmware_loader/CMakeLists.txt b/share/sysbuild/images/firmware_loader/CMakeLists.txt new file mode 100644 index 000000000000..21fbf62b1183 --- /dev/null +++ b/share/sysbuild/images/firmware_loader/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +if(SB_CONFIG_FIRMWARE_LOADER_IMAGE_PATH) + ExternalZephyrProject_Add( + APPLICATION ${SB_CONFIG_FIRMWARE_LOADER_IMAGE_NAME} + SOURCE_DIR ${SB_CONFIG_FIRMWARE_LOADER_IMAGE_PATH} + APP_TYPE FIRMWARE_LOADER + ) +endif() diff --git a/share/sysbuild/images/firmware_loader/Kconfig b/share/sysbuild/images/firmware_loader/Kconfig new file mode 100644 index 000000000000..a5c4283ad5c6 --- /dev/null +++ b/share/sysbuild/images/firmware_loader/Kconfig @@ -0,0 +1,37 @@ +# Copyright (c) 2025 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 + +config SUPPORT_FIRMWARE_LOADER_SMP_SVR + bool + default y + +choice FIRMWARE_LOADER + prompt "Firmware loader image" + default FIRMWARE_LOADER_IMAGE_NONE + depends on MCUBOOT_MODE_FIRMWARE_UPDATER + +config FIRMWARE_LOADER_IMAGE_NONE + bool "None" + help + Do not Include a firmware loader image in the build. + +config FIRMWARE_LOADER_IMAGE_SMP_SVR + bool "smp_svr" + depends on SUPPORT_FIRMWARE_LOADER_SMP_SVR + help + Include the MCUmgr ``smp_svr`` sample as the firmware loader image to use. + +endchoice + +config FIRMWARE_LOADER_IMAGE_NAME + string + default "smp_svr" if FIRMWARE_LOADER_IMAGE_SMP_SVR + help + Name of firmware loader image. + +config FIRMWARE_LOADER_IMAGE_PATH + string + default "${ZEPHYR_BASE}/samples/subsys/mgmt/mcumgr/smp_svr" if FIRMWARE_LOADER_IMAGE_SMP_SVR + help + Source directory of firmware loader image. From 6cc4673182f47219b41b8233195667d4a4cc1e0d Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 20 Feb 2025 13:48:47 +0000 Subject: [PATCH 6/7] scripts: ci: check_compliance: Add Kconfig to allow list Adds a Kconfig used in MCUboot to the allow list Signed-off-by: Jamie McCrae --- scripts/ci/check_compliance.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 09f347a2cca0..0c8447937372 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -1024,6 +1024,7 @@ def check_no_undef_outside_kconfig(self, kconf): "BOOT_ENCRYPTION_KEY_FILE", # Used in sysbuild "BOOT_ENCRYPT_IMAGE", # Used in sysbuild "BOOT_FIRMWARE_LOADER", # Used in sysbuild for MCUboot configuration + "BOOT_FIRMWARE_LOADER_BOOT_MODE", # Used in sysbuild for MCUboot configuration "BOOT_MAX_IMG_SECTORS_AUTO", # Used in sysbuild "BOOT_RAM_LOAD", # Used in sysbuild for MCUboot configuration "BOOT_SERIAL_BOOT_MODE", # Used in (sysbuild-based) test/ From f3aee54da2597699d03b93c65f9ecfc74d0b2ee2 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 10 Apr 2025 14:28:26 +0100 Subject: [PATCH 7/7] doc: build: dts: api: Add details on zephyr,boot-mode Adds details on this new chosen property Signed-off-by: Jamie McCrae --- doc/build/dts/api/api.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/build/dts/api/api.rst b/doc/build/dts/api/api.rst index c8c3c0563a9f..6fe1fb7fd1bc 100644 --- a/doc/build/dts/api/api.rst +++ b/doc/build/dts/api/api.rst @@ -467,3 +467,6 @@ device. :kconfig:option:`CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP_RAM_LOAD`, this property is used to tell MCUboot the load address of the image, which will be the ``reg`` of the chosen node. + * - zephyr,boot-mode + - Used for :ref:`boot_mode_api` selection, part of :ref:`retention_api`, which specifies + what image on a device should be booted.