diff --git a/modules/mcuboot/Kconfig b/modules/mcuboot/Kconfig index 7b40bc0f6d8c..be46461be9e8 100644 --- a/modules/mcuboot/Kconfig +++ b/modules/mcuboot/Kconfig @@ -72,3 +72,32 @@ config MCUBOOT_USE_ALL_AVAILABLE_RAM By default MCUBoot uses only the secure RAM partition. endmenu + +config NRF_MCUBOOT_BOOT_REQUEST + bool "MCUboot bootloader requests" + help + Handle bootloader requests. + +if NRF_MCUBOOT_BOOT_REQUEST + +choice NRF_MCUBOOT_BOOT_REQUEST_IMPL + prompt "Shared memory backend" + default NRF_MCUBOOT_BOOT_REQUEST_IMPL_RETENTION if RETENTION + +DT_CHOSEN_BOOTLOADER_REQUEST := nrf,bootloader-request + +config NRF_MCUBOOT_BOOT_REQUEST_IMPL_RETENTION + bool "Retention" + depends on RETENTION + depends on $(dt_chosen_enabled,$(DT_CHOSEN_BOOTLOADER_REQUEST)) + help + Use zephyr,bootloader-request chosen node compatible with the + zephyr,retention driver as the memory area to store and read from the + bootloader requests. + The built-in prefix property should be used to indicate the request + structure version to ensure compatibility between the bootloader and + the application. + +endchoice + +endif # NRF_MCUBOOT_BOOT_REQUEST diff --git a/modules/mcuboot/boot/zephyr/Kconfig b/modules/mcuboot/boot/zephyr/Kconfig index 53e0052f238e..5780db0033f0 100644 --- a/modules/mcuboot/boot/zephyr/Kconfig +++ b/modules/mcuboot/boot/zephyr/Kconfig @@ -171,3 +171,11 @@ config BOOT_SERIAL_IMG_GRP_HASH config BOOT_SERIAL_IMG_GPR_SLOT_INFO bool default n + +config FIND_NEXT_SLOT_HOOK_BOOT_REQ + bool "Enable default hook that uses bootloader requests module" + default y if NRF_MCUBOOT_BOOT_REQUEST + depends on FIND_NEXT_SLOT_HOOKS + help + This will read the image preference from the bootloader requests + module and if found, alter the Direct XIP slot selection. diff --git a/modules/mcuboot/hooks/CMakeLists.txt b/modules/mcuboot/hooks/CMakeLists.txt index 87ce19497371..bcbc19a25969 100644 --- a/modules/mcuboot/hooks/CMakeLists.txt +++ b/modules/mcuboot/hooks/CMakeLists.txt @@ -11,3 +11,11 @@ if(CONFIG_BOOT_IMAGE_ACCESS_HOOKS) zephyr_library_link_libraries(MCUBOOT_BOOTUTIL) endif() endif() + +if(CONFIG_FIND_NEXT_SLOT_HOOKS) + if(CONFIG_FIND_NEXT_SLOT_HOOK_BOOT_REQ) + zephyr_library() + zephyr_library_sources(hooks_find_next_slot.c) + zephyr_library_link_libraries(MCUBOOT_BOOTUTIL) + endif() +endif() diff --git a/modules/mcuboot/hooks/hooks_find_next_slot.c b/modules/mcuboot/hooks/hooks_find_next_slot.c new file mode 100644 index 000000000000..546ec8ca2c43 --- /dev/null +++ b/modules/mcuboot/hooks/hooks_find_next_slot.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include <../../bootutil/src/bootutil_priv.h> +#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST +#include +#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */ + +/** + * Finds the preferred slot containing the image based on bootloader requests. + */ +int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image, uint32_t *active_slot) +{ +#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST + uint32_t slot = BOOT_REQUEST_NO_PREFERRED_SLOT; + + if (active_slot == NULL) { + return BOOT_HOOK_REGULAR; + } + + slot = boot_request_get_preferred_slot(image); + if (slot != BOOT_REQUEST_NO_PREFERRED_SLOT) { + if (state->slot_usage[image].slot_available[slot]) { + *active_slot = slot; + return 0; + } + } +#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */ + + return BOOT_HOOK_REGULAR; +} diff --git a/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/boards/nrf54h20dk_nrf54h20_cpuapp_requests.overlay b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/boards/nrf54h20dk_nrf54h20_cpuapp_requests.overlay new file mode 100644 index 000000000000..4cb253a13f44 --- /dev/null +++ b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/boards/nrf54h20dk_nrf54h20_cpuapp_requests.overlay @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#include "../sysbuild/nrf54h20dk_nrf54h20_memory_map_requests.dtsi" + +/ { + chosen { + zephyr,boot-mode = &boot_request; + }; +}; diff --git a/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/prj_requests.conf b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/prj_requests.conf new file mode 100644 index 000000000000..a986ebd71d20 --- /dev/null +++ b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/prj_requests.conf @@ -0,0 +1,49 @@ +# Enable MCUmgr and dependencies. +CONFIG_NET_BUF=y +CONFIG_ZCBOR=y +CONFIG_CRC=y +CONFIG_MCUMGR=y +CONFIG_STREAM_FLASH=y +CONFIG_FLASH_MAP=y + +# Some command handlers require a large stack. +CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304 +CONFIG_MAIN_STACK_SIZE=2176 + +# Ensure an MCUboot-compatible binary is generated. +CONFIG_BOOTLOADER_MCUBOOT=y + +# Enable flash operations. +CONFIG_FLASH=y + +# Required by the `taskstat` command. +CONFIG_THREAD_MONITOR=y + +# Support for taskstat command +CONFIG_MCUMGR_GRP_OS_TASKSTAT=y + +# Enable statistics and statistic names. +CONFIG_STATS=y +CONFIG_STATS_NAMES=y + +# Enable most core commands. +CONFIG_FLASH=y +CONFIG_IMG_MANAGER=y +CONFIG_MCUMGR_GRP_IMG=y +CONFIG_MCUMGR_GRP_OS=y +CONFIG_MCUMGR_GRP_STAT=y + +# Enable logging +CONFIG_LOG=y +CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y + +# Disable debug logging +CONFIG_LOG_MAX_LEVEL=3 + +# Enable boot requests through retained memory. +CONFIG_RETAINED_MEM=y +CONFIG_RETENTION=y +CONFIG_NRF_MCUBOOT_BOOT_REQUEST=y + +CONFIG_RETENTION_BOOT_MODE=y +CONFIG_MCUMGR_GRP_OS_RESET_BOOT_MODE=y diff --git a/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sample.yaml b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sample.yaml index 5673cc482b4f..10100e7c7e48 100644 --- a/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sample.yaml +++ b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sample.yaml @@ -45,3 +45,17 @@ tests: - nrf54h20dk/nrf54h20/cpuapp integration_platforms: - nrf54h20dk/nrf54h20/cpuapp + sample.mcumgr.smp_svr.bt.nrf54h20dk.direct_xip_withrequests: + sysbuild: true + extra_args: + - FILE_SUFFIX="requests" + - EXTRA_CONF_FILE="overlay-bt.conf" + - SB_CONFIG_NETCORE_IPC_RADIO=y + - SB_CONFIG_NETCORE_IPC_RADIO_BT_HCI_IPC=y + - SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT=y + - mcuboot_CONFIG_NRF_SECURITY=y + - mcuboot_CONFIG_MULTITHREADING=y + platform_allow: + - nrf54h20dk/nrf54h20/cpuapp + integration_platforms: + - nrf54h20dk/nrf54h20/cpuapp diff --git a/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/mcuboot_requests.conf b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/mcuboot_requests.conf new file mode 100644 index 000000000000..093368d1bbf7 --- /dev/null +++ b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/mcuboot_requests.conf @@ -0,0 +1,4 @@ +# Enable boot requests through retained memory. +CONFIG_RETAINED_MEM=y +CONFIG_RETENTION=y +CONFIG_NRF_MCUBOOT_BOOT_REQUEST=y diff --git a/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/mcuboot_requests.overlay b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/mcuboot_requests.overlay new file mode 100644 index 000000000000..9f9660b1c2f2 --- /dev/null +++ b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/mcuboot_requests.overlay @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + + #include "nrf54h20dk_nrf54h20_memory_map_requests.dtsi" + +/ { + chosen { + zephyr,code-partition = &boot_partition; + }; +}; diff --git a/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf54h20dk_nrf54h20_memory_map_requests.dtsi b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf54h20dk_nrf54h20_memory_map_requests.dtsi new file mode 100644 index 000000000000..72b049e71111 --- /dev/null +++ b/samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sysbuild/nrf54h20dk_nrf54h20_memory_map_requests.dtsi @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/* On nRF54H20 the Direct XIP mode is supported in the merged slot configuration + * Merge application and radio slots by extending the application parition. + */ +&cpuapp_slot0_partition { + reg = <0x40000 DT_SIZE_K(656)>; +}; + +&cpuapp_slot1_partition { + reg = <0x100000 DT_SIZE_K(656)>; +}; + +/ { + chosen { + nrf,bootloader-request = &boot_request; + }; +}; + +/ { + reserved-memory { + cpuapp_retained_mem: memory@e1ad000 { + compatible = "zephyr,memory-region"; + reg = <0xe1ad000 DT_SIZE_K(4)>; + zephyr,memory-region = "RetainedMem"; + status = "okay"; + + retainedmem { + compatible = "zephyr,retained-ram"; + status = "okay"; + #address-cells = <1>; + #size-cells = <1>; + + boot_request: boot_request@0 { + compatible = "zephyr,retention"; + status = "okay"; + reg = <0x0 16>; + prefix = [0B 01]; + checksum = <4>; + }; + }; + }; + }; +}; diff --git a/west.yml b/west.yml index 68942e5a28f8..b9a0cb055a75 100644 --- a/west.yml +++ b/west.yml @@ -128,7 +128,7 @@ manifest: compare-by-default: true - name: mcuboot repo-path: sdk-mcuboot - revision: 285fd59f4386a0317e476da5484f67b906073296 + revision: e1f2ab3806ce7ebc7ef34b3fc04272e747590745 path: bootloader/mcuboot - name: qcbor url: https://github.com/laurencelundblade/QCBOR