Merge branch 'master' of git://git.denx.de/u-boot-usb
authorTom Rini <trini@konsulko.com>
Fri, 1 Jun 2018 13:52:15 +0000 (09:52 -0400)
committerTom Rini <trini@konsulko.com>
Fri, 1 Jun 2018 13:52:15 +0000 (09:52 -0400)
112 files changed:
arch/arm/Kconfig
arch/arm/mach-omap2/boot-common.c
arch/arm/mach-omap2/utils.c
arch/arm/mach-rockchip/rk3128-board.c
arch/arm/mach-rockchip/rk322x-board.c
board/amazon/kc1/kc1.c
board/lg/sniper/sniper.c
board/ti/am57xx/board.c
board/ti/common/Kconfig
board/ti/dra7xx/evm.c
cmd/Kconfig
cmd/fastboot.c
cmd/fastboot/Kconfig [deleted file]
cmd/mmc.c
common/Makefile
common/fb_mmc.c [deleted file]
common/fb_nand.c [deleted file]
common/image-sparse.c [deleted file]
configs/A13-OLinuXino_defconfig
configs/A20-OLinuXino-Lime2-eMMC_defconfig
configs/A20-OLinuXino-Lime2_defconfig
configs/A20-Olimex-SOM204-EVB-eMMC_defconfig
configs/A20-Olimex-SOM204-EVB_defconfig
configs/Bananapi_m2m_defconfig
configs/Cubietruck_defconfig
configs/Sinlinx_SinA33_defconfig
configs/am335x_boneblack_defconfig
configs/am335x_boneblack_vboot_defconfig
configs/am335x_evm_defconfig
configs/am335x_evm_nor_defconfig
configs/am335x_evm_norboot_defconfig
configs/am335x_evm_spiboot_defconfig
configs/am335x_evm_usbspl_defconfig
configs/am57xx_evm_defconfig
configs/am57xx_hs_evm_defconfig
configs/bcm23550_w1d_defconfig
configs/bcm28155_ap_defconfig
configs/birdland_bav335a_defconfig
configs/birdland_bav335b_defconfig
configs/cgtqmx6eval_defconfig
configs/chromebit_mickey_defconfig
configs/chromebook_jerry_defconfig
configs/chromebook_minnie_defconfig
configs/dra7xx_evm_defconfig
configs/dra7xx_hs_evm_defconfig
configs/evb-rk3036_defconfig
configs/evb-rk3128_defconfig
configs/evb-rk3229_defconfig
configs/evb-rk3288_defconfig
configs/evb-rk3328_defconfig
configs/fennec-rk3288_defconfig
configs/firefly-rk3288_defconfig
configs/imx6dl_mamoj_defconfig
configs/kc1_defconfig
configs/kylin-rk3036_defconfig
configs/miqi-rk3288_defconfig
configs/mx6qsabrelite_defconfig
configs/mx6sabresd_defconfig
configs/nitrogen6dl2g_defconfig
configs/nitrogen6dl_defconfig
configs/nitrogen6q2g_defconfig
configs/nitrogen6q_defconfig
configs/nitrogen6s1g_defconfig
configs/nitrogen6s_defconfig
configs/omap3_beagle_defconfig
configs/omap3_evm_defconfig
configs/omap3_logic_defconfig
configs/parrot_r16_defconfig
configs/phycore-rk3288_defconfig
configs/popmetal-rk3288_defconfig
configs/rock2_defconfig
configs/sniper_defconfig
configs/stih410-b2260_defconfig
configs/tbs_a711_defconfig
configs/tinker-rk3288_defconfig
configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig
configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig
configs/xilinx_zynqmp_zcu102_rev1_0_defconfig
configs/xilinx_zynqmp_zcu102_revA_defconfig
configs/xilinx_zynqmp_zcu102_revB_defconfig
configs/xilinx_zynqmp_zcu106_revA_defconfig
doc/README.android-fastboot
drivers/Kconfig
drivers/Makefile
drivers/fastboot/Kconfig [new file with mode: 0644]
drivers/fastboot/Makefile [new file with mode: 0644]
drivers/fastboot/fb_command.c [new file with mode: 0644]
drivers/fastboot/fb_common.c [new file with mode: 0644]
drivers/fastboot/fb_getvar.c [new file with mode: 0644]
drivers/fastboot/fb_mmc.c [new file with mode: 0644]
drivers/fastboot/fb_nand.c [new file with mode: 0644]
drivers/usb/gadget/f_fastboot.c
drivers/usb/gadget/f_thor.c
drivers/usb/host/xhci-rcar.c
drivers/usb/host/xhci-rockchip.c
drivers/usb/host/xhci.c
fs/fs.c
include/fastboot-internal.h [new file with mode: 0644]
include/fastboot.h
include/fb_mmc.h
include/fb_nand.h
include/fs.h
include/image-sparse.h
include/net.h
include/net/fastboot.h [new file with mode: 0644]
lib/Kconfig
lib/Makefile
lib/image-sparse.c [new file with mode: 0644]
net/Makefile
net/fastboot.c [new file with mode: 0644]
net/net.c
scripts/config_whitelist.txt

index 582e84cf4014555bd593459da994a17b65d7df7b..dde422bc5d53ce661747f86149fde1a33fe40bbd 100644 (file)
@@ -1258,9 +1258,7 @@ config ARCH_ROCKCHIP
        select DM_REGULATOR
        select ENABLE_ARM_SOC_BOOT0_HOOK
        select SPI
-       imply CMD_FASTBOOT
        imply DISTRO_DEFAULTS
-       imply FASTBOOT
        imply FAT_WRITE
        imply USB_FUNCTION_FASTBOOT
        imply SPL_SYSRESET
index 0e9fd03fefb05d645859d8822c6d245d6e809b9c..d4a1e2e42c4e299434ceb4a431dd0eb2ccf15d96 100644 (file)
@@ -236,13 +236,3 @@ void arch_preboot_os(void)
        ahci_reset((void __iomem *)DWC_AHSATA_BASE);
 }
 #endif
-
-#if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
-int fb_set_reboot_flag(void)
-{
-       printf("Setting reboot to fastboot flag ...\n");
-       env_set("dofastboot", "1");
-       env_save();
-       return 0;
-}
-#endif
index dc7b37f1643500d864e3defcfd59d3735fde0220..edf5edcb6808c86c35fb8a1fee183287c3fd0a89 100644 (file)
@@ -85,7 +85,7 @@ static void omap_set_fastboot_board_rev(void)
        env_set("fastboot.board_rev", board_rev);
 }
 
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_MMC
 static u32 omap_mmc_get_part_size(const char *part)
 {
        int res;
@@ -128,7 +128,7 @@ static void omap_set_fastboot_userdata_size(void)
 static inline void omap_set_fastboot_userdata_size(void)
 {
 }
-#endif /* CONFIG_FASTBOOT_FLASH_MMC_DEV */
+#endif /* CONFIG_FASTBOOT_FLASH_MMC */
 void omap_set_fastboot_vars(void)
 {
        omap_set_fastboot_cpu();
index 48cd8ba81e08d9a9002381c3333f650fd7dbf537..7fd667a0b8ec94a43df1f27b488c758892035e94 100644 (file)
@@ -111,8 +111,8 @@ int board_usb_cleanup(int index, enum usb_init_type init)
 }
 #endif
 
-#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
-int fb_set_reboot_flag(void)
+#if CONFIG_IS_ENABLED(FASTBOOT)
+int fastboot_set_reboot_flag(void)
 {
        struct rk3128_grf *grf;
 
index 99a60c4e2ee62178da8b9d6315b43c6ac83c5aeb..7366d45ab6c0ef7ffd4df31ccdddb5740a708add 100644 (file)
@@ -139,8 +139,8 @@ int board_usb_cleanup(int index, enum usb_init_type init)
 }
 #endif
 
-#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
-int fb_set_reboot_flag(void)
+#if CONFIG_IS_ENABLED(FASTBOOT)
+int fastboot_set_reboot_flag(void)
 {
        struct rk322x_grf *grf;
 
index d9ca18363cda8dd769e4bebbd290e40f012c106a..031fd110923c5e5c87602ada5ffef9282878223c 100644 (file)
@@ -161,7 +161,7 @@ void get_board_serial(struct tag_serialnr *serialnr)
        omap_die_id_get_board_serial(serialnr);
 }
 
-int fb_set_reboot_flag(void)
+int fastboot_set_reboot_flag(void)
 {
        return omap_reboot_mode_store("b");
 }
index 34a7a11f053dbde5d01ed78147c8562bc76a7aba..a7de4c21674c4eaa114aa5d096ac418df55d6879 100644 (file)
@@ -173,7 +173,7 @@ void reset_misc(void)
        omap_reboot_mode_store(reboot_mode);
 }
 
-int fb_set_reboot_flag(void)
+int fastboot_set_reboot_flag(void)
 {
        return omap_reboot_mode_store("b");
 }
index fd9d20779bef5c5ac11d5109138a56724f05f77f..177a3246c3dbc2d7b35b57415cddc42546b4e1c6 100644 (file)
@@ -1178,5 +1178,15 @@ void board_tee_image_process(ulong tee_image, size_t tee_size)
        secure_tee_install((u32)tee_image);
 }
 
+#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
+int fastboot_set_reboot_flag(void)
+{
+       printf("Setting reboot to fastboot flag ...\n");
+       env_set("dofastboot", "1");
+       env_save();
+       return 0;
+}
+#endif
+
 U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
 #endif
index c21eb8c2d2e39c9d17c8ec3616a1faa8c0fbf413..b1956b810035ab5e1ff64427942353453fcb0d05 100644 (file)
@@ -25,7 +25,6 @@ config TI_COMMON_CMD_OPTIONS
        imply CMD_EXT2
        imply CMD_EXT4
        imply CMD_EXT4_WRITE
-       imply CMD_FASTBOOT if FASTBOOT
        imply CMD_FAT
        imply FAT_WRITE if CMD_FAT
        imply CMD_FS_GENERIC
index 6918f4de01f31ac9b00e9d320d99bc8a3ff402e6..bbe54450aeec83d540fdba0660cd3e8e066a2f38 100644 (file)
@@ -1188,5 +1188,15 @@ void board_tee_image_process(ulong tee_image, size_t tee_size)
        secure_tee_install((u32)tee_image);
 }
 
+#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
+int fastboot_set_reboot_flag(void)
+{
+       printf("Setting reboot to fastboot flag ...\n");
+       env_set("dofastboot", "1");
+       env_save();
+       return 0;
+}
+#endif
+
 U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
 #endif
index 1a1ca60237dfe672f5a89ce00cf601a096a1a647..48a2a5720cf600853ef0e3c6ea0a2426167dc1d3 100644 (file)
@@ -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 either the network stack
+         enabled or 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
@@ -823,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
index a5ec5f46f63300052d4eb9f23f6092f09ebe0c1f..557257aef8437bcb79d60824a62574645740b931 100644 (file)
 #include <command.h>
 #include <console.h>
 #include <g_dnl.h>
+#include <fastboot.h>
+#include <net.h>
 #include <usb.h>
 
-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 <controller> | 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",
-       "<USB_controller>\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
 );
diff --git a/cmd/fastboot/Kconfig b/cmd/fastboot/Kconfig
deleted file mode 100644 (file)
index 0d2c2f1..0000000
+++ /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
index a3357eff8faa632ed817df9313e68b8696111a61..c2ee2d9c0af1d9e77d4339621a2173411e92d07a 100644 (file)
--- 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)
 {
@@ -367,13 +366,14 @@ 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;
 }
 #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"
index d0681c7dd96ac87f0636d6d18501a03164fee9bb..b3da72ebb2c94ee3ca23a104cb8d79a1be51f5eb 100644 (file)
@@ -29,7 +29,6 @@ obj-$(CONFIG_CMD_BOOTI) += bootm.o bootm_os.o
 
 obj-$(CONFIG_CMD_BEDBUG) += bedbug.o
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdt_support.o
-
 obj-$(CONFIG_MII) += miiphyutil.o
 obj-$(CONFIG_CMD_MII) += miiphyutil.o
 obj-$(CONFIG_PHYLIB) += miiphyutil.o
@@ -109,19 +108,6 @@ obj-$(CONFIG_IO_TRACE) += iotrace.o
 obj-y += memsize.o
 obj-y += stdio.o
 
-ifndef CONFIG_SPL_BUILD
-# This option is not just y/n - it can have a numeric value
-ifdef CONFIG_FASTBOOT_FLASH
-obj-y += image-sparse.o
-ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-obj-y += fb_mmc.o
-endif
-ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
-obj-y += fb_nand.o
-endif
-endif
-endif
-
 ifdef CONFIG_CMD_EEPROM_LAYOUT
 obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o
 endif
