introduce Rockchip rockusb
Subsystems (3)
v5 cover introduce Rockchip rockusb
rockusb is a protocol run between host pc and device. it help people get device info, flash image to device. this patch implement rockusb on device side
Changes in v5:
-fix build error when build other board
-fix checkpatch error
Changes in v4:
-use enum instead of macro define
-move some structure define and macro to f_rockusb.h -add some function comment as Simon required -address other comment from Simon
-fix build error as Lukasz point out
Changes in v3:
-switch back to use g_dnl code
-address comment from Lukasz and Simon
-fix checkpatch error
Changes in v2:
-switch to use usb masstorage framework
-add readme for rockusb
Eddie Cai (4):
usb: rockchip: add the rockusb gadget
usb: rockchip: add rockusb command
rockchip:usb: add a simple readme for rockusb
rockchip: rk3288: enable rockusb support on rk3288 based device
arch/arm/include/asm/arch-rockchip/f_rockusb.h | 123 +++++ cmd/Kconfig | 9 + cmd/Makefile | 1 + cmd/rockusb.c | 74 +++ doc/README.rockusb | 51 ++ drivers/usb/gadget/Kconfig | 8 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/f_rockusb.c | 680 +++++++++++++++++++++++++ include/configs/rk3288_common.h | 4 + 9 files changed, 951 insertions(+) create mode 100644 arch/arm/include/asm/arch-rockchip/f_rockusb.h create mode 100644 cmd/rockusb.c create mode 100644 doc/README.rockusb create mode 100644 drivers/usb/gadget/f_rockusb.c
Signature · 1 line
1.9.1
PATCH v5 1/4 usb: rockchip: add the rockusb gadget
this patch implement rockusb protocol on the device side. this is based on USB download gadget infrastructure. the rockusb function implements the rd, wl, rid commands. it can work with rkdeveloptool
Changes in v5:
-fix build error when build non-rockchip board
-fix checkpatch error
Changes in v4:
-use enum instead of macro define
-move some structure define and macro to f_rockusb.h -add some function comment as Simon required -address other comment from Simon
-fix build error as Lukasz point out
Changes in v3:
-split the macro to f_rockusb.h
-use ALLOC_CACHE_ALIGN_BUFFER to define cache safe struct inside the function. -fix checkpatch error
--- arch/arm/include/asm/arch-rockchip/f_rockusb.h | 123 +++++ drivers/usb/gadget/Kconfig | 8 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/f_rockusb.c | 680 +++++++++++++++++++++++++ 4 files changed, 812 insertions(+) create mode 100644 arch/arm/include/asm/arch-rockchip/f_rockusb.h create mode 100644 drivers/usb/gadget/f_rockusb.c
arch/arm/include/asm/arch-rockchip/f_rockusb.h new file +123 -0
@@ -0,0 +1,123 @@ +/* +* (C) Copyright 2017 +* +* Eddie Cai <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __F_ROCKUSB_H +#define __F_ROCKUSB_H +#define ROCKUSB_VERSION "0.1" + +#define ROCKUSB_INTERFACE_CLASS 0xff +#define ROCKUSB_INTERFACE_SUB_CLASS 0x06 +#define ROCKUSB_INTERFACE_PROTOCOL 0x05 + +#define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_2_0 (0x0200) +#define RX_ENDPOINT_MAXIMUM_PACKET_SIZE_1_1 (0x0040) +#define TX_ENDPOINT_MAXIMUM_PACKET_SIZE (0x0040) + +#define EP_BUFFER_SIZE 4096 +/* +* EP_BUFFER_SIZE must always be an integral multiple of maxpacket size +* (64 or 512 or 1024), else we break on certain controllers like DWC3 +* that expect bulk OUT requests to be divisible by maxpacket size. +*/ + +#define CONFIG_ROCKUSB_BUF_ADDR CONFIG_SYS_LOAD_ADDR +#define CONFIG_ROCKUSB_BUF_SIZE 0x08000000 + +#define RKUSB_STATUS_IDLE 0 +#define RKUSB_STATUS_CMD 1 +#define RKUSB_STATUS_RXDATA 2 +#define RKUSB_STATUS_TXDATA 3 +#define RKUSB_STATUS_CSW 4 +#define RKUSB_STATUS_RXDATA_PREPARE 5 +#define RKUSB_STATUS_TXDATA_PREPARE 6 + +enum rkusb_command { +K_FW_TEST_UNIT_READY =0x00 , +K_FW_READ_FLASH_ID =0x01 , +K_FW_SET_DEVICE_ID =0x02 , +K_FW_TEST_BAD_BLOCK =0x03 , +K_FW_READ_10 =0x04 , +K_FW_WRITE_10 =0x05 , +K_FW_ERASE_10 =0x06 , +K_FW_WRITE_SPARE =0x07 , +K_FW_READ_SPARE =0x08 , + +K_FW_ERASE_10_FORCE =0x0b , +K_FW_GET_VERSION =0x0c , + +K_FW_LBA_READ_10 =0x14 , +K_FW_LBA_WRITE_10 =0x15 , +K_FW_ERASE_SYS_DISK =0x16 , +K_FW_SDRAM_READ_10 =0x17 , +K_FW_SDRAM_WRITE_10 =0x18 , +K_FW_SDRAM_EXECUTE =0x19 , +K_FW_READ_FLASH_INFO =0x1A , +K_FW_GET_CHIP_VER =0x1B , +K_FW_LOW_FORMAT =0x1C , +K_FW_SET_RESET_FLAG =0x1E , +K_FW_SPI_READ_10 =0x21 , +K_FW_SPI_WRITE_10 =0x22 , + +K_FW_SESSION =0X30 , +K_FW_RESET =0xff , +}; + +#define CBW_DIRECTION_OUT 0x00 +#define CBW_DIRECTION_IN 0x80 + +struct cmd_dispatch_info { +enum rkusb_command cmd; +/* call back function to handle rockusb command */ +void (*cb)(struct usb_ep *ep,struct usb_request *req); +}; + +/* Bulk-only data structures */ + +/* Command Block Wrapper */ +struct fsg_bulk_cb_wrap { +__le32 signature;/* Contains 'USBC' */ +u32 tag;/* Unique per command id */ +__le32 data_transfer_length;/* Size of the data */ +u8 flags;/* Direction in bit 7 */ +u8 lun;/* lun (normally 0) */ +u8 length;/* Of the CDB, <= MAX_COMMAND_SIZE */ +u8 CDB[16 ];/* Command Data Block */ +}; + +#define USB_BULK_CB_WRAP_LEN 31 +#define USB_BULK_CB_SIG 0x43425355/* Spells out USBC */ +#define USB_BULK_IN_FLAG 0x80 + +/* Command status Wrapper */ +struct bulk_cs_wrap { +__le32 signature;/* Should = 'USBS' */ +u32 tag;/* Same as original command */ +__le32 residue;/* Amount not transferred */ +u8 status;/* See below */ +}; + +#define USB_BULK_CS_WRAP_LEN 13 +#define USB_BULK_CS_SIG 0x53425355/* Spells out 'USBS' */ +#define USB_STATUS_PASS 0 +#define USB_STATUS_FAIL 1 +#define USB_STATUS_PHASE_ERROR 2 + +#define CSW_GOOD 0x00 +#define CSW_FAIL 0x01 + +struct f_rockusb { +struct usb_function usb_function; +/* IN/OUT EP's and corresponding requests */ +struct usb_ep *in_ep, *out_ep; +struct usb_request *in_req, *out_req; +}; + +/* init rockusb device, tell rockusb which device you want to read/write*/ +void rockusb_dev_init (char *dev_type,int dev_index); +#endif /* __F_ROCKUSB_H */ +
drivers/usb/gadget/Kconfig +8 -0
@@ -112,6 +112,14 @@ config G_DNL_VENDOR_NUM config G_DNL_PRODUCT_NUM hex "Product ID of USB device" +config USB_FUNCTION_ROCKUSB + bool "Enable USB rockusb gadget" + help + Rockusb protocol is widely used by Rockchip SoC based devices. It can + read/write info, image to/from devices. This enables the USB part of + the rockusb gadget.for more detail about Rockusb protocol, please see + doc/README.rockusb + config USBNET_DEVADDR string "USB Gadget Ethernet device mac address" default "de:ad:be:ef:00:01"
drivers/usb/gadget/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o obj-$(CONFIG_USB_FUNCTION_DFU) += f_dfu.o obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o +obj-$(CONFIG_USB_FUNCTION_ROCKUSB) += f_rockusb.o endif endif ifdef CONFIG_USB_ETHER
drivers/usb/gadget/f_rockusb.c new file +680 -0
680 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v5 1/4 usb: rockchip: add the rockusb gadget
Quoted 20 lines · Eddie Cai
this patch implement rockusb protocol on the device side. this is based on USB download gadget infrastructure. the rockusb function implements the rd, wl, rid commands. it can work with rkdeveloptool
Signed-off-by Eddie Cai <[email protected]>Changes in v5:
(quoted diff) +0
-2-fix build error when build non-rockchip board -fix checkpatch errorChanges in v4:
(quoted diff) +0
-5-use enum instead of macro define -move some structure define and macro to f_rockusb.h -add some function comment as Simon required -address other comment from Simon -fix build error as Lukasz point outChanges in v3:
(quoted diff) +0
-2-split the macro to f_rockusb.h -use ALLOC_CACHE_ALIGN_BUFFER to define cache safe struct inside the function.
Review
Quoted 10 lines
(quoted diff) +0
-2-fix checkpatch error --- arch/arm/include/asm/arch-rockchip/f_rockusb.h | 123 +++++ drivers/usb/gadget/Kconfig | 8 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/f_rockusb.c | 680 +++++++++++++++++++++++++ 4 files changed, 812 insertions(+) create mode 100644 arch/arm/include/asm/arch-rockchip/f_rockusb.h create mode 100644 drivers/usb/gadget/f_rockusb.c
PATCH v5 2/4 usb: rockchip: add rockusb command
In reply to Eddie Caithis patch add rockusb command. the usage is rockusb <USB_controller> <devtype> <dev[:part]> e.g. rockusb 0 mmc 0
Changes in v5:
-none
Changes in v4:
-move USB_FUNCTION_ROCKUSB to drivers/usb/gadget/Kconfig -modify the dependence
Changes in v3:
-fix comment from Simon and Lukasz
-fix checkpactch error
--- cmd/Kconfig | 9 ++++++++ cmd/Makefile | 1 + cmd/rockusb.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 cmd/rockusb.c
cmd/Kconfig +9 -0
@@ -518,6 +518,15 @@ config CMD_DFU Enables the command "dfu" which is used to have U-Boot create a DFU class device via USB. +config CMD_ROCKUSB + bool "rockusb" + depends on USB_FUNCTION_ROCKUSB + help + Rockusb protocol is widely used by Rockchip SoC based devices. It can + read/write info, image to/from devices. This enable rockusb command + support to comunication with rockusb device. for more detail about + this command, please read doc/README.rockusb. + config CMD_USB_MASS_STORAGE bool "UMS usb mass storage" help
cmd/Makefile +1 -0
@@ -109,6 +109,7 @@ obj-$(CONFIG_CMD_READ) += read.o obj-$(CONFIG_CMD_REGINFO) += reginfo.o obj-$(CONFIG_CMD_REISER) += reiser.o obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o +obj-$(CONFIG_CMD_ROCKUSB) += rockusb.o obj-$(CONFIG_SANDBOX) += host.o obj-$(CONFIG_CMD_SATA) += sata.o obj-$(CONFIG_CMD_SF) += sf.o
cmd/rockusb.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v5 2/4 usb: rockchip: add rockusb command
Quoted 15 lines · Eddie Cai
this patch add rockusb command. the usage is rockusb <
USB_controller> <devtype> <dev[:part]> e.g. rockusb 0 mmc 0Signed-off-by Eddie Cai <[email protected]>Reviewed-by Simon Glass <[email protected]>Changes in v5:
-noneChanges in v4:
(quoted diff) +0
-2-move USB_FUNCTION_ROCKUSB to drivers/usb/gadget/Kconfig -modify the dependenceChanges in v3:
Review
Quoted 9 lines
(quoted diff) +0
-3-fix comment from Simon and Lukasz -fix checkpactch error --- cmd/Kconfig | 9 ++++++++ cmd/Makefile | 1 + cmd/rockusb.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 cmd/rockusb.c
PATCH v5 3/4 rockchip:usb: add a simple readme for rockusb
In reply to Eddie Caiadd a simple readme to introduce rockusb and tell people how to use it
Changes in v5:
-none
Changes in v4:
-add some blank line to make it look better
Changes in v3:
-fix checkpatch error
--- doc/README.rockusb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 doc/README.rockusb
doc/README.rockusb new file +51 -0
@@ -0,0 +1,51 @@ +Rockusb (Rockchip USB protocol) +===================================================== + +Overview +-------- + +Rockusb protocol is widely used by Rockchip SoC based devices. It can +read/write info, image to/from devices. This document briefly describes how to +use Rockusb for upgrading firmware (e.g. kernel, u-boot, rootfs, etc.). + +Tools +-------- +There are many tools can support Rockusb protocol. rkdeveloptool +(https://github.com/rockchip-linux/rkdeveloptool) is open source, +It is maintained by Rockchip. People don't want to build from source +can download from here +(https://github.com/rockchip-linux/rkbin/blob/master/tools/rkdeveloptool) + +Usage +-------- +The Usage of Rockusb command is: + +rockusb <USB_controller> <devtype> <dev[:part]> + +e.g. rockusb 0 mmc 0 + +On your U-Boot console, type this command to enter rockusb mode. +On your host PC. use lsusb command. you should see a usb device +using 0x2207 as its USB verdor id. + +for more detail about the rkdeveloptool. please read the usage. + +rkdeveloptool -h + +use rkdeveloptool wl command to write lba. BeginSec is the lba on device +you want to write. + +sudo rkdeveloptool wl <BeginSec> <File> + +to flash U-Boot image use below command. U-Boot binary is made by mkimage. +see doc/README.rockchip for more detail about how to get U-Boot binary. + +sudo rkdeveloptool wl 64 <U-Boot binary> + +There are plenty of Rockusb command. but wl(write lba) and +rd(reboot) command. These two command can let people flash +image to device. + +To do +----- +* Fully support Rockusb protocol
Signature · 1 line
1.9.1
PATCH v5 4/4 rockchip: rk3288: enable rockusb support on rk3288 based device
In reply to Eddie Caithis patch enable rockusb support on rk3288 based device.
Changes in v5:
-none
Changes in v4:
-move to rk3288_common.h
Changes in v3:
-move to defconfig
--- include/configs/rk3288_common.h | 4 ++++ 1 file changed, 4 insertions(+)
include/configs/rk3288_common.h +4 -0
@@ -72,6 +72,10 @@#define CONFIG_FASTBOOT_BUF_ADDR CONFIG_SYS_LOAD_ADDR#define CONFIG_FASTBOOT_BUF_SIZE 0x08000000 +/* rockusb */ +#define CONFIG_CMD_ROCKUSB +#define CONFIG_USB_FUNCTION_ROCKUSB +/* usb mass storage */ #define CONFIG_USB_FUNCTION_MASS_STORAGE #define CONFIG_CMD_USB_MASS_STORAGE
Signature · 1 line
1.9.1
PATCH v5 4/4 rockchip: rk3288: enable rockusb support on rk3288 based device
Quoted 22 lines · Eddie Cai
this patch enable rockusb support on rk3288 based device.
Signed-off-by Eddie Cai <[email protected]>Changes in v5:
-noneChanges in v4:
-move tork3288_common.hChanges in v3:
(quoted diff) +0
-2-move to defconfig --- include/configs/rk3288_common.h | 4 ++++ 1 file changed, 4 insertions(+)include/configs/rk3288_common.h +0
-0
include/configs/rk3288_common.h line 77
Quoted 6 lines
include/configs/rk3288_common.h +3
-0@@ -72,6 +72,10 @@#define CONFIG_FASTBOOT_BUF_ADDR CONFIG_SYS_LOAD_ADDR#define CONFIG_FASTBOOT_BUF_SIZE 0x08000000 +/* rockusb */ +#define CONFIG_CMD_ROCKUSB +#define CONFIG_USB_FUNCTION_ROCKUSB
These should go in Kconfig. I'm surprised you don't get a build error trying to do this.
Perhaps add 'imply' lines under 'config ARCH_ROCKCHIP' ?
Quoted 7 lines
include/configs/rk3288_common.h +1
-1+/* usb mass storage */ #define CONFIG_USB_FUNCTION_MASS_STORAGE #define CONFIG_CMD_USB_MASS_STORAGE --1.9.1