Message ID | 20250606-topic-fastboot-blk-v5-3-203538ec5b32@linaro.org |
---|---|
State | New |
Headers | show |
Series | fastboot: add support for generic block flashing | expand |
On Fri, Jun 06, 2025 at 11:33:09AM +0200, Neil Armstrong wrote: > From: Dmitrii Merkurev <dimorinny@google.com> > > 1. Get partition info/size > 2. Erase partition > 3. Flash partition > 4. BCB > > Signed-off-by: Dmitrii Merkurev <dimorinny@google.com> > Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> > Tested-by: Mattijs Korpershoek <mkorpershoek@kernel.org> > Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org> > --- > drivers/fastboot/Kconfig | 29 ++++++++++++++++++++++++++++- > drivers/fastboot/Makefile | 1 + > drivers/fastboot/fb_command.c | 8 ++++++++ > drivers/fastboot/fb_common.c | 22 ++++++++++++++++++---- > drivers/fastboot/fb_getvar.c | 8 +++++++- > 5 files changed, 62 insertions(+), 6 deletions(-) > > diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig > index 70207573de2bd0d56b4b7fa6f7e17fdc5803ba15..75911468ba4980d9b96e2af9e708f08b9ef16ac8 100644 > --- a/drivers/fastboot/Kconfig > +++ b/drivers/fastboot/Kconfig > @@ -91,7 +91,7 @@ config FASTBOOT_USB_DEV > config FASTBOOT_FLASH > bool "Enable FASTBOOT FLASH command" > default y if ARCH_SUNXI || ARCH_ROCKCHIP > - depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) > + depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) || BLK This is what's tricky. The symbol FASTBOOT_FLASH is default y for all ARCH_SUNXI and ARCH_ROCKCHIP platforms where FASTBOOT is enabled. Since looking in to effects here isn't super well documented, I'm going to be a bit more verbose here than I might otherwise just to have a post to refer back to later (possibly for adding to something under doc/develop/). So, tools/qconfig.py can be helpful here. If we use -b to first build the database of boards and CONFIG sybmols enabled, we can then do: $ tools/qconfig.py -f FASTBOOT ARCH_SUNXI BLK to get everything that is FASTBOOT and ARCH_SUNXI and BLK. We can also do: $ tools/qconfig.py -f FASTBOOT ARCH_SUNXI BLK ~FASTBOOT_FLASH To get the same as the above, but do not enable FASTBOOT_FLASH. This gives us the CHIP platform. This is going to be the one that now enables the new functionality. If we do the same but for ARCH_ROCKCHIP we get zero matches. So this is our culprit. This means the series, and this patch here needs to also disable the new functionality on the CHIP defconfig.
On 06/06/2025 16:36, Tom Rini wrote: > On Fri, Jun 06, 2025 at 11:33:09AM +0200, Neil Armstrong wrote: > >> From: Dmitrii Merkurev <dimorinny@google.com> >> >> 1. Get partition info/size >> 2. Erase partition >> 3. Flash partition >> 4. BCB >> >> Signed-off-by: Dmitrii Merkurev <dimorinny@google.com> >> Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com> >> Tested-by: Mattijs Korpershoek <mkorpershoek@kernel.org> >> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org> >> --- >> drivers/fastboot/Kconfig | 29 ++++++++++++++++++++++++++++- >> drivers/fastboot/Makefile | 1 + >> drivers/fastboot/fb_command.c | 8 ++++++++ >> drivers/fastboot/fb_common.c | 22 ++++++++++++++++++---- >> drivers/fastboot/fb_getvar.c | 8 +++++++- >> 5 files changed, 62 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig >> index 70207573de2bd0d56b4b7fa6f7e17fdc5803ba15..75911468ba4980d9b96e2af9e708f08b9ef16ac8 100644 >> --- a/drivers/fastboot/Kconfig >> +++ b/drivers/fastboot/Kconfig >> @@ -91,7 +91,7 @@ config FASTBOOT_USB_DEV >> config FASTBOOT_FLASH >> bool "Enable FASTBOOT FLASH command" >> default y if ARCH_SUNXI || ARCH_ROCKCHIP >> - depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) >> + depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) || BLK > > This is what's tricky. The symbol FASTBOOT_FLASH is default y for all > ARCH_SUNXI and ARCH_ROCKCHIP platforms where FASTBOOT is enabled. Since > looking in to effects here isn't super well documented, I'm going to be > a bit more verbose here than I might otherwise just to have a post to > refer back to later (possibly for adding to something under > doc/develop/). > > So, tools/qconfig.py can be helpful here. If we use -b to first build > the database of boards and CONFIG sybmols enabled, we can then do: > $ tools/qconfig.py -f FASTBOOT ARCH_SUNXI BLK > to get everything that is FASTBOOT and ARCH_SUNXI and BLK. > We can also do: > $ tools/qconfig.py -f FASTBOOT ARCH_SUNXI BLK ~FASTBOOT_FLASH > To get the same as the above, but do not enable FASTBOOT_FLASH. This > gives us the CHIP platform. This is going to be the one that now enables > the new functionality. If we do the same but for ARCH_ROCKCHIP we get > zero matches. So this is our culprit. > > This means the series, and this patch here needs to also disable the new > functionality on the CHIP defconfig. > Wow thanks for finding that, I didn't imagine this could cause such issues. Thanks, Neil
diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 70207573de2bd0d56b4b7fa6f7e17fdc5803ba15..75911468ba4980d9b96e2af9e708f08b9ef16ac8 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -91,7 +91,7 @@ config FASTBOOT_USB_DEV config FASTBOOT_FLASH bool "Enable FASTBOOT FLASH command" default y if ARCH_SUNXI || ARCH_ROCKCHIP - depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) + depends on MMC || (MTD_RAW_NAND && CMD_MTDPARTS) || BLK select IMAGE_SPARSE help The fastboot protocol includes a "flash" command for writing @@ -119,6 +119,10 @@ config FASTBOOT_FLASH_NAND bool "FASTBOOT on NAND" depends on MTD_RAW_NAND && CMD_MTDPARTS +config FASTBOOT_FLASH_BLOCK + bool "FASTBOOT on block device" + depends on BLK + endchoice config FASTBOOT_FLASH_MMC_DEV @@ -193,6 +197,29 @@ config FASTBOOT_MMC_USER_NAME defined here. The default target name for erasing EMMC_USER is "mmc0". +config FASTBOOT_FLASH_BLOCK_INTERFACE_NAME + string "Define FASTBOOT block interface name" + depends on FASTBOOT_FLASH_BLOCK + help + The fastboot "flash" and "erase" commands support operations + on any Block device, this should specify the block device name + like ide, scsi, usb, sata, nvme, virtio, blkmap, mtd... + The mmc block device type can be used but most of the features + available in the FASTBOOT_MMC will be missing. + Consider using FASTBOOT_MMC on a MMC block device until all + features are migrated. + +config FASTBOOT_FLASH_BLOCK_DEVICE_ID + int "Define FASTBOOT block device identifier" + depends on FASTBOOT_FLASH_BLOCK + default 0 + help + The fastboot "flash" and "erase" commands support operations + on any Block device, this should specify the block device + identifier on the system, as a number. + Device identifiers are numbered starting from 0 and the most + common case is to use the first controller on the system. + config FASTBOOT_GPT_NAME string "Target name for updating GPT" depends on FASTBOOT_FLASH_MMC && EFI_PARTITION diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile index c2214c968ab357371f5d3d27ecc9c1a3e9404e89..91e98763e8eab84ccd9b8e5354ff1419f61ef372 100644 --- a/drivers/fastboot/Makefile +++ b/drivers/fastboot/Makefile @@ -3,6 +3,7 @@ obj-y += fb_common.o obj-y += fb_getvar.o obj-y += fb_command.o +obj-$(CONFIG_FASTBOOT_FLASH_BLOCK) += fb_block.o # MMC reuses block implementation obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_block.o fb_mmc.o obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o diff --git a/drivers/fastboot/fb_command.c b/drivers/fastboot/fb_command.c index 2cdbac50ac4a0ce501753e95c1918ffa5d11158d..e6aee13e01618ee6567bf00527d3df327ae06f1c 100644 --- a/drivers/fastboot/fb_command.c +++ b/drivers/fastboot/fb_command.c @@ -8,6 +8,7 @@ #include <env.h> #include <fastboot.h> #include <fastboot-internal.h> +#include <fb_block.h> #include <fb_mmc.h> #include <fb_nand.h> #include <part.h> @@ -337,6 +338,10 @@ void fastboot_data_complete(char *response) */ static void __maybe_unused flash(char *cmd_parameter, char *response) { + if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_BLOCK)) + fastboot_block_flash_write(cmd_parameter, fastboot_buf_addr, + image_size, response); + if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) fastboot_mmc_flash_write(cmd_parameter, fastboot_buf_addr, image_size, response); @@ -357,6 +362,9 @@ static void __maybe_unused flash(char *cmd_parameter, char *response) */ static void __maybe_unused erase(char *cmd_parameter, char *response) { + if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_BLOCK)) + fastboot_block_erase(cmd_parameter, response); + if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) fastboot_mmc_erase(cmd_parameter, response); diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c index 68f92c4b887c8442cc212b8613fb70c7251cdcdf..dac5528f80908bf5b1224284c9ecd492394e4f0e 100644 --- a/drivers/fastboot/fb_common.c +++ b/drivers/fastboot/fb_common.c @@ -97,16 +97,24 @@ int __weak fastboot_set_reboot_flag(enum fastboot_reboot_reason reason) [FASTBOOT_REBOOT_REASON_FASTBOOTD] = "boot-fastboot", [FASTBOOT_REBOOT_REASON_RECOVERY] = "boot-recovery" }; - const int mmc_dev = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, - CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); - if (!IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) + int device = config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK, + CONFIG_FASTBOOT_FLASH_BLOCK_DEVICE_ID, -1); + if (device == -1) { + device = config_opt_enabled(CONFIG_FASTBOOT_FLASH_MMC, + CONFIG_FASTBOOT_FLASH_MMC_DEV, -1); + } + const char *bcb_iface = config_opt_enabled(CONFIG_FASTBOOT_FLASH_BLOCK, + CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME, + "mmc"); + + if (device == -1) return -EINVAL; if (reason >= FASTBOOT_REBOOT_REASONS_COUNT) return -EINVAL; - ret = bcb_find_partition_and_load("mmc", mmc_dev, "misc"); + ret = bcb_find_partition_and_load(bcb_iface, device, "misc"); if (ret) goto out; @@ -226,8 +234,14 @@ void fastboot_set_progress_callback(void (*progress)(const char *msg)) */ void fastboot_init(void *buf_addr, u32 buf_size) { +#if IS_ENABLED(CONFIG_FASTBOOT_FLASH_BLOCK) + if (!strcmp(CONFIG_FASTBOOT_FLASH_BLOCK_INTERFACE_NAME, "mmc")) + printf("Warning: the fastboot block backend features are limited, consider using the MMC backend\n"); +#endif + fastboot_buf_addr = buf_addr ? buf_addr : (void *)CONFIG_FASTBOOT_BUF_ADDR; fastboot_buf_size = buf_size ? buf_size : CONFIG_FASTBOOT_BUF_SIZE; fastboot_set_progress_callback(NULL); + } diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c index 9c2ce65a4e5bce0da6b18aa1b2818f7db556c528..f083b21c797dc7e55315f2cba017a4372483fa92 100644 --- a/drivers/fastboot/fb_getvar.c +++ b/drivers/fastboot/fb_getvar.c @@ -7,6 +7,7 @@ #include <fastboot.h> #include <fastboot-internal.h> #include <fb_mmc.h> +#include <fb_block.h> #include <fb_nand.h> #include <fs.h> #include <part.h> @@ -114,7 +115,12 @@ static int getvar_get_part_info(const char *part_name, char *response, struct disk_partition disk_part; struct part_info *part_info; - if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) { + if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_BLOCK)) { + r = fastboot_block_get_part_info(part_name, &dev_desc, &disk_part, + response); + if (r >= 0 && size) + *size = disk_part.size * disk_part.blksz; + } else if (IS_ENABLED(CONFIG_FASTBOOT_FLASH_MMC)) { r = fastboot_mmc_get_part_info(part_name, &dev_desc, &disk_part, response); if (r >= 0 && size)