From: Tom Rini <trini@konsulko.com>
To: Carlo Caione <ccaione@baylibre.com>
Cc: u-boot@lists.u-boot-project.org,
uboot-stm32@st-md-mailman.stormreply.com,
"Peng Fan" <peng.fan@nxp.com>,
"Jaehoon Chung" <jh80.chung@samsung.com>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Bastien Curutchet" <bastien.curutchet@bootlin.com>,
"Alexey Charkov" <alchark@gmail.com>,
"Johan Jonker" <jbx6244@gmail.com>,
"Richard Genoud" <richard.genoud@bootlin.com>,
"João Marcos Costa" <joaomarcos.costa@bootlin.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"David Lechner" <dlechner@baylibre.com>,
"Julien Stephan" <jstephan@baylibre.com>,
"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
"Patrick Delaunay" <patrick.delaunay@foss.st.com>,
"Patrice Chotard" <patrice.chotard@foss.st.com>,
"Heinrich Schuchardt" <xypron.glpk@gmx.de>
Subject: Re: [PATCH v2 2/2] spl: mmc: support dynamic selection in raw partition mode
Date: Fri, 11 Sep 2026 11:41:22 -0600 [thread overview]
Message-ID: <20260911174122.GS1764417@bill-the-cat> (raw)
In-Reply-To: <20260911-ccaione-upstream-part-dynamic-v2-2-295fefc9a3c4@baylibre.com>
[-- Attachment #1: Type: text/plain, Size: 5171 bytes --]
On Fri, Sep 11, 2026 at 02:05:59PM +0200, Carlo Caione wrote:
> Boards using boot metadata to select U-Boot should not need to configure
> an unused fixed partition number. Add an explicit runtime-selection
> option within the existing partition mode, retaining its loader and
> platform dependencies.
>
> A failed dynamic selection must not boot from an unrelated filesystem
> partition. Reject an invalid selection for this MMC attempt while keeping
> the existing fallback behavior when dynamic selection is disabled.
>
> STM32's existing hook implements fixed partition selection and references
> the static partition settings. Restrict it and its MMC2 setting to fixed
> mode so dynamic selection can provide its own hook.
>
> The board hook owns hardware-area selection, including access to metadata
> and leaving the image area selected.
>
> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
> ---
> arch/arm/mach-stm32mp/Kconfig | 1 +
> arch/arm/mach-stm32mp/stm32mp1/spl.c | 2 +-
> common/spl/Kconfig | 9 +++++++++
> common/spl/spl_mmc.c | 19 +++++++++++++------
> include/spl.h | 14 +++++++++-----
> 5 files changed, 33 insertions(+), 12 deletions(-)
>
> diff --git a/arch/arm/mach-stm32mp/Kconfig b/arch/arm/mach-stm32mp/Kconfig
> index f45010ddbd0..bea4a1b6aaf 100644
> --- a/arch/arm/mach-stm32mp/Kconfig
> +++ b/arch/arm/mach-stm32mp/Kconfig
> @@ -175,6 +175,7 @@ config DDR_CACHEABLE_SIZE
> config SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_MMC2
> hex "Partition on MMC2 to use to load U-Boot from"
> depends on SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
> + depends on !SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_DYNAMIC
> default 1
> help
> Partition on the second MMC to load U-Boot from when the MMC is being
> diff --git a/arch/arm/mach-stm32mp/stm32mp1/spl.c b/arch/arm/mach-stm32mp/stm32mp1/spl.c
> index 2229ebf5eeb..c1be468cb1d 100644
> --- a/arch/arm/mach-stm32mp/stm32mp1/spl.c
> +++ b/arch/arm/mach-stm32mp/stm32mp1/spl.c
> @@ -61,7 +61,7 @@ u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
> return MMCSD_MODE_RAW;
> }
>
> -#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
> +#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
> int spl_mmc_boot_partition(struct mmc *mmc, const u32 boot_device)
> {
> switch (boot_device) {
> diff --git a/common/spl/Kconfig b/common/spl/Kconfig
> index 0618f42c941..9e1c23ea0f4 100644
> --- a/common/spl/Kconfig
> +++ b/common/spl/Kconfig
> @@ -576,6 +576,14 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
>
> endchoice
>
> +config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_DYNAMIC
> + bool "Select the raw partition at runtime"
> + depends on SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
> + select SPL_PARTITIONS
> + help
> + Select the partition at runtime instead of using a fixed number.
> + The board must implement spl_mmc_boot_partition().
> +
> config SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
> hex "Address on the MMC to load U-Boot from"
> depends on SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
> @@ -609,6 +617,7 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET
> config SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
> hex "Partition to use to load U-Boot from"
> depends on SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
> + depends on !SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_DYNAMIC
> default 1
> help
> Partition on the MMC to load U-Boot from when the MMC is being
> diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
> index 3e637f5adbd..d538fbb9c41 100644
> --- a/common/spl/spl_mmc.c
> +++ b/common/spl/spl_mmc.c
> @@ -303,7 +303,11 @@ u32 __weak spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
> #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
> int __weak spl_mmc_boot_partition(struct mmc *mmc, const u32 boot_device)
> {
> +#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
> return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
> +#else
> + return -ENOSYS;
> +#endif
> }
> #endif
>
> @@ -432,8 +436,15 @@ int spl_mmc_load(struct spl_image_info *spl_image,
> #elif defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION) || \
> defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE)
> if (IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION) &&
> - raw_part == -1)
> + raw_part == -1) {
> raw_part = spl_mmc_boot_partition(mmc, bootdev->boot_device);
> + if (IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_DYNAMIC) &&
> + raw_part < 1) {
> + ret = raw_part < 0 ? raw_part : -EINVAL;
> + printf("spl: partition selection failed: %d\n", ret);
> + return ret;
> + }
> + }
> ret = mmc_load_image_raw_partition(spl_image, bootdev,
> mmc, raw_part,
> raw_sect);
This is better than v1. Did you look in to my suggestion about turning
this in to a choice between hard-coded number, hard-coded type and this
new dynamic option? I do wonder if that would let us get rid of a lot of
the if/else nesting we have in these functions. Thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-09-11 17:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 12:05 [PATCH v2 0/2] Support board-selected raw partitions Carlo Caione
2026-09-11 12:05 ` [PATCH v2 1/2] spl: mmc: select the boot partition after device initialization Carlo Caione
2026-09-11 12:05 ` [PATCH v2 2/2] spl: mmc: support dynamic selection in raw partition mode Carlo Caione
2026-09-11 17:41 ` Tom Rini [this message]
2026-09-12 10:51 ` Carlo Caione
2026-09-12 14:41 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260911174122.GS1764417@bill-the-cat \
--to=trini@konsulko.com \
--cc=alchark@gmail.com \
--cc=bastien.curutchet@bootlin.com \
--cc=ccaione@baylibre.com \
--cc=dlechner@baylibre.com \
--cc=ilias.apalodimas@linaro.org \
--cc=jbx6244@gmail.com \
--cc=jh80.chung@samsung.com \
--cc=joaomarcos.costa@bootlin.com \
--cc=jstephan@baylibre.com \
--cc=miquel.raynal@bootlin.com \
--cc=neil.armstrong@linaro.org \
--cc=patrice.chotard@foss.st.com \
--cc=patrick.delaunay@foss.st.com \
--cc=peng.fan@nxp.com \
--cc=richard.genoud@bootlin.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=uboot-stm32@st-md-mailman.stormreply.com \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox