[PATCH v2 3/4] fastboot: block: Add GPT/MBR partition table flashing support

Simon Glass sjg at chromium.org
Tue Apr 28 20:21:52 CEST 2026


Hi Balaji,

On 2026-04-27T12:06:41, Balaji Selvanathan
<balaji.selvanathan at oss.qualcomm.com> wrote:
> fastboot: block: Add GPT/MBR partition table flashing support
>
> Add support for flashing GPT and MBR partition tables to the
> fastboot block backend. This enables operations like "fastboot flash
> gpt gpt.img" and "fastboot flash mbr mbr.img" for block devices.
>
> The implementation validates partition table names and rejects
> invalid input formats such as ':gpt' or ':mbr' where the device
> prefix is missing. Valid formats include 'gpt', 'mbr', '0:gpt',
> and '1:mbr'.
>
> Update Kconfig dependencies to allow FASTBOOT_GPT_NAME and
> FASTBOOT_MBR_NAME to work with both MMC and block backends.
>
> Signed-off-by: Balaji Selvanathan <balaji.selvanathan at oss.qualcomm.com>
>
> drivers/fastboot/Kconfig    |  4 ++--
>  drivers/fastboot/fb_block.c | 49 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 51 insertions(+), 2 deletions(-)

> diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
> @@ -227,7 +227,7 @@ config FASTBOOT_FLASH_BLOCK_DEVICE_ID
> +Update Kconfig dependencies to allow FASTBOOT_GPT_NAME and
> +FASTBOOT_MBR_NAME to work with both MMC and block backends.`

Stray backtick at the end of this paragraph - please drop it.

> diff --git a/drivers/fastboot/fb_block.c b/drivers/fastboot/fb_block.c
> @@ -361,6 +382,34 @@ void fastboot_block_flash_write(const char *part_name, void *download_buffer,
> +#if CONFIG_IS_ENABLED(EFI_PARTITION)
> +     if (is_partition_table_name(part_name, CONFIG_FASTBOOT_GPT_NAME)) {
> +             int device;
> +             const char *interface = config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
> +                                                        CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME,
> +                                                        NULL);
> +
> +             parse_device_partition(part_name, &device, NULL);
> +             fastboot_flash_gpt_partition_table(interface, device,
> +                                                download_buffer, response);
> +             return;
> +     }
> +#endif
> +
> +#if CONFIG_IS_ENABLED(DOS_PARTITION)
> +     if (is_partition_table_name(part_name, CONFIG_FASTBOOT_MBR_NAME)) {
> +             int device;
> +             const char *interface = config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK,
> +                                                        CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME,
> +                                                        NULL);
> +
> +             parse_device_partition(part_name, &device, NULL);
> +             fastboot_flash_mbr_partition_table(interface, device,
> +                                                download_buffer, response);
> +             return;
> +     }
> +#endif

The two arms are near-identical and both repeat the interface lookup
that fastboot_block_get_part_info() already does. Please factor the
interface/device resolution into a small helper (or move it above the
#ifs) so the GPT and MBR branches reduce to the
is_partition_table_name() check and the helper call.

> diff --git a/drivers/fastboot/fb_block.c b/drivers/fastboot/fb_block.c
> @@ -361,6 +382,34 @@ void fastboot_block_flash_write(const char *part_name, void *download_buffer,
> +             parse_device_partition(part_name, &device, NULL);
> +             fastboot_flash_gpt_partition_table(interface, device,
> +                                                download_buffer, response);

The return value of parse_device_partition() is
discarded...is_partition_table_name() happens to filter out ':gpt'
today, so this is safe by construction, but the coupling is pretty
fragile - please check the return and fastboot_fail() on -EINVAL, or
add a comment explaining why it cannot fail. Same in the MBR branch.

Regards,
Simon


More information about the U-Boot mailing list