From 312a10f16bf3e8b68066fa359d4dd6a887b5fd55 Mon Sep 17 00:00:00 2001 From: Alex Kiernan Date: Tue, 29 May 2018 15:30:39 +0000 Subject: fastboot: Move fastboot to drivers/fastboot Separate CMD_FASTBOOT from FASTBOOT and move code and configuration to drivers/fastboot. Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT as anyone who wants FASTBOOT before this series wants USB_FUNCTION_FASTBOOT. Split USB_FUNCTION_FASTBOOT from FASTBOOT so they retain their existing behaviour. Signed-off-by: Alex Kiernan Reviewed-by: Simon Glass Acked-by: Joe Hershberger --- cmd/Kconfig | 14 +++++- cmd/fastboot/Kconfig | 134 --------------------------------------------------- 2 files changed, 12 insertions(+), 136 deletions(-) delete mode 100644 cmd/fastboot/Kconfig (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index d532c9fc41..9848c067da 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -137,8 +137,6 @@ config AUTOBOOT_STOP_STR_SHA256 endmenu -source "cmd/fastboot/Kconfig" - config BUILD_BIN2C bool @@ -650,6 +648,18 @@ config CMD_DM can be useful to see the state of driver model for debugging or interest. +config CMD_FASTBOOT + bool "fastboot - Android fastboot support" + depends on FASTBOOT + help + This enables the command "fastboot" which enables the Android + fastboot mode for the platform. Fastboot is a protocol for + downloading images, flashing and device control used on + Android devices. Fastboot requires support for acting as a USB + device. + + See doc/README.android-fastboot for more information. + config CMD_FDC bool "fdcboot - Boot from floppy device" help diff --git a/cmd/fastboot/Kconfig b/cmd/fastboot/Kconfig deleted file mode 100644 index 0d2c2f131e..0000000000 --- a/cmd/fastboot/Kconfig +++ /dev/null @@ -1,134 +0,0 @@ -comment "FASTBOOT" - -menuconfig FASTBOOT - bool "Fastboot support" - depends on USB_GADGET - default y if ARCH_SUNXI && USB_MUSB_GADGET - -if FASTBOOT - -config USB_FUNCTION_FASTBOOT - bool "Enable USB fastboot gadget" - default y - select USB_GADGET_DOWNLOAD - imply ANDROID_BOOT_IMAGE - imply CMD_FASTBOOT - help - This enables the USB part of the fastboot gadget. - -config CMD_FASTBOOT - bool "Enable FASTBOOT command" - help - This enables the command "fastboot" which enables the Android - fastboot mode for the platform's USB device. Fastboot is a USB - protocol for downloading images, flashing and device control - used on Android devices. - - See doc/README.android-fastboot for more information. - -if USB_FUNCTION_FASTBOOT - -config FASTBOOT_BUF_ADDR - hex "Define FASTBOOT buffer address" - default 0x82000000 if MX6SX || MX6SL || MX6UL || MX6SLL - default 0x81000000 if ARCH_OMAP2PLUS - default 0x42000000 if ARCH_SUNXI && !MACH_SUN9I - default 0x22000000 if ARCH_SUNXI && MACH_SUN9I - default 0x60800800 if ROCKCHIP_RK3036 || ROCKCHIP_RK3188 || \ - ROCKCHIP_RK322X - default 0x800800 if ROCKCHIP_RK3288 || ROCKCHIP_RK3329 || \ - ROCKCHIP_RK3399 - default 0x280000 if ROCKCHIP_RK3368 - default 0x100000 if ARCH_ZYNQMP - help - The fastboot protocol requires a large memory buffer for - downloads. Define this to the starting RAM address to use for - downloaded images. - -config FASTBOOT_BUF_SIZE - hex "Define FASTBOOT buffer size" - default 0x8000000 if ARCH_ROCKCHIP - default 0x6000000 if ARCH_ZYNQMP - default 0x2000000 if ARCH_SUNXI - default 0x7000000 - help - The fastboot protocol requires a large memory buffer for - downloads. This buffer should be as large as possible for a - platform. Define this to the size available RAM for fastboot. - -config FASTBOOT_USB_DEV - int "USB controller number" - default 0 - help - Some boards have USB OTG controller other than 0. Define this - option so it can be used in compiled environment (e.g. in - CONFIG_BOOTCOMMAND). - -config FASTBOOT_FLASH - bool "Enable FASTBOOT FLASH command" - default y if ARCH_SUNXI - help - The fastboot protocol includes a "flash" command for writing - the downloaded image to a non-volatile storage device. Define - this to enable the "fastboot flash" command. - -choice - prompt "Flash provider for FASTBOOT" - depends on FASTBOOT_FLASH - -config FASTBOOT_FLASH_MMC - bool "FASTBOOT on MMC" - depends on MMC - -config FASTBOOT_FLASH_NAND - bool "FASTBOOT on NAND" - depends on NAND - -endchoice - -config FASTBOOT_FLASH_MMC_DEV - int "Define FASTBOOT MMC FLASH default device" - depends on FASTBOOT_FLASH_MMC - default 0 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA = -1 - default 1 if ARCH_SUNXI && MMC_SUNXI_SLOT_EXTRA != -1 - help - The fastboot "flash" command requires additional information - regarding the non-volatile storage device. Define this to - the eMMC device that fastboot should use to store the image. - -config FASTBOOT_FLASH_NAND_DEV - int "Define FASTBOOT NAND FLASH default device" - depends on FASTBOOT_FLASH_NAND - depends on CMD_MTDPARTS - default 0 if ARCH_SUNXI && NAND_SUNXI - help - The fastboot "flash" command requires additional information - regarding the non-volatile storage device. Define this to - the NAND device that fastboot should use to store the image. - -config FASTBOOT_GPT_NAME - string "Target name for updating GPT" - depends on FASTBOOT_FLASH - default "gpt" - help - The fastboot "flash" command supports writing the downloaded - image to the Protective MBR and the Primary GUID Partition - Table. (Additionally, this downloaded image is post-processed - to generate and write the Backup GUID Partition Table.) - This occurs when the specified "partition name" on the - "fastboot flash" command line matches the value defined here. - The default target name for updating GPT is "gpt". - -config FASTBOOT_MBR_NAME - string "Target name for updating MBR" - depends on FASTBOOT_FLASH - default "mbr" - help - The fastboot "flash" command allows to write the downloaded image - to the Master Boot Record. This occurs when the "partition name" - specified on the "fastboot flash" command line matches the value - defined here. The default target name for updating MBR is "mbr". - -endif # USB_FUNCTION_FASTBOOT - -endif # FASTBOOT -- cgit v1.2.1 From c4ded03ef608be37db105200010d2f3f88195bd6 Mon Sep 17 00:00:00 2001 From: Alex Kiernan Date: Tue, 29 May 2018 15:30:40 +0000 Subject: fastboot: Refactor fastboot_okay/fail to take response Add the response string as a parameter to fastboot_okay/fail, instead of modifying a global, to match the contract expected by the AOSP U-Boot code. Signed-off-by: Alex Kiernan Reviewed-by: Joe Hershberger --- cmd/mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/mmc.c b/cmd/mmc.c index a3357eff8f..a5719b81eb 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -367,7 +367,7 @@ static int do_mmc_sparse_write(cmd_tbl_t *cmdtp, int flag, sparse.mssg = NULL; sprintf(dest, "0x" LBAF, sparse.start * sparse.blksz); - if (write_sparse_image(&sparse, dest, addr)) + if (write_sparse_image(&sparse, dest, addr, NULL)) return CMD_RET_FAILURE; else return CMD_RET_SUCCESS; -- cgit v1.2.1 From c232d14d11e29c88f2c6149d2c152f496caa5889 Mon Sep 17 00:00:00 2001 From: Alex Kiernan Date: Tue, 29 May 2018 15:30:52 +0000 Subject: mmc: Separate "mmc swrite" from fastboot Introduce CONFIG_IMAGE_SPARSE and CONFIG_CMD_MMC_SWRITE so the "mmc swrite" command is separated from the fastboot code. Move image-sparse from common to lib so it's clear it's library code. Rename CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE to CONFIG_IMAGE_SPARSE_FILLBUF_SIZE and migrate it to Kconfig. Signed-off-by: Alex Kiernan Acked-by: Jassi Brar Reviewed-by: Simon Glass --- cmd/Kconfig | 8 ++++++++ cmd/mmc.c | 12 ++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 9848c067da..30cf63f172 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -833,6 +833,14 @@ config CMD_MMC_RPMB Enable the commands for reading, writing and programming the key for the Replay Protection Memory Block partition in eMMC. +config CMD_MMC_SWRITE + bool "mmc swrite" + depends on CMD_MMC && MMC_WRITE + select IMAGE_SPARSE + help + Enable support for the "mmc swrite" command to write Android sparse + images to eMMC. + config CMD_NAND bool "nand" default y if NAND_SUNXI diff --git a/cmd/mmc.c b/cmd/mmc.c index a5719b81eb..c2ee2d9c0a 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -308,8 +308,7 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; } -#if CONFIG_IS_ENABLED(MMC_WRITE) -#if defined(CONFIG_FASTBOOT_FLASH) +#if CONFIG_IS_ENABLED(CMD_MMC_SWRITE) static lbaint_t mmc_sparse_write(struct sparse_storage *info, lbaint_t blk, lbaint_t blkcnt, const void *buffer) { @@ -374,6 +373,7 @@ static int do_mmc_sparse_write(cmd_tbl_t *cmdtp, int flag, } #endif +#if CONFIG_IS_ENABLED(MMC_WRITE) static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -868,10 +868,10 @@ static cmd_tbl_t cmd_mmc[] = { U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""), #if CONFIG_IS_ENABLED(MMC_WRITE) U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""), -#if defined(CONFIG_FASTBOOT_FLASH) - U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""), -#endif U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""), +#endif +#if CONFIG_IS_ENABLED(CMD_MMC_SWRITE) + U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""), #endif U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""), U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""), @@ -927,7 +927,7 @@ U_BOOT_CMD( "info - display info of the current MMC device\n" "mmc read addr blk# cnt\n" "mmc write addr blk# cnt\n" -#if defined(CONFIG_FASTBOOT_FLASH) +#if CONFIG_IS_ENABLED(CMD_MMC_SWRITE) "mmc swrite addr blk#\n" #endif "mmc erase blk# cnt\n" -- cgit v1.2.1 From f73a7df984a9820d9beb829b32ccb5c3d55dc152 Mon Sep 17 00:00:00 2001 From: Alex Kiernan Date: Tue, 29 May 2018 15:30:53 +0000 Subject: net: fastboot: Merge AOSP UDP fastboot Merge UDP fastboot support from AOSP: https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8 Signed-off-by: Alex Kiernan Signed-off-by: Alex Deymo Signed-off-by: Jocelyn Bohr Reviewed-by: Simon Glass --- cmd/Kconfig | 4 +-- cmd/fastboot.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 7 deletions(-) (limited to 'cmd') diff --git a/cmd/Kconfig b/cmd/Kconfig index 30cf63f172..17ca0bb267 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -655,8 +655,8 @@ config CMD_FASTBOOT This enables the command "fastboot" which enables the Android fastboot mode for the platform. Fastboot is a protocol for downloading images, flashing and device control used on - Android devices. Fastboot requires support for acting as a USB - device. + Android devices. Fastboot requires either the network stack + enabled or support for acting as a USB device. See doc/README.android-fastboot for more information. diff --git a/cmd/fastboot.c b/cmd/fastboot.c index a5ec5f46f6..557257aef8 100644 --- a/cmd/fastboot.c +++ b/cmd/fastboot.c @@ -10,10 +10,32 @@ #include #include #include +#include +#include #include -static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +static int do_fastboot_udp(int argc, char *const argv[], + uintptr_t buf_addr, size_t buf_size) { +#if CONFIG_IS_ENABLED(UDP_FUNCTION_FASTBOOT) + int err = net_loop(FASTBOOT); + + if (err < 0) { + printf("fastboot udp error: %d\n", err); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +#else + pr_err("Fastboot UDP not enabled\n"); + return CMD_RET_FAILURE; +#endif +} + +static int do_fastboot_usb(int argc, char *const argv[], + uintptr_t buf_addr, size_t buf_size) +{ +#if CONFIG_IS_ENABLED(USB_FUNCTION_FASTBOOT) int controller_index; char *usb_controller; int ret; @@ -58,11 +80,70 @@ exit: board_usb_cleanup(controller_index, USB_INIT_DEVICE); return ret; +#else + pr_err("Fastboot USB not enabled\n"); + return CMD_RET_FAILURE; +#endif +} + +static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + uintptr_t buf_addr = (uintptr_t)NULL; + size_t buf_size = 0; + + if (argc < 2) + return CMD_RET_USAGE; + + while (argc > 1 && **(argv + 1) == '-') { + char *arg = *++argv; + + --argc; + while (*++arg) { + switch (*arg) { + case 'l': + if (--argc <= 0) + return CMD_RET_USAGE; + buf_addr = simple_strtoul(*++argv, NULL, 16); + goto NXTARG; + + case 's': + if (--argc <= 0) + return CMD_RET_USAGE; + buf_size = simple_strtoul(*++argv, NULL, 16); + goto NXTARG; + + default: + return CMD_RET_USAGE; + } + } +NXTARG: + ; + } + + fastboot_init((void *)buf_addr, buf_size); + + if (!strcmp(argv[1], "udp")) + return do_fastboot_udp(argc, argv, buf_addr, buf_size); + + if (!strcmp(argv[1], "usb")) { + argv++; + argc--; + } + + return do_fastboot_usb(argc, argv, buf_addr, buf_size); } +#ifdef CONFIG_SYS_LONGHELP +static char fastboot_help_text[] = + "[-l addr] [-s size] usb | udp\n" + "\taddr - address of buffer used during data transfers (" + __stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n" + "\tsize - size of buffer used during data transfers (" + __stringify(CONFIG_FASTBOOT_BUF_SIZE) ")" + ; +#endif + U_BOOT_CMD( - fastboot, 2, 1, do_fastboot, - "use USB Fastboot protocol", - "\n" - " - run as a fastboot usb device" + fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot, + "run as a fastboot usb or udp device", fastboot_help_text ); -- cgit v1.2.1