Skip to content

Conversation

JarmouniA
Copy link
Contributor

@JarmouniA JarmouniA commented Oct 6, 2025

Introduce a board variant for storing an app in external QSPI NOR Flash and chainloading it with MCUboot (which is placed in internal Flash) to be executed either in place (XiP) (MCUBOOT_MODE_DIRECT_XIP, set by default in board's Kconfig.sysbuild) or to be loaded to RAM and be executed there (MCUBOOT_MODE_RAM_LOAD).

The ext Flash memory partition also allows for using the Swap-using-offset & swap-using-move MCUboot image upgrade algorithms, eventhough it's not optimal as it has same-sized slots.

The new variant requires a board DT overlay on the MCUboot side (mcu-tools/mcuboot#2479) to set the internal Flash & Flash controller as the chosen 'zephyr,flash' & 'zephyr,flash-controller'. This way, no overlay will be needed at the Zephyr user app level.

west build -p always -b stm32h750b_dk/stm32h750xx/ext_flash_app samples/modules/lvgl/demos --sysbuild

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.

@JarmouniA I was wondering if snippets could be used instead of adding a target each time we need to introduce an ext_mem app. Did you look at this possibility ?
Just thinking out loud, maybe the combination with sysbuild doesn't work great.

@JarmouniA
Copy link
Contributor Author

@JarmouniA I was wondering if snippets could be used

Not sure what we would put in them, maybe an ext Flash-specific snippet, but then the internal Flash is not necessarily the same, its sector size...

Many Zephyr subsystems as well MCUboot rely on the write-block-size and
erase-block-size properties, of the chosen Flash device in DT,
to determine the optimal parameters for using the flash & its partitions.

Include the soc-nv-flash binding in STM32 External NOR Flash binding so
that those two properties can be specified in the external Flash node
in board DT.

Until now, the workaround for STM32 boards using MCUboot has been to
disable CONFIG_BOOT_MAX_IMG_SECTORS_AUTO in MCUboot's board extra conf
and to set CONFIG_BOOT_MAX_IMG_SECTORS manually depending on the app slot
size & the NOR Flash sector size.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
Pull in the necessary MCUboot bits, will be removed before merging the PR.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
@JarmouniA JarmouniA force-pushed the fix_h750b-dk_ext_flash_app branch from 95ac7ff to 573417e Compare October 6, 2025 21:19
Copy link

github-actions bot commented Oct 6, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
mcuboot mcu-tools/mcuboot@d5b0dcb mcu-tools/mcuboot#2479 mcu-tools/mcuboot#2479/files

Additional metadata changed:

Name URL Submodules West cmds module.yml Blobs
mcuboot

DNM label due to: 1 project with PR revision and 1 project with metadata changes

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-mcuboot DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Oct 6, 2025
@JarmouniA JarmouniA force-pushed the fix_h750b-dk_ext_flash_app branch from 573417e to 00106a2 Compare October 6, 2025 21:31
Introduce a board variant for storing an app in external QSPI NOR Flash
and chainloading it with MCUboot (placed in internal Flash) to be
executed either in place (XiP) (set by default, MCUBOOT_MODE_DIRECT_XIP)
or to be loaded to RAM and be executed there (MCUBOOT_MODE_RAM_LOAD).
The new variant requires a board DT overlay on the MCUboot side
to set the internal Flash & Flash controller as the chosen 'zephyr,flash'
& 'zephyr,flash-controller'.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
Add stm32h750b_dk/stm32h750xx/ext_flash_app target to CI platforms

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
Add stm32h750b_dk/stm32h750xx/ext_flash_app target to CI platforms.

Signed-off-by: Abderrahmane JARMOUNI <[email protected]>
@JarmouniA JarmouniA force-pushed the fix_h750b-dk_ext_flash_app branch from 00106a2 to b26dafd Compare October 6, 2025 21:34
Copy link

sonarqubecloud bot commented Oct 6, 2025

Please retry analysis of this Pull-Request directly on SonarQube Cloud

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.

Nice!

Though, I think we can get rid of the mcuboot overlay by using stm32h750b_dk as the mcuboot target. This way, mcuboot is a usual zephyr application running on internal flash.
(Note also that zephyr,code-partition = &boot_partition; is already defined in mcuboot app.overlay)

To do this, you probably need to add a sysbuild.cmake file to the board, stating:

if(SB_CONFIG_BOOTLOADER_MCUBOOT)
  set_target_properties(mcuboot PROPERTIES BOARD stm32h750b_dk/stm32h750xx)
endif()

and no mcuboot dependency anymore.

Can you have a try and report back (somehow I can't find any stm32h750b_dk here anymore to test it myself) ?

@JarmouniA
Copy link
Contributor Author

Though, I think we can get rid of the mcuboot overlay by using stm32h750b_dk as the mcuboot target. This way, mcuboot is a usual zephyr application running on internal flash. (Note also that zephyr,code-partition = &boot_partition; is already defined in mcuboot app.overlay)

I already thought of that, but the MCUboot App build depends on info specified in ext_flash_app variant dts, an example is info about the slots
https://github.com/mcu-tools/mcuboot/blob/17a6ecd279d631abfd865bfa041d40964f9ecc62/boot/zephyr/CMakeLists.txt#L500
https://github.com/mcu-tools/mcuboot/blob/17a6ecd279d631abfd865bfa041d40964f9ecc62/boot/zephyr/include/target.h#L39

There are potentially other interdependencies at the sysbuild level as well, I don't think it's a good idea to use different targets.

@erwango
Copy link
Member

erwango commented Oct 7, 2025

There are potentially other interdependencies at the sysbuild level as well, I don't think it's a good idea to use different targets.

It builds on my side. I'm just unable to test it.
Defining all partitions in a unique .dtsi file is already what we're doing for stm32n6570_dk, this shouldn't be an issue on h7 target. Do I miss something ?

@JarmouniA
Copy link
Contributor Author

It builds on my side. I'm just unable to test it. Defining all partitions in a unique .dtsi file is already what we're doing for stm32n6570_dk, this shouldn't be an issue on h7 target. Do I miss something ?

The MCUboot partitions (slot0, slot1...) are not relevant to the base variant, which is supposed to be used with a regular Zephyr app (MCUboot is not a regular app, it's a bootloader) in internal Flash & external Flash is used for storage or whatever,

reg = <0x00000000 DT_SIZE_M(128)>; /* 128MB */

So why would we put the MCUboot partitions in the common dtsi, and of what use would be the ext_flash_app variant in that case?

@erwango
Copy link
Member

erwango commented Oct 8, 2025

The MCUboot partitions (slot0, slot1...) are not relevant to the base variant, which is supposed to be used with a regular Zephyr app (MCUboot is not a regular app, it's a bootloader) in internal Flash & external Flash is used for storage or whatever,

We already have this case on other boards where "main" variant .dts provides slot0/slot1 on internal flash and this "main" variant could be used either as a "direct" zephyr application or chainloaded behind mcuboot.

Difference here is that we need a variant to be able to specify different zephyr,flash and zephyr,flash-controller, hence the need for a dedicated variant (ext_flash_app). With your proposal, we don't need to provide a .conf file anymore for the MCUBoot target, let's go one step further and get rid of the .overlay and dependency on MCUBoot completely.

Also note that these boards (based on h750, h7r/s) are a bit specific in the way that they have a quite limited internal flash and are meant to be used with a ext_flash, from which the main application should run.
Having the main variant running on internal flash is convenient in order to be able to run upstream zephyr samples and tests, but proposing the external flash as an extra large storage slot is only interesting for validation purpose, not as a real final app. If co-existence of this storage slot with slot0/slot1 partition on the main variant raises an issue, then it should be defined as an overlay in tests/samples that actually need it.

Last point about interest of the ext_flash_app variant is that it could be used to specify configurations that would not be supported on the main variant running on the internal flash (thinking about video use cases for instance). But I need to verify this point.

@JarmouniA
Copy link
Contributor Author

but proposing the external flash as an extra large storage slot is only interesting for validation purpose, not as a real final app

It could definitely be used that way in a product where app upgrade is not needed by just relocating the big/non-critical parts of the app, running from internal Flash, to ext Flash.

#address-cells = <1>;
#size-cells = <1>;

slot0_partition: partition@0 {
Copy link
Contributor Author

@JarmouniA JarmouniA Oct 8, 2025

Choose a reason for hiding this comment

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

This does not work in RAM_LOAD mode, build system considers the slot address as the user app's hex address (where image will be flashed), which is actually at an offset of 0x90000000.

set(imgtool_args ${imgtool_args} --hex-addr ${slot0_partition_address})

Copy link
Member

Choose a reason for hiding this comment

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

Did you try with CONFIG_XIP=n ? (required when RAM_LOAD is used)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's done by sysbuild

set_config_bool(${ZCMAKE_APPLICATION} CONFIG_XIP n)

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants