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

Conversation

FRASTM
Copy link

@FRASTM FRASTM commented Dec 18, 2024

New version of the old PR #1891

Adding the stm32h7s3l8 nucleo board

Following zephyrproject-rtos/zephyr#76305

Build the application with sysbuild for the nucleo_h7S3L8 :

  1. west build -p auto -b nucleo_h7s3l8 samples/boards/st/hello_world_xip --sysbuild -- -DSB_CONFIG_BOOTLOADER_MCUBOOT=y
  2. then, download mcuboot at address 0x8000000 and download the signed hello_world_xip application at 0x70000000 (where i can read the magic nb)

@FRASTM
Copy link
Author

FRASTM commented Dec 18, 2024

requires the zephyrproject-rtos/zephyr#81651 which introduces the nucleo_h7s3l8 target
The application running in the external flash is a samples/hello_world available in the branch https://github.com/FRASTM/zephyr/tree/xip_h7s3

@de-nordic de-nordic added area: zephyr Affects the Zephyr port STM Changes related to STM platforms labels Dec 18, 2024
@JarmouniA
Copy link

JarmouniA commented Jan 17, 2025

@FRASTM Any plans to move forward with this PR? some CI issues to be fixed (Primarily caused by missing "Signed-off-by: Francois RAMU [email protected]" in some commits)

Copy link
Collaborator

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

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

same for all .dts files, otherwise you can't build a zephyr application for them

*/
/ {
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

@FRASTM
Copy link
Author

FRASTM commented Jan 23, 2025

correct sign-off
removing chosen zephyr,flash = &flash0; from the overlay as it is in the board DTS for zephyr


/ {
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

status = "okay";

partitions {
compatible = "fixed-partitions";
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 upstream zephyr board so it's visible to everything

Copy link
Author

Choose a reason for hiding this comment

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

The xspi1 node is not enabled in the zephyr boards/st/stm32h7s78_dk/
then moving the overlay from mcuboot to zephyr board DTS will create a dependency with another next PR in zephyr (a PR to add the xspi1 node)

@FRASTM FRASTM force-pushed the XIP_mcuboot branch 2 times, most recently from d81f77a to 500f4bd Compare January 23, 2025 15:17
@JarmouniA
Copy link

@FRASTM Any plans to mark this PR as ready?
@erwango

@Jowllel
Copy link

Jowllel commented Mar 29, 2025

These fixes seem a bit unclear to me. What do I need to change about the stm32h573i_dk board files, so I can use MCUBoot with XIP. My Issue is described in: zephyrproject-rtos/zephyr#87531

With CONFIG_STM32_MEMMAP flag get NOR flash 32 bytes header
Read the NOR flash to get header of the image.
The FLASH_DEVICE is now the external NOR defined by
the board device tree to be the first qspi/ospi/xspi instance
(not necessarily zephyr, flash-controller)

Signed-off-by: Francois Ramu <[email protected]>
@FRASTM
Copy link
Author

FRASTM commented Apr 2, 2025

rebased on the main branch c8470fb

tested on the nucleo_h7s3l8 where the external flash is MX25UW25645GXDI00
Requires the &xspi2 node definition

*** Booting MCUboot v2.1.0-rc1-187-g2d4946ed7e39 ***
*** Using Zephyr OS build v4.0.0-rc3-6-g88c5329c33e5 ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Image index: 0, Swap type: none
I: Bootloader chainload address offset: 0x0
I: Image version: v0.0.0
I: Jumping to the first image slot
*** Booting Zephyr OS build v4.0.0-rc3-6-g88c5329c33e5 ***
Hello World! from external flash  nucleo_h7s3l8

@FRASTM
Copy link
Author

FRASTM commented Apr 4, 2025

These fixes seem a bit unclear to me. What do I need to change about the stm32h573i_dk board files, so I can use MCUBoot with XIP. My Issue is described in: zephyrproject-rtos/zephyr#87531

@Jowllel, I will go with the stm32h573 disco kit in the coming days to execute from external flash

@FRASTM FRASTM force-pushed the XIP_mcuboot branch 3 times, most recently from 540654e to 374659f Compare April 11, 2025 13:36
@FRASTM FRASTM force-pushed the XIP_mcuboot branch 2 times, most recently from c821bee to 8d36285 Compare April 14, 2025 12:46
@FRASTM FRASTM marked this pull request as ready for review April 14, 2025 13:55
/ {
chosen {
zephyr,flash = &flash0;
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.

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).

Copy link
Collaborator

Choose a reason for hiding this comment

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

does this need to be added?

#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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Kconfig above looks correct for specifying the base address

FRASTM added 4 commits April 29, 2025 09:36
Define the stm32 disco board configuration to set
the STM32 XIP mode that will enable the MemoryMapped mode.
See Kconfig of the stm32 soc. Choose the mcu_boot partition
where to build ../bootloader/mcuboot/boot/zephyr
The zephyr, chosen zephyr,flash = &flash0; is in the board dts.
The zephyr,code-partition = &boot_partition; is given by the app.overlay

Signed-off-by: Francois Ramu <[email protected]>
Define the stm32h7s7 and stm32h73 board configuration to set
the STM32 XIP mode that will enable the MemoryMapped mode.
Gives larger sector size for the external NOR flash
See Kconfig of the stm32 soc. Choose the mcu_boot partition
where to build ../bootloader/mcuboot/boot/zephyr
The zephyr, chosen zephyr,flash = &flash0; is in the board dts.
The zephyr,code-partition = &boot_partition; is given by the app.overlay

Signed-off-by: F. Ramu <[email protected]>
Define the stm32h573 board configuration to set
the STM32 XIP mode that will enable the MemoryMapped mode.
Gives larger sector size for the external NOR flash
See Kconfig of the stm32 soc. Choose the mcu_boot partition
where to build ../bootloader/mcuboot/boot/zephyr
The zephyr, chosen zephyr,flash = &flash0; is in the board dts.
The zephyr,code-partition = &boot_partition; is given by the app.overlay

Signed-off-by: Francois Ramu <[email protected]>
FLASH_DEVICE_BASE is now given by the parent of the "st,stm32-xspi-nor"
node, which  is the "st,stm32-xspi" compatible

Signed-off-by: Francois Ramu <[email protected]>
@FRASTM
Copy link
Author

FRASTM commented Apr 29, 2025

without board overlay files :

  • zephyr,code-partition = &boot_partition; is in the app.overlay
  • zephyr,flash = &flash0; is already set in the board DTS

Requires the zephyrproject-rtos/zephyr#88579 where the CONFIG_FLASH_BASE_ADDRESS is defined by the soc/st/stm32/Kconfig.defconfig

#define FLASH_DEVICE_BASE DT_REG_ADDR(DT_INST(0, st_stm32_xspi_nor))
#define FLASH_DEVICE_BASE DT_REG_ADDR_BY_IDX(DT_INST(0, st_stm32_xspi),1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

fix in original commit

Copy link
Collaborator

Choose a reason for hiding this comment

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

does this need to be added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: zephyr Affects the Zephyr port STM Changes related to STM platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants