Skip to content

Commit 31e2046

Browse files
committed
samples: Add sample to verify bootloader requests
Add a sample variant that can be used to verify the bootloader request module. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 8f32baa commit 31e2046

File tree

11 files changed

+221
-1
lines changed

11 files changed

+221
-1
lines changed

modules/mcuboot/Kconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,32 @@ config MCUBOOT_USE_ALL_AVAILABLE_RAM
7272
By default MCUBoot uses only the secure RAM partition.
7373

7474
endmenu
75+
76+
config NRF_MCUBOOT_BOOT_REQUEST
77+
bool "MCUboot bootloader requests"
78+
help
79+
Handle bootloader requests.
80+
81+
if NRF_MCUBOOT_BOOT_REQUEST
82+
83+
choice NRF_MCUBOOT_BOOT_REQUEST_IMPL
84+
prompt "Shared memory backend"
85+
default NRF_MCUBOOT_BOOT_REQUEST_IMPL_RETENTION if RETENTION
86+
87+
DT_CHOSEN_BOOTLOADER_REQUEST := nrf,bootloader-request
88+
89+
config NRF_MCUBOOT_BOOT_REQUEST_IMPL_RETENTION
90+
bool "Retention"
91+
depends on RETENTION
92+
depends on $(dt_chosen_enabled,$(DT_CHOSEN_BOOTLOADER_REQUEST))
93+
help
94+
Use zephyr,bootloader-request chosen node compatible with the
95+
zephyr,retention driver as the memory area to store and read from the
96+
bootloader requests.
97+
The built-in prefix property should be used to indicate the request
98+
structure version to ensure compatibility between the bootloader and
99+
the application.
100+
101+
endchoice
102+
103+
endif # NRF_MCUBOOT_BOOT_REQUEST

modules/mcuboot/boot/zephyr/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,11 @@ config BOOT_SERIAL_IMG_GRP_HASH
171171
config BOOT_SERIAL_IMG_GPR_SLOT_INFO
172172
bool
173173
default n
174+
175+
config FIND_NEXT_SLOT_HOOK_BOOT_REQ
176+
bool "Enable default hook that uses bootloader requests module"
177+
default y if NRF_MCUBOOT_BOOT_REQUEST
178+
depends on FIND_NEXT_SLOT_HOOKS
179+
help
180+
This will read the image preference from the bootloader requests
181+
module and if found, alter the Direct XIP slot selection.

