Skip to content

Conversation

JarmouniA
Copy link
Contributor

@JarmouniA JarmouniA commented Oct 12, 2025

In MCUBoot RAM LOAD mode, the app slot addr is taken as the hex-addr passed to imgtool to create slot0 & 1 images, which is only correct if the grand-parent node's (usually the flash node) absolute address is actually 0, because the addresses of all the flash fixed-partitions in-tree are relative to their grand-parent node's address.

Hence, use the newly added dt_fixed_partition_addr() CMake function to get the absolute address of app slots partitions.

@nordicjm
Copy link
Contributor

My first point would be that you are missing a ranges property for your flash controller, but I have just investigated by building for stm32n6570_dk and I'm a bit confused because that board does not even use RAM load?

@nordicjm
Copy link
Contributor

Saw you need to manually specify it, so it is not default. Anyhow, this fixes it with the ranges property, otherwise you are declaring that the flash partitions start at 0x0 in dts, which is wrong:

diff --git a/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi b/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
index 5b91c96d7d4..758b007f0c6 100644
--- a/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
+++ b/boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
@@ -380,6 +380,8 @@ zephyr_udc0: &usbotg_hs1 {
 
 	mx66uw1g45g: ospi-nor-flash@0 {
 		compatible = "st,stm32-xspi-nor";
+		#address-cells = <1>;
+		#size-cells = <1>;
 		reg = <0>;
 		size = <DT_SIZE_M(1024)>; /* 1Gbits */
 		ospi-max-frequency = <DT_FREQ_M(200)>;
@@ -387,11 +389,13 @@ zephyr_udc0: &usbotg_hs1 {
 		data-rate = <XSPI_DTR_TRANSFER>;
 		four-byte-opcodes;
 		status = "okay";
+		ranges = <0x0 0x70000000 0x1000000>;
 
 		partitions {
 			compatible = "fixed-partitions";
 			#address-cells = <1>;
 			#size-cells = <1>;
+			ranges;
 
 			/*
 			 * Following flash partition is dedicated to the use of bootloader

@erwango
Copy link
Member

erwango commented Oct 14, 2025

My first point would be that you are missing a ranges property for your flash controller, but I have just investigated by building for stm32n6570_dk and I'm a bit confused because that board does not even use RAM load?

@nordicjm STM32N6 is a specific kind of STM32: there is no internal flash. In default mode, the BootROM (internal and non updatable bootloader) will load the binary (called First Stage Boot Loader) from ext flash (at a specific location) to RAM, which will then execute in XIP=n. FSBL can be a usual zephyr application or MCUBoot which will could then do it's usual job with application that would be also stored on ext flash.

endif()
set(imgtool_args_alt_slot ${imgtool_args} --hex-addr ${slot1_partition_address})
set(imgtool_args ${imgtool_args} --hex-addr ${slot0_partition_address})
math(EXPR SLOT0_PARTITION_ADDRESS "${CONFIG_FLASH_BASE_ADDRESS} + ${slot0_partition_address}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm implementing a CMake function in cmake.extensions, to replace dt_reg_addr above, that will give the absolute address of the slot partition, similar to the macro

#define DT_FIXED_PARTITION_ADDR(node_id) \

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good thing but nack on the board impact part for now

Introduce a new dt_fixed_partition_addr() function that returns the absolute
address of a fixed partition, meaning the sum of the base address of the
containing grand-parent node and the partition's offset.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
In RAM LOAD mode, the app slot addr is taken as the hex-addr passed to
imgtool, which is only correct if the grand-parent node's (usually the
flash node) absolute address is actually 0, because the addresses of all
the flash fixed-partitions in-tree are relative to their grand-parent
node's address.

Hence, use the newly added dt_fixed_partition_addr() function to get the
absolute address of app slots partitions.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
@JarmouniA JarmouniA force-pushed the fix_mcuboot_ramload_img_hexaddr branch from cf50563 to c6ca4e9 Compare October 18, 2025 11:30
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants