Skip to content

boards: st: refine boards embedding a scratch partition - #102759

Open
etienne-lms wants to merge 11 commits into
zephyrproject-rtos:mainfrom
etienne-lms:stm32-flash-layout
Open

boards: st: refine boards embedding a scratch partition#102759
etienne-lms wants to merge 11 commits into
zephyrproject-rtos:mainfrom
etienne-lms:stm32-flash-layout

Conversation

@etienne-lms

@etienne-lms etienne-lms commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

This P-R targets ST boards that are currently embedded a scratch partition in their flash layout (for MCUBoot use).

Some need to use swap-with-scratch MCUBoot mode due to big size of the sectors of the slot0/slot1 partitions (from 128kB to 256kB). For these boards, add a Kconf.sysbuild file to default enable MCUBOOT_MODE_SWAP_SCRATCH when needed.

Some do not need and can leverage the recommended swap-using-offset MCUBoot mode (that is the default mode enabled). Update the flash layout for these boards: by enlarging the slot1 partition and removing the useless scratch partition.

This P-R proposes the fix some DTS flash layout inconsistencies regarding the internal flash sector distribution (nucleo_f746zg, sensor_tile, nucleo_f207zg). This changes really apply only when MCUBoot is embedded unless what these board assigns the full internal flash to the Zephyr application.

@etienne-lms

etienne-lms commented Jan 23, 2026

Copy link
Copy Markdown
Contributor Author

Regarding MCUBoot support for boards, these boards that require swap-with-scratch can be handle in 2 ways:
* Either only enable MCUBOOT_MODE_SWAP_SCRATCH when BOOTLOADER_MCUBOOT is set.
This would add a Kconfig.sysbuild file in the related boards directory.
An example in this commit (temporary ref).

* Or provide a preconfig sysbuild env for the related boards that enable MCUBOOT & SWAP_SCRATCH.
This would add a Kconfig.sysbuild file + a note in the board doc in the related boards directory.
An example in this commit (temporary ref).

I prefer the former, not defaulting sysbuild to MCUBoot config and as more inline with Building a sample with MCUboot generic documentation.

(edited) I'll update this P-R using the 1st proposal: only enable MCUBOOT_MODE_SWAP_SCRATCH when BOOTLOADER_MCUBOOT is enable.

Comment thread boards/st/nucleo_f207zg/nucleo_f207zg.dts Outdated
@zephyrbot
zephyrbot requested review from HoZHel and asm5878 January 23, 2026 15:32
@etienne-lms etienne-lms changed the title [RFC] boards: st: fix flash layout on some boards + ease MCUBoot/sysbuild support boards: st: refine boards embedding a scratch partition Jan 23, 2026
@etienne-lms
etienne-lms force-pushed the stm32-flash-layout branch 3 times, most recently from 5979c53 to 9f89149 Compare January 23, 2026 17:03
@sonarqubecloud

Copy link
Copy Markdown

@djiatsaf-st djiatsaf-st left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

There are two open PRs that address CI build errors related to this PR.

@djiatsaf-st

djiatsaf-st commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

There are two open PRs that address CI build errors related to this PR.

The two PRs have been merged; you can now rebase.

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions Bot added the Stale label Mar 19, 2026
@erwango erwango added this to the v4.5.0 milestone Mar 19, 2026
@erwango erwango removed the Stale label Mar 19, 2026
@etienne-lms

Copy link
Copy Markdown
Contributor Author

Rebased

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@djiatsaf-st

Copy link
Copy Markdown
Contributor

LGTM,
Maybe this suggestion could help to solve the build CI issue

@etienne-lms

Copy link
Copy Markdown
Contributor Author

Thanks. I missed it, my apologies.

@sonarqubecloud

Copy link
Copy Markdown

@etienne-lms
etienne-lms force-pushed the stm32-flash-layout branch from 37f20e7 to d01f5a8 Compare June 1, 2026 06:22
@etienne-lms

Copy link
Copy Markdown
Contributor Author

Rebased to re-run CI tests.

@zephyrbot
zephyrbot requested a review from de-nordic June 1, 2026 06:24
@etienne-lms
etienne-lms force-pushed the stm32-flash-layout branch from d01f5a8 to 8e34b09 Compare June 3, 2026 16:13
@etienne-lms

Copy link
Copy Markdown
Contributor Author

Rebased (no changes) to re-run CI tests.

@sonarqubecloud

sonarqubecloud Bot commented Jun 3, 2026

Copy link
Copy Markdown

Correct the flash layout regarding flash sections sizes. Internal flash
sector 4 (at offset 0x20000) is 128kB large, followed by sectors 5 to
7 that are 256kB large. Change storage, slot0 and slot1 partition to
lay inside sector boundaries. Since storage requires at least 2 sectors,
move it to flash sector 2 and 3 (32kB each) and reduce boot partition
to 64kB.

With these changes, sector 4 (128kB) is unused.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Correct the storage partition in sensortile_box board flash layout that
was not consistent and overlapped scratch partition end.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Correct nucleo_f446re storage partition that needs at least 2 sectors
to be somewhat useful while prior this change was the partition
located in a single 64kB sector.

The SoC internal flash starts with 4 contiguous sectors of 16kByte
followed by 1 sector of 64kByte, make this latter unused and assign
32kB (2 sectors of 16kB) for each boot and storage partitions.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Correct nucleo_f446ze storage partition that needs at least 2 sectors
to be somewhat useful while prior this change was the partition
located in a single 64kB sector.

The SoC internal flash starts with 4 contiguous sectors of 16kByte
followed by 1 sector of 64kByte, make this latter unused and assign
32kB (2 sectors of 16kB) for each boot and storage partitions.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Correct the slot1 partition layout that overlapped slot0 partition
end.

While at it, also explain that storage partition could be enabled onlya
when booting with MCUBoot (in which case Zephyr application in in slot0)
and fix scratch partition node name from "partiimagtion@..." to
"partition@...".

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Remove the storage partition from nucleo_h743zi flash layout since
store needs at least 2 sectors to operate while the flash area used
was made of a single erasable sector.

Update littlefs sample board overlay file accordingly.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Add missing zephyr,code-partition DT chosen property in ST boards
that lack one while defining a slot0 partition. It is needed to embed
MCUBoot using sysbuild.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
…ratch

When MCUBoot boot stage is built with sysbuild, select
MCUBOOT_MODE_SWAP_SCRATCH as firmware update scheme since the default
scheme (MCUBOOT_MODE_SWAP_WITH_OFFSET) is not supported by the boards
modified by the change, I.e. boars whose flash sectors are too big
to leverage MCUBoot mode swap-using-offset or another swap scheme
not using a scratch partition.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
…ffset

Enlarge slot1 partition by one sector and remove useless scratch
partition in the flash layout of the ST boards that can fully support
MCUBoot mode swap-using-offset mode but still define the old
flash layout compliant with MCUBoot swap-with-scratch mode for
firmware update support.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Nucleo_f410rb board can only support MCUBoot update with overwrite only
mode due the very limmited number of sectors in the internal flash.
Therefore enable MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY when
using sysbuild to embed MCUBoot and correct the flash layout since
scratch partition cannot be used.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
…tion

Change stm32f0_disco board to add a storage partition at the end of the
flash and increase update-able application slots by 4kByte when MCUboot
is embedded.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
@etienne-lms
etienne-lms force-pushed the stm32-flash-layout branch from 8e34b09 to 78bf71d Compare July 4, 2026 13:02
@etienne-lms

Copy link
Copy Markdown
Contributor Author

Rebased (no change) to get CI build failures fixed.

compatible = "zephyr,mapped-partition";
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(64)>;
reg = <0x00000000 DT_SIZE_K(32)>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess you will need to verify if MCUboot with its default config fits in 32KB, otherwise will need to add a SoC-specific MCUboot conf with certain non-essential things disabled.

@sonarqubecloud

sonarqubecloud Bot commented Jul 4, 2026

Copy link
Copy Markdown

@JarmouniA JarmouniA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FYI, following the merge of MCUboot logical sectors mcu-tools/mcuboot#2786, SoCs with non-uniform Flash sector sizes no longer need swap-using-scratch (which will be deprecated mcu-tools/mcuboot#2792).

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.

5 participants