diff --git a/common/fb_mmc.c b/common/fb_mmc.c
deleted file mode 100644 (file)
index 46f0073..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright 2014 Broadcom Corporation.
- */
-
-#include <config.h>
-#include <common.h>
-#include <blk.h>
-#include <fastboot.h>
-#include <fb_mmc.h>
-#include <image-sparse.h>
-#include <part.h>
-#include <mmc.h>
-#include <div64.h>
-#include <linux/compat.h>
-#include <android_image.h>
-
-/*
- * FIXME: Ensure we always set these names via Kconfig once xxx_PARTITION is
- * migrated
- */
-#ifndef CONFIG_FASTBOOT_GPT_NAME
-#define CONFIG_FASTBOOT_GPT_NAME "gpt"
-#endif
-
-
-#ifndef CONFIG_FASTBOOT_MBR_NAME
-#define CONFIG_FASTBOOT_MBR_NAME "mbr"
-#endif
-
-#define BOOT_PARTITION_NAME "boot"
-
-struct fb_mmc_sparse {
-       struct blk_desc *dev_desc;
-};
-
-static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
-               const char *name, disk_partition_t *info)
-{
-       int ret;
-
-       ret = part_get_info_by_name(dev_desc, name, info);
-       if (ret < 0) {
-               /* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */
-               char env_alias_name[25 + 32 + 1];
-               char *aliased_part_name;
-
-               /* check for alias */
-               strcpy(env_alias_name, "fastboot_partition_alias_");
-               strncat(env_alias_name, name, 32);
-               aliased_part_name = env_get(env_alias_name);
-               if (aliased_part_name != NULL)
-                       ret = part_get_info_by_name(dev_desc,
-                                       aliased_part_name, info);
-       }
-       return ret;
-}
-
-static lbaint_t fb_mmc_sparse_write(struct sparse_storage *info,
-               lbaint_t blk, lbaint_t blkcnt, const void *buffer)
-{
-       struct fb_mmc_sparse *sparse = info->priv;
-       struct blk_desc *dev_desc = sparse->dev_desc;
-
-       return blk_dwrite(dev_desc, blk, blkcnt, buffer);
-}
-
-static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
-               lbaint_t blk, lbaint_t blkcnt)
-{
-       return blkcnt;
-}
-
-static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
-               const char *part_name, void *buffer,
-               unsigned int download_bytes)
-{
-       lbaint_t blkcnt;
-       lbaint_t blks;
-
-       /* determine number of blocks to write */
-       blkcnt = ((download_bytes + (info->blksz - 1)) & ~(info->blksz - 1));
-       blkcnt = lldiv(blkcnt, info->blksz);
-
-       if (blkcnt > info->size) {
-               pr_err("too large for partition: '%s'\n", part_name);
-               fastboot_fail("too large for partition");
-               return;
-       }
-
-       puts("Flashing Raw Image\n");
-
-       blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
-       if (blks != blkcnt) {
-               pr_err("failed writing to device %d\n", dev_desc->devnum);
-               fastboot_fail("failed writing to device");
-               return;
-       }
-
-       printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
-              part_name);
-       fastboot_okay("");
-}
-
-#ifdef CONFIG_ANDROID_BOOT_IMAGE
-/**
- * Read Android boot image header from boot partition.
- *
- * @param[in] dev_desc MMC device descriptor
- * @param[in] info Boot partition info
- * @param[out] hdr Where to store read boot image header
- *
- * @return Boot image header sectors count or 0 on error
- */
-static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
-                                      disk_partition_t *info,
-                                      struct andr_img_hdr *hdr)
-{
-       ulong sector_size;              /* boot partition sector size */
-       lbaint_t hdr_sectors;           /* boot image header sectors count */
-       int res;
-
-       /* Calculate boot image sectors count */
-       sector_size = info->blksz;
-       hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
-       if (hdr_sectors == 0) {
-               pr_err("invalid number of boot sectors: 0");
-               fastboot_fail("invalid number of boot sectors: 0");
-               return 0;
-       }
-
-       /* Read the boot image header */
-       res = blk_dread(dev_desc, info->start, hdr_sectors, (void *)hdr);
-       if (res != hdr_sectors) {
-               pr_err("cannot read header from boot partition");
-               fastboot_fail("cannot read header from boot partition");
-               return 0;
-       }
-
-       /* Check boot header magic string */
-       res = android_image_check_header(hdr);
-       if (res != 0) {
-               pr_err("bad boot image magic");
-               fastboot_fail("boot partition not initialized");
-               return 0;
-       }
-
-       return hdr_sectors;
-}
-
-/**
- * Write downloaded zImage to boot partition and repack it properly.
- *
- * @param dev_desc MMC device descriptor
- * @param download_buffer Address to fastboot buffer with zImage in it
- * @param download_bytes Size of fastboot buffer, in bytes
- *
- * @return 0 on success or -1 on error
- */
-static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
-                               void *download_buffer,
-                               unsigned int download_bytes)
-{
-       uintptr_t hdr_addr;                     /* boot image header address */
-       struct andr_img_hdr *hdr;               /* boot image header */
-       lbaint_t hdr_sectors;                   /* boot image header sectors */
-       u8 *ramdisk_buffer;
-       u32 ramdisk_sector_start;
-       u32 ramdisk_sectors;
-       u32 kernel_sector_start;
-       u32 kernel_sectors;
-       u32 sectors_per_page;
-       disk_partition_t info;
-       int res;
-
-       puts("Flashing zImage\n");
-
-       /* Get boot partition info */
-       res = part_get_info_by_name(dev_desc, BOOT_PARTITION_NAME, &info);
-       if (res < 0) {
-               pr_err("cannot find boot partition");
-               fastboot_fail("cannot find boot partition");
-               return -1;
-       }
-
-       /* Put boot image header in fastboot buffer after downloaded zImage */
-       hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
-       hdr = (struct andr_img_hdr *)hdr_addr;
-
-       /* Read boot image header */
-       hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr);
-       if (hdr_sectors == 0) {
-               pr_err("unable to read boot image header");
-               fastboot_fail("unable to read boot image header");
-               return -1;
-       }
-
-       /* Check if boot image has second stage in it (we don't support it) */
-       if (hdr->second_size > 0) {
-               pr_err("moving second stage is not supported yet");
-               fastboot_fail("moving second stage is not supported yet");
-               return -1;
-       }
-
-       /* Extract ramdisk location */
-       sectors_per_page = hdr->page_size / info.blksz;
-       ramdisk_sector_start = info.start + sectors_per_page;
-       ramdisk_sector_start += DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) *
-                                            sectors_per_page;
-       ramdisk_sectors = DIV_ROUND_UP(hdr->ramdisk_size, hdr->page_size) *
-                                      sectors_per_page;
-
-       /* Read ramdisk and put it in fastboot buffer after boot image header */
-       ramdisk_buffer = (u8 *)hdr + (hdr_sectors * info.blksz);
-       res = blk_dread(dev_desc, ramdisk_sector_start, ramdisk_sectors,
-                       ramdisk_buffer);
-       if (res != ramdisk_sectors) {
-               pr_err("cannot read ramdisk from boot partition");
-               fastboot_fail("cannot read ramdisk from boot partition");
-               return -1;
-       }
-
-       /* Write new kernel size to boot image header */
-       hdr->kernel_size = download_bytes;
-       res = blk_dwrite(dev_desc, info.start, hdr_sectors, (void *)hdr);
-       if (res == 0) {
-               pr_err("cannot writeback boot image header");
-               fastboot_fail("cannot write back boot image header");
-               return -1;
-       }
-
-       /* Write the new downloaded kernel */
-       kernel_sector_start = info.start + sectors_per_page;
-       kernel_sectors = DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) *
-                                     sectors_per_page;
-       res = blk_dwrite(dev_desc, kernel_sector_start, kernel_sectors,
-                        download_buffer);
-       if (res == 0) {
-               pr_err("cannot write new kernel");
-               fastboot_fail("cannot write new kernel");
-               return -1;
-       }
-
-       /* Write the saved ramdisk back */
-       ramdisk_sector_start = info.start + sectors_per_page;
-       ramdisk_sector_start += DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) *
-                                            sectors_per_page;
-       res = blk_dwrite(dev_desc, ramdisk_sector_start, ramdisk_sectors,
-                        ramdisk_buffer);
-       if (res == 0) {
-               pr_err("cannot write back original ramdisk");
-               fastboot_fail("cannot write back original ramdisk");
-               return -1;
-       }
-
-       puts("........ zImage was updated in boot partition\n");
-       fastboot_okay("");
-       return 0;
-}
-#endif
-
-void fb_mmc_flash_write(const char *cmd, void *download_buffer,
-                       unsigned int download_bytes)
-{
-       struct blk_desc *dev_desc;
-       disk_partition_t info;
-
-       dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
-       if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
-               pr_err("invalid mmc device\n");
-               fastboot_fail("invalid mmc device");
-               return;
-       }
-
-#if CONFIG_IS_ENABLED(EFI_PARTITION)
-       if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
-               printf("%s: updating MBR, Primary and Backup GPT(s)\n",
-                      __func__);
-               if (is_valid_gpt_buf(dev_desc, download_buffer)) {
-                       printf("%s: invalid GPT - refusing to write to flash\n",
-                              __func__);
-                       fastboot_fail("invalid GPT partition");
-                       return;
-               }
-               if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
-                       printf("%s: writing GPT partitions failed\n", __func__);
-                       fastboot_fail("writing GPT partitions failed");
-                       return;
-               }
-               printf("........ success\n");
-               fastboot_okay("");
-               return;
-       }
-#endif
-
-#if CONFIG_IS_ENABLED(DOS_PARTITION)
-       if (strcmp(cmd, CONFIG_FASTBOOT_MBR_NAME) == 0) {
-               printf("%s: updating MBR\n", __func__);
-               if (is_valid_dos_buf(download_buffer)) {
-                       printf("%s: invalid MBR - refusing to write to flash\n",
-                              __func__);
-                       fastboot_fail("invalid MBR partition");
-                       return;
-               }
-               if (write_mbr_partition(dev_desc, download_buffer)) {
-                       printf("%s: writing MBR partition failed\n", __func__);
-                       fastboot_fail("writing MBR partition failed");
-                       return;
-               }
-               printf("........ success\n");
-               fastboot_okay("");
-               return;
-       }
-#endif
-
-#ifdef CONFIG_ANDROID_BOOT_IMAGE
-       if (strncasecmp(cmd, "zimage", 6) == 0) {
-               fb_mmc_update_zimage(dev_desc, download_buffer, download_bytes);
-               return;
-       }
-#endif
-
-       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");
-               return;
-       }
-
-       if (is_sparse_image(download_buffer)) {
-               struct fb_mmc_sparse sparse_priv;
-               struct sparse_storage sparse;
-               int err;
-
-               sparse_priv.dev_desc = dev_desc;
-
-               sparse.blksz = info.blksz;
-               sparse.start = info.start;
-               sparse.size = info.size;
-               sparse.write = fb_mmc_sparse_write;
-               sparse.reserve = fb_mmc_sparse_reserve;
-               sparse.mssg = fastboot_fail;
-
-               printf("Flashing sparse image at offset " LBAFU "\n",
-                      sparse.start);
-
-               sparse.priv = &sparse_priv;
-               err = write_sparse_image(&sparse, cmd, download_buffer);
-               if (!err)
-                       fastboot_okay("");
-       } else {
-               write_raw_image(dev_desc, &info, cmd, download_buffer,
-                               download_bytes);
-       }
-}
-
-void fb_mmc_erase(const char *cmd)
-{
-       int ret;
-       struct blk_desc *dev_desc;
-       disk_partition_t info;
-       lbaint_t blks, blks_start, blks_size, grp_size;
-       struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
-
-       if (mmc == NULL) {
-               pr_err("invalid mmc device");
-               fastboot_fail("invalid mmc device");
-               return;
-       }
-
-       dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
-       if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
-               pr_err("invalid mmc device");
-               fastboot_fail("invalid mmc device");
-               return;
-       }
-
-       ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
-       if (ret < 0) {
-               pr_err("cannot find partition: '%s'", cmd);
-               fastboot_fail("cannot find partition");
-               return;
-       }
-
-       /* Align blocks to erase group size to avoid erasing other partitions */
-       grp_size = mmc->erase_grp_size;
-       blks_start = (info.start + grp_size - 1) & ~(grp_size - 1);
-       if (info.size >= grp_size)
-               blks_size = (info.size - (blks_start - info.start)) &
-                               (~(grp_size - 1));
-       else
-               blks_size = 0;
-
-       printf("Erasing blocks " LBAFU " to " LBAFU " due to alignment\n",
-              blks_start, blks_start + blks_size);
-
-       blks = blk_derase(dev_desc, blks_start, blks_size);
-       if (blks != blks_size) {
-               pr_err("failed erasing from device %d", dev_desc->devnum);
-               fastboot_fail("failed erasing from device");
-               return;
-       }
-
-       printf("........ erased " LBAFU " bytes from '%s'\n",
-              blks_size * info.blksz, cmd);
-       fastboot_okay("");
-}
diff --git a/common/fb_nand.c b/common/fb_nand.c
deleted file mode 100644 (file)
index c07655e..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright 2014 Broadcom Corporation.
- * Copyright 2015 Free Electrons.
- */
-
-#include <config.h>
-#include <common.h>
-
-#include <fastboot.h>
-#include <image-sparse.h>
-
-#include <linux/mtd/mtd.h>
-#include <jffs2/jffs2.h>
-#include <nand.h>
-
-struct fb_nand_sparse {
-       struct mtd_info         *mtd;
-       struct part_info        *part;
-};
-
-__weak int board_fastboot_erase_partition_setup(char *name)
-{
-       return 0;
-}
-
-__weak int board_fastboot_write_partition_setup(char *name)
-{
-       return 0;
-}
-
-static int fb_nand_lookup(const char *partname,
-                         struct mtd_info **mtd,
-                         struct part_info **part)
-{
-       struct mtd_device *dev;
-       int ret;
-       u8 pnum;
-
-       ret = mtdparts_init();
-       if (ret) {
-               pr_err("Cannot initialize MTD partitions\n");
-               fastboot_fail("cannot init mtdparts");
-               return ret;
-       }
-
-       ret = find_dev_and_part(partname, &dev, &pnum, part);
-       if (ret) {
-               pr_err("cannot find partition: '%s'", partname);
-               fastboot_fail("cannot find partition");
-               return ret;
-       }
-
-       if (dev->id->type != MTD_DEV_TYPE_NAND) {
-               pr_err("partition '%s' is not stored on a NAND device",
-                     partname);
-               fastboot_fail("not a NAND device");
-               return -EINVAL;
-       }
-
-       *mtd = get_nand_dev_by_index(dev->id->num);
-
-       return 0;
-}
-
-static int _fb_nand_erase(struct mtd_info *mtd, struct part_info *part)
-{
-       nand_erase_options_t opts;
-       int ret;
-
-       memset(&opts, 0, sizeof(opts));
-       opts.offset = part->offset;
-       opts.length = part->size;
-       opts.quiet = 1;
-
-       printf("Erasing blocks 0x%llx to 0x%llx\n",
-              part->offset, part->offset + part->size);
-
-       ret = nand_erase_opts(mtd, &opts);
-       if (ret)
-               return ret;
-
-       printf("........ erased 0x%llx bytes from '%s'\n",
-              part->size, part->name);
-
-       return 0;
-}
-
-static int _fb_nand_write(struct mtd_info *mtd, struct part_info *part,
-                         void *buffer, unsigned int offset,
-                         unsigned int length, size_t *written)
-{
-       int flags = WITH_WR_VERIFY;
-
-#ifdef CONFIG_FASTBOOT_FLASH_NAND_TRIMFFS
-       flags |= WITH_DROP_FFS;
-#endif
-
-       return nand_write_skip_bad(mtd, offset, &length, written,
-                                  part->size - (offset - part->offset),
-                                  buffer, flags);
-}
-
-static lbaint_t fb_nand_sparse_write(struct sparse_storage *info,
-               lbaint_t blk, lbaint_t blkcnt, const void *buffer)
-{
-       struct fb_nand_sparse *sparse = info->priv;
-       size_t written;
-       int ret;
-
-       ret = _fb_nand_write(sparse->mtd, sparse->part, (void *)buffer,
-                            blk * info->blksz,
-                            blkcnt * info->blksz, &written);
-       if (ret < 0) {
-               printf("Failed to write sparse chunk\n");
-               return ret;
-       }
-
-/* TODO - verify that the value "written" includes the "bad-blocks" ... */
-
-       /*
-        * the return value must be 'blkcnt' ("good-blocks") plus the
-        * number of "bad-blocks" encountered within this space...
-        */
-       return written / info->blksz;
-}
-
-static lbaint_t fb_nand_sparse_reserve(struct sparse_storage *info,
-               lbaint_t blk, lbaint_t blkcnt)
-{
-       int bad_blocks = 0;
-
-/*
- * TODO - implement a function to determine the total number
- * of blocks which must be used in order to reserve the specified
- * number ("blkcnt") of "good-blocks", starting at "blk"...
- * ( possibly something like the "check_skip_len()" function )
- */
-
-       /*
-        * the return value must be 'blkcnt' ("good-blocks") plus the
-        * number of "bad-blocks" encountered within this space...
-        */
-       return blkcnt + bad_blocks;
-}
-
-void fb_nand_flash_write(const char *cmd, void *download_buffer,
-                        unsigned int download_bytes)
-{
-       struct part_info *part;
-       struct mtd_info *mtd = NULL;
-       int ret;
-
-       ret = fb_nand_lookup(cmd, &mtd, &part);
-       if (ret) {
-               pr_err("invalid NAND device");
-               fastboot_fail("invalid NAND device");
-               return;
-       }
-
-       ret = board_fastboot_write_partition_setup(part->name);
-       if (ret)
-               return;
-
-       if (is_sparse_image(download_buffer)) {
-               struct fb_nand_sparse sparse_priv;
-               struct sparse_storage sparse;
-
-               sparse_priv.mtd = mtd;
-               sparse_priv.part = part;
-
-               sparse.blksz = mtd->writesize;
-               sparse.start = part->offset / sparse.blksz;
-               sparse.size = part->size / sparse.blksz;
-               sparse.write = fb_nand_sparse_write;
-               sparse.reserve = fb_nand_sparse_reserve;
-               sparse.mssg = fastboot_fail;
-
-               printf("Flashing sparse image at offset " LBAFU "\n",
-                      sparse.start);
-
-               sparse.priv = &sparse_priv;
-               ret = write_sparse_image(&sparse, cmd, download_buffer);
-               if (!ret)
-                       fastboot_okay("");
-       } else {
-               printf("Flashing raw image at offset 0x%llx\n",
-                      part->offset);
-
-               ret = _fb_nand_write(mtd, part, download_buffer, part->offset,
-                                    download_bytes, NULL);
-
-               printf("........ wrote %u bytes to '%s'\n",
-                      download_bytes, part->name);
-       }
-
-       if (ret) {
-               fastboot_fail("error writing the image");
-               return;
-       }
-
-       fastboot_okay("");
-}
-
-void fb_nand_erase(const char *cmd)
-{
-       struct part_info *part;
-       struct mtd_info *mtd = NULL;
-       int ret;
-
-       ret = fb_nand_lookup(cmd, &mtd, &part);
-       if (ret) {
-               pr_err("invalid NAND device");
-               fastboot_fail("invalid NAND device");
-               return;
-       }
-
-       ret = board_fastboot_erase_partition_setup(part->name);
-       if (ret)
-               return;
-
-       ret = _fb_nand_erase(mtd, part);
-       if (ret) {
-               pr_err("failed erasing from device %s", mtd->name);
-               fastboot_fail("failed erasing from device");
-               return;
-       }
-
-       fastboot_okay("");
-}
diff --git a/common/image-sparse.c b/common/image-sparse.c
deleted file mode 100644 (file)
index 9223b9a..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright (c) 2009, Google Inc.
- * All rights reserved.
- *
- * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
- * Portions Copyright 2014 Broadcom Corporation.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in the
- *       documentation and/or other materials provided with the distribution.
- *     * Neither the name of The Linux Foundation nor
- *       the names of its contributors may be used to endorse or promote
- *       products derived from this software without specific prior written
- *       permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * NOTE:
- *   Although it is very similar, this license text is not identical
- *   to the "BSD-3-Clause", therefore, DO NOT MODIFY THIS LICENSE TEXT!
- */
-
-#include <config.h>
-#include <common.h>
-#include <image-sparse.h>
-#include <div64.h>
-#include <malloc.h>
-#include <part.h>
-#include <sparse_format.h>
-
-#include <linux/math64.h>
-
-#ifndef CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE
-#define CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE (1024 * 512)
-#endif
-
-static void default_log(const char *ignored) {}
-
-int write_sparse_image(struct sparse_storage *info,
-                      const char *part_name, void *data)
-{
-       lbaint_t blk;
-       lbaint_t blkcnt;
-       lbaint_t blks;
-       uint32_t bytes_written = 0;
-       unsigned int chunk;
-       unsigned int offset;
-       unsigned int chunk_data_sz;
-       uint32_t *fill_buf = NULL;
-       uint32_t fill_val;
-       sparse_header_t *sparse_header;
-       chunk_header_t *chunk_header;
-       uint32_t total_blocks = 0;
-       int fill_buf_num_blks;
-       int i;
-       int j;
-
-       fill_buf_num_blks = CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE / info->blksz;
-
-       /* Read and skip over sparse image header */
-       sparse_header = (sparse_header_t *)data;
-
-       data += sparse_header->file_hdr_sz;
-       if (sparse_header->file_hdr_sz > sizeof(sparse_header_t)) {
-               /*
-                * Skip the remaining bytes in a header that is longer than
-                * we expected.
-                */
-               data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t));
-       }
-
-       if (!info->mssg)
-               info->mssg = default_log;
-
-       debug("=== Sparse Image Header ===\n");
-       debug("magic: 0x%x\n", sparse_header->magic);
-       debug("major_version: 0x%x\n", sparse_header->major_version);
-       debug("minor_version: 0x%x\n", sparse_header->minor_version);
-       debug("file_hdr_sz: %d\n", sparse_header->file_hdr_sz);
-       debug("chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz);
-       debug("blk_sz: %d\n", sparse_header->blk_sz);
-       debug("total_blks: %d\n", sparse_header->total_blks);
-       debug("total_chunks: %d\n", sparse_header->total_chunks);
-
-       /*
-        * Verify that the sparse block size is a multiple of our
-        * storage backend block size
-        */
-       div_u64_rem(sparse_header->blk_sz, info->blksz, &offset);
-       if (offset) {
-               printf("%s: Sparse image block size issue [%u]\n",
-                      __func__, sparse_header->blk_sz);
-               info->mssg("sparse image block size issue");
-               return -1;
-       }
-
-       puts("Flashing Sparse Image\n");
-
-       /* Start processing chunks */
-       blk = info->start;
-       for (chunk = 0; chunk < sparse_header->total_chunks; chunk++) {
-               /* Read and skip over chunk header */
-               chunk_header = (chunk_header_t *)data;
-               data += sizeof(chunk_header_t);
-
-               if (chunk_header->chunk_type != CHUNK_TYPE_RAW) {
-                       debug("=== Chunk Header ===\n");
-                       debug("chunk_type: 0x%x\n", chunk_header->chunk_type);
-                       debug("chunk_data_sz: 0x%x\n", chunk_header->chunk_sz);
-                       debug("total_size: 0x%x\n", chunk_header->total_sz);
-               }
-
-               if (sparse_header->chunk_hdr_sz > sizeof(chunk_header_t)) {
-                       /*
-                        * Skip the remaining bytes in a header that is longer
-                        * than we expected.
-                        */
-                       data += (sparse_header->chunk_hdr_sz -
-                                sizeof(chunk_header_t));
-               }
-
-               chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz;
-               blkcnt = chunk_data_sz / info->blksz;
-               switch (chunk_header->chunk_type) {
-               case CHUNK_TYPE_RAW:
-                       if (chunk_header->total_sz !=
-                           (sparse_header->chunk_hdr_sz + chunk_data_sz)) {
-                               info->mssg("Bogus chunk size for chunk type Raw");
-                               return -1;
-                       }
-
-                       if (blk + blkcnt > info->start + info->size) {
-                               printf(
-                                   "%s: Request would exceed partition size!\n",
-                                   __func__);
-                               info->mssg("Request would exceed partition size!");
-                               return -1;
-                       }
-
-                       blks = info->write(info, blk, blkcnt, data);
-                       /* blks might be > blkcnt (eg. NAND bad-blocks) */
-                       if (blks < blkcnt) {
-                               printf("%s: %s" LBAFU " [" LBAFU "]\n",
-                                      __func__, "Write failed, block #",
-                                      blk, blks);
-                               info->mssg("flash write failure");
-                               return -1;
-                       }
-                       blk += blks;
-                       bytes_written += blkcnt * info->blksz;
-                       total_blocks += chunk_header->chunk_sz;
-                       data += chunk_data_sz;
-                       break;
-
-               case CHUNK_TYPE_FILL:
-                       if (chunk_header->total_sz !=
-                           (sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
-                               info->mssg("Bogus chunk size for chunk type FILL");
-                               return -1;
-                       }
-
-                       fill_buf = (uint32_t *)
-                                  memalign(ARCH_DMA_MINALIGN,
-                                           ROUNDUP(
-                                               info->blksz * fill_buf_num_blks,
-                                               ARCH_DMA_MINALIGN));
-                       if (!fill_buf) {
-                               info->mssg("Malloc failed for: CHUNK_TYPE_FILL");
-                               return -1;
-                       }
-
-                       fill_val = *(uint32_t *)data;
-                       data = (char *)data + sizeof(uint32_t);
-
-                       for (i = 0;
-                            i < (info->blksz * fill_buf_num_blks /
-                                 sizeof(fill_val));
-                            i++)
-                               fill_buf[i] = fill_val;
-
-                       if (blk + blkcnt > info->start + info->size) {
-                               printf(
-                                   "%s: Request would exceed partition size!\n",
-                                   __func__);
-                               info->mssg("Request would exceed partition size!");
-                               return -1;
-                       }
-
-                       for (i = 0; i < blkcnt;) {
-                               j = blkcnt - i;
-                               if (j > fill_buf_num_blks)
-                                       j = fill_buf_num_blks;
-                               blks = info->write(info, blk, j, fill_buf);
-                               /* blks might be > j (eg. NAND bad-blocks) */
-                               if (blks < j) {
-                                       printf("%s: %s " LBAFU " [%d]\n",
-                                              __func__,
-                                              "Write failed, block #",
-                                              blk, j);
-                                       info->mssg("flash write failure");
-                                       free(fill_buf);
-                                       return -1;
-                               }
-                               blk += blks;
-                               i += j;
-                       }
-                       bytes_written += blkcnt * info->blksz;
-                       total_blocks += chunk_data_sz / sparse_header->blk_sz;
-                       free(fill_buf);
-                       break;
-
-               case CHUNK_TYPE_DONT_CARE:
-                       blk += info->reserve(info, blk, blkcnt);
-                       total_blocks += chunk_header->chunk_sz;
-                       break;
-
-               case CHUNK_TYPE_CRC32:
-                       if (chunk_header->total_sz !=
-                           sparse_header->chunk_hdr_sz) {
-                               info->mssg("Bogus chunk size for chunk type Dont Care");
-                               return -1;
-                       }
-                       total_blocks += chunk_header->chunk_sz;
-                       data += chunk_data_sz;
-                       break;
-
-               default:
-                       printf("%s: Unknown chunk type: %x\n", __func__,
-                              chunk_header->chunk_type);
-                       info->mssg("Unknown chunk type");
-                       return -1;
-               }
-       }
-
-       debug("Wrote %d blocks, expected to write %d blocks\n",
-             total_blocks, sparse_header->total_blks);
-       printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
-
-       if (total_blocks != sparse_header->total_blks) {
-               info->mssg("sparse image write failure");
-               return -1;
-       }
-
-       return 0;
-}
index 8e160d7cc4a8feb46b994f0908b357d43cdbaf4b..b8ec1e54dbcb4b83858632ced0872f8d30a8c314 100644 (file)
@@ -22,6 +22,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_DFU_RAM=y
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_AXP_ALDO3_VOLT=3300
 CONFIG_CONS_INDEX=2
 CONFIG_USB_EHCI_HCD=y
index 9d043e856a424403b57721cbd042bfa611f92e65..5657fc2594c2db153026824317f270893ad2bc3f 100644 (file)
@@ -20,6 +20,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_SCSI_AHCI=y
 CONFIG_DFU_RAM=y
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_RGMII=y
 CONFIG_SUN7I_GMAC=y
index f2997c6fe54ca0567716b8a8f278de3a7fb917b2..134d1d3fef69add316087f88976d5a0b00e04209 100644 (file)
@@ -19,6 +19,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_SCSI_AHCI=y
 CONFIG_DFU_RAM=y
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_RGMII=y
 CONFIG_SUN7I_GMAC=y
index 847945b6490801d09c38c808a265240188747939..3bb8c4c7e66702ef75d18e23564db3ad4e90c725 100644 (file)
@@ -18,6 +18,7 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_SCSI_AHCI=y
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_PHY_ADDR=3
 CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
index e56f2c71109b4da390cbed4ad6f002e1d592e303..cfb7ffa556f2c4c4bd07572e43c75a5d8ce35e1e 100644 (file)
@@ -17,6 +17,7 @@ CONFIG_SPL_I2C_SUPPORT=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_SCSI_AHCI=y
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_PHY_ADDR=3
 CONFIG_PHY_MICREL=y
 CONFIG_PHY_MICREL_KSZ90X1=y
index 2032a4aef8d9034a4cb53cc3d94fb98daeb7ec2a..2316437c9441c0b03662b67343cbdd4edf96f4c8 100644 (file)
@@ -13,6 +13,7 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-r16-bananapi-m2m"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_MUSB_GADGET=y
 CONFIG_USB_FUNCTION_MASS_STORAGE=y
index f0bb4c9d5ce7155b73721c625fb91dfab5b14c06..601eb3ca0c0c4fb474b55afff6ae1d93d3de4bd3 100644 (file)
@@ -21,6 +21,7 @@ CONFIG_CMD_USB_MASS_STORAGE=y
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_SCSI_AHCI=y
 CONFIG_DFU_RAM=y
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_RGMII=y
 CONFIG_SUN7I_GMAC=y
index 9e6267200b75ae36f74f830cca5b5e519ed533c8..394534b8b55ecd6e7365414c4f1461af84ab93e4 100644 (file)
@@ -18,6 +18,7 @@ CONFIG_CMD_DFU=y
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
 CONFIG_DFU_RAM=y
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_MUSB_GADGET=y
 CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y
index 5c01b20dff188ebd6249547ec804b100c7126801..31d2fe9cbfd19bece231a45262b2dc1a71483589 100644 (file)
@@ -16,9 +16,6 @@ CONFIG_AUTOBOOT_KEYED=y
 CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n"
 CONFIG_AUTOBOOT_DELAY_STR="d"
 CONFIG_AUTOBOOT_STOP_STR=" "
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=1
 CONFIG_CMD_SPL=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
@@ -28,6 +25,10 @@ CONFIG_BOOTCOUNT_LIMIT=y
 CONFIG_DFU_TFTP=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_MMC_OMAP_HS=y
 CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_WINBOND=y
index abbacdc77ec4b1657141fa51acdd38295c101d9e..baaae36d288c5a9822e5dadefc0644859049deff 100644 (file)
@@ -19,7 +19,7 @@ CONFIG_AUTOBOOT_KEYED=y
 CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n"
 CONFIG_AUTOBOOT_DELAY_STR="d"
 CONFIG_AUTOBOOT_STOP_STR=" "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_CMD_SPL=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
index 6732013b03f5bf4a0beec22f36ec7e31f9febcb1..cc556d1c3d7b01e46889ac990058d51373619d6e 100644 (file)
@@ -13,7 +13,7 @@ CONFIG_ARCH_MISC_INIT=y
 CONFIG_SPL_MTD_SUPPORT=y
 CONFIG_SPL_MUSB_NEW_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_CMD_SPL=y
 CONFIG_CMD_SPL_NAND_OFS=0x00080000
 # CONFIG_CMD_FLASH is not set
index bbde07fb1d64da69e73a5d6cf4a1ce7acef8eaa8..41a5c79604d6c746e7e3edf7dc6a58d25558cec1 100644 (file)
@@ -12,7 +12,7 @@ CONFIG_ARCH_MISC_INIT=y
 CONFIG_SPL_MTD_SUPPORT=y
 CONFIG_SPL_MUSB_NEW_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_CMD_SPL=y
 CONFIG_CMD_SPL_NAND_OFS=0x00080000
 CONFIG_CMD_NAND=y
index 3ddcf649423c48a3665dd12052773f68c3d8655e..75d0793f2d2c7ee01e032d071ff26f81e2c463c8 100644 (file)
@@ -12,7 +12,7 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_VERSION_VARIABLE=y
 CONFIG_ARCH_MISC_INIT=y
 CONFIG_BOARD_EARLY_INIT_F=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_MTDPARTS=y
 CONFIG_MTDIDS_DEFAULT="nor0=physmap-flash.0"
index 10eb0fe1ee8cbf7914129ec033373fbd46c67e56..b2678875ecab6e9b9b838bafa650cfd6cee3273e 100644 (file)
@@ -15,7 +15,7 @@ CONFIG_VERSION_VARIABLE=y
 CONFIG_ARCH_MISC_INIT=y
 CONFIG_SPL_MUSB_NEW_SUPPORT=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_MTDPARTS=y
index dc9ac216c215a2d215f6de72007e6bf9605bf546..44012919a366c741dcac5575d2763a2bd7beda75 100644 (file)
@@ -19,7 +19,7 @@ CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_USB_GADGET_SUPPORT=y
 CONFIG_SPL_USB_ETHER=y
 # CONFIG_SPL_YMODEM_SUPPORT is not set
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_CMD_SPL=y
 CONFIG_CMD_SPL_NAND_OFS=0x00080000
 # CONFIG_CMD_FLASH is not set
index 0e992684412ce8bf6b5d8d171234ab3693aaaffa..2d8e64e613aab3f03b34f7fff88d74eeb65a3e4e 100644 (file)
@@ -24,12 +24,6 @@ CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_BUF_ADDR=0x82000000
-CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
-CONFIG_FASTBOOT_USB_DEV=1
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=1
 CONFIG_CMD_SPL=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
@@ -45,6 +39,13 @@ CONFIG_SCSI_AHCI=y
 # CONFIG_BLK is not set
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x82000000
+CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
+CONFIG_FASTBOOT_USB_DEV=1
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_DM_MMC=y
index 165c2a40ba084fa65a773bedfef459c3daca953c..3a73fdb2ca9d276d16cb0898b09eff6de73ded08 100644 (file)
@@ -29,12 +29,6 @@ CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_BUF_ADDR=0x82000000
-CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
-CONFIG_FASTBOOT_USB_DEV=1
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=1
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_OF_CONTROL=y
@@ -48,6 +42,13 @@ CONFIG_SCSI_AHCI=y
 # CONFIG_BLK is not set
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x82000000
+CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
+CONFIG_FASTBOOT_USB_DEV=1
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_DM_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_DM_MMC=y
index 9a986ca9ae8a8500ae75bb340e59e84c3ce3b4b8..de4fa60df7c9cc5bf336302a47cf8d285d0f27fc 100644 (file)
@@ -7,7 +7,7 @@ CONFIG_VERSION_VARIABLE=y
 # CONFIG_DISPLAY_CPUINFO is not set
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x80000000
 CONFIG_FASTBOOT_BUF_SIZE=0x1D000000
 CONFIG_FASTBOOT_FLASH=y
index d26cde5b0ed0954f063dbe71fb2808e2d37e255c..4f7a58e362a85c12b8eaa4ea487f527e11f462c4 100644 (file)
@@ -8,7 +8,7 @@ CONFIG_VERSION_VARIABLE=y
 # CONFIG_DISPLAY_BOARDINFO is not set
 CONFIG_HUSH_PARSER=y
 # CONFIG_AUTOBOOT is not set
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x80000000
 CONFIG_FASTBOOT_BUF_SIZE=0x7FF00000
 CONFIG_FASTBOOT_FLASH=y
index 51b3e6b4e1a1bbe9b9e5bfeef1fdb59bb8c41f84..3efd5669a74924c101bc01e844756eafd8b6d42a 100644 (file)
@@ -25,7 +25,7 @@ CONFIG_SPL_MUSB_NEW_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_POWER_SUPPORT=y
 CONFIG_SPL_YMODEM_SUPPORT=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_CMD_SPL=y
 CONFIG_CMD_ASKENV=y
index 29b223a58062382f8fe96910427c81cda294cec2..2f981168734959abd53c06f8bfca747fdb2e307f 100644 (file)
@@ -25,7 +25,7 @@ CONFIG_SPL_MUSB_NEW_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_POWER_SUPPORT=y
 CONFIG_SPL_YMODEM_SUPPORT=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_CMD_SPL=y
 CONFIG_CMD_ASKENV=y
index d4204aa7122067231fd256383894aa4192188ff5..241e9582a5a255a8a4263d2f964d98f7100f4730 100644 (file)
@@ -24,7 +24,7 @@ CONFIG_SPL_I2C_SUPPORT=y
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="CGT-QMX6-Quad U-Boot > "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_DFU=y
index d1728ef6395ca67d891dc8efdd012de1445f8fa1..72ecdc69f6bfba160b7d8b4eacf86e8c24bb6f42 100644 (file)
@@ -16,8 +16,6 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -44,6 +42,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
 CONFIG_SYS_I2C_ROCKCHIP=y
index 43d93f4637ad5ad74d4f9a7136c142254756cc0a..fb8400d06ef879ff8986216755e1c3733180fdc1 100644 (file)
@@ -18,8 +18,6 @@ CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -46,6 +44,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
 CONFIG_SYS_I2C_ROCKCHIP=y
index 706809ca53fb8d70f8b1e699ba808acbef32c93b..a8776c9adfb80dd8fcaae2e91f10213bde793b3e 100644 (file)
@@ -17,8 +17,6 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -45,6 +43,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_I2C_CROS_EC_TUNNEL=y
 CONFIG_SYS_I2C_ROCKCHIP=y
index 9b81b0cc7168c1e27388efd1d7ad9654fea08b83..182f9a9ebfab6daf8838c5b9b52e8f5c1de96c8a 100644 (file)
@@ -25,11 +25,6 @@ CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_BUF_ADDR=0x82000000
-CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=1
 CONFIG_CMD_SPL=y
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
@@ -50,6 +45,12 @@ CONFIG_DWC_AHCI=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
 CONFIG_DFU_SF=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x82000000
+CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_DM_GPIO=y
 CONFIG_PCF8575_GPIO=y
 CONFIG_DM_I2C=y
index 536946eb29007db39d6f247660f850308c4983a0..8584d41f1aa4100dd938329b07cc06b631492996 100644 (file)
@@ -30,11 +30,6 @@ CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_BUF_ADDR=0x82000000
-CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=1
 # CONFIG_CMD_FLASH is not set
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_OF_CONTROL=y
@@ -50,6 +45,12 @@ CONFIG_DWC_AHCI=y
 CONFIG_DFU_MMC=y
 CONFIG_DFU_RAM=y
 CONFIG_DFU_SF=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x82000000
+CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_DM_GPIO=y
 CONFIG_PCF8575_GPIO=y
 CONFIG_DM_I2C=y
index 33775e8cdddbf1592aaf375a0b67f9c730dc6d8c..b9242e83e0a24501750ec20dcad59f6bad96d05e 100644 (file)
@@ -15,8 +15,6 @@ CONFIG_SPL_SYS_MALLOC_F_LEN=0x0
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 # CONFIG_SPL_FRAMEWORK is not set
 CONFIG_SPL_STACK_R=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
@@ -31,6 +29,9 @@ CONFIG_SPL_PARTITION_UUIDS=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_LED=y
index 796d0ec92e67110a50af9c8f174980d4b84412ad..9c8252e95f6bae3b5a2452f7d11d7fdbe6530432 100644 (file)
@@ -7,10 +7,6 @@ CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
-CONFIG_FASTBOOT_BUF_ADDR=0x60800800
-CONFIG_FASTBOOT_BUF_SIZE=0x04000000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_USB=y
@@ -20,6 +16,11 @@ CONFIG_CMD_TIME=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_CLK=y
+CONFIG_FASTBOOT_BUF_ADDR=0x60800800
+CONFIG_FASTBOOT_BUF_SIZE=0x04000000
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MMC_DW=y
index 710b0b4e1a99afc8eab17d3a4eab88a849c9b333..7298bf1963ee7c6e6bcb94c9a441bc72b328947e 100644 (file)
@@ -14,8 +14,6 @@ CONFIG_DEBUG_UART=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x200
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
 # CONFIG_CMD_SETEXPR is not set
@@ -30,6 +28,9 @@ CONFIG_SYSCON=y
 CONFIG_SPL_SYSCON=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MMC_DW=y
index 7695277daf350427d1b3b20688ba5a1fbb423ad8..a7beaa67288494f6124fd3ea14e608da3f641d31 100644 (file)
@@ -14,8 +14,6 @@ CONFIG_SILENT_CONSOLE=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -41,6 +39,9 @@ CONFIG_SYSCON=y
 CONFIG_SPL_SYSCON=y
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_LED=y
index 78ae24b56b27fecf4e2d5c14c47ab317e72b6b9a..59bf9e519787fd429844e9d24d6ef60b5eb3959b 100644 (file)
@@ -8,9 +8,6 @@ CONFIG_DEBUG_UART=y
 CONFIG_FIT=y
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_DISPLAY_BOARDINFO_LATE=y
-CONFIG_FASTBOOT_BUF_ADDR=0x800800
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=1
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
@@ -23,6 +20,10 @@ CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_CLK=y
+CONFIG_FASTBOOT_BUF_ADDR=0x800800
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=1
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MMC_DW=y
index efdd583cf6e5b34786aeea37cc55a27eeb8880b8..dbd6be55e240721f392af91c2fa6c4a0918310a7 100644 (file)
@@ -15,8 +15,6 @@ CONFIG_CONSOLE_MUX=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -42,6 +40,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MMC_DW=y
index b252d2746403e16cbaa1fb072945c50749ff8b00..83b4968c4a7fa3f3adaeae876ecb8edb6e9a8ef2 100644 (file)
@@ -14,8 +14,6 @@ CONFIG_SILENT_CONSOLE=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -42,6 +40,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_DM_KEYBOARD=y
index 0001457f5d08f702f34d963dd2b1bb21693be4df..40a128b8cbcc5032b1bfa6534870553b1c2836b3 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_DEFAULT_DEVICE_TREE="imx6dl-mamoj"
 CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=arch/arm/mach-imx/spl_sd.cfg"
 CONFIG_BOOTDELAY=3
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_FASTBOOT_BUF_SIZE=0x10000000
 CONFIG_FASTBOOT_FLASH=y
index 534d60484a078196137e796ff3f499304073bdd0..ce71e37011aeeef66af2d9900ed04f7930b3dd57 100644 (file)
@@ -12,7 +12,7 @@ CONFIG_SYS_CONSOLE_IS_IN_ENV=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=2
 CONFIG_SYS_PROMPT="kc1 # "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_FASTBOOT_BUF_SIZE=0x2000000
 CONFIG_FASTBOOT_FLASH=y
index ca53005ecb3de0fad14fd90c07121abf839948eb..373764aaf18e3831ee96b020e9cbd876d69a88ef 100644 (file)
@@ -14,8 +14,6 @@ CONFIG_SPL_SYS_MALLOC_F_LEN=0x0
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 # CONFIG_SPL_FRAMEWORK is not set
 CONFIG_SPL_STACK_R=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
@@ -31,6 +29,9 @@ CONFIG_ENV_IS_IN_MMC=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_LED=y
index f44537c88f40d7dc4d8ceaa1edf69df09ce6cd6d..5bfcb0c90bf14fdaa65e0b815de0215fba6dcc4f 100644 (file)
@@ -14,8 +14,6 @@ CONFIG_SILENT_CONSOLE=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -42,6 +40,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MMC_DW=y
index 966e823b40d7901c6248e0cfaa9714846bf97168..a4740d49cf428d240688b91313a96d3bbc4711d5 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_BOOTDELAY=3
 # CONFIG_USE_BOOTCOMMAND is not set
 CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_BOARD_EARLY_INIT_F=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_MEMTEST=y
 CONFIG_SYS_ALT_MEMTEST=y
index ca37d8bef80ec8164f9ab6fbfc4a6ed9a53500a4..5c8e9de0819ffb91f27266e34d522bc5097d0abe 100644 (file)
@@ -22,7 +22,7 @@ CONFIG_SPL_USB_HOST_SUPPORT=y
 CONFIG_SPL_USB_GADGET_SUPPORT=y
 CONFIG_SPL_USB_SDP_SUPPORT=y
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_FASTBOOT_BUF_SIZE=0x10000000
 CONFIG_FASTBOOT_FLASH=y
index 6ef4226db910a23d84dbc3fad26e8fc27539577b..cfb2ed8889d238d8445e2fba0d8f2789cbcc927c 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_MEMTEST=y
index b9784a2d23fed3698b6845392c4b41a1b49c386c..9cb7ac22d5441bccda5a75448b6dc02ef7d59f3f 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_MEMTEST=y
index 61688ba49e48fdf6b45291f3a4d9074c94ead62f..e31521a0609a685193725cc8dbff37a362978933 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_MEMTEST=y
index cfee7ba88916972ae84a0613e5d23232dda35ec7..85c352c6f0030acd00fcfb091bfc5bab78be4f13 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_MEMTEST=y
index 0f29a56c4646e6d3ce039ff29d9a64b7eb4d0ace..1f3732019da77e27028cafc55c92e2d3460006f7 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_MEMTEST=y
index 7ad1584af27fecab669e219899cc628d41e1283a..0696f09d5e68c3b8d834fc6b43819962071d1c98 100644 (file)
@@ -9,7 +9,7 @@ CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE=y
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_HUSH_PARSER=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x12000000
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_MEMTEST=y
index 7b81b039c9fd94a0cd6bb0b6af1ad80fb0123ad9..05dc73755f326f00ec54418be620a35f6cf3c0a0 100644 (file)
@@ -13,7 +13,7 @@ CONFIG_VERSION_VARIABLE=y
 CONFIG_SPL_MTD_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SYS_PROMPT="BeagleBoard # "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_CMD_SPL=y
 CONFIG_CMD_SPL_NAND_OFS=0x280000
index 20795c3170fdd5492eacd439e039964c13f894e1..52285cc1651f82e64322c41d80ac517d321628df 100644 (file)
@@ -12,7 +12,7 @@ CONFIG_VERSION_VARIABLE=y
 CONFIG_SPL_MTD_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SYS_PROMPT="OMAP3_EVM # "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_CMD_SPL=y
 CONFIG_CMD_SPL_NAND_OFS=0x280000
index 5a31e46dbaf5b00836aceaa06675ffe9914b2996..953980c95c962583be9f66593371bbf7ef9fdf9b 100644 (file)
@@ -13,7 +13,7 @@ CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_SPL_MTD_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SYS_PROMPT="OMAP Logic # "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 # CONFIG_CMD_IMI is not set
 CONFIG_CMD_SPL=y
index 991e9b99aaba75eef2ff2051366cdb48cda39fdc..553a8d6572886519c9e5b899672f786148b15959 100644 (file)
@@ -15,6 +15,7 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-r16-parrot"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_PARTITION_UUIDS is not set
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_CONS_INDEX=5
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_MUSB_GADGET=y
index d78b6d57b6b87a9fc315bff0258db1b35bff1013..fc3b81c43c11ec114a65e39ab02afdd9d0139995 100644 (file)
@@ -17,8 +17,6 @@ CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 CONFIG_SPL_I2C_SUPPORT=y
 CONFIG_SPL_POWER_SUPPORT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -44,6 +42,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MISC=y
index 2670b4b75aef890af8add7d19bdf55ee4a5ee55c..84c099560fa19c0b296581e00a33ccfac54290f4 100644 (file)
@@ -15,8 +15,6 @@ CONFIG_CONSOLE_MUX=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -42,6 +40,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MMC_DW=y
index cd9a82197464f7ed87091355e95be54719512b11..01d53ac1c394b81393c06a5050be189e604f2afd 100644 (file)
@@ -14,8 +14,6 @@ CONFIG_SILENT_CONSOLE=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -42,6 +40,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MMC_DW=y
index ad22a1cbe2ff1f683479dc5c1773a41f5f9b8de5..70e485fab27c865376e46149ef488d12fbaac288 100644 (file)
@@ -13,7 +13,7 @@ CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION=y
 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION=2
 # CONFIG_SPL_EXT_SUPPORT is not set
 CONFIG_SYS_PROMPT="sniper # "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_FASTBOOT_BUF_SIZE=0x2000000
 CONFIG_FASTBOOT_FLASH=y
index 67391bdfdf73e2e5c5e3d6ded08f027f9ac0d311..ba1ff25d355487e3c3329eb6e34dd072572a5ed3 100644 (file)
@@ -10,11 +10,6 @@ CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyAS1,115200 CONSOLE=/dev/ttyAS1 consoleblank=0 root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait mem=992M@0x40000000 vmalloc=256m"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SYS_PROMPT="stih410-b2260 => "
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_BUF_ADDR=0x40000000
-CONFIG_FASTBOOT_BUF_SIZE=0x3DF00000
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPT=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_USB=y
@@ -26,6 +21,12 @@ CONFIG_OF_CONTROL=y
 CONFIG_REGMAP=y
 CONFIG_SYSCON=y
 CONFIG_CLK=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_BUF_ADDR=0x40000000
+CONFIG_FASTBOOT_BUF_SIZE=0x3DF00000
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_MISC=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_STI=y
index 3e3de4fbb30906a80af685ae067c387aeff1251e..5d58f5ceb4e24b4b5dc39f3696a764fd6e062007 100644 (file)
@@ -16,6 +16,7 @@ CONFIG_DEFAULT_DEVICE_TREE="sun8i-a83t-tbs-a711"
 # CONFIG_CMD_FLASH is not set
 # CONFIG_SPL_DOS_PARTITION is not set
 # CONFIG_SPL_EFI_PARTITION is not set
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_AXP_DCDC5_VOLT=1200
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_MUSB_GADGET=y
index fb6bfa57ad7f917008020650cace9dadc371dc5f..e1c99c3828d7662abdd9903df131f852c21719de 100644 (file)
@@ -16,8 +16,6 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_SPL_STACK_R=y
 CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x2000
 CONFIG_SPL_I2C_SUPPORT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
@@ -43,6 +41,9 @@ CONFIG_SPL_SYSCON=y
 # CONFIG_SPL_SIMPLE_BUS is not set
 CONFIG_CLK=y
 CONFIG_SPL_CLK=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_MISC=y
index f5a33342fa64164836c1e42f1479123d367c35a4..b4521aab43e5d519d3bce629c8c82bc991b10fb5 100644 (file)
@@ -19,9 +19,6 @@ CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
 CONFIG_SPL_ATF=y
 CONFIG_SYS_PROMPT="ZynqMP> "
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_MEMTEST=y
 CONFIG_SYS_ALT_MEMTEST=y
@@ -47,6 +44,10 @@ CONFIG_SPL_DM=y
 CONFIG_SPL_DM_SEQ_ALIAS=y
 CONFIG_CLK_ZYNQMP=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_FPGA_XILINX=y
 CONFIG_FPGA_ZYNQMPPL=y
 CONFIG_DM_GPIO=y
index 7f7ee558ee7ef25d14e8d826004ec263c142581d..9d9216f5fe75d1e106234e66c12393921efce206 100644 (file)
@@ -20,7 +20,7 @@ CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
 CONFIG_SPL_ATF=y
 CONFIG_SYS_PROMPT="ZynqMP> "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_FLASH=y
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_MEMTEST=y
index 4cb3959f3626b655e1baddcfb64009839187b403..976640cae06f6190c906cf26d65d18e94ea05bfb 100644 (file)
@@ -19,9 +19,6 @@ CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
 CONFIG_SPL_ATF=y
 CONFIG_SYS_PROMPT="ZynqMP> "
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_EEPROM=y
 CONFIG_CMD_MEMTEST=y
@@ -50,6 +47,10 @@ CONFIG_SCSI_AHCI=y
 CONFIG_SATA_CEVA=y
 CONFIG_CLK_ZYNQMP=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_FPGA_XILINX=y
 CONFIG_FPGA_ZYNQMPPL=y
 CONFIG_DM_GPIO=y
index e989d1635c3092ee361f97811ce8a7c7161d59dd..3420ce5dc34aab6639c7c5c058e9a674f8410db7 100644 (file)
@@ -19,9 +19,6 @@ CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
 CONFIG_SPL_ATF=y
 CONFIG_SYS_PROMPT="ZynqMP> "
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_EEPROM=y
 CONFIG_CMD_MEMTEST=y
@@ -50,6 +47,10 @@ CONFIG_SCSI_AHCI=y
 CONFIG_SATA_CEVA=y
 CONFIG_CLK_ZYNQMP=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_FPGA_XILINX=y
 CONFIG_FPGA_ZYNQMPPL=y
 CONFIG_DM_GPIO=y
index bd67df904a2df1b7371896af379a3e72f7f8101a..a9ba4a17e9a3acb17a487d3c0f206811cfed2a39 100644 (file)
@@ -19,9 +19,6 @@ CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
 CONFIG_SPL_ATF=y
 CONFIG_SYS_PROMPT="ZynqMP> "
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_EEPROM=y
 CONFIG_CMD_MEMTEST=y
@@ -50,6 +47,10 @@ CONFIG_SCSI_AHCI=y
 CONFIG_SATA_CEVA=y
 CONFIG_CLK_ZYNQMP=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_FPGA_XILINX=y
 CONFIG_FPGA_ZYNQMPPL=y
 CONFIG_DM_GPIO=y
index a5fa33e366aec95201cca465f6271366cd92cf8c..32c6f232106c675e80947b150d2fc7e00bc3077f 100644 (file)
@@ -18,9 +18,6 @@ CONFIG_SPL_RAM_SUPPORT=y
 CONFIG_SPL_RAM_DEVICE=y
 CONFIG_SPL_ATF=y
 CONFIG_SYS_PROMPT="ZynqMP> "
-CONFIG_FASTBOOT=y
-CONFIG_FASTBOOT_FLASH=y
-CONFIG_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
 CONFIG_CMD_EEPROM=y
 CONFIG_CMD_MEMTEST=y
@@ -48,6 +45,10 @@ CONFIG_SCSI_AHCI=y
 CONFIG_SATA_CEVA=y
 CONFIG_CLK_ZYNQMP=y
 CONFIG_DFU_RAM=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
+CONFIG_FASTBOOT_FLASH=y
+CONFIG_FASTBOOT_FLASH_MMC_DEV=0
+CONFIG_FASTBOOT_CMD_OEM_FORMAT=y
 CONFIG_FPGA_XILINX=y
 CONFIG_FPGA_ZYNQMPPL=y
 CONFIG_DM_GPIO=y
index 2c3ee7810a4fc8940e93e87e972f13fbac1a2423..431191c473f267e05b4df4774c9de49c020834b1 100644 (file)
+================
 Android Fastboot
-~~~~~~~~~~~~~~~~
+================
 
 Overview
 ========
-The protocol that is used over USB is described in
-README.android-fastboot-protocol in same directory.
 
-The current implementation is a minimal support of the erase command,the
-"oem format" command and flash command;it only supports eMMC devices.
+The protocol that is used over USB and UDP is described in the
+``README.android-fastboot-protocol`` file in the same directory.
+
+The current implementation supports the following standard commands:
+
+- ``boot``
+- ``continue``
+- ``download``
+- ``erase`` (if enabled)
+- ``flash`` (if enabled)
+- ``getvar``
+- ``reboot``
+- ``reboot-bootloader``
+- ``set_active`` (only a stub implementation which always succeeds)
+
+The following OEM commands are supported (if enabled):
+
+- oem format - this executes ``gpt write mmc %x $partitions``
+
+Support for both eMMC and NAND devices is included.
 
 Client installation
 ===================
-The counterpart to this gadget is the fastboot client which can
-be found in Android's platform/system/core repository in the fastboot
-folder. It runs on Windows, Linux and even OSX. Linux user are lucky since
-they only need libusb.
-Windows users need to bring some time until they have Android SDK (currently
-http://dl.google.com/android/installer_r12-windows.exe) installed. You
-need to install ADB package which contains the required glue libraries for
-accessing USB. Also you need "Google USB driver package" and "SDK platform
-tools". Once installed the usb driver is placed in your SDK folder under
-extras\google\usb_driver. The android_winusb.inf needs a line like
-
-   %SingleBootLoaderInterface% = USB_Install, USB\VID_0451&PID_D022
-
-either in the [Google.NTx86] section for 32bit Windows or [Google.NTamd64]
-for 64bit Windows. VID and PID should match whatever the fastboot is
-advertising.
+
+The counterpart to this is the fastboot client which can be found in
+Android's ``platform/system/core`` repository in the fastboot
+folder. It runs on Windows, Linux and OSX. The fastboot client is
+part of the Android SDK Platform-Tools and can be downloaded from:
+
+https://developer.android.com/studio/releases/platform-tools
 
 Board specific
 ==============
+
+USB configuration
+-----------------
+
 The fastboot gadget relies on the USB download gadget, so the following
 options must be configured:
 
-CONFIG_USB_GADGET_DOWNLOAD
-CONFIG_USB_GADGET_VENDOR_NUM
-CONFIG_USB_GADGET_PRODUCT_NUM
-CONFIG_USB_GADGET_MANUFACTURER
+::
+
+   CONFIG_USB_GADGET_DOWNLOAD
+   CONFIG_USB_GADGET_VENDOR_NUM
+   CONFIG_USB_GADGET_PRODUCT_NUM
+   CONFIG_USB_GADGET_MANUFACTURER
 
-NOTE: The CONFIG_USB_GADGET_VENDOR_NUM must be one of the numbers supported by
-the fastboot client. The list of vendor IDs supported can be found in the
-fastboot client source code (fastboot.c) mentioned above.
+NOTE: The ``CONFIG_USB_GADGET_VENDOR_NUM`` must be one of the numbers
+supported by the fastboot client. The list of vendor IDs supported can
+be found in the fastboot client source code.
 
-The fastboot function is enabled by defining CONFIG_USB_FUNCTION_FASTBOOT,
-CONFIG_CMD_FASTBOOT and CONFIG_ANDROID_BOOT_IMAGE.
+General configuration
+---------------------
 
-The fastboot protocol requires a large memory buffer for downloads. This
-buffer should be as large as possible for a platform. The location of the
-buffer and size are set with CONFIG_FASTBOOT_BUF_ADDR and
-CONFIG_FASTBOOT_BUF_SIZE.
+The fastboot protocol requires a large memory buffer for
+downloads. This buffer should be as large as possible for a
+platform. The location of the buffer and size are set with
+``CONFIG_FASTBOOT_BUF_ADDR`` and ``CONFIG_FASTBOOT_BUF_SIZE``. These
+may be overridden on the fastboot command line using ``-l`` and
+``-s``.
+
+Fastboot environment variables
+==============================
+
+Partition aliases
+-----------------
 
 Fastboot partition aliases can also be defined for devices where GPT
 limitations prevent user-friendly partition names such as "boot", "system"
 and "cache".  Or, where the actual partition name doesn't match a standard
-partition name used commonly with fastboot.  Current implentation checks
-aliases when accessing partitions by name (flash_write and erase functions).
-To define a partition alias add an environment variable similar to:
-fastboot_partition_alias_<alias partition name>=<actual partition name>
-Example: fastboot_partition_alias_boot=LNX
+partition name used commonly with fastboot.
+
+The current implementation checks aliases when accessing partitions by
+name (flash_write and erase functions).  To define a partition alias
+add an environment variable similar to:
+
+``fastboot_partition_alias_<alias partition name>=<actual partition name>``
+
+for example:
+
+``fastboot_partition_alias_boot=LNX``
+
+Variable overrides
+------------------
+
+Variables retrived through ``getvar`` can be overridden by defining
+environment variables of the form ``fastboot.<variable>``. These are
+looked up first so can be used to override values which would
+otherwise be returned. Using this mechanism you can also return types
+for NAND filesystems, as the fully parameterised variable is looked
+up, e.g.
+
+``fastboot.partition-type:boot=jffs2``
+
+Boot command
+------------
+
+When executing the fastboot ``boot`` command, if ``fastboot_bootcmd`` is set then
+that will be executed in place of ``bootm <CONFIG_FASTBOOT_BUF_ADDR>``.
 
 Partition Names
 ===============
-The Fastboot implementation in U-boot allows to write images into disk
-partitions (currently on eMMC). Target partitions are referred on the host
-computer by their names.
+
+The Fastboot implementation in U-Boot allows to write images into disk
+partitions. Target partitions are referred on the host computer by
+their names.
 
 For GPT/EFI the respective partition name is used.
 
 For MBR the partitions are referred by generic names according to the
 following schema:
 
-  <device type> <device index letter> <partition index>
+  <device type><device index letter><partition index>
 
-Example: hda3, sdb1, usbda1
+Example: ``hda3``, ``sdb1``, ``usbda1``
 
 The device type is as follows:
 
-  * IDE, ATAPI and SATA disks: hd
-  * SCSI disks: sd
-  * USB media: usbd
-  * MMC and SD cards: mmcsd
-  * Disk on chip: docd
-  * other: xx
+  * IDE, ATAPI and SATA disks: ``hd``
+  * SCSI disks: ``sd``
+  * USB media: ``usbd``
+  * MMC and SD cards: ``mmcsd``
+  * Disk on chip: ``docd``
+  * other: ``xx``
 
-The device index starts from 'a' and refers to the interface (e.g. USB
+The device index starts from ``a`` and refers to the interface (e.g. USB
 controller, SD/MMC controller) or disk index. The partition index starts
-from 1 and describes the partition number on the particular device.
+from ``1`` and describes the partition number on the particular device.
 
 Writing Partition Table
 =======================
+
 Fastboot also allows to write the partition table to the media. This can be
 done by writing the respective partition table image to a special target
 "gpt" or "mbr". These names can be customized by defining the following
 configuration options:
 
-CONFIG_FASTBOOT_GPT_NAME
-CONFIG_FASTBOOT_MBR_NAME
+::
+
+   CONFIG_FASTBOOT_GPT_NAME
+   CONFIG_FASTBOOT_MBR_NAME
 
 In Action
 =========
-Enter into fastboot by executing the fastboot command in u-boot and you
-should see:
-|GADGET DRIVER: usb_dnl_fastboot
+
+Enter into fastboot by executing the fastboot command in U-Boot for either USB:
+
+::
+
+   => fastboot usb 0
+
+or UDP:
+
+::
+
+   => fastboot udp
+   link up on port 0, speed 100, full duplex
+   Using ethernet@4a100000 device
+   Listening for fastboot command on 192.168.0.102
 
 On the client side you can fetch the bootloader version for instance:
-|>fastboot getvar bootloader-version
-|bootloader-version: U-Boot 2014.04-00005-gd24cabc
-|finished. total time: 0.000s
+
+::
+
+   $ fastboot getvar bootloader-version
+   bootloader-version: U-Boot 2014.04-00005-gd24cabc
+   finished. total time: 0.000s
 
 or initiate a reboot:
-|>fastboot reboot
+
+::
+
+   $ fastboot reboot
 
 and once the client comes back, the board should reset.
 
 You can also specify a kernel image to boot. You have to either specify
-the an image in Android format _or_ pass a binary kernel and let the
+the an image in Android format *or* pass a binary kernel and let the
 fastboot client wrap the Android suite around it. On OMAP for instance you
 take zImage kernel and pass it to the fastboot client:
 
-|>fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0
-|      mem=128M" boot zImage
-|creating boot image...
-|creating boot image - 1847296 bytes
-|downloading 'boot.img'...
-|OKAY [  2.766s]
-|booting...
-|OKAY [ -0.000s]
-|finished. total time: 2.766s
-
-and on the gadget side you should see:
-|Starting download of 1847296 bytes
-|........................................................
-|downloading of 1847296 bytes finished
-|Booting kernel..
-|## Booting Android Image at 0x81000000 ...
-|Kernel load addr 0x80008000 size 1801 KiB
-|Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M
-|   Loading Kernel Image ... OK
-|OK
-|
-|Starting kernel ...
+::
+
+   $ fastboot -b 0x80000000 -c "console=ttyO2 earlyprintk root=/dev/ram0 mem=128M" boot zImage
+   creating boot image...
+   creating boot image - 1847296 bytes
+   downloading 'boot.img'...
+   OKAY [  2.766s]
+   booting...
+   OKAY [ -0.000s]
+   finished. total time: 2.766s
+
+and on the U-Boot side you should see:
+
+::
+
+   Starting download of 1847296 bytes
+   ........................................................
+   downloading of 1847296 bytes finished
+   Booting kernel..
+   ## Booting Android Image at 0x81000000 ...
+   Kernel load addr 0x80008000 size 1801 KiB
+   Kernel command line: console=ttyO2 earlyprintk root=/dev/ram0 mem=128M
+      Loading Kernel Image ... OK
+   OK
+
+   Starting kernel ...
index c2e813f5adf73762743245a95fd833991ed5cc64..8424898dbdc6226c645a2436c10c90c8370fe455 100644 (file)
@@ -28,6 +28,8 @@ source "drivers/dfu/Kconfig"
 
 source "drivers/dma/Kconfig"
 
+source "drivers/fastboot/Kconfig"
+
 source "drivers/firmware/Kconfig"
 
 source "drivers/fpga/Kconfig"
index b3f1b600a558cef08d1f750c1b42b27a6bb9ad51..d29a6e467b6c5d121d3b73152b7d3314e2af898a 100644 (file)
@@ -71,6 +71,7 @@ obj-y += block/
 obj-$(CONFIG_BOOTCOUNT_LIMIT) += bootcount/
 obj-$(CONFIG_CPU) += cpu/
 obj-y += crypto/
+obj-$(CONFIG_FASTBOOT) += fastboot/
 obj-y += firmware/
 obj-$(CONFIG_FPGA) += fpga/
 obj-y += misc/
diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
new file mode 100644 (file)
index 0000000..bc25ea1
--- /dev/null
@@ -0,0 +1,137 @@
+menu "Fastboot support"
+
+config FASTBOOT
+       bool
+       imply ANDROID_BOOT_IMAGE
+       imply CMD_FASTBOOT
+
+config USB_FUNCTION_FASTBOOT
+       bool "Enable USB fastboot gadget"
+       depends on USB_GADGET
+       default y if ARCH_SUNXI && USB_MUSB_GADGET
+       select FASTBOOT
+       select USB_GADGET_DOWNLOAD
+       help
+         This enables the USB part of the fastboot gadget.
+
+config UDP_FUNCTION_FASTBOOT
+       depends on NET
+       select FASTBOOT
+       bool "Enable fastboot protocol over UDP"
+       help
+         This enables the fastboot protocol over UDP.
+
+if 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"
+       depends on USB_FUNCTION_FASTBOOT
+       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
+       depends on MMC || (NAND && CMD_MTDPARTS)
+       select IMAGE_SPARSE
+       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 && CMD_MTDPARTS
+
+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_TRIMFFS
+       bool "Skip empty pages when flashing NAND"
+       depends on FASTBOOT_FLASH_NAND
+       help
+         When flashing NAND enable the DROP_FFS flag to drop trailing all-0xff
+         pages.
+
+config FASTBOOT_GPT_NAME
+       string "Target name for updating GPT"
+       depends on FASTBOOT_FLASH_MMC && EFI_PARTITION
+       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_MMC && DOS_PARTITION
+       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".
+
+config FASTBOOT_CMD_OEM_FORMAT
+       bool "Enable the 'oem format' command"
+       depends on FASTBOOT_FLASH_MMC && CMD_GPT
+       help
+         Add support for the "oem format" command from a client. This
+         relies on the env variable partitions to contain the list of
+         partitions as required by the gpt command.
+
+endif # FASTBOOT
+
+endmenu
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
new file mode 100644 (file)
index 0000000..a242156
--- /dev/null
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier:      GPL-2.0+
+
+obj-y += fb_common.o
+obj-y += fb_getvar.o
+obj-y += fb_command.o
+obj-$(CONFIG_FASTBOOT_FLASH_MMC) += 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
new file mode 100644 (file)
index 0000000..200f991
--- /dev/null
@@ -0,0 +1,335 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ */
+
+#include <common.h>
+#include <fastboot.h>
+#include <fastboot-internal.h>
+#include <fb_mmc.h>
+#include <fb_nand.h>
+#include <part.h>
+#include <stdlib.h>
+
+/**
+ * image_size - final fastboot image size
+ */
+static u32 image_size;
+
+/**
+ * fastboot_bytes_received - number of bytes received in the current download
+ */
+static u32 fastboot_bytes_received;
+
+/**
+ * fastboot_bytes_expected - number of bytes expected in the current download
+ */
+static u32 fastboot_bytes_expected;
+
+static void okay(char *, char *);
+static void getvar(char *, char *);
+static void download(char *, char *);
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+static void flash(char *, char *);
+static void erase(char *, char *);
+#endif
+static void reboot_bootloader(char *, char *);
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+static void oem_format(char *, char *);
+#endif
+
+static const struct {
+       const char *command;
+       void (*dispatch)(char *cmd_parameter, char *response);
+} commands[FASTBOOT_COMMAND_COUNT] = {
+       [FASTBOOT_COMMAND_GETVAR] = {
+               .command = "getvar",
+               .dispatch = getvar
+       },
+       [FASTBOOT_COMMAND_DOWNLOAD] = {
+               .command = "download",
+               .dispatch = download
+       },
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+       [FASTBOOT_COMMAND_FLASH] =  {
+               .command = "flash",
+               .dispatch = flash
+       },
+       [FASTBOOT_COMMAND_ERASE] =  {
+               .command = "erase",
+               .dispatch = erase
+       },
+#endif
+       [FASTBOOT_COMMAND_BOOT] =  {
+               .command = "boot",
+               .dispatch = okay
+       },
+       [FASTBOOT_COMMAND_CONTINUE] =  {
+               .command = "continue",
+               .dispatch = okay
+       },
+       [FASTBOOT_COMMAND_REBOOT] =  {
+               .command = "reboot",
+               .dispatch = okay
+       },
+       [FASTBOOT_COMMAND_REBOOT_BOOTLOADER] =  {
+               .command = "reboot-bootloader",
+               .dispatch = reboot_bootloader
+       },
+       [FASTBOOT_COMMAND_SET_ACTIVE] =  {
+               .command = "set_active",
+               .dispatch = okay
+       },
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+       [FASTBOOT_COMMAND_OEM_FORMAT] = {
+               .command = "oem format",
+               .dispatch = oem_format,
+       },
+#endif
+};
+
+/**
+ * fastboot_handle_command - Handle fastboot command
+ *
+ * @cmd_string: Pointer to command string
+ * @response: Pointer to fastboot response buffer
+ *
+ * Return: Executed command, or -1 if not recognized
+ */
+int fastboot_handle_command(char *cmd_string, char *response)
+{
+       int i;
+       char *cmd_parameter;
+
+       cmd_parameter = cmd_string;
+       strsep(&cmd_parameter, ":");
+
+       for (i = 0; i < FASTBOOT_COMMAND_COUNT; i++) {
+               if (!strcmp(commands[i].command, cmd_string)) {
+                       if (commands[i].dispatch) {
+                               commands[i].dispatch(cmd_parameter,
+                                                       response);
+                               return i;
+                       } else {
+                               break;
+                       }
+               }
+       }
+
+       pr_err("command %s not recognized.\n", cmd_string);
+       fastboot_fail("unrecognized command", response);
+       return -1;
+}
+
+/**
+ * okay() - Send bare OKAY response
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ *
+ * Send a bare OKAY fastboot response. This is used where the command is
+ * valid, but all the work is done after the response has been sent (e.g.
+ * boot, reboot etc.)
+ */
+static void okay(char *cmd_parameter, char *response)
+{
+       fastboot_okay(NULL, response);
+}
+
+/**
+ * getvar() - Read a config/version variable
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void getvar(char *cmd_parameter, char *response)
+{
+       fastboot_getvar(cmd_parameter, response);
+}
+
+/**
+ * fastboot_download() - Start a download transfer from the client
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void download(char *cmd_parameter, char *response)
+{
+       char *tmp;
+
+       if (!cmd_parameter) {
+               fastboot_fail("Expected command parameter", response);
+               return;
+       }
+       fastboot_bytes_received = 0;
+       fastboot_bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
+       if (fastboot_bytes_expected == 0) {
+               fastboot_fail("Expected nonzero image size", response);
+               return;
+       }
+       /*
+        * Nothing to download yet. Response is of the form:
+        * [DATA|FAIL]$cmd_parameter
+        *
+        * where cmd_parameter is an 8 digit hexadecimal number
+        */
+       if (fastboot_bytes_expected > fastboot_buf_size) {
+               fastboot_fail(cmd_parameter, response);
+       } else {
+               printf("Starting download of %d bytes\n",
+                      fastboot_bytes_expected);
+               fastboot_response("DATA", response, "%s", cmd_parameter);
+       }
+}
+
+/**
+ * fastboot_data_remaining() - return bytes remaining in current transfer
+ *
+ * Return: Number of bytes left in the current download
+ */
+u32 fastboot_data_remaining(void)
+{
+       return fastboot_bytes_expected - fastboot_bytes_received;
+}
+
+/**
+ * fastboot_data_download() - Copy image data to fastboot_buf_addr.
+ *
+ * @fastboot_data: Pointer to received fastboot data
+ * @fastboot_data_len: Length of received fastboot data
+ * @response: Pointer to fastboot response buffer
+ *
+ * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
+ * response. fastboot_bytes_received is updated to indicate the number
+ * of bytes that have been transferred.
+ *
+ * On completion sets image_size and ${filesize} to the total size of the
+ * downloaded image.
+ */
+void fastboot_data_download(const void *fastboot_data,
+                           unsigned int fastboot_data_len,
+                           char *response)
+{
+#define BYTES_PER_DOT  0x20000
+       u32 pre_dot_num, now_dot_num;
+
+       if (fastboot_data_len == 0 ||
+           (fastboot_bytes_received + fastboot_data_len) >
+           fastboot_bytes_expected) {
+               fastboot_fail("Received invalid data length",
+                             response);
+               return;
+       }
+       /* Download data to fastboot_buf_addr */
+       memcpy(fastboot_buf_addr + fastboot_bytes_received,
+              fastboot_data, fastboot_data_len);
+
+       pre_dot_num = fastboot_bytes_received / BYTES_PER_DOT;
+       fastboot_bytes_received += fastboot_data_len;
+       now_dot_num = fastboot_bytes_received / BYTES_PER_DOT;
+
+       if (pre_dot_num != now_dot_num) {
+               putc('.');
+               if (!(now_dot_num % 74))
+                       putc('\n');
+       }
+       *response = '\0';
+}
+
+/**
+ * fastboot_data_complete() - Mark current transfer complete
+ *
+ * @response: Pointer to fastboot response buffer
+ *
+ * Set image_size and ${filesize} to the total size of the downloaded image.
+ */
+void fastboot_data_complete(char *response)
+{
+       /* Download complete. Respond with "OKAY" */
+       fastboot_okay(NULL, response);
+       printf("\ndownloading of %d bytes finished\n", fastboot_bytes_received);
+       image_size = fastboot_bytes_received;
+       env_set_hex("filesize", image_size);
+       fastboot_bytes_expected = 0;
+       fastboot_bytes_received = 0;
+}
+
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+/**
+ * flash() - write the downloaded image to the indicated partition.
+ *
+ * @cmd_parameter: Pointer to partition name
+ * @response: Pointer to fastboot response buffer
+ *
+ * Writes the previously downloaded image to the partition indicated by
+ * cmd_parameter. Writes to response.
+ */
+static void flash(char *cmd_parameter, char *response)
+{
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+       fastboot_mmc_flash_write(cmd_parameter, fastboot_buf_addr, image_size,
+                                response);
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
+       fastboot_nand_flash_write(cmd_parameter, fastboot_buf_addr, image_size,
+                                 response);
+#endif
+}
+
+/**
+ * erase() - erase the indicated partition.
+ *
+ * @cmd_parameter: Pointer to partition name
+ * @response: Pointer to fastboot response buffer
+ *
+ * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes
+ * to response.
+ */
+static void erase(char *cmd_parameter, char *response)
+{
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+       fastboot_mmc_erase(cmd_parameter, response);
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
+       fastboot_nand_erase(cmd_parameter, response);
+#endif
+}
+#endif
+
+/**
+ * reboot_bootloader() - Sets reboot bootloader flag.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void reboot_bootloader(char *cmd_parameter, char *response)
+{
+       if (fastboot_set_reboot_flag())
+               fastboot_fail("Cannot set reboot flag", response);
+       else
+               fastboot_okay(NULL, response);
+}
+
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+/**
+ * oem_format() - Execute the OEM format command
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ */
+static void oem_format(char *cmd_parameter, char *response)
+{
+       char cmdbuf[32];
+
+       if (!env_get("partitions")) {
+               fastboot_fail("partitions not set", response);
+       } else {
+               sprintf(cmdbuf, "gpt write mmc %x $partitions",
+                       CONFIG_FASTBOOT_FLASH_MMC_DEV);
+               if (run_command(cmdbuf, 0))
+                       fastboot_fail("", response);
+               else
+                       fastboot_okay(NULL, response);
+       }
+}
+#endif
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
new file mode 100644 (file)
index 0000000..c6e06aa
--- /dev/null
@@ -0,0 +1,169 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2008 - 2009
+ * Windriver, <www.windriver.com>
+ * Tom Rix <Tom.Rix@windriver.com>
+ *
+ * Copyright 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
+ *
+ * Copyright 2014 Linaro, Ltd.
+ * Rob Herring <robh@kernel.org>
+ */
+
+#include <common.h>
+#include <fastboot.h>
+#include <net/fastboot.h>
+
+/**
+ * fastboot_buf_addr - base address of the fastboot download buffer
+ */
+void *fastboot_buf_addr;
+
+/**
+ * fastboot_buf_size - size of the fastboot download buffer
+ */
+u32 fastboot_buf_size;
+
+/**
+ * fastboot_progress_callback - callback executed during long operations
+ */
+void (*fastboot_progress_callback)(const char *msg);
+
+/**
+ * fastboot_response() - Writes a response of the form "$tag$reason".
+ *
+ * @tag: The first part of the response
+ * @response: Pointer to fastboot response buffer
+ * @format: printf style format string
+ */
+void fastboot_response(const char *tag, char *response,
+                      const char *format, ...)
+{
+       va_list args;
+
+       strlcpy(response, tag, FASTBOOT_RESPONSE_LEN);
+       if (format) {
+               va_start(args, format);
+               vsnprintf(response + strlen(response),
+                         FASTBOOT_RESPONSE_LEN - strlen(response) - 1,
+                         format, args);
+               va_end(args);
+       }
+}
+
+/**
+ * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
+ *
+ * @reason: Pointer to returned reason string
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_fail(const char *reason, char *response)
+{
+       fastboot_response("FAIL", response, "%s", reason);
+}
+
+/**
+ * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
+ *
+ * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_okay(const char *reason, char *response)
+{
+       if (reason)
+               fastboot_response("OKAY", response, "%s", reason);
+       else
+               fastboot_response("OKAY", response, NULL);
+}
+
+/**
+ * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
+ *
+ * Set flag which indicates that we should reboot into the bootloader
+ * following the reboot that fastboot executes after this function.
+ *
+ * This function should be overridden in your board file with one
+ * which sets whatever flag your board specific Android bootloader flow
+ * requires in order to re-enter the bootloader.
+ */
+int __weak fastboot_set_reboot_flag(void)
+{
+       return -ENOSYS;
+}
+
+/**
+ * fastboot_get_progress_callback() - Return progress callback
+ *
+ * Return: Pointer to function called during long operations
+ */
+void (*fastboot_get_progress_callback(void))(const char *)
+{
+       return fastboot_progress_callback;
+}
+
+/**
+ * fastboot_boot() - Execute fastboot boot command
+ *
+ * If ${fastboot_bootcmd} is set, run that command to execute the boot
+ * process, if that returns, then exit the fastboot server and return
+ * control to the caller.
+ *
+ * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
+ * the board.
+ */
+void fastboot_boot(void)
+{
+       char *s;
+
+       s = env_get("fastboot_bootcmd");
+       if (s) {
+               run_command(s, CMD_FLAG_ENV);
+       } else {
+               static char boot_addr_start[12];
+               static char *const bootm_args[] = {
+                       "bootm", boot_addr_start, NULL
+               };
+
+               snprintf(boot_addr_start, sizeof(boot_addr_start) - 1,
+                        "0x%p", fastboot_buf_addr);
+               printf("Booting kernel at %s...\n\n\n", boot_addr_start);
+
+               do_bootm(NULL, 0, 2, bootm_args);
+
+               /*
+                * This only happens if image is somehow faulty so we start
+                * over. We deliberately leave this policy to the invocation
+                * of fastbootcmd if that's what's being run
+                */
+               do_reset(NULL, 0, 0, NULL);
+       }
+}
+
+/**
+ * fastboot_set_progress_callback() - set progress callback
+ *
+ * @progress: Pointer to progress callback
+ *
+ * Set a callback which is invoked periodically during long running operations
+ * (flash and erase). This can be used (for example) by the UDP transport to
+ * send INFO responses to keep the client alive whilst those commands are
+ * executing.
+ */
+void fastboot_set_progress_callback(void (*progress)(const char *msg))
+{
+       fastboot_progress_callback = progress;
+}
+
+/*
+ * fastboot_init() - initialise new fastboot protocol session
+ *
+ * @buf_addr: Pointer to download buffer, or NULL for default
+ * @buf_size: Size of download buffer, or zero for default
+ */
+void fastboot_init(void *buf_addr, u32 buf_size)
+{
+       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
new file mode 100644 (file)
index 0000000..4d264c9
--- /dev/null
@@ -0,0 +1,230 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ */
+
+#include <common.h>
+#include <fastboot.h>
+#include <fastboot-internal.h>
+#include <fb_mmc.h>
+#include <fb_nand.h>
+#include <fs.h>
+#include <version.h>
+
+static void getvar_version(char *var_parameter, char *response);
+static void getvar_bootloader_version(char *var_parameter, char *response);
+static void getvar_downloadsize(char *var_parameter, char *response);
+static void getvar_serialno(char *var_parameter, char *response);
+static void getvar_version_baseband(char *var_parameter, char *response);
+static void getvar_product(char *var_parameter, char *response);
+static void getvar_current_slot(char *var_parameter, char *response);
+static void getvar_slot_suffixes(char *var_parameter, char *response);
+static void getvar_has_slot(char *var_parameter, char *response);
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+static void getvar_partition_type(char *part_name, char *response);
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+static void getvar_partition_size(char *part_name, char *response);
+#endif
+
+static const struct {
+       const char *variable;
+       void (*dispatch)(char *var_parameter, char *response);
+} getvar_dispatch[] = {
+       {
+               .variable = "version",
+               .dispatch = getvar_version
+       }, {
+               .variable = "bootloader-version",
+               .dispatch = getvar_bootloader_version
+       }, {
+               .variable = "version-bootloader",
+               .dispatch = getvar_bootloader_version
+       }, {
+               .variable = "downloadsize",
+               .dispatch = getvar_downloadsize
+       }, {
+               .variable = "max-download-size",
+               .dispatch = getvar_downloadsize
+       }, {
+               .variable = "serialno",
+               .dispatch = getvar_serialno
+       }, {
+               .variable = "version-baseband",
+               .dispatch = getvar_version_baseband
+       }, {
+               .variable = "product",
+               .dispatch = getvar_product
+       }, {
+               .variable = "current-slot",
+               .dispatch = getvar_current_slot
+       }, {
+               .variable = "slot-suffixes",
+               .dispatch = getvar_slot_suffixes
+       }, {
+               .variable = "has_slot",
+               .dispatch = getvar_has_slot
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+       }, {
+               .variable = "partition-type",
+               .dispatch = getvar_partition_type
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+       }, {
+               .variable = "partition-size",
+               .dispatch = getvar_partition_size
+#endif
+       }
+};
+
+static void getvar_version(char *var_parameter, char *response)
+{
+       fastboot_okay(FASTBOOT_VERSION, response);
+}
+
+static void getvar_bootloader_version(char *var_parameter, char *response)
+{
+       fastboot_okay(U_BOOT_VERSION, response);
+}
+
+static void getvar_downloadsize(char *var_parameter, char *response)
+{
+       fastboot_response("OKAY", response, "0x%08x", fastboot_buf_size);
+}
+
+static void getvar_serialno(char *var_parameter, char *response)
+{
+       const char *tmp = env_get("serial#");
+
+       if (tmp)
+               fastboot_okay(tmp, response);
+       else
+               fastboot_fail("Value not set", response);
+}
+
+static void getvar_version_baseband(char *var_parameter, char *response)
+{
+       fastboot_okay("N/A", response);
+}
+
+static void getvar_product(char *var_parameter, char *response)
+{
+       const char *board = env_get("board");
+
+       if (board)
+               fastboot_okay(board, response);
+       else
+               fastboot_fail("Board not set", response);
+}
+
+static void getvar_current_slot(char *var_parameter, char *response)
+{
+       /* A/B not implemented, for now always return _a */
+       fastboot_okay("_a", response);
+}
+
+static void getvar_slot_suffixes(char *var_parameter, char *response)
+{
+       fastboot_okay("_a,_b", response);
+}
+
+static void getvar_has_slot(char *part_name, char *response)
+{
+       if (part_name && (!strcmp(part_name, "boot") ||
+                         !strcmp(part_name, "system")))
+               fastboot_okay("yes", response);
+       else
+               fastboot_okay("no", response);
+}
+
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+static void getvar_partition_type(char *part_name, char *response)
+{
+       int r;
+       struct blk_desc *dev_desc;
+       disk_partition_t part_info;
+
+       r = fastboot_mmc_get_part_info(part_name, &dev_desc, &part_info,
+                                      response);
+       if (r >= 0) {
+               r = fs_set_blk_dev_with_part(dev_desc, r);
+               if (r < 0)
+                       fastboot_fail("failed to set partition", response);
+               else
+                       fastboot_okay(fs_get_type_name(), response);
+       }
+}
+#endif
+
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+static void getvar_partition_size(char *part_name, char *response)
+{
+       int r;
+       size_t size;
+
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+       struct blk_desc *dev_desc;
+       disk_partition_t part_info;
+
+       r = fastboot_mmc_get_part_info(part_name, &dev_desc, &part_info,
+                                      response);
+       if (r >= 0)
+               size = part_info.size;
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
+       struct part_info *part_info;
+
+       r = fastboot_nand_get_part_info(part_name, &part_info, response);
+       if (r >= 0)
+               size = part_info->size;
+#endif
+       if (r >= 0)
+               fastboot_response("OKAY", response, "0x%016zx", size);
+}
+#endif
+
+/**
+ * fastboot_getvar() - Writes variable indicated by cmd_parameter to response.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ *
+ * Look up cmd_parameter first as an environment variable of the form
+ * fastboot.<cmd_parameter>, if that exists return use its value to set
+ * response.
+ *
+ * Otherwise lookup the name of variable and execute the appropriate
+ * function to return the requested value.
+ */
+void fastboot_getvar(char *cmd_parameter, char *response)
+{
+       if (!cmd_parameter) {
+               fastboot_fail("missing var", response);
+       } else {
+#define FASTBOOT_ENV_PREFIX    "fastboot."
+               int i;
+               char *var_parameter = cmd_parameter;
+               char envstr[FASTBOOT_RESPONSE_LEN];
+               const char *s;
+
+               snprintf(envstr, sizeof(envstr) - 1,
+                        FASTBOOT_ENV_PREFIX "%s", cmd_parameter);
+               s = env_get(envstr);
+               if (s) {
+                       fastboot_response("OKAY", response, "%s", s);
+                       return;
+               }
+
+               strsep(&var_parameter, ":");
+               for (i = 0; i < ARRAY_SIZE(getvar_dispatch); ++i) {
+                       if (!strcmp(getvar_dispatch[i].variable,
+                                   cmd_parameter)) {
+                               getvar_dispatch[i].dispatch(var_parameter,
+                                                           response);
+                               return;
+                       }
+               }
+               pr_warn("WARNING: unknown variable: %s\n", cmd_parameter);
+               fastboot_fail("Variable not implemented", response);
+       }
+}
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
new file mode 100644 (file)
index 0000000..4c1c7fd
--- /dev/null
@@ -0,0 +1,488 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2014 Broadcom Corporation.
+ */
+
+#include <config.h>
+#include <common.h>
+#include <blk.h>
+#include <fastboot.h>
+#include <fastboot-internal.h>
+#include <fb_mmc.h>
+#include <image-sparse.h>
+#include <part.h>
+#include <mmc.h>
+#include <div64.h>
+#include <linux/compat.h>
+#include <android_image.h>
+
+#define FASTBOOT_MAX_BLK_WRITE 16384
+
+#define BOOT_PARTITION_NAME "boot"
+
+struct fb_mmc_sparse {
+       struct blk_desc *dev_desc;
+};
+
+static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
+               const char *name, disk_partition_t *info)
+{
+       int ret;
+
+       ret = part_get_info_by_name(dev_desc, name, info);
+       if (ret < 0) {
+               /* strlen("fastboot_partition_alias_") + 32(part_name) + 1 */
+               char env_alias_name[25 + 32 + 1];
+               char *aliased_part_name;
+
+               /* check for alias */
+               strcpy(env_alias_name, "fastboot_partition_alias_");
+               strncat(env_alias_name, name, 32);
+               aliased_part_name = env_get(env_alias_name);
+               if (aliased_part_name != NULL)
+                       ret = part_get_info_by_name(dev_desc,
+                                       aliased_part_name, info);
+       }
+       return ret;
+}
+
+/**
+ * fb_mmc_blk_write() - Write/erase MMC in chunks of FASTBOOT_MAX_BLK_WRITE
+ *
+ * @block_dev: Pointer to block device
+ * @start: First block to write/erase
+ * @blkcnt: Count of blocks
+ * @buffer: Pointer to data buffer for write or NULL for erase
+ */
+static lbaint_t fb_mmc_blk_write(struct blk_desc *block_dev, lbaint_t start,
+                                lbaint_t blkcnt, const void *buffer)
+{
+       lbaint_t blk = start;
+       lbaint_t blks_written;
+       lbaint_t cur_blkcnt;
+       lbaint_t blks = 0;
+       int i;
+
+       for (i = 0; i < blkcnt; i += FASTBOOT_MAX_BLK_WRITE) {
+               cur_blkcnt = min((int)blkcnt - i, FASTBOOT_MAX_BLK_WRITE);
+               if (buffer) {
+                       if (fastboot_progress_callback)
+                               fastboot_progress_callback("writing");
+                       blks_written = blk_dwrite(block_dev, blk, cur_blkcnt,
+                                                 buffer + (i * block_dev->blksz));
+               } else {
+                       if (fastboot_progress_callback)
+                               fastboot_progress_callback("erasing");
+                       blks_written = blk_derase(block_dev, blk, cur_blkcnt);
+               }
+               blk += blks_written;
+               blks += blks_written;
+       }
+       return blks;
+}
+
+static lbaint_t fb_mmc_sparse_write(struct sparse_storage *info,
+               lbaint_t blk, lbaint_t blkcnt, const void *buffer)
+{
+       struct fb_mmc_sparse *sparse = info->priv;
+       struct blk_desc *dev_desc = sparse->dev_desc;
+
+       return fb_mmc_blk_write(dev_desc, blk, blkcnt, buffer);
+}
+
+static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
+               lbaint_t blk, lbaint_t blkcnt)
+{
+       return blkcnt;
+}
+
+static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
+               const char *part_name, void *buffer,
+               u32 download_bytes, char *response)
+{
+       lbaint_t blkcnt;
+       lbaint_t blks;
+
+       /* determine number of blocks to write */
+       blkcnt = ((download_bytes + (info->blksz - 1)) & ~(info->blksz - 1));
+       blkcnt = lldiv(blkcnt, info->blksz);
+
+       if (blkcnt > info->size) {
+               pr_err("too large for partition: '%s'\n", part_name);
+               fastboot_fail("too large for partition", response);
+               return;
+       }
+
+       puts("Flashing Raw Image\n");
+
+       blks = fb_mmc_blk_write(dev_desc, info->start, blkcnt, buffer);
+
+       if (blks != blkcnt) {
+               pr_err("failed writing to device %d\n", dev_desc->devnum);
+               fastboot_fail("failed writing to device", response);
+               return;
+       }
+
+       printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
+              part_name);
+       fastboot_okay(NULL, response);
+}
+
+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+/**
+ * Read Android boot image header from boot partition.
+ *
+ * @param[in] dev_desc MMC device descriptor
+ * @param[in] info Boot partition info
+ * @param[out] hdr Where to store read boot image header
+ *
+ * @return Boot image header sectors count or 0 on error
+ */
+static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
+                                      disk_partition_t *info,
+                                      struct andr_img_hdr *hdr,
+                                      char *response)
+{
+       ulong sector_size;              /* boot partition sector size */
+       lbaint_t hdr_sectors;           /* boot image header sectors count */
+       int res;
+
+       /* Calculate boot image sectors count */
+       sector_size = info->blksz;
+       hdr_sectors = DIV_ROUND_UP(sizeof(struct andr_img_hdr), sector_size);
+       if (hdr_sectors == 0) {
+               pr_err("invalid number of boot sectors: 0\n");
+               fastboot_fail("invalid number of boot sectors: 0", response);
+               return 0;
+       }
+
+       /* Read the boot image header */
+       res = blk_dread(dev_desc, info->start, hdr_sectors, (void *)hdr);
+       if (res != hdr_sectors) {
+               pr_err("cannot read header from boot partition\n");
+               fastboot_fail("cannot read header from boot partition",
+                             response);
+               return 0;
+       }
+
+       /* Check boot header magic string */
+       res = android_image_check_header(hdr);
+       if (res != 0) {
+               pr_err("bad boot image magic\n");
+               fastboot_fail("boot partition not initialized", response);
+               return 0;
+       }
+
+       return hdr_sectors;
+}
+
+/**
+ * Write downloaded zImage to boot partition and repack it properly.
+ *
+ * @param dev_desc MMC device descriptor
+ * @param download_buffer Address to fastboot buffer with zImage in it
+ * @param download_bytes Size of fastboot buffer, in bytes
+ *
+ * @return 0 on success or -1 on error
+ */
+static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
+                               void *download_buffer,
+                               u32 download_bytes,
+                               char *response)
+{
+       uintptr_t hdr_addr;                     /* boot image header address */
+       struct andr_img_hdr *hdr;               /* boot image header */
+       lbaint_t hdr_sectors;                   /* boot image header sectors */
+       u8 *ramdisk_buffer;
+       u32 ramdisk_sector_start;
+       u32 ramdisk_sectors;
+       u32 kernel_sector_start;
+       u32 kernel_sectors;
+       u32 sectors_per_page;
+       disk_partition_t info;
+       int res;
+
+       puts("Flashing zImage\n");
+
+       /* Get boot partition info */
+       res = part_get_info_by_name(dev_desc, BOOT_PARTITION_NAME, &info);
+       if (res < 0) {
+               pr_err("cannot find boot partition\n");
+               fastboot_fail("cannot find boot partition", response);
+               return -1;
+       }
+
+       /* Put boot image header in fastboot buffer after downloaded zImage */
+       hdr_addr = (uintptr_t)download_buffer + ALIGN(download_bytes, PAGE_SIZE);
+       hdr = (struct andr_img_hdr *)hdr_addr;
+
+       /* Read boot image header */
+       hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
+       if (hdr_sectors == 0) {
+               pr_err("unable to read boot image header\n");
+               fastboot_fail("unable to read boot image header", response);
+               return -1;
+       }
+
+       /* Check if boot image has second stage in it (we don't support it) */
+       if (hdr->second_size > 0) {
+               pr_err("moving second stage is not supported yet\n");
+               fastboot_fail("moving second stage is not supported yet",
+                             response);
+               return -1;
+       }
+
+       /* Extract ramdisk location */
+       sectors_per_page = hdr->page_size / info.blksz;
+       ramdisk_sector_start = info.start + sectors_per_page;
+       ramdisk_sector_start += DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) *
+                                            sectors_per_page;
+       ramdisk_sectors = DIV_ROUND_UP(hdr->ramdisk_size, hdr->page_size) *
+                                      sectors_per_page;
+
+       /* Read ramdisk and put it in fastboot buffer after boot image header */
+       ramdisk_buffer = (u8 *)hdr + (hdr_sectors * info.blksz);
+       res = blk_dread(dev_desc, ramdisk_sector_start, ramdisk_sectors,
+                       ramdisk_buffer);
+       if (res != ramdisk_sectors) {
+               pr_err("cannot read ramdisk from boot partition\n");
+               fastboot_fail("cannot read ramdisk from boot partition",
+                             response);
+               return -1;
+       }
+
+       /* Write new kernel size to boot image header */
+       hdr->kernel_size = download_bytes;
+       res = blk_dwrite(dev_desc, info.start, hdr_sectors, (void *)hdr);
+       if (res == 0) {
+               pr_err("cannot writeback boot image header\n");
+               fastboot_fail("cannot write back boot image header", response);
+               return -1;
+       }
+
+       /* Write the new downloaded kernel */
+       kernel_sector_start = info.start + sectors_per_page;
+       kernel_sectors = DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) *
+                                     sectors_per_page;
+       res = blk_dwrite(dev_desc, kernel_sector_start, kernel_sectors,
+                        download_buffer);
+       if (res == 0) {
+               pr_err("cannot write new kernel\n");
+               fastboot_fail("cannot write new kernel", response);
+               return -1;
+       }
+
+       /* Write the saved ramdisk back */
+       ramdisk_sector_start = info.start + sectors_per_page;
+       ramdisk_sector_start += DIV_ROUND_UP(hdr->kernel_size, hdr->page_size) *
+                                            sectors_per_page;
+       res = blk_dwrite(dev_desc, ramdisk_sector_start, ramdisk_sectors,
+                        ramdisk_buffer);
+       if (res == 0) {
+               pr_err("cannot write back original ramdisk\n");
+               fastboot_fail("cannot write back original ramdisk", response);
+               return -1;
+       }
+
+       puts("........ zImage was updated in boot partition\n");
+       fastboot_okay(NULL, response);
+       return 0;
+}
+#endif
+
+/**
+ * fastboot_mmc_get_part_info() - Lookup eMMC partion by name
+ *
+ * @part_name: Named partition to lookup
+ * @dev_desc: Pointer to returned blk_desc pointer
+ * @part_info: Pointer to returned disk_partition_t
+ * @response: Pointer to fastboot response buffer
+ */
+int fastboot_mmc_get_part_info(char *part_name, struct blk_desc **dev_desc,
+                              disk_partition_t *part_info, char *response)
+{
+       int r;
+
+       *dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
+       if (!*dev_desc) {
+               fastboot_fail("block device not found", response);
+               return -ENOENT;
+       }
+       if (!part_name) {
+               fastboot_fail("partition not found", response);
+               return -ENOENT;
+       }
+
+       r = part_get_info_by_name_or_alias(*dev_desc, part_name, part_info);
+       if (r < 0) {
+               fastboot_fail("partition not found", response);
+               return r;
+       }
+
+       return r;
+}
+
+/**
+ * fastboot_mmc_flash_write() - Write image to eMMC for fastboot
+ *
+ * @cmd: Named partition to write image to
+ * @download_buffer: Pointer to image data
+ * @download_bytes: Size of image data
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_mmc_flash_write(const char *cmd, void *download_buffer,
+                             u32 download_bytes, char *response)
+{
+       struct blk_desc *dev_desc;
+       disk_partition_t info;
+
+       dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
+       if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
+               pr_err("invalid mmc device\n");
+               fastboot_fail("invalid mmc device", response);
+               return;
+       }
+
+#if CONFIG_IS_ENABLED(EFI_PARTITION)
+       if (strcmp(cmd, CONFIG_FASTBOOT_GPT_NAME) == 0) {
+               printf("%s: updating MBR, Primary and Backup GPT(s)\n",
+                      __func__);
+               if (is_valid_gpt_buf(dev_desc, download_buffer)) {
+                       printf("%s: invalid GPT - refusing to write to flash\n",
+                              __func__);
+                       fastboot_fail("invalid GPT partition", response);
+                       return;
+               }
+               if (write_mbr_and_gpt_partitions(dev_desc, download_buffer)) {
+                       printf("%s: writing GPT partitions failed\n", __func__);
+                       fastboot_fail("writing GPT partitions failed",
+                                     response);
+                       return;
+               }
+               printf("........ success\n");
+               fastboot_okay(NULL, response);
+               return;
+       }
+#endif
+
+#if CONFIG_IS_ENABLED(DOS_PARTITION)
+       if (strcmp(cmd, CONFIG_FASTBOOT_MBR_NAME) == 0) {
+               printf("%s: updating MBR\n", __func__);
+               if (is_valid_dos_buf(download_buffer)) {
+                       printf("%s: invalid MBR - refusing to write to flash\n",
+                              __func__);
+                       fastboot_fail("invalid MBR partition", response);
+                       return;
+               }
+               if (write_mbr_partition(dev_desc, download_buffer)) {
+                       printf("%s: writing MBR partition failed\n", __func__);
+                       fastboot_fail("writing MBR partition failed",
+                                     response);
+                       return;
+               }
+               printf("........ success\n");
+               fastboot_okay(NULL, response);
+               return;
+       }
+#endif
+
+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+       if (strncasecmp(cmd, "zimage", 6) == 0) {
+               fb_mmc_update_zimage(dev_desc, download_buffer,
+                                    download_bytes, response);
+               return;
+       }
+#endif
+
+       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;
+       }
+
+       if (is_sparse_image(download_buffer)) {
+               struct fb_mmc_sparse sparse_priv;
+               struct sparse_storage sparse;
+               int err;
+
+               sparse_priv.dev_desc = dev_desc;
+
+               sparse.blksz = info.blksz;
+               sparse.start = info.start;
+               sparse.size = info.size;
+               sparse.write = fb_mmc_sparse_write;
+               sparse.reserve = fb_mmc_sparse_reserve;
+               sparse.mssg = fastboot_fail;
+
+               printf("Flashing sparse image at offset " LBAFU "\n",
+                      sparse.start);
+
+               sparse.priv = &sparse_priv;
+               err = write_sparse_image(&sparse, cmd, download_buffer,
+                                        response);
+               if (!err)
+                       fastboot_okay(NULL, response);
+       } else {
+               write_raw_image(dev_desc, &info, cmd, download_buffer,
+                               download_bytes, response);
+       }
+}
+
+/**
+ * fastboot_mmc_flash_erase() - Erase eMMC for fastboot
+ *
+ * @cmd: Named partition to erase
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_mmc_erase(const char *cmd, char *response)
+{
+       int ret;
+       struct blk_desc *dev_desc;
+       disk_partition_t info;
+       lbaint_t blks, blks_start, blks_size, grp_size;
+       struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
+
+       if (mmc == NULL) {
+               pr_err("invalid mmc device\n");
+               fastboot_fail("invalid mmc device", response);
+               return;
+       }
+
+       dev_desc = blk_get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV);
+       if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) {
+               pr_err("invalid mmc device\n");
+               fastboot_fail("invalid mmc device", response);
+               return;
+       }
+
+       ret = part_get_info_by_name_or_alias(dev_desc, cmd, &info);
+       if (ret < 0) {
+               pr_err("cannot find partition: '%s'\n", cmd);
+               fastboot_fail("cannot find partition", response);
+               return;
+       }
+
+       /* Align blocks to erase group size to avoid erasing other partitions */
+       grp_size = mmc->erase_grp_size;
+       blks_start = (info.start + grp_size - 1) & ~(grp_size - 1);
+       if (info.size >= grp_size)
+               blks_size = (info.size - (blks_start - info.start)) &
+                               (~(grp_size - 1));
+       else
+               blks_size = 0;
+
+       printf("Erasing blocks " LBAFU " to " LBAFU " due to alignment\n",
+              blks_start, blks_start + blks_size);
+
+       blks = fb_mmc_blk_write(dev_desc, blks_start, blks_size, NULL);
+
+       if (blks != blks_size) {
+               pr_err("failed erasing from device %d\n", dev_desc->devnum);
+               fastboot_fail("failed erasing from device", response);
+               return;
+       }
+
+       printf("........ erased " LBAFU " bytes from '%s'\n",
+              blks_size * info.blksz, cmd);
+       fastboot_okay(NULL, response);
+}
diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
new file mode 100644 (file)
index 0000000..526bc12
--- /dev/null
@@ -0,0 +1,261 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2014 Broadcom Corporation.
+ * Copyright 2015 Free Electrons.
+ */
+
+#include <config.h>
+#include <common.h>
+
+#include <fastboot.h>
+#include <image-sparse.h>
+
+#include <linux/mtd/mtd.h>
+#include <jffs2/jffs2.h>
+#include <nand.h>
+
+struct fb_nand_sparse {
+       struct mtd_info         *mtd;
+       struct part_info        *part;
+};
+
+__weak int board_fastboot_erase_partition_setup(char *name)
+{
+       return 0;
+}
+
+__weak int board_fastboot_write_partition_setup(char *name)
+{
+       return 0;
+}
+
+static int fb_nand_lookup(const char *partname,
+                         struct mtd_info **mtd,
+                         struct part_info **part,
+                         char *response)
+{
+       struct mtd_device *dev;
+       int ret;
+       u8 pnum;
+
+       ret = mtdparts_init();
+       if (ret) {
+               pr_err("Cannot initialize MTD partitions\n");
+               fastboot_fail("cannot init mtdparts", response);
+               return ret;
+       }
+
+       ret = find_dev_and_part(partname, &dev, &pnum, part);
+       if (ret) {
+               pr_err("cannot find partition: '%s'", partname);
+               fastboot_fail("cannot find partition", response);
+               return ret;
+       }
+
+       if (dev->id->type != MTD_DEV_TYPE_NAND) {
+               pr_err("partition '%s' is not stored on a NAND device",
+                     partname);
+               fastboot_fail("not a NAND device", response);
+               return -EINVAL;
+       }
+
+       *mtd = get_nand_dev_by_index(dev->id->num);
+
+       return 0;
+}
+
+static int _fb_nand_erase(struct mtd_info *mtd, struct part_info *part)
+{
+       nand_erase_options_t opts;
+       int ret;
+
+       memset(&opts, 0, sizeof(opts));
+       opts.offset = part->offset;
+       opts.length = part->size;
+       opts.quiet = 1;
+
+       printf("Erasing blocks 0x%llx to 0x%llx\n",
+              part->offset, part->offset + part->size);
+
+       ret = nand_erase_opts(mtd, &opts);
+       if (ret)
+               return ret;
+
+       printf("........ erased 0x%llx bytes from '%s'\n",
+              part->size, part->name);
+
+       return 0;
+}
+
+static int _fb_nand_write(struct mtd_info *mtd, struct part_info *part,
+                         void *buffer, u32 offset,
+                         size_t length, size_t *written)
+{
+       int flags = WITH_WR_VERIFY;
+
+#ifdef CONFIG_FASTBOOT_FLASH_NAND_TRIMFFS
+       flags |= WITH_DROP_FFS;
+#endif
+
+       return nand_write_skip_bad(mtd, offset, &length, written,
+                                  part->size - (offset - part->offset),
+                                  buffer, flags);
+}
+
+static lbaint_t fb_nand_sparse_write(struct sparse_storage *info,
+               lbaint_t blk, lbaint_t blkcnt, const void *buffer)
+{
+       struct fb_nand_sparse *sparse = info->priv;
+       size_t written;
+       int ret;
+
+       ret = _fb_nand_write(sparse->mtd, sparse->part, (void *)buffer,
+                            blk * info->blksz,
+                            blkcnt * info->blksz, &written);
+       if (ret < 0) {
+               printf("Failed to write sparse chunk\n");
+               return ret;
+       }
+
+/* TODO - verify that the value "written" includes the "bad-blocks" ... */
+
+       /*
+        * the return value must be 'blkcnt' ("good-blocks") plus the
+        * number of "bad-blocks" encountered within this space...
+        */
+       return written / info->blksz;
+}
+
+static lbaint_t fb_nand_sparse_reserve(struct sparse_storage *info,
+               lbaint_t blk, lbaint_t blkcnt)
+{
+       int bad_blocks = 0;
+
+/*
+ * TODO - implement a function to determine the total number
+ * of blocks which must be used in order to reserve the specified
+ * number ("blkcnt") of "good-blocks", starting at "blk"...
+ * ( possibly something like the "check_skip_len()" function )
+ */
+
+       /*
+        * the return value must be 'blkcnt' ("good-blocks") plus the
+        * number of "bad-blocks" encountered within this space...
+        */
+       return blkcnt + bad_blocks;
+}
+
+/**
+ * fastboot_nand_get_part_info() - Lookup NAND partion by name
+ *
+ * @part_name: Named device to lookup
+ * @part_info: Pointer to returned part_info pointer
+ * @response: Pointer to fastboot response buffer
+ */
+int fastboot_nand_get_part_info(char *part_name, struct part_info **part_info,
+                               char *response)
+{
+       struct mtd_info *mtd = NULL;
+
+       return fb_nand_lookup(part_name, &mtd, part_info, response);
+}
+
+/**
+ * fastboot_nand_flash_write() - Write image to NAND for fastboot
+ *
+ * @cmd: Named device to write image to
+ * @download_buffer: Pointer to image data
+ * @download_bytes: Size of image data
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_nand_flash_write(const char *cmd, void *download_buffer,
+                              u32 download_bytes, char *response)
+{
+       struct part_info *part;
+       struct mtd_info *mtd = NULL;
+       int ret;
+
+       ret = fb_nand_lookup(cmd, &mtd, &part, response);
+       if (ret) {
+               pr_err("invalid NAND device");
+               fastboot_fail("invalid NAND device", response);
+               return;
+       }
+
+       ret = board_fastboot_write_partition_setup(part->name);
+       if (ret)
+               return;
+
+       if (is_sparse_image(download_buffer)) {
+               struct fb_nand_sparse sparse_priv;
+               struct sparse_storage sparse;
+
+               sparse_priv.mtd = mtd;
+               sparse_priv.part = part;
+
+               sparse.blksz = mtd->writesize;
+               sparse.start = part->offset / sparse.blksz;
+               sparse.size = part->size / sparse.blksz;
+               sparse.write = fb_nand_sparse_write;
+               sparse.reserve = fb_nand_sparse_reserve;
+               sparse.mssg = fastboot_fail;
+
+               printf("Flashing sparse image at offset " LBAFU "\n",
+                      sparse.start);
+
+               sparse.priv = &sparse_priv;
+               ret = write_sparse_image(&sparse, cmd, download_buffer,
+                                        response);
+               if (!ret)
+                       fastboot_okay(NULL, response);
+       } else {
+               printf("Flashing raw image at offset 0x%llx\n",
+                      part->offset);
+
+               ret = _fb_nand_write(mtd, part, download_buffer, part->offset,
+                                    download_bytes, NULL);
+
+               printf("........ wrote %u bytes to '%s'\n",
+                      download_bytes, part->name);
+       }
+
+       if (ret) {
+               fastboot_fail("error writing the image", response);
+               return;
+       }
+
+       fastboot_okay(NULL, response);
+}
+
+/**
+ * fastboot_nand_flash_erase() - Erase NAND for fastboot
+ *
+ * @cmd: Named device to erase
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_nand_erase(const char *cmd, char *response)
+{
+       struct part_info *part;
+       struct mtd_info *mtd = NULL;
+       int ret;
+
+       ret = fb_nand_lookup(cmd, &mtd, &part, response);
+       if (ret) {
+               pr_err("invalid NAND device");
+               fastboot_fail("invalid NAND device", response);
+               return;
+       }
+
+       ret = board_fastboot_erase_partition_setup(part->name);
+       if (ret)
+               return;
+
+       ret = _fb_nand_erase(mtd, part);
+       if (ret) {
+               pr_err("failed erasing from device %s", mtd->name);
+               fastboot_fail("failed erasing from device", response);
+               return;
+       }
+
+       fastboot_okay(NULL, response);
+}
index 3acadae8b170b80ef157e12b40ef0671f2244500..3ad4346f2d099b77a243dc88394b24f409408473 100644 (file)
 #include <linux/usb/gadget.h>
 #include <linux/usb/composite.h>
 #include <linux/compiler.h>
-#include <version.h>
 #include <g_dnl.h>
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-#include <fb_mmc.h>
-#endif
-#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
-#include <fb_nand.h>
-#endif
-
-#define FASTBOOT_VERSION               "0.4"
 
 #define FASTBOOT_INTERFACE_CLASS       0xff
 #define FASTBOOT_INTERFACE_SUB_CLASS   0x42
@@ -58,8 +49,6 @@ static inline struct f_fastboot *func_to_fastboot(struct usb_function *f)
 }
 
 static struct f_fastboot *fastboot_func;
-static unsigned int download_size;
-static unsigned int download_bytes;
 
 static struct usb_endpoint_descriptor fs_ep_in = {
        .bLength            = USB_DT_ENDPOINT_SIZE,
@@ -147,22 +136,6 @@ static struct usb_gadget_strings *fastboot_strings[] = {
 };
 
 static void rx_handler_command(struct usb_ep *ep, struct usb_request *req);
-static int strcmp_l1(const char *s1, const char *s2);
-
-
-static char *fb_response_str;
-
-void fastboot_fail(const char *reason)
-{
-       strncpy(fb_response_str, "FAIL\0", 5);
-       strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
-}
-
-void fastboot_okay(const char *reason)
-{
-       strncpy(fb_response_str, "OKAY\0", 5);
-       strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
-}
 
 static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -372,90 +345,9 @@ static void compl_do_reset(struct usb_ep *ep, struct usb_request *req)
        do_reset(NULL, 0, 0, NULL);
 }
 
-int __weak fb_set_reboot_flag(void)
-{
-       return -ENOSYS;
-}
-
-static void cb_reboot(struct usb_ep *ep, struct usb_request *req)
-{
-       char *cmd = req->buf;
-       if (!strcmp_l1("reboot-bootloader", cmd)) {
-               if (fb_set_reboot_flag()) {
-                       fastboot_tx_write_str("FAILCannot set reboot flag");
-                       return;
-               }
-       }
-       fastboot_func->in_req->complete = compl_do_reset;
-       fastboot_tx_write_str("OKAY");
-}
-
-static int strcmp_l1(const char *s1, const char *s2)
-{
-       if (!s1 || !s2)
-               return -1;
-       return strncmp(s1, s2, strlen(s1));
-}
-
-static void cb_getvar(struct usb_ep *ep, struct usb_request *req)
-{
-       char *cmd = req->buf;
-       char response[FASTBOOT_RESPONSE_LEN];
-       const char *s;
-       size_t chars_left;
-
-       strcpy(response, "OKAY");
-       chars_left = sizeof(response) - strlen(response) - 1;
-
-       strsep(&cmd, ":");
-       if (!cmd) {
-               pr_err("missing variable");
-               fastboot_tx_write_str("FAILmissing var");
-               return;
-       }
-
-       if (!strcmp_l1("version", cmd)) {
-               strncat(response, FASTBOOT_VERSION, chars_left);
-       } else if (!strcmp_l1("bootloader-version", cmd)) {
-               strncat(response, U_BOOT_VERSION, chars_left);
-       } else if (!strcmp_l1("downloadsize", cmd) ||
-               !strcmp_l1("max-download-size", cmd)) {
-               char str_num[12];
-
-               sprintf(str_num, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
-               strncat(response, str_num, chars_left);
-       } else if (!strcmp_l1("serialno", cmd)) {
-               s = env_get("serial#");
-               if (s)
-                       strncat(response, s, chars_left);
-               else
-                       strcpy(response, "FAILValue not set");
-       } else {
-               char *envstr;
-
-               envstr = malloc(strlen("fastboot.") + strlen(cmd) + 1);
-               if (!envstr) {
-                       fastboot_tx_write_str("FAILmalloc error");
-                       return;
-               }
-
-               sprintf(envstr, "fastboot.%s", cmd);
-               s = env_get(envstr);
-               if (s) {
-                       strncat(response, s, chars_left);
-               } else {
-                       printf("WARNING: unknown variable: %s\n", cmd);
-                       strcpy(response, "FAILVariable not implemented");
-               }
-
-               free(envstr);
-       }
-       fastboot_tx_write_str(response);
-}
-
 static unsigned int rx_bytes_expected(struct usb_ep *ep)
 {
-       int rx_remain = download_size - download_bytes;
+       int rx_remain = fastboot_data_remaining();
        unsigned int rem;
        unsigned int maxpacket = ep->maxpacket;
 
@@ -477,14 +369,12 @@ static unsigned int rx_bytes_expected(struct usb_ep *ep)
        return rx_remain;
 }
 
-#define BYTES_PER_DOT  0x20000
 static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
 {
-       char response[FASTBOOT_RESPONSE_LEN];
-       unsigned int transfer_size = download_size - download_bytes;
+       char response[FASTBOOT_RESPONSE_LEN] = {0};
+       unsigned int transfer_size = fastboot_data_remaining();
        const unsigned char *buffer = req->buf;
        unsigned int buffer_size = req->actual;
-       unsigned int pre_dot_num, now_dot_num;
 
        if (req->status != 0) {
                printf("Bad status: %d\n", req->status);
@@ -494,33 +384,19 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
        if (buffer_size < transfer_size)
                transfer_size = buffer_size;
 
-       memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + download_bytes,
-              buffer, transfer_size);
-
-       pre_dot_num = download_bytes / BYTES_PER_DOT;
-       download_bytes += transfer_size;
-       now_dot_num = download_bytes / BYTES_PER_DOT;
-
-       if (pre_dot_num != now_dot_num) {
-               putc('.');
-               if (!(now_dot_num % 74))
-                       putc('\n');
-       }
+       fastboot_data_download(buffer, transfer_size, response);
+       if (response[0]) {
+               fastboot_tx_write_str(response);
+       } else if (!fastboot_data_remaining()) {
+               fastboot_data_complete(response);
 
-       /* Check if transfer is done */
-       if (download_bytes >= download_size) {
                /*
-                * Reset global transfer variable, keep download_bytes because
-                * it will be used in the next possible flashing command
+                * Reset global transfer variable
                 */
-               download_size = 0;
                req->complete = rx_handler_command;
                req->length = EP_BUFFER_SIZE;
 
-               strcpy(response, "OKAY");
                fastboot_tx_write_str(response);
-
-               printf("\ndownloading of %d bytes finished\n", download_bytes);
        } else {
                req->length = rx_bytes_expected(ep);
        }
@@ -529,204 +405,55 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
        usb_ep_queue(ep, req, 0);
 }
 
-static void cb_download(struct usb_ep *ep, struct usb_request *req)
-{
-       char *cmd = req->buf;
-       char response[FASTBOOT_RESPONSE_LEN];
-
-       strsep(&cmd, ":");
-       download_size = simple_strtoul(cmd, NULL, 16);
-       download_bytes = 0;
-
-       printf("Starting download of %d bytes\n", download_size);
-
-       if (0 == download_size) {
-               strcpy(response, "FAILdata invalid size");
-       } else if (download_size > CONFIG_FASTBOOT_BUF_SIZE) {
-               download_size = 0;
-               strcpy(response, "FAILdata too large");
-       } else {
-               sprintf(response, "DATA%08x", download_size);
-               req->complete = rx_handler_dl_image;
-               req->length = rx_bytes_expected(ep);
-       }
-       fastboot_tx_write_str(response);
-}
-
-static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
-{
-       char boot_addr_start[12];
-       char *bootm_args[] = { "bootm", boot_addr_start, NULL };
-
-       puts("Booting kernel..\n");
-
-       sprintf(boot_addr_start, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
-       do_bootm(NULL, 0, 2, bootm_args);
-
-       /* This only happens if image is somehow faulty so we start over */
-       do_reset(NULL, 0, 0, NULL);
-}
-
-static void cb_boot(struct usb_ep *ep, struct usb_request *req)
-{
-       fastboot_func->in_req->complete = do_bootm_on_complete;
-       fastboot_tx_write_str("OKAY");
-}
-
 static void do_exit_on_complete(struct usb_ep *ep, struct usb_request *req)
 {
        g_dnl_trigger_detach();
 }
 
-static void cb_continue(struct usb_ep *ep, struct usb_request *req)
+static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
 {
-       fastboot_func->in_req->complete = do_exit_on_complete;
-       fastboot_tx_write_str("OKAY");
+       fastboot_boot();
+       do_exit_on_complete(ep, req);
 }
 
-#ifdef CONFIG_FASTBOOT_FLASH
-static void cb_flash(struct usb_ep *ep, struct usb_request *req)
+static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
 {
-       char *cmd = req->buf;
-       char response[FASTBOOT_RESPONSE_LEN];
+       char *cmdbuf = req->buf;
+       char response[FASTBOOT_RESPONSE_LEN] = {0};
+       int cmd = -1;
 
-       strsep(&cmd, ":");
-       if (!cmd) {
-               pr_err("missing partition name");
-               fastboot_tx_write_str("FAILmissing partition name");
+       if (req->status != 0 || req->length == 0)
                return;
-       }
-
-       /* initialize the response buffer */
-       fb_response_str = response;
-
-       fastboot_fail("no flash device defined");
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-       fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
-                          download_bytes);
-#endif
-#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
-       fb_nand_flash_write(cmd,
-                           (void *)CONFIG_FASTBOOT_BUF_ADDR,
-                           download_bytes);
-#endif
-       fastboot_tx_write_str(response);
-}
-#endif
 
