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

Balaji Selvanathan balaji.selvanathan at oss.qualcomm.com
Mon Apr 27 14:06:44 CEST 2026


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>
---
Changes in v2:
- Newly created in v2
- Adds GPT and MBR flash support to fastboot block codes
---
 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
index 576c3ef8a45..43d83265df4 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -227,7 +227,7 @@ config FASTBOOT_FLASH_BLOCK_DEVICE_ID
 
 config FASTBOOT_GPT_NAME
 	string "Target name for updating GPT"
-	depends on FASTBOOT_FLASH_MMC && EFI_PARTITION
+	depends on (FASTBOOT_FLASH_MMC || FASTBOOT_FLASH_BLOCK) && EFI_PARTITION
 	default "gpt"
 	help
 	  The fastboot "flash" command supports writing the downloaded
@@ -240,7 +240,7 @@ config FASTBOOT_GPT_NAME
 
 config FASTBOOT_MBR_NAME
 	string "Target name for updating MBR"
-	depends on FASTBOOT_FLASH_MMC && DOS_PARTITION
+	depends on (FASTBOOT_FLASH_MMC || FASTBOOT_FLASH_BLOCK) && DOS_PARTITION
 	default "mbr"
 	help
 	  The fastboot "flash" command allows to write the downloaded image
diff --git a/drivers/fastboot/fb_block.c b/drivers/fastboot/fb_block.c
index 061ffd930a5..a8c74e35d0d 100644
--- a/drivers/fastboot/fb_block.c
+++ b/drivers/fastboot/fb_block.c
@@ -163,6 +163,27 @@ static int parse_device_partition(const char *part_name, int *device,
 	return 0;
 }
 
+/**
+ * is_partition_table_name() - Check if name matches partition table target
+ * @part_name: Partition name to check
+ * @table_name: Config name for partition table (e.g., "gpt", "mbr")
+ *
+ * Returns: true if part_name matches table_name (with or without device prefix)
+ */
+static bool is_partition_table_name(const char *part_name, const char *table_name)
+{
+	const char *colon_pos;
+
+	if (strcmp(part_name, table_name) == 0)
+		return true;
+
+	colon_pos = strchr(part_name, ':');
+	if (colon_pos && colon_pos > part_name && strcmp(colon_pos + 1, table_name) == 0)
+		return true;
+
+	return false;
+}
+
 int fastboot_block_get_part_info(const char *part_name,
 				 struct blk_desc **dev_desc,
 				 struct disk_partition *part_info,
@@ -361,6 +382,34 @@ void fastboot_block_flash_write(const char *part_name, void *download_buffer,
 	struct blk_desc *dev_desc;
 	struct disk_partition part_info;
 
+#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
+
 	if (fastboot_block_get_part_info(part_name, &dev_desc, &part_info, response) < 0)
 		return;
 

-- 
2.34.1



More information about the U-Boot mailing list