Skip to content

Commit 9ba0099

Browse files
committed
applications: nrf_desktop: add constraints for MCUboot RAM load
Added the DTS RAM layout constraints to the nRF Desktop application when it uses the MCUboot bootloader in the RAM load mode. These constraints enforce a specific RAM layout for supported board targets. The user is required to define two DTS nodes that are part of the chosen SRAM DTS node of the application image: - cpuapp_sram_app_rxm_region - cpuapp_sram_mcuboot_ram_region Additionally, the cpuapp_sram_app_rxm_region DTS node must be placed before the cpuapp_sram_mcuboot_ram_region DTS node in the target device memory. Added a linker script with the assert statement that prevents the executable RAM region of the application image to overflow the standard RAM region of the MCUboot image. Ref: NCSDK-35506 Signed-off-by: Kamil Piszczek <[email protected]>
1 parent cff13a3 commit 9ba0099

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

applications/nrf_desktop/CMakeLists.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,55 @@ if(CONFIG_IMG_MANAGER)
4747
zephyr_library_link_libraries(MCUBOOT_BOOTUTIL)
4848
endif()
4949

50+
if(CONFIG_BOOTLOADER_MCUBOOT)
51+
if(NOT (CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP OR
52+
CONFIG_MCUBOOT_BOOTLOADER_MODE_DIRECT_XIP OR
53+
CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD OR
54+
CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_USING_MOVE))
55+
message(WARNING "
56+
------------------------------------------------------------------------------
57+
--- WARNING: The currently selected mode of the MCUboot bootloader has not ---
58+
--- been used or tested with any nRF Desktop configuration. ---
59+
------------------------------------------------------------------------------
60+
")
61+
endif()
62+
63+
if(CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD)
64+
message(WARNING "
65+
-----------------------------------------------------------------------------
66+
--- WARNING: The RAM load mode of the MCUboot bootloader is experimental. ---
67+
-----------------------------------------------------------------------------
68+
")
69+
70+
# Enforce the specific RAM layout in DTS when MCUboot uses the RAM load mode.
71+
dt_nodelabel(app_rxm_region_node NODELABEL cpuapp_sram_app_rxm_region)
72+
if(NOT app_rxm_region_node)
73+
message(FATAL_ERROR
74+
"Missing RXM (ROM + RAM) region definition (cpuapp_sram_app_rxm_region) for the "
75+
"application image in DTS.")
76+
endif()
77+
78+
dt_nodelabel(mcuboot_ram_region_node NODELABEL cpuapp_sram_mcuboot_ram_region)
79+
if(NOT mcuboot_ram_region_node)
80+
message(FATAL_ERROR
81+
"Missing RAM region definition (cpuapp_sram_mcuboot_ram_region) for the MCUboot "
82+
"bootloader in DTS.")
83+
endif()
84+
85+
dt_reg_addr(app_rxm_region_addr PATH ${app_rxm_region_node})
86+
dt_reg_addr(mcuboot_ram_region_addr PATH ${mcuboot_ram_region_node})
87+
if(mcuboot_ram_region_addr LESS_EQUAL app_rxm_region_addr)
88+
message(FATAL_ERROR
89+
"The start address of the RXM region (0x${app_rxm_region_addr}) must be located "
90+
"before the start address of the MCUboot RAM region (0x${mcuboot_ram_region_addr})."
91+
"The current order is wrong — modify your DTS RAM layout to fix this error.")
92+
endif()
93+
94+
# Ensure that generated application image will fit in the defined RAM partition after build.
95+
zephyr_linker_sources(RODATA linker/mcuboot_ram_load.ld)
96+
endif()
97+
endif()
98+
5099
if(CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE)
51100
zephyr_linker_sources(SECTIONS nrf_desktop.ld)
52101
zephyr_linker_section(NAME config_channel_modules KVMA RAM_REGION GROUP RODATA_REGION NOINPUT)

applications/nrf_desktop/Kconfig.defaults

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ config DESKTOP_LTO_DEFAULTS
2424
help
2525
nRF Desktop enables LTO to limit memory usage and improve performance.
2626

27+
config DESKTOP_MCUBOOT_RAM_LOAD_MCUBOOT_RAM_START_ADDR
28+
hex
29+
depends on MCUBOOT_BOOTLOADER_MODE_RAM_LOAD
30+
depends on $(dt_nodelabel_exists,cpuapp_sram_mcuboot_ram_region)
31+
default $(dt_nodelabel_reg_addr_hex,cpuapp_sram_mcuboot_ram_region)
32+
help
33+
The start address of the MCUboot RAM region. The Kconfig option is used to validate
34+
if the executable RAM region of the application image (also called the ROM section)
35+
does not overlap with the RAM region of the MCUboot image. The validation process
36+
assumes a specific RAM layout in DTS - you can refer to the following file as an example:
37+
./configuration/nrf54lm20dk_nrf54lm20a_cpuapp/memory_map_ram_load.dtsi
38+
2739
config APP_EVENT_MANAGER_MAX_EVENT_CNT
2840
default 64
2941
help
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* Validate that the ROM section from the application RAM region does not overlap with the
2+
* MCUboot RAM region. This ROM section defines the memory space where MCUboot copies the
3+
* application image. If this copied data overlaps with the MCUboot RAM region, MCUboot may
4+
* override its own RAM during the copy operation. The validation process assumes a specific
5+
* RAM layout in DTS - you can refer to the following file as an example:
6+
* ./configuration/nrf54lm20dk_nrf54lm20a_cpuapp/memory_map_ram_load.dtsi
7+
*/
8+
ASSERT(__rom_region_end <= CONFIG_DESKTOP_MCUBOOT_RAM_LOAD_MCUBOOT_RAM_START_ADDR,
9+
"The executable RAM region overlaps with the MCUboot RAM region");

0 commit comments

Comments
 (0)