Skip to content

mcuboot supports the stm32 external flash in XiP mode #2154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boot/zephyr/boards/b_u585i_iot02a.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
11 changes: 11 additions & 0 deletions boot/zephyr/boards/b_u585i_iot02a.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,flash = &flash0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should be in the board dts in zephyr

Copy link
Author

Choose a reason for hiding this comment

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

it is in each board dts for zephyr, so I think I can remove it from each overlay

zephyr,code-partition = &boot_partition;
};
};
4 changes: 4 additions & 0 deletions boot/zephyr/boards/nucleo_h7s3l8.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
CONFIG_BOOT_MAX_IMG_SECTORS_AUTO=n
CONFIG_BOOT_MAX_IMG_SECTORS=4096
12 changes: 12 additions & 0 deletions boot/zephyr/boards/nucleo_h7s3l8.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,flash = &flash0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this whole file shouldn't be needed since flash is already set here: https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/st/nucleo_h7s3l8/nucleo_h7s3l8.dts#L22 and code partition will be applied automatically via app.overlay

zephyr,code-partition = &boot_partition;

Choose a reason for hiding this comment

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

zephyr,code-partition = &boot_partition; is redundant, already in app.overlay, same remark for other overlays.

};
};
2 changes: 2 additions & 0 deletions boot/zephyr/boards/stm32f746g_disco.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
11 changes: 11 additions & 0 deletions boot/zephyr/boards/stm32f746g_disco.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &boot_partition;
};
};
4 changes: 4 additions & 0 deletions boot/zephyr/boards/stm32h573i_dk.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
CONFIG_BOOT_MAX_IMG_SECTORS_AUTO=n
CONFIG_BOOT_MAX_IMG_SECTORS=4096
11 changes: 11 additions & 0 deletions boot/zephyr/boards/stm32h573i_dk.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2025 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &boot_partition;
};
};
2 changes: 2 additions & 0 deletions boot/zephyr/boards/stm32h735g_disco.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
11 changes: 11 additions & 0 deletions boot/zephyr/boards/stm32h735g_disco.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &boot_partition;
};
};
2 changes: 2 additions & 0 deletions boot/zephyr/boards/stm32h747i_disco_m7.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
11 changes: 11 additions & 0 deletions boot/zephyr/boards/stm32h747i_disco_m7.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &boot_partition;
};
};
2 changes: 2 additions & 0 deletions boot/zephyr/boards/stm32h750b_dk.conf

Choose a reason for hiding this comment

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

CONFIG_BOOT_MAX_IMG_SECTORS_AUTO=n
CONFIG_BOOT_MAX_IMG_SECTORS=256

needed here (potentially for other boards as well, I only have access to this one).

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
11 changes: 11 additions & 0 deletions boot/zephyr/boards/stm32h750b_dk.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &boot_partition;
};
};
2 changes: 2 additions & 0 deletions boot/zephyr/boards/stm32h7b3i_dk.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
11 changes: 11 additions & 0 deletions boot/zephyr/boards/stm32h7b3i_dk.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,code-partition = &boot_partition;
};
};
4 changes: 4 additions & 0 deletions boot/zephyr/boards/stm32h7s78_dk.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
CONFIG_BOOT_MAX_IMG_SECTORS_AUTO=n
CONFIG_BOOT_MAX_IMG_SECTORS=4096
12 changes: 12 additions & 0 deletions boot/zephyr/boards/stm32h7s78_dk.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &boot_partition;
};
};
2 changes: 2 additions & 0 deletions boot/zephyr/boards/stm32l496g_disco.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_DIRECT_XIP=y
CONFIG_STM32_MEMMAP=y
11 changes: 11 additions & 0 deletions boot/zephyr/boards/stm32l496g_disco.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2024 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
chosen {
zephyr,flash = &flash0;
zephyr,code-partition = &boot_partition;
};
};
18 changes: 17 additions & 1 deletion boot/zephyr/flash_map_extended.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@

BOOT_LOG_MODULE_DECLARE(mcuboot);

#if (!defined(CONFIG_XTENSA) && DT_HAS_CHOSEN(zephyr_flash_controller))
#if defined(CONFIG_STM32_MEMMAP)
/* MEMORY MAPPED for XiP on external NOR flash takes the sspi-nor or ospi-nor or qspi-nor device */
#define FLASH_DEVICE_ID SPI_FLASH_0_ID
#if DT_NODE_HAS_STATUS(DT_INST(0, st_stm32_xspi_nor), okay)
#define FLASH_DEVICE_NODE DT_INST(0, st_stm32_xspi_nor)
#define FLASH_DEVICE_BASE DT_REG_ADDR(DT_INST(0, st_stm32_xspi_nor))

Choose a reason for hiding this comment

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

Shouldn't this be changed following #88646?

Copy link
Author

@FRASTM FRASTM Apr 24, 2025

Choose a reason for hiding this comment

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

Yes, the FLASH_DEVICE_BASE is now given by the parent of the "st,stm32-xspi-nor" node. However
#define FLASH_DEVICE_BASE DT_REG_ADDR_BY_IDX(DT_INST(0, st_stm32_xspi),1)
does not help linking at the expected address 0x90000000 (stm32h573i_dk)

Copy link
Author

Choose a reason for hiding this comment

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

only
-DCONFIG_FLASH_BASE_ADDRESS=0x90000000
can link at the correct address of the external flash memory

Copy link

Choose a reason for hiding this comment

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

@nordicjm Following zephyrproject-rtos/zephyr#88646, we're reusing similar bindings as you or NXP do for external memories (memory mapping address of the memory provided in a second reg cell of the memoy parent node ). I would expect we could align on a common code on mcuboot for this case, but apparently -DCONFIG_FLASH_BASE_ADDRESS=0x90000000 is still required which seems odd to me
Did we missed something ?

Copy link
Author

@FRASTM FRASTM Apr 28, 2025

Choose a reason for hiding this comment

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

I am checking when the CONFIG_FLASH_BASE_ADDRESS is given by the Kconfig.defconfig for any stm32 soc as follows:

DT_CHOSEN_Z_FLASH := zephyr,flash
DT_COMPAT_XSPI := st,stm32-xspi

DT_CHOSEN_FLASH_NODE := $(dt_chosen_path,$(DT_CHOSEN_Z_FLASH))
DT_CHOSEN_FLASH_PARENT := $(dt_node_parent,$(DT_CHOSEN_FLASH_NODE))
DT_FLASH_PARENT_IS_XSPI := $(dt_node_has_compat,$(DT_CHOSEN_FLASH_PARENT),$(DT_COMPAT_XSPI))

config FLASH_BASE_ADDRESS
	default $(dt_node_reg_addr_hex,$(DT_CHOSEN_FLASH_PARENT),1) \
		if $(DT_FLASH_PARENT_IS_XSPI)
	default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_FLASH))

The CONFIG_FLASH_BASE_ADDRESS is correctly defined = 0x90000000 which is the second reg of the xspi node:

		xspi1: spi@47001400 {
			compatible = "st,stm32-xspi";
			reg = <0x47001400 0x400>, <0x90000000 DT_SIZE_M(256)>;

Then build option -DCONFIG_FLASH_BASE_ADDRESS=0x90000000 is not required anymore and the application is correclty linked for external address of the NOR octo-flash

#elif DT_NODE_HAS_STATUS(DT_INST(0, st_stm32_ospi_nor), okay)
#define FLASH_DEVICE_NODE DT_INST(0, st_stm32_ospi_nor)
#define FLASH_DEVICE_BASE DT_REG_ADDR(DT_INST(0, st_stm32_ospi_nor))
#elif DT_NODE_HAS_STATUS(DT_INST(0, st_stm32_qspi_nor), okay)
#define FLASH_DEVICE_NODE DT_INST(0, st_stm32_qspi_nor)
#define FLASH_DEVICE_BASE DT_REG_ADDR(DT_INST(0, st_stm32_qspi_nor))
#else
#error "FLASH_DEVICE_NODE could not be determined"
#endif

#elif (!defined(CONFIG_XTENSA) && DT_HAS_CHOSEN(zephyr_flash_controller))
#define FLASH_DEVICE_ID SOC_FLASH_0_ID
#define FLASH_DEVICE_BASE CONFIG_FLASH_BASE_ADDRESS
#define FLASH_DEVICE_NODE DT_CHOSEN(zephyr_flash_controller)
Expand Down
Loading