[PATCH] env: mmc: Use correct eMMC HW partition size when calculating end of HW partition
Simon Glass
sjg at chromium.org
Mon May 4 14:22:16 CEST 2026
Hi Marek,
On 2026-04-29T12:13:06, Marek Vasut <marex at nabladev.com> wrote:
> env: mmc: Use correct eMMC HW partition size when calculating end of HW partition
>
> When calculating the end of eMMC HW partition, it is necessary to
> use the length of that eMMC HW partition, not the length of the
> eMMC HW USER partition unconditionally, otherwise the end of e.g.
> eMMC HW BOOT partition will be way past the actual end of that eMMC
> HW BOOT partition. Add the missing distinction. eMMC HW GP partitions
> are not supported, so those are not considered here.
>
> Signed-off-by: Marek Vasut <marex at nabladev.com>
>
> env/mmc.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
> env: mmc: Use correct eMMC HW partition size when calculating end of HW partition
nit: subject is 84 chars - please trim to <=72, e.g. "env: mmc: Use
correct HW partition size for end-relative offset".
> diff --git a/env/mmc.c b/env/mmc.c
> @@ -239,8 +239,12 @@ __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
> return -ENOENT;
> }
>
> - if (offset < 0)
> - offset += mmc->capacity;
> + if (offset < 0) {
> + if (CONFIG_ENV_MMC_EMMC_HW_PARTITION)
> + offset += mmc->capacity_boot;
> + else
> + offset += mmc->capacity;
> + }
Just to clarify the motivation: every caller of mmc_get_env_addr()
goes through init_mmc_for_env(), which calls mmc_set_env_part_init()
-> blk_select_hwpart_devnum() -> mmc_switch_part() ->
mmc_set_capacity(). After that switch mmc->capacity should already
equal mmc->capacity_boot when CONFIG_ENV_MMC_EMMC_HW_PARTITION is 1 or
2. Can you describe the path where mmc->capacity is still
capacity_user here? Perhaps the fix belongs instead in the
partition-switch path?
> diff --git a/env/mmc.c b/env/mmc.c
> @@ -239,8 +239,12 @@ __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
> + if (CONFIG_ENV_MMC_EMMC_HW_PARTITION)
> + offset += mmc->capacity_boot;
> + else
> + offset += mmc->capacity;
This seems to do the wrong thing for
CONFIG_ENV_MMC_EMMC_HW_PARTITION=3 (RPMB) - it picks capacity_boot
when capacity_rpmb is meant. The Kconfig is a plain int with no upper
bound, so this is reachable. If you want to keep the explicit
dispatch, you could key it off mmc_get_blk_desc(mmc)->hwpart so all
partition kinds (user/boot/rpmb) fall out correctly. What do you
think?
Regards,
Simon
More information about the U-Boot
mailing list