[PATCH v2 2/4] fastboot: Add GPT/MBR partition table flashing helper functions
Simon Glass
sjg at chromium.org
Tue Apr 28 20:20:40 CEST 2026
Hi Balaji,
On 2026-04-27T12:06:41, Balaji Selvanathan
<balaji.selvanathan at oss.qualcomm.com> wrote:
> fastboot: Add GPT/MBR partition table flashing helper functions
>
> Add fastboot_flash_gpt_partition_table() and
> fastboot_flash_mbr_partition_table() helper functions that handle
> flashing of GPT and MBR partition tables to block devices.
>
> The MMC backend now uses these helper functions for GPT and MBR
> operations, simplifying the code while maintaining the same
> functionality.
>
> Signed-off-by: Balaji Selvanathan <balaji.selvanathan at oss.qualcomm.com>
>
> drivers/fastboot/fb_common.c | 94 ++++++++++++++++++++++++++++++++++++++++++++
> drivers/fastboot/fb_mmc.c | 49 ++++-------------------
> include/fastboot-internal.h | 30 ++++++++++++++
> 3 files changed, 131 insertions(+), 42 deletions(-)
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)
> + dev_desc = blk_get_dev(interface, device);
> + if (!dev_desc) {
> + fastboot_fail("no such device", response);
> + return;
> + }
Looks like a regression for the MMC path: the current
fastboot_mmc_get_dev() rejects dev_desc->type == DEV_TYPE_UNKNOWN (mmc
driver present but no card) and reports 'invalid mmc device'. That
check is gone after this refactor, so an unprobed mmc falls through to
is_valid_gpt_buf() / write_mbr_and_gpt_partitions() with an unusable
dev_desc - please add the DEV_TYPE_UNKNOWN check in both helpers so
the common path is at least as strict as the code it replaces.
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)
> +#if CONFIG_IS_ENABLED(EFI_PARTITION)
> +/**
> + * fastboot_flash_gpt_partition_table() - Flash GPT partition table
> + * @interface: Block interface name (e.g., 'mmc', 'scsi')
> + * @device: Device number
> + * @download_buffer: Buffer containing GPT data
> + * @response: Fastboot response buffer
> + */
> +void fastboot_flash_gpt_partition_table(const char *interface,
> + int device,
> + void *download_buffer,
> + char *response)
The two helpers are almost identical - only is_valid_*_buf(),
write_mbr_*() and a couple of printed strings differ. Please factor
the common parts (interface check, blk_get_dev(), DEV_TYPE_UNKNOWN
check, part_init() + okay) and have the GPT and MBR variants supply
just the validate/write step. As written, the fail-paths are
duplicated and will drift over time.
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)
> + if (is_valid_gpt_buf(dev_desc, download_buffer)) {
> + printf("%s: invalid GPT - refusing to write to flash\n", __func__);
fb_common.c does not include <part.h> or <blk.h> even though it now
calls blk_get_dev(), is_valid_gpt_buf(),
write_mbr_and_gpt_partitions(), is_valid_dos_buf(), write_mbr_sector()
and part_init(). It builds today via a transitive include, but let's
add explicit includes.
> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
> @@ -343,7 +343,7 @@ int fastboot_mmc_get_part_info(const char *part_name,
> -static struct blk_desc *fastboot_mmc_get_dev(char *response)
> +static struct blk_desc __maybe_unused *fastboot_mmc_get_dev(char *response)
The convention is 'static __maybe_unused struct blk_desc
*fastboot_mmc_get_dev(...)'
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> @@ -245,3 +245,97 @@ void fastboot_init(void *buf_addr, u32 buf_size)
> + if (!interface || !strcmp(interface, "")) {
> + fastboot_fail("block interface isn't provided", response);
> + return;
> + }
The MMC caller passes the literal 'mmc', so this branch is dead on
that path. The check is really for the block backend in patch 3, where
the interface comes from CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME.
That validation belongs in the block caller (alongside the
parse_device_partition() call), not duplicated in both common helpers
- same reason fastboot_block_get_part_info() already does the check
itself.
Regards,
Simon
More information about the U-Boot
mailing list