[U-Boot] [PATCH] fastboot: mmc: add support for flashing boot partitions

Fabien Parent fparent at baylibre.com
Tue Jun 25 16:43:15 UTC 2019


MMC storage supports 4 hardware partitions:
	* User partition
	* 2 boot partitions
	* RPMB partition

Flashing to the User partition is already supported, and this commit
adds support for flashing to the 2 boot partitions.

User can run the following commands to flash to the boot partitions:
	fastboot flash mmcboot0 myfile
	fastboot flash mmcboot1 myfile

"mmcboot" is the default name of the partition and can be changed via
a Kconfig option.

Signed-off-by: Fabien Parent <fparent at baylibre.com>
---
 drivers/fastboot/Kconfig  | 17 +++++++++++++++++
 drivers/fastboot/fb_mmc.c | 36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index d63ecdd27e..f481d7596c 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -126,6 +126,23 @@ config FASTBOOT_MBR_NAME
 	  specified on the "fastboot flash" command line matches the value
 	  defined here. The default target name for updating MBR is "mbr".
 
+config FASTBOOT_MMC_BOOT_PART_NAME
+	string "Target name for updating MMC's boot partitions"
+	depends on FASTBOOT_FLASH_MMC
+	default "mmcboot"
+	help
+	  The fastboot "flash" command supports writing the downloaded
+	  image to the MMC's boot partitions.
+	  This occurs when the specified "partition name" on the
+	  "fastboot flash" command line is starts with the value defined here,
+	  and ends with '0' or '1' to specify which boot partition is being
+	  targeted.
+	  The default name for updating the boot partitions is "mmcboot".
+	  For example the two partitions can be flashed using the following
+	  commands if the default name is used:
+	    - "fastboot flash mmcboot0 myfile",
+	    - "fastboot flash mmcboot1 myfile".
+
 config FASTBOOT_CMD_OEM_FORMAT
 	bool "Enable the 'oem format' command"
 	depends on FASTBOOT_FLASH_MMC && CMD_GPT
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 90ca81da9b..c2451200f7 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -46,6 +46,28 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
 	return ret;
 }
 
+static int part_get_mmc_boot_info(int hwpart, disk_partition_t *info)
+{
+	struct mmc *mmc;
+	int ret;
+
+	mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
+	if (!mmc)
+		return -EINVAL;
+
+	ret = blk_select_hwpart_devnum(IF_TYPE_MMC,
+				       CONFIG_FASTBOOT_FLASH_MMC_DEV, hwpart);
+	if (ret < 0)
+		return ret;
+
+	memset(info, 0, sizeof(*info));
+	info->start = 0;
+	info->size = mmc->capacity_boot;
+	info->blksz = mmc->write_bl_len;
+
+	return 0;
+}
+
 /**
  * fb_mmc_blk_write() - Write/erase MMC in chunks of FASTBOOT_MAX_BLK_WRITE
  *
@@ -394,7 +416,19 @@ void fastboot_mmc_flash_write(const char *cmd, void *download_buffer,
 	}
 #endif
 
-	if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) {
+	if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT_PART_NAME "0") == 0) {
+		if (part_get_mmc_boot_info(1, &info) < 0) {
+			pr_err("cannot find partition: '%s'\n", cmd);
+			fastboot_fail("cannot find partition", response);
+			return;
+		}
+	} else if (strcmp(cmd, CONFIG_FASTBOOT_MMC_BOOT_PART_NAME "1") == 0) {
+		if (part_get_mmc_boot_info(2, &info) < 0) {
+			pr_err("cannot find partition: '%s'\n", cmd);
+			fastboot_fail("cannot find partition", response);
+			return;
+		}
+	} else if (part_get_info_by_name_or_alias(dev_desc, cmd, &info) < 0) {
 		pr_err("cannot find partition: '%s'\n", cmd);
 		fastboot_fail("cannot find partition", response);
 		return;
-- 
2.20.1



More information about the U-Boot mailing list