All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support
@ 2018-04-30  8:32 Alex Kiernan
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 01/20] fastboot: Move fastboot to drivers/fastboot Alex Kiernan
                   ` (20 more replies)
  0 siblings, 21 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot


This series merges the fastboot UDP support from AOSP into mainline
U-Boot.

The underlying implementations of most commands are now merged between
both code paths ('oem format' from the USB side is the only one remaining).

Other changes to command handling so that UDP follows the existing USB
behaviour:

- 'boot' now follows the USB code and does 'fastboot CONFIG_FASTBOOT_BUF_ADDR'.
  I've added 'fastbootcmd' which if set overrides the boot command and
  allows the existing UDP behaviour to be preserved.
- 'continue' in UDP now exits the fastboot server rather than executing
  'run bootcmd'
- 'reboot-bootloader' no longer writes 'reboot-bootloader' to
  CONFIG_FASTBOOT_BUF_ADDR as its marker for the subsequent boot. The code
  which is in AOSP common/android_bootloader.c expects this marker, but
  we have prior art in the USB code using the weak function
  fb_set_reboot_flag
- 'getvar' in the UDP path now supports fetching 'fastboot.' prefixed
  variables (inherited from the USB path)
- 'getvar' in the USB path inherits all the variables from the UDP path

Remaining issues:

- whilst I've merged NAND support into the UDP code path, I've no way
  of testing it. My expectation is it'll work, but will need timed_send_info
  working into the NAND path to avoid timeouts on the network side.
- I still need to fix timed_send_info handling when going through the USB
  path.
- the protocol part of the fastboot UDP implementation is separated out
  and would I expect form the basis of a consolidated implementation, but
  I'm inclined to address that as a clearly separate patch so it can be
  tested in isolation (I have no USB hardware I can try this on).

Changes in v2:
- ensure fastboot syntax is backward compatible - 'fastboot 0' means
  'fastboot usb 0'

Alex Kiernan (20):
  fastboot: Move fastboot to drivers/fastboot
  fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT
  fastboot: Refactor fastboot_okay/fail to take response
  fastboot: Extract fastboot_okay/fail to fb_common.c
  fastboot: Introduce fastboot_response and refactor fastboot_okay/fail
  fastboot: Correct dependencies in FASTBOOT_FLASH
  net: fastboot: Merge AOSP UDP fastboot
  net: fastboot: Support building without MMC
  fastboot: Refactor write_fb_response into fastboot_okay/fail/response
  fastboot: Merge USB and UDP getvar implementation
  fastboot: net: Change 'continue' so it matches USB fastboot
  fastboot: net: Convert command lookup to a table
  fastboot: Merge reboot-bootloader handling
  fastboot: Avoid re-parsing cmd_string for boot/reboot
  fastboot: Merge boot common across USB and UDP
  fastboot: net: Add NAND support
  fastboot: Guard getvar:partition-type/size with MMC
  fastboot: Check if part_name is NULL before using it
  fastboot: Add missing newlines
  fastboot: net: Split fastboot protocol out from net

 arch/arm/Kconfig                                 |   2 -
 arch/arm/mach-omap2/boot-common.c                |   2 +-
 arch/arm/mach-omap2/utils.c                      |   4 +-
 arch/arm/mach-rockchip/rk3128-board.c            |   2 +-
 arch/arm/mach-rockchip/rk322x-board.c            |   2 +-
 board/ti/common/Kconfig                          |   1 -
 cmd/Kconfig                                      |  14 +-
 cmd/fastboot.c                                   |  35 ++-
 cmd/net.c                                        |   6 +
 common/Makefile                                  |  13 --
 configs/am335x_boneblack_defconfig               |   2 +-
 configs/am335x_boneblack_vboot_defconfig         |   2 +-
 configs/am335x_evm_defconfig                     |   2 +-
 configs/am335x_evm_nor_defconfig                 |   2 +-
 configs/am335x_evm_norboot_defconfig             |   2 +-
 configs/am335x_evm_spiboot_defconfig             |   2 +-
 configs/am335x_evm_usbspl_defconfig              |   2 +-
 configs/am57xx_evm_defconfig                     |   2 +-
 configs/am57xx_hs_evm_defconfig                  |   2 +-
 configs/bcm23550_w1d_defconfig                   |   2 +-
 configs/bcm28155_ap_defconfig                    |   2 +-
 configs/birdland_bav335a_defconfig               |   2 +-
 configs/birdland_bav335b_defconfig               |   2 +-
 configs/cgtqmx6eval_defconfig                    |   2 +-
 configs/dra7xx_evm_defconfig                     |   2 +-
 configs/dra7xx_hs_evm_defconfig                  |   2 +-
 configs/kc1_defconfig                            |   2 +-
 configs/mx6qsabrelite_defconfig                  |   2 +-
 configs/mx6sabresd_defconfig                     |   2 +-
 configs/nitrogen6dl2g_defconfig                  |   2 +-
 configs/nitrogen6dl_defconfig                    |   2 +-
 configs/nitrogen6q2g_defconfig                   |   2 +-
 configs/nitrogen6q_defconfig                     |   2 +-
 configs/nitrogen6s1g_defconfig                   |   2 +-
 configs/nitrogen6s_defconfig                     |   2 +-
 configs/omap3_beagle_defconfig                   |   2 +-
 configs/omap3_evm_defconfig                      |   2 +-
 configs/omap3_logic_defconfig                    |   2 +-
 configs/sniper_defconfig                         |   2 +-
 configs/stih410-b2260_defconfig                  |   2 +-
 configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig |   2 +-
 configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig |   2 +-
 configs/xilinx_zynqmp_zcu102_rev1_0_defconfig    |   2 +-
 configs/xilinx_zynqmp_zcu102_revA_defconfig      |   2 +-
 configs/xilinx_zynqmp_zcu102_revB_defconfig      |   2 +-
 configs/xilinx_zynqmp_zcu106_revA_defconfig      |   2 +-
 drivers/Kconfig                                  |   2 +
 drivers/Makefile                                 |   1 +
 {cmd => drivers}/fastboot/Kconfig                |  46 ++--
 drivers/fastboot/Makefile                        |   9 +
 drivers/fastboot/fb_common.c                     | 136 ++++++++++++
 drivers/fastboot/fb_getvar.c                     |  96 +++++++++
 {common => drivers/fastboot}/fb_mmc.c            | 142 +++++++-----
 {common => drivers/fastboot}/fb_nand.c           |  31 +--
 drivers/fastboot/fb_packet.c                     | 249 +++++++++++++++++++++
 {common => drivers/fastboot}/image-sparse.c      |  41 ++--
 drivers/usb/gadget/f_fastboot.c                  | 133 ++----------
 include/fastboot.h                               |  65 +++++-
 include/fb_mmc.h                                 |   4 +-
 include/fb_nand.h                                |   4 +-
 include/image-sparse.h                           |   2 +-
 include/net.h                                    |   6 +-
 include/net/fastboot.h                           |  27 +++
 net/Makefile                                     |   1 +
 net/fastboot.c                                   | 262 +++++++++++++++++++++++
 net/net.c                                        |   9 +
 66 files changed, 1123 insertions(+), 296 deletions(-)
 rename {cmd => drivers}/fastboot/Kconfig (86%)
 create mode 100644 drivers/fastboot/Makefile
 create mode 100644 drivers/fastboot/fb_common.c
 create mode 100644 drivers/fastboot/fb_getvar.c
 rename {common => drivers/fastboot}/fb_mmc.c (71%)
 rename {common => drivers/fastboot}/fb_nand.c (86%)
 create mode 100644 drivers/fastboot/fb_packet.c
 rename {common => drivers/fastboot}/image-sparse.c (89%)
 create mode 100644 include/net/fastboot.h
 create mode 100644 net/fastboot.c

-- 
2.7.4

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 01/20] fastboot: Move fastboot to drivers/fastboot
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-04-30 23:12   ` Simon Glass
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 02/20] fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT Alex Kiernan
                   ` (19 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Separate CMD_FASTBOOT from FASTBOOT and move code and configuration to
drivers/fastboot.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 cmd/Kconfig                                 | 14 ++++++++++++--
 common/Makefile                             | 13 -------------
 drivers/Kconfig                             |  2 ++
 drivers/Makefile                            |  1 +
 {cmd => drivers}/fastboot/Kconfig           | 12 ------------
 drivers/fastboot/Makefile                   | 10 ++++++++++
 {common => drivers/fastboot}/fb_mmc.c       |  0
 {common => drivers/fastboot}/fb_nand.c      |  0
 {common => drivers/fastboot}/image-sparse.c |  0
 9 files changed, 25 insertions(+), 27 deletions(-)
 rename {cmd => drivers}/fastboot/Kconfig (91%)
 create mode 100644 drivers/fastboot/Makefile
 rename {common => drivers/fastboot}/fb_mmc.c (100%)
 rename {common => drivers/fastboot}/fb_nand.c (100%)
 rename {common => drivers/fastboot}/image-sparse.c (100%)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 225bb00..15361ff 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -137,8 +137,6 @@ config AUTOBOOT_STOP_STR_SHA256
 
 endmenu
 
-source "cmd/fastboot/Kconfig"
-
 config BUILD_BIN2C
 	bool
 
@@ -642,6 +640,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 USB_FUNCTION_FASTBOOT || UDP_FUNCTION_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 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
diff --git a/common/Makefile b/common/Makefile
index 7011dad..26f7fb1 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -111,19 +111,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/drivers/Kconfig b/drivers/Kconfig
index c2e813f..8424898 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -28,6 +28,8 @@ source "drivers/dfu/Kconfig"
 
 source "drivers/dma/Kconfig"
 
+source "drivers/fastboot/Kconfig"
+
 source "drivers/firmware/Kconfig"
 
 source "drivers/fpga/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 6846d18..78ec2f2 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -72,6 +72,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/cmd/fastboot/Kconfig b/drivers/fastboot/Kconfig
similarity index 91%
rename from cmd/fastboot/Kconfig
rename to drivers/fastboot/Kconfig
index 0d2c2f1..45600d2 100644
--- a/cmd/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -1,5 +1,3 @@
-comment "FASTBOOT"
-
 menuconfig FASTBOOT
 	bool "Fastboot support"
 	depends on USB_GADGET
@@ -16,16 +14,6 @@ config USB_FUNCTION_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
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
new file mode 100644
index 0000000..63a67c1
--- /dev/null
+++ b/drivers/fastboot/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier:      GPL-2.0+
+
+obj-$(CONFIG_FASTBOOT_FLASH) += 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
diff --git a/common/fb_mmc.c b/drivers/fastboot/fb_mmc.c
similarity index 100%
rename from common/fb_mmc.c
rename to drivers/fastboot/fb_mmc.c
diff --git a/common/fb_nand.c b/drivers/fastboot/fb_nand.c
similarity index 100%
rename from common/fb_nand.c
rename to drivers/fastboot/fb_nand.c
diff --git a/common/image-sparse.c b/drivers/fastboot/image-sparse.c
similarity index 100%
rename from common/image-sparse.c
rename to drivers/fastboot/image-sparse.c
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 02/20] fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 01/20] fastboot: Move fastboot to drivers/fastboot Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 18:19   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 03/20] fastboot: Refactor fastboot_okay/fail to take response Alex Kiernan
                   ` (18 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Anyone who wants FASTBOOT before this series wants USB_FUNCTION_FASTBOOT.
Split USB_FUNCTION_FASTBOOT from FASTBOOT so they retain their existing
behaviour.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 arch/arm/Kconfig                                 |  2 --
 board/ti/common/Kconfig                          |  1 -
 configs/am335x_boneblack_defconfig               |  2 +-
 configs/am335x_boneblack_vboot_defconfig         |  2 +-
 configs/am335x_evm_defconfig                     |  2 +-
 configs/am335x_evm_nor_defconfig                 |  2 +-
 configs/am335x_evm_norboot_defconfig             |  2 +-
 configs/am335x_evm_spiboot_defconfig             |  2 +-
 configs/am335x_evm_usbspl_defconfig              |  2 +-
 configs/am57xx_evm_defconfig                     |  2 +-
 configs/am57xx_hs_evm_defconfig                  |  2 +-
 configs/bcm23550_w1d_defconfig                   |  2 +-
 configs/bcm28155_ap_defconfig                    |  2 +-
 configs/birdland_bav335a_defconfig               |  2 +-
 configs/birdland_bav335b_defconfig               |  2 +-
 configs/cgtqmx6eval_defconfig                    |  2 +-
 configs/dra7xx_evm_defconfig                     |  2 +-
 configs/dra7xx_hs_evm_defconfig                  |  2 +-
 configs/kc1_defconfig                            |  2 +-
 configs/mx6qsabrelite_defconfig                  |  2 +-
 configs/mx6sabresd_defconfig                     |  2 +-
 configs/nitrogen6dl2g_defconfig                  |  2 +-
 configs/nitrogen6dl_defconfig                    |  2 +-
 configs/nitrogen6q2g_defconfig                   |  2 +-
 configs/nitrogen6q_defconfig                     |  2 +-
 configs/nitrogen6s1g_defconfig                   |  2 +-
 configs/nitrogen6s_defconfig                     |  2 +-
 configs/omap3_beagle_defconfig                   |  2 +-
 configs/omap3_evm_defconfig                      |  2 +-
 configs/omap3_logic_defconfig                    |  2 +-
 configs/sniper_defconfig                         |  2 +-
 configs/stih410-b2260_defconfig                  |  2 +-
 configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig |  2 +-
 configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig |  2 +-
 configs/xilinx_zynqmp_zcu102_rev1_0_defconfig    |  2 +-
 configs/xilinx_zynqmp_zcu102_revA_defconfig      |  2 +-
 configs/xilinx_zynqmp_zcu102_revB_defconfig      |  2 +-
 configs/xilinx_zynqmp_zcu106_revA_defconfig      |  2 +-
 drivers/fastboot/Kconfig                         | 14 +++++++-------
 39 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 35fcd24..9bf05d8 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1196,9 +1196,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
diff --git a/board/ti/common/Kconfig b/board/ti/common/Kconfig
index c21eb8c..b1956b8 100644
--- a/board/ti/common/Kconfig
+++ b/board/ti/common/Kconfig
@@ -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
diff --git a/configs/am335x_boneblack_defconfig b/configs/am335x_boneblack_defconfig
index 5c01b20..bd3a374 100644
--- a/configs/am335x_boneblack_defconfig
+++ b/configs/am335x_boneblack_defconfig
@@ -16,7 +16,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_FASTBOOT_FLASH=y
 CONFIG_FASTBOOT_FLASH_MMC_DEV=1
 CONFIG_CMD_SPL=y
diff --git a/configs/am335x_boneblack_vboot_defconfig b/configs/am335x_boneblack_vboot_defconfig
index abbacdc..baaae36 100644
--- a/configs/am335x_boneblack_vboot_defconfig
+++ b/configs/am335x_boneblack_vboot_defconfig
@@ -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
diff --git a/configs/am335x_evm_defconfig b/configs/am335x_evm_defconfig
index 6732013..cc556d1 100644
--- a/configs/am335x_evm_defconfig
+++ b/configs/am335x_evm_defconfig
@@ -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
diff --git a/configs/am335x_evm_nor_defconfig b/configs/am335x_evm_nor_defconfig
index bbde07f..41a5c79 100644
--- a/configs/am335x_evm_nor_defconfig
+++ b/configs/am335x_evm_nor_defconfig
@@ -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
diff --git a/configs/am335x_evm_norboot_defconfig b/configs/am335x_evm_norboot_defconfig
index 3ddcf64..75d0793 100644
--- a/configs/am335x_evm_norboot_defconfig
+++ b/configs/am335x_evm_norboot_defconfig
@@ -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"
diff --git a/configs/am335x_evm_spiboot_defconfig b/configs/am335x_evm_spiboot_defconfig
index 10eb0fe..b267887 100644
--- a/configs/am335x_evm_spiboot_defconfig
+++ b/configs/am335x_evm_spiboot_defconfig
@@ -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
diff --git a/configs/am335x_evm_usbspl_defconfig b/configs/am335x_evm_usbspl_defconfig
index dc9ac21..4401291 100644
--- a/configs/am335x_evm_usbspl_defconfig
+++ b/configs/am335x_evm_usbspl_defconfig
@@ -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
diff --git a/configs/am57xx_evm_defconfig b/configs/am57xx_evm_defconfig
index 0e99268..3b83b69 100644
--- a/configs/am57xx_evm_defconfig
+++ b/configs/am57xx_evm_defconfig
@@ -24,7 +24,7 @@ CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
 CONFIG_FASTBOOT_USB_DEV=1
diff --git a/configs/am57xx_hs_evm_defconfig b/configs/am57xx_hs_evm_defconfig
index 165c2a4..9c2aef4 100644
--- a/configs/am57xx_hs_evm_defconfig
+++ b/configs/am57xx_hs_evm_defconfig
@@ -29,7 +29,7 @@ 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_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
 CONFIG_FASTBOOT_USB_DEV=1
diff --git a/configs/bcm23550_w1d_defconfig b/configs/bcm23550_w1d_defconfig
index 9a986ca..de4fa60 100644
--- a/configs/bcm23550_w1d_defconfig
+++ b/configs/bcm23550_w1d_defconfig
@@ -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
diff --git a/configs/bcm28155_ap_defconfig b/configs/bcm28155_ap_defconfig
index d26cde5..4f7a58e 100644
--- a/configs/bcm28155_ap_defconfig
+++ b/configs/bcm28155_ap_defconfig
@@ -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
diff --git a/configs/birdland_bav335a_defconfig b/configs/birdland_bav335a_defconfig
index 51b3e6b..3efd566 100644
--- a/configs/birdland_bav335a_defconfig
+++ b/configs/birdland_bav335a_defconfig
@@ -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
diff --git a/configs/birdland_bav335b_defconfig b/configs/birdland_bav335b_defconfig
index 29b223a..2f98116 100644
--- a/configs/birdland_bav335b_defconfig
+++ b/configs/birdland_bav335b_defconfig
@@ -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
diff --git a/configs/cgtqmx6eval_defconfig b/configs/cgtqmx6eval_defconfig
index d4204aa..241e958 100644
--- a/configs/cgtqmx6eval_defconfig
+++ b/configs/cgtqmx6eval_defconfig
@@ -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
diff --git a/configs/dra7xx_evm_defconfig b/configs/dra7xx_evm_defconfig
index 9b81b0c..b766ba2 100644
--- a/configs/dra7xx_evm_defconfig
+++ b/configs/dra7xx_evm_defconfig
@@ -25,7 +25,7 @@ CONFIG_SPL_SEPARATE_BSS=y
 CONFIG_SPL_DMA_SUPPORT=y
 CONFIG_SPL_OS_BOOT=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
 CONFIG_FASTBOOT_FLASH=y
diff --git a/configs/dra7xx_hs_evm_defconfig b/configs/dra7xx_hs_evm_defconfig
index 536946e..39a6801 100644
--- a/configs/dra7xx_hs_evm_defconfig
+++ b/configs/dra7xx_hs_evm_defconfig
@@ -30,7 +30,7 @@ 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_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x82000000
 CONFIG_FASTBOOT_BUF_SIZE=0x2F000000
 CONFIG_FASTBOOT_FLASH=y
diff --git a/configs/kc1_defconfig b/configs/kc1_defconfig
index 534d604..ce71e37 100644
--- a/configs/kc1_defconfig
+++ b/configs/kc1_defconfig
@@ -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
diff --git a/configs/mx6qsabrelite_defconfig b/configs/mx6qsabrelite_defconfig
index e9d193c..159ff16 100644
--- a/configs/mx6qsabrelite_defconfig
+++ b/configs/mx6qsabrelite_defconfig
@@ -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
diff --git a/configs/mx6sabresd_defconfig b/configs/mx6sabresd_defconfig
index ca37d8b..5c8e9de 100644
--- a/configs/mx6sabresd_defconfig
+++ b/configs/mx6sabresd_defconfig
@@ -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
diff --git a/configs/nitrogen6dl2g_defconfig b/configs/nitrogen6dl2g_defconfig
index 6ef4226..cfb2ed8 100644
--- a/configs/nitrogen6dl2g_defconfig
+++ b/configs/nitrogen6dl2g_defconfig
@@ -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
diff --git a/configs/nitrogen6dl_defconfig b/configs/nitrogen6dl_defconfig
index b9784a2..9cb7ac2 100644
--- a/configs/nitrogen6dl_defconfig
+++ b/configs/nitrogen6dl_defconfig
@@ -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
diff --git a/configs/nitrogen6q2g_defconfig b/configs/nitrogen6q2g_defconfig
index 61688ba..e31521a 100644
--- a/configs/nitrogen6q2g_defconfig
+++ b/configs/nitrogen6q2g_defconfig
@@ -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
diff --git a/configs/nitrogen6q_defconfig b/configs/nitrogen6q_defconfig
index cfee7ba..85c352c 100644
--- a/configs/nitrogen6q_defconfig
+++ b/configs/nitrogen6q_defconfig
@@ -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
diff --git a/configs/nitrogen6s1g_defconfig b/configs/nitrogen6s1g_defconfig
index 0f29a56..1f37320 100644
--- a/configs/nitrogen6s1g_defconfig
+++ b/configs/nitrogen6s1g_defconfig
@@ -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
diff --git a/configs/nitrogen6s_defconfig b/configs/nitrogen6s_defconfig
index 7ad1584..0696f09 100644
--- a/configs/nitrogen6s_defconfig
+++ b/configs/nitrogen6s_defconfig
@@ -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
diff --git a/configs/omap3_beagle_defconfig b/configs/omap3_beagle_defconfig
index 7b81b03..05dc737 100644
--- a/configs/omap3_beagle_defconfig
+++ b/configs/omap3_beagle_defconfig
@@ -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
diff --git a/configs/omap3_evm_defconfig b/configs/omap3_evm_defconfig
index 20795c3..52285cc 100644
--- a/configs/omap3_evm_defconfig
+++ b/configs/omap3_evm_defconfig
@@ -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
diff --git a/configs/omap3_logic_defconfig b/configs/omap3_logic_defconfig
index 5a31e46..953980c 100644
--- a/configs/omap3_logic_defconfig
+++ b/configs/omap3_logic_defconfig
@@ -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
diff --git a/configs/sniper_defconfig b/configs/sniper_defconfig
index ad22a1c..70e485f 100644
--- a/configs/sniper_defconfig
+++ b/configs/sniper_defconfig
@@ -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
diff --git a/configs/stih410-b2260_defconfig b/configs/stih410-b2260_defconfig
index 67391bd..7d990f9 100644
--- a/configs/stih410-b2260_defconfig
+++ b/configs/stih410-b2260_defconfig
@@ -10,7 +10,7 @@ CONFIG_USE_BOOTARGS=y
 CONFIG_BOOTARGS="console=ttyAS1,115200 CONSOLE=/dev/ttyAS1 consoleblank=0 root=/dev/mmcblk0p2 rootfstype=ext4 rw rootwait mem=992M at 0x40000000 vmalloc=256m"
 # CONFIG_DISPLAY_CPUINFO is not set
 CONFIG_SYS_PROMPT="stih410-b2260 => "
-CONFIG_FASTBOOT=y
+CONFIG_USB_FUNCTION_FASTBOOT=y
 CONFIG_FASTBOOT_BUF_ADDR=0x40000000
 CONFIG_FASTBOOT_BUF_SIZE=0x3DF00000
 CONFIG_FASTBOOT_FLASH=y
diff --git a/configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig b/configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig
index 0272eea..917f842 100644
--- a/configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig
+++ b/configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig
@@ -21,7 +21,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_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
diff --git a/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig b/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig
index 2758bfb..1cdfe07 100644
--- a/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig
+++ b/configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig
@@ -22,7 +22,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
diff --git a/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig b/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig
index 68da9dc..bb8d6a3 100644
--- a/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig
+++ b/configs/xilinx_zynqmp_zcu102_rev1_0_defconfig
@@ -21,7 +21,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_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
diff --git a/configs/xilinx_zynqmp_zcu102_revA_defconfig b/configs/xilinx_zynqmp_zcu102_revA_defconfig
index 2adba61..688ba92 100644
--- a/configs/xilinx_zynqmp_zcu102_revA_defconfig
+++ b/configs/xilinx_zynqmp_zcu102_revA_defconfig
@@ -21,7 +21,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_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
diff --git a/configs/xilinx_zynqmp_zcu102_revB_defconfig b/configs/xilinx_zynqmp_zcu102_revB_defconfig
index 2310fa8..6175665 100644
--- a/configs/xilinx_zynqmp_zcu102_revB_defconfig
+++ b/configs/xilinx_zynqmp_zcu102_revB_defconfig
@@ -21,7 +21,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_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
diff --git a/configs/xilinx_zynqmp_zcu106_revA_defconfig b/configs/xilinx_zynqmp_zcu106_revA_defconfig
index 8c9a60d..dc88c94 100644
--- a/configs/xilinx_zynqmp_zcu106_revA_defconfig
+++ b/configs/xilinx_zynqmp_zcu106_revA_defconfig
@@ -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_FASTBOOT_FLASH_MMC_DEV=0
 CONFIG_CMD_THOR_DOWNLOAD=y
diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index 45600d2..eee866a 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -1,13 +1,13 @@
-menuconfig FASTBOOT
-	bool "Fastboot support"
-	depends on USB_GADGET
-	default y if ARCH_SUNXI && USB_MUSB_GADGET
+menu "Fastboot support"
 
-if FASTBOOT
+config FASTBOOT
+	bool
 
 config USB_FUNCTION_FASTBOOT
 	bool "Enable USB fastboot gadget"
-	default y
+	depends on USB_GADGET
+	default y if ARCH_SUNXI && USB_MUSB_GADGET
+	select FASTBOOT
 	select USB_GADGET_DOWNLOAD
 	imply ANDROID_BOOT_IMAGE
 	imply CMD_FASTBOOT
@@ -119,4 +119,4 @@ config FASTBOOT_MBR_NAME
 
 endif # USB_FUNCTION_FASTBOOT
 
-endif # FASTBOOT
+endmenu
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 03/20] fastboot: Refactor fastboot_okay/fail to take response
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 01/20] fastboot: Move fastboot to drivers/fastboot Alex Kiernan
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 02/20] fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 18:24   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 04/20] fastboot: Extract fastboot_okay/fail to fb_common.c Alex Kiernan
                   ` (17 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Add the response string as a parameter to fastboot_okay/fail, instead
of modifying a global, to match the contract expected by the AOSP
U-Boot code.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_mmc.c       | 80 ++++++++++++++++++++++-------------------
 drivers/fastboot/fb_nand.c      | 31 ++++++++--------
 drivers/fastboot/image-sparse.c | 41 +++++++++++----------
 drivers/usb/gadget/f_fastboot.c | 35 +++++++-----------
 include/fastboot.h              |  4 +--
 include/fb_mmc.h                |  4 +--
 include/fb_nand.h               |  4 +--
 include/image-sparse.h          |  2 +-
 8 files changed, 100 insertions(+), 101 deletions(-)

diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index cf5b77c..02864aa 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -74,7 +74,7 @@ static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
 
 static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
 		const char *part_name, void *buffer,
-		unsigned int download_bytes)
+		unsigned int download_bytes, char *response)
 {
 	lbaint_t blkcnt;
 	lbaint_t blks;
@@ -85,7 +85,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
 
 	if (blkcnt > info->size) {
 		pr_err("too large for partition: '%s'\n", part_name);
-		fastboot_fail("too large for partition");
+		fastboot_fail("too large for partition", response);
 		return;
 	}
 
@@ -94,13 +94,13 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
 	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");
+		fastboot_fail("failed writing to device", response);
 		return;
 	}
 
 	printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
 	       part_name);
-	fastboot_okay("");
+	fastboot_okay("", response);
 }
 
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
@@ -115,7 +115,8 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
  */
 static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 				       disk_partition_t *info,
-				       struct andr_img_hdr *hdr)
+				       struct andr_img_hdr *hdr,
+				       char *response)
 {
 	ulong sector_size;		/* boot partition sector size */
 	lbaint_t hdr_sectors;		/* boot image header sectors count */
@@ -126,7 +127,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 	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");
+		fastboot_fail("invalid number of boot sectors: 0", response);
 		return 0;
 	}
 
@@ -134,7 +135,8 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 	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");
+		fastboot_fail("cannot read header from boot partition",
+			      response);
 		return 0;
 	}
 
@@ -142,7 +144,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 	res = android_image_check_header(hdr);
 	if (res != 0) {
 		pr_err("bad boot image magic");
-		fastboot_fail("boot partition not initialized");
+		fastboot_fail("boot partition not initialized", response);
 		return 0;
 	}
 
@@ -160,7 +162,8 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
  */
 static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 				void *download_buffer,
-				unsigned int download_bytes)
+				unsigned int download_bytes,
+				char *response)
 {
 	uintptr_t hdr_addr;			/* boot image header address */
 	struct andr_img_hdr *hdr;		/* boot image header */
@@ -180,7 +183,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	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");
+		fastboot_fail("cannot find boot partition", response);
 		return -1;
 	}
 
@@ -189,17 +192,18 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	hdr = (struct andr_img_hdr *)hdr_addr;
 
 	/* Read boot image header */
-	hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr);
+	hdr_sectors = fb_mmc_get_boot_header(dev_desc, &info, hdr, response);
 	if (hdr_sectors == 0) {
 		pr_err("unable to read boot image header");
-		fastboot_fail("unable to read boot image header");
+		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");
-		fastboot_fail("moving second stage is not supported yet");
+		fastboot_fail("moving second stage is not supported yet",
+			      response);
 		return -1;
 	}
 
@@ -217,7 +221,8 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 			ramdisk_buffer);
 	if (res != ramdisk_sectors) {
 		pr_err("cannot read ramdisk from boot partition");
-		fastboot_fail("cannot read ramdisk from boot partition");
+		fastboot_fail("cannot read ramdisk from boot partition",
+			      response);
 		return -1;
 	}
 
@@ -226,7 +231,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	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");
+		fastboot_fail("cannot write back boot image header", response);
 		return -1;
 	}
 
@@ -238,7 +243,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 			 download_buffer);
 	if (res == 0) {
 		pr_err("cannot write new kernel");
-		fastboot_fail("cannot write new kernel");
+		fastboot_fail("cannot write new kernel", response);
 		return -1;
 	}
 
@@ -250,18 +255,18 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 			 ramdisk_buffer);
 	if (res == 0) {
 		pr_err("cannot write back original ramdisk");
-		fastboot_fail("cannot write back original ramdisk");
+		fastboot_fail("cannot write back original ramdisk", response);
 		return -1;
 	}
 
 	puts("........ zImage was updated in boot partition\n");
-	fastboot_okay("");
+	fastboot_okay("", response);
 	return 0;
 }
 #endif
 
 void fb_mmc_flash_write(const char *cmd, void *download_buffer,
-			unsigned int download_bytes)
+			unsigned int download_bytes, char *response)
 {
 	struct blk_desc *dev_desc;
 	disk_partition_t info;
@@ -269,7 +274,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 	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");
+		fastboot_fail("invalid mmc device", response);
 		return;
 	}
 
@@ -280,16 +285,17 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 		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");
+			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");
+			fastboot_fail("writing GPT partitions failed",
+				      response);
 			return;
 		}
 		printf("........ success\n");
-		fastboot_okay("");
+		fastboot_okay("", response);
 		return;
 	}
 #endif
@@ -300,30 +306,32 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 		if (is_valid_dos_buf(download_buffer)) {
 			printf("%s: invalid MBR - refusing to write to flash\n",
 			       __func__);
-			fastboot_fail("invalid MBR partition");
+			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");
+			fastboot_fail("writing MBR partition failed",
+				      response);
 			return;
 		}
 		printf("........ success\n");
-		fastboot_okay("");
+		fastboot_okay("", response);
 		return;
 	}
 #endif
 
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
 	if (strncasecmp(cmd, "zimage", 6) == 0) {
-		fb_mmc_update_zimage(dev_desc, download_buffer, download_bytes);
+		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");
+		fastboot_fail("cannot find partition", response);
 		return;
 	}
 
@@ -344,14 +352,14 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 
 		sparse.priv = &sparse_priv;
 		write_sparse_image(&sparse, cmd, download_buffer,
-				   download_bytes);
+				   download_bytes, response);
 	} else {
 		write_raw_image(dev_desc, &info, cmd, download_buffer,
-				download_bytes);
+				download_bytes, response);
 	}
 }
 
-void fb_mmc_erase(const char *cmd)
+void fb_mmc_erase(const char *cmd, char *response)
 {
 	int ret;
 	struct blk_desc *dev_desc;
@@ -361,21 +369,21 @@ void fb_mmc_erase(const char *cmd)
 
 	if (mmc == NULL) {
 		pr_err("invalid mmc device");
-		fastboot_fail("invalid mmc device");
+		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");
-		fastboot_fail("invalid mmc device");
+		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'", cmd);
-		fastboot_fail("cannot find partition");
+		fastboot_fail("cannot find partition", response);
 		return;
 	}
 
@@ -394,11 +402,11 @@ void fb_mmc_erase(const char *cmd)
 	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");
+		fastboot_fail("failed erasing from device", response);
 		return;
 	}
 
 	printf("........ erased " LBAFU " bytes from '%s'\n",
 	       blks_size * info.blksz, cmd);
-	fastboot_okay("");
+	fastboot_okay("", response);
 }
diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
index aa28046..3a0b101 100644
--- a/drivers/fastboot/fb_nand.c
+++ b/drivers/fastboot/fb_nand.c
@@ -32,7 +32,8 @@ __weak int board_fastboot_write_partition_setup(char *name)
 
 static int fb_nand_lookup(const char *partname,
 			  struct mtd_info **mtd,
-			  struct part_info **part)
+			  struct part_info **part,
+			  char *response)
 {
 	struct mtd_device *dev;
 	int ret;
@@ -41,21 +42,21 @@ static int fb_nand_lookup(const char *partname,
 	ret = mtdparts_init();
 	if (ret) {
 		pr_err("Cannot initialize MTD partitions\n");
-		fastboot_fail("cannot init mtdparts");
+		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");
+		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");
+		fastboot_fail("not a NAND device", response);
 		return -EINVAL;
 	}
 
@@ -146,16 +147,16 @@ static lbaint_t fb_nand_sparse_reserve(struct sparse_storage *info,
 }
 
 void fb_nand_flash_write(const char *cmd, void *download_buffer,
-			 unsigned int download_bytes)
+			 unsigned int download_bytes, char *response)
 {
 	struct part_info *part;
 	struct mtd_info *mtd = NULL;
 	int ret;
 
-	ret = fb_nand_lookup(cmd, &mtd, &part);
+	ret = fb_nand_lookup(cmd, &mtd, &part, response);
 	if (ret) {
 		pr_err("invalid NAND device");
-		fastboot_fail("invalid NAND device");
+		fastboot_fail("invalid NAND device", response);
 		return;
 	}
 
@@ -181,7 +182,7 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer,
 
 		sparse.priv = &sparse_priv;
 		write_sparse_image(&sparse, cmd, download_buffer,
-				   download_bytes);
+				   download_bytes, response);
 	} else {
 		printf("Flashing raw image at offset 0x%llx\n",
 		       part->offset);
@@ -194,23 +195,23 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer,
 	}
 
 	if (ret) {
-		fastboot_fail("error writing the image");
+		fastboot_fail("error writing the image", response);
 		return;
 	}
 
-	fastboot_okay("");
+	fastboot_okay("", response);
 }
 
-void fb_nand_erase(const char *cmd)
+void fb_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);
+	ret = fb_nand_lookup(cmd, &mtd, &part, response);
 	if (ret) {
 		pr_err("invalid NAND device");
-		fastboot_fail("invalid NAND device");
+		fastboot_fail("invalid NAND device", response);
 		return;
 	}
 
@@ -221,9 +222,9 @@ void fb_nand_erase(const char *cmd)
 	ret = _fb_nand_erase(mtd, part);
 	if (ret) {
 		pr_err("failed erasing from device %s", mtd->name);
-		fastboot_fail("failed erasing from device");
+		fastboot_fail("failed erasing from device", response);
 		return;
 	}
 
-	fastboot_okay("");
+	fastboot_okay("", response);
 }
diff --git a/drivers/fastboot/image-sparse.c b/drivers/fastboot/image-sparse.c
index ddf5772..616c2bd 100644
--- a/drivers/fastboot/image-sparse.c
+++ b/drivers/fastboot/image-sparse.c
@@ -51,7 +51,7 @@
 
 void write_sparse_image(
 		struct sparse_storage *info, const char *part_name,
-		void *data, unsigned sz)
+		void *data, unsigned int sz, char *response)
 {
 	lbaint_t blk;
 	lbaint_t blkcnt;
@@ -101,7 +101,7 @@ void write_sparse_image(
 	if (offset) {
 		printf("%s: Sparse image block size issue [%u]\n",
 		       __func__, sparse_header->blk_sz);
-		fastboot_fail("sparse image block size issue");
+		fastboot_fail("sparse image block size issue", response);
 		return;
 	}
 
@@ -136,8 +136,8 @@ void write_sparse_image(
 		case CHUNK_TYPE_RAW:
 			if (chunk_header->total_sz !=
 			    (sparse_header->chunk_hdr_sz + chunk_data_sz)) {
-				fastboot_fail(
-					"Bogus chunk size for chunk type Raw");
+				fastboot_fail("Bogus chunk size for chunk type Raw",
+					      response);
 				return;
 			}
 
@@ -145,8 +145,8 @@ void write_sparse_image(
 				printf(
 				    "%s: Request would exceed partition size!\n",
 				    __func__);
-				fastboot_fail(
-				    "Request would exceed partition size!");
+				fastboot_fail("Request would exceed partition size!",
+					      response);
 				return;
 			}
 
@@ -156,8 +156,7 @@ void write_sparse_image(
 				printf("%s: %s" LBAFU " [" LBAFU "]\n",
 				       __func__, "Write failed, block #",
 				       blk, blks);
-				fastboot_fail(
-					      "flash write failure");
+				fastboot_fail("flash write failure", response);
 				return;
 			}
 			blk += blks;
@@ -169,8 +168,8 @@ void write_sparse_image(
 		case CHUNK_TYPE_FILL:
 			if (chunk_header->total_sz !=
 			    (sparse_header->chunk_hdr_sz + sizeof(uint32_t))) {
-				fastboot_fail(
-					"Bogus chunk size for chunk type FILL");
+				fastboot_fail("Bogus chunk size for chunk type FILL",
+					      response);
 				return;
 			}
 
@@ -180,8 +179,8 @@ void write_sparse_image(
 						info->blksz * fill_buf_num_blks,
 						ARCH_DMA_MINALIGN));
 			if (!fill_buf) {
-				fastboot_fail(
-					"Malloc failed for: CHUNK_TYPE_FILL");
+				fastboot_fail("Malloc failed for: CHUNK_TYPE_FILL",
+					      response);
 				return;
 			}
 
@@ -198,8 +197,8 @@ void write_sparse_image(
 				printf(
 				    "%s: Request would exceed partition size!\n",
 				    __func__);
-				fastboot_fail(
-				    "Request would exceed partition size!");
+				fastboot_fail("Request would exceed partition size!",
+					      response);
 				return;
 			}
 
@@ -214,8 +213,8 @@ void write_sparse_image(
 					       __func__,
 					       "Write failed, block #",
 					       blk, j);
-					fastboot_fail(
-						      "flash write failure");
+					fastboot_fail("flash write failure",
+						      response);
 					free(fill_buf);
 					return;
 				}
@@ -235,8 +234,8 @@ void write_sparse_image(
 		case CHUNK_TYPE_CRC32:
 			if (chunk_header->total_sz !=
 			    sparse_header->chunk_hdr_sz) {
-				fastboot_fail(
-					"Bogus chunk size for chunk type Dont Care");
+				fastboot_fail("Bogus chunk size for chunk type Dont Care",
+					      response);
 				return;
 			}
 			total_blocks += chunk_header->chunk_sz;
@@ -246,7 +245,7 @@ void write_sparse_image(
 		default:
 			printf("%s: Unknown chunk type: %x\n", __func__,
 			       chunk_header->chunk_type);
-			fastboot_fail("Unknown chunk type");
+			fastboot_fail("Unknown chunk type", response);
 			return;
 		}
 	}
@@ -256,9 +255,9 @@ void write_sparse_image(
 	printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name);
 
 	if (total_blocks != sparse_header->total_blks)
-		fastboot_fail("sparse image write failure");
+		fastboot_fail("sparse image write failure", response);
 	else
-		fastboot_okay("");
+		fastboot_okay("", response);
 
 	return;
 }
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 7acffb6..6ae1d97 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -151,18 +151,16 @@ 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)
+void fastboot_fail(const char *reason, char *response)
 {
-	strncpy(fb_response_str, "FAIL\0", 5);
-	strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+	strncpy(response, "FAIL\0", 5);
+	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
 }
 
-void fastboot_okay(const char *reason)
+void fastboot_okay(const char *reason, char *response)
 {
-	strncpy(fb_response_str, "OKAY\0", 5);
-	strncat(fb_response_str, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+	strncpy(response, "OKAY\0", 5);
+	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
 }
 
 static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
@@ -598,18 +596,14 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req)
 		return;
 	}
 
-	/* initialize the response buffer */
-	fb_response_str = response;
-
-	fastboot_fail("no flash device defined");
+	fastboot_fail("no flash device defined", response);
 #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
 	fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
-			   download_bytes);
+			   download_bytes, response);
 #endif
 #ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
-	fb_nand_flash_write(cmd,
-			    (void *)CONFIG_FASTBOOT_BUF_ADDR,
-			    download_bytes);
+	fb_nand_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
+			    download_bytes, response);
 #endif
 	fastboot_tx_write_str(response);
 }
@@ -650,15 +644,12 @@ static void cb_erase(struct usb_ep *ep, struct usb_request *req)
 		return;
 	}
 
-	/* initialize the response buffer */
-	fb_response_str = response;
-
-	fastboot_fail("no flash device defined");
+	fastboot_fail("no flash device defined", response);
 #ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
-	fb_mmc_erase(cmd);
+	fb_mmc_erase(cmd, response);
 #endif
 #ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
-	fb_nand_erase(cmd);
+	fb_nand_erase(cmd, response);
 #endif
 	fastboot_tx_write_str(response);
 }
diff --git a/include/fastboot.h b/include/fastboot.h
index 616631e..f22080a 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -16,7 +16,7 @@
 /* The 64 defined bytes plus \0 */
 #define FASTBOOT_RESPONSE_LEN	(64 + 1)
 
-void fastboot_fail(const char *reason);
-void fastboot_okay(const char *reason);
+void fastboot_fail(const char *reason, char *response);
+void fastboot_okay(const char *reason, char *response);
 
 #endif /* _FASTBOOT_H_ */
diff --git a/include/fb_mmc.h b/include/fb_mmc.h
index 12b99cb..402ba9b 100644
--- a/include/fb_mmc.h
+++ b/include/fb_mmc.h
@@ -5,5 +5,5 @@
  */
 
 void fb_mmc_flash_write(const char *cmd, void *download_buffer,
-			unsigned int download_bytes);
-void fb_mmc_erase(const char *cmd);
+			unsigned int download_bytes, char *response);
+void fb_mmc_erase(const char *cmd, char *response);
diff --git a/include/fb_nand.h b/include/fb_nand.h
index aaf7cf7..88bdf36 100644
--- a/include/fb_nand.h
+++ b/include/fb_nand.h
@@ -6,5 +6,5 @@
  */
 
 void fb_nand_flash_write(const char *cmd, void *download_buffer,
-			 unsigned int download_bytes);
-void fb_nand_erase(const char *cmd);
+			 unsigned int download_bytes, char *response);
+void fb_nand_erase(const char *cmd, char *response);
diff --git a/include/image-sparse.h b/include/image-sparse.h
index b0cc500..02453c8 100644
--- a/include/image-sparse.h
+++ b/include/image-sparse.h
@@ -37,4 +37,4 @@ static inline int is_sparse_image(void *buf)
 }
 
 void write_sparse_image(struct sparse_storage *info, const char *part_name,
-			void *data, unsigned sz);
+			void *data, unsigned int sz, char *response);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 04/20] fastboot: Extract fastboot_okay/fail to fb_common.c
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (2 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 03/20] fastboot: Refactor fastboot_okay/fail to take response Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 18:26   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 05/20] fastboot: Introduce fastboot_response and refactor fastboot_okay/fail Alex Kiernan
                   ` (16 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Add drivers/fastboot/fb_common.c, where fastboot_okay/fail are implemented
so we can call them from a non-USB implementation.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/Makefile       |  1 +
 drivers/fastboot/fb_common.c    | 26 ++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c | 13 -------------
 3 files changed, 27 insertions(+), 13 deletions(-)
 create mode 100644 drivers/fastboot/fb_common.c

diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index 63a67c1..5b8337f 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier:      GPL-2.0+
 
+obj-y += fb_common.o
 obj-$(CONFIG_FASTBOOT_FLASH) += image-sparse.o
 
 ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
new file mode 100644
index 0000000..53cffe3
--- /dev/null
+++ b/drivers/fastboot/fb_common.c
@@ -0,0 +1,26 @@
+// 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>
+
+void fastboot_fail(const char *reason, char *response)
+{
+	strncpy(response, "FAIL\0", 5);
+	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+}
+
+void fastboot_okay(const char *reason, char *response)
+{
+	strncpy(response, "OKAY\0", 5);
+	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 6ae1d97..fda4505 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -150,19 +150,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);
 
-
-void fastboot_fail(const char *reason, char *response)
-{
-	strncpy(response, "FAIL\0", 5);
-	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
-}
-
-void fastboot_okay(const char *reason, char *response)
-{
-	strncpy(response, "OKAY\0", 5);
-	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
-}
-
 static void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
 {
 	int status = req->status;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 05/20] fastboot: Introduce fastboot_response and refactor fastboot_okay/fail
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (3 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 04/20] fastboot: Extract fastboot_okay/fail to fb_common.c Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 18:28   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 06/20] fastboot: Correct dependencies in FASTBOOT_FLASH Alex Kiernan
                   ` (15 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Introduce fastboot_response which takes varargs parameters so we can
use it to generate formatted response strings. Refactor fastboot_okay/fail
to use it.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_common.c | 28 ++++++++++++++++++++++++----
 include/fastboot.h           |  4 ++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 53cffe3..fe58803 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -13,14 +13,34 @@
 #include <common.h>
 #include <fastboot.h>
 
+/**
+ * Writes a response to response buffer of the form "$tag$reason".
+ *
+ * @param tag		The first part of the response
+ * @param response	Pointer to fastboot response buffer
+ * @param 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);
+	}
+}
+
 void fastboot_fail(const char *reason, char *response)
 {
-	strncpy(response, "FAIL\0", 5);
-	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+	fastboot_response("FAIL", response, "%s", reason);
 }
 
 void fastboot_okay(const char *reason, char *response)
 {
-	strncpy(response, "OKAY\0", 5);
-	strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+	fastboot_response("OKAY", response, "%s", reason);
 }
diff --git a/include/fastboot.h b/include/fastboot.h
index f22080a..2140c94 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -16,6 +16,10 @@
 /* The 64 defined bytes plus \0 */
 #define FASTBOOT_RESPONSE_LEN	(64 + 1)
 
+void fastboot_response(const char *tag, char *response,
+		       const char *format, ...)
+	__attribute__ ((format (__printf__, 3, 4)));
+
 void fastboot_fail(const char *reason, char *response);
 void fastboot_okay(const char *reason, char *response);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 06/20] fastboot: Correct dependencies in FASTBOOT_FLASH
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (4 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 05/20] fastboot: Introduce fastboot_response and refactor fastboot_okay/fail Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 18:34   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot Alex Kiernan
                   ` (14 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Ensure that when selecting FASTBOOT_FLASH you end up with a buildable
configuration. Prior to this you could select NAND without MTDPARTS
and end up with an image which (surprisingly) excluded NAND.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 arch/arm/mach-omap2/utils.c     |  4 ++--
 drivers/fastboot/Kconfig        |  8 ++++----
 drivers/fastboot/Makefile       |  8 ++------
 drivers/usb/gadget/f_fastboot.c | 14 +++++++-------
 4 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-omap2/utils.c b/arch/arm/mach-omap2/utils.c
index 1d39625..28ca0e8 100644
--- a/arch/arm/mach-omap2/utils.c
+++ b/arch/arm/mach-omap2/utils.c
@@ -84,7 +84,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;
@@ -127,7 +127,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();
diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index eee866a..64b94f0 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -55,6 +55,7 @@ config FASTBOOT_USB_DEV
 config FASTBOOT_FLASH
 	bool "Enable FASTBOOT FLASH command"
 	default y if ARCH_SUNXI
+	depends on MMC || (NAND && CMD_MTDPARTS)
 	help
 	  The fastboot protocol includes a "flash" command for writing
 	  the downloaded image to a non-volatile storage device. Define
@@ -70,7 +71,7 @@ config FASTBOOT_FLASH_MMC
 
 config FASTBOOT_FLASH_NAND
 	bool "FASTBOOT on NAND"
-	depends on NAND
+	depends on NAND && CMD_MTDPARTS
 
 endchoice
 
@@ -87,7 +88,6 @@ config FASTBOOT_FLASH_MMC_DEV
 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
@@ -96,7 +96,7 @@ config FASTBOOT_FLASH_NAND_DEV
 
 config FASTBOOT_GPT_NAME
 	string "Target name for updating GPT"
-	depends on FASTBOOT_FLASH
+	depends on FASTBOOT_FLASH_MMC
 	default "gpt"
 	help
 	  The fastboot "flash" command supports writing the downloaded
@@ -109,7 +109,7 @@ config FASTBOOT_GPT_NAME
 
 config FASTBOOT_MBR_NAME
 	string "Target name for updating MBR"
-	depends on FASTBOOT_FLASH
+	depends on FASTBOOT_FLASH_MMC
 	default "mbr"
 	help
 	  The fastboot "flash" command allows to write the downloaded image
diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index 5b8337f..c12dfa8 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -3,9 +3,5 @@
 obj-y += fb_common.o
 obj-$(CONFIG_FASTBOOT_FLASH) += 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
+obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o
+obj-$(CONFIG_FASTBOOT_FLASH_NAND) += fb_nand.o
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index fda4505..e757c3e 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -21,10 +21,10 @@
 #include <linux/compiler.h>
 #include <version.h>
 #include <g_dnl.h>
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_MMC
 #include <fb_mmc.h>
 #endif
-#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_NAND
 #include <fb_nand.h>
 #endif
 
@@ -584,11 +584,11 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req)
 	}
 
 	fastboot_fail("no flash device defined", response);
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_MMC
 	fb_mmc_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
 			   download_bytes, response);
 #endif
-#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_NAND
 	fb_nand_flash_write(cmd, (void *)CONFIG_FASTBOOT_BUF_ADDR,
 			    download_bytes, response);
 #endif
@@ -599,7 +599,7 @@ static void cb_flash(struct usb_ep *ep, struct usb_request *req)
 static void cb_oem(struct usb_ep *ep, struct usb_request *req)
 {
 	char *cmd = req->buf;
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_MMC
 	if (strncmp("format", cmd + 4, 6) == 0) {
 		char cmdbuf[32];
                 sprintf(cmdbuf, "gpt write mmc %x $partitions",
@@ -632,10 +632,10 @@ static void cb_erase(struct usb_ep *ep, struct usb_request *req)
 	}
 
 	fastboot_fail("no flash device defined", response);
-#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_MMC
 	fb_mmc_erase(cmd, response);
 #endif
-#ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV
+#ifdef CONFIG_FASTBOOT_FLASH_NAND
 	fb_nand_erase(cmd, response);
 #endif
 	fastboot_tx_write_str(response);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (5 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 06/20] fastboot: Correct dependencies in FASTBOOT_FLASH Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-01  6:28   ` Jocelyn Bohr
  2018-05-03 20:38   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 08/20] net: fastboot: Support building without MMC Alex Kiernan
                   ` (13 subsequent siblings)
  20 siblings, 2 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Merge UDP fastboot support from AOSP:

https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
Signed-off-by: Alex Deymo <deymo@google.com>
---

Changes in v2:
- ensure fastboot syntax is backward compatible - 'fastboot 0' means
  'fastboot usb 0'

 cmd/fastboot.c               |  35 ++-
 cmd/net.c                    |   6 +
 drivers/fastboot/Kconfig     |  16 +-
 drivers/fastboot/fb_common.c |  18 ++
 drivers/fastboot/fb_mmc.c    |  34 ++-
 include/fastboot.h           |  13 ++
 include/net.h                |   6 +-
 include/net/fastboot.h       |  27 +++
 net/Makefile                 |   1 +
 net/fastboot.c               | 542 +++++++++++++++++++++++++++++++++++++++++++
 net/net.c                    |   9 +
 11 files changed, 695 insertions(+), 12 deletions(-)
 create mode 100644 include/net/fastboot.h
 create mode 100644 net/fastboot.c

diff --git a/cmd/fastboot.c b/cmd/fastboot.c
index 8adcca5..68a41de 100644
--- a/cmd/fastboot.c
+++ b/cmd/fastboot.c
@@ -11,17 +11,41 @@
 #include <command.h>
 #include <console.h>
 #include <g_dnl.h>
+#include <net.h>
 #include <usb.h>
 
 static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
+#ifdef CONFIG_USB_FUNCTION_FASTBOOT
 	int controller_index;
 	char *usb_controller;
 	int ret;
+#endif
 
 	if (argc < 2)
 		return CMD_RET_USAGE;
 
+	if (!strcmp(argv[1], "udp")) {
+#ifndef CONFIG_UDP_FUNCTION_FASTBOOT
+		pr_err("Fastboot UDP not enabled\n");
+		return -1;
+#else
+		return do_fastboot_udp(cmdtp, flag, argc, argv);
+#endif
+	}
+
+	if (!strcmp(argv[1], "usb")) {
+		argv++;
+		argc--;
+	}
+
+	if (argc < 2)
+		return CMD_RET_USAGE;
+
+#ifndef CONFIG_USB_FUNCTION_FASTBOOT
+	pr_err("Fastboot USB not enabled\n");
+	return -1;
+#else
 	usb_controller = argv[1];
 	controller_index = simple_strtoul(usb_controller, NULL, 0);
 
@@ -59,11 +83,14 @@ exit:
 	board_usb_cleanup(controller_index, USB_INIT_DEVICE);
 
 	return ret;
+#endif
 }
 
 U_BOOT_CMD(
-	fastboot, 2, 1, do_fastboot,
-	"use USB Fastboot protocol",
-	"<USB_controller>\n"
-	"    - run as a fastboot usb device"
+	fastboot, 3, 1, do_fastboot,
+	"use USB or UDP Fastboot protocol",
+	"[usb,udp] <USB_controller>\n"
+	" - run as a fastboot usb or udp device\n"
+	"   usb: specify <USB_controller>\n"
+	"   udp: requires ip_addr set and ethernet initialized\n"
 );
diff --git a/cmd/net.c b/cmd/net.c
index 67888d4..668f344 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -74,6 +74,12 @@ U_BOOT_CMD(
 );
 #endif
 
+#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
+int do_fastboot_udp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	return netboot_common(FASTBOOT, cmdtp, argc, argv);
+}
+#endif
 
 #ifdef CONFIG_CMD_RARP
 int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
index 64b94f0..53c337f 100644
--- a/drivers/fastboot/Kconfig
+++ b/drivers/fastboot/Kconfig
@@ -2,6 +2,8 @@ menu "Fastboot support"
 
 config FASTBOOT
 	bool
+	imply ANDROID_BOOT_IMAGE
+	imply CMD_FASTBOOT
 
 config USB_FUNCTION_FASTBOOT
 	bool "Enable USB fastboot gadget"
@@ -9,12 +11,17 @@ config USB_FUNCTION_FASTBOOT
 	default y if ARCH_SUNXI && USB_MUSB_GADGET
 	select FASTBOOT
 	select USB_GADGET_DOWNLOAD
-	imply ANDROID_BOOT_IMAGE
-	imply CMD_FASTBOOT
 	help
 	  This enables the USB part of the fastboot gadget.
 
-if USB_FUNCTION_FASTBOOT
+config UDP_FUNCTION_FASTBOOT
+	depends on NET
+	select FASTBOOT
+	bool "Enable fastboot protocol over UDP"
+	help
+	  This enables the fastboot protocol over UDP.
+
+if USB_FUNCTION_FASTBOOT || UDP_FUNCTION_FASTBOOT
 
 config FASTBOOT_BUF_ADDR
 	hex "Define FASTBOOT buffer address"
@@ -46,6 +53,7 @@ config FASTBOOT_BUF_SIZE
 
 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
@@ -117,6 +125,6 @@ config FASTBOOT_MBR_NAME
 	  specified on the "fastboot flash" command line matches the value
 	  defined here. The default target name for updating MBR is "mbr".
 
-endif # USB_FUNCTION_FASTBOOT
+endif # USB_FUNCTION_FASTBOOT || UDP_FUNCTION_FASTBOOT
 
 endmenu
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index fe58803..7367fbb 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -12,6 +12,9 @@
 
 #include <common.h>
 #include <fastboot.h>
+#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
+#include <net/fastboot.h>
+#endif
 
 /**
  * Writes a response to response buffer of the form "$tag$reason".
@@ -44,3 +47,18 @@ void fastboot_okay(const char *reason, char *response)
 {
 	fastboot_response("OKAY", response, "%s", reason);
 }
+
+void timed_send_info(ulong *start, const char *msg)
+{
+#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
+	/* 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_send_info(msg);
+	}
+#endif
+}
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 02864aa..304bda1 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -29,6 +29,9 @@
 #define CONFIG_FASTBOOT_MBR_NAME "mbr"
 #endif
 
+#define FASTBOOT_MAX_BLK_WRITE 16384
+static ulong timer;
+
 #define BOOT_PARTITION_NAME "boot"
 
 struct fb_mmc_sparse {
@@ -57,13 +60,38 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
 	return ret;
 }
 
+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) {
+			timed_send_info(&timer, "writing");
+			blks_written = blk_dwrite(block_dev, blk, cur_blkcnt,
+						  buffer + (i * block_dev->blksz));
+		} else {
+			timed_send_info(&timer, "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 blk_dwrite(dev_desc, blk, blkcnt, buffer);
+	return fb_mmc_blk_write(dev_desc, blk, blkcnt, buffer);
 }
 
 static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
@@ -91,7 +119,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
 
 	puts("Flashing Raw Image\n");
 
-	blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
+	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);
@@ -399,7 +427,7 @@ void fb_mmc_erase(const char *cmd, char *response)
 	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);
+	blks = fb_mmc_blk_write(dev_desc, blks_start, blks_size, NULL);
 	if (blks != blks_size) {
 		pr_err("failed erasing from device %d", dev_desc->devnum);
 		fastboot_fail("failed erasing from device", response);
diff --git a/include/fastboot.h b/include/fastboot.h
index 2140c94..6f69423 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -23,4 +23,17 @@ void fastboot_response(const char *tag, char *response,
 void fastboot_fail(const char *reason, char *response);
 void fastboot_okay(const char *reason, char *response);
 
+/**
+ * Send an INFO packet during long commands based on timer. If
+ * CONFIG_UDP_FUNCTION_FASTBOOT is defined, an INFO packet is sent
+ * if the time is 30 seconds after start. Else, noop.
+ *
+ * TODO: Handle the situation where both UDP and USB fastboot are
+ *       enabled.
+ *
+ * @param start:  Time since last INFO packet was sent.
+ * @param msg:    String describing the reason for waiting
+ */
+void timed_send_info(ulong *start, const char *msg);
+
 #endif /* _FASTBOOT_H_ */
diff --git a/include/net.h b/include/net.h
index 3469811..890ae27 100644
--- a/include/net.h
+++ b/include/net.h
@@ -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 */
@@ -549,6 +549,10 @@ extern char *net_dns_resolve;		/* The host to resolve  */
 extern char *net_dns_env_var;		/* the env var to put the ip into */
 #endif
 
+#if defined(CONFIG_UDP_FUNCTION_FASTBOOT)
+int do_fastboot_udp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
+#endif
+
 #if defined(CONFIG_CMD_PING)
 extern struct in_addr net_ping_ip;	/* the ip address to ping */
 #endif
diff --git a/include/net/fastboot.h b/include/net/fastboot.h
new file mode 100644
index 0000000..c0dd033
--- /dev/null
+++ b/include/net/fastboot.h
@@ -0,0 +1,27 @@
+/* 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);
+/**
+ * Send an INFO packet during long commands
+ *
+ * @param msg: String describing the reason for waiting
+ */
+void fastboot_send_info(const char *msg);
+
+/**********************************************************************/
+
+#endif /* __NET_FASTBOOT_H__ */
diff --git a/net/Makefile b/net/Makefile
index ce6e5ad..3489ce5 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -25,6 +25,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
index 0000000..32cb581
--- /dev/null
+++ b/net/fastboot.c
@@ -0,0 +1,542 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ */
+
+#include <common.h>
+#include <fastboot.h>
+#include <fb_mmc.h>
+#include <net.h>
+#include <net/fastboot.h>
+#include <part.h>
+#include <stdlib.h>
+#include <version.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 FASTBOOT_HEADER_SIZE sizeof(struct fastboot_header)
+#define DATA_SIZE (PACKET_SIZE - FASTBOOT_HEADER_SIZE)
+#define FASTBOOT_VERSION "0.4"
+
+/* Sequence number sent for every packet */
+static unsigned short fb_sequence_number = 1;
+static const unsigned short fb_packet_size = PACKET_SIZE;
+static const unsigned short fb_udp_version = 1;
+
+/* Keep track of last packet for resubmission */
+static uchar last_packet[PACKET_SIZE];
+static unsigned int last_packet_len;
+
+/* Parsed from first fastboot command packet */
+static char *cmd_string;
+static char *cmd_parameter;
+
+/* Fastboot download parameters */
+static unsigned int bytes_received;
+static unsigned int bytes_expected;
+static unsigned int image_size;
+
+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 fb_getvar(char *);
+static void fb_download(char *, unsigned int, char *);
+static void fb_flash(char *);
+static void fb_erase(char *);
+static void fb_continue(char *);
+static void fb_reboot(char *);
+static void boot_downloaded_image(void);
+static void cleanup_command_data(void);
+static void write_fb_response(const char *, const char *, char *);
+
+void fastboot_send_info(const char *msg)
+{
+	uchar *packet;
+	uchar *packet_base;
+	int len = 0;
+	char response[FASTBOOT_RESPONSE_LEN] = {0};
+
+	struct fastboot_header fb_response_header = {
+		.id = FASTBOOT_FASTBOOT,
+		.flags = 0,
+		.seq = htons(fb_sequence_number)
+	};
+	++fb_sequence_number;
+	packet = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
+	packet_base = packet;
+
+	/* Write headers */
+	memcpy(packet, &fb_response_header, sizeof(fb_response_header));
+	packet += sizeof(fb_response_header);
+	/* Write response */
+	write_fb_response("INFO", msg, response);
+	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);
+}
+
+/**
+ * Constructs and sends a packet in response to received fastboot packet
+ *
+ * @param fb_header            Header for response packet
+ * @param fastboot_data        Pointer to received fastboot data
+ * @param fastboot_data_len    Length of received fastboot data
+ * @param retransmit           Nonzero if sending last sent packet
+ */
+static void fastboot_send(struct fastboot_header fb_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 fb_response_header = fb_header;
+	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;
+	}
+
+	fb_response_header.seq = htons(fb_response_header.seq);
+	memcpy(packet, &fb_response_header, sizeof(fb_response_header));
+	packet += sizeof(fb_response_header);
+
+	switch (fb_header.id) {
+	case FASTBOOT_QUERY:
+		tmp = htons(fb_sequence_number);
+		memcpy(packet, &tmp, sizeof(tmp));
+		packet += sizeof(tmp);
+		break;
+	case FASTBOOT_INIT:
+		tmp = htons(fb_udp_version);
+		memcpy(packet, &tmp, sizeof(tmp));
+		packet += sizeof(tmp);
+		tmp = htons(fb_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_string) {
+			/* Parse command and send ack */
+			cmd_parameter = fastboot_data;
+			cmd_string = strsep(&cmd_parameter, ":");
+			cmd_string = strdup(cmd_string);
+			if (cmd_parameter)
+				cmd_parameter = strdup(cmd_parameter);
+		} else if (!strcmp("getvar", cmd_string)) {
+			fb_getvar(response);
+		} else if (!strcmp("download", cmd_string)) {
+			fb_download(fastboot_data, fastboot_data_len, response);
+		} else if (!strcmp("flash", cmd_string)) {
+			fb_flash(response);
+		} else if (!strcmp("erase", cmd_string)) {
+			fb_erase(response);
+		} else if (!strcmp("boot", cmd_string)) {
+			write_fb_response("OKAY", "", response);
+		} else if (!strcmp("continue", cmd_string)) {
+			fb_continue(response);
+		} else if (!strncmp("reboot", cmd_string, 6)) {
+			fb_reboot(response);
+		} else if (!strcmp("set_active", cmd_string)) {
+			/* A/B not implemented, for now do nothing */
+			write_fb_response("OKAY", "", response);
+		} else {
+			pr_err("command %s not implemented.\n", cmd_string);
+			write_fb_response("FAIL", "unrecognized command",
+					  response);
+		}
+		/* Sent some INFO packets, need to update sequence number in
+		 * header
+		 */
+		if (fb_header.seq != fb_sequence_number) {
+			fb_response_header.seq = htons(fb_sequence_number);
+			memcpy(packet_base, &fb_response_header,
+			       sizeof(fb_response_header));
+		}
+		/* Write response to packet */
+		memcpy(packet, response, strlen(response));
+		packet += strlen(response);
+		break;
+	default:
+		pr_err("ID %d not implemented.\n", fb_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)) {
+		if (!strcmp("boot", cmd_string)) {
+			boot_downloaded_image();
+		} else if (!strcmp("continue", cmd_string)) {
+			run_command(env_get("bootcmd"), CMD_FLAG_ENV);
+		} else if (!strncmp("reboot", cmd_string, 6)) {
+			/* Matches reboot or reboot-bootloader */
+			do_reset(NULL, 0, 0, NULL);
+		}
+	}
+
+	/* OKAY and FAIL indicate command is complete */
+	if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4))
+		cleanup_command_data();
+}
+
+/**
+ * Writes ascii string specified by cmd_parameter to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void fb_getvar(char *response)
+{
+	if (!cmd_parameter) {
+		write_fb_response("FAIL", "missing var", response);
+	} else if (!strcmp("version", cmd_parameter)) {
+		write_fb_response("OKAY", FASTBOOT_VERSION, response);
+	} else if (!strcmp("bootloader-version", cmd_parameter) ||
+		   !strcmp("version-bootloader", cmd_parameter)) {
+		write_fb_response("OKAY", U_BOOT_VERSION, response);
+	} else if (!strcmp("downloadsize", cmd_parameter) ||
+		   !strcmp("max-download-size", cmd_parameter)) {
+		char buf_size_str[12];
+
+		sprintf(buf_size_str, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
+		write_fb_response("OKAY", buf_size_str, response);
+	} else if (!strcmp("serialno", cmd_parameter)) {
+		const char *tmp = env_get("serial#");
+
+		if (tmp)
+			write_fb_response("OKAY", tmp, response);
+		else
+			write_fb_response("FAIL", "Value not set", response);
+	} else if (!strcmp("version-baseband", cmd_parameter)) {
+		write_fb_response("OKAY", "N/A", response);
+	} else if (!strcmp("product", cmd_parameter)) {
+		const char *board = env_get("board");
+
+		if (board)
+			write_fb_response("OKAY", board, response);
+		else
+			write_fb_response("FAIL", "Board not set", response);
+	} else if (!strcmp("current-slot", cmd_parameter)) {
+		/* A/B not implemented, for now always return _a */
+		write_fb_response("OKAY", "_a", response);
+	} else if (!strcmp("slot-suffixes", cmd_parameter)) {
+		write_fb_response("OKAY", "_a,_b", response);
+	} else if (!strncmp("has-slot", cmd_parameter, 8)) {
+		char *part_name = cmd_parameter;
+
+		cmd_parameter = strsep(&part_name, ":");
+		if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
+			write_fb_response("OKAY", "yes", response);
+		else
+			write_fb_response("OKAY", "no", response);
+	} else if (!strncmp("partition-type", cmd_parameter, 14) ||
+		   !strncmp("partition-size", cmd_parameter, 14)) {
+		disk_partition_t part_info;
+		struct blk_desc *dev_desc;
+		char *part_name = cmd_parameter;
+		char part_size_str[20];
+
+		cmd_parameter = strsep(&part_name, ":");
+		dev_desc = blk_get_dev("mmc", 0);
+		if (!dev_desc) {
+			write_fb_response("FAIL", "block device not found",
+					  response);
+		} else if (part_get_info_by_name(dev_desc, part_name,
+						 &part_info) < 0) {
+			write_fb_response("FAIL", "partition not found",
+					  response);
+		} else if (!strncmp("partition-type", cmd_parameter, 14)) {
+			write_fb_response("OKAY", (char *)part_info.type,
+					  response);
+		} else if (!strncmp("partition-size", cmd_parameter, 14)) {
+			sprintf(part_size_str, "0x%016x", (int)part_info.size);
+			write_fb_response("OKAY", part_size_str, response);
+		}
+	} else {
+		printf("WARNING: unknown variable: %s\n", cmd_parameter);
+		write_fb_response("FAIL", "Variable not implemented",
+				  response);
+	}
+}
+
+/**
+ * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
+ * Writes to response.
+ *
+ * @param fastboot_data        Pointer to received fastboot data
+ * @param fastboot_data_len    Length of received fastboot data
+ * @param repsonse             Pointer to fastboot response buffer
+ */
+static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
+			char *response)
+{
+	char *tmp;
+
+	if (bytes_expected == 0) {
+		if (!cmd_parameter) {
+			write_fb_response("FAIL", "Expected command parameter",
+					  response);
+			return;
+		}
+		bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
+		if (bytes_expected == 0) {
+			write_fb_response("FAIL", "Expected nonzero image size",
+					  response);
+			return;
+		}
+	}
+	if (fastboot_data_len == 0 && bytes_received == 0) {
+		/* Nothing to download yet. Response is of the form:
+		 * [DATA|FAIL]$cmd_parameter
+		 *
+		 * where cmd_parameter is an 8 digit hexadecimal number
+		 */
+		if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
+			write_fb_response("FAIL", cmd_parameter, response);
+		else
+			write_fb_response("DATA", cmd_parameter, response);
+	} else if (fastboot_data_len == 0 &&
+		   (bytes_received >= bytes_expected)) {
+		/* Download complete. Respond with "OKAY" */
+		write_fb_response("OKAY", "", response);
+		image_size = bytes_received;
+		bytes_expected = 0;
+		bytes_received = 0;
+	} else {
+		if (fastboot_data_len == 0 ||
+		    (bytes_received + fastboot_data_len) > bytes_expected) {
+			write_fb_response("FAIL",
+					  "Received invalid data length",
+					  response);
+			return;
+		}
+		/* Download data to CONFIG_FASTBOOT_BUF_ADDR */
+		memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + bytes_received,
+		       fastboot_data, fastboot_data_len);
+		bytes_received += fastboot_data_len;
+	}
+}
+
+/**
+ * Writes the previously downloaded image to the partition indicated by
+ * cmd_parameter. Writes to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void fb_flash(char *response)
+{
+	fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
+			   image_size, response);
+}
+
+/**
+ * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes
+ * to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void fb_erase(char *response)
+{
+	fb_mmc_erase(cmd_parameter, response);
+}
+
+/**
+ * Continues normal boot process by running "bootcmd". Writes
+ * to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void fb_continue(char *response)
+{
+	char *bootcmd;
+
+	bootcmd = env_get("bootcmd");
+	if (bootcmd)
+		write_fb_response("OKAY", "", response);
+	else
+		write_fb_response("FAIL", "bootcmd not set", response);
+}
+
+/**
+ * Sets reboot bootloader flag if requested. Writes to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void fb_reboot(char *response)
+{
+	write_fb_response("OKAY", "", response);
+	if (!strcmp("reboot-bootloader", cmd_string))
+		strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR, "reboot-bootloader");
+}
+
+/**
+ * Boots into downloaded image.
+ */
+static void boot_downloaded_image(void)
+{
+	char kernel_addr[12];
+	char *fdt_addr = env_get("fdt_addr_r");
+	char *const bootm_args[] = {
+		"bootm", kernel_addr, "-", fdt_addr, NULL
+	};
+
+	sprintf(kernel_addr, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
+
+	printf("\nBooting kernel at %s with fdt at %s...\n\n\n",
+	       kernel_addr, fdt_addr);
+	do_bootm(NULL, 0, 4, bootm_args);
+
+	/* This only happens if image is faulty so we start over. */
+	do_reset(NULL, 0, 0, NULL);
+}
+
+/**
+ * Writes a response to response buffer of the form "$tag$reason".
+ *
+ * @param tag         The first part of the response
+ * @param reason      The second part of the response
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void write_fb_response(const char *tag, const char *reason,
+			      char *response)
+{
+	strncpy(response, tag, strlen(tag));
+	strncat(response, reason, FASTBOOT_RESPONSE_LEN - strlen(tag) - 1);
+}
+
+/**
+ * Frees any resources allocated during current fastboot command.
+ */
+static void cleanup_command_data(void)
+{
+	/* cmd_parameter and cmd_string potentially point to memory allocated by
+	 * strdup
+	 */
+	if (cmd_parameter)
+		free(cmd_parameter);
+	if (cmd_string)
+		free(cmd_string);
+	cmd_parameter = NULL;
+	cmd_string = NULL;
+}
+
+/**
+ * Incoming UDP packet handler.
+ *
+ * @param packet  Pointer to incoming UDP packet
+ * @param dport   Destination UDP port
+ * @param sip     Source IP address
+ * @param sport   Source UDP port
+ * @param 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 fb_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 < FASTBOOT_HEADER_SIZE || len > PACKET_SIZE)
+		return;
+	memcpy(&fb_header, packet, sizeof(fb_header));
+	fb_header.flags = 0;
+	fb_header.seq = ntohs(fb_header.seq);
+	packet += sizeof(fb_header);
+	len -= sizeof(fb_header);
+
+	switch (fb_header.id) {
+	case FASTBOOT_QUERY:
+		fastboot_send(fb_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 (fb_header.seq == fb_sequence_number) {
+			fastboot_send(fb_header, fastboot_data,
+				      fastboot_data_len, 0);
+			fb_sequence_number++;
+		} else if (fb_header.seq == fb_sequence_number - 1) {
+			/* Retransmit last sent packet */
+			fastboot_send(fb_header, fastboot_data,
+				      fastboot_data_len, 1);
+		}
+		break;
+	default:
+		pr_err("ID %d not implemented.\n", fb_header.id);
+		fb_header.id = FASTBOOT_ERROR;
+		fastboot_send(fb_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;
+
+	net_set_udp_handler(fastboot_handler);
+
+	/* zero out server ether in case the server ip has changed */
+	memset(net_server_ethaddr, 0, 6);
+}
diff --git a/net/net.c b/net/net.c
index d222c1f..554df7a 100644
--- a/net/net.c
+++ b/net/net.c
@@ -87,6 +87,9 @@
 #include <environment.h>
 #include <errno.h>
 #include <net.h>
+#if defined(CONFIG_UDP_FUNCTION_FASTBOOT)
+#include <net/fastboot.h>
+#endif
 #include <net/tftp.h>
 #if defined(CONFIG_LED_STATUS)
 #include <miiphy.h>
@@ -451,6 +454,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 +1330,7 @@ common:
 		/* Fall through */
 
 	case NETCONS:
+	case FASTBOOT:
 	case TFTPSRV:
 		if (net_ip.s_addr == 0) {
 			puts("*** ERROR: `ipaddr' not set\n");
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 08/20] net: fastboot: Support building without MMC
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (6 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 20:39   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 09/20] fastboot: Refactor write_fb_response into fastboot_okay/fail/response Alex Kiernan
                   ` (12 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

If the fastboot flash/erase commands are disabled, remove that support
so we still build correctly.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 net/fastboot.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/fastboot.c b/net/fastboot.c
index 32cb581..87c12e5 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -59,8 +59,10 @@ static int fastboot_our_port;
 
 static void fb_getvar(char *);
 static void fb_download(char *, unsigned int, char *);
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 static void fb_flash(char *);
 static void fb_erase(char *);
+#endif
 static void fb_continue(char *);
 static void fb_reboot(char *);
 static void boot_downloaded_image(void);
@@ -169,10 +171,12 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 			fb_getvar(response);
 		} else if (!strcmp("download", cmd_string)) {
 			fb_download(fastboot_data, fastboot_data_len, response);
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 		} else if (!strcmp("flash", cmd_string)) {
 			fb_flash(response);
 		} else if (!strcmp("erase", cmd_string)) {
 			fb_erase(response);
+#endif
 		} else if (!strcmp("boot", cmd_string)) {
 			write_fb_response("OKAY", "", response);
 		} else if (!strcmp("continue", cmd_string)) {
@@ -367,6 +371,7 @@ static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
 	}
 }
 
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 /**
  * Writes the previously downloaded image to the partition indicated by
  * cmd_parameter. Writes to response.
@@ -389,6 +394,7 @@ static void fb_erase(char *response)
 {
 	fb_mmc_erase(cmd_parameter, response);
 }
+#endif
 
 /**
  * Continues normal boot process by running "bootcmd". Writes
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 09/20] fastboot: Refactor write_fb_response into fastboot_okay/fail/response
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (7 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 08/20] net: fastboot: Support building without MMC Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 20:48   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 10/20] fastboot: Merge USB and UDP getvar implementation Alex Kiernan
                   ` (11 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Replace write_fb_response with fastboot_okay/fail/response. Also allow
fastboot_okay to take NULL when we have no message to send.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_common.c    |  5 ++-
 drivers/fastboot/fb_mmc.c       | 10 ++---
 drivers/fastboot/fb_nand.c      |  4 +-
 drivers/fastboot/image-sparse.c |  2 +-
 net/fastboot.c                  | 95 +++++++++++++++--------------------------
 5 files changed, 47 insertions(+), 69 deletions(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 7367fbb..f0bf53d 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -45,7 +45,10 @@ void fastboot_fail(const char *reason, char *response)
 
 void fastboot_okay(const char *reason, char *response)
 {
-	fastboot_response("OKAY", response, "%s", reason);
+	if (reason)
+		fastboot_response("OKAY", response, "%s", reason);
+	else
+		fastboot_response("OKAY", response, NULL);
 }
 
 void timed_send_info(ulong *start, const char *msg)
diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 304bda1..416f309 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -128,7 +128,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
 
 	printf("........ wrote " LBAFU " bytes to '%s'\n", blkcnt * info->blksz,
 	       part_name);
-	fastboot_okay("", response);
+	fastboot_okay(NULL, response);
 }
 
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
@@ -288,7 +288,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	}
 
 	puts("........ zImage was updated in boot partition\n");
-	fastboot_okay("", response);
+	fastboot_okay(NULL, response);
 	return 0;
 }
 #endif
@@ -323,7 +323,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 			return;
 		}
 		printf("........ success\n");
-		fastboot_okay("", response);
+		fastboot_okay(NULL, response);
 		return;
 	}
 #endif
@@ -344,7 +344,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,
 			return;
 		}
 		printf("........ success\n");
-		fastboot_okay("", response);
+		fastboot_okay(NULL, response);
 		return;
 	}
 #endif
@@ -436,5 +436,5 @@ void fb_mmc_erase(const char *cmd, char *response)
 
 	printf("........ erased " LBAFU " bytes from '%s'\n",
 	       blks_size * info.blksz, cmd);
-	fastboot_okay("", response);
+	fastboot_okay(NULL, response);
 }
diff --git a/drivers/fastboot/fb_nand.c b/drivers/fastboot/fb_nand.c
index 3a0b101..de869a0 100644
--- a/drivers/fastboot/fb_nand.c
+++ b/drivers/fastboot/fb_nand.c
@@ -199,7 +199,7 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer,
 		return;
 	}
 
-	fastboot_okay("", response);
+	fastboot_okay(NULL, response);
 }
 
 void fb_nand_erase(const char *cmd, char *response)
@@ -226,5 +226,5 @@ void fb_nand_erase(const char *cmd, char *response)
 		return;
 	}
 
-	fastboot_okay("", response);
+	fastboot_okay(NULL, response);
 }
diff --git a/drivers/fastboot/image-sparse.c b/drivers/fastboot/image-sparse.c
index 616c2bd..ecdb3d3 100644
--- a/drivers/fastboot/image-sparse.c
+++ b/drivers/fastboot/image-sparse.c
@@ -257,7 +257,7 @@ void write_sparse_image(
 	if (total_blocks != sparse_header->total_blks)
 		fastboot_fail("sparse image write failure", response);
 	else
-		fastboot_okay("", response);
+		fastboot_okay(NULL, response);
 
 	return;
 }
diff --git a/net/fastboot.c b/net/fastboot.c
index 87c12e5..960e7f1 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -67,7 +67,6 @@ static void fb_continue(char *);
 static void fb_reboot(char *);
 static void boot_downloaded_image(void);
 static void cleanup_command_data(void);
-static void write_fb_response(const char *, const char *, char *);
 
 void fastboot_send_info(const char *msg)
 {
@@ -89,7 +88,7 @@ void fastboot_send_info(const char *msg)
 	memcpy(packet, &fb_response_header, sizeof(fb_response_header));
 	packet += sizeof(fb_response_header);
 	/* Write response */
-	write_fb_response("INFO", msg, response);
+	fastboot_response("INFO", response, "%s", msg);
 	memcpy(packet, response, strlen(response));
 	packet += strlen(response);
 
@@ -178,18 +177,17 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 			fb_erase(response);
 #endif
 		} else if (!strcmp("boot", cmd_string)) {
-			write_fb_response("OKAY", "", response);
+			fastboot_okay(NULL, response);
 		} else if (!strcmp("continue", cmd_string)) {
 			fb_continue(response);
 		} else if (!strncmp("reboot", cmd_string, 6)) {
 			fb_reboot(response);
 		} else if (!strcmp("set_active", cmd_string)) {
 			/* A/B not implemented, for now do nothing */
-			write_fb_response("OKAY", "", response);
+			fastboot_okay(NULL, response);
 		} else {
 			pr_err("command %s not implemented.\n", cmd_string);
-			write_fb_response("FAIL", "unrecognized command",
-					  response);
+			fastboot_fail("unrecognized command", response);
 		}
 		/* Sent some INFO packets, need to update sequence number in
 		 * header
@@ -242,74 +240,67 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 static void fb_getvar(char *response)
 {
 	if (!cmd_parameter) {
-		write_fb_response("FAIL", "missing var", response);
+		fastboot_fail("missing var", response);
 	} else if (!strcmp("version", cmd_parameter)) {
-		write_fb_response("OKAY", FASTBOOT_VERSION, response);
+		fastboot_okay(FASTBOOT_VERSION, response);
 	} else if (!strcmp("bootloader-version", cmd_parameter) ||
 		   !strcmp("version-bootloader", cmd_parameter)) {
-		write_fb_response("OKAY", U_BOOT_VERSION, response);
+		fastboot_okay(U_BOOT_VERSION, response);
 	} else if (!strcmp("downloadsize", cmd_parameter) ||
 		   !strcmp("max-download-size", cmd_parameter)) {
-		char buf_size_str[12];
-
-		sprintf(buf_size_str, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
-		write_fb_response("OKAY", buf_size_str, response);
+		fastboot_response("OKAY", response,
+				  "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
 	} else if (!strcmp("serialno", cmd_parameter)) {
 		const char *tmp = env_get("serial#");
 
 		if (tmp)
-			write_fb_response("OKAY", tmp, response);
+			fastboot_okay(tmp, response);
 		else
-			write_fb_response("FAIL", "Value not set", response);
+			fastboot_fail("Value not set", response);
 	} else if (!strcmp("version-baseband", cmd_parameter)) {
-		write_fb_response("OKAY", "N/A", response);
+		fastboot_okay("N/A", response);
 	} else if (!strcmp("product", cmd_parameter)) {
 		const char *board = env_get("board");
 
 		if (board)
-			write_fb_response("OKAY", board, response);
+			fastboot_okay(board, response);
 		else
-			write_fb_response("FAIL", "Board not set", response);
+			fastboot_fail("Board not set", response);
 	} else if (!strcmp("current-slot", cmd_parameter)) {
 		/* A/B not implemented, for now always return _a */
-		write_fb_response("OKAY", "_a", response);
+		fastboot_okay("_a", response);
 	} else if (!strcmp("slot-suffixes", cmd_parameter)) {
-		write_fb_response("OKAY", "_a,_b", response);
+		fastboot_okay("_a,_b", response);
 	} else if (!strncmp("has-slot", cmd_parameter, 8)) {
 		char *part_name = cmd_parameter;
 
 		cmd_parameter = strsep(&part_name, ":");
 		if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
-			write_fb_response("OKAY", "yes", response);
+			fastboot_okay("yes", response);
 		else
-			write_fb_response("OKAY", "no", response);
+			fastboot_okay("no", response);
 	} else if (!strncmp("partition-type", cmd_parameter, 14) ||
 		   !strncmp("partition-size", cmd_parameter, 14)) {
 		disk_partition_t part_info;
 		struct blk_desc *dev_desc;
 		char *part_name = cmd_parameter;
-		char part_size_str[20];
 
 		cmd_parameter = strsep(&part_name, ":");
 		dev_desc = blk_get_dev("mmc", 0);
 		if (!dev_desc) {
-			write_fb_response("FAIL", "block device not found",
-					  response);
+			fastboot_fail("block device not found", response);
 		} else if (part_get_info_by_name(dev_desc, part_name,
 						 &part_info) < 0) {
-			write_fb_response("FAIL", "partition not found",
-					  response);
+			fastboot_fail("partition not found", response);
 		} else if (!strncmp("partition-type", cmd_parameter, 14)) {
-			write_fb_response("OKAY", (char *)part_info.type,
-					  response);
+			fastboot_okay((char *)part_info.type, response);
 		} else if (!strncmp("partition-size", cmd_parameter, 14)) {
-			sprintf(part_size_str, "0x%016x", (int)part_info.size);
-			write_fb_response("OKAY", part_size_str, response);
+			fastboot_response("OKAY", response,
+					  "0x%016x", (int)part_info.size);
 		}
 	} else {
 		printf("WARNING: unknown variable: %s\n", cmd_parameter);
-		write_fb_response("FAIL", "Variable not implemented",
-				  response);
+		fastboot_fail("Variable not implemented", response);
 	}
 }
 
@@ -328,14 +319,12 @@ static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
 
 	if (bytes_expected == 0) {
 		if (!cmd_parameter) {
-			write_fb_response("FAIL", "Expected command parameter",
-					  response);
+			fastboot_fail("Expected command parameter", response);
 			return;
 		}
 		bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
 		if (bytes_expected == 0) {
-			write_fb_response("FAIL", "Expected nonzero image size",
-					  response);
+			fastboot_fail("Expected nonzero image size", response);
 			return;
 		}
 	}
@@ -346,22 +335,22 @@ static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
 		 * where cmd_parameter is an 8 digit hexadecimal number
 		 */
 		if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
-			write_fb_response("FAIL", cmd_parameter, response);
+			fastboot_fail(cmd_parameter, response);
 		else
-			write_fb_response("DATA", cmd_parameter, response);
+			fastboot_response("DATA", response, "%s",
+					  cmd_parameter);
 	} else if (fastboot_data_len == 0 &&
 		   (bytes_received >= bytes_expected)) {
 		/* Download complete. Respond with "OKAY" */
-		write_fb_response("OKAY", "", response);
+		fastboot_okay(NULL, response);
 		image_size = bytes_received;
 		bytes_expected = 0;
 		bytes_received = 0;
 	} else {
 		if (fastboot_data_len == 0 ||
 		    (bytes_received + fastboot_data_len) > bytes_expected) {
-			write_fb_response("FAIL",
-					  "Received invalid data length",
-					  response);
+			fastboot_fail("Received invalid data length",
+				      response);
 			return;
 		}
 		/* Download data to CONFIG_FASTBOOT_BUF_ADDR */
@@ -408,9 +397,9 @@ static void fb_continue(char *response)
 
 	bootcmd = env_get("bootcmd");
 	if (bootcmd)
-		write_fb_response("OKAY", "", response);
+		fastboot_okay(NULL, response);
 	else
-		write_fb_response("FAIL", "bootcmd not set", response);
+		fastboot_fail("bootcmd not set", response);
 }
 
 /**
@@ -420,7 +409,7 @@ static void fb_continue(char *response)
  */
 static void fb_reboot(char *response)
 {
-	write_fb_response("OKAY", "", response);
+	fastboot_okay(NULL, response);
 	if (!strcmp("reboot-bootloader", cmd_string))
 		strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR, "reboot-bootloader");
 }
@@ -447,20 +436,6 @@ static void boot_downloaded_image(void)
 }
 
 /**
- * Writes a response to response buffer of the form "$tag$reason".
- *
- * @param tag         The first part of the response
- * @param reason      The second part of the response
- * @param repsonse    Pointer to fastboot response buffer
- */
-static void write_fb_response(const char *tag, const char *reason,
-			      char *response)
-{
-	strncpy(response, tag, strlen(tag));
-	strncat(response, reason, FASTBOOT_RESPONSE_LEN - strlen(tag) - 1);
-}
-
-/**
  * Frees any resources allocated during current fastboot command.
  */
 static void cleanup_command_data(void)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 10/20] fastboot: Merge USB and UDP getvar implementation
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (8 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 09/20] fastboot: Refactor write_fb_response into fastboot_okay/fail/response Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 20:56   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot Alex Kiernan
                   ` (10 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Merge the USB and UDP getvar implementations into one. The USB side
gains new variables previously defined in the network side and the
network side now supports fetching of arbitrary variables prefixed with
'fastboot.'

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/Makefile       |  1 +
 drivers/fastboot/fb_common.c    |  7 ++++
 drivers/fastboot/fb_getvar.c    | 93 +++++++++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c | 56 +------------------------
 include/fastboot.h              | 18 ++++++++
 net/fastboot.c                  | 75 +--------------------------------
 6 files changed, 121 insertions(+), 129 deletions(-)
 create mode 100644 drivers/fastboot/fb_getvar.c

diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index c12dfa8..9af4073 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier:      GPL-2.0+
 
 obj-y += fb_common.o
+obj-y += fb_getvar.o
 obj-$(CONFIG_FASTBOOT_FLASH) += image-sparse.o
 
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index f0bf53d..3b68f25 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -65,3 +65,10 @@ void timed_send_info(ulong *start, const char *msg)
 	}
 #endif
 }
+
+int strcmp_l1(const char *s1, const char *s2)
+{
+	if (!s1 || !s2)
+		return -1;
+	return strncmp(s1, s2, strlen(s1));
+}
diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
new file mode 100644
index 0000000..aa68371
--- /dev/null
+++ b/drivers/fastboot/fb_getvar.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ */
+
+#include <common.h>
+#include <fastboot.h>
+#include <version.h>
+
+/**
+ * Writes ascii string specified by cmd_parameter to response.
+ *
+ * @param cmd_parameter	Point to command parameter
+ * @param response	Pointer to fastboot response buffer
+ */
+void fb_getvar(char *cmd_parameter, char *response)
+{
+	if (!cmd_parameter) {
+		fastboot_fail("missing var", response);
+	} else if (!strcmp("version", cmd_parameter)) {
+		fastboot_okay(FASTBOOT_VERSION, response);
+	} else if (!strcmp("bootloader-version", cmd_parameter) ||
+		   !strcmp("version-bootloader", cmd_parameter)) {
+		fastboot_okay(U_BOOT_VERSION, response);
+	} else if (!strcmp("downloadsize", cmd_parameter) ||
+		   !strcmp("max-download-size", cmd_parameter)) {
+		fastboot_response("OKAY", response,
+				  "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
+	} else if (!strcmp("serialno", cmd_parameter)) {
+		const char *tmp = env_get("serial#");
+
+		if (tmp)
+			fastboot_okay(tmp, response);
+		else
+			fastboot_fail("Value not set", response);
+	} else if (!strcmp("version-baseband", cmd_parameter)) {
+		fastboot_okay("N/A", response);
+	} else if (!strcmp("product", cmd_parameter)) {
+		const char *board = env_get("board");
+
+		if (board)
+			fastboot_okay(board, response);
+		else
+			fastboot_fail("Board not set", response);
+	} else if (!strcmp("current-slot", cmd_parameter)) {
+		/* A/B not implemented, for now always return _a */
+		fastboot_okay("_a", response);
+	} else if (!strcmp("slot-suffixes", cmd_parameter)) {
+		fastboot_okay("_a,_b", response);
+	} else if (!strcmp_l1("has-slot", cmd_parameter)) {
+		char *part_name = cmd_parameter;
+
+		cmd_parameter = strsep(&part_name, ":");
+		if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
+			fastboot_okay("yes", response);
+		else
+			fastboot_okay("no", response);
+	} else if (!strcmp_l1("partition-type", cmd_parameter) ||
+		   !strcmp_l1("partition-size", cmd_parameter)) {
+		disk_partition_t part_info;
+		struct blk_desc *dev_desc;
+		char *part_name = cmd_parameter;
+
+		cmd_parameter = strsep(&part_name, ":");
+		dev_desc = blk_get_dev("mmc", 0);
+		if (!dev_desc) {
+			fastboot_fail("block device not found", response);
+		} else if (part_get_info_by_name(dev_desc, part_name,
+						 &part_info) < 0) {
+			fastboot_fail("partition not found", response);
+		} else if (!strcmp_l1("partition-type", cmd_parameter)) {
+			fastboot_okay((char *)part_info.type, response);
+		} else if (!strcmp_l1("partition-size", cmd_parameter)) {
+			fastboot_response("OKAY", response,
+					  "0x%016x", (int)part_info.size);
+		}
+	} else {
+#define FASTBOOT_ENV_PREFIX	"fastboot."
+		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);
+		} else {
+			pr_warn("WARNING: unknown variable: %s\n",
+				cmd_parameter);
+			fastboot_fail("Variable not implemented", response);
+		}
+	}
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index e757c3e..a493c75 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -148,7 +148,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 void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
 {
@@ -376,66 +375,13 @@ static void cb_reboot(struct usb_ep *ep, struct usb_request *req)
 	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);
-	}
+	fb_getvar(cmd, response);
 	fastboot_tx_write_str(response);
 }
 
diff --git a/include/fastboot.h b/include/fastboot.h
index 6f69423..fb58358 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -13,6 +13,8 @@
 #ifndef _FASTBOOT_H_
 #define _FASTBOOT_H_
 
+#define FASTBOOT_VERSION	"0.4"
+
 /* The 64 defined bytes plus \0 */
 #define FASTBOOT_RESPONSE_LEN	(64 + 1)
 
@@ -24,6 +26,14 @@ void fastboot_fail(const char *reason, char *response);
 void fastboot_okay(const char *reason, char *response);
 
 /**
+ * Writes ascii string specified by cmd_parameter to response.
+ *
+ * @param cmd_parameter	Pointer to variable name
+ * @param response	Pointer to fastboot response buffer
+ */
+void fb_getvar(char *cmd_parameter, char *response);
+
+/**
  * Send an INFO packet during long commands based on timer. If
  * CONFIG_UDP_FUNCTION_FASTBOOT is defined, an INFO packet is sent
  * if the time is 30 seconds after start. Else, noop.
@@ -36,4 +46,12 @@ void fastboot_okay(const char *reason, char *response);
  */
 void timed_send_info(ulong *start, const char *msg);
 
+/**
+ * Compare strings over the length of s1
+ *
+ * @param s1		Pointer to string which limits the comparisson
+ * @param s2		Second string
+ */
+int strcmp_l1(const char *s1, const char *s2);
+
 #endif /* _FASTBOOT_H_ */
diff --git a/net/fastboot.c b/net/fastboot.c
index 960e7f1..cd09ada 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -57,7 +57,6 @@ static int fastboot_remote_port;
 /* The UDP port at our end */
 static int fastboot_our_port;
 
-static void fb_getvar(char *);
 static void fb_download(char *, unsigned int, char *);
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 static void fb_flash(char *);
@@ -167,7 +166,7 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 			if (cmd_parameter)
 				cmd_parameter = strdup(cmd_parameter);
 		} else if (!strcmp("getvar", cmd_string)) {
-			fb_getvar(response);
+			fb_getvar(cmd_parameter, response);
 		} else if (!strcmp("download", cmd_string)) {
 			fb_download(fastboot_data, fastboot_data_len, response);
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
@@ -233,78 +232,6 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 }
 
 /**
- * Writes ascii string specified by cmd_parameter to response.
- *
- * @param repsonse    Pointer to fastboot response buffer
- */
-static void fb_getvar(char *response)
-{
-	if (!cmd_parameter) {
-		fastboot_fail("missing var", response);
-	} else if (!strcmp("version", cmd_parameter)) {
-		fastboot_okay(FASTBOOT_VERSION, response);
-	} else if (!strcmp("bootloader-version", cmd_parameter) ||
-		   !strcmp("version-bootloader", cmd_parameter)) {
-		fastboot_okay(U_BOOT_VERSION, response);
-	} else if (!strcmp("downloadsize", cmd_parameter) ||
-		   !strcmp("max-download-size", cmd_parameter)) {
-		fastboot_response("OKAY", response,
-				  "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
-	} else if (!strcmp("serialno", cmd_parameter)) {
-		const char *tmp = env_get("serial#");
-
-		if (tmp)
-			fastboot_okay(tmp, response);
-		else
-			fastboot_fail("Value not set", response);
-	} else if (!strcmp("version-baseband", cmd_parameter)) {
-		fastboot_okay("N/A", response);
-	} else if (!strcmp("product", cmd_parameter)) {
-		const char *board = env_get("board");
-
-		if (board)
-			fastboot_okay(board, response);
-		else
-			fastboot_fail("Board not set", response);
-	} else if (!strcmp("current-slot", cmd_parameter)) {
-		/* A/B not implemented, for now always return _a */
-		fastboot_okay("_a", response);
-	} else if (!strcmp("slot-suffixes", cmd_parameter)) {
-		fastboot_okay("_a,_b", response);
-	} else if (!strncmp("has-slot", cmd_parameter, 8)) {
-		char *part_name = cmd_parameter;
-
-		cmd_parameter = strsep(&part_name, ":");
-		if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
-			fastboot_okay("yes", response);
-		else
-			fastboot_okay("no", response);
-	} else if (!strncmp("partition-type", cmd_parameter, 14) ||
-		   !strncmp("partition-size", cmd_parameter, 14)) {
-		disk_partition_t part_info;
-		struct blk_desc *dev_desc;
-		char *part_name = cmd_parameter;
-
-		cmd_parameter = strsep(&part_name, ":");
-		dev_desc = blk_get_dev("mmc", 0);
-		if (!dev_desc) {
-			fastboot_fail("block device not found", response);
-		} else if (part_get_info_by_name(dev_desc, part_name,
-						 &part_info) < 0) {
-			fastboot_fail("partition not found", response);
-		} else if (!strncmp("partition-type", cmd_parameter, 14)) {
-			fastboot_okay((char *)part_info.type, response);
-		} else if (!strncmp("partition-size", cmd_parameter, 14)) {
-			fastboot_response("OKAY", response,
-					  "0x%016x", (int)part_info.size);
-		}
-	} else {
-		printf("WARNING: unknown variable: %s\n", cmd_parameter);
-		fastboot_fail("Variable not implemented", response);
-	}
-}
-
-/**
  * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
  * Writes to response.
  *
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (9 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 10/20] fastboot: Merge USB and UDP getvar implementation Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 20:58   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 12/20] fastboot: net: Convert command lookup to a table Alex Kiernan
                   ` (9 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Change the behaviour of 'continue' so that we simply exit the fastboot
server and leave the caller to decide what to do next. This matches
the USB fastboot behaviour.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 net/fastboot.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/net/fastboot.c b/net/fastboot.c
index cd09ada..ed13890 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -218,8 +218,6 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 	if (!strncmp("OKAY", response, 4)) {
 		if (!strcmp("boot", cmd_string)) {
 			boot_downloaded_image();
-		} else if (!strcmp("continue", cmd_string)) {
-			run_command(env_get("bootcmd"), CMD_FLAG_ENV);
 		} else if (!strncmp("reboot", cmd_string, 6)) {
 			/* Matches reboot or reboot-bootloader */
 			do_reset(NULL, 0, 0, NULL);
@@ -313,20 +311,15 @@ static void fb_erase(char *response)
 #endif
 
 /**
- * Continues normal boot process by running "bootcmd". Writes
+ * Continues normal boot process by exiting fastboot server. Writes
  * to response.
  *
  * @param repsonse    Pointer to fastboot response buffer
  */
 static void fb_continue(char *response)
 {
-	char *bootcmd;
-
-	bootcmd = env_get("bootcmd");
-	if (bootcmd)
-		fastboot_okay(NULL, response);
-	else
-		fastboot_fail("bootcmd not set", response);
+	net_set_state(NETLOOP_SUCCESS);
+	fastboot_okay(NULL, response);
 }
 
 /**
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 12/20] fastboot: net: Convert command lookup to a table
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (10 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:08   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling Alex Kiernan
                   ` (8 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Change command lookup to use a lookup table so it matches the existing
USB fastboot code.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_common.c |  30 ++++++++++++
 include/fastboot.h           |  21 +++++++++
 net/fastboot.c               | 108 ++++++++++++++++++++++++++++++-------------
 3 files changed, 127 insertions(+), 32 deletions(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 3b68f25..8b3627b 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -72,3 +72,33 @@ int strcmp_l1(const char *s1, const char *s2)
 		return -1;
 	return strncmp(s1, s2, strlen(s1));
 }
+
+static const char *const fb_commands[] = {
+	[FB_CMD_GETVAR] = "getvar",
+	[FB_CMD_DOWNLOAD] = "download",
+	[FB_CMD_VERIFY] = "verify",
+	[FB_CMD_FLASH] = "flash",
+	[FB_CMD_ERASE] = "erase",
+	[FB_CMD_BOOT] = "boot",
+	[FB_CMD_CONTINUE] = "continue",
+	[FB_CMD_REBOOT] = "reboot",
+	[FB_CMD_REBOOT_BOOTLOADER] = "reboot-bootloader",
+	[FB_CMD_POWERDOWN] = "powerdown",
+	[FB_CMD_SET_ACTIVE] = "set_active",
+	[FB_CMD_UPLOAD] = "upload",
+};
+
+int fastboot_lookup_command(const char *cmd_string)
+{
+	int i;
+
+	for (i = 0; i < FB_CMD_COUNT; i++) {
+		int len = strlen(fb_commands[i]);
+
+		if (!strncmp(fb_commands[i], cmd_string, len) &&
+		    (cmd_string[len] == '\0' || cmd_string[len] == ':'))
+			return i;
+	}
+
+	return -1;
+}
diff --git a/include/fastboot.h b/include/fastboot.h
index fb58358..de07220 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -18,6 +18,26 @@
 /* The 64 defined bytes plus \0 */
 #define FASTBOOT_RESPONSE_LEN	(64 + 1)
 
+/**
+ * All known commands to fastboot
+ */
+enum {
+	FB_CMD_GETVAR = 0,
+	FB_CMD_DOWNLOAD,
+	FB_CMD_VERIFY,
+	FB_CMD_FLASH,
+	FB_CMD_ERASE,
+	FB_CMD_BOOT,
+	FB_CMD_CONTINUE,
+	FB_CMD_REBOOT,
+	FB_CMD_REBOOT_BOOTLOADER,
+	FB_CMD_POWERDOWN,
+	FB_CMD_SET_ACTIVE,
+	FB_CMD_UPLOAD,
+
+	FB_CMD_COUNT
+};
+
 void fastboot_response(const char *tag, char *response,
 		       const char *format, ...)
 	__attribute__ ((format (__printf__, 3, 4)));
@@ -54,4 +74,5 @@ void timed_send_info(ulong *start, const char *msg);
  */
 int strcmp_l1(const char *s1, const char *s2);
 
+int fastboot_lookup_command(const char *cmd_string);
 #endif /* _FASTBOOT_H_ */
diff --git a/net/fastboot.c b/net/fastboot.c
index ed13890..155049a 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -57,13 +57,39 @@ static int fastboot_remote_port;
 /* The UDP port@our end */
 static int fastboot_our_port;
 
-static void fb_download(char *, unsigned int, char *);
+static void cb_okay(char *, char *, unsigned int, char *);
+static void cb_getvar(char *, char *, unsigned int, char *);
+static void cb_download(char *, char *, unsigned int, char *);
 #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
-static void fb_flash(char *);
-static void fb_erase(char *);
+static void cb_flash(char *, char *, unsigned int, char *);
+static void cb_erase(char *, char *, unsigned int, char *);
 #endif
-static void fb_continue(char *);
-static void fb_reboot(char *);
+static void cb_continue(char *, char *, unsigned int, char *);
+static void cb_reboot(char *, char *, unsigned int, char *);
+
+static void (*fb_net_dispatch[])(char *cmd_parameter,
+				 char *fastboot_data,
+				 unsigned int fastboot_data_len,
+				 char *response) = {
+	[FB_CMD_GETVAR] = cb_getvar,
+	[FB_CMD_DOWNLOAD] = cb_download,
+	[FB_CMD_VERIFY] = NULL,
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+	[FB_CMD_FLASH] = cb_flash,
+	[FB_CMD_ERASE] = cb_erase,
+#else
+	[FB_CMD_FLASH] = NULL,
+	[FB_CMD_ERASE] = NULL,
+#endif
+	[FB_CMD_BOOT] = cb_okay,
+	[FB_CMD_CONTINUE] = cb_continue,
+	[FB_CMD_REBOOT] = cb_reboot,
+	[FB_CMD_REBOOT_BOOTLOADER] = cb_reboot,
+	[FB_CMD_POWERDOWN] = NULL,
+	[FB_CMD_SET_ACTIVE] = cb_okay,
+	[FB_CMD_UPLOAD] = NULL,
+};
+
 static void boot_downloaded_image(void);
 static void cleanup_command_data(void);
 
@@ -165,28 +191,30 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 			cmd_string = strdup(cmd_string);
 			if (cmd_parameter)
 				cmd_parameter = strdup(cmd_parameter);
-		} else if (!strcmp("getvar", cmd_string)) {
-			fb_getvar(cmd_parameter, response);
-		} else if (!strcmp("download", cmd_string)) {
-			fb_download(fastboot_data, fastboot_data_len, response);
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
-		} else if (!strcmp("flash", cmd_string)) {
-			fb_flash(response);
-		} else if (!strcmp("erase", cmd_string)) {
-			fb_erase(response);
-#endif
-		} else if (!strcmp("boot", cmd_string)) {
-			fastboot_okay(NULL, response);
-		} else if (!strcmp("continue", cmd_string)) {
-			fb_continue(response);
-		} else if (!strncmp("reboot", cmd_string, 6)) {
-			fb_reboot(response);
-		} else if (!strcmp("set_active", cmd_string)) {
-			/* A/B not implemented, for now do nothing */
-			fastboot_okay(NULL, response);
 		} else {
-			pr_err("command %s not implemented.\n", cmd_string);
-			fastboot_fail("unrecognized command", response);
+			int i;
+
+			i = fastboot_lookup_command(cmd_string);
+			if (i >= 0) {
+				void (*fb_call)(char *cmd_parameter,
+						char *fastboot_data,
+						unsigned int fastboot_data_len,
+						char *response);
+				fb_call = fb_net_dispatch[i];
+				if (fb_call) {
+					fb_call(cmd_parameter, fastboot_data,
+						fastboot_data_len, response);
+				} else {
+					pr_err("command %s not implemented.\n",
+					       cmd_string);
+					fastboot_fail("unrecognized command",
+						      response);
+				}
+			} else {
+				pr_err("command %s not recognized.\n",
+				       cmd_string);
+				fastboot_fail("unrecognized command", response);
+			}
 		}
 		/* Sent some INFO packets, need to update sequence number in
 		 * header
@@ -229,6 +257,18 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 		cleanup_command_data();
 }
 
+static void cb_okay(char *cmd_parameter, char *fastboot_data,
+		    unsigned int fastboot_data_len, char *response)
+{
+	fastboot_okay(NULL, response);
+}
+
+static void cb_getvar(char *cmd_parameter, char *fastboot_data,
+		      unsigned int fastboot_data_len, char *response)
+{
+	fb_getvar(cmd_parameter, response);
+}
+
 /**
  * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
  * Writes to response.
@@ -237,8 +277,8 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
  * @param fastboot_data_len    Length of received fastboot data
  * @param repsonse             Pointer to fastboot response buffer
  */
-static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
-			char *response)
+static void cb_download(char *cmd_parameter, char *fastboot_data,
+			unsigned int fastboot_data_len, char *response)
 {
 	char *tmp;
 
@@ -292,7 +332,8 @@ static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
  *
  * @param repsonse    Pointer to fastboot response buffer
  */
-static void fb_flash(char *response)
+static void cb_flash(char *cmd_parameter, char *fastboot_data,
+		     unsigned int fastboot_data_len, char *response)
 {
 	fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
 			   image_size, response);
@@ -304,7 +345,8 @@ static void fb_flash(char *response)
  *
  * @param repsonse    Pointer to fastboot response buffer
  */
-static void fb_erase(char *response)
+static void cb_erase(char *cmd_parameter, char *fastboot_data,
+		     unsigned int fastboot_data_len, char *response)
 {
 	fb_mmc_erase(cmd_parameter, response);
 }
@@ -316,7 +358,8 @@ static void fb_erase(char *response)
  *
  * @param repsonse    Pointer to fastboot response buffer
  */
-static void fb_continue(char *response)
+static void cb_continue(char *cmd_parameter, char *fastboot_data,
+			unsigned int fastboot_data_len, char *response)
 {
 	net_set_state(NETLOOP_SUCCESS);
 	fastboot_okay(NULL, response);
@@ -327,7 +370,8 @@ static void fb_continue(char *response)
  *
  * @param repsonse    Pointer to fastboot response buffer
  */
-static void fb_reboot(char *response)
+static void cb_reboot(char *cmd_parameter, char *fastboot_data,
+		      unsigned int fastboot_data_len, char *response)
 {
 	fastboot_okay(NULL, response);
 	if (!strcmp("reboot-bootloader", cmd_string))
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (11 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 12/20] fastboot: net: Convert command lookup to a table Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-01  6:49   ` Jocelyn Bohr
  2018-05-03 21:15   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot Alex Kiernan
                   ` (7 subsequent siblings)
  20 siblings, 2 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Extract fb_set_reboot_flag() from USB code and ensure all the overides
are included, then make the UDP fastboot code go through this same
path.

Note this changes the behaviour of the fastboot net code such that
"reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR for
use as a marker on reboot (the AOSP code in common/android-bootloader.c
uses this marker - this code could be reinstated there if that gets
merged).

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 arch/arm/mach-omap2/boot-common.c     |  2 +-
 arch/arm/mach-rockchip/rk3128-board.c |  2 +-
 arch/arm/mach-rockchip/rk322x-board.c |  2 +-
 drivers/fastboot/fb_common.c          |  5 +++++
 drivers/usb/gadget/f_fastboot.c       |  5 -----
 include/fastboot.h                    |  1 +
 net/fastboot.c                        | 17 +++++++++--------
 7 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-omap2/boot-common.c b/arch/arm/mach-omap2/boot-common.c
index f9ab5da..2be5c11 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -238,7 +238,7 @@ void arch_preboot_os(void)
 }
 #endif
 
-#if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
+#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
 int fb_set_reboot_flag(void)
 {
 	printf("Setting reboot to fastboot flag ...\n");
diff --git a/arch/arm/mach-rockchip/rk3128-board.c b/arch/arm/mach-rockchip/rk3128-board.c
index 2e8393d..00ad563 100644
--- a/arch/arm/mach-rockchip/rk3128-board.c
+++ b/arch/arm/mach-rockchip/rk3128-board.c
@@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum usb_init_type init)
 }
 #endif
 
-#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
+#if CONFIG_IS_ENABLED(FASTBOOT)
 int fb_set_reboot_flag(void)
 {
 	struct rk3128_grf *grf;
diff --git a/arch/arm/mach-rockchip/rk322x-board.c b/arch/arm/mach-rockchip/rk322x-board.c
index 8642a90..0ddfac8 100644
--- a/arch/arm/mach-rockchip/rk322x-board.c
+++ b/arch/arm/mach-rockchip/rk322x-board.c
@@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum usb_init_type init)
 }
 #endif
 
-#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
+#if CONFIG_IS_ENABLED(FASTBOOT)
 int fb_set_reboot_flag(void)
 {
 	struct rk322x_grf *grf;
diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 8b3627b..36ef669 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -102,3 +102,8 @@ int fastboot_lookup_command(const char *cmd_string)
 
 	return -1;
 }
+
+int __weak fb_set_reboot_flag(void)
+{
+	return -1;
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index a493c75..84515da 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -357,11 +357,6 @@ 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;
diff --git a/include/fastboot.h b/include/fastboot.h
index de07220..9767065 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -75,4 +75,5 @@ void timed_send_info(ulong *start, const char *msg);
 int strcmp_l1(const char *s1, const char *s2);
 
 int fastboot_lookup_command(const char *cmd_string);
+int fb_set_reboot_flag(void);
 #endif /* _FASTBOOT_H_ */
diff --git a/net/fastboot.c b/net/fastboot.c
index 155049a..edf78df 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -65,7 +65,7 @@ static void cb_flash(char *, char *, unsigned int, char *);
 static void cb_erase(char *, char *, unsigned int, char *);
 #endif
 static void cb_continue(char *, char *, unsigned int, char *);
-static void cb_reboot(char *, char *, unsigned int, char *);
+static void cb_reboot_bootloader(char *, char *, unsigned int, char *);
 
 static void (*fb_net_dispatch[])(char *cmd_parameter,
 				 char *fastboot_data,
@@ -83,8 +83,8 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
 #endif
 	[FB_CMD_BOOT] = cb_okay,
 	[FB_CMD_CONTINUE] = cb_continue,
-	[FB_CMD_REBOOT] = cb_reboot,
-	[FB_CMD_REBOOT_BOOTLOADER] = cb_reboot,
+	[FB_CMD_REBOOT] = cb_okay,
+	[FB_CMD_REBOOT_BOOTLOADER] = cb_reboot_bootloader,
 	[FB_CMD_POWERDOWN] = NULL,
 	[FB_CMD_SET_ACTIVE] = cb_okay,
 	[FB_CMD_UPLOAD] = NULL,
@@ -370,12 +370,13 @@ static void cb_continue(char *cmd_parameter, char *fastboot_data,
  *
  * @param repsonse    Pointer to fastboot response buffer
  */
-static void cb_reboot(char *cmd_parameter, char *fastboot_data,
-		      unsigned int fastboot_data_len, char *response)
+static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
+				 unsigned int fastboot_data_len, char *response)
 {
-	fastboot_okay(NULL, response);
-	if (!strcmp("reboot-bootloader", cmd_string))
-		strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR, "reboot-bootloader");
+	if (fb_set_reboot_flag())
+		fastboot_fail("Cannot set reboot flag", response);
+	else
+		fastboot_okay(NULL, response);
 }
 
 /**
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (12 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:17   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP Alex Kiernan
                   ` (6 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

When picking up boot/reboot after we've sent our result packet, use
the previously parsed command rather than redoing the strcmp.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 net/fastboot.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/net/fastboot.c b/net/fastboot.c
index edf78df..ad8c101 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -141,6 +141,7 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 	uchar *packet;
 	uchar *packet_base;
 	int len = 0;
+	int cmd = -1;
 	const char *error_msg = "An error occurred.";
 	short tmp;
 	struct fastboot_header fb_response_header = fb_header;
@@ -192,15 +193,13 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 			if (cmd_parameter)
 				cmd_parameter = strdup(cmd_parameter);
 		} else {
-			int i;
-
-			i = fastboot_lookup_command(cmd_string);
-			if (i >= 0) {
+			cmd = fastboot_lookup_command(cmd_string);
+			if (cmd >= 0) {
 				void (*fb_call)(char *cmd_parameter,
 						char *fastboot_data,
 						unsigned int fastboot_data_len,
 						char *response);
-				fb_call = fb_net_dispatch[i];
+				fb_call = fb_net_dispatch[cmd];
 				if (fb_call) {
 					fb_call(cmd_parameter, fastboot_data,
 						fastboot_data_len, response);
@@ -244,10 +243,10 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 
 	/* Continue boot process after sending response */
 	if (!strncmp("OKAY", response, 4)) {
-		if (!strcmp("boot", cmd_string)) {
+		if (cmd == FB_CMD_BOOT) {
 			boot_downloaded_image();
-		} else if (!strncmp("reboot", cmd_string, 6)) {
-			/* Matches reboot or reboot-bootloader */
+		} else if (cmd == FB_CMD_REBOOT ||
+			   cmd == FB_CMD_REBOOT_BOOTLOADER) {
 			do_reset(NULL, 0, 0, NULL);
 		}
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (13 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:21   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support Alex Kiernan
                   ` (5 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Merge USB and UDP boot code. The USB implementation stays the same, but
UDP no longer passes an fdt. We introduce a new environment variable
'fastbootcmd' which if set overrides the hardcoded boot command, setting
this then allows the UDP implementation to remain the same. If after
running 'fastbootcmd' the board has not booted, control is returned
to U-Boot and the fastboot process ends.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_common.c    | 27 +++++++++++++++++++++++++++
 drivers/usb/gadget/f_fastboot.c | 22 +++++++---------------
 include/fastboot.h              |  1 +
 net/fastboot.c                  | 16 ++--------------
 4 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
index 36ef669..73d8f94 100644
--- a/drivers/fastboot/fb_common.c
+++ b/drivers/fastboot/fb_common.c
@@ -107,3 +107,30 @@ int __weak fb_set_reboot_flag(void)
 {
 	return -1;
 }
+
+void fastboot_boot(void *addr)
+{
+	char *s;
+
+	s = env_get("fastbootcmd");
+	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%lx", (long)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);
+	}
+}
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 84515da..1dca4dd 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -480,18 +480,15 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req)
 	fastboot_tx_write_str(response);
 }
 
-static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
+static void do_exit_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);
+	g_dnl_trigger_detach();
+}
 
-	/* This only happens if image is somehow faulty so we start over */
-	do_reset(NULL, 0, 0, NULL);
+static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
+{
+	fastboot_boot((void *)CONFIG_FASTBOOT_BUF_ADDR);
+	do_exit_on_complete(ep, req);
 }
 
 static void cb_boot(struct usb_ep *ep, struct usb_request *req)
@@ -500,11 +497,6 @@ static void cb_boot(struct usb_ep *ep, struct usb_request *req)
 	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)
 {
 	fastboot_func->in_req->complete = do_exit_on_complete;
diff --git a/include/fastboot.h b/include/fastboot.h
index 9767065..64f9939 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -76,4 +76,5 @@ int strcmp_l1(const char *s1, const char *s2);
 
 int fastboot_lookup_command(const char *cmd_string);
 int fb_set_reboot_flag(void);
+void fastboot_boot(void *addr);
 #endif /* _FASTBOOT_H_ */
diff --git a/net/fastboot.c b/net/fastboot.c
index ad8c101..119011c 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -383,20 +383,8 @@ static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
  */
 static void boot_downloaded_image(void)
 {
-	char kernel_addr[12];
-	char *fdt_addr = env_get("fdt_addr_r");
-	char *const bootm_args[] = {
-		"bootm", kernel_addr, "-", fdt_addr, NULL
-	};
-
-	sprintf(kernel_addr, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
-
-	printf("\nBooting kernel at %s with fdt at %s...\n\n\n",
-	       kernel_addr, fdt_addr);
-	do_bootm(NULL, 0, 4, bootm_args);
-
-	/* This only happens if image is faulty so we start over. */
-	do_reset(NULL, 0, 0, NULL);
+	fastboot_boot((void *)CONFIG_FASTBOOT_BUF_ADDR);
+	net_set_state(NETLOOP_SUCCESS);
 }
 
 /**
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (14 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:24   ` Joe Hershberger
  2018-05-08  6:53   ` Jocelyn Bohr
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 17/20] fastboot: Guard getvar:partition-type/size with MMC Alex Kiernan
                   ` (4 subsequent siblings)
  20 siblings, 2 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Add NAND support to fastboot UDP flash/erase commands

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 net/fastboot.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/net/fastboot.c b/net/fastboot.c
index 119011c..a07b1ad 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -60,7 +60,7 @@ static int fastboot_our_port;
 static void cb_okay(char *, char *, unsigned int, char *);
 static void cb_getvar(char *, char *, unsigned int, char *);
 static void cb_download(char *, char *, unsigned int, char *);
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
 static void cb_flash(char *, char *, unsigned int, char *);
 static void cb_erase(char *, char *, unsigned int, char *);
 #endif
@@ -74,7 +74,7 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
 	[FB_CMD_GETVAR] = cb_getvar,
 	[FB_CMD_DOWNLOAD] = cb_download,
 	[FB_CMD_VERIFY] = NULL,
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
 	[FB_CMD_FLASH] = cb_flash,
 	[FB_CMD_ERASE] = cb_erase,
 #else
@@ -324,7 +324,7 @@ static void cb_download(char *cmd_parameter, char *fastboot_data,
 	}
 }
 
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
 /**
  * Writes the previously downloaded image to the partition indicated by
  * cmd_parameter. Writes to response.
@@ -334,8 +334,14 @@ static void cb_download(char *cmd_parameter, char *fastboot_data,
 static void cb_flash(char *cmd_parameter, char *fastboot_data,
 		     unsigned int fastboot_data_len, char *response)
 {
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 	fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
 			   image_size, response);
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
+	fb_nand_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
+			    image_size, response);
+#endif
 }
 
 /**
@@ -347,7 +353,12 @@ static void cb_flash(char *cmd_parameter, char *fastboot_data,
 static void cb_erase(char *cmd_parameter, char *fastboot_data,
 		     unsigned int fastboot_data_len, char *response)
 {
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 	fb_mmc_erase(cmd_parameter, response);
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
+	fb_nand_erase(cmd_parameter, response);
+#endif
 }
 #endif
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 17/20] fastboot: Guard getvar:partition-type/size with MMC
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (15 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:26   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 18/20] fastboot: Check if part_name is NULL before using it Alex Kiernan
                   ` (3 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Add guard for partition-type/size against MMC as we need that in order
to lookup partitions.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_getvar.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
index aa68371..7989a19 100644
--- a/drivers/fastboot/fb_getvar.c
+++ b/drivers/fastboot/fb_getvar.c
@@ -55,6 +55,7 @@ void fb_getvar(char *cmd_parameter, char *response)
 			fastboot_okay("yes", response);
 		else
 			fastboot_okay("no", response);
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
 	} else if (!strcmp_l1("partition-type", cmd_parameter) ||
 		   !strcmp_l1("partition-size", cmd_parameter)) {
 		disk_partition_t part_info;
@@ -74,6 +75,7 @@ void fb_getvar(char *cmd_parameter, char *response)
 			fastboot_response("OKAY", response,
 					  "0x%016x", (int)part_info.size);
 		}
+#endif
 	} else {
 #define FASTBOOT_ENV_PREFIX	"fastboot."
 		char envstr[FASTBOOT_RESPONSE_LEN];
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 18/20] fastboot: Check if part_name is NULL before using it
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (16 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 17/20] fastboot: Guard getvar:partition-type/size with MMC Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:26   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 19/20] fastboot: Add missing newlines Alex Kiernan
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

If we don't have a partition name passed, report it as not found.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_getvar.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
index 7989a19..cc74bab 100644
--- a/drivers/fastboot/fb_getvar.c
+++ b/drivers/fastboot/fb_getvar.c
@@ -66,7 +66,8 @@ void fb_getvar(char *cmd_parameter, char *response)
 		dev_desc = blk_get_dev("mmc", 0);
 		if (!dev_desc) {
 			fastboot_fail("block device not found", response);
-		} else if (part_get_info_by_name(dev_desc, part_name,
+		} else if (!part_name ||
+			   part_get_info_by_name(dev_desc, part_name,
 						 &part_info) < 0) {
 			fastboot_fail("partition not found", response);
 		} else if (!strcmp_l1("partition-type", cmd_parameter)) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 19/20] fastboot: Add missing newlines
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (17 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 18/20] fastboot: Check if part_name is NULL before using it Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:26   ` Joe Hershberger
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 20/20] fastboot: net: Split fastboot protocol out from net Alex Kiernan
  2018-05-02  6:33 ` [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Jocelyn Bohr
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Add newlines so we format our output correctly.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/fb_mmc.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
index 416f309..2f67965 100644
--- a/drivers/fastboot/fb_mmc.c
+++ b/drivers/fastboot/fb_mmc.c
@@ -154,7 +154,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 	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");
+		pr_err("invalid number of boot sectors: 0\n");
 		fastboot_fail("invalid number of boot sectors: 0", response);
 		return 0;
 	}
@@ -162,7 +162,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 	/* 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");
+		pr_err("cannot read header from boot partition\n");
 		fastboot_fail("cannot read header from boot partition",
 			      response);
 		return 0;
@@ -171,7 +171,7 @@ static lbaint_t fb_mmc_get_boot_header(struct blk_desc *dev_desc,
 	/* Check boot header magic string */
 	res = android_image_check_header(hdr);
 	if (res != 0) {
-		pr_err("bad boot image magic");
+		pr_err("bad boot image magic\n");
 		fastboot_fail("boot partition not initialized", response);
 		return 0;
 	}
@@ -210,7 +210,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	/* 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");
+		pr_err("cannot find boot partition\n");
 		fastboot_fail("cannot find boot partition", response);
 		return -1;
 	}
@@ -222,14 +222,14 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	/* 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");
+		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");
+		pr_err("moving second stage is not supported yet\n");
 		fastboot_fail("moving second stage is not supported yet",
 			      response);
 		return -1;
@@ -248,7 +248,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	res = blk_dread(dev_desc, ramdisk_sector_start, ramdisk_sectors,
 			ramdisk_buffer);
 	if (res != ramdisk_sectors) {
-		pr_err("cannot read ramdisk from boot partition");
+		pr_err("cannot read ramdisk from boot partition\n");
 		fastboot_fail("cannot read ramdisk from boot partition",
 			      response);
 		return -1;
@@ -258,7 +258,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	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");
+		pr_err("cannot writeback boot image header\n");
 		fastboot_fail("cannot write back boot image header", response);
 		return -1;
 	}
@@ -270,7 +270,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	res = blk_dwrite(dev_desc, kernel_sector_start, kernel_sectors,
 			 download_buffer);
 	if (res == 0) {
-		pr_err("cannot write new kernel");
+		pr_err("cannot write new kernel\n");
 		fastboot_fail("cannot write new kernel", response);
 		return -1;
 	}
@@ -282,7 +282,7 @@ static int fb_mmc_update_zimage(struct blk_desc *dev_desc,
 	res = blk_dwrite(dev_desc, ramdisk_sector_start, ramdisk_sectors,
 			 ramdisk_buffer);
 	if (res == 0) {
-		pr_err("cannot write back original ramdisk");
+		pr_err("cannot write back original ramdisk\n");
 		fastboot_fail("cannot write back original ramdisk", response);
 		return -1;
 	}
@@ -396,21 +396,21 @@ void fb_mmc_erase(const char *cmd, char *response)
 	struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV);
 
 	if (mmc == NULL) {
-		pr_err("invalid mmc device");
+		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");
+		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'", cmd);
+		pr_err("cannot find partition: '%s'\n", cmd);
 		fastboot_fail("cannot find partition", response);
 		return;
 	}
@@ -429,7 +429,7 @@ void fb_mmc_erase(const char *cmd, char *response)
 
 	blks = fb_mmc_blk_write(dev_desc, blks_start, blks_size, NULL);
 	if (blks != blks_size) {
-		pr_err("failed erasing from device %d", dev_desc->devnum);
+		pr_err("failed erasing from device %d\n", dev_desc->devnum);
 		fastboot_fail("failed erasing from device", response);
 		return;
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 20/20] fastboot: net: Split fastboot protocol out from net
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (18 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 19/20] fastboot: Add missing newlines Alex Kiernan
@ 2018-04-30  8:32 ` Alex Kiernan
  2018-05-03 21:29   ` Joe Hershberger
  2018-05-02  6:33 ` [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Jocelyn Bohr
  20 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-04-30  8:32 UTC (permalink / raw)
  To: u-boot

Separate the fastboot protocol handling from the fastboot UDP code in
preparation for reusing it in the USB code.

Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---

Changes in v2: None

 drivers/fastboot/Makefile    |   1 +
 drivers/fastboot/fb_packet.c | 249 +++++++++++++++++++++++++++++++++++++++++++
 include/fastboot.h           |   3 +
 net/fastboot.c               | 234 +---------------------------------------
 4 files changed, 258 insertions(+), 229 deletions(-)
 create mode 100644 drivers/fastboot/fb_packet.c

diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
index 9af4073..c0106a7 100644
--- a/drivers/fastboot/Makefile
+++ b/drivers/fastboot/Makefile
@@ -2,6 +2,7 @@
 
 obj-y += fb_common.o
 obj-y += fb_getvar.o
+obj-y += fb_packet.o
 obj-$(CONFIG_FASTBOOT_FLASH) += image-sparse.o
 
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o
diff --git a/drivers/fastboot/fb_packet.c b/drivers/fastboot/fb_packet.c
new file mode 100644
index 0000000..fbe5668
--- /dev/null
+++ b/drivers/fastboot/fb_packet.c
@@ -0,0 +1,249 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ */
+
+#include <common.h>
+#include <fastboot.h>
+#include <fb_mmc.h>
+#include <part.h>
+#include <stdlib.h>
+#include <version.h>
+
+/* Parsed from first fastboot command packet */
+static char *cmd_string;
+static char *cmd_parameter;
+static int cmd = -1;
+
+/* Fastboot download parameters */
+static unsigned int bytes_received;
+static unsigned int bytes_expected;
+static unsigned int image_size;
+
+static void cb_okay(char *, char *, unsigned int, char *);
+static void cb_getvar(char *, char *, unsigned int, char *);
+static void cb_download(char *, char *, unsigned int, char *);
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+static void cb_flash(char *, char *, unsigned int, char *);
+static void cb_erase(char *, char *, unsigned int, char *);
+#endif
+static void cb_continue(char *, char *, unsigned int, char *);
+static void cb_reboot_bootloader(char *, char *, unsigned int, char *);
+
+static void (*fb_net_dispatch[])(char *cmd_parameter,
+				 char *fastboot_data,
+				 unsigned int fastboot_data_len,
+				 char *response) = {
+	[FB_CMD_GETVAR] = cb_getvar,
+	[FB_CMD_DOWNLOAD] = cb_download,
+	[FB_CMD_VERIFY] = NULL,
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+	[FB_CMD_FLASH] = cb_flash,
+	[FB_CMD_ERASE] = cb_erase,
+#else
+	[FB_CMD_FLASH] = NULL,
+	[FB_CMD_ERASE] = NULL,
+#endif
+	[FB_CMD_BOOT] = cb_okay,
+	[FB_CMD_CONTINUE] = cb_continue,
+	[FB_CMD_REBOOT] = cb_okay,
+	[FB_CMD_REBOOT_BOOTLOADER] = cb_reboot_bootloader,
+	[FB_CMD_POWERDOWN] = NULL,
+	[FB_CMD_SET_ACTIVE] = cb_okay,
+	[FB_CMD_UPLOAD] = NULL,
+};
+
+static void cleanup_command_data(void);
+
+int fastboot_packet_handle(char *fastboot_data,
+			   unsigned int fastboot_data_len, char *response)
+{
+	if (!cmd_string) {
+		/* Parse command and send ack */
+		cmd_parameter = fastboot_data;
+		cmd_string = strsep(&cmd_parameter, ":");
+		cmd_string = strdup(cmd_string);
+		cmd = fastboot_lookup_command(cmd_string);
+		if (cmd_parameter)
+			cmd_parameter = strdup(cmd_parameter);
+	} else {
+		if (cmd >= 0) {
+			void (*fb_call)(char *cmd_parameter,
+					char *fastboot_data,
+					unsigned int fastboot_data_len,
+					char *response);
+			fb_call = fb_net_dispatch[cmd];
+			if (fb_call) {
+				fb_call(cmd_parameter, fastboot_data,
+					fastboot_data_len, response);
+			} else {
+				pr_err("command %s not implemented.\n",
+				       cmd_string);
+				fastboot_fail("unrecognized command",
+					      response);
+			}
+		} else {
+			pr_err("command %s not recognized.\n",
+			       cmd_string);
+			fastboot_fail("unrecognized command", response);
+		}
+	}
+	return cmd;
+}
+
+void fastboot_after_response(char *response)
+{
+	/* OKAY and FAIL indicate command is complete */
+	if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4))
+		cleanup_command_data();
+}
+
+static void cb_okay(char *cmd_parameter, char *fastboot_data,
+		    unsigned int fastboot_data_len, char *response)
+{
+	fastboot_okay(NULL, response);
+}
+
+static void cb_getvar(char *cmd_parameter, char *fastboot_data,
+		      unsigned int fastboot_data_len, char *response)
+{
+	fb_getvar(cmd_parameter, response);
+}
+
+/**
+ * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
+ * Writes to response.
+ *
+ * @param fastboot_data        Pointer to received fastboot data
+ * @param fastboot_data_len    Length of received fastboot data
+ * @param repsonse             Pointer to fastboot response buffer
+ */
+static void cb_download(char *cmd_parameter, char *fastboot_data,
+			unsigned int fastboot_data_len, char *response)
+{
+	char *tmp;
+
+	if (bytes_expected == 0) {
+		if (!cmd_parameter) {
+			fastboot_fail("Expected command parameter", response);
+			return;
+		}
+		bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
+		if (bytes_expected == 0) {
+			fastboot_fail("Expected nonzero image size", response);
+			return;
+		}
+	}
+	if (fastboot_data_len == 0 && bytes_received == 0) {
+		/* Nothing to download yet. Response is of the form:
+		 * [DATA|FAIL]$cmd_parameter
+		 *
+		 * where cmd_parameter is an 8 digit hexadecimal number
+		 */
+		if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
+			fastboot_fail(cmd_parameter, response);
+		else
+			fastboot_response("DATA", response, "%s",
+					  cmd_parameter);
+	} else if (fastboot_data_len == 0 &&
+		   (bytes_received >= bytes_expected)) {
+		/* Download complete. Respond with "OKAY" */
+		fastboot_okay(NULL, response);
+		image_size = bytes_received;
+		bytes_expected = 0;
+		bytes_received = 0;
+	} else {
+		if (fastboot_data_len == 0 ||
+		    (bytes_received + fastboot_data_len) > bytes_expected) {
+			fastboot_fail("Received invalid data length",
+				      response);
+			return;
+		}
+		/* Download data to CONFIG_FASTBOOT_BUF_ADDR */
+		memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + bytes_received,
+		       fastboot_data, fastboot_data_len);
+		bytes_received += fastboot_data_len;
+	}
+}
+
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
+/**
+ * Writes the previously downloaded image to the partition indicated by
+ * cmd_parameter. Writes to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void cb_flash(char *cmd_parameter, char *fastboot_data,
+		     unsigned int fastboot_data_len, char *response)
+{
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+	fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
+			   image_size, response);
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
+	fb_nand_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
+			    image_size, response);
+#endif
+}
+
+/**
+ * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes
+ * to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void cb_erase(char *cmd_parameter, char *fastboot_data,
+		     unsigned int fastboot_data_len, char *response)
+{
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
+	fb_mmc_erase(cmd_parameter, response);
+#endif
+#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
+	fb_nand_erase(cmd_parameter, response);
+#endif
+}
+#endif
+
+/**
+ * Continues normal boot process by exiting fastboot server. Writes
+ * to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void cb_continue(char *cmd_parameter, char *fastboot_data,
+			unsigned int fastboot_data_len, char *response)
+{
+	net_set_state(NETLOOP_SUCCESS);
+	fastboot_okay(NULL, response);
+}
+
+/**
+ * Sets reboot bootloader flag if requested. Writes to response.
+ *
+ * @param repsonse    Pointer to fastboot response buffer
+ */
+static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
+				 unsigned int fastboot_data_len, char *response)
+{
+	if (fb_set_reboot_flag())
+		fastboot_fail("Cannot set reboot flag", response);
+	else
+		fastboot_okay(NULL, response);
+}
+
+/**
+ * Frees any resources allocated during current fastboot command.
+ */
+static void cleanup_command_data(void)
+{
+	/* cmd_parameter and cmd_string potentially point to memory allocated by
+	 * strdup
+	 */
+	if (cmd_parameter)
+		free(cmd_parameter);
+	if (cmd_string)
+		free(cmd_string);
+	cmd_parameter = NULL;
+	cmd_string = NULL;
+	cmd = -1;
+}
diff --git a/include/fastboot.h b/include/fastboot.h
index 64f9939..4a02554 100644
--- a/include/fastboot.h
+++ b/include/fastboot.h
@@ -77,4 +77,7 @@ int strcmp_l1(const char *s1, const char *s2);
 int fastboot_lookup_command(const char *cmd_string);
 int fb_set_reboot_flag(void);
 void fastboot_boot(void *addr);
+int fastboot_packet_handle(char *fastboot_data,
+			   unsigned int fastboot_data_len, char *response);
+void fastboot_after_response(char *response);
 #endif /* _FASTBOOT_H_ */
diff --git a/net/fastboot.c b/net/fastboot.c
index a07b1ad..97f75a5 100644
--- a/net/fastboot.c
+++ b/net/fastboot.c
@@ -5,12 +5,8 @@
 
 #include <common.h>
 #include <fastboot.h>
-#include <fb_mmc.h>
 #include <net.h>
 #include <net/fastboot.h>
-#include <part.h>
-#include <stdlib.h>
-#include <version.h>
 
 /* Fastboot port # defined in spec */
 #define WELL_KNOWN_PORT 5554
@@ -42,56 +38,13 @@ static const unsigned short fb_udp_version = 1;
 static uchar last_packet[PACKET_SIZE];
 static unsigned int last_packet_len;
 
-/* Parsed from first fastboot command packet */
-static char *cmd_string;
-static char *cmd_parameter;
-
-/* Fastboot download parameters */
-static unsigned int bytes_received;
-static unsigned int bytes_expected;
-static unsigned int image_size;
-
 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 cb_okay(char *, char *, unsigned int, char *);
-static void cb_getvar(char *, char *, unsigned int, char *);
-static void cb_download(char *, char *, unsigned int, char *);
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
-static void cb_flash(char *, char *, unsigned int, char *);
-static void cb_erase(char *, char *, unsigned int, char *);
-#endif
-static void cb_continue(char *, char *, unsigned int, char *);
-static void cb_reboot_bootloader(char *, char *, unsigned int, char *);
-
-static void (*fb_net_dispatch[])(char *cmd_parameter,
-				 char *fastboot_data,
-				 unsigned int fastboot_data_len,
-				 char *response) = {
-	[FB_CMD_GETVAR] = cb_getvar,
-	[FB_CMD_DOWNLOAD] = cb_download,
-	[FB_CMD_VERIFY] = NULL,
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
-	[FB_CMD_FLASH] = cb_flash,
-	[FB_CMD_ERASE] = cb_erase,
-#else
-	[FB_CMD_FLASH] = NULL,
-	[FB_CMD_ERASE] = NULL,
-#endif
-	[FB_CMD_BOOT] = cb_okay,
-	[FB_CMD_CONTINUE] = cb_continue,
-	[FB_CMD_REBOOT] = cb_okay,
-	[FB_CMD_REBOOT_BOOTLOADER] = cb_reboot_bootloader,
-	[FB_CMD_POWERDOWN] = NULL,
-	[FB_CMD_SET_ACTIVE] = cb_okay,
-	[FB_CMD_UPLOAD] = NULL,
-};
-
 static void boot_downloaded_image(void);
-static void cleanup_command_data(void);
 
 void fastboot_send_info(const char *msg)
 {
@@ -185,36 +138,8 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 		packet += strlen(error_msg);
 		break;
 	case FASTBOOT_FASTBOOT:
-		if (!cmd_string) {
-			/* Parse command and send ack */
-			cmd_parameter = fastboot_data;
-			cmd_string = strsep(&cmd_parameter, ":");
-			cmd_string = strdup(cmd_string);
-			if (cmd_parameter)
-				cmd_parameter = strdup(cmd_parameter);
-		} else {
-			cmd = fastboot_lookup_command(cmd_string);
-			if (cmd >= 0) {
-				void (*fb_call)(char *cmd_parameter,
-						char *fastboot_data,
-						unsigned int fastboot_data_len,
-						char *response);
-				fb_call = fb_net_dispatch[cmd];
-				if (fb_call) {
-					fb_call(cmd_parameter, fastboot_data,
-						fastboot_data_len, response);
-				} else {
-					pr_err("command %s not implemented.\n",
-					       cmd_string);
-					fastboot_fail("unrecognized command",
-						      response);
-				}
-			} else {
-				pr_err("command %s not recognized.\n",
-				       cmd_string);
-				fastboot_fail("unrecognized command", response);
-			}
-		}
+		cmd = fastboot_packet_handle(fastboot_data, fastboot_data_len,
+					     response);
 		/* Sent some INFO packets, need to update sequence number in
 		 * header
 		 */
@@ -245,148 +170,15 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
 	if (!strncmp("OKAY", response, 4)) {
 		if (cmd == FB_CMD_BOOT) {
 			boot_downloaded_image();
+		} else if (cmd == FB_CMD_CONTINUE) {
+			net_set_state(NETLOOP_SUCCESS);
 		} else if (cmd == FB_CMD_REBOOT ||
 			   cmd == FB_CMD_REBOOT_BOOTLOADER) {
 			do_reset(NULL, 0, 0, NULL);
 		}
 	}
 
-	/* OKAY and FAIL indicate command is complete */
-	if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4))
-		cleanup_command_data();
-}
-
-static void cb_okay(char *cmd_parameter, char *fastboot_data,
-		    unsigned int fastboot_data_len, char *response)
-{
-	fastboot_okay(NULL, response);
-}
-
-static void cb_getvar(char *cmd_parameter, char *fastboot_data,
-		      unsigned int fastboot_data_len, char *response)
-{
-	fb_getvar(cmd_parameter, response);
-}
-
-/**
- * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
- * Writes to response.
- *
- * @param fastboot_data        Pointer to received fastboot data
- * @param fastboot_data_len    Length of received fastboot data
- * @param repsonse             Pointer to fastboot response buffer
- */
-static void cb_download(char *cmd_parameter, char *fastboot_data,
-			unsigned int fastboot_data_len, char *response)
-{
-	char *tmp;
-
-	if (bytes_expected == 0) {
-		if (!cmd_parameter) {
-			fastboot_fail("Expected command parameter", response);
-			return;
-		}
-		bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
-		if (bytes_expected == 0) {
-			fastboot_fail("Expected nonzero image size", response);
-			return;
-		}
-	}
-	if (fastboot_data_len == 0 && bytes_received == 0) {
-		/* Nothing to download yet. Response is of the form:
-		 * [DATA|FAIL]$cmd_parameter
-		 *
-		 * where cmd_parameter is an 8 digit hexadecimal number
-		 */
-		if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
-			fastboot_fail(cmd_parameter, response);
-		else
-			fastboot_response("DATA", response, "%s",
-					  cmd_parameter);
-	} else if (fastboot_data_len == 0 &&
-		   (bytes_received >= bytes_expected)) {
-		/* Download complete. Respond with "OKAY" */
-		fastboot_okay(NULL, response);
-		image_size = bytes_received;
-		bytes_expected = 0;
-		bytes_received = 0;
-	} else {
-		if (fastboot_data_len == 0 ||
-		    (bytes_received + fastboot_data_len) > bytes_expected) {
-			fastboot_fail("Received invalid data length",
-				      response);
-			return;
-		}
-		/* Download data to CONFIG_FASTBOOT_BUF_ADDR */
-		memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + bytes_received,
-		       fastboot_data, fastboot_data_len);
-		bytes_received += fastboot_data_len;
-	}
-}
-
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
-/**
- * Writes the previously downloaded image to the partition indicated by
- * cmd_parameter. Writes to response.
- *
- * @param repsonse    Pointer to fastboot response buffer
- */
-static void cb_flash(char *cmd_parameter, char *fastboot_data,
-		     unsigned int fastboot_data_len, char *response)
-{
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
-	fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
-			   image_size, response);
-#endif
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
-	fb_nand_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
-			    image_size, response);
-#endif
-}
-
-/**
- * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes
- * to response.
- *
- * @param repsonse    Pointer to fastboot response buffer
- */
-static void cb_erase(char *cmd_parameter, char *fastboot_data,
-		     unsigned int fastboot_data_len, char *response)
-{
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
-	fb_mmc_erase(cmd_parameter, response);
-#endif
-#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
-	fb_nand_erase(cmd_parameter, response);
-#endif
-}
-#endif
-
-/**
- * Continues normal boot process by exiting fastboot server. Writes
- * to response.
- *
- * @param repsonse    Pointer to fastboot response buffer
- */
-static void cb_continue(char *cmd_parameter, char *fastboot_data,
-			unsigned int fastboot_data_len, char *response)
-{
-	net_set_state(NETLOOP_SUCCESS);
-	fastboot_okay(NULL, response);
-}
-
-/**
- * Sets reboot bootloader flag if requested. Writes to response.
- *
- * @param repsonse    Pointer to fastboot response buffer
- */
-static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
-				 unsigned int fastboot_data_len, char *response)
-{
-	if (fb_set_reboot_flag())
-		fastboot_fail("Cannot set reboot flag", response);
-	else
-		fastboot_okay(NULL, response);
+	fastboot_after_response(response);
 }
 
 /**
@@ -399,22 +191,6 @@ static void boot_downloaded_image(void)
 }
 
 /**
- * Frees any resources allocated during current fastboot command.
- */
-static void cleanup_command_data(void)
-{
-	/* cmd_parameter and cmd_string potentially point to memory allocated by
-	 * strdup
-	 */
-	if (cmd_parameter)
-		free(cmd_parameter);
-	if (cmd_string)
-		free(cmd_string);
-	cmd_parameter = NULL;
-	cmd_string = NULL;
-}
-
-/**
  * Incoming UDP packet handler.
  *
  * @param packet  Pointer to incoming UDP packet
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 01/20] fastboot: Move fastboot to drivers/fastboot
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 01/20] fastboot: Move fastboot to drivers/fastboot Alex Kiernan
@ 2018-04-30 23:12   ` Simon Glass
  0 siblings, 0 replies; 74+ messages in thread
From: Simon Glass @ 2018-04-30 23:12 UTC (permalink / raw)
  To: u-boot

On 30 April 2018 at 02:32, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Separate CMD_FASTBOOT from FASTBOOT and move code and configuration to
> drivers/fastboot.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
>
> Changes in v2: None
>
>  cmd/Kconfig                                 | 14 ++++++++++++--
>  common/Makefile                             | 13 -------------
>  drivers/Kconfig                             |  2 ++
>  drivers/Makefile                            |  1 +
>  {cmd => drivers}/fastboot/Kconfig           | 12 ------------
>  drivers/fastboot/Makefile                   | 10 ++++++++++
>  {common => drivers/fastboot}/fb_mmc.c       |  0
>  {common => drivers/fastboot}/fb_nand.c      |  0
>  {common => drivers/fastboot}/image-sparse.c |  0
>  9 files changed, 25 insertions(+), 27 deletions(-)
>  rename {cmd => drivers}/fastboot/Kconfig (91%)
>  create mode 100644 drivers/fastboot/Makefile
>  rename {common => drivers/fastboot}/fb_mmc.c (100%)
>  rename {common => drivers/fastboot}/fb_nand.c (100%)
>  rename {common => drivers/fastboot}/image-sparse.c (100%)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot Alex Kiernan
@ 2018-05-01  6:28   ` Jocelyn Bohr
  2018-05-03 20:38   ` Joe Hershberger
  1 sibling, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-01  6:28 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

> Merge UDP fastboot support from AOSP:
>
>
> https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> Signed-off-by: Alex Deymo <deymo@google.com>
> ---
>
> Changes in v2:
> - ensure fastboot syntax is backward compatible - 'fastboot 0' means
>   'fastboot usb 0'
>
>  cmd/fastboot.c               |  35 ++-
>  cmd/net.c                    |   6 +
>  drivers/fastboot/Kconfig     |  16 +-
>  drivers/fastboot/fb_common.c |  18 ++
>  drivers/fastboot/fb_mmc.c    |  34 ++-
>  include/fastboot.h           |  13 ++
>  include/net.h                |   6 +-
>  include/net/fastboot.h       |  27 +++
>  net/Makefile                 |   1 +
>  net/fastboot.c               | 542
> +++++++++++++++++++++++++++++++++++++++++++
>  net/net.c                    |   9 +
>  11 files changed, 695 insertions(+), 12 deletions(-)
>  create mode 100644 include/net/fastboot.h
>  create mode 100644 net/fastboot.c
>
> diff --git a/cmd/fastboot.c b/cmd/fastboot.c
> index 8adcca5..68a41de 100644
> --- a/cmd/fastboot.c
> +++ b/cmd/fastboot.c
> @@ -11,17 +11,41 @@
>  #include <command.h>
>  #include <console.h>
>  #include <g_dnl.h>
> +#include <net.h>
>  #include <usb.h>
>
>  static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const
> argv[])
>  {
> +#ifdef CONFIG_USB_FUNCTION_FASTBOOT
>         int controller_index;
>         char *usb_controller;
>         int ret;
> +#endif
>
>         if (argc < 2)
>                 return CMD_RET_USAGE;
>
> +       if (!strcmp(argv[1], "udp")) {
> +#ifndef CONFIG_UDP_FUNCTION_FASTBOOT
> +               pr_err("Fastboot UDP not enabled\n");
> +               return -1;
> +#else
> +               return do_fastboot_udp(cmdtp, flag, argc, argv);
> +#endif
> +       }
> +
> +       if (!strcmp(argv[1], "usb")) {
> +               argv++;
> +               argc--;
> +       }
> +
> +       if (argc < 2)
> +               return CMD_RET_USAGE;
> +
> +#ifndef CONFIG_USB_FUNCTION_FASTBOOT
> +       pr_err("Fastboot USB not enabled\n");
> +       return -1;
> +#else
>         usb_controller = argv[1];
>         controller_index = simple_strtoul(usb_controller, NULL, 0);
>
> @@ -59,11 +83,14 @@ exit:
>         board_usb_cleanup(controller_index, USB_INIT_DEVICE);
>
>         return ret;
> +#endif
>  }
>
>  U_BOOT_CMD(
> -       fastboot, 2, 1, do_fastboot,
> -       "use USB Fastboot protocol",
> -       "<USB_controller>\n"
> -       "    - run as a fastboot usb device"
> +       fastboot, 3, 1, do_fastboot,
> +       "use USB or UDP Fastboot protocol",
> +       "[usb,udp] <USB_controller>\n"
> +       " - run as a fastboot usb or udp device\n"
> +       "   usb: specify <USB_controller>\n"
> +       "   udp: requires ip_addr set and ethernet initialized\n"
>  );
> diff --git a/cmd/net.c b/cmd/net.c
> index 67888d4..668f344 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -74,6 +74,12 @@ U_BOOT_CMD(
>  );
>  #endif
>
> +#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
> +int do_fastboot_udp(cmd_tbl_t *cmdtp, int flag, int argc, char *const
> argv[])
> +{
> +       return netboot_common(FASTBOOT, cmdtp, argc, argv);
> +}
> +#endif
>
>  #ifdef CONFIG_CMD_RARP
>  int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
> index 64b94f0..53c337f 100644
> --- a/drivers/fastboot/Kconfig
> +++ b/drivers/fastboot/Kconfig
> @@ -2,6 +2,8 @@ menu "Fastboot support"
>
>  config FASTBOOT
>         bool
> +       imply ANDROID_BOOT_IMAGE
> +       imply CMD_FASTBOOT
>
>  config USB_FUNCTION_FASTBOOT
>         bool "Enable USB fastboot gadget"
> @@ -9,12 +11,17 @@ config USB_FUNCTION_FASTBOOT
>         default y if ARCH_SUNXI && USB_MUSB_GADGET
>         select FASTBOOT
>         select USB_GADGET_DOWNLOAD
> -       imply ANDROID_BOOT_IMAGE
> -       imply CMD_FASTBOOT
>         help
>           This enables the USB part of the fastboot gadget.
>
> -if USB_FUNCTION_FASTBOOT
> +config UDP_FUNCTION_FASTBOOT
> +       depends on NET
> +       select FASTBOOT
> +       bool "Enable fastboot protocol over UDP"
> +       help
> +         This enables the fastboot protocol over UDP.
> +
> +if USB_FUNCTION_FASTBOOT || UDP_FUNCTION_FASTBOOT
>
>  config FASTBOOT_BUF_ADDR
>         hex "Define FASTBOOT buffer address"
> @@ -46,6 +53,7 @@ config FASTBOOT_BUF_SIZE
>
>  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
> @@ -117,6 +125,6 @@ config FASTBOOT_MBR_NAME
>           specified on the "fastboot flash" command line matches the value
>           defined here. The default target name for updating MBR is "mbr".
>
> -endif # USB_FUNCTION_FASTBOOT
> +endif # USB_FUNCTION_FASTBOOT || UDP_FUNCTION_FASTBOOT
>
>  endmenu
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> index fe58803..7367fbb 100644
> --- a/drivers/fastboot/fb_common.c
> +++ b/drivers/fastboot/fb_common.c
> @@ -12,6 +12,9 @@
>
>  #include <common.h>
>  #include <fastboot.h>
> +#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
> +#include <net/fastboot.h>
> +#endif
>
>  /**
>   * Writes a response to response buffer of the form "$tag$reason".
> @@ -44,3 +47,18 @@ void fastboot_okay(const char *reason, char *response)
>  {
>         fastboot_response("OKAY", response, "%s", reason);
>  }
> +
> +void timed_send_info(ulong *start, const char *msg)
> +{
> +#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
> +       /* 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_send_info(msg);
> +       }
> +#endif
> +}
> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
> index 02864aa..304bda1 100644
> --- a/drivers/fastboot/fb_mmc.c
> +++ b/drivers/fastboot/fb_mmc.c
> @@ -29,6 +29,9 @@
>  #define CONFIG_FASTBOOT_MBR_NAME "mbr"
>  #endif
>
> +#define FASTBOOT_MAX_BLK_WRITE 16384
> +static ulong timer;
> +
>  #define BOOT_PARTITION_NAME "boot"
>
>  struct fb_mmc_sparse {
> @@ -57,13 +60,38 @@ static int part_get_info_by_name_or_alias(struct
> blk_desc *dev_desc,
>         return ret;
>  }
>
> +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) {
> +                       timed_send_info(&timer, "writing");
> +                       blks_written = blk_dwrite(block_dev, blk,
> cur_blkcnt,
> +                                                 buffer + (i *
> block_dev->blksz));
> +               } else {
> +                       timed_send_info(&timer, "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 blk_dwrite(dev_desc, blk, blkcnt, buffer);
> +       return fb_mmc_blk_write(dev_desc, blk, blkcnt, buffer);
>  }
>
>  static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
> @@ -91,7 +119,7 @@ static void write_raw_image(struct blk_desc *dev_desc,
> disk_partition_t *info,
>
>         puts("Flashing Raw Image\n");
>
> -       blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
> +       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);
> @@ -399,7 +427,7 @@ void fb_mmc_erase(const char *cmd, char *response)
>         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);
> +       blks = fb_mmc_blk_write(dev_desc, blks_start, blks_size, NULL);
>         if (blks != blks_size) {
>                 pr_err("failed erasing from device %d", dev_desc->devnum);
>                 fastboot_fail("failed erasing from device", response);
> diff --git a/include/fastboot.h b/include/fastboot.h
> index 2140c94..6f69423 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -23,4 +23,17 @@ void fastboot_response(const char *tag, char *response,
>  void fastboot_fail(const char *reason, char *response);
>  void fastboot_okay(const char *reason, char *response);
>
> +/**
> + * Send an INFO packet during long commands based on timer. If
> + * CONFIG_UDP_FUNCTION_FASTBOOT is defined, an INFO packet is sent
> + * if the time is 30 seconds after start. Else, noop.
> + *
> + * TODO: Handle the situation where both UDP and USB fastboot are
> + *       enabled.
> + *
> + * @param start:  Time since last INFO packet was sent.
> + * @param msg:    String describing the reason for waiting
> + */
> +void timed_send_info(ulong *start, const char *msg);
> +
>  #endif /* _FASTBOOT_H_ */
> diff --git a/include/net.h b/include/net.h
> index 3469811..890ae27 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -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 */
> @@ -549,6 +549,10 @@ extern char *net_dns_resolve;              /* The
> host to resolve  */
>  extern char *net_dns_env_var;          /* the env var to put the ip into
> */
>  #endif
>
> +#if defined(CONFIG_UDP_FUNCTION_FASTBOOT)
> +int do_fastboot_udp(cmd_tbl_t *cmdtp, int flag, int argc, char *const
> argv[]);
> +#endif
> +
>  #if defined(CONFIG_CMD_PING)
>  extern struct in_addr net_ping_ip;     /* the ip address to ping */
>  #endif
> diff --git a/include/net/fastboot.h b/include/net/fastboot.h
> new file mode 100644
> index 0000000..c0dd033
> --- /dev/null
> +++ b/include/net/fastboot.h
> @@ -0,0 +1,27 @@
> +/* 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);
> +/**
> + * Send an INFO packet during long commands
> + *
> + * @param msg: String describing the reason for waiting
> + */
> +void fastboot_send_info(const char *msg);
> +
> +/**********************************************************************/
> +
> +#endif /* __NET_FASTBOOT_H__ */
> diff --git a/net/Makefile b/net/Makefile
> index ce6e5ad..3489ce5 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -25,6 +25,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
> index 0000000..32cb581
> --- /dev/null
> +++ b/net/fastboot.c
> @@ -0,0 +1,542 @@
> +// SPDX-License-Identifier: BSD-2-Clause
> +/*
> + * Copyright (C) 2016 The Android Open Source Project
> + */
> +
> +#include <common.h>
> +#include <fastboot.h>
> +#include <fb_mmc.h>
> +#include <net.h>
> +#include <net/fastboot.h>
> +#include <part.h>
> +#include <stdlib.h>
> +#include <version.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 FASTBOOT_HEADER_SIZE sizeof(struct fastboot_header)
> +#define DATA_SIZE (PACKET_SIZE - FASTBOOT_HEADER_SIZE)
> +#define FASTBOOT_VERSION "0.4"
> +
> +/* Sequence number sent for every packet */
> +static unsigned short fb_sequence_number = 1;
> +static const unsigned short fb_packet_size = PACKET_SIZE;
> +static const unsigned short fb_udp_version = 1;
> +
> +/* Keep track of last packet for resubmission */
> +static uchar last_packet[PACKET_SIZE];
> +static unsigned int last_packet_len;
> +
> +/* Parsed from first fastboot command packet */
> +static char *cmd_string;
> +static char *cmd_parameter;
> +
> +/* Fastboot download parameters */
> +static unsigned int bytes_received;
> +static unsigned int bytes_expected;
> +static unsigned int image_size;
> +
> +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 fb_getvar(char *);
> +static void fb_download(char *, unsigned int, char *);
> +static void fb_flash(char *);
> +static void fb_erase(char *);
> +static void fb_continue(char *);
> +static void fb_reboot(char *);
> +static void boot_downloaded_image(void);
> +static void cleanup_command_data(void);
> +static void write_fb_response(const char *, const char *, char *);
> +
> +void fastboot_send_info(const char *msg)
> +{
> +       uchar *packet;
> +       uchar *packet_base;
> +       int len = 0;
> +       char response[FASTBOOT_RESPONSE_LEN] = {0};
> +
> +       struct fastboot_header fb_response_header = {
> +               .id = FASTBOOT_FASTBOOT,
> +               .flags = 0,
> +               .seq = htons(fb_sequence_number)
> +       };
> +       ++fb_sequence_number;
> +       packet = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
> +       packet_base = packet;
> +
> +       /* Write headers */
> +       memcpy(packet, &fb_response_header, sizeof(fb_response_header));
> +       packet += sizeof(fb_response_header);
> +       /* Write response */
> +       write_fb_response("INFO", msg, response);
> +       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);
> +}
> +
> +/**
> + * Constructs and sends a packet in response to received fastboot packet
> + *
> + * @param fb_header            Header for response packet
> + * @param fastboot_data        Pointer to received fastboot data
> + * @param fastboot_data_len    Length of received fastboot data
> + * @param retransmit           Nonzero if sending last sent packet
> + */
> +static void fastboot_send(struct fastboot_header fb_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 fb_response_header = fb_header;
> +       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;
> +       }
> +
> +       fb_response_header.seq = htons(fb_response_header.seq);
> +       memcpy(packet, &fb_response_header, sizeof(fb_response_header));
> +       packet += sizeof(fb_response_header);
> +
> +       switch (fb_header.id) {
> +       case FASTBOOT_QUERY:
> +               tmp = htons(fb_sequence_number);
> +               memcpy(packet, &tmp, sizeof(tmp));
> +               packet += sizeof(tmp);
> +               break;
> +       case FASTBOOT_INIT:
> +               tmp = htons(fb_udp_version);
> +               memcpy(packet, &tmp, sizeof(tmp));
> +               packet += sizeof(tmp);
> +               tmp = htons(fb_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_string) {
> +                       /* Parse command and send ack */
> +                       cmd_parameter = fastboot_data;
> +                       cmd_string = strsep(&cmd_parameter, ":");
> +                       cmd_string = strdup(cmd_string);
> +                       if (cmd_parameter)
> +                               cmd_parameter = strdup(cmd_parameter);
> +               } else if (!strcmp("getvar", cmd_string)) {
> +                       fb_getvar(response);
> +               } else if (!strcmp("download", cmd_string)) {
> +                       fb_download(fastboot_data, fastboot_data_len,
> response);
> +               } else if (!strcmp("flash", cmd_string)) {
> +                       fb_flash(response);
> +               } else if (!strcmp("erase", cmd_string)) {
> +                       fb_erase(response);
> +               } else if (!strcmp("boot", cmd_string)) {
> +                       write_fb_response("OKAY", "", response);
> +               } else if (!strcmp("continue", cmd_string)) {
> +                       fb_continue(response);
> +               } else if (!strncmp("reboot", cmd_string, 6)) {
> +                       fb_reboot(response);
> +               } else if (!strcmp("set_active", cmd_string)) {
> +                       /* A/B not implemented, for now do nothing */
> +                       write_fb_response("OKAY", "", response);
> +               } else {
> +                       pr_err("command %s not implemented.\n",
> cmd_string);
> +                       write_fb_response("FAIL", "unrecognized command",
> +                                         response);
> +               }
> +               /* Sent some INFO packets, need to update sequence number
> in
> +                * header
> +                */
> +               if (fb_header.seq != fb_sequence_number) {
> +                       fb_response_header.seq = htons(fb_sequence_number);
> +                       memcpy(packet_base, &fb_response_header,
> +                              sizeof(fb_response_header));
> +               }
> +               /* Write response to packet */
> +               memcpy(packet, response, strlen(response));
> +               packet += strlen(response);
> +               break;
> +       default:
> +               pr_err("ID %d not implemented.\n", fb_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)) {
> +               if (!strcmp("boot", cmd_string)) {
> +                       boot_downloaded_image();
> +               } else if (!strcmp("continue", cmd_string)) {
> +                       run_command(env_get("bootcmd"), CMD_FLAG_ENV);
> +               } else if (!strncmp("reboot", cmd_string, 6)) {
> +                       /* Matches reboot or reboot-bootloader */
> +                       do_reset(NULL, 0, 0, NULL);
> +               }
> +       }
> +
> +       /* OKAY and FAIL indicate command is complete */
> +       if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4))
> +               cleanup_command_data();
> +}
> +
> +/**
> + * Writes ascii string specified by cmd_parameter to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_getvar(char *response)
> +{
> +       if (!cmd_parameter) {
> +               write_fb_response("FAIL", "missing var", response);
> +       } else if (!strcmp("version", cmd_parameter)) {
> +               write_fb_response("OKAY", FASTBOOT_VERSION, response);
> +       } else if (!strcmp("bootloader-version", cmd_parameter) ||
> +                  !strcmp("version-bootloader", cmd_parameter)) {
> +               write_fb_response("OKAY", U_BOOT_VERSION, response);
> +       } else if (!strcmp("downloadsize", cmd_parameter) ||
> +                  !strcmp("max-download-size", cmd_parameter)) {
> +               char buf_size_str[12];
> +
> +               sprintf(buf_size_str, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
> +               write_fb_response("OKAY", buf_size_str, response);
> +       } else if (!strcmp("serialno", cmd_parameter)) {
> +               const char *tmp = env_get("serial#");
> +
> +               if (tmp)
> +                       write_fb_response("OKAY", tmp, response);
> +               else
> +                       write_fb_response("FAIL", "Value not set",
> response);
> +       } else if (!strcmp("version-baseband", cmd_parameter)) {
> +               write_fb_response("OKAY", "N/A", response);
> +       } else if (!strcmp("product", cmd_parameter)) {
> +               const char *board = env_get("board");
> +
> +               if (board)
> +                       write_fb_response("OKAY", board, response);
> +               else
> +                       write_fb_response("FAIL", "Board not set",
> response);
> +       } else if (!strcmp("current-slot", cmd_parameter)) {
> +               /* A/B not implemented, for now always return _a */
> +               write_fb_response("OKAY", "_a", response);
> +       } else if (!strcmp("slot-suffixes", cmd_parameter)) {
> +               write_fb_response("OKAY", "_a,_b", response);
> +       } else if (!strncmp("has-slot", cmd_parameter, 8)) {
> +               char *part_name = cmd_parameter;
> +
> +               cmd_parameter = strsep(&part_name, ":");
> +               if (!strcmp(part_name, "boot") || !strcmp(part_name,
> "system"))
> +                       write_fb_response("OKAY", "yes", response);
> +               else
> +                       write_fb_response("OKAY", "no", response);
> +       } else if (!strncmp("partition-type", cmd_parameter, 14) ||
> +                  !strncmp("partition-size", cmd_parameter, 14)) {
> +               disk_partition_t part_info;
> +               struct blk_desc *dev_desc;
> +               char *part_name = cmd_parameter;
> +               char part_size_str[20];
> +
> +               cmd_parameter = strsep(&part_name, ":");
> +               dev_desc = blk_get_dev("mmc", 0);
> +               if (!dev_desc) {
> +                       write_fb_response("FAIL", "block device not found",
> +                                         response);
> +               } else if (part_get_info_by_name(dev_desc, part_name,
> +                                                &part_info) < 0) {
> +                       write_fb_response("FAIL", "partition not found",
> +                                         response);
> +               } else if (!strncmp("partition-type", cmd_parameter, 14)) {
> +                       write_fb_response("OKAY", (char *)part_info.type,
> +                                         response);
> +               } else if (!strncmp("partition-size", cmd_parameter, 14)) {
> +                       sprintf(part_size_str, "0x%016x",
> (int)part_info.size);
> +                       write_fb_response("OKAY", part_size_str, response);
> +               }
> +       } else {
> +               printf("WARNING: unknown variable: %s\n", cmd_parameter);
> +               write_fb_response("FAIL", "Variable not implemented",
> +                                 response);
> +       }
> +}
> +
> +/**
> + * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
> + * Writes to response.
> + *
> + * @param fastboot_data        Pointer to received fastboot data
> + * @param fastboot_data_len    Length of received fastboot data
> + * @param repsonse             Pointer to fastboot response buffer
> + */
> +static void fb_download(char *fastboot_data, unsigned int
> fastboot_data_len,
> +                       char *response)
> +{
> +       char *tmp;
> +
> +       if (bytes_expected == 0) {
> +               if (!cmd_parameter) {
> +                       write_fb_response("FAIL", "Expected command
> parameter",
> +                                         response);
> +                       return;
> +               }
> +               bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
> +               if (bytes_expected == 0) {
> +                       write_fb_response("FAIL", "Expected nonzero image
> size",
> +                                         response);
> +                       return;
> +               }
> +       }
> +       if (fastboot_data_len == 0 && bytes_received == 0) {
> +               /* Nothing to download yet. Response is of the form:
> +                * [DATA|FAIL]$cmd_parameter
> +                *
> +                * where cmd_parameter is an 8 digit hexadecimal number
> +                */
> +               if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
> +                       write_fb_response("FAIL", cmd_parameter, response);
> +               else
> +                       write_fb_response("DATA", cmd_parameter, response);
> +       } else if (fastboot_data_len == 0 &&
> +                  (bytes_received >= bytes_expected)) {
> +               /* Download complete. Respond with "OKAY" */
> +               write_fb_response("OKAY", "", response);
> +               image_size = bytes_received;
> +               bytes_expected = 0;
> +               bytes_received = 0;
> +       } else {
> +               if (fastboot_data_len == 0 ||
> +                   (bytes_received + fastboot_data_len) > bytes_expected)
> {
> +                       write_fb_response("FAIL",
> +                                         "Received invalid data length",
> +                                         response);
> +                       return;
> +               }
> +               /* Download data to CONFIG_FASTBOOT_BUF_ADDR */
> +               memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + bytes_received,
> +                      fastboot_data, fastboot_data_len);
> +               bytes_received += fastboot_data_len;
> +       }
> +}
> +
> +/**
> + * Writes the previously downloaded image to the partition indicated by
> + * cmd_parameter. Writes to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_flash(char *response)
> +{
> +       fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
> +                          image_size, response);
> +}
> +
> +/**
> + * Erases the partition indicated by cmd_parameter (clear to 0x00s).
> Writes
> + * to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_erase(char *response)
> +{
> +       fb_mmc_erase(cmd_parameter, response);
> +}
> +
> +/**
> + * Continues normal boot process by running "bootcmd". Writes
> + * to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_continue(char *response)
> +{
> +       char *bootcmd;
> +
> +       bootcmd = env_get("bootcmd");
> +       if (bootcmd)
> +               write_fb_response("OKAY", "", response);
> +       else
> +               write_fb_response("FAIL", "bootcmd not set", response);
> +}
> +
> +/**
> + * Sets reboot bootloader flag if requested. Writes to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_reboot(char *response)
> +{
> +       write_fb_response("OKAY", "", response);
> +       if (!strcmp("reboot-bootloader", cmd_string))
> +               strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR,
> "reboot-bootloader");
> +}
> +
> +/**
> + * Boots into downloaded image.
> + */
> +static void boot_downloaded_image(void)
> +{
> +       char kernel_addr[12];
> +       char *fdt_addr = env_get("fdt_addr_r");
> +       char *const bootm_args[] = {
> +               "bootm", kernel_addr, "-", fdt_addr, NULL
> +       };
> +
> +       sprintf(kernel_addr, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
> +
> +       printf("\nBooting kernel at %s with fdt at %s...\n\n\n",
> +              kernel_addr, fdt_addr);
> +       do_bootm(NULL, 0, 4, bootm_args);
> +
> +       /* This only happens if image is faulty so we start over. */
> +       do_reset(NULL, 0, 0, NULL);
> +}
> +
> +/**
> + * Writes a response to response buffer of the form "$tag$reason".
> + *
> + * @param tag         The first part of the response
> + * @param reason      The second part of the response
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void write_fb_response(const char *tag, const char *reason,
> +                             char *response)
> +{
> +       strncpy(response, tag, strlen(tag));
> +       strncat(response, reason, FASTBOOT_RESPONSE_LEN - strlen(tag) - 1);
> +}
> +
> +/**
> + * Frees any resources allocated during current fastboot command.
> + */
> +static void cleanup_command_data(void)
> +{
> +       /* cmd_parameter and cmd_string potentially point to memory
> allocated by
> +        * strdup
> +        */
> +       if (cmd_parameter)
> +               free(cmd_parameter);
> +       if (cmd_string)
> +               free(cmd_string);
> +       cmd_parameter = NULL;
> +       cmd_string = NULL;
> +}
> +
> +/**
> + * Incoming UDP packet handler.
> + *
> + * @param packet  Pointer to incoming UDP packet
> + * @param dport   Destination UDP port
> + * @param sip     Source IP address
> + * @param sport   Source UDP port
> + * @param 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 fb_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 < FASTBOOT_HEADER_SIZE || len > PACKET_SIZE)
> +               return;
> +       memcpy(&fb_header, packet, sizeof(fb_header));
> +       fb_header.flags = 0;
> +       fb_header.seq = ntohs(fb_header.seq);
> +       packet += sizeof(fb_header);
> +       len -= sizeof(fb_header);
> +
> +       switch (fb_header.id) {
> +       case FASTBOOT_QUERY:
> +               fastboot_send(fb_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 (fb_header.seq == fb_sequence_number) {
> +                       fastboot_send(fb_header, fastboot_data,
> +                                     fastboot_data_len, 0);
> +                       fb_sequence_number++;
> +               } else if (fb_header.seq == fb_sequence_number - 1) {
> +                       /* Retransmit last sent packet */
> +                       fastboot_send(fb_header, fastboot_data,
> +                                     fastboot_data_len, 1);
> +               }
> +               break;
> +       default:
> +               pr_err("ID %d not implemented.\n", fb_header.id);
> +               fb_header.id = FASTBOOT_ERROR;
> +               fastboot_send(fb_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;
> +
> +       net_set_udp_handler(fastboot_handler);
> +
> +       /* zero out server ether in case the server ip has changed */
> +       memset(net_server_ethaddr, 0, 6);
> +}
> diff --git a/net/net.c b/net/net.c
> index d222c1f..554df7a 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -87,6 +87,9 @@
>  #include <environment.h>
>  #include <errno.h>
>  #include <net.h>
> +#if defined(CONFIG_UDP_FUNCTION_FASTBOOT)
> +#include <net/fastboot.h>
> +#endif
>  #include <net/tftp.h>
>  #if defined(CONFIG_LED_STATUS)
>  #include <miiphy.h>
> @@ -451,6 +454,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 +1330,7 @@ common:
>                 /* Fall through */
>
>         case NETCONS:
> +       case FASTBOOT:
>         case TFTPSRV:
>                 if (net_ip.s_addr == 0) {
>                         puts("*** ERROR: `ipaddr' not set\n");
> --
> 2.7.4
>
>
 Signed-off-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling Alex Kiernan
@ 2018-05-01  6:49   ` Jocelyn Bohr
  2018-05-01  7:23     ` Alex Kiernan
  2018-05-03 21:15   ` Joe Hershberger
  1 sibling, 1 reply; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-01  6:49 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

> Extract fb_set_reboot_flag() from USB code and ensure all the overides
> are included, then make the UDP fastboot code go through this same
> path.
>
> Note this changes the behaviour of the fastboot net code such that
> "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR for
> use as a marker on reboot (the AOSP code in common/android-bootloader.c
> uses this marker - this code could be reinstated there if that gets
> merged).
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
>
> Changes in v2: None
>
>  arch/arm/mach-omap2/boot-common.c     |  2 +-
>  arch/arm/mach-rockchip/rk3128-board.c |  2 +-
>  arch/arm/mach-rockchip/rk322x-board.c |  2 +-
>  drivers/fastboot/fb_common.c          |  5 +++++
>  drivers/usb/gadget/f_fastboot.c       |  5 -----
>  include/fastboot.h                    |  1 +
>  net/fastboot.c                        | 17 +++++++++--------
>  7 files changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/boot-common.c
> b/arch/arm/mach-omap2/boot-common.c
> index f9ab5da..2be5c11 100644
> --- a/arch/arm/mach-omap2/boot-common.c
> +++ b/arch/arm/mach-omap2/boot-common.c
> @@ -238,7 +238,7 @@ void arch_preboot_os(void)
>  }
>  #endif
>
> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) &&
> !defined(CONFIG_ENV_IS_NOWHERE)
> +#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
>  int fb_set_reboot_flag(void)
>  {
>         printf("Setting reboot to fastboot flag ...\n");
> diff --git a/arch/arm/mach-rockchip/rk3128-board.c
> b/arch/arm/mach-rockchip/rk3128-board.c
> index 2e8393d..00ad563 100644
> --- a/arch/arm/mach-rockchip/rk3128-board.c
> +++ b/arch/arm/mach-rockchip/rk3128-board.c
> @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum usb_init_type
> init)
>  }
>  #endif
>
> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> +#if CONFIG_IS_ENABLED(FASTBOOT)
>  int fb_set_reboot_flag(void)
>  {
>         struct rk3128_grf *grf;
> diff --git a/arch/arm/mach-rockchip/rk322x-board.c
> b/arch/arm/mach-rockchip/rk322x-board.c
> index 8642a90..0ddfac8 100644
> --- a/arch/arm/mach-rockchip/rk322x-board.c
> +++ b/arch/arm/mach-rockchip/rk322x-board.c
> @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum usb_init_type
> init)
>  }
>  #endif
>
> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> +#if CONFIG_IS_ENABLED(FASTBOOT)
>  int fb_set_reboot_flag(void)
>  {
>         struct rk322x_grf *grf;
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> index 8b3627b..36ef669 100644
> --- a/drivers/fastboot/fb_common.c
> +++ b/drivers/fastboot/fb_common.c
> @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char *cmd_string)
>
>         return -1;
>  }
> +
> +int __weak fb_set_reboot_flag(void)
> +{
> +       return -1;
> +}
>
Instead could this write the string "reboot-bootloader" to
CONFIG_FASTBOOT_BUF_ADDR?


> diff --git a/drivers/usb/gadget/f_fastboot.c
> b/drivers/usb/gadget/f_fastboot.c
> index a493c75..84515da 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -357,11 +357,6 @@ 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;
> diff --git a/include/fastboot.h b/include/fastboot.h
> index de07220..9767065 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -75,4 +75,5 @@ void timed_send_info(ulong *start, const char *msg);
>  int strcmp_l1(const char *s1, const char *s2);
>
>  int fastboot_lookup_command(const char *cmd_string);
> +int fb_set_reboot_flag(void);
>  #endif /* _FASTBOOT_H_ */
> diff --git a/net/fastboot.c b/net/fastboot.c
> index 155049a..edf78df 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -65,7 +65,7 @@ static void cb_flash(char *, char *, unsigned int, char
> *);
>  static void cb_erase(char *, char *, unsigned int, char *);
>  #endif
>  static void cb_continue(char *, char *, unsigned int, char *);
> -static void cb_reboot(char *, char *, unsigned int, char *);
> +static void cb_reboot_bootloader(char *, char *, unsigned int, char *);
>
>  static void (*fb_net_dispatch[])(char *cmd_parameter,
>                                  char *fastboot_data,
> @@ -83,8 +83,8 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
>  #endif
>         [FB_CMD_BOOT] = cb_okay,
>         [FB_CMD_CONTINUE] = cb_continue,
> -       [FB_CMD_REBOOT] = cb_reboot,
>
Why is the normal reboot removed here?


> -       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot,
> +       [FB_CMD_REBOOT] = cb_okay,

+       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot_bootloader,
>         [FB_CMD_POWERDOWN] = NULL,
>         [FB_CMD_SET_ACTIVE] = cb_okay,
>         [FB_CMD_UPLOAD] = NULL,
> @@ -370,12 +370,13 @@ static void cb_continue(char *cmd_parameter, char
> *fastboot_data,
>   *
>   * @param repsonse    Pointer to fastboot response buffer
>   */
> -static void cb_reboot(char *cmd_parameter, char *fastboot_data,
> -                     unsigned int fastboot_data_len, char *response)
> +static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
> +                                unsigned int fastboot_data_len, char
> *response)
>  {
> -       fastboot_okay(NULL, response);
> -       if (!strcmp("reboot-bootloader", cmd_string))
> -               strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR,
> "reboot-bootloader");
> +       if (fb_set_reboot_flag())
> +               fastboot_fail("Cannot set reboot flag", response);
> +       else
> +               fastboot_okay(NULL, response);
>  }
>
>  /**
> --
> 2.7.4
>
>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-05-01  6:49   ` Jocelyn Bohr
@ 2018-05-01  7:23     ` Alex Kiernan
  2018-05-01  8:21       ` Alex Kiernan
  0 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-05-01  7:23 UTC (permalink / raw)
  To: u-boot

On Tue, May 1, 2018 at 7:50 AM Jocelyn Bohr <bohr@google.com> wrote:



> On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
wrote:

>> Extract fb_set_reboot_flag() from USB code and ensure all the overides
>> are included, then make the UDP fastboot code go through this same
>> path.

>> Note this changes the behaviour of the fastboot net code such that
>> "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR for
>> use as a marker on reboot (the AOSP code in common/android-bootloader.c
>> uses this marker - this code could be reinstated there if that gets
>> merged).

>> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>> ---

>> Changes in v2: None

>>   arch/arm/mach-omap2/boot-common.c     |  2 +-
>>   arch/arm/mach-rockchip/rk3128-board.c |  2 +-
>>   arch/arm/mach-rockchip/rk322x-board.c |  2 +-
>>   drivers/fastboot/fb_common.c          |  5 +++++
>>   drivers/usb/gadget/f_fastboot.c       |  5 -----
>>   include/fastboot.h                    |  1 +
>>   net/fastboot.c                        | 17 +++++++++--------
>>   7 files changed, 18 insertions(+), 16 deletions(-)

>> diff --git a/arch/arm/mach-omap2/boot-common.c
b/arch/arm/mach-omap2/boot-common.c
>> index f9ab5da..2be5c11 100644
>> --- a/arch/arm/mach-omap2/boot-common.c
>> +++ b/arch/arm/mach-omap2/boot-common.c
>> @@ -238,7 +238,7 @@ void arch_preboot_os(void)
>>   }
>>   #endif

>> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) &&
!defined(CONFIG_ENV_IS_NOWHERE)
>> +#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
>>   int fb_set_reboot_flag(void)
>>   {
>>          printf("Setting reboot to fastboot flag ...\n");
>> diff --git a/arch/arm/mach-rockchip/rk3128-board.c
b/arch/arm/mach-rockchip/rk3128-board.c
>> index 2e8393d..00ad563 100644
>> --- a/arch/arm/mach-rockchip/rk3128-board.c
>> +++ b/arch/arm/mach-rockchip/rk3128-board.c
>> @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum usb_init_type
init)
>>   }
>>   #endif

>> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
>> +#if CONFIG_IS_ENABLED(FASTBOOT)
>>   int fb_set_reboot_flag(void)
>>   {
>>          struct rk3128_grf *grf;
>> diff --git a/arch/arm/mach-rockchip/rk322x-board.c
b/arch/arm/mach-rockchip/rk322x-board.c
>> index 8642a90..0ddfac8 100644
>> --- a/arch/arm/mach-rockchip/rk322x-board.c
>> +++ b/arch/arm/mach-rockchip/rk322x-board.c
>> @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum usb_init_type
init)
>>   }
>>   #endif

>> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
>> +#if CONFIG_IS_ENABLED(FASTBOOT)
>>   int fb_set_reboot_flag(void)
>>   {
>>          struct rk322x_grf *grf;
>> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
>> index 8b3627b..36ef669 100644
>> --- a/drivers/fastboot/fb_common.c
>> +++ b/drivers/fastboot/fb_common.c
>> @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char *cmd_string)

>>          return -1;
>>   }
>> +
>> +int __weak fb_set_reboot_flag(void)
>> +{
>> +       return -1;
>> +}

> Instead could this write the string "reboot-bootloader" to
CONFIG_FASTBOOT_BUF_ADDR?


I guess the thing you lose is you don't then get a default "I don't know
how to do that" response. Am I right in thinking you're only using this
behaviour on Raspberry Pi, or is it broader?


>> diff --git a/drivers/usb/gadget/f_fastboot.c
b/drivers/usb/gadget/f_fastboot.c
>> index a493c75..84515da 100644
>> --- a/drivers/usb/gadget/f_fastboot.c
>> +++ b/drivers/usb/gadget/f_fastboot.c
>> @@ -357,11 +357,6 @@ 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;
>> diff --git a/include/fastboot.h b/include/fastboot.h
>> index de07220..9767065 100644
>> --- a/include/fastboot.h
>> +++ b/include/fastboot.h
>> @@ -75,4 +75,5 @@ void timed_send_info(ulong *start, const char *msg);
>>   int strcmp_l1(const char *s1, const char *s2);

>>   int fastboot_lookup_command(const char *cmd_string);
>> +int fb_set_reboot_flag(void);
>>   #endif /* _FASTBOOT_H_ */
>> diff --git a/net/fastboot.c b/net/fastboot.c
>> index 155049a..edf78df 100644
>> --- a/net/fastboot.c
>> +++ b/net/fastboot.c
>> @@ -65,7 +65,7 @@ static void cb_flash(char *, char *, unsigned int,
char *);
>>   static void cb_erase(char *, char *, unsigned int, char *);
>>   #endif
>>   static void cb_continue(char *, char *, unsigned int, char *);
>> -static void cb_reboot(char *, char *, unsigned int, char *);
>> +static void cb_reboot_bootloader(char *, char *, unsigned int, char *);

>>   static void (*fb_net_dispatch[])(char *cmd_parameter,
>>                                   char *fastboot_data,
>> @@ -83,8 +83,8 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
>>   #endif
>>          [FB_CMD_BOOT] = cb_okay,
>>          [FB_CMD_CONTINUE] = cb_continue,
>> -       [FB_CMD_REBOOT] = cb_reboot,

> Why is the normal reboot removed here?


The reboot handling is really all in the post-packet handling, so for a
reboot all you need is the OKAY which gets added two lines down in that
patch:

-       [FB_CMD_REBOOT] = cb_reboot,
-       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot,
+       [FB_CMD_REBOOT] = cb_okay,
+       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot_bootloader,

And then leverage the reboot handling further down the flow:

                 } else if (cmd == FB_CMD_REBOOT ||
                            cmd == FB_CMD_REBOOT_BOOTLOADER) {
                         do_reset(NULL, 0, 0, NULL);
                 }

I guess the biggest change overall here is to introduce named identifiers
for the commands rather than doing prefix matching.

That said I should split this patch out as it's not doing what the commit
says.

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-05-01  7:23     ` Alex Kiernan
@ 2018-05-01  8:21       ` Alex Kiernan
  2018-05-02  5:46         ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-05-01  8:21 UTC (permalink / raw)
  To: u-boot

On Tue, May 1, 2018 at 8:22 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:


> On Tue, May 1, 2018 at 7:50 AM Jocelyn Bohr <bohr@google.com> wrote:



> > On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
> wrote:

> >> Extract fb_set_reboot_flag() from USB code and ensure all the overides
> >> are included, then make the UDP fastboot code go through this same
> >> path.

> >> Note this changes the behaviour of the fastboot net code such that
> >> "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR
for
> >> use as a marker on reboot (the AOSP code in common/android-bootloader.c
> >> uses this marker - this code could be reinstated there if that gets
> >> merged).

> >> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> >> ---

> >> Changes in v2: None

> >>   arch/arm/mach-omap2/boot-common.c     |  2 +-
> >>   arch/arm/mach-rockchip/rk3128-board.c |  2 +-
> >>   arch/arm/mach-rockchip/rk322x-board.c |  2 +-
> >>   drivers/fastboot/fb_common.c          |  5 +++++
> >>   drivers/usb/gadget/f_fastboot.c       |  5 -----
> >>   include/fastboot.h                    |  1 +
> >>   net/fastboot.c                        | 17 +++++++++--------
> >>   7 files changed, 18 insertions(+), 16 deletions(-)

> >> diff --git a/arch/arm/mach-omap2/boot-common.c
> b/arch/arm/mach-omap2/boot-common.c
> >> index f9ab5da..2be5c11 100644
> >> --- a/arch/arm/mach-omap2/boot-common.c
> >> +++ b/arch/arm/mach-omap2/boot-common.c
> >> @@ -238,7 +238,7 @@ void arch_preboot_os(void)
> >>   }
> >>   #endif

> >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) &&
> !defined(CONFIG_ENV_IS_NOWHERE)
> >> +#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
> >>   int fb_set_reboot_flag(void)
> >>   {
> >>          printf("Setting reboot to fastboot flag ...\n");
> >> diff --git a/arch/arm/mach-rockchip/rk3128-board.c
> b/arch/arm/mach-rockchip/rk3128-board.c
> >> index 2e8393d..00ad563 100644
> >> --- a/arch/arm/mach-rockchip/rk3128-board.c
> >> +++ b/arch/arm/mach-rockchip/rk3128-board.c
> >> @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum usb_init_type
> init)
> >>   }
> >>   #endif

> >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> >> +#if CONFIG_IS_ENABLED(FASTBOOT)
> >>   int fb_set_reboot_flag(void)
> >>   {
> >>          struct rk3128_grf *grf;
> >> diff --git a/arch/arm/mach-rockchip/rk322x-board.c
> b/arch/arm/mach-rockchip/rk322x-board.c
> >> index 8642a90..0ddfac8 100644
> >> --- a/arch/arm/mach-rockchip/rk322x-board.c
> >> +++ b/arch/arm/mach-rockchip/rk322x-board.c
> >> @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum usb_init_type
> init)
> >>   }
> >>   #endif

> >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> >> +#if CONFIG_IS_ENABLED(FASTBOOT)
> >>   int fb_set_reboot_flag(void)
> >>   {
> >>          struct rk322x_grf *grf;
> >> diff --git a/drivers/fastboot/fb_common.c
b/drivers/fastboot/fb_common.c
> >> index 8b3627b..36ef669 100644
> >> --- a/drivers/fastboot/fb_common.c
> >> +++ b/drivers/fastboot/fb_common.c
> >> @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char *cmd_string)

> >>          return -1;
> >>   }
> >> +
> >> +int __weak fb_set_reboot_flag(void)
> >> +{
> >> +       return -1;
> >> +}

> > Instead could this write the string "reboot-bootloader" to
> CONFIG_FASTBOOT_BUF_ADDR?


> I guess the thing you lose is you don't then get a default "I don't know
> how to do that" response. Am I right in thinking you're only using this
> behaviour on Raspberry Pi, or is it broader?


Thinking about this some more... if we moved that string write into the
default fb_set_reboot_flag implementation and then guarded the
reboot-bootloader command with a new Kconfig symbol, you could get the "I
don't know how to do that" behaviour by disabling the command?

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-05-01  8:21       ` Alex Kiernan
@ 2018-05-02  5:46         ` Jocelyn Bohr
  2018-05-02  5:51           ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-02  5:46 UTC (permalink / raw)
  To: u-boot

On Tue, May 1, 2018 at 1:21 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

> On Tue, May 1, 2018 at 8:22 AM Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
>
>
> > On Tue, May 1, 2018 at 7:50 AM Jocelyn Bohr <bohr@google.com> wrote:
>
>
>
> > > On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
> > wrote:
>
> > >> Extract fb_set_reboot_flag() from USB code and ensure all the overides
> > >> are included, then make the UDP fastboot code go through this same
> > >> path.
>
> > >> Note this changes the behaviour of the fastboot net code such that
> > >> "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR
> for
> > >> use as a marker on reboot (the AOSP code in
> common/android-bootloader.c
> > >> uses this marker - this code could be reinstated there if that gets
> > >> merged).
>
> > >> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> > >> ---
>
> > >> Changes in v2: None
>
> > >>   arch/arm/mach-omap2/boot-common.c     |  2 +-
> > >>   arch/arm/mach-rockchip/rk3128-board.c |  2 +-
> > >>   arch/arm/mach-rockchip/rk322x-board.c |  2 +-
> > >>   drivers/fastboot/fb_common.c          |  5 +++++
> > >>   drivers/usb/gadget/f_fastboot.c       |  5 -----
> > >>   include/fastboot.h                    |  1 +
> > >>   net/fastboot.c                        | 17 +++++++++--------
> > >>   7 files changed, 18 insertions(+), 16 deletions(-)
>
> > >> diff --git a/arch/arm/mach-omap2/boot-common.c
> > b/arch/arm/mach-omap2/boot-common.c
> > >> index f9ab5da..2be5c11 100644
> > >> --- a/arch/arm/mach-omap2/boot-common.c
> > >> +++ b/arch/arm/mach-omap2/boot-common.c
> > >> @@ -238,7 +238,7 @@ void arch_preboot_os(void)
> > >>   }
> > >>   #endif
>
> > >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) &&
> > !defined(CONFIG_ENV_IS_NOWHERE)
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
> > >>   int fb_set_reboot_flag(void)
> > >>   {
> > >>          printf("Setting reboot to fastboot flag ...\n");
> > >> diff --git a/arch/arm/mach-rockchip/rk3128-board.c
> > b/arch/arm/mach-rockchip/rk3128-board.c
> > >> index 2e8393d..00ad563 100644
> > >> --- a/arch/arm/mach-rockchip/rk3128-board.c
> > >> +++ b/arch/arm/mach-rockchip/rk3128-board.c
> > >> @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum
> usb_init_type
> > init)
> > >>   }
> > >>   #endif
>
> > >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT)
> > >>   int fb_set_reboot_flag(void)
> > >>   {
> > >>          struct rk3128_grf *grf;
> > >> diff --git a/arch/arm/mach-rockchip/rk322x-board.c
> > b/arch/arm/mach-rockchip/rk322x-board.c
> > >> index 8642a90..0ddfac8 100644
> > >> --- a/arch/arm/mach-rockchip/rk322x-board.c
> > >> +++ b/arch/arm/mach-rockchip/rk322x-board.c
> > >> @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum
> usb_init_type
> > init)
> > >>   }
> > >>   #endif
>
> > >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT)
> > >>   int fb_set_reboot_flag(void)
> > >>   {
> > >>          struct rk322x_grf *grf;
> > >> diff --git a/drivers/fastboot/fb_common.c
> b/drivers/fastboot/fb_common.c
> > >> index 8b3627b..36ef669 100644
> > >> --- a/drivers/fastboot/fb_common.c
> > >> +++ b/drivers/fastboot/fb_common.c
> > >> @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char
> *cmd_string)
>
> > >>          return -1;
> > >>   }
> > >> +
> > >> +int __weak fb_set_reboot_flag(void)
> > >> +{
> > >> +       return -1;
> > >> +}
>
> > > Instead could this write the string "reboot-bootloader" to
> > CONFIG_FASTBOOT_BUF_ADDR?
>
>
> > I guess the thing you lose is you don't then get a default "I don't know
> > how to do that" response. Am I right in thinking you're only using this
> > behaviour on Raspberry Pi, or is it broader?
>
>
> Thinking about this some more... if we moved that string write into the
> default fb_set_reboot_flag implementation and then guarded the
> reboot-bootloader command with a new Kconfig symbol, you could get the "I
> don't know how to do that" behaviour by disabling the command?
>

The "reboot-bootloader" behavior isn't RPi specific, it's part of the
fastboot
protocol and is required by all Android bootloaders that support fastboot.

https://android.googlesource.com/platform/system/core/+/master/fastboot/

So my thinking was that since it's part of the protocol, the weak function
could
have some default implementation. I can't think of a reason for a device to
support fastboot but not the "reboot-bootloader" command.

-- 
> Alex Kiernan
>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-05-02  5:46         ` Jocelyn Bohr
@ 2018-05-02  5:51           ` Jocelyn Bohr
  2018-05-02  8:24             ` Alex Kiernan
  0 siblings, 1 reply; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-02  5:51 UTC (permalink / raw)
  To: u-boot

On Tue, May 1, 2018 at 10:46 PM Jocelyn Bohr <bohr@google.com> wrote:

>
>
> On Tue, May 1, 2018 at 1:21 AM Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
>
>> On Tue, May 1, 2018 at 8:22 AM Alex Kiernan <alex.kiernan@gmail.com>
>> wrote:
>>
>>
>> > On Tue, May 1, 2018 at 7:50 AM Jocelyn Bohr <bohr@google.com> wrote:
>>
>>
>>
>> > > On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
>> > wrote:
>>
>> > >> Extract fb_set_reboot_flag() from USB code and ensure all the
>> overides
>> > >> are included, then make the UDP fastboot code go through this same
>> > >> path.
>>
>> > >> Note this changes the behaviour of the fastboot net code such that
>> > >> "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR
>> for
>> > >> use as a marker on reboot (the AOSP code in
>> common/android-bootloader.c
>> > >> uses this marker - this code could be reinstated there if that gets
>> > >> merged).
>>
>> > >> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>> > >> ---
>>
>> > >> Changes in v2: None
>>
>> > >>   arch/arm/mach-omap2/boot-common.c     |  2 +-
>> > >>   arch/arm/mach-rockchip/rk3128-board.c |  2 +-
>> > >>   arch/arm/mach-rockchip/rk322x-board.c |  2 +-
>> > >>   drivers/fastboot/fb_common.c          |  5 +++++
>> > >>   drivers/usb/gadget/f_fastboot.c       |  5 -----
>> > >>   include/fastboot.h                    |  1 +
>> > >>   net/fastboot.c                        | 17 +++++++++--------
>> > >>   7 files changed, 18 insertions(+), 16 deletions(-)
>>
>> > >> diff --git a/arch/arm/mach-omap2/boot-common.c
>> > b/arch/arm/mach-omap2/boot-common.c
>> > >> index f9ab5da..2be5c11 100644
>> > >> --- a/arch/arm/mach-omap2/boot-common.c
>> > >> +++ b/arch/arm/mach-omap2/boot-common.c
>> > >> @@ -238,7 +238,7 @@ void arch_preboot_os(void)
>> > >>   }
>> > >>   #endif
>>
>> > >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) &&
>> > !defined(CONFIG_ENV_IS_NOWHERE)
>> > >> +#if CONFIG_IS_ENABLED(FASTBOOT) &&
>> !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
>> > >>   int fb_set_reboot_flag(void)
>> > >>   {
>> > >>          printf("Setting reboot to fastboot flag ...\n");
>> > >> diff --git a/arch/arm/mach-rockchip/rk3128-board.c
>> > b/arch/arm/mach-rockchip/rk3128-board.c
>> > >> index 2e8393d..00ad563 100644
>> > >> --- a/arch/arm/mach-rockchip/rk3128-board.c
>> > >> +++ b/arch/arm/mach-rockchip/rk3128-board.c
>> > >> @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum
>> usb_init_type
>> > init)
>> > >>   }
>> > >>   #endif
>>
>> > >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
>> > >> +#if CONFIG_IS_ENABLED(FASTBOOT)
>> > >>   int fb_set_reboot_flag(void)
>> > >>   {
>> > >>          struct rk3128_grf *grf;
>> > >> diff --git a/arch/arm/mach-rockchip/rk322x-board.c
>> > b/arch/arm/mach-rockchip/rk322x-board.c
>> > >> index 8642a90..0ddfac8 100644
>> > >> --- a/arch/arm/mach-rockchip/rk322x-board.c
>> > >> +++ b/arch/arm/mach-rockchip/rk322x-board.c
>> > >> @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum
>> usb_init_type
>> > init)
>> > >>   }
>> > >>   #endif
>>
>> > >> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
>> > >> +#if CONFIG_IS_ENABLED(FASTBOOT)
>> > >>   int fb_set_reboot_flag(void)
>> > >>   {
>> > >>          struct rk322x_grf *grf;
>> > >> diff --git a/drivers/fastboot/fb_common.c
>> b/drivers/fastboot/fb_common.c
>> > >> index 8b3627b..36ef669 100644
>> > >> --- a/drivers/fastboot/fb_common.c
>> > >> +++ b/drivers/fastboot/fb_common.c
>> > >> @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char
>> *cmd_string)
>>
>> > >>          return -1;
>> > >>   }
>> > >> +
>> > >> +int __weak fb_set_reboot_flag(void)
>> > >> +{
>> > >> +       return -1;
>> > >> +}
>>
>> > > Instead could this write the string "reboot-bootloader" to
>> > CONFIG_FASTBOOT_BUF_ADDR?
>>
>>
>> > I guess the thing you lose is you don't then get a default "I don't know
>> > how to do that" response. Am I right in thinking you're only using this
>> > behaviour on Raspberry Pi, or is it broader?
>>
>>
>> Thinking about this some more... if we moved that string write into the
>> default fb_set_reboot_flag implementation and then guarded the
>> reboot-bootloader command with a new Kconfig symbol, you could get the "I
>> don't know how to do that" behaviour by disabling the command?
>>
>
> The "reboot-bootloader" behavior isn't RPi specific, it's part of the
> fastboot
> protocol and is required by all Android bootloaders that support fastboot.
>
> https://android.googlesource.com/platform/system/core/+/master/fastboot/
>
> So my thinking was that since it's part of the protocol, the weak function
> could
> have some default implementation. I can't think of a reason for a device to
> support fastboot but not the "reboot-bootloader" command.
>

I think I'm also fine with adding a default implementation later, when
common/android-bootloader.c from AOSP gets merged. That would probably make
more sense, because currently nothing in the upstream code reads the
"reboot-bootloader" flag. But I prefer to not add a new Kconfig to guard the
reboot-bootloader command.


> --
>> Alex Kiernan
>>
>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support
  2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
                   ` (19 preceding siblings ...)
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 20/20] fastboot: net: Split fastboot protocol out from net Alex Kiernan
@ 2018-05-02  6:33 ` Jocelyn Bohr
  2018-05-02  8:14   ` Alex Kiernan
  20 siblings, 1 reply; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-02  6:33 UTC (permalink / raw)
  To: u-boot

Hi Alex,

I think this approach looks really good so far, and will make maintaining
both
implementations easier going forward. I haven't looked at every change here
yet, but when going through the patches should I add a "Reviewed-by:" line
if
the change looks good to me?

Thanks,
Jocelyn

On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

>
> This series merges the fastboot UDP support from AOSP into mainline
> U-Boot.
>
> The underlying implementations of most commands are now merged between
> both code paths ('oem format' from the USB side is the only one remaining).
>
> Other changes to command handling so that UDP follows the existing USB
> behaviour:
>
> - 'boot' now follows the USB code and does 'fastboot
> CONFIG_FASTBOOT_BUF_ADDR'.
>   I've added 'fastbootcmd' which if set overrides the boot command and
>   allows the existing UDP behaviour to be preserved.
>

The UDP behavior more correct based on the specification.
"The previously downloaded data is a boot.img and should be booted
according to
the normal procedure for a boot.img."

https://android.googlesource.com/platform/system/core/+/master/fastboot/

I'm not sure who we will break if we change the USB code...also we probably
want to make sure image verification happens with "fastboot boot", making
sure
"fastboot boot" doesn't allow booting an unverified kernel on locked
devices. I
think we can add that flow later though, upstream U-boot doesn't support
lock/unlock commands anyway.


> - 'continue' in UDP now exits the fastboot server rather than executing
>   'run bootcmd'
> - 'reboot-bootloader' no longer writes 'reboot-bootloader' to
>   CONFIG_FASTBOOT_BUF_ADDR as its marker for the subsequent boot. The code
>   which is in AOSP common/android_bootloader.c expects this marker, but
>   we have prior art in the USB code using the weak function
>   fb_set_reboot_flag
> - 'getvar' in the UDP path now supports fetching 'fastboot.' prefixed
>   variables (inherited from the USB path)
> - 'getvar' in the USB path inherits all the variables from the UDP path
>
> Remaining issues:
>
> - whilst I've merged NAND support into the UDP code path, I've no way
>   of testing it. My expectation is it'll work, but will need
> timed_send_info
>   working into the NAND path to avoid timeouts on the network side.


I don't know of any devices that use NAND and the fastboot UDP code, so
I'm inclined to say this is okay.

- I still need to fix timed_send_info handling when going through the USB
>   path.
> - the protocol part of the fastboot UDP implementation is separated out
>   and would I expect form the basis of a consolidated implementation, but
>   I'm inclined to address that as a clearly separate patch so it can be
>   tested in isolation (I have no USB hardware I can try this on).
>

Should this set of patches be tested on USB hardware too? There are some
changes here to the USB implementation.


>
> Changes in v2:
> - ensure fastboot syntax is backward compatible - 'fastboot 0' means
>   'fastboot usb 0'
>
> Alex Kiernan (20):
>   fastboot: Move fastboot to drivers/fastboot
>   fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT
>   fastboot: Refactor fastboot_okay/fail to take response
>   fastboot: Extract fastboot_okay/fail to fb_common.c
>   fastboot: Introduce fastboot_response and refactor fastboot_okay/fail
>   fastboot: Correct dependencies in FASTBOOT_FLASH
>   net: fastboot: Merge AOSP UDP fastboot
>   net: fastboot: Support building without MMC
>   fastboot: Refactor write_fb_response into fastboot_okay/fail/response
>   fastboot: Merge USB and UDP getvar implementation
>   fastboot: net: Change 'continue' so it matches USB fastboot
>   fastboot: net: Convert command lookup to a table
>   fastboot: Merge reboot-bootloader handling
>   fastboot: Avoid re-parsing cmd_string for boot/reboot
>   fastboot: Merge boot common across USB and UDP
>   fastboot: net: Add NAND support
>   fastboot: Guard getvar:partition-type/size with MMC
>   fastboot: Check if part_name is NULL before using it
>   fastboot: Add missing newlines
>   fastboot: net: Split fastboot protocol out from net
>
>  arch/arm/Kconfig                                 |   2 -
>  arch/arm/mach-omap2/boot-common.c                |   2 +-
>  arch/arm/mach-omap2/utils.c                      |   4 +-
>  arch/arm/mach-rockchip/rk3128-board.c            |   2 +-
>  arch/arm/mach-rockchip/rk322x-board.c            |   2 +-
>  board/ti/common/Kconfig                          |   1 -
>  cmd/Kconfig                                      |  14 +-
>  cmd/fastboot.c                                   |  35 ++-
>  cmd/net.c                                        |   6 +
>  common/Makefile                                  |  13 --
>  configs/am335x_boneblack_defconfig               |   2 +-
>  configs/am335x_boneblack_vboot_defconfig         |   2 +-
>  configs/am335x_evm_defconfig                     |   2 +-
>  configs/am335x_evm_nor_defconfig                 |   2 +-
>  configs/am335x_evm_norboot_defconfig             |   2 +-
>  configs/am335x_evm_spiboot_defconfig             |   2 +-
>  configs/am335x_evm_usbspl_defconfig              |   2 +-
>  configs/am57xx_evm_defconfig                     |   2 +-
>  configs/am57xx_hs_evm_defconfig                  |   2 +-
>  configs/bcm23550_w1d_defconfig                   |   2 +-
>  configs/bcm28155_ap_defconfig                    |   2 +-
>  configs/birdland_bav335a_defconfig               |   2 +-
>  configs/birdland_bav335b_defconfig               |   2 +-
>  configs/cgtqmx6eval_defconfig                    |   2 +-
>  configs/dra7xx_evm_defconfig                     |   2 +-
>  configs/dra7xx_hs_evm_defconfig                  |   2 +-
>  configs/kc1_defconfig                            |   2 +-
>  configs/mx6qsabrelite_defconfig                  |   2 +-
>  configs/mx6sabresd_defconfig                     |   2 +-
>  configs/nitrogen6dl2g_defconfig                  |   2 +-
>  configs/nitrogen6dl_defconfig                    |   2 +-
>  configs/nitrogen6q2g_defconfig                   |   2 +-
>  configs/nitrogen6q_defconfig                     |   2 +-
>  configs/nitrogen6s1g_defconfig                   |   2 +-
>  configs/nitrogen6s_defconfig                     |   2 +-
>  configs/omap3_beagle_defconfig                   |   2 +-
>  configs/omap3_evm_defconfig                      |   2 +-
>  configs/omap3_logic_defconfig                    |   2 +-
>  configs/sniper_defconfig                         |   2 +-
>  configs/stih410-b2260_defconfig                  |   2 +-
>  configs/xilinx_zynqmp_zc1751_xm015_dc1_defconfig |   2 +-
>  configs/xilinx_zynqmp_zc1751_xm016_dc2_defconfig |   2 +-
>  configs/xilinx_zynqmp_zcu102_rev1_0_defconfig    |   2 +-
>  configs/xilinx_zynqmp_zcu102_revA_defconfig      |   2 +-
>  configs/xilinx_zynqmp_zcu102_revB_defconfig      |   2 +-
>  configs/xilinx_zynqmp_zcu106_revA_defconfig      |   2 +-
>  drivers/Kconfig                                  |   2 +
>  drivers/Makefile                                 |   1 +
>  {cmd => drivers}/fastboot/Kconfig                |  46 ++--
>  drivers/fastboot/Makefile                        |   9 +
>  drivers/fastboot/fb_common.c                     | 136 ++++++++++++
>  drivers/fastboot/fb_getvar.c                     |  96 +++++++++
>  {common => drivers/fastboot}/fb_mmc.c            | 142 +++++++-----
>  {common => drivers/fastboot}/fb_nand.c           |  31 +--
>  drivers/fastboot/fb_packet.c                     | 249
> +++++++++++++++++++++
>  {common => drivers/fastboot}/image-sparse.c      |  41 ++--
>  drivers/usb/gadget/f_fastboot.c                  | 133 ++----------
>  include/fastboot.h                               |  65 +++++-
>  include/fb_mmc.h                                 |   4 +-
>  include/fb_nand.h                                |   4 +-
>  include/image-sparse.h                           |   2 +-
>  include/net.h                                    |   6 +-
>  include/net/fastboot.h                           |  27 +++
>  net/Makefile                                     |   1 +
>  net/fastboot.c                                   | 262
> +++++++++++++++++++++++
>  net/net.c                                        |   9 +
>  66 files changed, 1123 insertions(+), 296 deletions(-)
>  rename {cmd => drivers}/fastboot/Kconfig (86%)
>  create mode 100644 drivers/fastboot/Makefile
>  create mode 100644 drivers/fastboot/fb_common.c
>  create mode 100644 drivers/fastboot/fb_getvar.c
>  rename {common => drivers/fastboot}/fb_mmc.c (71%)
>  rename {common => drivers/fastboot}/fb_nand.c (86%)
>  create mode 100644 drivers/fastboot/fb_packet.c
>  rename {common => drivers/fastboot}/image-sparse.c (89%)
>  create mode 100644 include/net/fastboot.h
>  create mode 100644 net/fastboot.c
>
> --
> 2.7.4
>
>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support
  2018-05-02  6:33 ` [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Jocelyn Bohr
@ 2018-05-02  8:14   ` Alex Kiernan
  2018-05-08  7:13     ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-05-02  8:14 UTC (permalink / raw)
  To: u-boot

On Wed, May 2, 2018 at 7:34 AM Jocelyn Bohr <bohr@google.com> wrote:

> Hi Alex,

> I think this approach looks really good so far, and will make maintaining
both
> implementations easier going forward. I haven't looked at every change
here
> yet, but when going through the patches should I add a "Reviewed-by:"
line if
> the change looks good to me?


Yes please!

> Thanks,
> Jocelyn

> On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
wrote:


>> This series merges the fastboot UDP support from AOSP into mainline
>> U-Boot.

>> The underlying implementations of most commands are now merged between
>> both code paths ('oem format' from the USB side is the only one
remaining).

>> Other changes to command handling so that UDP follows the existing USB
>> behaviour:

>> - 'boot' now follows the USB code and does 'fastboot
CONFIG_FASTBOOT_BUF_ADDR'.
>>    I've added 'fastbootcmd' which if set overrides the boot command and
>>    allows the existing UDP behaviour to be preserved.


> The UDP behavior more correct based on the specification.
> "The previously downloaded data is a boot.img and should be booted
according to
> the normal procedure for a boot.img."

> https://android.googlesource.com/platform/system/core/+/master/fastboot/

> I'm not sure who we will break if we change the USB code...

Making sure we don't break (or at least trying my hardest to) existing
upstream code was my aim in this. If the right thing is to change it, then
do that when the android bootflow gets merged?

> also we probably
> want to make sure image verification happens with "fastboot boot", making
sure
> "fastboot boot" doesn't allow booting an unverified kernel on locked
devices. I
> think we can add that flow later though, upstream U-boot doesn't support
> lock/unlock commands anyway.


I think running a general command here (via 'fastbootcmd') should give
enough options to implement that policy. For my use case fastboot is
actually just a convenient technology and I don't need the Android image
format or bootflow... so I'm getting my signature verification out of a
signed FIT image, and use something like:

fastbootcmd='setenv verify yes; bootm 0x81000800#conf at 0'


>> - 'continue' in UDP now exits the fastboot server rather than executing
>>    'run bootcmd'
>> - 'reboot-bootloader' no longer writes 'reboot-bootloader' to
>>    CONFIG_FASTBOOT_BUF_ADDR as its marker for the subsequent boot. The
code
>>    which is in AOSP common/android_bootloader.c expects this marker, but
>>    we have prior art in the USB code using the weak function
>>    fb_set_reboot_flag
>> - 'getvar' in the UDP path now supports fetching 'fastboot.' prefixed
>>    variables (inherited from the USB path)
>> - 'getvar' in the USB path inherits all the variables from the UDP path

>> Remaining issues:

>> - whilst I've merged NAND support into the UDP code path, I've no way
>>    of testing it. My expectation is it'll work, but will need
timed_send_info
>>    working into the NAND path to avoid timeouts on the network side.


> I don't know of any devices that use NAND and the fastboot UDP code, so
> I'm inclined to say this is okay.


I think so... it's not broken today because there's no UDP and NAND code in
upstream, if someone needs that then the mechanics are all there to wire it
in (and I've no way of testing it).

>> - I still need to fix timed_send_info handling when going through the USB
>>    path.
>> - the protocol part of the fastboot UDP implementation is separated out
>>    and would I expect form the basis of a consolidated implementation, but
>>    I'm inclined to address that as a clearly separate patch so it can be
>>    tested in isolation (I have no USB hardware I can try this on).


> Should this set of patches be tested on USB hardware too? There are some
> changes here to the USB implementation.


My aim thus far was to keep them sufficiently minimal that you get decide
on correctness by inspection, which isn't to say I've actually got it
right, but I'm hopeful. That said you can't beat a real test!

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-05-02  5:51           ` Jocelyn Bohr
@ 2018-05-02  8:24             ` Alex Kiernan
  0 siblings, 0 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-05-02  8:24 UTC (permalink / raw)
  To: u-boot

On Wed, May 2, 2018 at 6:51 AM Jocelyn Bohr <bohr@verily.com> wrote:



> On Tue, May 1, 2018 at 10:46 PM Jocelyn Bohr <bohr@google.com> wrote:



>> On Tue, May 1, 2018 at 1:21 AM Alex Kiernan <alex.kiernan@gmail.com>
wrote:

>>> On Tue, May 1, 2018 at 8:22 AM Alex Kiernan <alex.kiernan@gmail.com>
wrote:


>>> > On Tue, May 1, 2018 at 7:50 AM Jocelyn Bohr <bohr@google.com> wrote:



>>> > > On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com

>>> > wrote:


...

>>> > >> diff --git a/drivers/fastboot/fb_common.c
>>> b/drivers/fastboot/fb_common.c
>>> > >> index 8b3627b..36ef669 100644
>>> > >> --- a/drivers/fastboot/fb_common.c
>>> > >> +++ b/drivers/fastboot/fb_common.c
>>> > >> @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char
*cmd_string)

>>> > >>          return -1;
>>> > >>   }
>>> > >> +
>>> > >> +int __weak fb_set_reboot_flag(void)
>>> > >> +{
>>> > >> +       return -1;
>>> > >> +}

>>> > > Instead could this write the string "reboot-bootloader" to
>>> > CONFIG_FASTBOOT_BUF_ADDR?


>>> > I guess the thing you lose is you don't then get a default "I don't
know
>>> > how to do that" response. Am I right in thinking you're only using
this
>>> > behaviour on Raspberry Pi, or is it broader?


>>> Thinking about this some more... if we moved that string write into the
>>> default fb_set_reboot_flag implementation and then guarded the
>>> reboot-bootloader command with a new Kconfig symbol, you could get the
"I
>>> don't know how to do that" behaviour by disabling the command?


>> The "reboot-bootloader" behavior isn't RPi specific, it's part of the
fastboot
>> protocol and is required by all Android bootloaders that support
fastboot.

>> https://android.googlesource.com/platform/system/core/+/master/fastboot/

>> So my thinking was that since it's part of the protocol, the weak
function could
>> have some default implementation. I can't think of a reason for a device
to
>> support fastboot but not the "reboot-bootloader" command.


> I think I'm also fine with adding a default implementation later, when
> common/android-bootloader.c from AOSP gets merged. That would probably
make
> more sense, because currently nothing in the upstream code reads the
> "reboot-bootloader" flag. But I prefer to not add a new Kconfig to guard
the
> reboot-bootloader command.


Thanks, I'll leave it like it is...

Whenever code to honour it gets added, the various other mechanisms that
already exist for fb_set_reboot_flag() want looking at too as there's a mix
of approaches today (my least favourite of which is
arch/arm/mach-omap2/boot-common.c... which the board I'm interested in ends
up using).

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 02/20] fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 02/20] fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT Alex Kiernan
@ 2018-05-03 18:19   ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 18:19 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Anyone who wants FASTBOOT before this series wants USB_FUNCTION_FASTBOOT.
> Split USB_FUNCTION_FASTBOOT from FASTBOOT so they retain their existing
> behaviour.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 03/20] fastboot: Refactor fastboot_okay/fail to take response
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 03/20] fastboot: Refactor fastboot_okay/fail to take response Alex Kiernan
@ 2018-05-03 18:24   ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 18:24 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Add the response string as a parameter to fastboot_okay/fail, instead
> of modifying a global, to match the contract expected by the AOSP
> U-Boot code.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 04/20] fastboot: Extract fastboot_okay/fail to fb_common.c
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 04/20] fastboot: Extract fastboot_okay/fail to fb_common.c Alex Kiernan
@ 2018-05-03 18:26   ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 18:26 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Add drivers/fastboot/fb_common.c, where fastboot_okay/fail are implemented
> so we can call them from a non-USB implementation.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 05/20] fastboot: Introduce fastboot_response and refactor fastboot_okay/fail
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 05/20] fastboot: Introduce fastboot_response and refactor fastboot_okay/fail Alex Kiernan
@ 2018-05-03 18:28   ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 18:28 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Introduce fastboot_response which takes varargs parameters so we can
> use it to generate formatted response strings. Refactor fastboot_okay/fail
> to use it.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 06/20] fastboot: Correct dependencies in FASTBOOT_FLASH
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 06/20] fastboot: Correct dependencies in FASTBOOT_FLASH Alex Kiernan
@ 2018-05-03 18:34   ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 18:34 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Ensure that when selecting FASTBOOT_FLASH you end up with a buildable
> configuration. Prior to this you could select NAND without MTDPARTS
> and end up with an image which (surprisingly) excluded NAND.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot Alex Kiernan
  2018-05-01  6:28   ` Jocelyn Bohr
@ 2018-05-03 20:38   ` Joe Hershberger
  2018-05-08  9:11     ` Alex Kiernan
  1 sibling, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 20:38 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Merge UDP fastboot support from AOSP:
>
> https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> Signed-off-by: Alex Deymo <deymo@google.com>
> ---
>
> Changes in v2:
> - ensure fastboot syntax is backward compatible - 'fastboot 0' means
>   'fastboot usb 0'
>
>  cmd/fastboot.c               |  35 ++-
>  cmd/net.c                    |   6 +
>  drivers/fastboot/Kconfig     |  16 +-
>  drivers/fastboot/fb_common.c |  18 ++
>  drivers/fastboot/fb_mmc.c    |  34 ++-
>  include/fastboot.h           |  13 ++
>  include/net.h                |   6 +-
>  include/net/fastboot.h       |  27 +++
>  net/Makefile                 |   1 +
>  net/fastboot.c               | 542 +++++++++++++++++++++++++++++++++++++++++++
>  net/net.c                    |   9 +
>  11 files changed, 695 insertions(+), 12 deletions(-)
>  create mode 100644 include/net/fastboot.h
>  create mode 100644 net/fastboot.c
>
> diff --git a/cmd/fastboot.c b/cmd/fastboot.c
> index 8adcca5..68a41de 100644
> --- a/cmd/fastboot.c
> +++ b/cmd/fastboot.c
> @@ -11,17 +11,41 @@
>  #include <command.h>
>  #include <console.h>
>  #include <g_dnl.h>
> +#include <net.h>
>  #include <usb.h>
>
>  static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
>  {
> +#ifdef CONFIG_USB_FUNCTION_FASTBOOT
>         int controller_index;
>         char *usb_controller;
>         int ret;
> +#endif
>
>         if (argc < 2)
>                 return CMD_RET_USAGE;
>
> +       if (!strcmp(argv[1], "udp")) {
> +#ifndef CONFIG_UDP_FUNCTION_FASTBOOT
> +               pr_err("Fastboot UDP not enabled\n");
> +               return -1;

Commands should always return an enum command_ret_t.

> +#else
> +               return do_fastboot_udp(cmdtp, flag, argc, argv);
> +#endif
> +       }
> +
> +       if (!strcmp(argv[1], "usb")) {
> +               argv++;
> +               argc--;
> +       }
> +
> +       if (argc < 2)
> +               return CMD_RET_USAGE;
> +
> +#ifndef CONFIG_USB_FUNCTION_FASTBOOT
> +       pr_err("Fastboot USB not enabled\n");
> +       return -1;

Commands should always return an enum command_ret_t.

> +#else
>         usb_controller = argv[1];
>         controller_index = simple_strtoul(usb_controller, NULL, 0);
>
> @@ -59,11 +83,14 @@ exit:
>         board_usb_cleanup(controller_index, USB_INIT_DEVICE);
>
>         return ret;
> +#endif
>  }
>
>  U_BOOT_CMD(
> -       fastboot, 2, 1, do_fastboot,
> -       "use USB Fastboot protocol",
> -       "<USB_controller>\n"
> -       "    - run as a fastboot usb device"
> +       fastboot, 3, 1, do_fastboot,
> +       "use USB or UDP Fastboot protocol",
> +       "[usb,udp] <USB_controller>\n"
> +       " - run as a fastboot usb or udp device\n"
> +       "   usb: specify <USB_controller>\n"
> +       "   udp: requires ip_addr set and ethernet initialized\n"
>  );
> diff --git a/cmd/net.c b/cmd/net.c
> index 67888d4..668f344 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -74,6 +74,12 @@ U_BOOT_CMD(
>  );
>  #endif
>
> +#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
> +int do_fastboot_udp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])

You should move this to cmd/fastboot.c and make it static.

> +{
> +       return netboot_common(FASTBOOT, cmdtp, argc, argv);

Is this really what you want? You are passing these command
parameters, but you don't really want them to be interpreted (as a
load address or file name), right?

I think you just want this:

        int err = net_loop(FASTBOOT);

        if (err < 0) {
                printf("fastboot udp error: %i\n", err);
                return CMD_RET_FAILURE;
        }

        return CMD_RET_SUCCESS;


> +}
> +#endif
>
>  #ifdef CONFIG_CMD_RARP
>  int do_rarpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig
> index 64b94f0..53c337f 100644
> --- a/drivers/fastboot/Kconfig
> +++ b/drivers/fastboot/Kconfig
> @@ -2,6 +2,8 @@ menu "Fastboot support"
>
>  config FASTBOOT
>         bool
> +       imply ANDROID_BOOT_IMAGE
> +       imply CMD_FASTBOOT
>
>  config USB_FUNCTION_FASTBOOT
>         bool "Enable USB fastboot gadget"
> @@ -9,12 +11,17 @@ config USB_FUNCTION_FASTBOOT
>         default y if ARCH_SUNXI && USB_MUSB_GADGET
>         select FASTBOOT
>         select USB_GADGET_DOWNLOAD
> -       imply ANDROID_BOOT_IMAGE
> -       imply CMD_FASTBOOT
>         help
>           This enables the USB part of the fastboot gadget.
>
> -if USB_FUNCTION_FASTBOOT
> +config UDP_FUNCTION_FASTBOOT
> +       depends on NET

This is the correct level of dependency once you start using net_loop
directly, but based on how you have it now, you would have to depend
on CMD_NET.

> +       select FASTBOOT
> +       bool "Enable fastboot protocol over UDP"
> +       help
> +         This enables the fastboot protocol over UDP.
> +
> +if USB_FUNCTION_FASTBOOT || UDP_FUNCTION_FASTBOOT
>
>  config FASTBOOT_BUF_ADDR
>         hex "Define FASTBOOT buffer address"
> @@ -46,6 +53,7 @@ config FASTBOOT_BUF_SIZE
>
>  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
> @@ -117,6 +125,6 @@ config FASTBOOT_MBR_NAME
>           specified on the "fastboot flash" command line matches the value
>           defined here. The default target name for updating MBR is "mbr".
>
> -endif # USB_FUNCTION_FASTBOOT
> +endif # USB_FUNCTION_FASTBOOT || UDP_FUNCTION_FASTBOOT
>
>  endmenu
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> index fe58803..7367fbb 100644
> --- a/drivers/fastboot/fb_common.c
> +++ b/drivers/fastboot/fb_common.c
> @@ -12,6 +12,9 @@
>
>  #include <common.h>
>  #include <fastboot.h>
> +#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
> +#include <net/fastboot.h>
> +#endif
>
>  /**
>   * Writes a response to response buffer of the form "$tag$reason".
> @@ -44,3 +47,18 @@ void fastboot_okay(const char *reason, char *response)
>  {
>         fastboot_response("OKAY", response, "%s", reason);
>  }
> +
> +void timed_send_info(ulong *start, const char *msg)

This should be called fastboot_send_info()... it is in the global namespace!

> +{
> +#ifdef CONFIG_UDP_FUNCTION_FASTBOOT
> +       /* Initialize timer */
> +       if (*start == 0)

You should probably be a little more defensive and check for NULL
before dereferencing.

> +               *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_send_info(msg);

This should call fastboot_(udp_)send_info()

> +       }
> +#endif
> +}
> diff --git a/drivers/fastboot/fb_mmc.c b/drivers/fastboot/fb_mmc.c
> index 02864aa..304bda1 100644
> --- a/drivers/fastboot/fb_mmc.c
> +++ b/drivers/fastboot/fb_mmc.c
> @@ -29,6 +29,9 @@
>  #define CONFIG_FASTBOOT_MBR_NAME "mbr"
>  #endif
>
> +#define FASTBOOT_MAX_BLK_WRITE 16384
> +static ulong timer;

This timer seems like it should be a static variable inside of
fastboot_send_info() (the function currently called timed_send_info).
Then you don't have to pass it as a parameter and fb_mmc.c doesn't
need to know what fb_common is doing with the info update.

> +
>  #define BOOT_PARTITION_NAME "boot"
>
>  struct fb_mmc_sparse {
> @@ -57,13 +60,38 @@ static int part_get_info_by_name_or_alias(struct blk_desc *dev_desc,
>         return ret;
>  }
>
> +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) {
> +                       timed_send_info(&timer, "writing");
> +                       blks_written = blk_dwrite(block_dev, blk, cur_blkcnt,
> +                                                 buffer + (i * block_dev->blksz));
> +               } else {
> +                       timed_send_info(&timer, "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 blk_dwrite(dev_desc, blk, blkcnt, buffer);
> +       return fb_mmc_blk_write(dev_desc, blk, blkcnt, buffer);
>  }
>
>  static lbaint_t fb_mmc_sparse_reserve(struct sparse_storage *info,
> @@ -91,7 +119,7 @@ static void write_raw_image(struct blk_desc *dev_desc, disk_partition_t *info,
>
>         puts("Flashing Raw Image\n");
>
> -       blks = blk_dwrite(dev_desc, info->start, blkcnt, buffer);
> +       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);
> @@ -399,7 +427,7 @@ void fb_mmc_erase(const char *cmd, char *response)
>         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);
> +       blks = fb_mmc_blk_write(dev_desc, blks_start, blks_size, NULL);
>         if (blks != blks_size) {
>                 pr_err("failed erasing from device %d", dev_desc->devnum);
>                 fastboot_fail("failed erasing from device", response);
> diff --git a/include/fastboot.h b/include/fastboot.h
> index 2140c94..6f69423 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -23,4 +23,17 @@ void fastboot_response(const char *tag, char *response,
>  void fastboot_fail(const char *reason, char *response);
>  void fastboot_okay(const char *reason, char *response);
>
> +/**
> + * Send an INFO packet during long commands based on timer. If
> + * CONFIG_UDP_FUNCTION_FASTBOOT is defined, an INFO packet is sent
> + * if the time is 30 seconds after start. Else, noop.
> + *
> + * TODO: Handle the situation where both UDP and USB fastboot are
> + *       enabled.
> + *
> + * @param start:  Time since last INFO packet was sent.
> + * @param msg:    String describing the reason for waiting
> + */
> +void timed_send_info(ulong *start, const char *msg);
> +
>  #endif /* _FASTBOOT_H_ */
> diff --git a/include/net.h b/include/net.h
> index 3469811..890ae27 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -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 */
> @@ -549,6 +549,10 @@ extern char *net_dns_resolve;              /* The host to resolve  */
>  extern char *net_dns_env_var;          /* the env var to put the ip into */
>  #endif
>
> +#if defined(CONFIG_UDP_FUNCTION_FASTBOOT)

Probably not necessary to guard - the linker would complain if it's not there.

> +int do_fastboot_udp(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);

This would be better as a static function in cmd/fastboot.c

> +#endif
> +
>  #if defined(CONFIG_CMD_PING)
>  extern struct in_addr net_ping_ip;     /* the ip address to ping */
>  #endif
> diff --git a/include/net/fastboot.h b/include/net/fastboot.h
> new file mode 100644
> index 0000000..c0dd033
> --- /dev/null
> +++ b/include/net/fastboot.h
> @@ -0,0 +1,27 @@
> +/* 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);

Since this is in the global namespace, it should probably be
qualified... fastboot_udp_start_server()

> +/**
> + * Send an INFO packet during long commands
> + *
> + * @param msg: String describing the reason for waiting
> + */
> +void fastboot_send_info(const char *msg);

Same here... fastboot_udp_send_info()

> +
> +/**********************************************************************/
> +
> +#endif /* __NET_FASTBOOT_H__ */
> diff --git a/net/Makefile b/net/Makefile
> index ce6e5ad..3489ce5 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -25,6 +25,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
> index 0000000..32cb581
> --- /dev/null
> +++ b/net/fastboot.c
> @@ -0,0 +1,542 @@
> +// SPDX-License-Identifier: BSD-2-Clause
> +/*
> + * Copyright (C) 2016 The Android Open Source Project
> + */
> +
> +#include <common.h>
> +#include <fastboot.h>
> +#include <fb_mmc.h>
> +#include <net.h>
> +#include <net/fastboot.h>
> +#include <part.h>
> +#include <stdlib.h>
> +#include <version.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 FASTBOOT_HEADER_SIZE sizeof(struct fastboot_header)

This define doesn't seem any better than just using the sizeof() directly.

> +#define DATA_SIZE (PACKET_SIZE - FASTBOOT_HEADER_SIZE)
> +#define FASTBOOT_VERSION "0.4"
> +
> +/* Sequence number sent for every packet */
> +static unsigned short fb_sequence_number = 1;
> +static const unsigned short fb_packet_size = PACKET_SIZE;
> +static const unsigned short fb_udp_version = 1;
> +
> +/* Keep track of last packet for resubmission */
> +static uchar last_packet[PACKET_SIZE];
> +static unsigned int last_packet_len;
> +
> +/* Parsed from first fastboot command packet */
> +static char *cmd_string;
> +static char *cmd_parameter;
> +
> +/* Fastboot download parameters */
> +static unsigned int bytes_received;
> +static unsigned int bytes_expected;

These two are only ever used in fb_download(). They should be static
variables in that function.

> +static unsigned int image_size;
> +
> +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 fb_getvar(char *);
> +static void fb_download(char *, unsigned int, char *);
> +static void fb_flash(char *);
> +static void fb_erase(char *);
> +static void fb_continue(char *);
> +static void fb_reboot(char *);
> +static void boot_downloaded_image(void);
> +static void cleanup_command_data(void);
> +static void write_fb_response(const char *, const char *, char *);
> +
> +void fastboot_send_info(const char *msg)
> +{
> +       uchar *packet;
> +       uchar *packet_base;
> +       int len = 0;
> +       char response[FASTBOOT_RESPONSE_LEN] = {0};
> +
> +       struct fastboot_header fb_response_header = {
> +               .id = FASTBOOT_FASTBOOT,
> +               .flags = 0,
> +               .seq = htons(fb_sequence_number)
> +       };
> +       ++fb_sequence_number;
> +       packet = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
> +       packet_base = packet;
> +
> +       /* Write headers */
> +       memcpy(packet, &fb_response_header, sizeof(fb_response_header));
> +       packet += sizeof(fb_response_header);
> +       /* Write response */
> +       write_fb_response("INFO", msg, response);
> +       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);
> +}
> +
> +/**
> + * Constructs and sends a packet in response to received fastboot packet
> + *
> + * @param fb_header            Header for response packet
> + * @param fastboot_data        Pointer to received fastboot data
> + * @param fastboot_data_len    Length of received fastboot data
> + * @param retransmit           Nonzero if sending last sent packet
> + */
> +static void fastboot_send(struct fastboot_header fb_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 fb_response_header = fb_header;
> +       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;
> +       }
> +
> +       fb_response_header.seq = htons(fb_response_header.seq);
> +       memcpy(packet, &fb_response_header, sizeof(fb_response_header));
> +       packet += sizeof(fb_response_header);
> +
> +       switch (fb_header.id) {
> +       case FASTBOOT_QUERY:
> +               tmp = htons(fb_sequence_number);
> +               memcpy(packet, &tmp, sizeof(tmp));
> +               packet += sizeof(tmp);
> +               break;
> +       case FASTBOOT_INIT:
> +               tmp = htons(fb_udp_version);
> +               memcpy(packet, &tmp, sizeof(tmp));
> +               packet += sizeof(tmp);
> +               tmp = htons(fb_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_string) {
> +                       /* Parse command and send ack */
> +                       cmd_parameter = fastboot_data;

This seems unnecessary. There are only 4 cases handled, and of them
only download seems to be a command that happens more than once. And
in download, the first past through this parameter is saved internally
as bytes_expected.

> +                       cmd_string = strsep(&cmd_parameter, ":");
> +                       cmd_string = strdup(cmd_string);
> +                       if (cmd_parameter)
> +                               cmd_parameter = strdup(cmd_parameter);
> +               } else if (!strcmp("getvar", cmd_string)) {
> +                       fb_getvar(response);

Seems like you should simply pass the "fastboot_data" as a parameter
here rather than using a global.

> +               } else if (!strcmp("download", cmd_string)) {
> +                       fb_download(fastboot_data, fastboot_data_len, response);
> +               } else if (!strcmp("flash", cmd_string)) {
> +                       fb_flash(response);
> +               } else if (!strcmp("erase", cmd_string)) {
> +                       fb_erase(response);
> +               } else if (!strcmp("boot", cmd_string)) {
> +                       write_fb_response("OKAY", "", response);
> +               } else if (!strcmp("continue", cmd_string)) {
> +                       fb_continue(response);
> +               } else if (!strncmp("reboot", cmd_string, 6)) {
> +                       fb_reboot(response);
> +               } else if (!strcmp("set_active", cmd_string)) {
> +                       /* A/B not implemented, for now do nothing */
> +                       write_fb_response("OKAY", "", response);
> +               } else {
> +                       pr_err("command %s not implemented.\n", cmd_string);
> +                       write_fb_response("FAIL", "unrecognized command",
> +                                         response);
> +               }
> +               /* Sent some INFO packets, need to update sequence number in
> +                * header
> +                */
> +               if (fb_header.seq != fb_sequence_number) {
> +                       fb_response_header.seq = htons(fb_sequence_number);
> +                       memcpy(packet_base, &fb_response_header,
> +                              sizeof(fb_response_header));
> +               }
> +               /* Write response to packet */
> +               memcpy(packet, response, strlen(response));
> +               packet += strlen(response);
> +               break;
> +       default:
> +               pr_err("ID %d not implemented.\n", fb_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)) {
> +               if (!strcmp("boot", cmd_string)) {
> +                       boot_downloaded_image();
> +               } else if (!strcmp("continue", cmd_string)) {
> +                       run_command(env_get("bootcmd"), CMD_FLAG_ENV);
> +               } else if (!strncmp("reboot", cmd_string, 6)) {
> +                       /* Matches reboot or reboot-bootloader */
> +                       do_reset(NULL, 0, 0, NULL);
> +               }
> +       }
> +
> +       /* OKAY and FAIL indicate command is complete */
> +       if (!strncmp("OKAY", response, 4) || !strncmp("FAIL", response, 4))
> +               cleanup_command_data();
> +}
> +
> +/**
> + * Writes ascii string specified by cmd_parameter to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_getvar(char *response)
> +{
> +       if (!cmd_parameter) {
> +               write_fb_response("FAIL", "missing var", response);
> +       } else if (!strcmp("version", cmd_parameter)) {
> +               write_fb_response("OKAY", FASTBOOT_VERSION, response);
> +       } else if (!strcmp("bootloader-version", cmd_parameter) ||
> +                  !strcmp("version-bootloader", cmd_parameter)) {
> +               write_fb_response("OKAY", U_BOOT_VERSION, response);
> +       } else if (!strcmp("downloadsize", cmd_parameter) ||
> +                  !strcmp("max-download-size", cmd_parameter)) {
> +               char buf_size_str[12];
> +
> +               sprintf(buf_size_str, "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
> +               write_fb_response("OKAY", buf_size_str, response);
> +       } else if (!strcmp("serialno", cmd_parameter)) {
> +               const char *tmp = env_get("serial#");
> +
> +               if (tmp)
> +                       write_fb_response("OKAY", tmp, response);
> +               else
> +                       write_fb_response("FAIL", "Value not set", response);
> +       } else if (!strcmp("version-baseband", cmd_parameter)) {
> +               write_fb_response("OKAY", "N/A", response);
> +       } else if (!strcmp("product", cmd_parameter)) {
> +               const char *board = env_get("board");
> +
> +               if (board)
> +                       write_fb_response("OKAY", board, response);
> +               else
> +                       write_fb_response("FAIL", "Board not set", response);
> +       } else if (!strcmp("current-slot", cmd_parameter)) {
> +               /* A/B not implemented, for now always return _a */
> +               write_fb_response("OKAY", "_a", response);
> +       } else if (!strcmp("slot-suffixes", cmd_parameter)) {
> +               write_fb_response("OKAY", "_a,_b", response);
> +       } else if (!strncmp("has-slot", cmd_parameter, 8)) {
> +               char *part_name = cmd_parameter;
> +
> +               cmd_parameter = strsep(&part_name, ":");
> +               if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
> +                       write_fb_response("OKAY", "yes", response);
> +               else
> +                       write_fb_response("OKAY", "no", response);
> +       } else if (!strncmp("partition-type", cmd_parameter, 14) ||
> +                  !strncmp("partition-size", cmd_parameter, 14)) {
> +               disk_partition_t part_info;
> +               struct blk_desc *dev_desc;
> +               char *part_name = cmd_parameter;
> +               char part_size_str[20];
> +
> +               cmd_parameter = strsep(&part_name, ":");
> +               dev_desc = blk_get_dev("mmc", 0);
> +               if (!dev_desc) {
> +                       write_fb_response("FAIL", "block device not found",
> +                                         response);
> +               } else if (part_get_info_by_name(dev_desc, part_name,
> +                                                &part_info) < 0) {
> +                       write_fb_response("FAIL", "partition not found",
> +                                         response);
> +               } else if (!strncmp("partition-type", cmd_parameter, 14)) {
> +                       write_fb_response("OKAY", (char *)part_info.type,
> +                                         response);
> +               } else if (!strncmp("partition-size", cmd_parameter, 14)) {
> +                       sprintf(part_size_str, "0x%016x", (int)part_info.size);
> +                       write_fb_response("OKAY", part_size_str, response);
> +               }
> +       } else {
> +               printf("WARNING: unknown variable: %s\n", cmd_parameter);
> +               write_fb_response("FAIL", "Variable not implemented",
> +                                 response);
> +       }
> +}
> +
> +/**
> + * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
> + * Writes to response.
> + *
> + * @param fastboot_data        Pointer to received fastboot data
> + * @param fastboot_data_len    Length of received fastboot data
> + * @param repsonse             Pointer to fastboot response buffer
> + */
> +static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
> +                       char *response)
> +{
> +       char *tmp;
> +
> +       if (bytes_expected == 0) {
> +               if (!cmd_parameter) {
> +                       write_fb_response("FAIL", "Expected command parameter",
> +                                         response);
> +                       return;
> +               }
> +               bytes_expected = simple_strtoul(cmd_parameter, &tmp, 16);
> +               if (bytes_expected == 0) {
> +                       write_fb_response("FAIL", "Expected nonzero image size",
> +                                         response);
> +                       return;
> +               }
> +       }
> +       if (fastboot_data_len == 0 && bytes_received == 0) {
> +               /* Nothing to download yet. Response is of the form:
> +                * [DATA|FAIL]$cmd_parameter
> +                *
> +                * where cmd_parameter is an 8 digit hexadecimal number
> +                */
> +               if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
> +                       write_fb_response("FAIL", cmd_parameter, response);
> +               else
> +                       write_fb_response("DATA", cmd_parameter, response);
> +       } else if (fastboot_data_len == 0 &&
> +                  (bytes_received >= bytes_expected)) {
> +               /* Download complete. Respond with "OKAY" */
> +               write_fb_response("OKAY", "", response);
> +               image_size = bytes_received;
> +               bytes_expected = 0;
> +               bytes_received = 0;
> +       } else {
> +               if (fastboot_data_len == 0 ||
> +                   (bytes_received + fastboot_data_len) > bytes_expected) {
> +                       write_fb_response("FAIL",
> +                                         "Received invalid data length",
> +                                         response);
> +                       return;
> +               }
> +               /* Download data to CONFIG_FASTBOOT_BUF_ADDR */
> +               memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR + bytes_received,
> +                      fastboot_data, fastboot_data_len);

This is different than all the other approaches, which take the load
address as a command parameter. Is there a good reason to have it
baked in like this?

> +               bytes_received += fastboot_data_len;
> +       }
> +}
> +
> +/**
> + * Writes the previously downloaded image to the partition indicated by
> + * cmd_parameter. Writes to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_flash(char *response)
> +{
> +       fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
> +                          image_size, response);

It's peculiar that this hard-codes mmc.

> +}
> +
> +/**
> + * Erases the partition indicated by cmd_parameter (clear to 0x00s). Writes
> + * to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_erase(char *response)
> +{
> +       fb_mmc_erase(cmd_parameter, response);
> +}
> +
> +/**
> + * Continues normal boot process by running "bootcmd". Writes
> + * to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_continue(char *response)
> +{
> +       char *bootcmd;
> +
> +       bootcmd = env_get("bootcmd");
> +       if (bootcmd)
> +               write_fb_response("OKAY", "", response);
> +       else
> +               write_fb_response("FAIL", "bootcmd not set", response);
> +}
> +
> +/**
> + * Sets reboot bootloader flag if requested. Writes to response.
> + *
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void fb_reboot(char *response)
> +{
> +       write_fb_response("OKAY", "", response);
> +       if (!strcmp("reboot-bootloader", cmd_string))
> +               strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR, "reboot-bootloader");
> +}
> +
> +/**
> + * Boots into downloaded image.
> + */
> +static void boot_downloaded_image(void)
> +{
> +       char kernel_addr[12];
> +       char *fdt_addr = env_get("fdt_addr_r");
> +       char *const bootm_args[] = {
> +               "bootm", kernel_addr, "-", fdt_addr, NULL
> +       };

It seems like this should be able to affected from the host side...
for instance choosing a config in an ITB.

How is the fdt supposed to be populated in the scenario at all?

> +
> +       sprintf(kernel_addr, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
> +
> +       printf("\nBooting kernel at %s with fdt at %s...\n\n\n",
> +              kernel_addr, fdt_addr);
> +       do_bootm(NULL, 0, 4, bootm_args);
> +
> +       /* This only happens if image is faulty so we start over. */
> +       do_reset(NULL, 0, 0, NULL);
> +}
> +
> +/**
> + * Writes a response to response buffer of the form "$tag$reason".
> + *
> + * @param tag         The first part of the response
> + * @param reason      The second part of the response
> + * @param repsonse    Pointer to fastboot response buffer
> + */
> +static void write_fb_response(const char *tag, const char *reason,
> +                             char *response)
> +{
> +       strncpy(response, tag, strlen(tag));
> +       strncat(response, reason, FASTBOOT_RESPONSE_LEN - strlen(tag) - 1);
> +}
> +
> +/**
> + * Frees any resources allocated during current fastboot command.
> + */
> +static void cleanup_command_data(void)
> +{
> +       /* cmd_parameter and cmd_string potentially point to memory allocated by

Use correct multi-line comment format. "/*" on its own line.

> +        * strdup
> +        */
> +       if (cmd_parameter)
> +               free(cmd_parameter);
> +       if (cmd_string)
> +               free(cmd_string);
> +       cmd_parameter = NULL;
> +       cmd_string = NULL;
> +}
> +
> +/**
> + * Incoming UDP packet handler.
> + *
> + * @param packet  Pointer to incoming UDP packet
> + * @param dport   Destination UDP port
> + * @param sip     Source IP address
> + * @param sport   Source UDP port
> + * @param 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 fb_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 < FASTBOOT_HEADER_SIZE || len > PACKET_SIZE)
> +               return;
> +       memcpy(&fb_header, packet, sizeof(fb_header));
> +       fb_header.flags = 0;
> +       fb_header.seq = ntohs(fb_header.seq);
> +       packet += sizeof(fb_header);
> +       len -= sizeof(fb_header);
> +
> +       switch (fb_header.id) {
> +       case FASTBOOT_QUERY:
> +               fastboot_send(fb_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 (fb_header.seq == fb_sequence_number) {
> +                       fastboot_send(fb_header, fastboot_data,
> +                                     fastboot_data_len, 0);
> +                       fb_sequence_number++;
> +               } else if (fb_header.seq == fb_sequence_number - 1) {
> +                       /* Retransmit last sent packet */
> +                       fastboot_send(fb_header, fastboot_data,
> +                                     fastboot_data_len, 1);
> +               }
> +               break;
> +       default:
> +               pr_err("ID %d not implemented.\n", fb_header.id);
> +               fb_header.id = FASTBOOT_ERROR;
> +               fastboot_send(fb_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;
> +
> +       net_set_udp_handler(fastboot_handler);
> +
> +       /* zero out server ether in case the server ip has changed */
> +       memset(net_server_ethaddr, 0, 6);
> +}
> diff --git a/net/net.c b/net/net.c
> index d222c1f..554df7a 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -87,6 +87,9 @@
>  #include <environment.h>
>  #include <errno.h>
>  #include <net.h>
> +#if defined(CONFIG_UDP_FUNCTION_FASTBOOT)

I'd prefer we not proliferate the guards around includes.

> +#include <net/fastboot.h>
> +#endif
>  #include <net/tftp.h>
>  #if defined(CONFIG_LED_STATUS)
>  #include <miiphy.h>
> @@ -451,6 +454,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 +1330,7 @@ common:
>                 /* Fall through */
>
>         case NETCONS:
> +       case FASTBOOT:
>         case TFTPSRV:
>                 if (net_ip.s_addr == 0) {
>                         puts("*** ERROR: `ipaddr' not set\n");
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 08/20] net: fastboot: Support building without MMC
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 08/20] net: fastboot: Support building without MMC Alex Kiernan
@ 2018-05-03 20:39   ` Joe Hershberger
  2018-05-04  6:06     ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 20:39 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> If the fastboot flash/erase commands are disabled, remove that support
> so we still build correctly.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 09/20] fastboot: Refactor write_fb_response into fastboot_okay/fail/response
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 09/20] fastboot: Refactor write_fb_response into fastboot_okay/fail/response Alex Kiernan
@ 2018-05-03 20:48   ` Joe Hershberger
  2018-05-04  6:00     ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 20:48 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Replace write_fb_response with fastboot_okay/fail/response. Also allow
> fastboot_okay to take NULL when we have no message to send.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 10/20] fastboot: Merge USB and UDP getvar implementation
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 10/20] fastboot: Merge USB and UDP getvar implementation Alex Kiernan
@ 2018-05-03 20:56   ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 20:56 UTC (permalink / raw)
  To: u-boot

 On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Merge the USB and UDP getvar implementations into one. The USB side
> gains new variables previously defined in the network side and the
> network side now supports fetching of arbitrary variables prefixed with
> 'fastboot.'
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
>
> Changes in v2: None
>
>  drivers/fastboot/Makefile       |  1 +
>  drivers/fastboot/fb_common.c    |  7 ++++
>  drivers/fastboot/fb_getvar.c    | 93 +++++++++++++++++++++++++++++++++++++++++
>  drivers/usb/gadget/f_fastboot.c | 56 +------------------------
>  include/fastboot.h              | 18 ++++++++
>  net/fastboot.c                  | 75 +--------------------------------
>  6 files changed, 121 insertions(+), 129 deletions(-)
>  create mode 100644 drivers/fastboot/fb_getvar.c
>
> diff --git a/drivers/fastboot/Makefile b/drivers/fastboot/Makefile
> index c12dfa8..9af4073 100644
> --- a/drivers/fastboot/Makefile
> +++ b/drivers/fastboot/Makefile
> @@ -1,6 +1,7 @@
>  # SPDX-License-Identifier:      GPL-2.0+
>
>  obj-y += fb_common.o
> +obj-y += fb_getvar.o
>  obj-$(CONFIG_FASTBOOT_FLASH) += image-sparse.o
>
>  obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fb_mmc.o
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> index f0bf53d..3b68f25 100644
> --- a/drivers/fastboot/fb_common.c
> +++ b/drivers/fastboot/fb_common.c
> @@ -65,3 +65,10 @@ void timed_send_info(ulong *start, const char *msg)
>         }
>  #endif
>  }
> +
> +int strcmp_l1(const char *s1, const char *s2)
> +{
> +       if (!s1 || !s2)
> +               return -1;
> +       return strncmp(s1, s2, strlen(s1));
> +}
> diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
> new file mode 100644
> index 0000000..aa68371
> --- /dev/null
> +++ b/drivers/fastboot/fb_getvar.c
> @@ -0,0 +1,93 @@
> +// SPDX-License-Identifier: BSD-2-Clause
> +/*
> + * Copyright (C) 2016 The Android Open Source Project
> + */
> +
> +#include <common.h>
> +#include <fastboot.h>
> +#include <version.h>
> +
> +/**
> + * Writes ascii string specified by cmd_parameter to response.
> + *
> + * @param cmd_parameter        Point to command parameter
> + * @param response     Pointer to fastboot response buffer
> + */
> +void fb_getvar(char *cmd_parameter, char *response)
> +{
> +       if (!cmd_parameter) {
> +               fastboot_fail("missing var", response);
> +       } else if (!strcmp("version", cmd_parameter)) {
> +               fastboot_okay(FASTBOOT_VERSION, response);
> +       } else if (!strcmp("bootloader-version", cmd_parameter) ||
> +                  !strcmp("version-bootloader", cmd_parameter)) {
> +               fastboot_okay(U_BOOT_VERSION, response);
> +       } else if (!strcmp("downloadsize", cmd_parameter) ||
> +                  !strcmp("max-download-size", cmd_parameter)) {
> +               fastboot_response("OKAY", response,
> +                                 "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
> +       } else if (!strcmp("serialno", cmd_parameter)) {
> +               const char *tmp = env_get("serial#");
> +
> +               if (tmp)
> +                       fastboot_okay(tmp, response);
> +               else
> +                       fastboot_fail("Value not set", response);
> +       } else if (!strcmp("version-baseband", cmd_parameter)) {
> +               fastboot_okay("N/A", response);
> +       } else if (!strcmp("product", cmd_parameter)) {
> +               const char *board = env_get("board");
> +
> +               if (board)
> +                       fastboot_okay(board, response);
> +               else
> +                       fastboot_fail("Board not set", response);
> +       } else if (!strcmp("current-slot", cmd_parameter)) {
> +               /* A/B not implemented, for now always return _a */
> +               fastboot_okay("_a", response);
> +       } else if (!strcmp("slot-suffixes", cmd_parameter)) {
> +               fastboot_okay("_a,_b", response);
> +       } else if (!strcmp_l1("has-slot", cmd_parameter)) {
> +               char *part_name = cmd_parameter;
> +
> +               cmd_parameter = strsep(&part_name, ":");
> +               if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
> +                       fastboot_okay("yes", response);
> +               else
> +                       fastboot_okay("no", response);
> +       } else if (!strcmp_l1("partition-type", cmd_parameter) ||
> +                  !strcmp_l1("partition-size", cmd_parameter)) {
> +               disk_partition_t part_info;
> +               struct blk_desc *dev_desc;
> +               char *part_name = cmd_parameter;
> +
> +               cmd_parameter = strsep(&part_name, ":");
> +               dev_desc = blk_get_dev("mmc", 0);
> +               if (!dev_desc) {
> +                       fastboot_fail("block device not found", response);
> +               } else if (part_get_info_by_name(dev_desc, part_name,
> +                                                &part_info) < 0) {
> +                       fastboot_fail("partition not found", response);
> +               } else if (!strcmp_l1("partition-type", cmd_parameter)) {
> +                       fastboot_okay((char *)part_info.type, response);
> +               } else if (!strcmp_l1("partition-size", cmd_parameter)) {
> +                       fastboot_response("OKAY", response,
> +                                         "0x%016x", (int)part_info.size);
> +               }
> +       } else {
> +#define FASTBOOT_ENV_PREFIX    "fastboot."
> +               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);
> +               } else {
> +                       pr_warn("WARNING: unknown variable: %s\n",
> +                               cmd_parameter);
> +                       fastboot_fail("Variable not implemented", response);
> +               }
> +       }
> +}
> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> index e757c3e..a493c75 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -148,7 +148,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 void fastboot_complete(struct usb_ep *ep, struct usb_request *req)
>  {
> @@ -376,66 +375,13 @@ static void cb_reboot(struct usb_ep *ep, struct usb_request *req)
>         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);
> -       }
> +       fb_getvar(cmd, response);
>         fastboot_tx_write_str(response);
>  }
>
> diff --git a/include/fastboot.h b/include/fastboot.h
> index 6f69423..fb58358 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -13,6 +13,8 @@
>  #ifndef _FASTBOOT_H_
>  #define _FASTBOOT_H_
>
> +#define FASTBOOT_VERSION       "0.4"

This should be pulled out of net/fastboot.c.  Probably just put it in
include/fastboot.h to begin with.

> +
>  /* The 64 defined bytes plus \0 */
>  #define FASTBOOT_RESPONSE_LEN  (64 + 1)
>
> @@ -24,6 +26,14 @@ void fastboot_fail(const char *reason, char *response);
>  void fastboot_okay(const char *reason, char *response);
>
>  /**
> + * Writes ascii string specified by cmd_parameter to response.
> + *
> + * @param cmd_parameter        Pointer to variable name
> + * @param response     Pointer to fastboot response buffer
> + */
> +void fb_getvar(char *cmd_parameter, char *response);
> +
> +/**
>   * Send an INFO packet during long commands based on timer. If
>   * CONFIG_UDP_FUNCTION_FASTBOOT is defined, an INFO packet is sent
>   * if the time is 30 seconds after start. Else, noop.
> @@ -36,4 +46,12 @@ void fastboot_okay(const char *reason, char *response);
>   */
>  void timed_send_info(ulong *start, const char *msg);
>
> +/**
> + * Compare strings over the length of s1
> + *
> + * @param s1           Pointer to string which limits the comparisson

comparisson -> comparison

> + * @param s2           Second string
> + */
> +int strcmp_l1(const char *s1, const char *s2);

This doesn't seem like the right place for this. Probably just make it
a static inline in include/common.h

> +
>  #endif /* _FASTBOOT_H_ */
> diff --git a/net/fastboot.c b/net/fastboot.c
> index 960e7f1..cd09ada 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -57,7 +57,6 @@ static int fastboot_remote_port;
>  /* The UDP port at our end */
>  static int fastboot_our_port;
>
> -static void fb_getvar(char *);
>  static void fb_download(char *, unsigned int, char *);
>  #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
>  static void fb_flash(char *);
> @@ -167,7 +166,7 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
>                         if (cmd_parameter)
>                                 cmd_parameter = strdup(cmd_parameter);
>                 } else if (!strcmp("getvar", cmd_string)) {
> -                       fb_getvar(response);
> +                       fb_getvar(cmd_parameter, response);
>                 } else if (!strcmp("download", cmd_string)) {
>                         fb_download(fastboot_data, fastboot_data_len, response);
>  #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> @@ -233,78 +232,6 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
>  }
>
>  /**
> - * Writes ascii string specified by cmd_parameter to response.
> - *
> - * @param repsonse    Pointer to fastboot response buffer
> - */
> -static void fb_getvar(char *response)
> -{
> -       if (!cmd_parameter) {
> -               fastboot_fail("missing var", response);
> -       } else if (!strcmp("version", cmd_parameter)) {
> -               fastboot_okay(FASTBOOT_VERSION, response);
> -       } else if (!strcmp("bootloader-version", cmd_parameter) ||
> -                  !strcmp("version-bootloader", cmd_parameter)) {
> -               fastboot_okay(U_BOOT_VERSION, response);
> -       } else if (!strcmp("downloadsize", cmd_parameter) ||
> -                  !strcmp("max-download-size", cmd_parameter)) {
> -               fastboot_response("OKAY", response,
> -                                 "0x%08x", CONFIG_FASTBOOT_BUF_SIZE);
> -       } else if (!strcmp("serialno", cmd_parameter)) {
> -               const char *tmp = env_get("serial#");
> -
> -               if (tmp)
> -                       fastboot_okay(tmp, response);
> -               else
> -                       fastboot_fail("Value not set", response);
> -       } else if (!strcmp("version-baseband", cmd_parameter)) {
> -               fastboot_okay("N/A", response);
> -       } else if (!strcmp("product", cmd_parameter)) {
> -               const char *board = env_get("board");
> -
> -               if (board)
> -                       fastboot_okay(board, response);
> -               else
> -                       fastboot_fail("Board not set", response);
> -       } else if (!strcmp("current-slot", cmd_parameter)) {
> -               /* A/B not implemented, for now always return _a */
> -               fastboot_okay("_a", response);
> -       } else if (!strcmp("slot-suffixes", cmd_parameter)) {
> -               fastboot_okay("_a,_b", response);
> -       } else if (!strncmp("has-slot", cmd_parameter, 8)) {
> -               char *part_name = cmd_parameter;
> -
> -               cmd_parameter = strsep(&part_name, ":");
> -               if (!strcmp(part_name, "boot") || !strcmp(part_name, "system"))
> -                       fastboot_okay("yes", response);
> -               else
> -                       fastboot_okay("no", response);
> -       } else if (!strncmp("partition-type", cmd_parameter, 14) ||
> -                  !strncmp("partition-size", cmd_parameter, 14)) {
> -               disk_partition_t part_info;
> -               struct blk_desc *dev_desc;
> -               char *part_name = cmd_parameter;
> -
> -               cmd_parameter = strsep(&part_name, ":");
> -               dev_desc = blk_get_dev("mmc", 0);
> -               if (!dev_desc) {
> -                       fastboot_fail("block device not found", response);
> -               } else if (part_get_info_by_name(dev_desc, part_name,
> -                                                &part_info) < 0) {
> -                       fastboot_fail("partition not found", response);
> -               } else if (!strncmp("partition-type", cmd_parameter, 14)) {
> -                       fastboot_okay((char *)part_info.type, response);
> -               } else if (!strncmp("partition-size", cmd_parameter, 14)) {
> -                       fastboot_response("OKAY", response,
> -                                         "0x%016x", (int)part_info.size);
> -               }
> -       } else {
> -               printf("WARNING: unknown variable: %s\n", cmd_parameter);
> -               fastboot_fail("Variable not implemented", response);
> -       }
> -}
> -
> -/**
>   * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
>   * Writes to response.
>   *
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot Alex Kiernan
@ 2018-05-03 20:58   ` Joe Hershberger
  2018-05-04  6:18     ` Jocelyn Bohr
  2018-05-08  9:20     ` Alex Kiernan
  0 siblings, 2 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 20:58 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Change the behaviour of 'continue' so that we simply exit the fastboot
> server and leave the caller to decide what to do next. This matches
> the USB fastboot behaviour.

Good, I was considering recommending this approach.

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
>
> Changes in v2: None
>
>  net/fastboot.c | 13 +++----------
>  1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/net/fastboot.c b/net/fastboot.c
> index cd09ada..ed13890 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -218,8 +218,6 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
>         if (!strncmp("OKAY", response, 4)) {
>                 if (!strcmp("boot", cmd_string)) {
>                         boot_downloaded_image();
> -               } else if (!strcmp("continue", cmd_string)) {
> -                       run_command(env_get("bootcmd"), CMD_FLAG_ENV);
>                 } else if (!strncmp("reboot", cmd_string, 6)) {
>                         /* Matches reboot or reboot-bootloader */
>                         do_reset(NULL, 0, 0, NULL);
> @@ -313,20 +311,15 @@ static void fb_erase(char *response)
>  #endif
>
>  /**
> - * Continues normal boot process by running "bootcmd". Writes
> + * Continues normal boot process by exiting fastboot server. Writes
>   * to response.
>   *
>   * @param repsonse    Pointer to fastboot response buffer
>   */
>  static void fb_continue(char *response)
>  {
> -       char *bootcmd;
> -
> -       bootcmd = env_get("bootcmd");
> -       if (bootcmd)
> -               fastboot_okay(NULL, response);
> -       else
> -               fastboot_fail("bootcmd not set", response);
> +       net_set_state(NETLOOP_SUCCESS);
> +       fastboot_okay(NULL, response);
>  }
>
>  /**
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 12/20] fastboot: net: Convert command lookup to a table
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 12/20] fastboot: net: Convert command lookup to a table Alex Kiernan
@ 2018-05-03 21:08   ` Joe Hershberger
  2018-05-04  9:14     ` Alex Kiernan
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:08 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Change command lookup to use a lookup table so it matches the existing
> USB fastboot code.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
>
> Changes in v2: None
>
>  drivers/fastboot/fb_common.c |  30 ++++++++++++
>  include/fastboot.h           |  21 +++++++++
>  net/fastboot.c               | 108 ++++++++++++++++++++++++++++++-------------
>  3 files changed, 127 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> index 3b68f25..8b3627b 100644
> --- a/drivers/fastboot/fb_common.c
> +++ b/drivers/fastboot/fb_common.c
> @@ -72,3 +72,33 @@ int strcmp_l1(const char *s1, const char *s2)
>                 return -1;
>         return strncmp(s1, s2, strlen(s1));
>  }
> +
> +static const char *const fb_commands[] = {
> +       [FB_CMD_GETVAR] = "getvar",
> +       [FB_CMD_DOWNLOAD] = "download",
> +       [FB_CMD_VERIFY] = "verify",
> +       [FB_CMD_FLASH] = "flash",
> +       [FB_CMD_ERASE] = "erase",
> +       [FB_CMD_BOOT] = "boot",
> +       [FB_CMD_CONTINUE] = "continue",
> +       [FB_CMD_REBOOT] = "reboot",
> +       [FB_CMD_REBOOT_BOOTLOADER] = "reboot-bootloader",
> +       [FB_CMD_POWERDOWN] = "powerdown",
> +       [FB_CMD_SET_ACTIVE] = "set_active",
> +       [FB_CMD_UPLOAD] = "upload",
> +};
> +
> +int fastboot_lookup_command(const char *cmd_string)
> +{
> +       int i;
> +
> +       for (i = 0; i < FB_CMD_COUNT; i++) {
> +               int len = strlen(fb_commands[i]);
> +
> +               if (!strncmp(fb_commands[i], cmd_string, len) &&

Why not use your new strcmp_l1()?

> +                   (cmd_string[len] == '\0' || cmd_string[len] == ':'))

At this point the ':' is already deleted.

> +                       return i;
> +       }
> +
> +       return -1;
> +}
> diff --git a/include/fastboot.h b/include/fastboot.h
> index fb58358..de07220 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -18,6 +18,26 @@
>  /* The 64 defined bytes plus \0 */
>  #define FASTBOOT_RESPONSE_LEN  (64 + 1)
>
> +/**
> + * All known commands to fastboot
> + */
> +enum {
> +       FB_CMD_GETVAR = 0,
> +       FB_CMD_DOWNLOAD,
> +       FB_CMD_VERIFY,
> +       FB_CMD_FLASH,
> +       FB_CMD_ERASE,
> +       FB_CMD_BOOT,
> +       FB_CMD_CONTINUE,
> +       FB_CMD_REBOOT,
> +       FB_CMD_REBOOT_BOOTLOADER,
> +       FB_CMD_POWERDOWN,
> +       FB_CMD_SET_ACTIVE,
> +       FB_CMD_UPLOAD,
> +
> +       FB_CMD_COUNT
> +};
> +
>  void fastboot_response(const char *tag, char *response,
>                        const char *format, ...)
>         __attribute__ ((format (__printf__, 3, 4)));
> @@ -54,4 +74,5 @@ void timed_send_info(ulong *start, const char *msg);
>   */
>  int strcmp_l1(const char *s1, const char *s2);
>
> +int fastboot_lookup_command(const char *cmd_string);
>  #endif /* _FASTBOOT_H_ */
> diff --git a/net/fastboot.c b/net/fastboot.c
> index ed13890..155049a 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -57,13 +57,39 @@ static int fastboot_remote_port;
>  /* The UDP port at our end */
>  static int fastboot_our_port;
>
> -static void fb_download(char *, unsigned int, char *);
> +static void cb_okay(char *, char *, unsigned int, char *);
> +static void cb_getvar(char *, char *, unsigned int, char *);
> +static void cb_download(char *, char *, unsigned int, char *);
>  #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> -static void fb_flash(char *);
> -static void fb_erase(char *);
> +static void cb_flash(char *, char *, unsigned int, char *);
> +static void cb_erase(char *, char *, unsigned int, char *);
>  #endif
> -static void fb_continue(char *);
> -static void fb_reboot(char *);
> +static void cb_continue(char *, char *, unsigned int, char *);
> +static void cb_reboot(char *, char *, unsigned int, char *);
> +
> +static void (*fb_net_dispatch[])(char *cmd_parameter,
> +                                char *fastboot_data,
> +                                unsigned int fastboot_data_len,
> +                                char *response) = {
> +       [FB_CMD_GETVAR] = cb_getvar,
> +       [FB_CMD_DOWNLOAD] = cb_download,
> +       [FB_CMD_VERIFY] = NULL,
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> +       [FB_CMD_FLASH] = cb_flash,
> +       [FB_CMD_ERASE] = cb_erase,
> +#else
> +       [FB_CMD_FLASH] = NULL,
> +       [FB_CMD_ERASE] = NULL,
> +#endif
> +       [FB_CMD_BOOT] = cb_okay,
> +       [FB_CMD_CONTINUE] = cb_continue,
> +       [FB_CMD_REBOOT] = cb_reboot,
> +       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot,
> +       [FB_CMD_POWERDOWN] = NULL,
> +       [FB_CMD_SET_ACTIVE] = cb_okay,
> +       [FB_CMD_UPLOAD] = NULL,
> +};
> +
>  static void boot_downloaded_image(void);
>  static void cleanup_command_data(void);
>
> @@ -165,28 +191,30 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
>                         cmd_string = strdup(cmd_string);
>                         if (cmd_parameter)
>                                 cmd_parameter = strdup(cmd_parameter);
> -               } else if (!strcmp("getvar", cmd_string)) {
> -                       fb_getvar(cmd_parameter, response);
> -               } else if (!strcmp("download", cmd_string)) {
> -                       fb_download(fastboot_data, fastboot_data_len, response);
> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> -               } else if (!strcmp("flash", cmd_string)) {
> -                       fb_flash(response);
> -               } else if (!strcmp("erase", cmd_string)) {
> -                       fb_erase(response);
> -#endif
> -               } else if (!strcmp("boot", cmd_string)) {
> -                       fastboot_okay(NULL, response);
> -               } else if (!strcmp("continue", cmd_string)) {
> -                       fb_continue(response);
> -               } else if (!strncmp("reboot", cmd_string, 6)) {
> -                       fb_reboot(response);
> -               } else if (!strcmp("set_active", cmd_string)) {
> -                       /* A/B not implemented, for now do nothing */
> -                       fastboot_okay(NULL, response);
>                 } else {
> -                       pr_err("command %s not implemented.\n", cmd_string);
> -                       fastboot_fail("unrecognized command", response);
> +                       int i;
> +
> +                       i = fastboot_lookup_command(cmd_string);
> +                       if (i >= 0) {
> +                               void (*fb_call)(char *cmd_parameter,
> +                                               char *fastboot_data,
> +                                               unsigned int fastboot_data_len,
> +                                               char *response);
> +                               fb_call = fb_net_dispatch[i];
> +                               if (fb_call) {
> +                                       fb_call(cmd_parameter, fastboot_data,
> +                                               fastboot_data_len, response);
> +                               } else {
> +                                       pr_err("command %s not implemented.\n",
> +                                              cmd_string);
> +                                       fastboot_fail("unrecognized command",
> +                                                     response);
> +                               }
> +                       } else {
> +                               pr_err("command %s not recognized.\n",
> +                                      cmd_string);
> +                               fastboot_fail("unrecognized command", response);
> +                       }
>                 }
>                 /* Sent some INFO packets, need to update sequence number in
>                  * header
> @@ -229,6 +257,18 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
>                 cleanup_command_data();
>  }
>
> +static void cb_okay(char *cmd_parameter, char *fastboot_data,

What does "cb_" stand for?

> +                   unsigned int fastboot_data_len, char *response)
> +{
> +       fastboot_okay(NULL, response);
> +}
> +
> +static void cb_getvar(char *cmd_parameter, char *fastboot_data,
> +                     unsigned int fastboot_data_len, char *response)
> +{
> +       fb_getvar(cmd_parameter, response);
> +}
> +
>  /**
>   * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
>   * Writes to response.
> @@ -237,8 +277,8 @@ static void fastboot_send(struct fastboot_header fb_header, char *fastboot_data,
>   * @param fastboot_data_len    Length of received fastboot data
>   * @param repsonse             Pointer to fastboot response buffer
>   */
> -static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
> -                       char *response)
> +static void cb_download(char *cmd_parameter, char *fastboot_data,
> +                       unsigned int fastboot_data_len, char *response)
>  {
>         char *tmp;
>
> @@ -292,7 +332,8 @@ static void fb_download(char *fastboot_data, unsigned int fastboot_data_len,
>   *
>   * @param repsonse    Pointer to fastboot response buffer
>   */
> -static void fb_flash(char *response)
> +static void cb_flash(char *cmd_parameter, char *fastboot_data,
> +                    unsigned int fastboot_data_len, char *response)
>  {
>         fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
>                            image_size, response);
> @@ -304,7 +345,8 @@ static void fb_flash(char *response)
>   *
>   * @param repsonse    Pointer to fastboot response buffer
>   */
> -static void fb_erase(char *response)
> +static void cb_erase(char *cmd_parameter, char *fastboot_data,
> +                    unsigned int fastboot_data_len, char *response)
>  {
>         fb_mmc_erase(cmd_parameter, response);
>  }
> @@ -316,7 +358,8 @@ static void fb_erase(char *response)
>   *
>   * @param repsonse    Pointer to fastboot response buffer
>   */
> -static void fb_continue(char *response)
> +static void cb_continue(char *cmd_parameter, char *fastboot_data,
> +                       unsigned int fastboot_data_len, char *response)
>  {
>         net_set_state(NETLOOP_SUCCESS);
>         fastboot_okay(NULL, response);
> @@ -327,7 +370,8 @@ static void fb_continue(char *response)
>   *
>   * @param repsonse    Pointer to fastboot response buffer
>   */
> -static void fb_reboot(char *response)
> +static void cb_reboot(char *cmd_parameter, char *fastboot_data,
> +                     unsigned int fastboot_data_len, char *response)
>  {
>         fastboot_okay(NULL, response);
>         if (!strcmp("reboot-bootloader", cmd_string))
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling Alex Kiernan
  2018-05-01  6:49   ` Jocelyn Bohr
@ 2018-05-03 21:15   ` Joe Hershberger
  2018-05-04  7:34     ` Alex Kiernan
  1 sibling, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:15 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Extract fb_set_reboot_flag() from USB code and ensure all the overides
> are included, then make the UDP fastboot code go through this same
> path.
>
> Note this changes the behaviour of the fastboot net code such that
> "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR for
> use as a marker on reboot (the AOSP code in common/android-bootloader.c
> uses this marker - this code could be reinstated there if that gets
> merged).
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

One nit below, but,

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

> ---
>
> Changes in v2: None
>
>  arch/arm/mach-omap2/boot-common.c     |  2 +-
>  arch/arm/mach-rockchip/rk3128-board.c |  2 +-
>  arch/arm/mach-rockchip/rk322x-board.c |  2 +-
>  drivers/fastboot/fb_common.c          |  5 +++++
>  drivers/usb/gadget/f_fastboot.c       |  5 -----
>  include/fastboot.h                    |  1 +
>  net/fastboot.c                        | 17 +++++++++--------
>  7 files changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/boot-common.c b/arch/arm/mach-omap2/boot-common.c
> index f9ab5da..2be5c11 100644
> --- a/arch/arm/mach-omap2/boot-common.c
> +++ b/arch/arm/mach-omap2/boot-common.c
> @@ -238,7 +238,7 @@ void arch_preboot_os(void)
>  }
>  #endif
>
> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) && !defined(CONFIG_ENV_IS_NOWHERE)
> +#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
>  int fb_set_reboot_flag(void)
>  {
>         printf("Setting reboot to fastboot flag ...\n");
> diff --git a/arch/arm/mach-rockchip/rk3128-board.c b/arch/arm/mach-rockchip/rk3128-board.c
> index 2e8393d..00ad563 100644
> --- a/arch/arm/mach-rockchip/rk3128-board.c
> +++ b/arch/arm/mach-rockchip/rk3128-board.c
> @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum usb_init_type init)
>  }
>  #endif
>
> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> +#if CONFIG_IS_ENABLED(FASTBOOT)
>  int fb_set_reboot_flag(void)
>  {
>         struct rk3128_grf *grf;
> diff --git a/arch/arm/mach-rockchip/rk322x-board.c b/arch/arm/mach-rockchip/rk322x-board.c
> index 8642a90..0ddfac8 100644
> --- a/arch/arm/mach-rockchip/rk322x-board.c
> +++ b/arch/arm/mach-rockchip/rk322x-board.c
> @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum usb_init_type init)
>  }
>  #endif
>
> -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> +#if CONFIG_IS_ENABLED(FASTBOOT)
>  int fb_set_reboot_flag(void)
>  {
>         struct rk322x_grf *grf;
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> index 8b3627b..36ef669 100644
> --- a/drivers/fastboot/fb_common.c
> +++ b/drivers/fastboot/fb_common.c
> @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char *cmd_string)
>
>         return -1;
>  }
> +
> +int __weak fb_set_reboot_flag(void)
> +{
> +       return -1;

Why did you stop returning a proper errno?

> +}
> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> index a493c75..84515da 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -357,11 +357,6 @@ 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;
> diff --git a/include/fastboot.h b/include/fastboot.h
> index de07220..9767065 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -75,4 +75,5 @@ void timed_send_info(ulong *start, const char *msg);
>  int strcmp_l1(const char *s1, const char *s2);
>
>  int fastboot_lookup_command(const char *cmd_string);
> +int fb_set_reboot_flag(void);
>  #endif /* _FASTBOOT_H_ */
> diff --git a/net/fastboot.c b/net/fastboot.c
> index 155049a..edf78df 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -65,7 +65,7 @@ static void cb_flash(char *, char *, unsigned int, char *);
>  static void cb_erase(char *, char *, unsigned int, char *);
>  #endif
>  static void cb_continue(char *, char *, unsigned int, char *);
> -static void cb_reboot(char *, char *, unsigned int, char *);
> +static void cb_reboot_bootloader(char *, char *, unsigned int, char *);
>
>  static void (*fb_net_dispatch[])(char *cmd_parameter,
>                                  char *fastboot_data,
> @@ -83,8 +83,8 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
>  #endif
>         [FB_CMD_BOOT] = cb_okay,
>         [FB_CMD_CONTINUE] = cb_continue,
> -       [FB_CMD_REBOOT] = cb_reboot,
> -       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot,
> +       [FB_CMD_REBOOT] = cb_okay,
> +       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot_bootloader,
>         [FB_CMD_POWERDOWN] = NULL,
>         [FB_CMD_SET_ACTIVE] = cb_okay,
>         [FB_CMD_UPLOAD] = NULL,
> @@ -370,12 +370,13 @@ static void cb_continue(char *cmd_parameter, char *fastboot_data,
>   *
>   * @param repsonse    Pointer to fastboot response buffer
>   */
> -static void cb_reboot(char *cmd_parameter, char *fastboot_data,
> -                     unsigned int fastboot_data_len, char *response)
> +static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
> +                                unsigned int fastboot_data_len, char *response)
>  {
> -       fastboot_okay(NULL, response);
> -       if (!strcmp("reboot-bootloader", cmd_string))
> -               strcpy((char *)CONFIG_FASTBOOT_BUF_ADDR, "reboot-bootloader");
> +       if (fb_set_reboot_flag())
> +               fastboot_fail("Cannot set reboot flag", response);
> +       else
> +               fastboot_okay(NULL, response);
>  }
>
>  /**
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot Alex Kiernan
@ 2018-05-03 21:17   ` Joe Hershberger
  2018-05-07 21:20     ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:17 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> When picking up boot/reboot after we've sent our result packet, use
> the previously parsed command rather than redoing the strcmp.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP Alex Kiernan
@ 2018-05-03 21:21   ` Joe Hershberger
  2018-05-07 21:59     ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:21 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Merge USB and UDP boot code. The USB implementation stays the same, but
> UDP no longer passes an fdt. We introduce a new environment variable
> 'fastbootcmd' which if set overrides the hardcoded boot command, setting
> this then allows the UDP implementation to remain the same. If after
> running 'fastbootcmd' the board has not booted, control is returned
> to U-Boot and the fastboot process ends.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Nit below...

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

> ---
>
> Changes in v2: None
>
>  drivers/fastboot/fb_common.c    | 27 +++++++++++++++++++++++++++
>  drivers/usb/gadget/f_fastboot.c | 22 +++++++---------------
>  include/fastboot.h              |  1 +
>  net/fastboot.c                  | 16 ++--------------
>  4 files changed, 37 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> index 36ef669..73d8f94 100644
> --- a/drivers/fastboot/fb_common.c
> +++ b/drivers/fastboot/fb_common.c
> @@ -107,3 +107,30 @@ int __weak fb_set_reboot_flag(void)
>  {
>         return -1;
>  }
> +
> +void fastboot_boot(void *addr)
> +{
> +       char *s;
> +
> +       s = env_get("fastbootcmd");
> +       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%lx", (long)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

Use multi-line comment format. '/*' gets its own line.

> +                * over. We deliberately leave this policy to the invocation
> +                * of fastbootcmd if that's what's being run
> +                */
> +               do_reset(NULL, 0, 0, NULL);
> +       }
> +}
> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> index 84515da..1dca4dd 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -480,18 +480,15 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req)
>         fastboot_tx_write_str(response);
>  }
>
> -static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
> +static void do_exit_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);
> +       g_dnl_trigger_detach();
> +}
>
> -       /* This only happens if image is somehow faulty so we start over */
> -       do_reset(NULL, 0, 0, NULL);
> +static void do_bootm_on_complete(struct usb_ep *ep, struct usb_request *req)
> +{
> +       fastboot_boot((void *)CONFIG_FASTBOOT_BUF_ADDR);
> +       do_exit_on_complete(ep, req);
>  }
>
>  static void cb_boot(struct usb_ep *ep, struct usb_request *req)
> @@ -500,11 +497,6 @@ static void cb_boot(struct usb_ep *ep, struct usb_request *req)
>         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)
>  {
>         fastboot_func->in_req->complete = do_exit_on_complete;
> diff --git a/include/fastboot.h b/include/fastboot.h
> index 9767065..64f9939 100644
> --- a/include/fastboot.h
> +++ b/include/fastboot.h
> @@ -76,4 +76,5 @@ int strcmp_l1(const char *s1, const char *s2);
>
>  int fastboot_lookup_command(const char *cmd_string);
>  int fb_set_reboot_flag(void);
> +void fastboot_boot(void *addr);
>  #endif /* _FASTBOOT_H_ */
> diff --git a/net/fastboot.c b/net/fastboot.c
> index ad8c101..119011c 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -383,20 +383,8 @@ static void cb_reboot_bootloader(char *cmd_parameter, char *fastboot_data,
>   */
>  static void boot_downloaded_image(void)
>  {
> -       char kernel_addr[12];
> -       char *fdt_addr = env_get("fdt_addr_r");
> -       char *const bootm_args[] = {
> -               "bootm", kernel_addr, "-", fdt_addr, NULL
> -       };
> -
> -       sprintf(kernel_addr, "0x%lx", (long)CONFIG_FASTBOOT_BUF_ADDR);
> -
> -       printf("\nBooting kernel at %s with fdt at %s...\n\n\n",
> -              kernel_addr, fdt_addr);
> -       do_bootm(NULL, 0, 4, bootm_args);
> -
> -       /* This only happens if image is faulty so we start over. */
> -       do_reset(NULL, 0, 0, NULL);
> +       fastboot_boot((void *)CONFIG_FASTBOOT_BUF_ADDR);
> +       net_set_state(NETLOOP_SUCCESS);
>  }
>
>  /**
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support Alex Kiernan
@ 2018-05-03 21:24   ` Joe Hershberger
  2018-05-08 16:38     ` Jocelyn Bohr
  2018-05-08  6:53   ` Jocelyn Bohr
  1 sibling, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:24 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Add NAND support to fastboot UDP flash/erase commands
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 17/20] fastboot: Guard getvar:partition-type/size with MMC
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 17/20] fastboot: Guard getvar:partition-type/size with MMC Alex Kiernan
@ 2018-05-03 21:26   ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:26 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Add guard for partition-type/size against MMC as we need that in order
> to lookup partitions.

Why? It seems you should just be using mtdparts when NAND is enabled instead.

>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
>
> Changes in v2: None
>
>  drivers/fastboot/fb_getvar.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/fastboot/fb_getvar.c b/drivers/fastboot/fb_getvar.c
> index aa68371..7989a19 100644
> --- a/drivers/fastboot/fb_getvar.c
> +++ b/drivers/fastboot/fb_getvar.c
> @@ -55,6 +55,7 @@ void fb_getvar(char *cmd_parameter, char *response)
>                         fastboot_okay("yes", response);
>                 else
>                         fastboot_okay("no", response);
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
>         } else if (!strcmp_l1("partition-type", cmd_parameter) ||
>                    !strcmp_l1("partition-size", cmd_parameter)) {
>                 disk_partition_t part_info;
> @@ -74,6 +75,7 @@ void fb_getvar(char *cmd_parameter, char *response)
>                         fastboot_response("OKAY", response,
>                                           "0x%016x", (int)part_info.size);
>                 }
> +#endif
>         } else {
>  #define FASTBOOT_ENV_PREFIX    "fastboot."
>                 char envstr[FASTBOOT_RESPONSE_LEN];
> --
> 2.7.4
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 18/20] fastboot: Check if part_name is NULL before using it
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 18/20] fastboot: Check if part_name is NULL before using it Alex Kiernan
@ 2018-05-03 21:26   ` Joe Hershberger
  2018-05-08  6:55     ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:26 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> If we don't have a partition name passed, report it as not found.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 19/20] fastboot: Add missing newlines
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 19/20] fastboot: Add missing newlines Alex Kiernan
@ 2018-05-03 21:26   ` Joe Hershberger
  2018-05-08  6:56     ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:26 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Add newlines so we format our output correctly.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 20/20] fastboot: net: Split fastboot protocol out from net
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 20/20] fastboot: net: Split fastboot protocol out from net Alex Kiernan
@ 2018-05-03 21:29   ` Joe Hershberger
  2018-05-04  6:05     ` Alex Kiernan
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-03 21:29 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> Separate the fastboot protocol handling from the fastboot UDP code in
> preparation for reusing it in the USB code.
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

This is the last patch, yet you are preparing for something to follow,
so I'll review when you get to that point.

Cheers,
-Joe

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 09/20] fastboot: Refactor write_fb_response into fastboot_okay/fail/response
  2018-05-03 20:48   ` Joe Hershberger
@ 2018-05-04  6:00     ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-04  6:00 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 1:48 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > Replace write_fb_response with fastboot_okay/fail/response. Also allow
> > fastboot_okay to take NULL when we have no message to send.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 20/20] fastboot: net: Split fastboot protocol out from net
  2018-05-03 21:29   ` Joe Hershberger
@ 2018-05-04  6:05     ` Alex Kiernan
  0 siblings, 0 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-05-04  6:05 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 10:30 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
wrote:
> > Separate the fastboot protocol handling from the fastboot UDP code in
> > preparation for reusing it in the USB code.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

> This is the last patch, yet you are preparing for something to follow,
> so I'll review when you get to that point.


Thanks for all your reviewing efforts so far.

Stopping here, was clearly the right choice as now I'm carving up the USB
code, it's clear that I left some of the UDP protocol handling in this
patch.

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 08/20] net: fastboot: Support building without MMC
  2018-05-03 20:39   ` Joe Hershberger
@ 2018-05-04  6:06     ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-04  6:06 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 1:40 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > If the fastboot flash/erase commands are disabled, remove that support
> > so we still build correctly.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot
  2018-05-03 20:58   ` Joe Hershberger
@ 2018-05-04  6:18     ` Jocelyn Bohr
  2018-05-08  9:20     ` Alex Kiernan
  1 sibling, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-04  6:18 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 1:58 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > Change the behaviour of 'continue' so that we simply exit the fastboot
> > server and leave the caller to decide what to do next. This matches
> > the USB fastboot behaviour.
>
> Good, I was considering recommending this approach.
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>


Agreed, this is really the correct behavior of continue.

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-05-03 21:15   ` Joe Hershberger
@ 2018-05-04  7:34     ` Alex Kiernan
  2018-05-04  7:44       ` Joe Hershberger
  0 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-05-04  7:34 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 10:16 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
wrote:
> > Extract fb_set_reboot_flag() from USB code and ensure all the overides
> > are included, then make the UDP fastboot code go through this same
> > path.
> >
> > Note this changes the behaviour of the fastboot net code such that
> > "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR for
> > use as a marker on reboot (the AOSP code in common/android-bootloader.c
> > uses this marker - this code could be reinstated there if that gets
> > merged).
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>

> One nit below, but,

> Acked-by: Joe Hershberger <joe.hershberger@ni.com>

> > ---
> >
> > Changes in v2: None
> >
> >  arch/arm/mach-omap2/boot-common.c     |  2 +-
> >  arch/arm/mach-rockchip/rk3128-board.c |  2 +-
> >  arch/arm/mach-rockchip/rk322x-board.c |  2 +-
> >  drivers/fastboot/fb_common.c          |  5 +++++
> >  drivers/usb/gadget/f_fastboot.c       |  5 -----
> >  include/fastboot.h                    |  1 +
> >  net/fastboot.c                        | 17 +++++++++--------
> >  7 files changed, 18 insertions(+), 16 deletions(-)
> >
> > diff --git a/arch/arm/mach-omap2/boot-common.c
b/arch/arm/mach-omap2/boot-common.c
> > index f9ab5da..2be5c11 100644
> > --- a/arch/arm/mach-omap2/boot-common.c
> > +++ b/arch/arm/mach-omap2/boot-common.c
> > @@ -238,7 +238,7 @@ void arch_preboot_os(void)
> >  }
> >  #endif
> >
> > -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) &&
!defined(CONFIG_ENV_IS_NOWHERE)
> > +#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
> >  int fb_set_reboot_flag(void)
> >  {
> >         printf("Setting reboot to fastboot flag ...\n");
> > diff --git a/arch/arm/mach-rockchip/rk3128-board.c
b/arch/arm/mach-rockchip/rk3128-board.c
> > index 2e8393d..00ad563 100644
> > --- a/arch/arm/mach-rockchip/rk3128-board.c
> > +++ b/arch/arm/mach-rockchip/rk3128-board.c
> > @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum usb_init_type
init)
> >  }
> >  #endif
> >
> > -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> > +#if CONFIG_IS_ENABLED(FASTBOOT)
> >  int fb_set_reboot_flag(void)
> >  {
> >         struct rk3128_grf *grf;
> > diff --git a/arch/arm/mach-rockchip/rk322x-board.c
b/arch/arm/mach-rockchip/rk322x-board.c
> > index 8642a90..0ddfac8 100644
> > --- a/arch/arm/mach-rockchip/rk322x-board.c
> > +++ b/arch/arm/mach-rockchip/rk322x-board.c
> > @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum usb_init_type
init)
> >  }
> >  #endif
> >
> > -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
> > +#if CONFIG_IS_ENABLED(FASTBOOT)
> >  int fb_set_reboot_flag(void)
> >  {
> >         struct rk322x_grf *grf;
> > diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> > index 8b3627b..36ef669 100644
> > --- a/drivers/fastboot/fb_common.c
> > +++ b/drivers/fastboot/fb_common.c
> > @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char *cmd_string)
> >
> >         return -1;
> >  }
> > +
> > +int __weak fb_set_reboot_flag(void)
> > +{
> > +       return -1;

> Why did you stop returning a proper errno?


checkpatch doesn't like it:

WARNING: ENOSYS means 'invalid syscall nr' and nothing else
#10: FILE: drivers/fastboot/fb_common.c:92:
+ return -ENOSYS;

If that's a warning we're happy to ignore, I'll swap it back.

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling
  2018-05-04  7:34     ` Alex Kiernan
@ 2018-05-04  7:44       ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-04  7:44 UTC (permalink / raw)
  To: u-boot

On Fri, May 4, 2018 at 2:34 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> On Thu, May 3, 2018 at 10:16 PM Joe Hershberger <joe.hershberger@ni.com>
> wrote:
>
>> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
>> > Extract fb_set_reboot_flag() from USB code and ensure all the overides
>> > are included, then make the UDP fastboot code go through this same
>> > path.
>> >
>> > Note this changes the behaviour of the fastboot net code such that
>> > "reboot-bootloader" is no longer written to CONFIG_FASTBOOT_BUF_ADDR for
>> > use as a marker on reboot (the AOSP code in common/android-bootloader.c
>> > uses this marker - this code could be reinstated there if that gets
>> > merged).
>> >
>> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
>> One nit below, but,
>
>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>
>> > ---
>> >
>> > Changes in v2: None
>> >
>> >  arch/arm/mach-omap2/boot-common.c     |  2 +-
>> >  arch/arm/mach-rockchip/rk3128-board.c |  2 +-
>> >  arch/arm/mach-rockchip/rk322x-board.c |  2 +-
>> >  drivers/fastboot/fb_common.c          |  5 +++++
>> >  drivers/usb/gadget/f_fastboot.c       |  5 -----
>> >  include/fastboot.h                    |  1 +
>> >  net/fastboot.c                        | 17 +++++++++--------
>> >  7 files changed, 18 insertions(+), 16 deletions(-)
>> >
>> > diff --git a/arch/arm/mach-omap2/boot-common.c
> b/arch/arm/mach-omap2/boot-common.c
>> > index f9ab5da..2be5c11 100644
>> > --- a/arch/arm/mach-omap2/boot-common.c
>> > +++ b/arch/arm/mach-omap2/boot-common.c
>> > @@ -238,7 +238,7 @@ void arch_preboot_os(void)
>> >  }
>> >  #endif
>> >
>> > -#if defined(CONFIG_USB_FUNCTION_FASTBOOT) &&
> !defined(CONFIG_ENV_IS_NOWHERE)
>> > +#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
>> >  int fb_set_reboot_flag(void)
>> >  {
>> >         printf("Setting reboot to fastboot flag ...\n");
>> > diff --git a/arch/arm/mach-rockchip/rk3128-board.c
> b/arch/arm/mach-rockchip/rk3128-board.c
>> > index 2e8393d..00ad563 100644
>> > --- a/arch/arm/mach-rockchip/rk3128-board.c
>> > +++ b/arch/arm/mach-rockchip/rk3128-board.c
>> > @@ -112,7 +112,7 @@ int board_usb_cleanup(int index, enum usb_init_type
> init)
>> >  }
>> >  #endif
>> >
>> > -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
>> > +#if CONFIG_IS_ENABLED(FASTBOOT)
>> >  int fb_set_reboot_flag(void)
>> >  {
>> >         struct rk3128_grf *grf;
>> > diff --git a/arch/arm/mach-rockchip/rk322x-board.c
> b/arch/arm/mach-rockchip/rk322x-board.c
>> > index 8642a90..0ddfac8 100644
>> > --- a/arch/arm/mach-rockchip/rk322x-board.c
>> > +++ b/arch/arm/mach-rockchip/rk322x-board.c
>> > @@ -140,7 +140,7 @@ int board_usb_cleanup(int index, enum usb_init_type
> init)
>> >  }
>> >  #endif
>> >
>> > -#if defined(CONFIG_USB_FUNCTION_FASTBOOT)
>> > +#if CONFIG_IS_ENABLED(FASTBOOT)
>> >  int fb_set_reboot_flag(void)
>> >  {
>> >         struct rk322x_grf *grf;
>> > diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
>> > index 8b3627b..36ef669 100644
>> > --- a/drivers/fastboot/fb_common.c
>> > +++ b/drivers/fastboot/fb_common.c
>> > @@ -102,3 +102,8 @@ int fastboot_lookup_command(const char *cmd_string)
>> >
>> >         return -1;
>> >  }
>> > +
>> > +int __weak fb_set_reboot_flag(void)
>> > +{
>> > +       return -1;
>
>> Why did you stop returning a proper errno?
>
>
> checkpatch doesn't like it:
>
> WARNING: ENOSYS means 'invalid syscall nr' and nothing else
> #10: FILE: drivers/fastboot/fb_common.c:92:
> + return -ENOSYS;
>
> If that's a warning we're happy to ignore, I'll swap it back.

Yep, I'll ignore it. That's a Linux-only complaint. It should be added
to the checkpatch config to be skipped.

> --
> Alex Kiernan
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 12/20] fastboot: net: Convert command lookup to a table
  2018-05-03 21:08   ` Joe Hershberger
@ 2018-05-04  9:14     ` Alex Kiernan
  0 siblings, 0 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-05-04  9:14 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 10:08 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
wrote:
> > Change command lookup to use a lookup table so it matches the existing
> > USB fastboot code.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> > ---
> >
> > Changes in v2: None
> >
> >  drivers/fastboot/fb_common.c |  30 ++++++++++++
> >  include/fastboot.h           |  21 +++++++++
> >  net/fastboot.c               | 108
++++++++++++++++++++++++++++++-------------
> >  3 files changed, 127 insertions(+), 32 deletions(-)
> >
> > diff --git a/drivers/fastboot/fb_common.c b/drivers/fastboot/fb_common.c
> > index 3b68f25..8b3627b 100644
> > --- a/drivers/fastboot/fb_common.c
> > +++ b/drivers/fastboot/fb_common.c
> > @@ -72,3 +72,33 @@ int strcmp_l1(const char *s1, const char *s2)
> >                 return -1;
> >         return strncmp(s1, s2, strlen(s1));
> >  }
> > +
> > +static const char *const fb_commands[] = {
> > +       [FB_CMD_GETVAR] = "getvar",
> > +       [FB_CMD_DOWNLOAD] = "download",
> > +       [FB_CMD_VERIFY] = "verify",
> > +       [FB_CMD_FLASH] = "flash",
> > +       [FB_CMD_ERASE] = "erase",
> > +       [FB_CMD_BOOT] = "boot",
> > +       [FB_CMD_CONTINUE] = "continue",
> > +       [FB_CMD_REBOOT] = "reboot",
> > +       [FB_CMD_REBOOT_BOOTLOADER] = "reboot-bootloader",
> > +       [FB_CMD_POWERDOWN] = "powerdown",
> > +       [FB_CMD_SET_ACTIVE] = "set_active",
> > +       [FB_CMD_UPLOAD] = "upload",
> > +};
> > +
> > +int fastboot_lookup_command(const char *cmd_string)
> > +{
> > +       int i;
> > +
> > +       for (i = 0; i < FB_CMD_COUNT; i++) {
> > +               int len = strlen(fb_commands[i]);
> > +
> > +               if (!strncmp(fb_commands[i], cmd_string, len) &&

> Why not use your new strcmp_l1()?

> > +                   (cmd_string[len] == '\0' || cmd_string[len] == ':'))

> At this point the ':' is already deleted.


It's a bit of my prep for picking the USB code leaking in. But I'm probably
going to refactor this change out of existence now I'm actually looking at
the USB code.

> > +                       return i;
> > +       }
> > +
> > +       return -1;
> > +}
> > diff --git a/include/fastboot.h b/include/fastboot.h
> > index fb58358..de07220 100644
> > --- a/include/fastboot.h
> > +++ b/include/fastboot.h
> > @@ -18,6 +18,26 @@
> >  /* The 64 defined bytes plus \0 */
> >  #define FASTBOOT_RESPONSE_LEN  (64 + 1)
> >
> > +/**
> > + * All known commands to fastboot
> > + */
> > +enum {
> > +       FB_CMD_GETVAR = 0,
> > +       FB_CMD_DOWNLOAD,
> > +       FB_CMD_VERIFY,
> > +       FB_CMD_FLASH,
> > +       FB_CMD_ERASE,
> > +       FB_CMD_BOOT,
> > +       FB_CMD_CONTINUE,
> > +       FB_CMD_REBOOT,
> > +       FB_CMD_REBOOT_BOOTLOADER,
> > +       FB_CMD_POWERDOWN,
> > +       FB_CMD_SET_ACTIVE,
> > +       FB_CMD_UPLOAD,
> > +
> > +       FB_CMD_COUNT
> > +};
> > +
> >  void fastboot_response(const char *tag, char *response,
> >                        const char *format, ...)
> >         __attribute__ ((format (__printf__, 3, 4)));
> > @@ -54,4 +74,5 @@ void timed_send_info(ulong *start, const char *msg);
> >   */
> >  int strcmp_l1(const char *s1, const char *s2);
> >
> > +int fastboot_lookup_command(const char *cmd_string);
> >  #endif /* _FASTBOOT_H_ */
> > diff --git a/net/fastboot.c b/net/fastboot.c
> > index ed13890..155049a 100644
> > --- a/net/fastboot.c
> > +++ b/net/fastboot.c
> > @@ -57,13 +57,39 @@ static int fastboot_remote_port;
> >  /* The UDP port at our end */
> >  static int fastboot_our_port;
> >
> > -static void fb_download(char *, unsigned int, char *);
> > +static void cb_okay(char *, char *, unsigned int, char *);
> > +static void cb_getvar(char *, char *, unsigned int, char *);
> > +static void cb_download(char *, char *, unsigned int, char *);
> >  #if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> > -static void fb_flash(char *);
> > -static void fb_erase(char *);
> > +static void cb_flash(char *, char *, unsigned int, char *);
> > +static void cb_erase(char *, char *, unsigned int, char *);
> >  #endif
> > -static void fb_continue(char *);
> > -static void fb_reboot(char *);
> > +static void cb_continue(char *, char *, unsigned int, char *);
> > +static void cb_reboot(char *, char *, unsigned int, char *);
> > +
> > +static void (*fb_net_dispatch[])(char *cmd_parameter,
> > +                                char *fastboot_data,
> > +                                unsigned int fastboot_data_len,
> > +                                char *response) = {
> > +       [FB_CMD_GETVAR] = cb_getvar,
> > +       [FB_CMD_DOWNLOAD] = cb_download,
> > +       [FB_CMD_VERIFY] = NULL,
> > +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> > +       [FB_CMD_FLASH] = cb_flash,
> > +       [FB_CMD_ERASE] = cb_erase,
> > +#else
> > +       [FB_CMD_FLASH] = NULL,
> > +       [FB_CMD_ERASE] = NULL,
> > +#endif
> > +       [FB_CMD_BOOT] = cb_okay,
> > +       [FB_CMD_CONTINUE] = cb_continue,
> > +       [FB_CMD_REBOOT] = cb_reboot,
> > +       [FB_CMD_REBOOT_BOOTLOADER] = cb_reboot,
> > +       [FB_CMD_POWERDOWN] = NULL,
> > +       [FB_CMD_SET_ACTIVE] = cb_okay,
> > +       [FB_CMD_UPLOAD] = NULL,
> > +};
> > +
> >  static void boot_downloaded_image(void);
> >  static void cleanup_command_data(void);
> >
> > @@ -165,28 +191,30 @@ static void fastboot_send(struct fastboot_header
fb_header, char *fastboot_data,
> >                         cmd_string = strdup(cmd_string);
> >                         if (cmd_parameter)
> >                                 cmd_parameter = strdup(cmd_parameter);
> > -               } else if (!strcmp("getvar", cmd_string)) {
> > -                       fb_getvar(cmd_parameter, response);
> > -               } else if (!strcmp("download", cmd_string)) {
> > -                       fb_download(fastboot_data, fastboot_data_len,
response);
> > -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> > -               } else if (!strcmp("flash", cmd_string)) {
> > -                       fb_flash(response);
> > -               } else if (!strcmp("erase", cmd_string)) {
> > -                       fb_erase(response);
> > -#endif
> > -               } else if (!strcmp("boot", cmd_string)) {
> > -                       fastboot_okay(NULL, response);
> > -               } else if (!strcmp("continue", cmd_string)) {
> > -                       fb_continue(response);
> > -               } else if (!strncmp("reboot", cmd_string, 6)) {
> > -                       fb_reboot(response);
> > -               } else if (!strcmp("set_active", cmd_string)) {
> > -                       /* A/B not implemented, for now do nothing */
> > -                       fastboot_okay(NULL, response);
> >                 } else {
> > -                       pr_err("command %s not implemented.\n",
cmd_string);
> > -                       fastboot_fail("unrecognized command", response);
> > +                       int i;
> > +
> > +                       i = fastboot_lookup_command(cmd_string);
> > +                       if (i >= 0) {
> > +                               void (*fb_call)(char *cmd_parameter,
> > +                                               char *fastboot_data,
> > +                                               unsigned int
fastboot_data_len,
> > +                                               char *response);
> > +                               fb_call = fb_net_dispatch[i];
> > +                               if (fb_call) {
> > +                                       fb_call(cmd_parameter,
fastboot_data,
> > +                                               fastboot_data_len,
response);
> > +                               } else {
> > +                                       pr_err("command %s not
implemented.\n",
> > +                                              cmd_string);
> > +                                       fastboot_fail("unrecognized
command",
> > +                                                     response);
> > +                               }
> > +                       } else {
> > +                               pr_err("command %s not recognized.\n",
> > +                                      cmd_string);
> > +                               fastboot_fail("unrecognized command",
response);
> > +                       }
> >                 }
> >                 /* Sent some INFO packets, need to update sequence
number in
> >                  * header
> > @@ -229,6 +257,18 @@ static void fastboot_send(struct fastboot_header
fb_header, char *fastboot_data,
> >                 cleanup_command_data();
> >  }
> >
> > +static void cb_okay(char *cmd_parameter, char *fastboot_data,

> What does "cb_" stand for?


Stolen from the USB fastboot code. I guess it's callback, but its not
really that... I'll change it.

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot
  2018-05-03 21:17   ` Joe Hershberger
@ 2018-05-07 21:20     ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-07 21:20 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 2:18 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > When picking up boot/reboot after we've sent our result packet, use
> > the previously parsed command rather than redoing the strcmp.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP
  2018-05-03 21:21   ` Joe Hershberger
@ 2018-05-07 21:59     ` Jocelyn Bohr
  2018-05-08  6:08       ` Joe Hershberger
  0 siblings, 1 reply; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-07 21:59 UTC (permalink / raw)
  To: u-boot

Optional nit: Consider renaming "fastbootcmd" to "fb_bootcmd" or similar.
IMO "fastbootcmd" is
ambiguous as there can be multiple env variable commands related to
fastboot.

On Thu, May 3, 2018 at 2:21 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > Merge USB and UDP boot code. The USB implementation stays the same, but
> > UDP no longer passes an fdt. We introduce a new environment variable
> > 'fastbootcmd' which if set overrides the hardcoded boot command, setting
> > this then allows the UDP implementation to remain the same. If after
> > running 'fastbootcmd' the board has not booted, control is returned
> > to U-Boot and the fastboot process ends.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Nit below...
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP
  2018-05-07 21:59     ` Jocelyn Bohr
@ 2018-05-08  6:08       ` Joe Hershberger
  2018-05-08  6:54         ` Alex Kiernan
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-08  6:08 UTC (permalink / raw)
  To: u-boot

On Mon, May 7, 2018 at 4:59 PM, Jocelyn Bohr <bohr@google.com> wrote:
> Optional nit: Consider renaming "fastbootcmd" to "fb_bootcmd" or similar.
> IMO "fastbootcmd" is
> ambiguous as there can be multiple env variable commands related to
> fastboot.

Seems like a good suggestion to me.

> On Thu, May 3, 2018 at 2:21 PM Joe Hershberger <joe.hershberger@ni.com>
> wrote:
>
>> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
>> wrote:
>> > Merge USB and UDP boot code. The USB implementation stays the same, but
>> > UDP no longer passes an fdt. We introduce a new environment variable
>> > 'fastbootcmd' which if set overrides the hardcoded boot command, setting
>> > this then allows the UDP implementation to remain the same. If after
>> > running 'fastbootcmd' the board has not booted, control is returned
>> > to U-Boot and the fastboot process ends.
>> >
>> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>>
>> Nit below...
>>
>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>>
>
> Reviewed-by: Jocelyn Bohr <bohr@google.com>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support
  2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support Alex Kiernan
  2018-05-03 21:24   ` Joe Hershberger
@ 2018-05-08  6:53   ` Jocelyn Bohr
  2018-05-08  7:19     ` Joe Hershberger
  1 sibling, 1 reply; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-08  6:53 UTC (permalink / raw)
  To: u-boot

On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

> Add NAND support to fastboot UDP flash/erase commands
>
> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> ---
>
> Changes in v2: None
>
>  net/fastboot.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/net/fastboot.c b/net/fastboot.c
> index 119011c..a07b1ad 100644
> --- a/net/fastboot.c
> +++ b/net/fastboot.c
> @@ -60,7 +60,7 @@ static int fastboot_our_port;
>  static void cb_okay(char *, char *, unsigned int, char *);
>  static void cb_getvar(char *, char *, unsigned int, char *);
>  static void cb_download(char *, char *, unsigned int, char *);
> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
>  static void cb_flash(char *, char *, unsigned int, char *);
>  static void cb_erase(char *, char *, unsigned int, char *);
>  #endif
> @@ -74,7 +74,7 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
>         [FB_CMD_GETVAR] = cb_getvar,
>         [FB_CMD_DOWNLOAD] = cb_download,
>         [FB_CMD_VERIFY] = NULL,
> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
>         [FB_CMD_FLASH] = cb_flash,
>         [FB_CMD_ERASE] = cb_erase,
>  #else
> @@ -324,7 +324,7 @@ static void cb_download(char *cmd_parameter, char
> *fastboot_data,
>         }
>  }
>
> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
>  /**
>   * Writes the previously downloaded image to the partition indicated by
>   * cmd_parameter. Writes to response.
> @@ -334,8 +334,14 @@ static void cb_download(char *cmd_parameter, char
> *fastboot_data,
>  static void cb_flash(char *cmd_parameter, char *fastboot_data,
>                      unsigned int fastboot_data_len, char *response)
>  {
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
>         fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
>                            image_size, response);
> +#endif
> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
> +       fb_nand_flash_write(cmd_parameter, (void
> *)CONFIG_FASTBOOT_BUF_ADDR,
> +                           image_size, response);
> +#endif
>

Is there a way to make FASTBOOT_FLASH_MMC and FASTBOOT_FLASH_NAND
mutually exclusive? Currently here and elsewhere, both mmc and nand write
are executed
when both configs are enabled, and I'm not sure if that's the intended
behavior.

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP
  2018-05-08  6:08       ` Joe Hershberger
@ 2018-05-08  6:54         ` Alex Kiernan
  0 siblings, 0 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-05-08  6:54 UTC (permalink / raw)
  To: u-boot

On Tue, May 8, 2018 at 7:09 AM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, May 7, 2018 at 4:59 PM, Jocelyn Bohr <bohr@google.com> wrote:
> > Optional nit: Consider renaming "fastbootcmd" to "fb_bootcmd" or
similar.
> > IMO "fastbootcmd" is
> > ambiguous as there can be multiple env variable commands related to
> > fastboot.

> Seems like a good suggestion to me.


Yes. I'll pick it up in v3.

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 18/20] fastboot: Check if part_name is NULL before using it
  2018-05-03 21:26   ` Joe Hershberger
@ 2018-05-08  6:55     ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-08  6:55 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 2:26 PM Joe Hershberger <joe.hershberger@gmail.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > If we don't have a partition name passed, report it as not found.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 19/20] fastboot: Add missing newlines
  2018-05-03 21:26   ` Joe Hershberger
@ 2018-05-08  6:56     ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-08  6:56 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 2:27 PM Joe Hershberger <joe.hershberger@gmail.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > Add newlines so we format our output correctly.
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support
  2018-05-02  8:14   ` Alex Kiernan
@ 2018-05-08  7:13     ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-08  7:13 UTC (permalink / raw)
  To: u-boot

On Wed, May 2, 2018 at 1:14 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

> On Wed, May 2, 2018 at 7:34 AM Jocelyn Bohr <bohr@google.com> wrote:
>
> > Hi Alex,
>
> > I think this approach looks really good so far, and will make maintaining
> both
> > implementations easier going forward. I haven't looked at every change
> here
> > yet, but when going through the patches should I add a "Reviewed-by:"
> line if
> > the change looks good to me?
>
>
> Yes please!
>

Great, I believe I have reviewed most of the relevant patchsets so far. I
am planning to continue reviewing on the next set of patches, since it
sounds like there will be several changes.


> > Thanks,
> > Jocelyn
>
> > On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
>
>
> >> This series merges the fastboot UDP support from AOSP into mainline
> >> U-Boot.
>
> >> The underlying implementations of most commands are now merged between
> >> both code paths ('oem format' from the USB side is the only one
> remaining).
>
> >> Other changes to command handling so that UDP follows the existing USB
> >> behaviour:
>
> >> - 'boot' now follows the USB code and does 'fastboot
> CONFIG_FASTBOOT_BUF_ADDR'.
> >>    I've added 'fastbootcmd' which if set overrides the boot command and
> >>    allows the existing UDP behaviour to be preserved.
>
>
> > The UDP behavior more correct based on the specification.
> > "The previously downloaded data is a boot.img and should be booted
> according to
> > the normal procedure for a boot.img."
>
> > https://android.googlesource.com/platform/system/core/+/master/fastboot/
>
> > I'm not sure who we will break if we change the USB code...
>
> Making sure we don't break (or at least trying my hardest to) existing
> upstream code was my aim in this. If the right thing is to change it, then
> do that when the android bootflow gets merged?


> > also we probably
> > want to make sure image verification happens with "fastboot boot", making
> sure
> > "fastboot boot" doesn't allow booting an unverified kernel on locked
> devices. I
> > think we can add that flow later though, upstream U-boot doesn't support
> > lock/unlock commands anyway.
>
>
> I think running a general command here (via 'fastbootcmd') should give
> enough options to implement that policy. For my use case fastboot is
> actually just a convenient technology and I don't need the Android image
> format or bootflow... so I'm getting my signature verification out of a
> signed FIT image, and use something like:
>
> fastbootcmd='setenv verify yes; bootm 0x81000800#conf at 0'
>

SGTM, I like this approach too beacuse it doesn't break upstream code.
Thanks for providing the additional context of your use case! I was
assuming you were booting Android...that explains some other questions I
had, like why reboot-bootloader was made optional.


>
> >> - 'continue' in UDP now exits the fastboot server rather than executing
> >>    'run bootcmd'
> >> - 'reboot-bootloader' no longer writes 'reboot-bootloader' to
> >>    CONFIG_FASTBOOT_BUF_ADDR as its marker for the subsequent boot. The
> code
> >>    which is in AOSP common/android_bootloader.c expects this marker, but
> >>    we have prior art in the USB code using the weak function
> >>    fb_set_reboot_flag
> >> - 'getvar' in the UDP path now supports fetching 'fastboot.' prefixed
> >>    variables (inherited from the USB path)
> >> - 'getvar' in the USB path inherits all the variables from the UDP path
>
> >> Remaining issues:
>
> >> - whilst I've merged NAND support into the UDP code path, I've no way
> >>    of testing it. My expectation is it'll work, but will need
> timed_send_info
> >>    working into the NAND path to avoid timeouts on the network side.
>
>
> > I don't know of any devices that use NAND and the fastboot UDP code, so
> > I'm inclined to say this is okay.
>
>
> I think so... it's not broken today because there's no UDP and NAND code in
> upstream, if someone needs that then the mechanics are all there to wire it
> in (and I've no way of testing it).
>
> >> - I still need to fix timed_send_info handling when going through the
> USB
> >>    path.
> >> - the protocol part of the fastboot UDP implementation is separated out
> >>    and would I expect form the basis of a consolidated implementation,
> but
> >>    I'm inclined to address that as a clearly separate patch so it can be
> >>    tested in isolation (I have no USB hardware I can try this on).
>
>
> > Should this set of patches be tested on USB hardware too? There are some
> > changes here to the USB implementation.
>
>
> My aim thus far was to keep them sufficiently minimal that you get decide
> on correctness by inspection, which isn't to say I've actually got it
> right, but I'm hopeful. That said you can't beat a real test!
>
> --
> Alex Kiernan
>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support
  2018-05-08  6:53   ` Jocelyn Bohr
@ 2018-05-08  7:19     ` Joe Hershberger
  2018-05-08  9:09       ` Alex Kiernan
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-08  7:19 UTC (permalink / raw)
  To: u-boot

On Tue, May 8, 2018 at 1:53 AM, Jocelyn Bohr <bohr@verily.com> wrote:
> On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:
>
>> Add NAND support to fastboot UDP flash/erase commands
>>
>> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>> ---
>>
>> Changes in v2: None
>>
>>  net/fastboot.c | 17 ++++++++++++++---
>>  1 file changed, 14 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/fastboot.c b/net/fastboot.c
>> index 119011c..a07b1ad 100644
>> --- a/net/fastboot.c
>> +++ b/net/fastboot.c
>> @@ -60,7 +60,7 @@ static int fastboot_our_port;
>>  static void cb_okay(char *, char *, unsigned int, char *);
>>  static void cb_getvar(char *, char *, unsigned int, char *);
>>  static void cb_download(char *, char *, unsigned int, char *);
>> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
>> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
>>  static void cb_flash(char *, char *, unsigned int, char *);
>>  static void cb_erase(char *, char *, unsigned int, char *);
>>  #endif
>> @@ -74,7 +74,7 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
>>         [FB_CMD_GETVAR] = cb_getvar,
>>         [FB_CMD_DOWNLOAD] = cb_download,
>>         [FB_CMD_VERIFY] = NULL,
>> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
>> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
>>         [FB_CMD_FLASH] = cb_flash,
>>         [FB_CMD_ERASE] = cb_erase,
>>  #else
>> @@ -324,7 +324,7 @@ static void cb_download(char *cmd_parameter, char
>> *fastboot_data,
>>         }
>>  }
>>
>> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
>> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
>>  /**
>>   * Writes the previously downloaded image to the partition indicated by
>>   * cmd_parameter. Writes to response.
>> @@ -334,8 +334,14 @@ static void cb_download(char *cmd_parameter, char
>> *fastboot_data,
>>  static void cb_flash(char *cmd_parameter, char *fastboot_data,
>>                      unsigned int fastboot_data_len, char *response)
>>  {
>> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
>>         fb_mmc_flash_write(cmd_parameter, (void *)CONFIG_FASTBOOT_BUF_ADDR,
>>                            image_size, response);
>> +#endif
>> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
>> +       fb_nand_flash_write(cmd_parameter, (void
>> *)CONFIG_FASTBOOT_BUF_ADDR,
>> +                           image_size, response);
>> +#endif
>>
>
> Is there a way to make FASTBOOT_FLASH_MMC and FASTBOOT_FLASH_NAND
> mutually exclusive? Currently here and elsewhere, both mmc and nand write
> are executed
> when both configs are enabled, and I'm not sure if that's the intended
> behavior.

I thought in Kconfig those two configs are a "choice" so only one can
be enabled at a time.

> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support
  2018-05-08  7:19     ` Joe Hershberger
@ 2018-05-08  9:09       ` Alex Kiernan
  2018-05-08 16:37         ` Jocelyn Bohr
  0 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-05-08  9:09 UTC (permalink / raw)
  To: u-boot

On Tue, May 8, 2018 at 8:20 AM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Tue, May 8, 2018 at 1:53 AM, Jocelyn Bohr <bohr@verily.com> wrote:
> > On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
wrote:
> >
> >> Add NAND support to fastboot UDP flash/erase commands
> >>
> >> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> >> ---
> >>
> >> Changes in v2: None
> >>
> >>  net/fastboot.c | 17 ++++++++++++++---
> >>  1 file changed, 14 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/net/fastboot.c b/net/fastboot.c
> >> index 119011c..a07b1ad 100644
> >> --- a/net/fastboot.c
> >> +++ b/net/fastboot.c
> >> @@ -60,7 +60,7 @@ static int fastboot_our_port;
> >>  static void cb_okay(char *, char *, unsigned int, char *);
> >>  static void cb_getvar(char *, char *, unsigned int, char *);
> >>  static void cb_download(char *, char *, unsigned int, char *);
> >> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
> >>  static void cb_flash(char *, char *, unsigned int, char *);
> >>  static void cb_erase(char *, char *, unsigned int, char *);
> >>  #endif
> >> @@ -74,7 +74,7 @@ static void (*fb_net_dispatch[])(char *cmd_parameter,
> >>         [FB_CMD_GETVAR] = cb_getvar,
> >>         [FB_CMD_DOWNLOAD] = cb_download,
> >>         [FB_CMD_VERIFY] = NULL,
> >> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
> >>         [FB_CMD_FLASH] = cb_flash,
> >>         [FB_CMD_ERASE] = cb_erase,
> >>  #else
> >> @@ -324,7 +324,7 @@ static void cb_download(char *cmd_parameter, char
> >> *fastboot_data,
> >>         }
> >>  }
> >>
> >> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
> >>  /**
> >>   * Writes the previously downloaded image to the partition indicated
by
> >>   * cmd_parameter. Writes to response.
> >> @@ -334,8 +334,14 @@ static void cb_download(char *cmd_parameter, char
> >> *fastboot_data,
> >>  static void cb_flash(char *cmd_parameter, char *fastboot_data,
> >>                      unsigned int fastboot_data_len, char *response)
> >>  {
> >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> >>         fb_mmc_flash_write(cmd_parameter, (void
*)CONFIG_FASTBOOT_BUF_ADDR,
> >>                            image_size, response);
> >> +#endif
> >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
> >> +       fb_nand_flash_write(cmd_parameter, (void
> >> *)CONFIG_FASTBOOT_BUF_ADDR,
> >> +                           image_size, response);
> >> +#endif
> >>
> >
> > Is there a way to make FASTBOOT_FLASH_MMC and FASTBOOT_FLASH_NAND
> > mutually exclusive? Currently here and elsewhere, both mmc and nand
write
> > are executed
> > when both configs are enabled, and I'm not sure if that's the intended
> > behavior.

> I thought in Kconfig those two configs are a "choice" so only one can
> be enabled at a time.

They are.

--
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot
  2018-05-03 20:38   ` Joe Hershberger
@ 2018-05-08  9:11     ` Alex Kiernan
  2018-05-08 15:24       ` Joe Hershberger
  0 siblings, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-05-08  9:11 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 9:39 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
wrote:

<snip>

> > +/**
> > + * Constructs and sends a packet in response to received fastboot
packet
> > + *
> > + * @param fb_header            Header for response packet
> > + * @param fastboot_data        Pointer to received fastboot data
> > + * @param fastboot_data_len    Length of received fastboot data
> > + * @param retransmit           Nonzero if sending last sent packet
> > + */
> > +static void fastboot_send(struct fastboot_header fb_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 fb_response_header = fb_header;
> > +       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;
> > +       }
> > +
> > +       fb_response_header.seq = htons(fb_response_header.seq);
> > +       memcpy(packet, &fb_response_header, sizeof(fb_response_header));
> > +       packet += sizeof(fb_response_header);
> > +
> > +       switch (fb_header.id) {
> > +       case FASTBOOT_QUERY:
> > +               tmp = htons(fb_sequence_number);
> > +               memcpy(packet, &tmp, sizeof(tmp));
> > +               packet += sizeof(tmp);
> > +               break;
> > +       case FASTBOOT_INIT:
> > +               tmp = htons(fb_udp_version);
> > +               memcpy(packet, &tmp, sizeof(tmp));
> > +               packet += sizeof(tmp);
> > +               tmp = htons(fb_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_string) {
> > +                       /* Parse command and send ack */
> > +                       cmd_parameter = fastboot_data;

> This seems unnecessary. There are only 4 cases handled, and of them
> only download seems to be a command that happens more than once. And
> in download, the first past through this parameter is saved internally
> as bytes_expected.

> > +                       cmd_string = strsep(&cmd_parameter, ":");
> > +                       cmd_string = strdup(cmd_string);
> > +                       if (cmd_parameter)
> > +                               cmd_parameter = strdup(cmd_parameter);
> > +               } else if (!strcmp("getvar", cmd_string)) {
> > +                       fb_getvar(response);

> Seems like you should simply pass the "fastboot_data" as a parameter
> here rather than using a global.

I'm completely pulling this apart in a later patch. I wonder if I should
really be folding some of these back into this - I was trying to maintain a
clear line to the AOSP code which this came from.

> > +/**
> > + * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
> > + * Writes to response.
> > + *
> > + * @param fastboot_data        Pointer to received fastboot data
> > + * @param fastboot_data_len    Length of received fastboot data
> > + * @param repsonse             Pointer to fastboot response buffer
> > + */
> > +static void fb_download(char *fastboot_data, unsigned int
fastboot_data_len,
> > +                       char *response)
> > +{
> > +       char *tmp;
> > +
> > +       if (bytes_expected == 0) {
> > +               if (!cmd_parameter) {
> > +                       write_fb_response("FAIL", "Expected command
parameter",
> > +                                         response);
> > +                       return;
> > +               }
> > +               bytes_expected = simple_strtoul(cmd_parameter, &tmp,
16);
> > +               if (bytes_expected == 0) {
> > +                       write_fb_response("FAIL", "Expected nonzero
image size",
> > +                                         response);
> > +                       return;
> > +               }
> > +       }
> > +       if (fastboot_data_len == 0 && bytes_received == 0) {
> > +               /* Nothing to download yet. Response is of the form:
> > +                * [DATA|FAIL]$cmd_parameter
> > +                *
> > +                * where cmd_parameter is an 8 digit hexadecimal number
> > +                */
> > +               if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
> > +                       write_fb_response("FAIL", cmd_parameter,
response);
> > +               else
> > +                       write_fb_response("DATA", cmd_parameter,
response);
> > +       } else if (fastboot_data_len == 0 &&
> > +                  (bytes_received >= bytes_expected)) {
> > +               /* Download complete. Respond with "OKAY" */
> > +               write_fb_response("OKAY", "", response);
> > +               image_size = bytes_received;
> > +               bytes_expected = 0;
> > +               bytes_received = 0;
> > +       } else {
> > +               if (fastboot_data_len == 0 ||
> > +                   (bytes_received + fastboot_data_len) >
bytes_expected) {
> > +                       write_fb_response("FAIL",
> > +                                         "Received invalid data
length",
> > +                                         response);
> > +                       return;
> > +               }
> > +               /* Download data to CONFIG_FASTBOOT_BUF_ADDR */
> > +               memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR +
bytes_received,
> > +                      fastboot_data, fastboot_data_len);

> This is different than all the other approaches, which take the load
> address as a command parameter. Is there a good reason to have it
> baked in like this?

Feels odd to me too, but this is just following the USB code. I'm thinking
we should change the command so it's:

fastboot ... [<load-address> [<size>]]

And then default to the current values is they're not overridden?

> > +               bytes_received += fastboot_data_len;
> > +       }
> > +}
> > +
> > +/**
> > + * Writes the previously downloaded image to the partition indicated by
> > + * cmd_parameter. Writes to response.
> > + *
> > + * @param repsonse    Pointer to fastboot response buffer
> > + */
> > +static void fb_flash(char *response)
> > +{
> > +       fb_mmc_flash_write(cmd_parameter, (void
*)CONFIG_FASTBOOT_BUF_ADDR,
> > +                          image_size, response);

> It's peculiar that this hard-codes mmc.

Fixed up in a later patch.

> > +/**
> > + * Boots into downloaded image.
> > + */
> > +static void boot_downloaded_image(void)
> > +{
> > +       char kernel_addr[12];
> > +       char *fdt_addr = env_get("fdt_addr_r");
> > +       char *const bootm_args[] = {
> > +               "bootm", kernel_addr, "-", fdt_addr, NULL
> > +       };

> It seems like this should be able to affected from the host side...
> for instance choosing a config in an ITB.

> How is the fdt supposed to be populated in the scenario at all?

I strip this bit out in a later patch and replace it with either a simple
bootm (which follows the USB code), or run fastbootcmd.

Again, this is part of trying to land this patch as close as possible to
the code which comes from AOSP.

--
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot
  2018-05-03 20:58   ` Joe Hershberger
  2018-05-04  6:18     ` Jocelyn Bohr
@ 2018-05-08  9:20     ` Alex Kiernan
  2018-05-08 15:32       ` Joe Hershberger
  1 sibling, 1 reply; 74+ messages in thread
From: Alex Kiernan @ 2018-05-08  9:20 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 9:58 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
wrote:
> > Change the behaviour of 'continue' so that we simply exit the fastboot
> > server and leave the caller to decide what to do next. This matches
> > the USB fastboot behaviour.

> Good, I was considering recommending this approach.

> Acked-by: Joe Hershberger <joe.hershberger@ni.com>

> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> > ---
> >
> > Changes in v2: None
> >
> >  net/fastboot.c | 13 +++----------
> >  1 file changed, 3 insertions(+), 10 deletions(-)
> >
> > diff --git a/net/fastboot.c b/net/fastboot.c
> > index cd09ada..ed13890 100644
> > --- a/net/fastboot.c
> > +++ b/net/fastboot.c
> > @@ -218,8 +218,6 @@ static void fastboot_send(struct fastboot_header
fb_header, char *fastboot_data,
> >         if (!strncmp("OKAY", response, 4)) {
> >                 if (!strcmp("boot", cmd_string)) {
> >                         boot_downloaded_image();
> > -               } else if (!strcmp("continue", cmd_string)) {
> > -                       run_command(env_get("bootcmd"), CMD_FLAG_ENV);
> >                 } else if (!strncmp("reboot", cmd_string, 6)) {
> >                         /* Matches reboot or reboot-bootloader */
> >                         do_reset(NULL, 0, 0, NULL);
> > @@ -313,20 +311,15 @@ static void fb_erase(char *response)
> >  #endif
> >
> >  /**
> > - * Continues normal boot process by running "bootcmd". Writes
> > + * Continues normal boot process by exiting fastboot server. Writes
> >   * to response.
> >   *
> >   * @param repsonse    Pointer to fastboot response buffer
> >   */
> >  static void fb_continue(char *response)
> >  {
> > -       char *bootcmd;
> > -
> > -       bootcmd = env_get("bootcmd");
> > -       if (bootcmd)
> > -               fastboot_okay(NULL, response);
> > -       else
> > -               fastboot_fail("bootcmd not set", response);
> > +       net_set_state(NETLOOP_SUCCESS);
> > +       fastboot_okay(NULL, response);
> >  }
> >

I'm struggling with this returning the final ACK to the client correctly.
If I add something like mdelay(5) before exiting the server, then I get the
final ACK, without that, I never see it hit the network, even though I can
see it traversing all the layers of the net code if I wind up the debug
(and of course it makes it out if I wind up the debug, presumably as it
then goes much slower).

Wild hand wavey speculation... it's getting lost in something like a DMA
buffer in the network driver which gets torn down before it makes it onto
the wire? This is using the TI CPSW on an am335x.

-- 
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot
  2018-05-08  9:11     ` Alex Kiernan
@ 2018-05-08 15:24       ` Joe Hershberger
  2018-05-08 15:51         ` Alex Kiernan
  0 siblings, 1 reply; 74+ messages in thread
From: Joe Hershberger @ 2018-05-08 15:24 UTC (permalink / raw)
  To: u-boot

On Tue, May 8, 2018 at 4:11 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> On Thu, May 3, 2018 at 9:39 PM Joe Hershberger <joe.hershberger@ni.com>
> wrote:
>
>> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
>
> <snip>
>
>> > +/**
>> > + * Constructs and sends a packet in response to received fastboot
> packet
>> > + *
>> > + * @param fb_header            Header for response packet
>> > + * @param fastboot_data        Pointer to received fastboot data
>> > + * @param fastboot_data_len    Length of received fastboot data
>> > + * @param retransmit           Nonzero if sending last sent packet
>> > + */
>> > +static void fastboot_send(struct fastboot_header fb_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 fb_response_header = fb_header;
>> > +       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;
>> > +       }
>> > +
>> > +       fb_response_header.seq = htons(fb_response_header.seq);
>> > +       memcpy(packet, &fb_response_header, sizeof(fb_response_header));
>> > +       packet += sizeof(fb_response_header);
>> > +
>> > +       switch (fb_header.id) {
>> > +       case FASTBOOT_QUERY:
>> > +               tmp = htons(fb_sequence_number);
>> > +               memcpy(packet, &tmp, sizeof(tmp));
>> > +               packet += sizeof(tmp);
>> > +               break;
>> > +       case FASTBOOT_INIT:
>> > +               tmp = htons(fb_udp_version);
>> > +               memcpy(packet, &tmp, sizeof(tmp));
>> > +               packet += sizeof(tmp);
>> > +               tmp = htons(fb_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_string) {
>> > +                       /* Parse command and send ack */
>> > +                       cmd_parameter = fastboot_data;
>
>> This seems unnecessary. There are only 4 cases handled, and of them
>> only download seems to be a command that happens more than once. And
>> in download, the first past through this parameter is saved internally
>> as bytes_expected.
>
>> > +                       cmd_string = strsep(&cmd_parameter, ":");
>> > +                       cmd_string = strdup(cmd_string);
>> > +                       if (cmd_parameter)
>> > +                               cmd_parameter = strdup(cmd_parameter);
>> > +               } else if (!strcmp("getvar", cmd_string)) {
>> > +                       fb_getvar(response);
>
>> Seems like you should simply pass the "fastboot_data" as a parameter
>> here rather than using a global.
>
> I'm completely pulling this apart in a later patch. I wonder if I should
> really be folding some of these back into this - I was trying to maintain a
> clear line to the AOSP code which this came from.

What value do we get from that? Is there a merge technique you are
trying to enable to make pulling in future AOSP changes easier? Are
you trying to isolate your changes from AOSP for attribution purposes?
So far I'm of the opinion that the fixes to the existing code should
simply be there in the originating patch. Feel free to convince me
otherwise.

>> > +/**
>> > + * Copies image data from fastboot_data to CONFIG_FASTBOOT_BUF_ADDR.
>> > + * Writes to response.
>> > + *
>> > + * @param fastboot_data        Pointer to received fastboot data
>> > + * @param fastboot_data_len    Length of received fastboot data
>> > + * @param repsonse             Pointer to fastboot response buffer
>> > + */
>> > +static void fb_download(char *fastboot_data, unsigned int
> fastboot_data_len,
>> > +                       char *response)
>> > +{
>> > +       char *tmp;
>> > +
>> > +       if (bytes_expected == 0) {
>> > +               if (!cmd_parameter) {
>> > +                       write_fb_response("FAIL", "Expected command
> parameter",
>> > +                                         response);
>> > +                       return;
>> > +               }
>> > +               bytes_expected = simple_strtoul(cmd_parameter, &tmp,
> 16);
>> > +               if (bytes_expected == 0) {
>> > +                       write_fb_response("FAIL", "Expected nonzero
> image size",
>> > +                                         response);
>> > +                       return;
>> > +               }
>> > +       }
>> > +       if (fastboot_data_len == 0 && bytes_received == 0) {
>> > +               /* Nothing to download yet. Response is of the form:
>> > +                * [DATA|FAIL]$cmd_parameter
>> > +                *
>> > +                * where cmd_parameter is an 8 digit hexadecimal number
>> > +                */
>> > +               if (bytes_expected > CONFIG_FASTBOOT_BUF_SIZE)
>> > +                       write_fb_response("FAIL", cmd_parameter,
> response);
>> > +               else
>> > +                       write_fb_response("DATA", cmd_parameter,
> response);
>> > +       } else if (fastboot_data_len == 0 &&
>> > +                  (bytes_received >= bytes_expected)) {
>> > +               /* Download complete. Respond with "OKAY" */
>> > +               write_fb_response("OKAY", "", response);
>> > +               image_size = bytes_received;
>> > +               bytes_expected = 0;
>> > +               bytes_received = 0;
>> > +       } else {
>> > +               if (fastboot_data_len == 0 ||
>> > +                   (bytes_received + fastboot_data_len) >
> bytes_expected) {
>> > +                       write_fb_response("FAIL",
>> > +                                         "Received invalid data
> length",
>> > +                                         response);
>> > +                       return;
>> > +               }
>> > +               /* Download data to CONFIG_FASTBOOT_BUF_ADDR */
>> > +               memcpy((void *)CONFIG_FASTBOOT_BUF_ADDR +
> bytes_received,
>> > +                      fastboot_data, fastboot_data_len);
>
>> This is different than all the other approaches, which take the load
>> address as a command parameter. Is there a good reason to have it
>> baked in like this?
>
> Feels odd to me too, but this is just following the USB code. I'm thinking
> we should change the command so it's:
>
> fastboot ... [<load-address> [<size>]]
>
> And then default to the current values is they're not overridden?
>
>> > +               bytes_received += fastboot_data_len;
>> > +       }
>> > +}
>> > +
>> > +/**
>> > + * Writes the previously downloaded image to the partition indicated by
>> > + * cmd_parameter. Writes to response.
>> > + *
>> > + * @param repsonse    Pointer to fastboot response buffer
>> > + */
>> > +static void fb_flash(char *response)
>> > +{
>> > +       fb_mmc_flash_write(cmd_parameter, (void
> *)CONFIG_FASTBOOT_BUF_ADDR,
>> > +                          image_size, response);
>
>> It's peculiar that this hard-codes mmc.
>
> Fixed up in a later patch.
>
>> > +/**
>> > + * Boots into downloaded image.
>> > + */
>> > +static void boot_downloaded_image(void)
>> > +{
>> > +       char kernel_addr[12];
>> > +       char *fdt_addr = env_get("fdt_addr_r");
>> > +       char *const bootm_args[] = {
>> > +               "bootm", kernel_addr, "-", fdt_addr, NULL
>> > +       };
>
>> It seems like this should be able to affected from the host side...
>> for instance choosing a config in an ITB.
>
>> How is the fdt supposed to be populated in the scenario at all?
>
> I strip this bit out in a later patch and replace it with either a simple
> bootm (which follows the USB code), or run fastbootcmd.
>
> Again, this is part of trying to land this patch as close as possible to
> the code which comes from AOSP.
>
> --
> Alex Kiernan
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot
  2018-05-08  9:20     ` Alex Kiernan
@ 2018-05-08 15:32       ` Joe Hershberger
  0 siblings, 0 replies; 74+ messages in thread
From: Joe Hershberger @ 2018-05-08 15:32 UTC (permalink / raw)
  To: u-boot

On Tue, May 8, 2018 at 4:20 AM, Alex Kiernan <alex.kiernan@gmail.com> wrote:
> On Thu, May 3, 2018 at 9:58 PM Joe Hershberger <joe.hershberger@ni.com>
> wrote:
>
>> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
>> > Change the behaviour of 'continue' so that we simply exit the fastboot
>> > server and leave the caller to decide what to do next. This matches
>> > the USB fastboot behaviour.
>
>> Good, I was considering recommending this approach.
>
>> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>
>> >
>> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>> > ---
>> >
>> > Changes in v2: None
>> >
>> >  net/fastboot.c | 13 +++----------
>> >  1 file changed, 3 insertions(+), 10 deletions(-)
>> >
>> > diff --git a/net/fastboot.c b/net/fastboot.c
>> > index cd09ada..ed13890 100644
>> > --- a/net/fastboot.c
>> > +++ b/net/fastboot.c
>> > @@ -218,8 +218,6 @@ static void fastboot_send(struct fastboot_header
> fb_header, char *fastboot_data,
>> >         if (!strncmp("OKAY", response, 4)) {
>> >                 if (!strcmp("boot", cmd_string)) {
>> >                         boot_downloaded_image();
>> > -               } else if (!strcmp("continue", cmd_string)) {
>> > -                       run_command(env_get("bootcmd"), CMD_FLAG_ENV);
>> >                 } else if (!strncmp("reboot", cmd_string, 6)) {
>> >                         /* Matches reboot or reboot-bootloader */
>> >                         do_reset(NULL, 0, 0, NULL);
>> > @@ -313,20 +311,15 @@ static void fb_erase(char *response)
>> >  #endif
>> >
>> >  /**
>> > - * Continues normal boot process by running "bootcmd". Writes
>> > + * Continues normal boot process by exiting fastboot server. Writes
>> >   * to response.
>> >   *
>> >   * @param repsonse    Pointer to fastboot response buffer
>> >   */
>> >  static void fb_continue(char *response)
>> >  {
>> > -       char *bootcmd;
>> > -
>> > -       bootcmd = env_get("bootcmd");
>> > -       if (bootcmd)
>> > -               fastboot_okay(NULL, response);
>> > -       else
>> > -               fastboot_fail("bootcmd not set", response);
>> > +       net_set_state(NETLOOP_SUCCESS);
>> > +       fastboot_okay(NULL, response);
>> >  }
>> >
>
> I'm struggling with this returning the final ACK to the client correctly.
> If I add something like mdelay(5) before exiting the server, then I get the
> final ACK, without that, I never see it hit the network, even though I can
> see it traversing all the layers of the net code if I wind up the debug
> (and of course it makes it out if I wind up the debug, presumably as it
> then goes much slower).
>
> Wild hand wavey speculation... it's getting lost in something like a DMA
> buffer in the network driver which gets torn down before it makes it onto
> the wire? This is using the TI CPSW on an am335x.

Sounds like a reasonable theory.

The eth driver for that board probably needs to check for the TX
channel to be in a quiescent state in the davinci_eth_close() function
before tearing it down.

-Joe

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot
  2018-05-08 15:24       ` Joe Hershberger
@ 2018-05-08 15:51         ` Alex Kiernan
  0 siblings, 0 replies; 74+ messages in thread
From: Alex Kiernan @ 2018-05-08 15:51 UTC (permalink / raw)
  To: u-boot

On Tue, May 8, 2018 at 4:24 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Tue, May 8, 2018 at 4:11 AM, Alex Kiernan <alex.kiernan@gmail.com>
wrote:
> > On Thu, May 3, 2018 at 9:39 PM Joe Hershberger <joe.hershberger@ni.com>
> > wrote:
> >
> >> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> > wrote:
> >
> > <snip>
> >
> >> > +/**
> >> > + * Constructs and sends a packet in response to received fastboot
> > packet
> >> > + *
> >> > + * @param fb_header            Header for response packet
> >> > + * @param fastboot_data        Pointer to received fastboot data
> >> > + * @param fastboot_data_len    Length of received fastboot data
> >> > + * @param retransmit           Nonzero if sending last sent packet
> >> > + */
> >> > +static void fastboot_send(struct fastboot_header fb_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 fb_response_header = fb_header;
> >> > +       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;
> >> > +       }
> >> > +
> >> > +       fb_response_header.seq = htons(fb_response_header.seq);
> >> > +       memcpy(packet, &fb_response_header,
sizeof(fb_response_header));
> >> > +       packet += sizeof(fb_response_header);
> >> > +
> >> > +       switch (fb_header.id) {
> >> > +       case FASTBOOT_QUERY:
> >> > +               tmp = htons(fb_sequence_number);
> >> > +               memcpy(packet, &tmp, sizeof(tmp));
> >> > +               packet += sizeof(tmp);
> >> > +               break;
> >> > +       case FASTBOOT_INIT:
> >> > +               tmp = htons(fb_udp_version);
> >> > +               memcpy(packet, &tmp, sizeof(tmp));
> >> > +               packet += sizeof(tmp);
> >> > +               tmp = htons(fb_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_string) {
> >> > +                       /* Parse command and send ack */
> >> > +                       cmd_parameter = fastboot_data;
> >
> >> This seems unnecessary. There are only 4 cases handled, and of them
> >> only download seems to be a command that happens more than once. And
> >> in download, the first past through this parameter is saved internally
> >> as bytes_expected.
> >
> >> > +                       cmd_string = strsep(&cmd_parameter, ":");
> >> > +                       cmd_string = strdup(cmd_string);
> >> > +                       if (cmd_parameter)
> >> > +                               cmd_parameter =
strdup(cmd_parameter);
> >> > +               } else if (!strcmp("getvar", cmd_string)) {
> >> > +                       fb_getvar(response);
> >
> >> Seems like you should simply pass the "fastboot_data" as a parameter
> >> here rather than using a global.
> >
> > I'm completely pulling this apart in a later patch. I wonder if I should
> > really be folding some of these back into this - I was trying to
maintain a
> > clear line to the AOSP code which this came from.

> What value do we get from that? Is there a merge technique you are
> trying to enable to make pulling in future AOSP changes easier? Are
> you trying to isolate your changes from AOSP for attribution purposes?

I was trying to maintain the attribution line, but given the level of
change I'm struggling to achieve that in what's an increasingly complex
chain of patches which end up interacting too much.

Given Alex and Jocelyn are engaged, I'm not sure I see the value in
continuing trying to do this.

> So far I'm of the opinion that the fixes to the existing code should
> simply be there in the originating patch. Feel free to convince me
> otherwise.

I'll fail to convince you as I'm increasingly unconvinced myself... I'm
spending more time rebasing patches than actually separating the code into
something which can handle both UDP and USB transports.

--
Alex Kiernan

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support
  2018-05-08  9:09       ` Alex Kiernan
@ 2018-05-08 16:37         ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-08 16:37 UTC (permalink / raw)
  To: u-boot

On Tue, May 8, 2018 at 2:09 AM Alex Kiernan <alex.kiernan@gmail.com> wrote:

> On Tue, May 8, 2018 at 8:20 AM Joe Hershberger <joe.hershberger@ni.com>
> wrote:
>
> > On Tue, May 8, 2018 at 1:53 AM, Jocelyn Bohr <bohr@verily.com> wrote:
> > > On Mon, Apr 30, 2018 at 1:33 AM Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > >
> > >> Add NAND support to fastboot UDP flash/erase commands
> > >>
> > >> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
> > >> ---
> > >>
> > >> Changes in v2: None
> > >>
> > >>  net/fastboot.c | 17 ++++++++++++++---
> > >>  1 file changed, 14 insertions(+), 3 deletions(-)
> > >>
> > >> diff --git a/net/fastboot.c b/net/fastboot.c
> > >> index 119011c..a07b1ad 100644
> > >> --- a/net/fastboot.c
> > >> +++ b/net/fastboot.c
> > >> @@ -60,7 +60,7 @@ static int fastboot_our_port;
> > >>  static void cb_okay(char *, char *, unsigned int, char *);
> > >>  static void cb_getvar(char *, char *, unsigned int, char *);
> > >>  static void cb_download(char *, char *, unsigned int, char *);
> > >> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
> > >>  static void cb_flash(char *, char *, unsigned int, char *);
> > >>  static void cb_erase(char *, char *, unsigned int, char *);
> > >>  #endif
> > >> @@ -74,7 +74,7 @@ static void (*fb_net_dispatch[])(char
> *cmd_parameter,
> > >>         [FB_CMD_GETVAR] = cb_getvar,
> > >>         [FB_CMD_DOWNLOAD] = cb_download,
> > >>         [FB_CMD_VERIFY] = NULL,
> > >> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
> > >>         [FB_CMD_FLASH] = cb_flash,
> > >>         [FB_CMD_ERASE] = cb_erase,
> > >>  #else
> > >> @@ -324,7 +324,7 @@ static void cb_download(char *cmd_parameter, char
> > >> *fastboot_data,
> > >>         }
> > >>  }
> > >>
> > >> -#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH)
> > >>  /**
> > >>   * Writes the previously downloaded image to the partition indicated
> by
> > >>   * cmd_parameter. Writes to response.
> > >> @@ -334,8 +334,14 @@ static void cb_download(char *cmd_parameter, char
> > >> *fastboot_data,
> > >>  static void cb_flash(char *cmd_parameter, char *fastboot_data,
> > >>                      unsigned int fastboot_data_len, char *response)
> > >>  {
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_MMC)
> > >>         fb_mmc_flash_write(cmd_parameter, (void
> *)CONFIG_FASTBOOT_BUF_ADDR,
> > >>                            image_size, response);
> > >> +#endif
> > >> +#if CONFIG_IS_ENABLED(FASTBOOT_FLASH_NAND)
> > >> +       fb_nand_flash_write(cmd_parameter, (void
> > >> *)CONFIG_FASTBOOT_BUF_ADDR,
> > >> +                           image_size, response);
> > >> +#endif
> > >>
> > >
> > > Is there a way to make FASTBOOT_FLASH_MMC and FASTBOOT_FLASH_NAND
> > > mutually exclusive? Currently here and elsewhere, both mmc and nand
> write
> > > are executed
> > > when both configs are enabled, and I'm not sure if that's the intended
> > > behavior.
>
> > I thought in Kconfig those two configs are a "choice" so only one can
> > be enabled at a time.
>
> They are.
>

Oh great, sorry I'm not super familiar with Kconfig. LGTM then!

>
> --
> Alex Kiernan
>

^ permalink raw reply	[flat|nested] 74+ messages in thread

* [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support
  2018-05-03 21:24   ` Joe Hershberger
@ 2018-05-08 16:38     ` Jocelyn Bohr
  0 siblings, 0 replies; 74+ messages in thread
From: Jocelyn Bohr @ 2018-05-08 16:38 UTC (permalink / raw)
  To: u-boot

On Thu, May 3, 2018 at 2:24 PM Joe Hershberger <joe.hershberger@ni.com>
wrote:

> On Mon, Apr 30, 2018 at 3:32 AM, Alex Kiernan <alex.kiernan@gmail.com>
> wrote:
> > Add NAND support to fastboot UDP flash/erase commands
> >
> > Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Jocelyn Bohr <bohr@google.com>

^ permalink raw reply	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2018-05-08 16:38 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-30  8:32 [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Alex Kiernan
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 01/20] fastboot: Move fastboot to drivers/fastboot Alex Kiernan
2018-04-30 23:12   ` Simon Glass
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 02/20] fastboot: Switch dependencies on FASTBOOT to USB_FUNCTION_FASTBOOT Alex Kiernan
2018-05-03 18:19   ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 03/20] fastboot: Refactor fastboot_okay/fail to take response Alex Kiernan
2018-05-03 18:24   ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 04/20] fastboot: Extract fastboot_okay/fail to fb_common.c Alex Kiernan
2018-05-03 18:26   ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 05/20] fastboot: Introduce fastboot_response and refactor fastboot_okay/fail Alex Kiernan
2018-05-03 18:28   ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 06/20] fastboot: Correct dependencies in FASTBOOT_FLASH Alex Kiernan
2018-05-03 18:34   ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 07/20] net: fastboot: Merge AOSP UDP fastboot Alex Kiernan
2018-05-01  6:28   ` Jocelyn Bohr
2018-05-03 20:38   ` Joe Hershberger
2018-05-08  9:11     ` Alex Kiernan
2018-05-08 15:24       ` Joe Hershberger
2018-05-08 15:51         ` Alex Kiernan
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 08/20] net: fastboot: Support building without MMC Alex Kiernan
2018-05-03 20:39   ` Joe Hershberger
2018-05-04  6:06     ` Jocelyn Bohr
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 09/20] fastboot: Refactor write_fb_response into fastboot_okay/fail/response Alex Kiernan
2018-05-03 20:48   ` Joe Hershberger
2018-05-04  6:00     ` Jocelyn Bohr
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 10/20] fastboot: Merge USB and UDP getvar implementation Alex Kiernan
2018-05-03 20:56   ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 11/20] fastboot: net: Change 'continue' so it matches USB fastboot Alex Kiernan
2018-05-03 20:58   ` Joe Hershberger
2018-05-04  6:18     ` Jocelyn Bohr
2018-05-08  9:20     ` Alex Kiernan
2018-05-08 15:32       ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 12/20] fastboot: net: Convert command lookup to a table Alex Kiernan
2018-05-03 21:08   ` Joe Hershberger
2018-05-04  9:14     ` Alex Kiernan
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 13/20] fastboot: Merge reboot-bootloader handling Alex Kiernan
2018-05-01  6:49   ` Jocelyn Bohr
2018-05-01  7:23     ` Alex Kiernan
2018-05-01  8:21       ` Alex Kiernan
2018-05-02  5:46         ` Jocelyn Bohr
2018-05-02  5:51           ` Jocelyn Bohr
2018-05-02  8:24             ` Alex Kiernan
2018-05-03 21:15   ` Joe Hershberger
2018-05-04  7:34     ` Alex Kiernan
2018-05-04  7:44       ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 14/20] fastboot: Avoid re-parsing cmd_string for boot/reboot Alex Kiernan
2018-05-03 21:17   ` Joe Hershberger
2018-05-07 21:20     ` Jocelyn Bohr
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 15/20] fastboot: Merge boot common across USB and UDP Alex Kiernan
2018-05-03 21:21   ` Joe Hershberger
2018-05-07 21:59     ` Jocelyn Bohr
2018-05-08  6:08       ` Joe Hershberger
2018-05-08  6:54         ` Alex Kiernan
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 16/20] fastboot: net: Add NAND support Alex Kiernan
2018-05-03 21:24   ` Joe Hershberger
2018-05-08 16:38     ` Jocelyn Bohr
2018-05-08  6:53   ` Jocelyn Bohr
2018-05-08  7:19     ` Joe Hershberger
2018-05-08  9:09       ` Alex Kiernan
2018-05-08 16:37         ` Jocelyn Bohr
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 17/20] fastboot: Guard getvar:partition-type/size with MMC Alex Kiernan
2018-05-03 21:26   ` Joe Hershberger
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 18/20] fastboot: Check if part_name is NULL before using it Alex Kiernan
2018-05-03 21:26   ` Joe Hershberger
2018-05-08  6:55     ` Jocelyn Bohr
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 19/20] fastboot: Add missing newlines Alex Kiernan
2018-05-03 21:26   ` Joe Hershberger
2018-05-08  6:56     ` Jocelyn Bohr
2018-04-30  8:32 ` [U-Boot] [RFC PATCH v2 20/20] fastboot: net: Split fastboot protocol out from net Alex Kiernan
2018-05-03 21:29   ` Joe Hershberger
2018-05-04  6:05     ` Alex Kiernan
2018-05-02  6:33 ` [U-Boot] [RFC PATCH v2 00/20] Add fastboot UDP support Jocelyn Bohr
2018-05-02  8:14   ` Alex Kiernan
2018-05-08  7:13     ` Jocelyn Bohr

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.