modules/mcuboot/hooks/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ if(CONFIG_BOOT_IMAGE_ACCESS_HOOKS)
1111
zephyr_library_link_libraries(MCUBOOT_BOOTUTIL)
1212
endif()
1313
endif()
14+
15+
if(CONFIG_FIND_NEXT_SLOT_HOOKS)
16+
if(CONFIG_FIND_NEXT_SLOT_HOOK_BOOT_REQ)
17+
zephyr_library()
18+
zephyr_library_sources(hooks_find_next_slot.c)
19+
zephyr_library_link_libraries(MCUBOOT_BOOTUTIL)
20+
endif()
21+
endif()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <../../bootutil/src/bootutil_priv.h>
8+
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
9+
#include <bootutil/boot_request.h>
10+
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
11+
12+
/**
13+
* Finds the preferred slot containing the image based on bootloader requests.
14+
*/
15+
int boot_find_next_slot_hook(struct boot_loader_state *state, uint8_t image, uint32_t *active_slot)
16+
{
17+
#ifdef CONFIG_NRF_MCUBOOT_BOOT_REQUEST
18+
uint32_t slot = BOOT_REQUEST_NO_PREFERRED_SLOT;
19+
20+
if (active_slot == NULL) {
21+
return BOOT_HOOK_REGULAR;
22+
}
23+
24+
slot = boot_request_get_preferred_slot(image);
25+
if (slot != BOOT_REQUEST_NO_PREFERRED_SLOT) {
26+
if (state->slot_usage[image].slot_available[slot]) {
27+
*active_slot = slot;
28+
return 0;
29+
}
30+
}
31+
#endif /* CONFIG_NRF_MCUBOOT_BOOT_REQUEST */
32+
33+
return BOOT_HOOK_REGULAR;
34+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include "../sysbuild/nrf54h20dk_nrf54h20_memory_map_requests.dtsi"
8+
9+
/ {
10+
chosen {
11+
zephyr,boot-mode = &boot_request;
12+
};
13+
};
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Enable MCUmgr and dependencies.
2+
CONFIG_NET_BUF=y
3+
CONFIG_ZCBOR=y
4+
CONFIG_CRC=y
5+
CONFIG_MCUMGR=y
6+
CONFIG_STREAM_FLASH=y
7+
CONFIG_FLASH_MAP=y
8+
9+
# Some command handlers require a large stack.
10+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
11+
CONFIG_MAIN_STACK_SIZE=2176
12+
13+
# Ensure an MCUboot-compatible binary is generated.
14+
CONFIG_BOOTLOADER_MCUBOOT=y
15+
16+
# Enable flash operations.
17+
CONFIG_FLASH=y
18+
19+
# Required by the `taskstat` command.
20+
CONFIG_THREAD_MONITOR=y
21+
22+
# Support for taskstat command
23+
CONFIG_MCUMGR_GRP_OS_TASKSTAT=y
24+
25+
# Enable statistics and statistic names.
26+
CONFIG_STATS=y
27+
CONFIG_STATS_NAMES=y
28+
29+
# Enable most core commands.
30+
CONFIG_FLASH=y
31+
CONFIG_IMG_MANAGER=y
32+
CONFIG_MCUMGR_GRP_IMG=y
33+
CONFIG_MCUMGR_GRP_OS=y
34+
CONFIG_MCUMGR_GRP_STAT=y
35+
36+
# Enable logging
37+
CONFIG_LOG=y
38+
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y
39+
40+
# Disable debug logging
41+
CONFIG_LOG_MAX_LEVEL=3
42+
43+
# Enable boot requests through retained memory.
44+
CONFIG_RETAINED_MEM=y
45+
CONFIG_RETENTION=y
46+
CONFIG_NRF_MCUBOOT_BOOT_REQUEST=y
47+
48+
CONFIG_RETENTION_BOOT_MODE=y
49+
CONFIG_MCUMGR_GRP_OS_RESET_BOOT_MODE=y

samples/zephyr/subsys/mgmt/mcumgr/smp_svr/sample.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,17 @@ tests:
4545
- nrf54h20dk/nrf54h20/cpuapp
4646
integration_platforms:
4747
- nrf54h20dk/nrf54h20/cpuapp
48+
sample.mcumgr.smp_svr.bt.nrf54h20dk.direct_xip_withrequests:
49+
sysbuild: true
50+
extra_args:
51+
- FILE_SUFFIX="requests"
52+
- EXTRA_CONF_FILE="overlay-bt.conf"
53+
- SB_CONFIG_NETCORE_IPC_RADIO=y
54+
- SB_CONFIG_NETCORE_IPC_RADIO_BT_HCI_IPC=y
55+
- SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WITH_REVERT=y
56+
- mcuboot_CONFIG_NRF_SECURITY=y
57+
- mcuboot_CONFIG_MULTITHREADING=y
58+
platform_allow:
59+
- nrf54h20dk/nrf54h20/cpuapp
60+
integration_platforms:
61+
- nrf54h20dk/nrf54h20/cpuapp
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Enable boot requests through retained memory.
2+
CONFIG_RETAINED_MEM=y
3+
CONFIG_RETENTION=y
4+
CONFIG_NRF_MCUBOOT_BOOT_REQUEST=y
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include "nrf54h20dk_nrf54h20_memory_map_requests.dtsi"
8+
9+
/ {
10+
chosen {
11+
zephyr,code-partition = &boot_partition;
12+
};
13+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
/* On nRF54H20 the Direct XIP mode is supported in the merged slot configuration
8+
* Merge application and radio slots by extending the application parition.
9+
*/
10+
&cpuapp_slot0_partition {
11+
reg = <0x40000 DT_SIZE_K(656)>;
12+
};
13+
14+
&cpuapp_slot1_partition {
15+
reg = <0x100000 DT_SIZE_K(656)>;
16+
};
17+
18+
/ {
19+
chosen {
20+
nrf,bootloader-request = &boot_request;
21+
};
22+
};
23+
24+
/ {
25+
reserved-memory {
26+
cpuapp_retained_mem: memory@e1ad000 {
27+
compatible = "zephyr,memory-region";
28+
reg = <0xe1ad000 DT_SIZE_K(4)>;
29+
zephyr,memory-region = "RetainedMem";
30+
status = "okay";
31+
32+
retainedmem {
33+
compatible = "zephyr,retained-ram";
34+
status = "okay";
35+
#address-cells = <1>;
36+
#size-cells = <1>;
37+
38+
boot_request: boot_request@0 {
39+
compatible = "zephyr,retention";
40+
status = "okay";
41+
reg = <0x0 16>;
42+
prefix = [0B 01];
43+
checksum = <4>;
44+
};
45+
};
46+
};
47+
};
48+
};

0 commit comments

Comments
 (0)