-static void cb_oem(struct usb_ep *ep, struct usb_request *req)
-{
-       char *cmd = req->buf;
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-       if (strncmp("format", cmd + 4, 6) == 0) {
-               char cmdbuf[32];
-                sprintf(cmdbuf, "gpt write mmc %x $partitions",
-                       CONFIG_FASTBOOT_FLASH_MMC_DEV);
-                if (run_command(cmdbuf, 0))
-                       fastboot_tx_write_str("FAIL");
-                else
-                       fastboot_tx_write_str("OKAY");
-       } else
-#endif
-       if (strncmp("unlock", cmd + 4, 8) == 0) {
-               fastboot_tx_write_str("FAILnot implemented");
-       }
-       else {
-               fastboot_tx_write_str("FAILunknown oem command");
+       if (req->actual < req->length) {
+               cmdbuf[req->actual] = '\0';
+               cmd = fastboot_handle_command(cmdbuf, response);
+       } else {
+               pr_err("buffer overflow");
+               fastboot_fail("buffer overflow", response);
        }
-}
-
-#ifdef CONFIG_FASTBOOT_FLASH
-static void cb_erase(struct usb_ep *ep, struct usb_request *req)
-{
-       char *cmd = req->buf;
-       char response[FASTBOOT_RESPONSE_LEN];
 
-       strsep(&cmd, ":");
-       if (!cmd) {
-               pr_err("missing partition name");
-               fastboot_tx_write_str("FAILmissing partition name");
-               return;
+       if (!strncmp("DATA", response, 4)) {
+               req->complete = rx_handler_dl_image;
+               req->length = rx_bytes_expected(ep);
        }
 
-       /* initialize the response buffer */
-       fb_response_str = response;
-
-       fastboot_fail("no flash device defined");
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-       fb_mmc_erase(cmd);
-#endif
-#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
-       fb_nand_erase(cmd);
-#endif
        fastboot_tx_write_str(response);
-}
-#endif
-
-struct cmd_dispatch_info {
-       char *cmd;
-       void (*cb)(struct usb_ep *ep, struct usb_request *req);
-};
-
-static const struct cmd_dispatch_info cmd_dispatch_info[] = {
-       {
-               .cmd = "reboot",
-               .cb = cb_reboot,
-       }, {
-               .cmd = "getvar:",
-               .cb = cb_getvar,
-       }, {
-               .cmd = "download:",
-               .cb = cb_download,
-       }, {
-               .cmd = "boot",
-               .cb = cb_boot,
-       }, {
-               .cmd = "continue",
-               .cb = cb_continue,
-       },
-#ifdef CONFIG_FASTBOOT_FLASH
-       {
-               .cmd = "flash",
-               .cb = cb_flash,
-       }, {
-               .cmd = "erase",
-               .cb = cb_erase,
-       },
-#endif
-       {
-               .cmd = "oem",
-               .cb = cb_oem,
-       },
-};
-
-static void rx_handler_command(struct usb_ep *ep, struct usb_request *req)
-{
-       char *cmdbuf = req->buf;
-       void (*func_cb)(struct usb_ep *ep, struct usb_request *req) = NULL;
-       int i;
 
-       if (req->status != 0 || req->length == 0)
-               return;
+       if (!strncmp("OKAY", response, 4)) {
+               switch (cmd) {
+               case FASTBOOT_COMMAND_BOOT:
+                       fastboot_func->in_req->complete = do_bootm_on_complete;
+                       break;
 
-       for (i = 0; i < ARRAY_SIZE(cmd_dispatch_info); i++) {
-               if (!strcmp_l1(cmd_dispatch_info[i].cmd, cmdbuf)) {
-                       func_cb = cmd_dispatch_info[i].cb;
+               case FASTBOOT_COMMAND_CONTINUE:
+                       fastboot_func->in_req->complete = do_exit_on_complete;
                        break;
-               }
-       }
 
-       if (!func_cb) {
-               pr_err("unknown command: %.*s", req->actual, cmdbuf);
-               fastboot_tx_write_str("FAILunknown command");
-       } else {
-               if (req->actual < req->length) {
-                       u8 *buf = (u8 *)req->buf;
-                       buf[req->actual] = 0;
-                       func_cb(ep, req);
-               } else {
-                       pr_err("buffer overflow");
-                       fastboot_tx_write_str("FAILbuffer overflow");
+               case FASTBOOT_COMMAND_REBOOT:
+               case FASTBOOT_COMMAND_REBOOT_BOOTLOADER:
+                       fastboot_func->in_req->complete = compl_do_reset;
+                       break;
                }
        }
 
index c8eda058329cec84e4f3cafc040f70de9f1d09b1..1aa6be44bb4d0894604dca8ad1f90e83bd0c225c 100644 (file)
@@ -620,22 +620,6 @@ static void thor_rx_tx_complete(struct usb_ep *ep, struct usb_request *req)
              status, req->actual, req->length);
 }
 
-static struct usb_request *thor_start_ep(struct usb_ep *ep)
-{
-       struct usb_request *req;
-
-       req = alloc_ep_req(ep, THOR_PACKET_SIZE);
-       debug("%s: ep:%p req:%p\n", __func__, ep, req);
-
-       if (!req)
-               return NULL;
-
-       memset(req->buf, 0, req->length);
-       req->complete = thor_rx_tx_complete;
-
-       return req;
-}
-
 static void thor_setup_complete(struct usb_ep *ep, struct usb_request *req)
 {
        if (req->status || req->actual != req->length)
@@ -752,6 +736,13 @@ int thor_handle(void)
        return 0;
 }
 
+static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
+{
+       if (req->buf)
+               free(req->buf);
+       usb_ep_free_request(ep, req);
+}
+
 static int thor_func_bind(struct usb_configuration *c, struct usb_function *f)
 {
        struct usb_gadget *gadget = c->cdev->gadget;
@@ -860,21 +851,18 @@ static int thor_func_bind(struct usb_configuration *c, struct usb_function *f)
        return 0;
 
  fail:
+       if (dev->req)
+               free_ep_req(gadget->ep0, dev->req);
        free(dev);
        return status;
 }
 
-static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
-{
-       free(req->buf);
-       usb_ep_free_request(ep, req);
-}
-
 static void thor_unbind(struct usb_configuration *c, struct usb_function *f)
 {
        struct f_thor *f_thor = func_to_thor(f);
        struct thor_dev *dev = f_thor->dev;
 
+       free_ep_req(dev->gadget->ep0, dev->req);
        free(dev);
        memset(thor_func, 0, sizeof(*thor_func));
        thor_func = NULL;
@@ -895,8 +883,6 @@ static void thor_func_disable(struct usb_function *f)
        }
 
        if (dev->out_ep->driver_data) {
-               free(dev->out_req->buf);
-               dev->out_req->buf = NULL;
                usb_ep_free_request(dev->out_ep, dev->out_req);
                usb_ep_disable(dev->out_ep);
                dev->out_ep->driver_data = NULL;
@@ -924,16 +910,17 @@ static int thor_eps_setup(struct usb_function *f)
 
        result = usb_ep_enable(ep, d);
        if (result)
-               goto exit;
+               goto err;
 
        ep->driver_data = cdev; /* claim */
-       req = thor_start_ep(ep);
+       req = alloc_ep_req(ep, THOR_PACKET_SIZE);
        if (!req) {
-               usb_ep_disable(ep);
                result = -EIO;
-               goto exit;
+               goto err_disable_in_ep;
        }
 
+       memset(req->buf, 0, req->length);
+       req->complete = thor_rx_tx_complete;
        dev->in_req = req;
        ep = dev->out_ep;
        d = ep_desc(gadget, &hs_out_desc, &fs_out_desc);
@@ -941,22 +928,34 @@ static int thor_eps_setup(struct usb_function *f)
 
        result = usb_ep_enable(ep, d);
        if (result)
-               goto exit;
+               goto err_free_in_req;
 
        ep->driver_data = cdev; /* claim */
-       req = thor_start_ep(ep);
+       req = usb_ep_alloc_request(ep, 0);
        if (!req) {
-               usb_ep_disable(ep);
                result = -EIO;
-               goto exit;
+               goto err_disable_out_ep;
        }
 
+       req->complete = thor_rx_tx_complete;
        dev->out_req = req;
        /* ACM control EP */
        ep = dev->int_ep;
        ep->driver_data = cdev; /* claim */
 
- exit:
+       return 0;
+
+ err_disable_out_ep:
+       usb_ep_disable(dev->out_ep);
+
+ err_free_in_req:
+       free_ep_req(dev->in_ep, dev->in_req);
+       dev->in_req = NULL;
+
+ err_disable_in_ep:
+       usb_ep_disable(dev->in_ep);
+
+ err:
        return result;
 }
 
index a837afc483bf3c5e2fbca18f74713c32aad98ce1..f2e91ef0feb71bec72f80ebb69b3b07fecd5597d 100644 (file)
@@ -117,12 +117,15 @@ err_clk:
 
 static int xhci_rcar_deregister(struct udevice *dev)
 {
+       int ret;
        struct rcar_xhci_platdata *plat = dev_get_platdata(dev);
 
+       ret = xhci_deregister(dev);
+
        clk_disable(&plat->clk);
        clk_free(&plat->clk);
 
-       return xhci_deregister(dev);
+       return ret;
 }
 
 static int xhci_rcar_ofdata_to_platdata(struct udevice *dev)
index 060a6c43092f441f37322c220ba1d6ae45b4b55f..f19bea3a91b736d1ad2e9434aa6192c78494b77a 100644 (file)
@@ -17,7 +17,6 @@
 
 struct rockchip_xhci_platdata {
        fdt_addr_t hcd_base;
-       fdt_addr_t phy_base;
        struct udevice *vbus_supply;
 };
 
@@ -35,7 +34,6 @@ struct rockchip_xhci {
 static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
 {
        struct rockchip_xhci_platdata *plat = dev_get_platdata(dev);
-       struct udevice *child;
        int ret = 0;
 
        /*
@@ -47,20 +45,6 @@ static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
                return -ENXIO;
        }
 
-       /* Get the base address for usbphy from the device node */
-       for (device_find_first_child(dev, &child); child;
-            device_find_next_child(&child)) {
-               if (!device_is_compatible(child, "rockchip,rk3399-usb3-phy"))
-                       continue;
-               plat->phy_base = devfdt_get_addr(child);
-               break;
-       }
-
-       if (plat->phy_base == FDT_ADDR_T_NONE) {
-               pr_err("Can't get the usbphy register address\n");
-               return -ENXIO;
-       }
-
        /* Vbus regulator */
        ret = device_get_supply_regulator(dev, "vbus-supply",
                                          &plat->vbus_supply);
index 3adb0028f2ae3501b84b0cab8d4fc1e6e432d2d6..9ded14cc3cb7a6703da755d4ded51e91338ecd91 100644 (file)
@@ -536,7 +536,7 @@ static int xhci_set_configuration(struct usb_device *udev)
        /* slot context */
        xhci_slot_copy(ctrl, in_ctx, out_ctx);
        slot_ctx = xhci_get_slot_ctx(ctrl, in_ctx);
-       slot_ctx->dev_info &= ~(LAST_CTX_MASK);
+       slot_ctx->dev_info &= ~(cpu_to_le32(LAST_CTX_MASK));
        slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(max_ep_flag + 1) | 0);
 
        xhci_endpoint_copy(ctrl, in_ctx, out_ctx, 0);
@@ -1424,7 +1424,7 @@ static int xhci_update_hub_device(struct udevice *dev, struct usb_device *udev)
 
        ctrl_ctx = xhci_get_input_control_ctx(in_ctx);
        /* Initialize the input context control */
-       ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
+       ctrl_ctx->add_flags = cpu_to_le32(SLOT_FLAG);
        ctrl_ctx->drop_flags = 0;
 
        xhci_inval_cache((uintptr_t)out_ctx->bytes, out_ctx->size);
@@ -1435,8 +1435,15 @@ static int xhci_update_hub_device(struct udevice *dev, struct usb_device *udev)
 
        /* Update hub related fields */
        slot_ctx->dev_info |= cpu_to_le32(DEV_HUB);
-       if (hub->tt.multi && udev->speed == USB_SPEED_HIGH)
+       /*
+        * refer to section 6.2.2: MTT should be 0 for full speed hub,
+        * but it may be already set to 1 when setup an xHCI virtual
+        * device, so clear it anyway.
+        */
+       if (hub->tt.multi)
                slot_ctx->dev_info |= cpu_to_le32(DEV_MTT);
+       else if (udev->speed == USB_SPEED_FULL)
+               slot_ctx->dev_info &= cpu_to_le32(~DEV_MTT);
        slot_ctx->dev_info2 |= cpu_to_le32(XHCI_MAX_PORTS(udev->maxchild));
        /*
         * Set TT think time - convert from ns to FS bit times.
@@ -1452,6 +1459,7 @@ static int xhci_update_hub_device(struct udevice *dev, struct usb_device *udev)
                think_time = (think_time / 666) - 1;
        if (udev->speed == USB_SPEED_HIGH)
                slot_ctx->tt_info |= cpu_to_le32(TT_THINK_TIME(think_time));
+       slot_ctx->dev_state = 0;
 
        return xhci_configure_endpoints(udev, false);
 }
diff --git a/fs/fs.c b/fs/fs.c
index 94cdc37debfb39c0e813129bea976e81ed15d8e6..33808d549e0a5cd5e0a005dc5b00a3337aa4f0f8 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -265,6 +265,19 @@ static struct fstype_info *fs_get_info(int fstype)
        return info;
 }
 
+/**
+ * fs_get_type_name() - Get type of current filesystem
+ *
+ * Return: Pointer to filesystem name
+ *
+ * Returns a string describing the current filesystem, or the sentinel
+ * "unsupported" for any unrecognised filesystem.
+ */
+const char *fs_get_type_name(void)
+{
+       return fs_get_info(fs_type)->name;
+}
+
 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
 {
        struct fstype_info *info;
diff --git a/include/fastboot-internal.h b/include/fastboot-internal.h
new file mode 100644 (file)
index 0000000..bf2f2b3
--- /dev/null
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef _FASTBOOT_INTERNAL_H_
+#define _FASTBOOT_INTERNAL_H_
+
+/**
+ * fastboot_buf_addr - base address of the fastboot download buffer
+ */
+extern void *fastboot_buf_addr;
+
+/**
+ * fastboot_buf_size - size of the fastboot download buffer
+ */
+extern u32 fastboot_buf_size;
+
+/**
+ * fastboot_progress_callback - callback executed during long operations
+ */
+extern void (*fastboot_progress_callback)(const char *msg);
+
+/**
+ * fastboot_getvar() - Writes variable indicated by cmd_parameter to response.
+ *
+ * @cmd_parameter: Pointer to command parameter
+ * @response: Pointer to fastboot response buffer
+ *
+ * Look up cmd_parameter first as an environment variable of the form
+ * fastboot.<cmd_parameter>, if that exists return use its value to set
+ * response.
+ *
+ * Otherwise lookup the name of variable and execute the appropriate
+ * function to return the requested value.
+ */
+void fastboot_getvar(char *cmd_parameter, char *response);
+
+#endif
index 009f1a72e10fb287fa721cac91028b4db065371c..1933b1d98e3bb9a03832f37b5efb616cb6ec952b 100644 (file)
 #ifndef _FASTBOOT_H_
 #define _FASTBOOT_H_
 
+#define FASTBOOT_VERSION       "0.4"
+
 /* The 64 defined bytes plus \0 */
+#define FASTBOOT_COMMAND_LEN   (64 + 1)
 #define FASTBOOT_RESPONSE_LEN  (64 + 1)
 
-void fastboot_fail(const char *reason);
-void fastboot_okay(const char *reason);
+/**
+ * All known commands to fastboot
+ */
+enum {
+       FASTBOOT_COMMAND_GETVAR = 0,
+       FASTBOOT_COMMAND_DOWNLOAD,
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+       FASTBOOT_COMMAND_FLASH,
+       FASTBOOT_COMMAND_ERASE,
+#endif
+       FASTBOOT_COMMAND_BOOT,
+       FASTBOOT_COMMAND_CONTINUE,
+       FASTBOOT_COMMAND_REBOOT,
+       FASTBOOT_COMMAND_REBOOT_BOOTLOADER,
+       FASTBOOT_COMMAND_SET_ACTIVE,
+#if CONFIG_IS_ENABLED(FASTBOOT_CMD_OEM_FORMAT)
+       FASTBOOT_COMMAND_OEM_FORMAT,
+#endif
+
+       FASTBOOT_COMMAND_COUNT
+};
+
+/**
+ * fastboot_response() - Writes a response of the form "$tag$reason".
+ *
+ * @tag: The first part of the response
+ * @response: Pointer to fastboot response buffer
+ * @format: printf style format string
+ */
+void fastboot_response(const char *tag, char *response,
+                      const char *format, ...)
+       __attribute__ ((format (__printf__, 3, 4)));
+
+/**
+ * fastboot_fail() - Write a FAIL response of the form "FAIL$reason".
+ *
+ * @reason: Pointer to returned reason string
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_fail(const char *reason, char *response);
+
+/**
+ * fastboot_okay() - Write an OKAY response of the form "OKAY$reason".
+ *
+ * @reason: Pointer to returned reason string, or NULL to send a bare "OKAY"
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_okay(const char *reason, char *response);
+
+/**
+ * fastboot_set_reboot_flag() - Set flag to indicate reboot-bootloader
+ *
+ * Set flag which indicates that we should reboot into the bootloader
+ * following the reboot that fastboot executes after this function.
+ *
+ * This function should be overridden in your board file with one
+ * which sets whatever flag your board specific Android bootloader flow
+ * requires in order to re-enter the bootloader.
+ */
+int fastboot_set_reboot_flag(void);
+
+/**
+ * fastboot_set_progress_callback() - set progress callback
+ *
+ * @progress: Pointer to progress callback
+ *
+ * Set a callback which is invoked periodically during long running operations
+ * (flash and erase). This can be used (for example) by the UDP transport to
+ * send INFO responses to keep the client alive whilst those commands are
+ * executing.
+ */
+void fastboot_set_progress_callback(void (*progress)(const char *msg));
+
+/*
+ * fastboot_init() - initialise new fastboot protocol session
+ *
+ * @buf_addr: Pointer to download buffer, or NULL for default
+ * @buf_size: Size of download buffer, or zero for default
+ */
+void fastboot_init(void *buf_addr, u32 buf_size);
+
+/**
+ * fastboot_boot() - Execute fastboot boot command
+ *
+ * If ${fastboot_bootcmd} is set, run that command to execute the boot
+ * process, if that returns, then exit the fastboot server and return
+ * control to the caller.
+ *
+ * Otherwise execute "bootm <fastboot_buf_addr>", if that fails, reset
+ * the board.
+ */
+void fastboot_boot(void);
+
+/**
+ * fastboot_handle_command() - Handle fastboot command
+ *
+ * @cmd_string: Pointer to command string
+ * @response: Pointer to fastboot response buffer
+ *
+ * Return: Executed command, or -1 if not recognized
+ */
+int fastboot_handle_command(char *cmd_string, char *response);
+
+/**
+ * fastboot_data_remaining() - return bytes remaining in current transfer
+ *
+ * Return: Number of bytes left in the current download
+ */
+u32 fastboot_data_remaining(void);
+
+/**
+ * fastboot_data_download() - Copy image data to fastboot_buf_addr.
+ *
+ * @fastboot_data: Pointer to received fastboot data
+ * @fastboot_data_len: Length of received fastboot data
+ * @response: Pointer to fastboot response buffer
+ *
+ * Copies image data from fastboot_data to fastboot_buf_addr. Writes to
+ * response. fastboot_bytes_received is updated to indicate the number
+ * of bytes that have been transferred.
+ */
+void fastboot_data_download(const void *fastboot_data,
+                           unsigned int fastboot_data_len, char *response);
+
+/**
+ * fastboot_data_complete() - Mark current transfer complete
+ *
+ * @response: Pointer to fastboot response buffer
+ *
+ * Set image_size and ${filesize} to the total size of the downloaded image.
+ */
+void fastboot_data_complete(char *response);
 
 #endif /* _FASTBOOT_H_ */
index a2d7c4895fa1b5f9449b43619f27c71a3aea9b7d..fd5db9eac8753b8e526036a65bb610d162ea4780 100644 (file)
@@ -3,6 +3,35 @@
  * Copyright 2014 Broadcom Corporation.
  */
 
-void fb_mmc_flash_write(const char *cmd, void *download_buffer,
-                       unsigned int download_bytes);
-void fb_mmc_erase(const char *cmd);
+#ifndef _FB_MMC_H_
+#define _FB_MMC_H_
+
+/**
+ * fastboot_mmc_get_part_info() - Lookup eMMC partion by name
+ *
+ * @part_name: Named partition to lookup
+ * @dev_desc: Pointer to returned blk_desc pointer
+ * @part_info: Pointer to returned disk_partition_t
+ * @response: Pointer to fastboot response buffer
+ */
+int fastboot_mmc_get_part_info(char *part_name, struct blk_desc **dev_desc,
+                              disk_partition_t *part_info, char *response);
+
+/**
+ * fastboot_mmc_flash_write() - Write image to eMMC for fastboot
+ *
+ * @cmd: Named partition to write image to
+ * @download_buffer: Pointer to image data
+ * @download_bytes: Size of image data
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_mmc_flash_write(const char *cmd, void *download_buffer,
+                             u32 download_bytes, char *response);
+/**
+ * fastboot_mmc_flash_erase() - Erase eMMC for fastboot
+ *
+ * @cmd: Named partition to erase
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_mmc_erase(const char *cmd, char *response);
+#endif
index 3daae8c4ca450ade1dad49600cd183eb833882ac..08ab0e28a6545ed1df6d1eaca87a3534a0a57356 100644 (file)
@@ -4,6 +4,37 @@
  * Copyright 2015 Free Electrons.
  */
 
-void fb_nand_flash_write(const char *cmd, void *download_buffer,
-                        unsigned int download_bytes);
-void fb_nand_erase(const char *cmd);
+#ifndef _FB_NAND_H_
+#define _FB_NAND_H_
+
+#include <jffs2/load_kernel.h>
+
+/**
+ * fastboot_nand_get_part_info() - Lookup NAND partion by name
+ *
+ * @part_name: Named device to lookup
+ * @part_info: Pointer to returned part_info pointer
+ * @response: Pointer to fastboot response buffer
+ */
+int fastboot_nand_get_part_info(char *part_name, struct part_info **part_info,
+                               char *response);
+
+/**
+ * fastboot_nand_flash_write() - Write image to NAND for fastboot
+ *
+ * @cmd: Named device to write image to
+ * @download_buffer: Pointer to image data
+ * @download_bytes: Size of image data
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_nand_flash_write(const char *cmd, void *download_buffer,
+                              u32 download_bytes, char *response);
+
+/**
+ * fastboot_nand_flash_erase() - Erase NAND for fastboot
+ *
+ * @cmd: Named device to erase
+ * @response: Pointer to fastboot response buffer
+ */
+void fastboot_nand_erase(const char *cmd, char *response);
+#endif
index d703ed5027edef072830ac09cd9f18c475ffe8ec..163da103b472bd65fae7c7ef71ea50815385bcae 100644 (file)
@@ -37,6 +37,16 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype);
  */
 int fs_set_blk_dev_with_part(struct blk_desc *desc, int part);
 
+/**
+ * fs_get_type_name() - Get type of current filesystem
+ *
+ * Return: Pointer to filesystem name
+ *
+ * Returns a string describing the current filesystem, or the sentinel
+ * "unsupported" for any unrecognised filesystem.
+ */
+const char *fs_get_type_name(void);
+
 /*
  * Print the list of files on the partition previously set by fs_set_blk_dev(),
  * in directory "dirname".
index f39dc16617f32d987882fae7d134ff93f04cd07a..234c237b845fe592077d4be51e98ffe7cfb8ef3b 100644 (file)
@@ -23,7 +23,7 @@ struct sparse_storage {
                                 lbaint_t blk,
                                 lbaint_t blkcnt);
 
-       void            (*mssg)(const char *str);
+       void            (*mssg)(const char *str, char *response);
 };
 
 static inline int is_sparse_image(void *buf)
@@ -38,4 +38,4 @@ static inline int is_sparse_image(void *buf)
 }
 
 int write_sparse_image(struct sparse_storage *info, const char *part_name,
-                      void *data);
+                      void *data, char *response);
index 65f51d77a555d3e7dce91ef769bf4ba7bbe564c2..57606855564f002f5b0d4e38c1df926a998e0a43 100644 (file)
@@ -535,7 +535,7 @@ extern int          net_restart_wrap;       /* Tried all network devices */
 
 enum proto_t {
        BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
-       TFTPSRV, TFTPPUT, LINKLOCAL
+       TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT
 };
 
 extern char    net_boot_file_name[1024];/* Boot File name */
diff --git a/include/net/fastboot.h b/include/net/fastboot.h
new file mode 100644 (file)
index 0000000..6860209
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2016 The Android Open Source Project
+ */
+
+#ifndef __NET_FASTBOOT_H__
+#define __NET_FASTBOOT_H__
+
+/**********************************************************************/
+/*
+ *     Global functions and variables.
+ */
+
+/**
+ * Wait for incoming fastboot comands.
+ */
+void fastboot_start_server(void);
+
+/**********************************************************************/
+
+#endif /* __NET_FASTBOOT_H__ */
index 1590f7afa40250cf3df678fccd57aecaa5e1e940..15c6a52d4a1b57273c1d84ce822191209004fa9f 100644 (file)
@@ -61,6 +61,17 @@ config SPL_STRTO
 config TPL_STRTO
        bool
 
+config IMAGE_SPARSE
+       bool
+
+config IMAGE_SPARSE_FILLBUF_SIZE
+       hex "Android sparse image CHUNK_TYPE_FILL buffer size"
+       default 0x80000
+       depends on IMAGE_SPARSE
+       help
+         Set the size of the fill buffer used when processing CHUNK_TYPE_FILL
+         chunks.
+
 config USE_PRIVATE_LIBGCC
        bool "Use private libgcc"
        depends on HAVE_PRIVATE_LIBGCC
index e6cb4afc232650ac31072fcd553fb5be7c732cc6..c0511cbff84450b28926ed543c050a610766ec74 100644 (file)
@@ -29,6 +29,7 @@ obj-$(CONFIG_FIT) += fdtdec_common.o
 obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
 obj-$(CONFIG_GZIP_COMPRESSED) += gzip.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
+obj-$(CONFIG_IMAGE_SPARSE) += image-sparse.o
 obj-y += initcall.o
 obj-$(CONFIG_LMB) += lmb.o
 obj-y += ldiv.o
diff --git a/lib/image-sparse.c b/lib/image-sparse.c
new file mode 100644 (file)
index 0000000..0360621
--- /dev/null
@@ -0,0 +1,261 @@
+/*
+ * Copyright (c) 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
+ * Portions Copyright 2014 Broadcom Corporation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of The Linux Foundation nor
+ *       the names of its contributors may be used to endorse or promote
+ *       products derived from this software without specific prior written
+ *       permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * NOTE:
+ *   Although it is very similar, this license text is not identical
+ *   to the "BSD-3-Clause", therefore, DO NOT MODIFY THIS LICENSE TEXT!
+ */
+
+#include <config.h>
+#include <common.h>
+#include <image-sparse.h>
+#include <div64.h>
+#include <malloc.h>
+#include <part.h>
+#include <sparse_format.h>
+
+#include <linux/math64.h>
+
+static void default_log(const char *ignored, char *response) {}
+
+int write_sparse_image(struct sparse_storage *info,
+                      const char *part_name, void *data, char *response)
+{
+       lbaint_t blk;
+       lbaint_t blkcnt;
+       lbaint_t blks;
+       uint32_t bytes_written = 0;
+       unsigned int chunk;
+       unsigned int offset;
+       unsigned int chunk_data_sz;
+       uint32_t *fill_buf = NULL;
+       uint32_t fill_val;
+       sparse_header_t *sparse_header;
+       chunk_header_t *chunk_header;
+       uint32_t total_blocks = 0;
+       int fill_buf_num_blks;
+       int i;
+       int j;
+
+       fill_buf_num_blks = CONFIG_IMAGE_SPARSE_FILLBUF_SIZE / info->blksz;
+
+       /* Read and skip over sparse image header */
+       sparse_header = (sparse_header_t *)data;
+
+       data += sparse_header->file_hdr_sz;
+       if (sparse_header->file_hdr_sz > sizeof(sparse_header_t)) {
+               /*
+                * Skip the remaining bytes in a header that is longer than
+                * we expected.
+                */
+               data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t));
+       }
+
+       if (!info->mssg)
+               info->mssg = default_log;
+
+       debug("=== Sparse Image Header ===\n");
+       debug("magic: 0x%x\n", sparse_header->magic);
+       debug("major_version: 0x%x\n", sparse_header->major_version);
+       debug("minor_version: 0x%x\n", sparse_header->minor_version);
+       debug("file_hdr_sz: %d\n", sparse_header->file_hdr_sz);
+       debug("chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz);
+       debug("blk_sz: %d\n", sparse_header->blk_sz);
+       debug("total_blks: %d\n", sparse_header->total_blks);
+       debug("total_chunks: %d\n", sparse_header->total_chunks);
+
+       /*
+        * Verify that the sparse block size is a multiple of our
+        * storage backend block size
+        */
+       div_u64_rem(sparse_header->blk_sz, info->blksz, &offset);
+       if (offset) {
+               printf("%s: Sparse image block size issue [%u]\n",
+                      __func__, sparse_header->blk_sz);
+               info->mssg("sparse image block size issue", response);
+               return -1;
+       }
+
+       puts("Flashing Sparse Image\n");
+
+       /* Start processing chunks */
+       blk = info->start;
+       for (chunk = 0; chunk < sparse_header->total_chunks; chunk++) {
+               /* Read and skip over chunk header */
+               chunk_header = (chunk_header_t *)data;
+               data += sizeof(chunk_header_t);
+
+               if (chunk_header->chunk_type != CHUNK_TYPE_RAW) {
+                       debug("=== Chunk Header ===\n");
+                       debug("chunk_type: 0x%x\n", chunk_header->chunk_type);
+                       debug("chunk_data_sz: 0x%x\n", chunk_header->chunk_sz);
+                       debug("total_size: 0x%x\n", chunk_header->total_sz);
+               }
+
+               if (sparse_header->chunk_hdr_sz > sizeof(chunk_header_t)) {
+                       /*
+                        * Skip the remaining bytes in a header that is longer
+                        * than we expected.
+                        */
+                       data += (sparse_header->chunk_hdr_sz -
+                                sizeof(chunk_header_t));
+               }
+
+               chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz;
+               blkcnt = chunk_data_sz / info->blksz;
+               switch (chunk_header->chunk_type) {
+               case CHUNK_TYPE_RAW:
+                       if (chunk_header->total_sz !=
+                           (sparse_header->chunk_hdr_sz + chunk_data_sz)) {
+                               info->mssg("Bogus chunk size for chunk type Raw",
+                                          response);
+                               return -1;
+                       }
+
+                       if (blk + blkcnt > info->start + info->size) {
+                               printf(
+                                   "%s: Request would exceed partition size!\n",
+                                   __func__);
+                               info->mssg("Request would exceed partition size!",
+                                          response);
+                               return -1;
+                       }
+
+                       blks = info->write(info, blk, blkcnt, data);
+                       /* blks might be > blkcnt (eg. NAND bad-blocks) */
+                       if (blks < blkcnt) {
+                               printf("%s: %s" LBAFU " [" LBAFU "]\n",
+                                      __func__, "Write failed, block #",
+                                      blk, blks);
+                               info->mssg("flash write failure", response);
+                               return -1;
+                       }
+                       blk += blks;
+                       bytes_written += blkcnt * info->blksz;
+                       total_blocks += chunk_header->chunk_sz;
+                       data += chunk_data_sz;
+                       break;
+
+               case CHUNK_TYPE_FILL:
+                       if (chunk_header->total_sz !=
+                           (sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
+                               info->mssg("Bogus chunk size for chunk type FILL", response);
+                               return -1;
+                       }
+
+                       fill_buf = (uint32_t *)
+                                  memalign(ARCH_DMA_MINALIGN,
+                                           ROUNDUP(
+                                               info->blksz * fill_buf_num_blks,
+                                               ARCH_DMA_MINALIGN));
+                       if (!fill_buf) {
+                               info->mssg("Malloc failed for: CHUNK_TYPE_FILL",
+                                          response);
+                               return -1;
+                       }
+
+                       fill_val = *(uint32_t *)data;
+                       data = (char *)data + sizeof(uint32_t);
+
+                       for (i = 0;
+                            i < (info->blksz * fill_buf_num_blks /
+                                 sizeof(fill_val));
+                            i++)
+                               fill_buf[i] = fill_val;
+
+                       if (blk + blkcnt > info->start + info->size) {
+                               printf(
+                                   "%s: Request would exceed partition size!\n",
+                                   __func__);
+                               info->mssg("Request would exceed partition size!",
+                                          response);
+                               return -1;
+                       }
+
+                       for (i = 0; i < blkcnt;) {
+                               j = blkcnt - i;
+                               if (j > fill_buf_num_blks)
+                                       j = fill_buf_num_blks;
+                               blks = info->write(info, blk, j, fill_buf);
+                               /* blks might be > j (eg. NAND bad-blocks) */
+                               if (blks < j) {
+                                       printf("%s: %s " LBAFU " [%d]\n",
+                                              __func__,
+                                              "Write failed, block #",
+                                              blk, j);
+                                       info->mssg("flash write failure",
+                                                  response);
+                                       free(fill_buf);
+                                       return -1;
+                               }
+                               blk += blks;
+                               i += j;
+                       }
+                       bytes_written += blkcnt * info->blksz;
+                       total_blocks += chunk_data_sz / sparse_header->blk_sz;
+                       free(fill_buf);
+                       break;
+
+               case CHUNK_TYPE_DONT_CARE:
+                       blk += info->reserve(info, blk, blkcnt);
+                       total_blocks += chunk_header->chunk_sz;
+                       break;
+
+               case CHUNK_TYPE_CRC32:
+                       if (chunk_header->total_sz !=
+                           sparse_header->chunk_hdr_sz) {
+                               info->mssg("Bogus chunk size for chunk type Dont Care",
+                                          response);
+                               return -1;
+                       }
+                       total_blocks += chunk_header->chunk_sz;
+                       data += chunk_data_sz;
+                       break;
+
+               default:
+                       printf("%s: Unknown chunk type: %x\n", __func__,
+                              chunk_header->chunk_type);
+                       info->mssg("Unknown chunk type", response);
+                       return -1;
+               }
+       }
+
+       debug("Wrote %d blocks, expected to write %d blocks\n",
+             total_blocks, sparse_header->total_blks);
+       printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
+
+       if (total_blocks != sparse_header->total_blks) {
+               info->mssg("sparse image write failure", response);
+               return -1;
+       }
+
+       return 0;
+}
index d1e8e01f62fbfc9f114898d6c84e3a41bf5bac1c..07466879f501f77aea77853b9f2ba609f7ad64a7 100644 (file)
@@ -23,6 +23,7 @@ obj-$(CONFIG_CMD_PING) += ping.o
 obj-$(CONFIG_CMD_RARP) += rarp.o
 obj-$(CONFIG_CMD_SNTP) += sntp.o
 obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
+obj-$(CONFIG_UDP_FUNCTION_FASTBOOT)  += fastboot.o
 
 # Disable this warning as it is triggered by:
 # sprintf(buf, index ? "foo%d" : "foo", index)
diff --git a/net/fastboot.c b/net/fastboot.c
new file mode 100644 (file)
index 0000000..a9f7c07
--- /dev/null
@@ -0,0 +1,317 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ */
+
+#include <common.h>
+#include <fastboot.h>
+#include <net.h>
+#include <net/fastboot.h>
+
+/* Fastboot port # defined in spec */
+#define WELL_KNOWN_PORT 5554
+
+enum {
+       FASTBOOT_ERROR = 0,
+       FASTBOOT_QUERY = 1,
+       FASTBOOT_INIT = 2,
+       FASTBOOT_FASTBOOT = 3,
+};
+
+struct __packed fastboot_header {
+       uchar id;
+       uchar flags;
+       unsigned short seq;
+};
+
+#define PACKET_SIZE 1024
+#define DATA_SIZE (PACKET_SIZE - sizeof(struct fastboot_header))
+
+/* Sequence number sent for every packet */
+static unsigned short sequence_number = 1;
+static const unsigned short packet_size = PACKET_SIZE;
+static const unsigned short udp_version = 1;
+
+/* Keep track of last packet for resubmission */
+static uchar last_packet[PACKET_SIZE];
+static unsigned int last_packet_len;
+
+static struct in_addr fastboot_remote_ip;
+/* The UDP port at their end */
+static int fastboot_remote_port;
+/* The UDP port at our end */
+static int fastboot_our_port;
+
+static void boot_downloaded_image(void);
+
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+/**
+ * fastboot_udp_send_info() - Send an INFO packet during long commands.
+ *
+ * @msg: String describing the reason for waiting
+ */
+static void fastboot_udp_send_info(const char *msg)
+{
+       uchar *packet;
+       uchar *packet_base;
+       int len = 0;
+       char response[FASTBOOT_RESPONSE_LEN] = {0};
+
+       struct fastboot_header response_header = {
+               .id = FASTBOOT_FASTBOOT,
+               .flags = 0,
+               .seq = htons(sequence_number)
+       };
+       ++sequence_number;
+       packet = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
+       packet_base = packet;
+
+       /* Write headers */
+       memcpy(packet, &response_header, sizeof(response_header));
+       packet += sizeof(response_header);
+       /* Write response */
+       fastboot_response("INFO", response, "%s", msg);
+       memcpy(packet, response, strlen(response));
+       packet += strlen(response);
+
+       len = packet - packet_base;
+
+       /* Save packet for retransmitting */
+       last_packet_len = len;
+       memcpy(last_packet, packet_base, last_packet_len);
+
+       net_send_udp_packet(net_server_ethaddr, fastboot_remote_ip,
+                           fastboot_remote_port, fastboot_our_port, len);
+}
+
+/**
+ * fastboot_timed_send_info() - Send INFO packet every 30 seconds
+ *
+ * @msg: String describing the reason for waiting
+ *
+ * Send an INFO packet during long commands based on timer. An INFO packet
+ * is sent if the time is 30 seconds after start. Else, noop.
+ */
+static void fastboot_timed_send_info(const char *msg)
+{
+       static ulong start;
+
+       /* Initialize timer */
+       if (start == 0)
+               start = get_timer(0);
+       ulong time = get_timer(start);
+       /* Send INFO packet to host every 30 seconds */
+       if (time >= 30000) {
+               start = get_timer(0);
+               fastboot_udp_send_info(msg);
+       }
+}
+#endif
+
+/**
+ * fastboot_send() - Sends a packet in response to received fastboot packet
+ *
+ * @header: Header for response packet
+ * @fastboot_data: Pointer to received fastboot data
+ * @fastboot_data_len: Length of received fastboot data
+ * @retransmit: Nonzero if sending last sent packet
+ */
+static void fastboot_send(struct fastboot_header header, char *fastboot_data,
+                         unsigned int fastboot_data_len, uchar retransmit)
+{
+       uchar *packet;
+       uchar *packet_base;
+       int len = 0;
+       const char *error_msg = "An error occurred.";
+       short tmp;
+       struct fastboot_header response_header = header;
+       static char command[FASTBOOT_COMMAND_LEN];
+       static int cmd = -1;
+       static bool pending_command;
+       char response[FASTBOOT_RESPONSE_LEN] = {0};
+
+       /*
+        * We will always be sending some sort of packet, so
+        * cobble together the packet headers now.
+        */
+       packet = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
+       packet_base = packet;
+
+       /* Resend last packet */
+       if (retransmit) {
+               memcpy(packet, last_packet, last_packet_len);
+               net_send_udp_packet(net_server_ethaddr, fastboot_remote_ip,
+                                   fastboot_remote_port, fastboot_our_port,
+                                   last_packet_len);
+               return;
+       }
+
+       response_header.seq = htons(response_header.seq);
+       memcpy(packet, &response_header, sizeof(response_header));
+       packet += sizeof(response_header);
+
+       switch (header.id) {
+       case FASTBOOT_QUERY:
+               tmp = htons(sequence_number);
+               memcpy(packet, &tmp, sizeof(tmp));
+               packet += sizeof(tmp);
+               break;
+       case FASTBOOT_INIT:
+               tmp = htons(udp_version);
+               memcpy(packet, &tmp, sizeof(tmp));
+               packet += sizeof(tmp);
+               tmp = htons(packet_size);
+               memcpy(packet, &tmp, sizeof(tmp));
+               packet += sizeof(tmp);
+               break;
+       case FASTBOOT_ERROR:
+               memcpy(packet, error_msg, strlen(error_msg));
+               packet += strlen(error_msg);
+               break;
+       case FASTBOOT_FASTBOOT:
+               if (cmd == FASTBOOT_COMMAND_DOWNLOAD) {
+                       if (!fastboot_data_len && !fastboot_data_remaining()) {
+                               fastboot_data_complete(response);
+                       } else {
+                               fastboot_data_download(fastboot_data,
+                                                      fastboot_data_len,
+                                                      response);
+                       }
+               } else if (!pending_command) {
+                       strlcpy(command, fastboot_data,
+                               min((size_t)fastboot_data_len + 1,
+                                   sizeof(command)));
+                       pending_command = true;
+               } else {
+                       cmd = fastboot_handle_command(command, response);
+                       pending_command = false;
+               }
+               /*
+                * Sent some INFO packets, need to update sequence number in
+                * header
+                */
+               if (header.seq != sequence_number) {
+                       response_header.seq = htons(sequence_number);
+                       memcpy(packet_base, &response_header,
+                              sizeof(response_header));
+               }
+               /* Write response to packet */
+               memcpy(packet, response, strlen(response));
+               packet += strlen(response);
+               break;
+       default:
+               pr_err("ID %d not implemented.\n", header.id);
+               return;
+       }
+
+       len = packet - packet_base;
+
+       /* Save packet for retransmitting */
+       last_packet_len = len;
+       memcpy(last_packet, packet_base, last_packet_len);
+
+       net_send_udp_packet(net_server_ethaddr, fastboot_remote_ip,
+                           fastboot_remote_port, fastboot_our_port, len);
+
+       /* Continue boot process after sending response */
+       if (!strncmp("OKAY", response, 4)) {
+               switch (cmd) {
+               case FASTBOOT_COMMAND_BOOT:
+                       boot_downloaded_image();
+                       break;
+
+               case FASTBOOT_COMMAND_CONTINUE:
+                       net_set_state(NETLOOP_SUCCESS);
+                       break;
+
+               case FASTBOOT_COMMAND_REBOOT:
+               case FASTBOOT_COMMAND_REBOOT_BOOTLOADER:
+                       do_reset(NULL, 0, 0, NULL);
+                       break;
+               }
+       }
+
+       if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4))
+               cmd = -1;
+}
+
+/**
+ * boot_downloaded_image() - Boots into downloaded image.
+ */
+static void boot_downloaded_image(void)
+{
+       fastboot_boot();
+       net_set_state(NETLOOP_SUCCESS);
+}
+
+/**
+ * fastboot_handler() - Incoming UDP packet handler.
+ *
+ * @packet: Pointer to incoming UDP packet
+ * @dport: Destination UDP port
+ * @sip: Source IP address
+ * @sport: Source UDP port
+ * @len: Packet length
+ */
+static void fastboot_handler(uchar *packet, unsigned int dport,
+                            struct in_addr sip, unsigned int sport,
+                            unsigned int len)
+{
+       struct fastboot_header header;
+       char fastboot_data[DATA_SIZE] = {0};
+       unsigned int fastboot_data_len = 0;
+
+       if (dport != fastboot_our_port)
+               return;
+
+       fastboot_remote_ip = sip;
+       fastboot_remote_port = sport;
+
+       if (len < sizeof(struct fastboot_header) || len > PACKET_SIZE)
+               return;
+       memcpy(&header, packet, sizeof(header));
+       header.flags = 0;
+       header.seq = ntohs(header.seq);
+       packet += sizeof(header);
+       len -= sizeof(header);
+
+       switch (header.id) {
+       case FASTBOOT_QUERY:
+               fastboot_send(header, fastboot_data, 0, 0);
+               break;
+       case FASTBOOT_INIT:
+       case FASTBOOT_FASTBOOT:
+               fastboot_data_len = len;
+               if (len > 0)
+                       memcpy(fastboot_data, packet, len);
+               if (header.seq == sequence_number) {
+                       fastboot_send(header, fastboot_data,
+                                     fastboot_data_len, 0);
+                       sequence_number++;
+               } else if (header.seq == sequence_number - 1) {
+                       /* Retransmit last sent packet */
+                       fastboot_send(header, fastboot_data,
+                                     fastboot_data_len, 1);
+               }
+               break;
+       default:
+               pr_err("ID %d not implemented.\n", header.id);
+               header.id = FASTBOOT_ERROR;
+               fastboot_send(header, fastboot_data, 0, 0);
+               break;
+       }
+}
+
+void fastboot_start_server(void)
+{
+       printf("Using %s device\n", eth_get_name());
+       printf("Listening for fastboot command on %pI4\n", &net_ip);
+
+       fastboot_our_port = WELL_KNOWN_PORT;
+
+       fastboot_set_progress_callback(fastboot_timed_send_info);
+       net_set_udp_handler(fastboot_handler);
+
+       /* zero out server ether in case the server ip has changed */
+       memset(net_server_ethaddr, 0, 6);
+}
index 7f852114427e56cfea1d5a0da150684e3a27bbe1..a4932f46d905f51d0466983b2032a35b134e4e73 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -87,6 +87,7 @@
 #include <environment.h>
 #include <errno.h>
 #include <net.h>
+#include <net/fastboot.h>
 #include <net/tftp.h>
 #if defined(CONFIG_LED_STATUS)
 #include <miiphy.h>
@@ -451,6 +452,11 @@ restart:
                        tftp_start_server();
                        break;
 #endif
+#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
+               case FASTBOOT:
+                       fastboot_start_server();
+                       break;
+#endif
 #if defined(CONFIG_CMD_DHCP)
                case DHCP:
                        bootp_reset();
@@ -1322,6 +1328,7 @@ common:
                /* Fall through */
 
        case NETCONS:
+       case FASTBOOT:
        case TFTPSRV:
                if (net_ip.s_addr == 0) {
                        puts("*** ERROR: `ipaddr' not set\n");
index aa6dec0c7bf6b52bb14f50d3eaeb4a51d740fbd7..d6819370269dfe3956092da564642e9dd9b80f13 100644 (file)
@@ -589,8 +589,6 @@ CONFIG_EXYNOS_RELOCATE_CODE_BASE
 CONFIG_EXYNOS_SPL
 CONFIG_EXYNOS_TMU
 CONFIG_FACTORYSET
-CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE
-CONFIG_FASTBOOT_FLASH_NAND_TRIMFFS
 CONFIG_FAST_FLASH_BIT
 CONFIG_FB_ADDR
 CONFIG_FB_BACKLIGHT