[U-Boot] [U-Boot PATCH V2 0/9] 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.
Eddie Cai (9): usb: ums: split macro and data struct in storage_common.c usb: ums: split macro and data struct in f_mass_storage.c usb: ums: merge storage_common.c into f_mass_storage.c usb: ums: remove static declaration of some ums functions usb: ums: add functions to set and get usb interface descriptor usb: ums: add do_extra_command cmd: add rockusb command rockchip: config: enable rockusb support on rk3288 based board rockusb: add a simple readme
cmd/Kconfig | 5 + cmd/Makefile | 1 + cmd/rockusb.c | 383 +++++++++++++++++++++ configs/evb-rk3288_defconfig | 2 + configs/fennec-rk3288_defconfig | 1 + configs/firefly-rk3288_defconfig | 1 + configs/miqi-rk3288_defconfig | 1 + configs/popmetal-rk3288_defconfig | 1 + configs/rock2_defconfig | 2 + configs/sandbox_defconfig | 1 + configs/tinker-rk3288_defconfig | 1 + doc/README.rockusb | 35 ++ drivers/usb/gadget/f_mass_storage.c | 356 +++++++++++++------ .../storage_common.c => include/f_mass_storage.h | 296 +++++----------- 14 files changed, 775 insertions(+), 311 deletions(-) create mode 100644 cmd/rockusb.c create mode 100644 doc/README.rockusb rename drivers/usb/gadget/storage_common.c => include/f_mass_storage.h (65%)

split the macro and data struct in storage_common.c to f_mass_storage.h
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- drivers/usb/gadget/storage_common.c | 380 +--------------------------------- include/f_mass_storage.h | 393 ++++++++++++++++++++++++++++++++++++ 2 files changed, 394 insertions(+), 379 deletions(-) create mode 100644 include/f_mass_storage.h
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index b6df130..bea7607 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -14,385 +14,7 @@ * SPDX-License-Identifier: GPL-2.0+ */
- -/* - * This file requires the following identifiers used in USB strings to - * be defined (each of type pointer to char): - * - fsg_string_manufacturer -- name of the manufacturer - * - fsg_string_product -- name of the product - * - fsg_string_serial -- product's serial - * - fsg_string_config -- name of the configuration - * - fsg_string_interface -- name of the interface - * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS - * macro is defined prior to including this file. - */ - -/* - * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and - * fsg_hs_intr_in_desc objects as well as - * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES - * macros are not defined. - * - * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER, - * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not - * defined (as well as corresponding entries in string tables are - * missing) and FSG_STRING_INTERFACE has value of zero. - * - * When FSG_NO_OTG is defined fsg_otg_desc won't be defined. - */ - -/* - * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included - * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN - * characters rather then a pointer to void. - */ - - -/* #include <asm/unaligned.h> */ - - -/* - * Thanks to NetChip Technologies for donating this product ID. - * - * DO NOT REUSE THESE IDs with any other driver!! Ever!! - * Instead: allocate your own, using normal USB-IF procedures. - */ -#define FSG_VENDOR_ID 0x0525 /* NetChip */ -#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ - -/*-------------------------------------------------------------------------*/ - -#ifndef DEBUG -#undef VERBOSE_DEBUG -#undef DUMP_MSGS -#endif /* !DEBUG */ - -#ifdef VERBOSE_DEBUG -#define VLDBG LDBG -#else -#define VLDBG(lun, fmt, args...) do { } while (0) -#endif /* VERBOSE_DEBUG */ - -/* -#define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args) -#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args) -#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) -#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) -*/ - -#define LDBG(lun, fmt, args...) do { } while (0) -#define LERROR(lun, fmt, args...) do { } while (0) -#define LWARN(lun, fmt, args...) do { } while (0) -#define LINFO(lun, fmt, args...) do { } while (0) - -/* - * Keep those macros in sync with those in - * include/linux/usb/composite.h or else GCC will complain. If they - * are identical (the same names of arguments, white spaces in the - * same places) GCC will allow redefinition otherwise (even if some - * white space is removed or added) warning will be issued. - * - * Those macros are needed here because File Storage Gadget does not - * include the composite.h header. For composite gadgets those macros - * are redundant since composite.h is included any way. - * - * One could check whether those macros are already defined (which - * would indicate composite.h had been included) or not (which would - * indicate we were in FSG) but this is not done because a warning is - * desired if definitions here differ from the ones in composite.h. - * - * We want the definitions to match and be the same in File Storage - * Gadget as well as Mass Storage Function (and so composite gadgets - * using MSF). If someone changes them in composite.h it will produce - * a warning in this file when building MSF. - */ - -#define DBG(d, fmt, args...) debug(fmt , ## args) -#define VDBG(d, fmt, args...) debug(fmt , ## args) -/* #define ERROR(d, fmt, args...) printf(fmt , ## args) */ -/* #define WARNING(d, fmt, args...) printf(fmt , ## args) */ -/* #define INFO(d, fmt, args...) printf(fmt , ## args) */ - -/* #define DBG(d, fmt, args...) do { } while (0) */ -/* #define VDBG(d, fmt, args...) do { } while (0) */ -#define ERROR(d, fmt, args...) do { } while (0) -#define WARNING(d, fmt, args...) do { } while (0) -#define INFO(d, fmt, args...) do { } while (0) - -#ifdef DUMP_MSGS - -/* dump_msg(fsg, const char * label, const u8 * buf, unsigned length); */ -# define dump_msg(fsg, label, buf, length) do { \ - if (length < 512) { \ - DBG(fsg, "%s, length %u:\n", label, length); \ - print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \ - 16, 1, buf, length, 0); \ - } \ -} while (0) - -# define dump_cdb(fsg) do { } while (0) - -#else - -# define dump_msg(fsg, /* const char * */ label, \ - /* const u8 * */ buf, /* unsigned */ length) do { } while (0) - -# ifdef VERBOSE_DEBUG - -# define dump_cdb(fsg) \ - print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \ - 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \ - -# else - -# define dump_cdb(fsg) do { } while (0) - -# endif /* VERBOSE_DEBUG */ - -#endif /* DUMP_MSGS */ - -/*-------------------------------------------------------------------------*/ - -/* SCSI device types */ -#define TYPE_DISK 0x00 -#define TYPE_CDROM 0x05 - -/* USB protocol value = the transport method */ -#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */ -#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */ -#define USB_PR_BULK 0x50 /* Bulk-only */ - -/* USB subclass value = the protocol encapsulation */ -#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */ -#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */ -#define USB_SC_QIC 0x03 /* QIC-157 (tape) */ -#define USB_SC_UFI 0x04 /* UFI (floppy) */ -#define USB_SC_8070 0x05 /* SFF-8070i (removable) */ -#define USB_SC_SCSI 0x06 /* Transparent SCSI */ - -/* Bulk-only data structures */ - -/* Command Block Wrapper */ -struct fsg_bulk_cb_wrap { - __le32 Signature; /* Contains 'USBC' */ - u32 Tag; /* Unique per command id */ - __le32 DataTransferLength; /* 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 - -/* Bulk-only class specific requests */ -#define USB_BULK_RESET_REQUEST 0xff -#define USB_BULK_GET_MAX_LUN_REQUEST 0xfe - -/* CBI Interrupt data structure */ -struct interrupt_data { - u8 bType; - u8 bValue; -}; - -#define CBI_INTERRUPT_DATA_LEN 2 - -/* CBI Accept Device-Specific Command request */ -#define USB_CBI_ADSC_REQUEST 0x00 - -/* Length of a SCSI Command Data Block */ -#define MAX_COMMAND_SIZE 16 - -/* SCSI commands that we recognize */ -#define SC_FORMAT_UNIT 0x04 -#define SC_INQUIRY 0x12 -#define SC_MODE_SELECT_6 0x15 -#define SC_MODE_SELECT_10 0x55 -#define SC_MODE_SENSE_6 0x1a -#define SC_MODE_SENSE_10 0x5a -#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e -#define SC_READ_6 0x08 -#define SC_READ_10 0x28 -#define SC_READ_12 0xa8 -#define SC_READ_CAPACITY 0x25 -#define SC_READ_FORMAT_CAPACITIES 0x23 -#define SC_READ_HEADER 0x44 -#define SC_READ_TOC 0x43 -#define SC_RELEASE 0x17 -#define SC_REQUEST_SENSE 0x03 -#define SC_RESERVE 0x16 -#define SC_SEND_DIAGNOSTIC 0x1d -#define SC_START_STOP_UNIT 0x1b -#define SC_SYNCHRONIZE_CACHE 0x35 -#define SC_TEST_UNIT_READY 0x00 -#define SC_VERIFY 0x2f -#define SC_WRITE_6 0x0a -#define SC_WRITE_10 0x2a -#define SC_WRITE_12 0xaa - -/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ -#define SS_NO_SENSE 0 -#define SS_COMMUNICATION_FAILURE 0x040800 -#define SS_INVALID_COMMAND 0x052000 -#define SS_INVALID_FIELD_IN_CDB 0x052400 -#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 -#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 -#define SS_MEDIUM_NOT_PRESENT 0x023a00 -#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 -#define SS_NOT_READY_TO_READY_TRANSITION 0x062800 -#define SS_RESET_OCCURRED 0x062900 -#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 -#define SS_UNRECOVERED_READ_ERROR 0x031100 -#define SS_WRITE_ERROR 0x030c02 -#define SS_WRITE_PROTECTED 0x072700 - -#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ -#define ASC(x) ((u8) ((x) >> 8)) -#define ASCQ(x) ((u8) (x)) - -struct device_attribute { int i; }; -#define ETOOSMALL 525 - -#include <usb_mass_storage.h> - -/*-------------------------------------------------------------------------*/ - -struct fsg_lun { - loff_t file_length; - loff_t num_sectors; - - unsigned int initially_ro:1; - unsigned int ro:1; - unsigned int removable:1; - unsigned int cdrom:1; - unsigned int prevent_medium_removal:1; - unsigned int registered:1; - unsigned int info_valid:1; - unsigned int nofua:1; - - u32 sense_data; - u32 sense_data_info; - u32 unit_attention_data; - - struct device dev; -}; - -#define fsg_lun_is_open(curlun) ((curlun)->filp != NULL) -#if 0 -static struct fsg_lun *fsg_lun_from_dev(struct device *dev) -{ - return container_of(dev, struct fsg_lun, dev); -} -#endif - -/* Big enough to hold our biggest descriptor */ -#define EP0_BUFSIZE 256 -#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ - -/* Number of buffers we will use. 2 is enough for double-buffering */ -#define FSG_NUM_BUFFERS 2 - -/* Default size of buffer length. */ -#define FSG_BUFLEN ((u32)16384) - -/* Maximal number of LUNs supported in mass storage function */ -#define FSG_MAX_LUNS 8 - -enum fsg_buffer_state { - BUF_STATE_EMPTY = 0, - BUF_STATE_FULL, - BUF_STATE_BUSY -}; - -struct fsg_buffhd { -#ifdef FSG_BUFFHD_STATIC_BUFFER - char buf[FSG_BUFLEN]; -#else - void *buf; -#endif - enum fsg_buffer_state state; - struct fsg_buffhd *next; - - /* - * The NetChip 2280 is faster, and handles some protocol faults - * better, if we don't submit any short bulk-out read requests. - * So we will record the intended request length here. - */ - unsigned int bulk_out_intended_length; - - struct usb_request *inreq; - int inreq_busy; - struct usb_request *outreq; - int outreq_busy; -}; - -enum fsg_state { - /* This one isn't used anywhere */ - FSG_STATE_COMMAND_PHASE = -10, - FSG_STATE_DATA_PHASE, - FSG_STATE_STATUS_PHASE, - - FSG_STATE_IDLE = 0, - FSG_STATE_ABORT_BULK_OUT, - FSG_STATE_RESET, - FSG_STATE_INTERFACE_CHANGE, - FSG_STATE_CONFIG_CHANGE, - FSG_STATE_DISCONNECT, - FSG_STATE_EXIT, - FSG_STATE_TERMINATED -}; - -enum data_direction { - DATA_DIR_UNKNOWN = 0, - DATA_DIR_FROM_HOST, - DATA_DIR_TO_HOST, - DATA_DIR_NONE -}; - -/*-------------------------------------------------------------------------*/ - -static inline u32 get_unaligned_be24(u8 *buf) -{ - return 0xffffff & (u32) get_unaligned_be32(buf - 1); -} - -/*-------------------------------------------------------------------------*/ - -enum { -#ifndef FSG_NO_DEVICE_STRINGS - FSG_STRING_MANUFACTURER = 1, - FSG_STRING_PRODUCT, - FSG_STRING_SERIAL, - FSG_STRING_CONFIG, -#endif - FSG_STRING_INTERFACE -}; - -#ifndef FSG_NO_OTG -static struct usb_otg_descriptor -fsg_otg_desc = { - .bLength = sizeof fsg_otg_desc, - .bDescriptorType = USB_DT_OTG, - - .bmAttributes = USB_OTG_SRP, -}; -#endif +#include <f_mass_storage.h>
/* There is only one interface. */
diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h new file mode 100644 index 0000000..679f242 --- /dev/null +++ b/include/f_mass_storage.h @@ -0,0 +1,393 @@ +/* + * f_mass_storage.h -- Common definitions for mass storage functionality + * + * Copyright (C) 2003-2008 Alan Stern + * Copyeight (C) 2009 Samsung Electronics + * Author: Michal Nazarewicz (m.nazarewicz@samsung.com) + * + * Ported to u-boot: + * Andrzej Pietrasiewicz andrzej.p@samsung.com + * + * Code refactoring & cleanup: + * Łukasz Majewski l.majewski@samsung.com + * Eddie Cai eddie.cai.linux@gmail.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __F_MASS_STORAGE_H_ +#define __F_MASS_STORAGE_H_ +#include <usb_mass_storage.h> + +/* + * This file requires the following identifiers used in USB strings to + * be defined (each of type pointer to char): + * - fsg_string_manufacturer -- name of the manufacturer + * - fsg_string_product -- name of the product + * - fsg_string_serial -- product's serial + * - fsg_string_config -- name of the configuration + * - fsg_string_interface -- name of the interface + * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS + * macro is defined prior to including this file. + */ + +/* + * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and + * fsg_hs_intr_in_desc objects as well as + * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES + * macros are not defined. + * + * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER, + * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not + * defined (as well as corresponding entries in string tables are + * missing) and FSG_STRING_INTERFACE has value of zero. + * + * When FSG_NO_OTG is defined fsg_otg_desc won't be defined. + */ + +/* + * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included + * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN + * characters rather then a pointer to void. + */ + + +/* #include <asm/unaligned.h> */ + + +/* + * Thanks to NetChip Technologies for donating this product ID. + * + * DO NOT REUSE THESE IDs with any other driver!! Ever!! + * Instead: allocate your own, using normal USB-IF procedures. + */ +#define FSG_VENDOR_ID 0x0525 /* NetChip */ +#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ + +/*-------------------------------------------------------------------------*/ + +#ifndef DEBUG +#undef VERBOSE_DEBUG +#undef DUMP_MSGS +#endif /* !DEBUG */ + +#ifdef VERBOSE_DEBUG +#define VLDBG LDBG +#else +#define VLDBG(lun, fmt, args...) do { } while (0) +#endif /* VERBOSE_DEBUG */ + +/* +#define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args) +#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args) +#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) +#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) +*/ + +#define LDBG(lun, fmt, args...) do { } while (0) +#define LERROR(lun, fmt, args...) do { } while (0) +#define LWARN(lun, fmt, args...) do { } while (0) +#define LINFO(lun, fmt, args...) do { } while (0) + +/* + * Keep those macros in sync with those in + * include/linux/usb/composite.h or else GCC will complain. If they + * are identical (the same names of arguments, white spaces in the + * same places) GCC will allow redefinition otherwise (even if some + * white space is removed or added) warning will be issued. + * + * Those macros are needed here because File Storage Gadget does not + * include the composite.h header. For composite gadgets those macros + * are redundant since composite.h is included any way. + * + * One could check whether those macros are already defined (which + * would indicate composite.h had been included) or not (which would + * indicate we were in FSG) but this is not done because a warning is + * desired if definitions here differ from the ones in composite.h. + * + * We want the definitions to match and be the same in File Storage + * Gadget as well as Mass Storage Function (and so composite gadgets + * using MSF). If someone changes them in composite.h it will produce + * a warning in this file when building MSF. + */ + +#define DBG(d, fmt, args...) debug(fmt , ## args) +#define VDBG(d, fmt, args...) debug(fmt , ## args) +/* #define ERROR(d, fmt, args...) printf(fmt , ## args) */ +/* #define WARNING(d, fmt, args...) printf(fmt , ## args) */ +/* #define INFO(d, fmt, args...) printf(fmt , ## args) */ + +/* #define DBG(d, fmt, args...) do { } while (0) */ +/* #define VDBG(d, fmt, args...) do { } while (0) */ +#define ERROR(d, fmt, args...) do { } while (0) +#define WARNING(d, fmt, args...) do { } while (0) +#define INFO(d, fmt, args...) do { } while (0) + +#ifdef DUMP_MSGS + +/* dump_msg(fsg, const char * label, const u8 * buf, unsigned length); */ +# define dump_msg(fsg, label, buf, length) do { \ + if (length < 512) { \ + DBG(fsg, "%s, length %u:\n", label, length); \ + print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \ + 16, 1, buf, length, 0); \ + } \ +} while (0) + +# define dump_cdb(fsg) do { } while (0) + +#else + +# define dump_msg(fsg, /* const char * */ label, \ + /* const u8 * */ buf, /* unsigned */ length) do { } while (0) + +# ifdef VERBOSE_DEBUG + +# define dump_cdb(fsg) \ + print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \ + 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \ + +# else + +# define dump_cdb(fsg) do { } while (0) + +# endif /* VERBOSE_DEBUG */ + +#endif /* DUMP_MSGS */ + +/*-------------------------------------------------------------------------*/ + +/* SCSI device types */ +#define TYPE_DISK 0x00 +#define TYPE_CDROM 0x05 + +/* USB protocol value = the transport method */ +#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */ +#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */ +#define USB_PR_BULK 0x50 /* Bulk-only */ + +/* USB subclass value = the protocol encapsulation */ +#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */ +#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */ +#define USB_SC_QIC 0x03 /* QIC-157 (tape) */ +#define USB_SC_UFI 0x04 /* UFI (floppy) */ +#define USB_SC_8070 0x05 /* SFF-8070i (removable) */ +#define USB_SC_SCSI 0x06 /* Transparent SCSI */ + +/* Bulk-only data structures */ + +/* Command Block Wrapper */ +struct fsg_bulk_cb_wrap { + __le32 Signature; /* Contains 'USBC' */ + u32 Tag; /* Unique per command id */ + __le32 DataTransferLength; /* 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 + +/* Bulk-only class specific requests */ +#define USB_BULK_RESET_REQUEST 0xff +#define USB_BULK_GET_MAX_LUN_REQUEST 0xfe + +/* CBI Interrupt data structure */ +struct interrupt_data { + u8 bType; + u8 bValue; +}; + +#define CBI_INTERRUPT_DATA_LEN 2 + +/* CBI Accept Device-Specific Command request */ +#define USB_CBI_ADSC_REQUEST 0x00 + +/* Length of a SCSI Command Data Block */ +#define MAX_COMMAND_SIZE 16 + +/* SCSI commands that we recognize */ +#define SC_FORMAT_UNIT 0x04 +#define SC_INQUIRY 0x12 +#define SC_MODE_SELECT_6 0x15 +#define SC_MODE_SELECT_10 0x55 +#define SC_MODE_SENSE_6 0x1a +#define SC_MODE_SENSE_10 0x5a +#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e +#define SC_READ_6 0x08 +#define SC_READ_10 0x28 +#define SC_READ_12 0xa8 +#define SC_READ_CAPACITY 0x25 +#define SC_READ_FORMAT_CAPACITIES 0x23 +#define SC_READ_HEADER 0x44 +#define SC_READ_TOC 0x43 +#define SC_RELEASE 0x17 +#define SC_REQUEST_SENSE 0x03 +#define SC_RESERVE 0x16 +#define SC_SEND_DIAGNOSTIC 0x1d +#define SC_START_STOP_UNIT 0x1b +#define SC_SYNCHRONIZE_CACHE 0x35 +#define SC_TEST_UNIT_READY 0x00 +#define SC_VERIFY 0x2f +#define SC_WRITE_6 0x0a +#define SC_WRITE_10 0x2a +#define SC_WRITE_12 0xaa + +/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ +#define SS_NO_SENSE 0 +#define SS_COMMUNICATION_FAILURE 0x040800 +#define SS_INVALID_COMMAND 0x052000 +#define SS_INVALID_FIELD_IN_CDB 0x052400 +#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 +#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 +#define SS_MEDIUM_NOT_PRESENT 0x023a00 +#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 +#define SS_NOT_READY_TO_READY_TRANSITION 0x062800 +#define SS_RESET_OCCURRED 0x062900 +#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 +#define SS_UNRECOVERED_READ_ERROR 0x031100 +#define SS_WRITE_ERROR 0x030c02 +#define SS_WRITE_PROTECTED 0x072700 + +#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ +#define ASC(x) ((u8) ((x) >> 8)) +#define ASCQ(x) ((u8) (x)) + +struct device_attribute { int i; }; +#define ETOOSMALL 525 + + +/*-------------------------------------------------------------------------*/ + +struct fsg_lun { + loff_t file_length; + loff_t num_sectors; + + unsigned int initially_ro:1; + unsigned int ro:1; + unsigned int removable:1; + unsigned int cdrom:1; + unsigned int prevent_medium_removal:1; + unsigned int registered:1; + unsigned int info_valid:1; + unsigned int nofua:1; + + u32 sense_data; + u32 sense_data_info; + u32 unit_attention_data; + + struct device dev; +}; + +#define fsg_lun_is_open(curlun) ((curlun)->filp != NULL) +/* Big enough to hold our biggest descriptor */ +#define EP0_BUFSIZE 256 +#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ + +/* Number of buffers we will use. 2 is enough for double-buffering */ +#define FSG_NUM_BUFFERS 2 + +/* Default size of buffer length. */ +#define FSG_BUFLEN ((u32)16384) + +/* Maximal number of LUNs supported in mass storage function */ +#define FSG_MAX_LUNS 8 + +enum fsg_buffer_state { + BUF_STATE_EMPTY = 0, + BUF_STATE_FULL, + BUF_STATE_BUSY +}; + +struct fsg_buffhd { +#ifdef FSG_BUFFHD_STATIC_BUFFER + char buf[FSG_BUFLEN]; +#else + void *buf; +#endif + enum fsg_buffer_state state; + struct fsg_buffhd *next; + + /* + * The NetChip 2280 is faster, and handles some protocol faults + * better, if we don't submit any short bulk-out read requests. + * So we will record the intended request length here. + */ + unsigned int bulk_out_intended_length; + + struct usb_request *inreq; + int inreq_busy; + struct usb_request *outreq; + int outreq_busy; +}; + +enum fsg_state { + /* This one isn't used anywhere */ + FSG_STATE_COMMAND_PHASE = -10, + FSG_STATE_DATA_PHASE, + FSG_STATE_STATUS_PHASE, + + FSG_STATE_IDLE = 0, + FSG_STATE_ABORT_BULK_OUT, + FSG_STATE_RESET, + FSG_STATE_INTERFACE_CHANGE, + FSG_STATE_CONFIG_CHANGE, + FSG_STATE_DISCONNECT, + FSG_STATE_EXIT, + FSG_STATE_TERMINATED +}; + +enum data_direction { + DATA_DIR_UNKNOWN = 0, + DATA_DIR_FROM_HOST, + DATA_DIR_TO_HOST, + DATA_DIR_NONE +}; + +/*-------------------------------------------------------------------------*/ + +static inline u32 get_unaligned_be24(u8 *buf) +{ + return 0xffffff & (u32) get_unaligned_be32(buf - 1); +} + +/*-------------------------------------------------------------------------*/ + +enum { +#ifndef FSG_NO_DEVICE_STRINGS + FSG_STRING_MANUFACTURER = 1, + FSG_STRING_PRODUCT, + FSG_STRING_SERIAL, + FSG_STRING_CONFIG, +#endif + FSG_STRING_INTERFACE +}; + +#ifndef FSG_NO_OTG +static struct usb_otg_descriptor +fsg_otg_desc = { + .bLength = sizeof(fsg_otg_desc), + .bDescriptorType = USB_DT_OTG, + + .bmAttributes = USB_OTG_SRP, +}; +#endif + +#endif /* __F_MASS_STORAGE_H_ */

Hi Eddie,
Sorry for late reply - the Easter break.
I would prefer to keep things as they are now.
The reason is that f_mass_storage gadget in Linux has the same file structure as u-boot - e.g. ./drivers/usb/gadget/function/storage_common.c in Linux tree.
It would be easier then to update the u-boot to Linux code if needed (or ported to DM).
Best regards, Łukasz Majewski
split the macro and data struct in storage_common.c to f_mass_storage.h
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/storage_common.c | 380 +--------------------------------- include/f_mass_storage.h | 393 ++++++++++++++++++++++++++++++++++++ 2 files changed, 394 insertions(+), 379 deletions(-) create mode 100644 include/f_mass_storage.h
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c index b6df130..bea7607 100644 --- a/drivers/usb/gadget/storage_common.c +++ b/drivers/usb/gadget/storage_common.c @@ -14,385 +14,7 @@
- SPDX-License-Identifier: GPL-2.0+
*/
-/*
- This file requires the following identifiers used in USB strings
to
- be defined (each of type pointer to char):
- fsg_string_manufacturer -- name of the manufacturer
- fsg_string_product -- name of the product
- fsg_string_serial -- product's serial
- fsg_string_config -- name of the configuration
- fsg_string_interface -- name of the interface
- The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
- macro is defined prior to including this file.
- */
-/*
- When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and
- fsg_hs_intr_in_desc objects as well as
- FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES
- macros are not defined.
- When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER,
- FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are
not
- defined (as well as corresponding entries in string tables are
- missing) and FSG_STRING_INTERFACE has value of zero.
- When FSG_NO_OTG is defined fsg_otg_desc won't be defined.
- */
-/*
- When FSG_BUFFHD_STATIC_BUFFER is defined when this file is
included
- the fsg_buffhd structure's buf field will be an array of
FSG_BUFLEN
- characters rather then a pointer to void.
- */
-/* #include <asm/unaligned.h> */
-/*
- Thanks to NetChip Technologies for donating this product ID.
- DO NOT REUSE THESE IDs with any other driver!! Ever!!
- Instead: allocate your own, using normal USB-IF procedures.
- */
-#define FSG_VENDOR_ID 0x0525 /* NetChip */ -#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ - -/*-------------------------------------------------------------------------*/
-#ifndef DEBUG -#undef VERBOSE_DEBUG -#undef DUMP_MSGS -#endif /* !DEBUG */
-#ifdef VERBOSE_DEBUG -#define VLDBG LDBG -#else -#define VLDBG(lun, fmt, args...) do { } while (0) -#endif /* VERBOSE_DEBUG */
-/* -#define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args) -#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args) -#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) -#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) -*/
-#define LDBG(lun, fmt, args...) do { } while (0) -#define LERROR(lun, fmt, args...) do { } while (0) -#define LWARN(lun, fmt, args...) do { } while (0) -#define LINFO(lun, fmt, args...) do { } while (0)
-/*
- Keep those macros in sync with those in
- include/linux/usb/composite.h or else GCC will complain. If they
- are identical (the same names of arguments, white spaces in the
- same places) GCC will allow redefinition otherwise (even if some
- white space is removed or added) warning will be issued.
- Those macros are needed here because File Storage Gadget does not
- include the composite.h header. For composite gadgets those
macros
- are redundant since composite.h is included any way.
- One could check whether those macros are already defined (which
- would indicate composite.h had been included) or not (which would
- indicate we were in FSG) but this is not done because a warning is
- desired if definitions here differ from the ones in composite.h.
- We want the definitions to match and be the same in File Storage
- Gadget as well as Mass Storage Function (and so composite gadgets
- using MSF). If someone changes them in composite.h it will
produce
- a warning in this file when building MSF.
- */
-#define DBG(d, fmt, args...) debug(fmt , ## args) -#define VDBG(d, fmt, args...) debug(fmt , ## args) -/* #define ERROR(d, fmt, args...) printf(fmt , ## args) */ -/* #define WARNING(d, fmt, args...) printf(fmt , ## args) */ -/* #define INFO(d, fmt, args...) printf(fmt , ## args) */
-/* #define DBG(d, fmt, args...) do { } while (0) */ -/* #define VDBG(d, fmt, args...) do { } while (0) */ -#define ERROR(d, fmt, args...) do { } while (0) -#define WARNING(d, fmt, args...) do { } while (0) -#define INFO(d, fmt, args...) do { } while (0)
-#ifdef DUMP_MSGS
-/* dump_msg(fsg, const char * label, const u8 * buf, unsigned length); */ -# define dump_msg(fsg, label, buf, length) do { \
- if (length < 512)
{ \
DBG(fsg, "%s, length %u:\n", label,
length); \
print_hex_dump(KERN_DEBUG, "",
DUMP_PREFIX_OFFSET, \
16, 1, buf, length,
0); \
- }
\ -} while (0)
-# define dump_cdb(fsg) do { } while (0)
-#else
-# define dump_msg(fsg, /* const char * */ label, \
/* const u8 * */ buf, /* unsigned */ length) do
{ } while (0) - -# ifdef VERBOSE_DEBUG
-# define dump_cdb(fsg) \
- print_hex_dump(KERN_DEBUG, "SCSI CDB: ",
DUMP_PREFIX_NONE, \
16, 1, (fsg)->cmnd, (fsg)->cmnd_size,
\ -
-# else
-# define dump_cdb(fsg) do { } while (0)
-# endif /* VERBOSE_DEBUG */
-#endif /* DUMP_MSGS */
-/*-------------------------------------------------------------------------*/
-/* SCSI device types */ -#define TYPE_DISK 0x00 -#define TYPE_CDROM 0x05
-/* USB protocol value = the transport method */ -#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */ -#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */ -#define USB_PR_BULK 0x50 /* Bulk-only */ - -/* USB subclass value = the protocol encapsulation */ -#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */ -#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */ -#define USB_SC_QIC 0x03 /* QIC-157 (tape) */ -#define USB_SC_UFI 0x04 /* UFI (floppy) */ -#define USB_SC_8070 0x05 /* SFF-8070i (removable) */ -#define USB_SC_SCSI 0x06 /* Transparent SCSI */ - -/* Bulk-only data structures */
-/* Command Block Wrapper */ -struct fsg_bulk_cb_wrap {
- __le32 Signature; /* Contains 'USBC' */
- u32 Tag; /* Unique per command
id */
- __le32 DataTransferLength; /* 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
-/* Bulk-only class specific requests */ -#define USB_BULK_RESET_REQUEST 0xff -#define USB_BULK_GET_MAX_LUN_REQUEST 0xfe
-/* CBI Interrupt data structure */ -struct interrupt_data {
- u8 bType;
- u8 bValue;
-};
-#define CBI_INTERRUPT_DATA_LEN 2
-/* CBI Accept Device-Specific Command request */ -#define USB_CBI_ADSC_REQUEST 0x00
-/* Length of a SCSI Command Data Block */ -#define MAX_COMMAND_SIZE 16
-/* SCSI commands that we recognize */ -#define SC_FORMAT_UNIT 0x04 -#define SC_INQUIRY 0x12 -#define SC_MODE_SELECT_6 0x15 -#define SC_MODE_SELECT_10 0x55 -#define SC_MODE_SENSE_6 0x1a -#define SC_MODE_SENSE_10 0x5a -#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e -#define SC_READ_6 0x08 -#define SC_READ_10 0x28 -#define SC_READ_12 0xa8 -#define SC_READ_CAPACITY 0x25 -#define SC_READ_FORMAT_CAPACITIES 0x23 -#define SC_READ_HEADER 0x44 -#define SC_READ_TOC 0x43 -#define SC_RELEASE 0x17 -#define SC_REQUEST_SENSE 0x03 -#define SC_RESERVE 0x16 -#define SC_SEND_DIAGNOSTIC 0x1d -#define SC_START_STOP_UNIT 0x1b -#define SC_SYNCHRONIZE_CACHE 0x35 -#define SC_TEST_UNIT_READY 0x00 -#define SC_VERIFY 0x2f -#define SC_WRITE_6 0x0a -#define SC_WRITE_10 0x2a -#define SC_WRITE_12 0xaa
-/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ -#define SS_NO_SENSE 0 -#define SS_COMMUNICATION_FAILURE 0x040800 -#define SS_INVALID_COMMAND 0x052000 -#define SS_INVALID_FIELD_IN_CDB 0x052400 -#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 -#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 -#define SS_MEDIUM_NOT_PRESENT 0x023a00 -#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 -#define SS_NOT_READY_TO_READY_TRANSITION 0x062800 -#define SS_RESET_OCCURRED 0x062900 -#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 -#define SS_UNRECOVERED_READ_ERROR 0x031100 -#define SS_WRITE_ERROR 0x030c02 -#define SS_WRITE_PROTECTED 0x072700
-#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ -#define ASC(x) ((u8) ((x) >> 8)) -#define ASCQ(x) ((u8) (x))
-struct device_attribute { int i; }; -#define ETOOSMALL 525
-#include <usb_mass_storage.h>
-/*-------------------------------------------------------------------------*/
-struct fsg_lun {
- loff_t file_length;
- loff_t num_sectors;
- unsigned int initially_ro:1;
- unsigned int ro:1;
- unsigned int removable:1;
- unsigned int cdrom:1;
- unsigned int prevent_medium_removal:1;
- unsigned int registered:1;
- unsigned int info_valid:1;
- unsigned int nofua:1;
- u32 sense_data;
- u32 sense_data_info;
- u32 unit_attention_data;
- struct device dev;
-};
-#define fsg_lun_is_open(curlun) ((curlun)->filp != NULL) -#if 0 -static struct fsg_lun *fsg_lun_from_dev(struct device *dev) -{
- return container_of(dev, struct fsg_lun, dev);
-} -#endif
-/* Big enough to hold our biggest descriptor */ -#define EP0_BUFSIZE 256 -#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ - -/* Number of buffers we will use. 2 is enough for double-buffering */ -#define FSG_NUM_BUFFERS 2
-/* Default size of buffer length. */ -#define FSG_BUFLEN ((u32)16384)
-/* Maximal number of LUNs supported in mass storage function */ -#define FSG_MAX_LUNS 8
-enum fsg_buffer_state {
- BUF_STATE_EMPTY = 0,
- BUF_STATE_FULL,
- BUF_STATE_BUSY
-};
-struct fsg_buffhd { -#ifdef FSG_BUFFHD_STATIC_BUFFER
- char buf[FSG_BUFLEN];
-#else
- void *buf;
-#endif
- enum fsg_buffer_state state;
- struct fsg_buffhd *next;
- /*
* The NetChip 2280 is faster, and handles some protocol
faults
* better, if we don't submit any short bulk-out read
requests.
* So we will record the intended request length here.
*/
- unsigned int bulk_out_intended_length;
- struct usb_request *inreq;
- int inreq_busy;
- struct usb_request *outreq;
- int outreq_busy;
-};
-enum fsg_state {
- /* This one isn't used anywhere */
- FSG_STATE_COMMAND_PHASE = -10,
- FSG_STATE_DATA_PHASE,
- FSG_STATE_STATUS_PHASE,
- FSG_STATE_IDLE = 0,
- FSG_STATE_ABORT_BULK_OUT,
- FSG_STATE_RESET,
- FSG_STATE_INTERFACE_CHANGE,
- FSG_STATE_CONFIG_CHANGE,
- FSG_STATE_DISCONNECT,
- FSG_STATE_EXIT,
- FSG_STATE_TERMINATED
-};
-enum data_direction {
- DATA_DIR_UNKNOWN = 0,
- DATA_DIR_FROM_HOST,
- DATA_DIR_TO_HOST,
- DATA_DIR_NONE
-};
-/*-------------------------------------------------------------------------*/
-static inline u32 get_unaligned_be24(u8 *buf) -{
- return 0xffffff & (u32) get_unaligned_be32(buf - 1);
-}
-/*-------------------------------------------------------------------------*/
-enum { -#ifndef FSG_NO_DEVICE_STRINGS
- FSG_STRING_MANUFACTURER = 1,
- FSG_STRING_PRODUCT,
- FSG_STRING_SERIAL,
- FSG_STRING_CONFIG,
-#endif
- FSG_STRING_INTERFACE
-};
-#ifndef FSG_NO_OTG -static struct usb_otg_descriptor -fsg_otg_desc = {
- .bLength = sizeof fsg_otg_desc,
- .bDescriptorType = USB_DT_OTG,
- .bmAttributes = USB_OTG_SRP,
-}; -#endif +#include <f_mass_storage.h>
/* There is only one interface. */
diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h new file mode 100644 index 0000000..679f242 --- /dev/null +++ b/include/f_mass_storage.h @@ -0,0 +1,393 @@ +/*
- f_mass_storage.h -- Common definitions for mass storage
functionality
- Copyright (C) 2003-2008 Alan Stern
- Copyeight (C) 2009 Samsung Electronics
- Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
- Ported to u-boot:
- Andrzej Pietrasiewicz andrzej.p@samsung.com
- Code refactoring & cleanup:
- Łukasz Majewski l.majewski@samsung.com
- Eddie Cai eddie.cai.linux@gmail.com
- SPDX-License-Identifier: GPL-2.0+
- */
+#ifndef __F_MASS_STORAGE_H_ +#define __F_MASS_STORAGE_H_ +#include <usb_mass_storage.h>
+/*
- This file requires the following identifiers used in USB strings
to
- be defined (each of type pointer to char):
- fsg_string_manufacturer -- name of the manufacturer
- fsg_string_product -- name of the product
- fsg_string_serial -- product's serial
- fsg_string_config -- name of the configuration
- fsg_string_interface -- name of the interface
- The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
- macro is defined prior to including this file.
- */
+/*
- When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and
- fsg_hs_intr_in_desc objects as well as
- FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES
- macros are not defined.
- When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER,
- FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are
not
- defined (as well as corresponding entries in string tables are
- missing) and FSG_STRING_INTERFACE has value of zero.
- When FSG_NO_OTG is defined fsg_otg_desc won't be defined.
- */
+/*
- When FSG_BUFFHD_STATIC_BUFFER is defined when this file is
included
- the fsg_buffhd structure's buf field will be an array of
FSG_BUFLEN
- characters rather then a pointer to void.
- */
+/* #include <asm/unaligned.h> */
+/*
- Thanks to NetChip Technologies for donating this product ID.
- DO NOT REUSE THESE IDs with any other driver!! Ever!!
- Instead: allocate your own, using normal USB-IF procedures.
- */
+#define FSG_VENDOR_ID 0x0525 /* NetChip */ +#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */ + +/*-------------------------------------------------------------------------*/
+#ifndef DEBUG +#undef VERBOSE_DEBUG +#undef DUMP_MSGS +#endif /* !DEBUG */
+#ifdef VERBOSE_DEBUG +#define VLDBG LDBG +#else +#define VLDBG(lun, fmt, args...) do { } while (0) +#endif /* VERBOSE_DEBUG */
+/* +#define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args) +#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args) +#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args) +#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args) +*/
+#define LDBG(lun, fmt, args...) do { } while (0) +#define LERROR(lun, fmt, args...) do { } while (0) +#define LWARN(lun, fmt, args...) do { } while (0) +#define LINFO(lun, fmt, args...) do { } while (0)
+/*
- Keep those macros in sync with those in
- include/linux/usb/composite.h or else GCC will complain. If they
- are identical (the same names of arguments, white spaces in the
- same places) GCC will allow redefinition otherwise (even if some
- white space is removed or added) warning will be issued.
- Those macros are needed here because File Storage Gadget does not
- include the composite.h header. For composite gadgets those
macros
- are redundant since composite.h is included any way.
- One could check whether those macros are already defined (which
- would indicate composite.h had been included) or not (which would
- indicate we were in FSG) but this is not done because a warning is
- desired if definitions here differ from the ones in composite.h.
- We want the definitions to match and be the same in File Storage
- Gadget as well as Mass Storage Function (and so composite gadgets
- using MSF). If someone changes them in composite.h it will
produce
- a warning in this file when building MSF.
- */
+#define DBG(d, fmt, args...) debug(fmt , ## args) +#define VDBG(d, fmt, args...) debug(fmt , ## args) +/* #define ERROR(d, fmt, args...) printf(fmt , ## args) */ +/* #define WARNING(d, fmt, args...) printf(fmt , ## args) */ +/* #define INFO(d, fmt, args...) printf(fmt , ## args) */
+/* #define DBG(d, fmt, args...) do { } while (0) */ +/* #define VDBG(d, fmt, args...) do { } while (0) */ +#define ERROR(d, fmt, args...) do { } while (0) +#define WARNING(d, fmt, args...) do { } while (0) +#define INFO(d, fmt, args...) do { } while (0)
+#ifdef DUMP_MSGS
+/* dump_msg(fsg, const char * label, const u8 * buf, unsigned length); */ +# define dump_msg(fsg, label, buf, length) do { \
- if (length < 512)
{ \
DBG(fsg, "%s, length %u:\n", label,
length); \
print_hex_dump(KERN_DEBUG, "",
DUMP_PREFIX_OFFSET, \
16, 1, buf, length,
0); \
- }
\ +} while (0)
+# define dump_cdb(fsg) do { } while (0)
+#else
+# define dump_msg(fsg, /* const char * */ label, \
/* const u8 * */ buf, /* unsigned */ length) do
{ } while (0) + +# ifdef VERBOSE_DEBUG
+# define dump_cdb(fsg) \
- print_hex_dump(KERN_DEBUG, "SCSI CDB: ",
DUMP_PREFIX_NONE, \
16, 1, (fsg)->cmnd, (fsg)->cmnd_size,
\ +
+# else
+# define dump_cdb(fsg) do { } while (0)
+# endif /* VERBOSE_DEBUG */
+#endif /* DUMP_MSGS */
+/*-------------------------------------------------------------------------*/
+/* SCSI device types */ +#define TYPE_DISK 0x00 +#define TYPE_CDROM 0x05
+/* USB protocol value = the transport method */ +#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */ +#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */ +#define USB_PR_BULK 0x50 /* Bulk-only */ + +/* USB subclass value = the protocol encapsulation */ +#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */ +#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */ +#define USB_SC_QIC 0x03 /* QIC-157 (tape) */ +#define USB_SC_UFI 0x04 /* UFI (floppy) */ +#define USB_SC_8070 0x05 /* SFF-8070i (removable) */ +#define USB_SC_SCSI 0x06 /* Transparent SCSI */ + +/* Bulk-only data structures */
+/* Command Block Wrapper */ +struct fsg_bulk_cb_wrap {
- __le32 Signature; /* Contains 'USBC' */
- u32 Tag; /* Unique per command
id */
- __le32 DataTransferLength; /* 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
+/* Bulk-only class specific requests */ +#define USB_BULK_RESET_REQUEST 0xff +#define USB_BULK_GET_MAX_LUN_REQUEST 0xfe
+/* CBI Interrupt data structure */ +struct interrupt_data {
- u8 bType;
- u8 bValue;
+};
+#define CBI_INTERRUPT_DATA_LEN 2
+/* CBI Accept Device-Specific Command request */ +#define USB_CBI_ADSC_REQUEST 0x00
+/* Length of a SCSI Command Data Block */ +#define MAX_COMMAND_SIZE 16
+/* SCSI commands that we recognize */ +#define SC_FORMAT_UNIT 0x04 +#define SC_INQUIRY 0x12 +#define SC_MODE_SELECT_6 0x15 +#define SC_MODE_SELECT_10 0x55 +#define SC_MODE_SENSE_6 0x1a +#define SC_MODE_SENSE_10 0x5a +#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e +#define SC_READ_6 0x08 +#define SC_READ_10 0x28 +#define SC_READ_12 0xa8 +#define SC_READ_CAPACITY 0x25 +#define SC_READ_FORMAT_CAPACITIES 0x23 +#define SC_READ_HEADER 0x44 +#define SC_READ_TOC 0x43 +#define SC_RELEASE 0x17 +#define SC_REQUEST_SENSE 0x03 +#define SC_RESERVE 0x16 +#define SC_SEND_DIAGNOSTIC 0x1d +#define SC_START_STOP_UNIT 0x1b +#define SC_SYNCHRONIZE_CACHE 0x35 +#define SC_TEST_UNIT_READY 0x00 +#define SC_VERIFY 0x2f +#define SC_WRITE_6 0x0a +#define SC_WRITE_10 0x2a +#define SC_WRITE_12 0xaa
+/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */ +#define SS_NO_SENSE 0 +#define SS_COMMUNICATION_FAILURE 0x040800 +#define SS_INVALID_COMMAND 0x052000 +#define SS_INVALID_FIELD_IN_CDB 0x052400 +#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100 +#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500 +#define SS_MEDIUM_NOT_PRESENT 0x023a00 +#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302 +#define SS_NOT_READY_TO_READY_TRANSITION 0x062800 +#define SS_RESET_OCCURRED 0x062900 +#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900 +#define SS_UNRECOVERED_READ_ERROR 0x031100 +#define SS_WRITE_ERROR 0x030c02 +#define SS_WRITE_PROTECTED 0x072700
+#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */ +#define ASC(x) ((u8) ((x) >> 8)) +#define ASCQ(x) ((u8) (x))
+struct device_attribute { int i; }; +#define ETOOSMALL 525
+/*-------------------------------------------------------------------------*/
+struct fsg_lun {
- loff_t file_length;
- loff_t num_sectors;
- unsigned int initially_ro:1;
- unsigned int ro:1;
- unsigned int removable:1;
- unsigned int cdrom:1;
- unsigned int prevent_medium_removal:1;
- unsigned int registered:1;
- unsigned int info_valid:1;
- unsigned int nofua:1;
- u32 sense_data;
- u32 sense_data_info;
- u32 unit_attention_data;
- struct device dev;
+};
+#define fsg_lun_is_open(curlun) ((curlun)->filp != NULL) +/* Big enough to hold our biggest descriptor */ +#define EP0_BUFSIZE 256 +#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */ + +/* Number of buffers we will use. 2 is enough for double-buffering */ +#define FSG_NUM_BUFFERS 2
+/* Default size of buffer length. */ +#define FSG_BUFLEN ((u32)16384)
+/* Maximal number of LUNs supported in mass storage function */ +#define FSG_MAX_LUNS 8
+enum fsg_buffer_state {
- BUF_STATE_EMPTY = 0,
- BUF_STATE_FULL,
- BUF_STATE_BUSY
+};
+struct fsg_buffhd { +#ifdef FSG_BUFFHD_STATIC_BUFFER
- char buf[FSG_BUFLEN];
+#else
- void *buf;
+#endif
- enum fsg_buffer_state state;
- struct fsg_buffhd *next;
- /*
* The NetChip 2280 is faster, and handles some protocol
faults
* better, if we don't submit any short bulk-out read
requests.
* So we will record the intended request length here.
*/
- unsigned int bulk_out_intended_length;
- struct usb_request *inreq;
- int inreq_busy;
- struct usb_request *outreq;
- int outreq_busy;
+};
+enum fsg_state {
- /* This one isn't used anywhere */
- FSG_STATE_COMMAND_PHASE = -10,
- FSG_STATE_DATA_PHASE,
- FSG_STATE_STATUS_PHASE,
- FSG_STATE_IDLE = 0,
- FSG_STATE_ABORT_BULK_OUT,
- FSG_STATE_RESET,
- FSG_STATE_INTERFACE_CHANGE,
- FSG_STATE_CONFIG_CHANGE,
- FSG_STATE_DISCONNECT,
- FSG_STATE_EXIT,
- FSG_STATE_TERMINATED
+};
+enum data_direction {
- DATA_DIR_UNKNOWN = 0,
- DATA_DIR_FROM_HOST,
- DATA_DIR_TO_HOST,
- DATA_DIR_NONE
+};
+/*-------------------------------------------------------------------------*/
+static inline u32 get_unaligned_be24(u8 *buf) +{
- return 0xffffff & (u32) get_unaligned_be32(buf - 1);
+}
+/*-------------------------------------------------------------------------*/
+enum { +#ifndef FSG_NO_DEVICE_STRINGS
- FSG_STRING_MANUFACTURER = 1,
- FSG_STRING_PRODUCT,
- FSG_STRING_SERIAL,
- FSG_STRING_CONFIG,
+#endif
- FSG_STRING_INTERFACE
+};
+#ifndef FSG_NO_OTG +static struct usb_otg_descriptor +fsg_otg_desc = {
- .bLength = sizeof(fsg_otg_desc),
- .bDescriptorType = USB_DT_OTG,
- .bmAttributes = USB_OTG_SRP,
+}; +#endif
+#endif /* __F_MASS_STORAGE_H_ */
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

split the macro and data struct in f_mass_storage.c to f_mass_storage.h
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- drivers/usb/gadget/f_mass_storage.c | 108 --------------------------------- include/f_mass_storage.h | 116 ++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 108 deletions(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 1ecb92a..7164655 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -274,15 +274,6 @@ static const char fsg_string_interface[] = "Mass Storage";
/*-------------------------------------------------------------------------*/
-#define GFP_ATOMIC ((gfp_t) 0) -#define PAGE_CACHE_SHIFT 12 -#define PAGE_CACHE_SIZE (1 << PAGE_CACHE_SHIFT) -#define kthread_create(...) __builtin_return_address(0) -#define wait_for_completion(...) do {} while (0) - -struct kref {int x; }; -struct completion {int x; }; - inline void set_bit(int nr, volatile void *addr) { int mask; @@ -303,105 +294,6 @@ inline void clear_bit(int nr, volatile void *addr) *a &= ~mask; }
-struct fsg_dev; -struct fsg_common; - -/* Data shared by all the FSG instances. */ -struct fsg_common { - struct usb_gadget *gadget; - struct fsg_dev *fsg, *new_fsg; - - struct usb_ep *ep0; /* Copy of gadget->ep0 */ - struct usb_request *ep0req; /* Copy of cdev->req */ - unsigned int ep0_req_tag; - - struct fsg_buffhd *next_buffhd_to_fill; - struct fsg_buffhd *next_buffhd_to_drain; - struct fsg_buffhd buffhds[FSG_NUM_BUFFERS]; - - int cmnd_size; - u8 cmnd[MAX_COMMAND_SIZE]; - - unsigned int nluns; - unsigned int lun; - struct fsg_lun luns[FSG_MAX_LUNS]; - - unsigned int bulk_out_maxpacket; - enum fsg_state state; /* For exception handling */ - unsigned int exception_req_tag; - - enum data_direction data_dir; - u32 data_size; - u32 data_size_from_cmnd; - u32 tag; - u32 residue; - u32 usb_amount_left; - - unsigned int can_stall:1; - unsigned int free_storage_on_release:1; - unsigned int phase_error:1; - unsigned int short_packet_received:1; - unsigned int bad_lun_okay:1; - unsigned int running:1; - - int thread_wakeup_needed; - struct completion thread_notifier; - struct task_struct *thread_task; - - /* Callback functions. */ - const struct fsg_operations *ops; - /* Gadget's private data. */ - void *private_data; - - const char *vendor_name; /* 8 characters or less */ - const char *product_name; /* 16 characters or less */ - u16 release; - - /* Vendor (8 chars), product (16 chars), release (4 - * hexadecimal digits) and NUL byte */ - char inquiry_string[8 + 16 + 4 + 1]; - - struct kref ref; -}; - -struct fsg_config { - unsigned nluns; - struct fsg_lun_config { - const char *filename; - char ro; - char removable; - char cdrom; - char nofua; - } luns[FSG_MAX_LUNS]; - - /* Callback functions. */ - const struct fsg_operations *ops; - /* Gadget's private data. */ - void *private_data; - - const char *vendor_name; /* 8 characters or less */ - const char *product_name; /* 16 characters or less */ - - char can_stall; -}; - -struct fsg_dev { - struct usb_function function; - struct usb_gadget *gadget; /* Copy of cdev->gadget */ - struct fsg_common *common; - - u16 interface_number; - - unsigned int bulk_in_enabled:1; - unsigned int bulk_out_enabled:1; - - unsigned long atomic_bitflags; -#define IGNORE_BULK_OUT 0 - - struct usb_ep *bulk_in; - struct usb_ep *bulk_out; -}; -
static inline int __fsg_is_set(struct fsg_common *common, const char *func, unsigned line) diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h index 679f242..620af06 100644 --- a/include/f_mass_storage.h +++ b/include/f_mass_storage.h @@ -390,4 +390,120 @@ fsg_otg_desc = { }; #endif
+ + + + +#define GFP_ATOMIC ((gfp_t) 0) +#define PAGE_CACHE_SHIFT 12 +#define PAGE_CACHE_SIZE (1 << PAGE_CACHE_SHIFT) +#define kthread_create(...) __builtin_return_address(0) +#define wait_for_completion(...) do {} while (0) + +struct kref {int x; }; +struct completion {int x; }; + + +struct fsg_dev; +struct fsg_common; + +/* Data shared by all the FSG instances. */ +struct fsg_common { + struct usb_gadget *gadget; + struct fsg_dev *fsg, *new_fsg; + + struct usb_ep *ep0; /* Copy of gadget->ep0 */ + struct usb_request *ep0req; /* Copy of cdev->req */ + unsigned int ep0_req_tag; + + struct fsg_buffhd *next_buffhd_to_fill; + struct fsg_buffhd *next_buffhd_to_drain; + struct fsg_buffhd buffhds[FSG_NUM_BUFFERS]; + + int cmnd_size; + u8 cmnd[MAX_COMMAND_SIZE]; + + unsigned int nluns; + unsigned int lun; + struct fsg_lun luns[FSG_MAX_LUNS]; + + unsigned int bulk_out_maxpacket; + enum fsg_state state; /* For exception handling */ + unsigned int exception_req_tag; + + enum data_direction data_dir; + u32 data_size; + u32 data_size_from_cmnd; + u32 tag; + u32 residue; + u32 usb_amount_left; + + unsigned int can_stall:1; + unsigned int free_storage_on_release:1; + unsigned int phase_error:1; + unsigned int short_packet_received:1; + unsigned int bad_lun_okay:1; + unsigned int running:1; + + int thread_wakeup_needed; + struct completion thread_notifier; + struct task_struct *thread_task; + + /* Callback functions. */ + const struct fsg_operations *ops; + /* Gadget's private data. */ + void *private_data; + + const char *vendor_name; /* 8 characters or less */ + const char *product_name; /* 16 characters or less */ + u16 release; + + /* Vendor (8 chars), product (16 chars), release (4 + * hexadecimal digits) and NUL byte */ + char inquiry_string[8 + 16 + 4 + 1]; + + struct kref ref; +}; + +struct fsg_config { + unsigned nluns; + struct fsg_lun_config { + const char *filename; + char ro; + char removable; + char cdrom; + char nofua; + } luns[FSG_MAX_LUNS]; + + /* Callback functions. */ + const struct fsg_operations *ops; + /* Gadget's private data. */ + void *private_data; + + const char *vendor_name; /* 8 characters or less */ + const char *product_name; /* 16 characters or less */ + + char can_stall; +}; + +struct fsg_dev { + struct usb_function function; + struct usb_gadget *gadget; /* Copy of cdev->gadget */ + struct fsg_common *common; + + u16 interface_number; + + unsigned int bulk_in_enabled:1; + unsigned int bulk_out_enabled:1; + + unsigned long atomic_bitflags; +#define IGNORE_BULK_OUT 0 + + struct usb_ep *bulk_in; + struct usb_ep *bulk_out; +}; + #endif /* __F_MASS_STORAGE_H_ */ + + +

Hi Eddie,
split the macro and data struct in f_mass_storage.c to f_mass_storage.h
The same comment as to patch 1/9
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

storage_common.c is only used by f_mass_storage. so merge it.
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- drivers/usb/gadget/f_mass_storage.c | 222 ++++++++++++++++++++++++++++++++- drivers/usb/gadget/storage_common.c | 238 ------------------------------------ 2 files changed, 221 insertions(+), 239 deletions(-) delete mode 100644 drivers/usb/gadget/storage_common.c
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 7164655..eb2ff82 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -270,7 +270,227 @@ static const char fsg_string_interface[] = "Mass Storage"; #define FSG_NO_OTG 1 #define FSG_NO_INTR_EP 1
-#include "storage_common.c" +#include <f_mass_storage.h> + +/* There is only one interface. */ + +static struct usb_interface_descriptor +fsg_intf_desc = { + .bLength = sizeof(fsg_intf_desc), + .bDescriptorType = USB_DT_INTERFACE, + + .bNumEndpoints = 2, /* Adjusted during fsg_bind() */ + .bInterfaceClass = USB_CLASS_MASS_STORAGE, + .bInterfaceSubClass = USB_SC_SCSI, /* Adjusted during fsg_bind() */ + .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ + .iInterface = FSG_STRING_INTERFACE, +}; + +/* + * Three full-speed endpoint descriptors: bulk-in, bulk-out, and + * interrupt-in. + */ + +static struct usb_endpoint_descriptor +fsg_fs_bulk_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + + .bEndpointAddress = USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + /* wMaxPacketSize set by autoconfiguration */ +}; + +static struct usb_endpoint_descriptor +fsg_fs_bulk_out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + + .bEndpointAddress = USB_DIR_OUT, + .bmAttributes = USB_ENDPOINT_XFER_BULK, + /* wMaxPacketSize set by autoconfiguration */ +}; + +#ifndef FSG_NO_INTR_EP + +static struct usb_endpoint_descriptor +fsg_fs_intr_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + + .bEndpointAddress = USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = cpu_to_le16(2), + .bInterval = 32, /* frames -> 32 ms */ +}; + +#ifndef FSG_NO_OTG +# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2 +#else +# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 1 +#endif + +#endif + +static struct usb_descriptor_header *fsg_fs_function[] = { +#ifndef FSG_NO_OTG + (struct usb_descriptor_header *)&fsg_otg_desc, +#endif + (struct usb_descriptor_header *)&fsg_intf_desc, + (struct usb_descriptor_header *)&fsg_fs_bulk_in_desc, + (struct usb_descriptor_header *)&fsg_fs_bulk_out_desc, +#ifndef FSG_NO_INTR_EP + (struct usb_descriptor_header *)&fsg_fs_intr_in_desc, +#endif + NULL, +}; + +/* + * USB 2.0 devices need to expose both high speed and full speed + * descriptors, unless they only run at full speed. + * + * That means alternate endpoint descriptors (bigger packets) + * and a "device qualifier" ... plus more construction options + * for the configuration descriptor. + */ +static struct usb_endpoint_descriptor +fsg_hs_bulk_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + + /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */ + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(512), +}; + +static struct usb_endpoint_descriptor +fsg_hs_bulk_out_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + + /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */ + .bmAttributes = USB_ENDPOINT_XFER_BULK, + .wMaxPacketSize = cpu_to_le16(512), + .bInterval = 1, /* NAK every 1 uframe */ +}; + +#ifndef FSG_NO_INTR_EP + +static struct usb_endpoint_descriptor +fsg_hs_intr_in_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + + /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = cpu_to_le16(2), + .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */ +}; + +#ifndef FSG_NO_OTG +# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2 +#else +# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 1 +#endif + +#endif + +static struct usb_descriptor_header *fsg_hs_function[] = { +#ifndef FSG_NO_OTG + (struct usb_descriptor_header *)&fsg_otg_desc, +#endif + (struct usb_descriptor_header *)&fsg_intf_desc, + (struct usb_descriptor_header *)&fsg_hs_bulk_in_desc, + (struct usb_descriptor_header *)&fsg_hs_bulk_out_desc, +#ifndef FSG_NO_INTR_EP + (struct usb_descriptor_header *)&fsg_hs_intr_in_desc, +#endif + NULL, +}; + +/* Maxpacket and other transfer characteristics vary by speed. */ +static struct usb_endpoint_descriptor *fsg_ep_desc( + struct usb_gadget *g, + struct usb_endpoint_descriptor *fs, + struct usb_endpoint_descriptor *hs) +{ + if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) + return hs; + return fs; +} + +/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ +static struct usb_string fsg_strings[] = { +#ifndef FSG_NO_DEVICE_STRINGS + {FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, + {FSG_STRING_PRODUCT, fsg_string_product}, + {FSG_STRING_SERIAL, fsg_string_serial}, + {FSG_STRING_CONFIG, fsg_string_config}, +#endif + {FSG_STRING_INTERFACE, fsg_string_interface}, + {} +}; + +static struct usb_gadget_strings fsg_stringtab = { + .language = 0x0409, /* en-us */ + .strings = fsg_strings, +}; + +/*-------------------------------------------------------------------------*/ + +/* + * If the next two routines are called while the gadget is registered, + * the caller must own fsg->filesem for writing. + */ + +static int fsg_lun_open(struct fsg_lun *curlun, unsigned int num_sectors, + const char *filename) +{ + int ro; + + /* R/W if we can, R/O if we must */ + ro = curlun->initially_ro; + + curlun->ro = ro; + curlun->file_length = num_sectors << 9; + curlun->num_sectors = num_sectors; + debug("open backing file: %s\n", filename); + + return 0; +} + +static void fsg_lun_close(struct fsg_lun *curlun) +{ +} + +/*-------------------------------------------------------------------------*/ + +/* + * Sync the file data, don't bother with the metadata. + * This code was copied from fs/buffer.c:sys_fdatasync(). + */ +static int fsg_lun_fsync_sub(struct fsg_lun *curlun) +{ + return 0; +} + +static void store_cdrom_address(u8 *dest, int msf, u32 addr) +{ + if (msf) { + /* Convert to Minutes-Seconds-Frames */ + addr >>= 2; /* Convert to 2048-byte frames */ + addr += 2*75; /* Lead-in occupies 2 seconds */ + dest[3] = addr % 75; /* Frames */ + addr /= 75; + dest[2] = addr % 60; /* Seconds */ + addr /= 60; + dest[1] = addr; /* Minutes */ + dest[0] = 0; /* Reserved */ + } else { + /* Absolute sector */ + put_unaligned_be32(addr, dest); + } +}
/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c deleted file mode 100644 index bea7607..0000000 --- a/drivers/usb/gadget/storage_common.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * storage_common.c -- Common definitions for mass storage functionality - * - * Copyright (C) 2003-2008 Alan Stern - * Copyeight (C) 2009 Samsung Electronics - * Author: Michal Nazarewicz (m.nazarewicz@samsung.com) - * - * Ported to u-boot: - * Andrzej Pietrasiewicz andrzej.p@samsung.com - * - * Code refactoring & cleanup: - * Łukasz Majewski l.majewski@samsung.com - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include <f_mass_storage.h> - -/* There is only one interface. */ - -static struct usb_interface_descriptor -fsg_intf_desc = { - .bLength = sizeof fsg_intf_desc, - .bDescriptorType = USB_DT_INTERFACE, - - .bNumEndpoints = 2, /* Adjusted during fsg_bind() */ - .bInterfaceClass = USB_CLASS_MASS_STORAGE, - .bInterfaceSubClass = USB_SC_SCSI, /* Adjusted during fsg_bind() */ - .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */ - .iInterface = FSG_STRING_INTERFACE, -}; - -/* - * Three full-speed endpoint descriptors: bulk-in, bulk-out, and - * interrupt-in. - */ - -static struct usb_endpoint_descriptor -fsg_fs_bulk_in_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - - .bEndpointAddress = USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - /* wMaxPacketSize set by autoconfiguration */ -}; - -static struct usb_endpoint_descriptor -fsg_fs_bulk_out_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - - .bEndpointAddress = USB_DIR_OUT, - .bmAttributes = USB_ENDPOINT_XFER_BULK, - /* wMaxPacketSize set by autoconfiguration */ -}; - -#ifndef FSG_NO_INTR_EP - -static struct usb_endpoint_descriptor -fsg_fs_intr_in_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - - .bEndpointAddress = USB_DIR_IN, - .bmAttributes = USB_ENDPOINT_XFER_INT, - .wMaxPacketSize = cpu_to_le16(2), - .bInterval = 32, /* frames -> 32 ms */ -}; - -#ifndef FSG_NO_OTG -# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2 -#else -# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 1 -#endif - -#endif - -static struct usb_descriptor_header *fsg_fs_function[] = { -#ifndef FSG_NO_OTG - (struct usb_descriptor_header *) &fsg_otg_desc, -#endif - (struct usb_descriptor_header *) &fsg_intf_desc, - (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc, - (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc, -#ifndef FSG_NO_INTR_EP - (struct usb_descriptor_header *) &fsg_fs_intr_in_desc, -#endif - NULL, -}; - -/* - * USB 2.0 devices need to expose both high speed and full speed - * descriptors, unless they only run at full speed. - * - * That means alternate endpoint descriptors (bigger packets) - * and a "device qualifier" ... plus more construction options - * for the configuration descriptor. - */ -static struct usb_endpoint_descriptor -fsg_hs_bulk_in_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - - /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */ - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(512), -}; - -static struct usb_endpoint_descriptor -fsg_hs_bulk_out_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - - /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */ - .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = cpu_to_le16(512), - .bInterval = 1, /* NAK every 1 uframe */ -}; - -#ifndef FSG_NO_INTR_EP - -static struct usb_endpoint_descriptor -fsg_hs_intr_in_desc = { - .bLength = USB_DT_ENDPOINT_SIZE, - .bDescriptorType = USB_DT_ENDPOINT, - - /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ - .bmAttributes = USB_ENDPOINT_XFER_INT, - .wMaxPacketSize = cpu_to_le16(2), - .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */ -}; - -#ifndef FSG_NO_OTG -# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2 -#else -# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 1 -#endif - -#endif - -static struct usb_descriptor_header *fsg_hs_function[] = { -#ifndef FSG_NO_OTG - (struct usb_descriptor_header *) &fsg_otg_desc, -#endif - (struct usb_descriptor_header *) &fsg_intf_desc, - (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc, - (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc, -#ifndef FSG_NO_INTR_EP - (struct usb_descriptor_header *) &fsg_hs_intr_in_desc, -#endif - NULL, -}; - -/* Maxpacket and other transfer characteristics vary by speed. */ -static struct usb_endpoint_descriptor * -fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs, - struct usb_endpoint_descriptor *hs) -{ - if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) - return hs; - return fs; -} - -/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */ -static struct usb_string fsg_strings[] = { -#ifndef FSG_NO_DEVICE_STRINGS - {FSG_STRING_MANUFACTURER, fsg_string_manufacturer}, - {FSG_STRING_PRODUCT, fsg_string_product}, - {FSG_STRING_SERIAL, fsg_string_serial}, - {FSG_STRING_CONFIG, fsg_string_config}, -#endif - {FSG_STRING_INTERFACE, fsg_string_interface}, - {} -}; - -static struct usb_gadget_strings fsg_stringtab = { - .language = 0x0409, /* en-us */ - .strings = fsg_strings, -}; - -/*-------------------------------------------------------------------------*/ - -/* - * If the next two routines are called while the gadget is registered, - * the caller must own fsg->filesem for writing. - */ - -static int fsg_lun_open(struct fsg_lun *curlun, unsigned int num_sectors, - const char *filename) -{ - int ro; - - /* R/W if we can, R/O if we must */ - ro = curlun->initially_ro; - - curlun->ro = ro; - curlun->file_length = num_sectors << 9; - curlun->num_sectors = num_sectors; - debug("open backing file: %s\n", filename); - - return 0; -} - -static void fsg_lun_close(struct fsg_lun *curlun) -{ -} - -/*-------------------------------------------------------------------------*/ - -/* - * Sync the file data, don't bother with the metadata. - * This code was copied from fs/buffer.c:sys_fdatasync(). - */ -static int fsg_lun_fsync_sub(struct fsg_lun *curlun) -{ - return 0; -} - -static void store_cdrom_address(u8 *dest, int msf, u32 addr) -{ - if (msf) { - /* Convert to Minutes-Seconds-Frames */ - addr >>= 2; /* Convert to 2048-byte frames */ - addr += 2*75; /* Lead-in occupies 2 seconds */ - dest[3] = addr % 75; /* Frames */ - addr /= 75; - dest[2] = addr % 60; /* Seconds */ - addr /= 60; - dest[1] = addr; /* Minutes */ - dest[0] = 0; /* Reserved */ - } else { - /* Absolute sector */ - put_unaligned_be32(addr, dest); - } -} - -/*-------------------------------------------------------------------------*/

Hi Eddie,
storage_common.c is only used by f_mass_storage. so merge it.
The same comment as to patch 1/9
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

remove static declaration of some functions. so these functions can be called by other module
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- drivers/usb/gadget/f_mass_storage.c | 4 ++-- include/f_mass_storage.h | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index eb2ff82..faf875e 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -775,7 +775,7 @@ static void busy_indicator(void) state = 0; }
-static int sleep_thread(struct fsg_common *common) +int sleep_thread(struct fsg_common *common) { int rc = 0; int i = 0, k = 0; @@ -1899,7 +1899,7 @@ static int check_command(struct fsg_common *common, int cmnd_size, }
-static int do_scsi_command(struct fsg_common *common) +int do_scsi_command(struct fsg_common *common) { struct fsg_buffhd *bh; int rc; diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h index 620af06..df6ea33 100644 --- a/include/f_mass_storage.h +++ b/include/f_mass_storage.h @@ -391,9 +391,6 @@ fsg_otg_desc = { #endif
- - - #define GFP_ATOMIC ((gfp_t) 0) #define PAGE_CACHE_SHIFT 12 #define PAGE_CACHE_SIZE (1 << PAGE_CACHE_SHIFT) @@ -503,7 +500,9 @@ struct fsg_dev { struct usb_ep *bulk_out; };
-#endif /* __F_MASS_STORAGE_H_ */ +int sleep_thread(struct fsg_common *common); +int do_scsi_command(struct fsg_common *common);
+#endif /* __F_MASS_STORAGE_H_ */

add functions to set and get usb interface descriptor, so people can customize usb interface descriptor
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- drivers/usb/gadget/f_mass_storage.c | 18 ++++++++++++++++++ include/f_mass_storage.h | 2 ++ 2 files changed, 20 insertions(+)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index faf875e..333f069 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2870,6 +2870,24 @@ static int fsg_bind_config(struct usb_composite_dev *cdev, return rc; }
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void) +{ + return &fsg_intf_desc; +} + +void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc) +{ + if (desc) { + fsg_intf_desc.bLength = desc->bLength; + fsg_intf_desc.bDescriptorType = desc->bDescriptorType; + fsg_intf_desc.bNumEndpoints = desc->bNumEndpoints; + fsg_intf_desc.bInterfaceClass = desc->bInterfaceClass; + fsg_intf_desc.bInterfaceSubClass = desc->bInterfaceSubClass; + fsg_intf_desc.bInterfaceProtocol = desc->bInterfaceProtocol; + fsg_intf_desc.iInterface = desc->iInterface; + } +} + int fsg_add(struct usb_configuration *c) { struct fsg_common *fsg_common; diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h index df6ea33..0cf29df 100644 --- a/include/f_mass_storage.h +++ b/include/f_mass_storage.h @@ -500,6 +500,8 @@ struct fsg_dev { struct usb_ep *bulk_out; };
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void); +void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc); int sleep_thread(struct fsg_common *common); int do_scsi_command(struct fsg_common *common);

Hi Eddie,
add functions to set and get usb interface descriptor, so people can customize usb interface descriptor
The f_mass_storage USB function is used through the g_dnl code:
./drivers/usb/gadget/g_dnl.c
Other gadget functions - like dfu and thor are using it.
Please consider following this scheme - for example look into the Samsung's Thor protocol support at:
./drivers/usb/gadget/f_thor.c
Since we managed to add Thor (vendor specific protocol), then it should be doable to add rockusb as well.
Another good example of this framework reuse is f_fastboot.c to support Android fastboot protocol.
Please consider if rockchip could be added in the same manner.
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/f_mass_storage.c | 18 ++++++++++++++++++ include/f_mass_storage.h | 2 ++ 2 files changed, 20 insertions(+)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index faf875e..333f069 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2870,6 +2870,24 @@ static int fsg_bind_config(struct usb_composite_dev *cdev, return rc; }
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void) +{
To adjust the usb descriptor one can use:
g_dnl_bind_fixup() function (defined at g_dnl.c).
It is used to adjust information added to USB file descriptor - e.g. board/samsung/common/gadget.c or board/siemens/common/factoryreset.c
- return &fsg_intf_desc;
+}
+void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc) +{
- if (desc) {
fsg_intf_desc.bLength = desc->bLength;
fsg_intf_desc.bDescriptorType =
desc->bDescriptorType;
fsg_intf_desc.bNumEndpoints = desc->bNumEndpoints;
fsg_intf_desc.bInterfaceClass =
desc->bInterfaceClass;
fsg_intf_desc.bInterfaceSubClass =
desc->bInterfaceSubClass;
fsg_intf_desc.bInterfaceProtocol =
desc->bInterfaceProtocol;
fsg_intf_desc.iInterface = desc->iInterface;
- }
+}
int fsg_add(struct usb_configuration *c) { struct fsg_common *fsg_common; diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h index df6ea33..0cf29df 100644 --- a/include/f_mass_storage.h +++ b/include/f_mass_storage.h @@ -500,6 +500,8 @@ struct fsg_dev { struct usb_ep *bulk_out; };
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void); +void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc); int sleep_thread(struct fsg_common *common); int do_scsi_command(struct fsg_common *common);
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

Hi Lukasz
2017-04-19 23:29 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi Eddie,
add functions to set and get usb interface descriptor, so people can customize usb interface descriptor
The f_mass_storage USB function is used through the g_dnl code:
./drivers/usb/gadget/g_dnl.c
Other gadget functions - like dfu and thor are using it.
Please consider following this scheme - for example look into the Samsung's Thor protocol support at:
./drivers/usb/gadget/f_thor.c
Since we managed to add Thor (vendor specific protocol), then it should be doable to add rockusb as well.
Another good example of this framework reuse is f_fastboot.c to support Android fastboot protocol.
Please consider if rockchip could be added in the same manner.
That is the same way i did in my V1 patches. can you review my V1 patches again and give some comment? that will be easy for me to address your comments at the same time. https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/f_mass_storage.c | 18 ++++++++++++++++++ include/f_mass_storage.h | 2 ++ 2 files changed, 20 insertions(+)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index faf875e..333f069 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2870,6 +2870,24 @@ static int fsg_bind_config(struct usb_composite_dev *cdev, return rc; }
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void) +{
To adjust the usb descriptor one can use:
g_dnl_bind_fixup() function (defined at g_dnl.c).
It is used to adjust information added to USB file descriptor - e.g. board/samsung/common/gadget.c or board/siemens/common/factoryreset.c
return &fsg_intf_desc;
+}
+void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc) +{
if (desc) {
fsg_intf_desc.bLength = desc->bLength;
fsg_intf_desc.bDescriptorType =
desc->bDescriptorType;
fsg_intf_desc.bNumEndpoints = desc->bNumEndpoints;
fsg_intf_desc.bInterfaceClass =
desc->bInterfaceClass;
fsg_intf_desc.bInterfaceSubClass =
desc->bInterfaceSubClass;
fsg_intf_desc.bInterfaceProtocol =
desc->bInterfaceProtocol;
fsg_intf_desc.iInterface = desc->iInterface;
}
+}
int fsg_add(struct usb_configuration *c) { struct fsg_common *fsg_common; diff --git a/include/f_mass_storage.h b/include/f_mass_storage.h index df6ea33..0cf29df 100644 --- a/include/f_mass_storage.h +++ b/include/f_mass_storage.h @@ -500,6 +500,8 @@ struct fsg_dev { struct usb_ep *bulk_out; };
+struct usb_interface_descriptor *fsg_get_usb_interface_descriptor(void); +void fsg_set_usb_interface_descriptor(struct usb_interface_descriptor *desc); int sleep_thread(struct fsg_common *common); int do_scsi_command(struct fsg_common *common);
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

add do_extra_command to let people deal with customized command
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- drivers/usb/gadget/f_mass_storage.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 333f069..d431e53 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2168,6 +2168,10 @@ unknown_cmnd: return 0; }
+int __weak do_extra_command(struct fsg_common *common) +{ + return -EINVAL; +} /*-------------------------------------------------------------------------*/
static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) @@ -2540,8 +2544,10 @@ int fsg_main_thread(void *common_) if (!exception_in_progress(common)) common->state = FSG_STATE_DATA_PHASE;
- if (do_scsi_command(common) || finish_reply(common)) + if ((do_extra_command(common) && do_scsi_command(common)) || + finish_reply(common)) { continue; + }
if (!exception_in_progress(common)) common->state = FSG_STATE_STATUS_PHASE;

Hi Eddie,
add do_extra_command to let people deal with customized command
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/f_mass_storage.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 333f069..d431e53 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2168,6 +2168,10 @@ unknown_cmnd: return 0; }
+int __weak do_extra_command(struct fsg_common *common) +{
- return -EINVAL;
+} /*-------------------------------------------------------------------------*/
static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) @@ -2540,8 +2544,10 @@ int fsg_main_thread(void *common_) if (!exception_in_progress(common)) common->state = FSG_STATE_DATA_PHASE;
if (do_scsi_command(common) || finish_reply(common))
if ((do_extra_command(common) &&
do_scsi_command(common)) ||
I must admit that I'm against mixing things. Let's leave f_mass_storage for mass storage and add f_rockchip_* for separate function.
If possible we can reuse as much as possible from f_*.c and g_dnl.* files.
finish_reply(common)) { continue;
}
if (!exception_in_progress(common)) common->state = FSG_STATE_STATUS_PHASE;
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

Hi Lukasz
2017-04-20 6:14 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi Eddie,
add do_extra_command to let people deal with customized command
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/f_mass_storage.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 333f069..d431e53 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2168,6 +2168,10 @@ unknown_cmnd: return 0; }
+int __weak do_extra_command(struct fsg_common *common) +{
return -EINVAL;
+} /*-------------------------------------------------------------------------*/
static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) @@ -2540,8 +2544,10 @@ int fsg_main_thread(void *common_) if (!exception_in_progress(common)) common->state = FSG_STATE_DATA_PHASE;
if (do_scsi_command(common) || finish_reply(common))
if ((do_extra_command(common) &&
do_scsi_command(common)) ||
I must admit that I'm against mixing things. Let's leave f_mass_storage for mass storage and add f_rockchip_* for separate function.
Do you mean add f_rockusb.c for rockusb function?
If possible we can reuse as much as possible from f_*.c and g_dnl.* files.
Yes, Totally agree. Can you review my V1 patches? I think that is what you expect. https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
finish_reply(common)) { continue;
} if (!exception_in_progress(common)) common->state = FSG_STATE_STATUS_PHASE;
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

Hi Eddie,
Hi Lukasz
2017-04-20 6:14 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi Eddie,
add do_extra_command to let people deal with customized command
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/f_mass_storage.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 333f069..d431e53 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2168,6 +2168,10 @@ unknown_cmnd: return 0; }
+int __weak do_extra_command(struct fsg_common *common) +{
return -EINVAL;
+} /*-------------------------------------------------------------------------*/
static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) @@ -2540,8 +2544,10 @@ int fsg_main_thread(void *common_) if (!exception_in_progress(common)) common->state = FSG_STATE_DATA_PHASE;
if (do_scsi_command(common) || finish_reply(common))
if ((do_extra_command(common) &&
do_scsi_command(common)) ||
I must admit that I'm against mixing things. Let's leave f_mass_storage for mass storage and add f_rockchip_* for separate function.
Do you mean add f_rockusb.c for rockusb function?
If possible we can reuse as much as possible from f_*.c and g_dnl.* files.
Yes, Totally agree. Can you review my V1 patches? I think that is what you expect. https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
No problem, I will look on them.
finish_reply(common)) { continue;
} if (!exception_in_progress(common)) common->state = FSG_STATE_STATUS_PHASE;
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

Hi,
Hi Eddie,
Hi Lukasz
2017-04-20 6:14 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi Eddie,
add do_extra_command to let people deal with customized command
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/f_mass_storage.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 333f069..d431e53 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2168,6 +2168,10 @@ unknown_cmnd: return 0; }
+int __weak do_extra_command(struct fsg_common *common) +{
return -EINVAL;
+} /*-------------------------------------------------------------------------*/
static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) @@ -2540,8 +2544,10 @@ int fsg_main_thread(void *common_) if (!exception_in_progress(common)) common->state = FSG_STATE_DATA_PHASE;
if (do_scsi_command(common) ||
finish_reply(common))
if ((do_extra_command(common) &&
do_scsi_command(common)) ||
I must admit that I'm against mixing things. Let's leave f_mass_storage for mass storage and add f_rockchip_* for separate function.
Do you mean add f_rockusb.c for rockusb function?
If possible we can reuse as much as possible from f_*.c and g_dnl.* files.
Yes, Totally agree. Can you review my V1 patches? I think that is what you expect. https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
No problem, I will look on them.
One more remark/nit:
It is very useful to add info regarding changes between versions:
--- Changes for v3: - -
Changes for v2: - Moved from f_rockchip_* to f_mass_storage - Combine storage_common.c file with f_mass_storage.c
finish_reply(common)) { continue;
} if (!exception_in_progress(common)) common->state = FSG_STATE_STATUS_PHASE;
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

HI Lukasz
2017-04-20 17:14 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi,
Hi Eddie,
Hi Lukasz
2017-04-20 6:14 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi Eddie,
add do_extra_command to let people deal with customized command
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
drivers/usb/gadget/f_mass_storage.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index 333f069..d431e53 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -2168,6 +2168,10 @@ unknown_cmnd: return 0; }
+int __weak do_extra_command(struct fsg_common *common) +{
return -EINVAL;
+} /*-------------------------------------------------------------------------*/
static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) @@ -2540,8 +2544,10 @@ int fsg_main_thread(void *common_) if (!exception_in_progress(common)) common->state = FSG_STATE_DATA_PHASE;
if (do_scsi_command(common) ||
finish_reply(common))
if ((do_extra_command(common) &&
do_scsi_command(common)) ||
I must admit that I'm against mixing things. Let's leave f_mass_storage for mass storage and add f_rockchip_* for separate function.
Do you mean add f_rockusb.c for rockusb function?
If possible we can reuse as much as possible from f_*.c and g_dnl.* files.
Yes, Totally agree. Can you review my V1 patches? I think that is what you expect. https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
No problem, I will look on them.
One more remark/nit:
It is very useful to add info regarding changes between versions:
Changes for v3:
Changes for v2:
- Moved from f_rockchip_* to f_mass_storage
- Combine storage_common.c file with f_mass_storage.c
Got it. Thanks for reminding. I will add it in next version.
finish_reply(common)) { continue;
} if (!exception_in_progress(common)) common->state = FSG_STATE_STATUS_PHASE;
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

this patch add rockusb command. the usage is rockusb <USB_controller> [<devtype>] <devnum> e.g. rockusb 0 mmc 0
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- cmd/Kconfig | 5 + cmd/Makefile | 1 + cmd/rockusb.c | 383 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 389 insertions(+) create mode 100644 cmd/rockusb.c
diff --git a/cmd/Kconfig b/cmd/Kconfig index 661ae7a..c94f509 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -509,6 +509,11 @@ 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" + help + enables the rockusb command. + config CMD_USB_MASS_STORAGE bool "UMS usb mass storage" help diff --git a/cmd/Makefile b/cmd/Makefile index ef1406b..9111ba3 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -112,6 +112,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 diff --git a/cmd/rockusb.c b/cmd/rockusb.c new file mode 100644 index 0000000..883db09 --- /dev/null +++ b/cmd/rockusb.c @@ -0,0 +1,383 @@ +/* + * Copyright (C) 2017 Eddie Cai eddie.cai.linux@gmail.com + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <command.h> +#include <console.h> +#include <f_mass_storage.h> +#include <g_dnl.h> +#include <usb.h> +#include <usb_mass_storage.h> + +#define K_FW_TEST_UNIT_READY 0x00 +#define K_FW_READ_FLASH_ID 0x01 +#define K_FW_SET_DEVICE_ID 0x02 +#define K_FW_TEST_BAD_BLOCK 0x03 +#define K_FW_READ_10 0x04 +#define K_FW_WRITE_10 0x05 +#define K_FW_ERASE_10 0x06 +#define K_FW_WRITE_SPARE 0x07 +#define K_FW_READ_SPARE 0x08 + +#define K_FW_ERASE_10_FORCE 0x0b +#define K_FW_GET_VERSION 0x0c + +#define K_FW_LBA_READ_10 0x14 +#define K_FW_LBA_WRITE_10 0x15 +#define K_FW_ERASE_SYS_DISK 0x16 +#define K_FW_SDRAM_READ_10 0x17 +#define K_FW_SDRAM_WRITE_10 0x18 +#define K_FW_SDRAM_EXECUTE 0x19 +#define K_FW_READ_FLASH_INFO 0x1A +#define K_FW_GET_CHIP_VER 0x1B +#define K_FW_LOW_FORMAT 0x1C +#define K_FW_SET_RESET_FLAG 0x1E +#define K_FW_SPI_READ_10 0x21 +#define K_FW_SPI_WRITE_10 0x22 + +#define K_FW_SESSION 0X30 +#define K_FW_RESET 0xff + +#define ROCKUSB_INTERFACE_CLASS 0xff +#define ROCKUSB_INTERFACE_SUB_CLASS 0x06 +#define ROCKUSB_INTERFACE_PROTOCOL 0x05 + +static struct usb_interface_descriptor rockusb_desc = { + .bLength = USB_DT_INTERFACE_SIZE, + .bDescriptorType = USB_DT_INTERFACE, + .bNumEndpoints = 0x02, + .bInterfaceClass = ROCKUSB_INTERFACE_CLASS, + .bInterfaceSubClass = ROCKUSB_INTERFACE_SUB_CLASS, + .bInterfaceProtocol = ROCKUSB_INTERFACE_PROTOCOL, + .iInterface = FSG_STRING_INTERFACE, +}; + +int __weak rkusb_set_reboot_flag(int flag) +{ + printf("rkusb_set_reboot_flag: %d\n", flag); + return -ENOSYS; +} + +static void rkusb_do_reset(struct usb_ep *ep, struct usb_request *req) +{ + do_reset(NULL, 0, 0, NULL); +} + +#ifdef DEBUG +static void printcbw(struct fsg_bulk_cb_wrap *cbw) +{ + debug("cbw: Signature:%x\n", cbw->Signature); + debug("cbw: Tag=%x\n", cbw->Tag); + debug("cbw: DataTransferLength=%d\n", cbw->DataTransferLength); + debug("cbw: Flags=%x\n", cbw->Flags); + debug("cbw: Lun=%d\n", cbw->Lun); + debug("cbw: Length=%d\n", cbw->Length); + debug("cbw: ucOperCode=%x\n", cbw->CDB[0]); + debug("cbw: ucReserved=%x\n", cbw->CDB[1]); + debug( + "cbw: dwAddress:%x %x %x %x\n", + cbw->CDB[5], cbw->CDB[4], cbw->CDB[3], cbw->CDB[2]); + debug("cbw: ucReserved2=%x\n", cbw->CDB[6]); + debug("cbw: usLength:%x %x\n", cbw->CDB[8], cbw->CDB[7]); +} + +static void printcsw(struct bulk_cs_wrap *csw) +{ + debug("csw: Signature:%x\n", csw->Signature); + debug("csw: Tag:%x\n", csw->Tag); + debug("csw: Residue:%x\n", csw->Residue); + debug("csw: Status:%x\n", csw->Status); +} +#endif + +int do_extra_command(struct fsg_common *common) +{ + struct fsg_buffhd *bh; + int rc, reply = -EINVAL; + struct usb_interface_descriptor *desc; + + desc = fsg_get_usb_interface_descriptor(); + /* make sure we are dealing with rockusb protocol */ + if (desc->bInterfaceClass != ROCKUSB_INTERFACE_CLASS || + desc->bInterfaceSubClass != ROCKUSB_INTERFACE_SUB_CLASS || + desc->bInterfaceProtocol != ROCKUSB_INTERFACE_PROTOCOL){ + return reply; + } + + /* Wait for the next buffer to become available for data or status */ + bh = common->next_buffhd_to_fill; + common->next_buffhd_to_drain = bh; +#ifdef DEBUG + struct usb_request *req; + struct fsg_bulk_cb_wrap *cbw; + req = bh->outreq; + cbw = req->buf; + printcbw(cbw); +#endif + debug("%s: cmd=%d\n", __func__, common->cmnd[0]); + while (bh->state != BUF_STATE_EMPTY) { + rc = sleep_thread(common); + if (rc) + return rc; + } + common->phase_error = 0; + common->short_packet_received = 0; + + switch (common->cmnd[0]) { + case K_FW_RESET: + common->data_size_from_cmnd = common->cmnd[4]; + rkusb_set_reboot_flag(common->cmnd[1]); + bh->inreq->complete = rkusb_do_reset; + bh->state = BUF_STATE_EMPTY; + bh->inreq->length = USB_BULK_CS_WRAP_LEN; + common->residue -= USB_BULK_CS_WRAP_LEN; + return 0; + case K_FW_LBA_WRITE_10: + common->cmnd[0] = SC_WRITE_10; + common->data_dir = DATA_DIR_FROM_HOST; + common->data_size_from_cmnd = + get_unaligned_be16(&common->cmnd[7]) << 9; + common->data_size = common->data_size_from_cmnd; + do_scsi_command(common); + return 0; + default: + return reply; + } + return reply; +} + +static int rkusb_read_sector(struct ums *rkusb_dev, + ulong start, lbaint_t blkcnt, void *buf) +{ + struct blk_desc *block_dev = &rkusb_dev->block_dev; + lbaint_t blkstart = start + rkusb_dev->start_sector; + + return blk_dread(block_dev, blkstart, blkcnt, buf); +} + +static int rkusb_write_sector(struct ums *rkusb_dev, + ulong start, lbaint_t blkcnt, const void *buf) +{ + struct blk_desc *block_dev = &rkusb_dev->block_dev; + lbaint_t blkstart = start + rkusb_dev->start_sector; + + return blk_dwrite(block_dev, blkstart, blkcnt, buf); +} + +static struct ums *rkusb; +static int rkusb_count; + +static void rkusb_fini(void) +{ + int i; + + for (i = 0; i < rkusb_count; i++) + free((void *)rkusb[i].name); + free(rkusb); + rkusb = 0; + rkusb_count = 0; +} + +#define ROCKUSB_NAME_LEN 16 + +static int rkusb_init(const char *devtype, const char *devnrkusb_part_str) +{ + char *s, *t, *devnum_part_str, *name; + struct blk_desc *block_dev; + disk_partition_t info; + int partnum; + int ret = -1; + struct ums *rkusb_new; + + s = strdup(devnrkusb_part_str); + if (!s) + return -1; + + t = s; + rkusb_count = 0; + + for (;;) { + devnum_part_str = strsep(&t, ","); + if (!devnum_part_str) + break; + + partnum = blk_get_device_part_str(devtype, devnum_part_str, + &block_dev, &info, 1); + + if (partnum < 0) + goto cleanup; + + /* Check if the argument is in legacy format. If yes, + * expose all partitions by setting the partnum = 0 + * e.g. rkusb 0 mmc 0 + */ + if (!strchr(devnum_part_str, ':')) + partnum = 0; + + /* f_mass_storage.c assumes SECTOR_SIZE sectors */ + if (block_dev->blksz != SECTOR_SIZE) + goto cleanup; + + rkusb_new = realloc(rkusb, (rkusb_count + 1) * sizeof(*rkusb)); + if (!rkusb_new) + goto cleanup; + rkusb = rkusb_new; + + /* if partnum = 0, expose all partitions */ + if (partnum == 0) { + rkusb[rkusb_count].start_sector = 0; + rkusb[rkusb_count].num_sectors = block_dev->lba; + } else { + rkusb[rkusb_count].start_sector = info.start; + rkusb[rkusb_count].num_sectors = info.size; + } + + rkusb[rkusb_count].read_sector = rkusb_read_sector; + rkusb[rkusb_count].write_sector = rkusb_write_sector; + + name = malloc(ROCKUSB_NAME_LEN); + if (!name) + goto cleanup; + snprintf(name, ROCKUSB_NAME_LEN, "rkusb disk %d", rkusb_count); + rkusb[rkusb_count].name = name; + rkusb[rkusb_count].block_dev = *block_dev; + + printf("ROCKUSB: LUN %d, dev %d, hwpart %d, sector %#x, count %#x\n", + rkusb_count, rkusb[rkusb_count].block_dev.devnum, + rkusb[rkusb_count].block_dev.hwpart, + rkusb[rkusb_count].start_sector, + rkusb[rkusb_count].num_sectors); + + rkusb_count++; + } + + if (rkusb_count) + ret = 0; + +cleanup: + free(s); + + if (ret < 0) + rkusb_fini(); + + return ret; +} + +static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{ + const char *usb_controller; + const char *devtype; + const char *devnum; + unsigned int controller_index; + int rc; + int cable_ready_timeout __maybe_unused; + struct usb_interface_descriptor desc; + + if (argc < 3) + return CMD_RET_USAGE; + + usb_controller = argv[1]; + if (argc >= 4) { + devtype = argv[2]; + devnum = argv[3]; + } else { + devtype = "mmc"; + devnum = argv[2]; + } + + rc = rkusb_init(devtype, devnum); + if (rc < 0) + return CMD_RET_FAILURE; + + controller_index = (unsigned int)(simple_strtoul( + usb_controller, NULL, 0)); + if (board_usb_init(controller_index, USB_INIT_DEVICE)) { + error("Couldn't init USB controller."); + rc = CMD_RET_FAILURE; + goto cleanup_rkusb_init; + } + + rc = fsg_init(rkusb, rkusb_count); + if (rc) { + error("fsg_init failed"); + rc = CMD_RET_FAILURE; + goto cleanup_board; + } + + memcpy(&desc, fsg_get_usb_interface_descriptor(), + sizeof(struct usb_interface_descriptor)); + fsg_set_usb_interface_descriptor(&rockusb_desc); + rc = g_dnl_register("usb_dnl_ums"); + if (rc) { + error("g_dnl_register failed"); + rc = CMD_RET_FAILURE; + goto cleanup_board; + } + + /* Timeout unit: seconds */ + cable_ready_timeout = UMS_CABLE_READY_TIMEOUT; + + if (!g_dnl_board_usb_cable_connected()) { + /* + * Won't execute if we don't know whether the cable is + * connected. + */ + puts("Please connect USB cable.\n"); + + while (!g_dnl_board_usb_cable_connected()) { + if (ctrlc()) { + puts("\rCTRL+C - Operation aborted.\n"); + rc = CMD_RET_SUCCESS; + goto cleanup_register; + } + if (!cable_ready_timeout) { + puts("\rUSB cable not detected.Command exit.\n"); + rc = CMD_RET_SUCCESS; + goto cleanup_register; + } + + printf("\rAuto exit in: %.2d s.", cable_ready_timeout); + mdelay(1000); + cable_ready_timeout--; + } + puts("\r\n"); + } + + while (1) { + usb_gadget_handle_interrupts(controller_index); + + rc = fsg_main_thread(NULL); + if (rc) { + /* Check I/O error */ + if (rc == -EIO) + printf("\rCheck USB cable connection\n"); + + /* Check CTRL+C */ + if (rc == -EPIPE) + printf("\rCTRL+C - Operation aborted\n"); + + rc = CMD_RET_SUCCESS; + goto cleanup_register; + } + } + +cleanup_register: + g_dnl_unregister(); +cleanup_board: + board_usb_cleanup(controller_index, USB_INIT_DEVICE); + fsg_set_usb_interface_descriptor(&desc); +cleanup_rkusb_init: + rkusb_fini(); + + return rc; +} + +U_BOOT_CMD( + rockusb, 4, 1, do_rockusb, + "use the ROCKUSB protocol", + "rockusb <USB_controller> [<devtype>] <devnum> e.g. rockusb 0 mmc 0\n" + " devtype defaults to mmc" +);

Hi Eddie,
this patch add rockusb command. the usage is rockusb <USB_controller> [<devtype>] <devnum> e.g. rockusb 0 mmc 0
Ok.
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
cmd/Kconfig | 5 + cmd/Makefile | 1 + cmd/rockusb.c | 383 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 389 insertions(+) create mode 100644 cmd/rockusb.c
diff --git a/cmd/Kconfig b/cmd/Kconfig index 661ae7a..c94f509 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -509,6 +509,11 @@ 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"
- help
enables the rockusb command.
Here you would need to add some dependencies/selects (like with CMD_DFU).
config CMD_USB_MASS_STORAGE bool "UMS usb mass storage" help diff --git a/cmd/Makefile b/cmd/Makefile index ef1406b..9111ba3 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -112,6 +112,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 diff --git a/cmd/rockusb.c b/cmd/rockusb.c new file mode 100644 index 0000000..883db09 --- /dev/null +++ b/cmd/rockusb.c @@ -0,0 +1,383 @@ +/*
- Copyright (C) 2017 Eddie Cai eddie.cai.linux@gmail.com
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <command.h> +#include <console.h> +#include <f_mass_storage.h> +#include <g_dnl.h> +#include <usb.h> +#include <usb_mass_storage.h>
+#define K_FW_TEST_UNIT_READY 0x00 +#define K_FW_READ_FLASH_ID 0x01 +#define K_FW_SET_DEVICE_ID 0x02 +#define K_FW_TEST_BAD_BLOCK 0x03 +#define K_FW_READ_10 0x04 +#define K_FW_WRITE_10 0x05 +#define K_FW_ERASE_10 0x06 +#define K_FW_WRITE_SPARE 0x07 +#define K_FW_READ_SPARE 0x08
+#define K_FW_ERASE_10_FORCE 0x0b +#define K_FW_GET_VERSION 0x0c
+#define K_FW_LBA_READ_10 0x14 +#define K_FW_LBA_WRITE_10 0x15 +#define K_FW_ERASE_SYS_DISK 0x16 +#define K_FW_SDRAM_READ_10 0x17 +#define K_FW_SDRAM_WRITE_10 0x18 +#define K_FW_SDRAM_EXECUTE 0x19 +#define K_FW_READ_FLASH_INFO 0x1A +#define K_FW_GET_CHIP_VER 0x1B +#define K_FW_LOW_FORMAT 0x1C +#define K_FW_SET_RESET_FLAG 0x1E +#define K_FW_SPI_READ_10 0x21 +#define K_FW_SPI_WRITE_10 0x22
+#define K_FW_SESSION 0X30 +#define K_FW_RESET 0xff
+#define ROCKUSB_INTERFACE_CLASS 0xff +#define ROCKUSB_INTERFACE_SUB_CLASS 0x06 +#define ROCKUSB_INTERFACE_PROTOCOL 0x05
This should be probably moved to some *.h file - similar to f_thor.h @ ./drivers/usb/gadget
+static struct usb_interface_descriptor rockusb_desc = {
- .bLength = USB_DT_INTERFACE_SIZE,
- .bDescriptorType = USB_DT_INTERFACE,
- .bNumEndpoints = 0x02,
- .bInterfaceClass = ROCKUSB_INTERFACE_CLASS,
- .bInterfaceSubClass = ROCKUSB_INTERFACE_SUB_CLASS,
- .bInterfaceProtocol = ROCKUSB_INTERFACE_PROTOCOL,
- .iInterface = FSG_STRING_INTERFACE,
+};
The descriptor also should not be defined in the command file - better place would be f_rockchip_*.c file
+int __weak rkusb_set_reboot_flag(int flag) +{
- printf("rkusb_set_reboot_flag: %d\n", flag);
- return -ENOSYS;
+}
+static void rkusb_do_reset(struct usb_ep *ep, struct usb_request *req) +{
- do_reset(NULL, 0, 0, NULL);
+}
OK.
+#ifdef DEBUG +static void printcbw(struct fsg_bulk_cb_wrap *cbw) +{
- debug("cbw: Signature:%x\n", cbw->Signature);
- debug("cbw: Tag=%x\n", cbw->Tag);
- debug("cbw: DataTransferLength=%d\n",
cbw->DataTransferLength);
- debug("cbw: Flags=%x\n", cbw->Flags);
- debug("cbw: Lun=%d\n", cbw->Lun);
- debug("cbw: Length=%d\n", cbw->Length);
- debug("cbw: ucOperCode=%x\n", cbw->CDB[0]);
- debug("cbw: ucReserved=%x\n", cbw->CDB[1]);
- debug(
"cbw: dwAddress:%x %x %x %x\n",
cbw->CDB[5], cbw->CDB[4], cbw->CDB[3],
cbw->CDB[2]);
- debug("cbw: ucReserved2=%x\n", cbw->CDB[6]);
- debug("cbw: usLength:%x %x\n", cbw->CDB[8], cbw->CDB[7]);
+}
+static void printcsw(struct bulk_cs_wrap *csw) +{
- debug("csw: Signature:%x\n", csw->Signature);
- debug("csw: Tag:%x\n", csw->Tag);
- debug("csw: Residue:%x\n", csw->Residue);
- debug("csw: Status:%x\n", csw->Status);
+} +#endif
+int do_extra_command(struct fsg_common *common) +{
- struct fsg_buffhd *bh;
- int rc, reply = -EINVAL;
- struct usb_interface_descriptor *desc;
- desc = fsg_get_usb_interface_descriptor();
- /* make sure we are dealing with rockusb protocol */
- if (desc->bInterfaceClass != ROCKUSB_INTERFACE_CLASS ||
desc->bInterfaceSubClass != ROCKUSB_INTERFACE_SUB_CLASS
||
desc->bInterfaceProtocol != ROCKUSB_INTERFACE_PROTOCOL){
return reply;
- }
- /* Wait for the next buffer to become available for data or
status */
- bh = common->next_buffhd_to_fill;
- common->next_buffhd_to_drain = bh;
+#ifdef DEBUG
- struct usb_request *req;
- struct fsg_bulk_cb_wrap *cbw;
- req = bh->outreq;
- cbw = req->buf;
- printcbw(cbw);
+#endif
- debug("%s: cmd=%d\n", __func__, common->cmnd[0]);
- while (bh->state != BUF_STATE_EMPTY) {
rc = sleep_thread(common);
if (rc)
return rc;
- }
- common->phase_error = 0;
- common->short_packet_received = 0;
- switch (common->cmnd[0]) {
- case K_FW_RESET:
common->data_size_from_cmnd = common->cmnd[4];
rkusb_set_reboot_flag(common->cmnd[1]);
bh->inreq->complete = rkusb_do_reset;
bh->state = BUF_STATE_EMPTY;
bh->inreq->length = USB_BULK_CS_WRAP_LEN;
common->residue -= USB_BULK_CS_WRAP_LEN;
return 0;
- case K_FW_LBA_WRITE_10:
common->cmnd[0] = SC_WRITE_10;
common->data_dir = DATA_DIR_FROM_HOST;
common->data_size_from_cmnd =
get_unaligned_be16(&common->cmnd[7]) << 9;
common->data_size = common->data_size_from_cmnd;
do_scsi_command(common);
return 0;
- default:
return reply;
- }
- return reply;
+}
This code should be moved to f_rockchip_* as it is the routine providing "core" support for the protocol.
+static int rkusb_read_sector(struct ums *rkusb_dev,
ulong start, lbaint_t blkcnt, void *buf)
+{
- struct blk_desc *block_dev = &rkusb_dev->block_dev;
- lbaint_t blkstart = start + rkusb_dev->start_sector;
- return blk_dread(block_dev, blkstart, blkcnt, buf);
+}
+static int rkusb_write_sector(struct ums *rkusb_dev,
ulong start, lbaint_t blkcnt, const void
*buf) +{
- struct blk_desc *block_dev = &rkusb_dev->block_dev;
- lbaint_t blkstart = start + rkusb_dev->start_sector;
- return blk_dwrite(block_dev, blkstart, blkcnt, buf);
+}
+static struct ums *rkusb; +static int rkusb_count;
+static void rkusb_fini(void) +{
- int i;
- for (i = 0; i < rkusb_count; i++)
free((void *)rkusb[i].name);
- free(rkusb);
- rkusb = 0;
- rkusb_count = 0;
+}
+#define ROCKUSB_NAME_LEN 16
+static int rkusb_init(const char *devtype, const char *devnrkusb_part_str) +{
- char *s, *t, *devnum_part_str, *name;
- struct blk_desc *block_dev;
- disk_partition_t info;
- int partnum;
- int ret = -1;
- struct ums *rkusb_new;
- s = strdup(devnrkusb_part_str);
- if (!s)
return -1;
- t = s;
- rkusb_count = 0;
- for (;;) {
devnum_part_str = strsep(&t, ",");
if (!devnum_part_str)
break;
partnum = blk_get_device_part_str(devtype,
devnum_part_str,
&block_dev, &info, 1);
if (partnum < 0)
goto cleanup;
/* Check if the argument is in legacy format. If yes,
* expose all partitions by setting the partnum = 0
* e.g. rkusb 0 mmc 0
*/
if (!strchr(devnum_part_str, ':'))
partnum = 0;
/* f_mass_storage.c assumes SECTOR_SIZE sectors */
if (block_dev->blksz != SECTOR_SIZE)
goto cleanup;
rkusb_new = realloc(rkusb, (rkusb_count + 1) *
sizeof(*rkusb));
if (!rkusb_new)
goto cleanup;
rkusb = rkusb_new;
/* if partnum = 0, expose all partitions */
if (partnum == 0) {
rkusb[rkusb_count].start_sector = 0;
rkusb[rkusb_count].num_sectors =
block_dev->lba;
} else {
rkusb[rkusb_count].start_sector = info.start;
rkusb[rkusb_count].num_sectors = info.size;
}
rkusb[rkusb_count].read_sector = rkusb_read_sector;
rkusb[rkusb_count].write_sector = rkusb_write_sector;
name = malloc(ROCKUSB_NAME_LEN);
if (!name)
goto cleanup;
snprintf(name, ROCKUSB_NAME_LEN, "rkusb disk %d",
rkusb_count);
rkusb[rkusb_count].name = name;
rkusb[rkusb_count].block_dev = *block_dev;
printf("ROCKUSB: LUN %d, dev %d, hwpart %d, sector
%#x, count %#x\n",
rkusb_count,
rkusb[rkusb_count].block_dev.devnum,
rkusb[rkusb_count].block_dev.hwpart,
rkusb[rkusb_count].start_sector,
rkusb[rkusb_count].num_sectors);
rkusb_count++;
- }
- if (rkusb_count)
ret = 0;
+cleanup:
- free(s);
- if (ret < 0)
rkusb_fini();
- return ret;
+}
The same comment as above applies here.
+static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{
- const char *usb_controller;
- const char *devtype;
- const char *devnum;
- unsigned int controller_index;
- int rc;
- int cable_ready_timeout __maybe_unused;
- struct usb_interface_descriptor desc;
- if (argc < 3)
return CMD_RET_USAGE;
- usb_controller = argv[1];
- if (argc >= 4) {
devtype = argv[2];
devnum = argv[3];
- } else {
devtype = "mmc";
devnum = argv[2];
- }
- rc = rkusb_init(devtype, devnum);
- if (rc < 0)
return CMD_RET_FAILURE;
- controller_index = (unsigned int)(simple_strtoul(
usb_controller, NULL, 0));
- if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
error("Couldn't init USB controller.");
rc = CMD_RET_FAILURE;
goto cleanup_rkusb_init;
- }
- rc = fsg_init(rkusb, rkusb_count);
- if (rc) {
error("fsg_init failed");
rc = CMD_RET_FAILURE;
goto cleanup_board;
- }
- memcpy(&desc, fsg_get_usb_interface_descriptor(),
sizeof(struct usb_interface_descriptor));
- fsg_set_usb_interface_descriptor(&rockusb_desc);
- rc = g_dnl_register("usb_dnl_ums");
- if (rc) {
error("g_dnl_register failed");
rc = CMD_RET_FAILURE;
goto cleanup_board;
- }
- /* Timeout unit: seconds */
- cable_ready_timeout = UMS_CABLE_READY_TIMEOUT;
- if (!g_dnl_board_usb_cable_connected()) {
/*
* Won't execute if we don't know whether the cable
is
* connected.
*/
puts("Please connect USB cable.\n");
while (!g_dnl_board_usb_cable_connected()) {
if (ctrlc()) {
puts("\rCTRL+C - Operation
aborted.\n");
rc = CMD_RET_SUCCESS;
goto cleanup_register;
}
if (!cable_ready_timeout) {
puts("\rUSB cable not
detected.Command exit.\n");
rc = CMD_RET_SUCCESS;
goto cleanup_register;
}
printf("\rAuto exit in: %.2d s.",
cable_ready_timeout);
mdelay(1000);
cable_ready_timeout--;
}
puts("\r\n");
- }
- while (1) {
usb_gadget_handle_interrupts(controller_index);
rc = fsg_main_thread(NULL);
if (rc) {
/* Check I/O error */
if (rc == -EIO)
printf("\rCheck USB cable
connection\n"); +
/* Check CTRL+C */
if (rc == -EPIPE)
printf("\rCTRL+C - Operation
aborted\n"); +
rc = CMD_RET_SUCCESS;
goto cleanup_register;
}
- }
+cleanup_register:
- g_dnl_unregister();
+cleanup_board:
- board_usb_cleanup(controller_index, USB_INIT_DEVICE);
- fsg_set_usb_interface_descriptor(&desc);
+cleanup_rkusb_init:
- rkusb_fini();
- return rc;
+}
+U_BOOT_CMD(
rockusb, 4, 1, do_rockusb,
"use the ROCKUSB protocol",
"rockusb <USB_controller> [<devtype>] <devnum> e.g.
rockusb 0 mmc 0\n"
" devtype defaults to mmc"
+);
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

2017-04-20 6:27 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi Eddie,
this patch add rockusb command. the usage is rockusb <USB_controller> [<devtype>] <devnum> e.g. rockusb 0 mmc 0
Ok.
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
cmd/Kconfig | 5 + cmd/Makefile | 1 + cmd/rockusb.c | 383 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 389 insertions(+) create mode 100644 cmd/rockusb.c
diff --git a/cmd/Kconfig b/cmd/Kconfig index 661ae7a..c94f509 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -509,6 +509,11 @@ 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"
help
enables the rockusb command.
Here you would need to add some dependencies/selects (like with CMD_DFU).
config CMD_USB_MASS_STORAGE bool "UMS usb mass storage" help diff --git a/cmd/Makefile b/cmd/Makefile index ef1406b..9111ba3 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -112,6 +112,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 diff --git a/cmd/rockusb.c b/cmd/rockusb.c new file mode 100644 index 0000000..883db09 --- /dev/null +++ b/cmd/rockusb.c @@ -0,0 +1,383 @@ +/*
- Copyright (C) 2017 Eddie Cai eddie.cai.linux@gmail.com
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <command.h> +#include <console.h> +#include <f_mass_storage.h> +#include <g_dnl.h> +#include <usb.h> +#include <usb_mass_storage.h>
+#define K_FW_TEST_UNIT_READY 0x00 +#define K_FW_READ_FLASH_ID 0x01 +#define K_FW_SET_DEVICE_ID 0x02 +#define K_FW_TEST_BAD_BLOCK 0x03 +#define K_FW_READ_10 0x04 +#define K_FW_WRITE_10 0x05 +#define K_FW_ERASE_10 0x06 +#define K_FW_WRITE_SPARE 0x07 +#define K_FW_READ_SPARE 0x08
+#define K_FW_ERASE_10_FORCE 0x0b +#define K_FW_GET_VERSION 0x0c
+#define K_FW_LBA_READ_10 0x14 +#define K_FW_LBA_WRITE_10 0x15 +#define K_FW_ERASE_SYS_DISK 0x16 +#define K_FW_SDRAM_READ_10 0x17 +#define K_FW_SDRAM_WRITE_10 0x18 +#define K_FW_SDRAM_EXECUTE 0x19 +#define K_FW_READ_FLASH_INFO 0x1A +#define K_FW_GET_CHIP_VER 0x1B +#define K_FW_LOW_FORMAT 0x1C +#define K_FW_SET_RESET_FLAG 0x1E +#define K_FW_SPI_READ_10 0x21 +#define K_FW_SPI_WRITE_10 0x22
+#define K_FW_SESSION 0X30 +#define K_FW_RESET 0xff
+#define ROCKUSB_INTERFACE_CLASS 0xff +#define ROCKUSB_INTERFACE_SUB_CLASS 0x06 +#define ROCKUSB_INTERFACE_PROTOCOL 0x05
This should be probably moved to some *.h file - similar to f_thor.h @ ./drivers/usb/gadget
It is in f_rockusb.c in my V1 patch. I think we don't share this macro with other file. So i don't put it in a .h file. Let me know if you have further comment. https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
+static struct usb_interface_descriptor rockusb_desc = {
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
.bNumEndpoints = 0x02,
.bInterfaceClass = ROCKUSB_INTERFACE_CLASS,
.bInterfaceSubClass = ROCKUSB_INTERFACE_SUB_CLASS,
.bInterfaceProtocol = ROCKUSB_INTERFACE_PROTOCOL,
.iInterface = FSG_STRING_INTERFACE,
+};
The descriptor also should not be defined in the command file - better place would be f_rockchip_*.c file
Yes, I already put it in f_rockusb.c in my V1 patch.
+int __weak rkusb_set_reboot_flag(int flag) +{
printf("rkusb_set_reboot_flag: %d\n", flag);
return -ENOSYS;
+}
+static void rkusb_do_reset(struct usb_ep *ep, struct usb_request *req) +{
do_reset(NULL, 0, 0, NULL);
+}
OK.
+#ifdef DEBUG +static void printcbw(struct fsg_bulk_cb_wrap *cbw) +{
debug("cbw: Signature:%x\n", cbw->Signature);
debug("cbw: Tag=%x\n", cbw->Tag);
debug("cbw: DataTransferLength=%d\n",
cbw->DataTransferLength);
debug("cbw: Flags=%x\n", cbw->Flags);
debug("cbw: Lun=%d\n", cbw->Lun);
debug("cbw: Length=%d\n", cbw->Length);
debug("cbw: ucOperCode=%x\n", cbw->CDB[0]);
debug("cbw: ucReserved=%x\n", cbw->CDB[1]);
debug(
"cbw: dwAddress:%x %x %x %x\n",
cbw->CDB[5], cbw->CDB[4], cbw->CDB[3],
cbw->CDB[2]);
debug("cbw: ucReserved2=%x\n", cbw->CDB[6]);
debug("cbw: usLength:%x %x\n", cbw->CDB[8], cbw->CDB[7]);
+}
+static void printcsw(struct bulk_cs_wrap *csw) +{
debug("csw: Signature:%x\n", csw->Signature);
debug("csw: Tag:%x\n", csw->Tag);
debug("csw: Residue:%x\n", csw->Residue);
debug("csw: Status:%x\n", csw->Status);
+} +#endif
+int do_extra_command(struct fsg_common *common) +{
struct fsg_buffhd *bh;
int rc, reply = -EINVAL;
struct usb_interface_descriptor *desc;
desc = fsg_get_usb_interface_descriptor();
/* make sure we are dealing with rockusb protocol */
if (desc->bInterfaceClass != ROCKUSB_INTERFACE_CLASS ||
desc->bInterfaceSubClass != ROCKUSB_INTERFACE_SUB_CLASS
||
desc->bInterfaceProtocol != ROCKUSB_INTERFACE_PROTOCOL){
return reply;
}
/* Wait for the next buffer to become available for data or
status */
bh = common->next_buffhd_to_fill;
common->next_buffhd_to_drain = bh;
+#ifdef DEBUG
struct usb_request *req;
struct fsg_bulk_cb_wrap *cbw;
req = bh->outreq;
cbw = req->buf;
printcbw(cbw);
+#endif
debug("%s: cmd=%d\n", __func__, common->cmnd[0]);
while (bh->state != BUF_STATE_EMPTY) {
rc = sleep_thread(common);
if (rc)
return rc;
}
common->phase_error = 0;
common->short_packet_received = 0;
switch (common->cmnd[0]) {
case K_FW_RESET:
common->data_size_from_cmnd = common->cmnd[4];
rkusb_set_reboot_flag(common->cmnd[1]);
bh->inreq->complete = rkusb_do_reset;
bh->state = BUF_STATE_EMPTY;
bh->inreq->length = USB_BULK_CS_WRAP_LEN;
common->residue -= USB_BULK_CS_WRAP_LEN;
return 0;
case K_FW_LBA_WRITE_10:
common->cmnd[0] = SC_WRITE_10;
common->data_dir = DATA_DIR_FROM_HOST;
common->data_size_from_cmnd =
get_unaligned_be16(&common->cmnd[7]) << 9;
common->data_size = common->data_size_from_cmnd;
do_scsi_command(common);
return 0;
default:
return reply;
}
return reply;
+}
This code should be moved to f_rockchip_* as it is the routine providing "core" support for the protocol.
the same, I already did it in my V1 patch https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
+static int rkusb_read_sector(struct ums *rkusb_dev,
ulong start, lbaint_t blkcnt, void *buf)
+{
struct blk_desc *block_dev = &rkusb_dev->block_dev;
lbaint_t blkstart = start + rkusb_dev->start_sector;
return blk_dread(block_dev, blkstart, blkcnt, buf);
+}
+static int rkusb_write_sector(struct ums *rkusb_dev,
ulong start, lbaint_t blkcnt, const void
*buf) +{
struct blk_desc *block_dev = &rkusb_dev->block_dev;
lbaint_t blkstart = start + rkusb_dev->start_sector;
return blk_dwrite(block_dev, blkstart, blkcnt, buf);
+}
+static struct ums *rkusb; +static int rkusb_count;
+static void rkusb_fini(void) +{
int i;
for (i = 0; i < rkusb_count; i++)
free((void *)rkusb[i].name);
free(rkusb);
rkusb = 0;
rkusb_count = 0;
+}
+#define ROCKUSB_NAME_LEN 16
+static int rkusb_init(const char *devtype, const char *devnrkusb_part_str) +{
char *s, *t, *devnum_part_str, *name;
struct blk_desc *block_dev;
disk_partition_t info;
int partnum;
int ret = -1;
struct ums *rkusb_new;
s = strdup(devnrkusb_part_str);
if (!s)
return -1;
t = s;
rkusb_count = 0;
for (;;) {
devnum_part_str = strsep(&t, ",");
if (!devnum_part_str)
break;
partnum = blk_get_device_part_str(devtype,
devnum_part_str,
&block_dev, &info, 1);
if (partnum < 0)
goto cleanup;
/* Check if the argument is in legacy format. If yes,
* expose all partitions by setting the partnum = 0
* e.g. rkusb 0 mmc 0
*/
if (!strchr(devnum_part_str, ':'))
partnum = 0;
/* f_mass_storage.c assumes SECTOR_SIZE sectors */
if (block_dev->blksz != SECTOR_SIZE)
goto cleanup;
rkusb_new = realloc(rkusb, (rkusb_count + 1) *
sizeof(*rkusb));
if (!rkusb_new)
goto cleanup;
rkusb = rkusb_new;
/* if partnum = 0, expose all partitions */
if (partnum == 0) {
rkusb[rkusb_count].start_sector = 0;
rkusb[rkusb_count].num_sectors =
block_dev->lba;
} else {
rkusb[rkusb_count].start_sector = info.start;
rkusb[rkusb_count].num_sectors = info.size;
}
rkusb[rkusb_count].read_sector = rkusb_read_sector;
rkusb[rkusb_count].write_sector = rkusb_write_sector;
name = malloc(ROCKUSB_NAME_LEN);
if (!name)
goto cleanup;
snprintf(name, ROCKUSB_NAME_LEN, "rkusb disk %d",
rkusb_count);
rkusb[rkusb_count].name = name;
rkusb[rkusb_count].block_dev = *block_dev;
printf("ROCKUSB: LUN %d, dev %d, hwpart %d, sector
%#x, count %#x\n",
rkusb_count,
rkusb[rkusb_count].block_dev.devnum,
rkusb[rkusb_count].block_dev.hwpart,
rkusb[rkusb_count].start_sector,
rkusb[rkusb_count].num_sectors);
rkusb_count++;
}
if (rkusb_count)
ret = 0;
+cleanup:
free(s);
if (ret < 0)
rkusb_fini();
return ret;
+}
The same comment as above applies here.
+static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) +{
const char *usb_controller;
const char *devtype;
const char *devnum;
unsigned int controller_index;
int rc;
int cable_ready_timeout __maybe_unused;
struct usb_interface_descriptor desc;
if (argc < 3)
return CMD_RET_USAGE;
usb_controller = argv[1];
if (argc >= 4) {
devtype = argv[2];
devnum = argv[3];
} else {
devtype = "mmc";
devnum = argv[2];
}
rc = rkusb_init(devtype, devnum);
if (rc < 0)
return CMD_RET_FAILURE;
controller_index = (unsigned int)(simple_strtoul(
usb_controller, NULL, 0));
if (board_usb_init(controller_index, USB_INIT_DEVICE)) {
error("Couldn't init USB controller.");
rc = CMD_RET_FAILURE;
goto cleanup_rkusb_init;
}
rc = fsg_init(rkusb, rkusb_count);
if (rc) {
error("fsg_init failed");
rc = CMD_RET_FAILURE;
goto cleanup_board;
}
memcpy(&desc, fsg_get_usb_interface_descriptor(),
sizeof(struct usb_interface_descriptor));
fsg_set_usb_interface_descriptor(&rockusb_desc);
rc = g_dnl_register("usb_dnl_ums");
if (rc) {
error("g_dnl_register failed");
rc = CMD_RET_FAILURE;
goto cleanup_board;
}
/* Timeout unit: seconds */
cable_ready_timeout = UMS_CABLE_READY_TIMEOUT;
if (!g_dnl_board_usb_cable_connected()) {
/*
* Won't execute if we don't know whether the cable
is
* connected.
*/
puts("Please connect USB cable.\n");
while (!g_dnl_board_usb_cable_connected()) {
if (ctrlc()) {
puts("\rCTRL+C - Operation
aborted.\n");
rc = CMD_RET_SUCCESS;
goto cleanup_register;
}
if (!cable_ready_timeout) {
puts("\rUSB cable not
detected.Command exit.\n");
rc = CMD_RET_SUCCESS;
goto cleanup_register;
}
printf("\rAuto exit in: %.2d s.",
cable_ready_timeout);
mdelay(1000);
cable_ready_timeout--;
}
puts("\r\n");
}
while (1) {
usb_gadget_handle_interrupts(controller_index);
rc = fsg_main_thread(NULL);
if (rc) {
/* Check I/O error */
if (rc == -EIO)
printf("\rCheck USB cable
connection\n"); +
/* Check CTRL+C */
if (rc == -EPIPE)
printf("\rCTRL+C - Operation
aborted\n"); +
rc = CMD_RET_SUCCESS;
goto cleanup_register;
}
}
+cleanup_register:
g_dnl_unregister();
+cleanup_board:
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
fsg_set_usb_interface_descriptor(&desc);
+cleanup_rkusb_init:
rkusb_fini();
return rc;
+}
+U_BOOT_CMD(
rockusb, 4, 1, do_rockusb,
"use the ROCKUSB protocol",
"rockusb <USB_controller> [<devtype>] <devnum> e.g.
rockusb 0 mmc 0\n"
" devtype defaults to mmc"
+);
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

all rk3288 based boards support rockusb, so enable it
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- configs/evb-rk3288_defconfig | 2 ++ configs/fennec-rk3288_defconfig | 1 + configs/firefly-rk3288_defconfig | 1 + configs/miqi-rk3288_defconfig | 1 + configs/popmetal-rk3288_defconfig | 1 + configs/rock2_defconfig | 2 ++ configs/sandbox_defconfig | 1 + configs/tinker-rk3288_defconfig | 1 + 8 files changed, 10 insertions(+)
diff --git a/configs/evb-rk3288_defconfig b/configs/evb-rk3288_defconfig index aad2533..6be46fb 100644 --- a/configs/evb-rk3288_defconfig +++ b/configs/evb-rk3288_defconfig @@ -17,6 +17,8 @@ CONFIG_CMD_MMC=y CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y +CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/fennec-rk3288_defconfig b/configs/fennec-rk3288_defconfig index d1b0ffc..ba8a356 100644 --- a/configs/fennec-rk3288_defconfig +++ b/configs/fennec-rk3288_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/firefly-rk3288_defconfig b/configs/firefly-rk3288_defconfig index b0741d7..c860c06 100644 --- a/configs/firefly-rk3288_defconfig +++ b/configs/firefly-rk3288_defconfig @@ -17,6 +17,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/miqi-rk3288_defconfig b/configs/miqi-rk3288_defconfig index 203824b..3c42d99 100644 --- a/configs/miqi-rk3288_defconfig +++ b/configs/miqi-rk3288_defconfig @@ -17,6 +17,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/popmetal-rk3288_defconfig b/configs/popmetal-rk3288_defconfig index dfc84b9..ddf6062 100644 --- a/configs/popmetal-rk3288_defconfig +++ b/configs/popmetal-rk3288_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/rock2_defconfig b/configs/rock2_defconfig index e9a32a9..365bc90 100644 --- a/configs/rock2_defconfig +++ b/configs/rock2_defconfig @@ -16,6 +16,8 @@ CONFIG_CMD_MMC=y CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y +CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 7f3f5ac..9350d51 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -33,6 +33,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_GPIO=y CONFIG_CMD_TFTPPUT=y diff --git a/configs/tinker-rk3288_defconfig b/configs/tinker-rk3288_defconfig index cec3938..d96d7d3 100644 --- a/configs/tinker-rk3288_defconfig +++ b/configs/tinker-rk3288_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y

Hi Eddie,
all rk3288 based boards support rockusb, so enable it
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
configs/evb-rk3288_defconfig | 2 ++ configs/fennec-rk3288_defconfig | 1 + configs/firefly-rk3288_defconfig | 1 + configs/miqi-rk3288_defconfig | 1 + configs/popmetal-rk3288_defconfig | 1 + configs/rock2_defconfig | 2 ++ configs/sandbox_defconfig | 1 + configs/tinker-rk3288_defconfig | 1 + 8 files changed, 10 insertions(+)
diff --git a/configs/evb-rk3288_defconfig b/configs/evb-rk3288_defconfig index aad2533..6be46fb 100644 --- a/configs/evb-rk3288_defconfig +++ b/configs/evb-rk3288_defconfig @@ -17,6 +17,8 @@ CONFIG_CMD_MMC=y CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y +CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/fennec-rk3288_defconfig b/configs/fennec-rk3288_defconfig index d1b0ffc..ba8a356 100644 --- a/configs/fennec-rk3288_defconfig +++ b/configs/fennec-rk3288_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/firefly-rk3288_defconfig b/configs/firefly-rk3288_defconfig index b0741d7..c860c06 100644 --- a/configs/firefly-rk3288_defconfig +++ b/configs/firefly-rk3288_defconfig @@ -17,6 +17,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/miqi-rk3288_defconfig b/configs/miqi-rk3288_defconfig index 203824b..3c42d99 100644 --- a/configs/miqi-rk3288_defconfig +++ b/configs/miqi-rk3288_defconfig @@ -17,6 +17,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/popmetal-rk3288_defconfig b/configs/popmetal-rk3288_defconfig index dfc84b9..ddf6062 100644 --- a/configs/popmetal-rk3288_defconfig +++ b/configs/popmetal-rk3288_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/rock2_defconfig b/configs/rock2_defconfig index e9a32a9..365bc90 100644 --- a/configs/rock2_defconfig +++ b/configs/rock2_defconfig @@ -16,6 +16,8 @@ CONFIG_CMD_MMC=y CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y +CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 7f3f5ac..9350d51 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -33,6 +33,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_GPIO=y CONFIG_CMD_TFTPPUT=y diff --git a/configs/tinker-rk3288_defconfig b/configs/tinker-rk3288_defconfig index cec3938..d96d7d3 100644 --- a/configs/tinker-rk3288_defconfig +++ b/configs/tinker-rk3288_defconfig @@ -18,6 +18,7 @@ CONFIG_CMD_SF=y CONFIG_CMD_SPI=y CONFIG_CMD_I2C=y CONFIG_CMD_USB=y +CONFIG_CMD_ROCKUSB=y CONFIG_CMD_GPIO=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_CACHE=y
This patch would need to be adjusted if mentioned earlier changes are applied.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

add a simple readme to introduce rockusb and tell people how to use it
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com --- doc/README.rockusb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 doc/README.rockusb
diff --git a/doc/README.rockusb b/doc/README.rockusb new file mode 100644 index 0000000..13893d9 --- /dev/null +++ b/doc/README.rockusb @@ -0,0 +1,35 @@ +Rockusb (Rockchip USB protocol) +===================================================== + +Overview +-------- + +Rockusb protocol is widely used with Rockchip 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 +is open source, It is maintained by Rockchip. + +Usage +-------- +The Usage of Rockusb command is +rockusb <USB_controller> [<devtype>] <devnum> +e.g. rockusb 0 mmc 0 +rockusb 0 usb 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. Then use rkdeveloptool +sudo rkdeveloptool wl <BeginSec> <File> +to flash U-Boot image use command +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

Hi Eddie,
add a simple readme to introduce rockusb and tell people how to use it
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
doc/README.rockusb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 doc/README.rockusb
diff --git a/doc/README.rockusb b/doc/README.rockusb new file mode 100644 index 0000000..13893d9 --- /dev/null +++ b/doc/README.rockusb @@ -0,0 +1,35 @@ +Rockusb (Rockchip USB protocol) +=====================================================
+Overview +--------
+Rockusb protocol is widely used with Rockchip devices. +It can read/write info,
R/W the info is the differentiator here. What kind of information canwe read from the device? Do you plan to add this in the future?
Does it allow for reading/writing the RK soc's env variables ?
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 +is open source, It is maintained by Rockchip.
Ok.
+Usage +-------- +The Usage of Rockusb command is +rockusb <USB_controller> [<devtype>] <devnum> +e.g. rockusb 0 mmc 0 +rockusb 0 usb 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. Then use rkdeveloptool +sudo rkdeveloptool wl <BeginSec> <File> +to flash U-Boot image use command +sudo rkdeveloptool wl 64 <U-Boot binary>
Just informative - this could be achieved with UMS command with using dd.
+There are plenty of Rockusb command. but wl(write lba) and +rd(reboot) command.
Reboot is also supported - but there is no unification - though each gadget (thor, dfu, fastboot)
These two command can let people flash +image to device.
IMHO reading images (for backup) would be handy as well.
+To do +----- +* Fully support Rockusb protocol
For me it is OK, to have a minimal subset of commands supported - let's add the very basic support and extend it latter.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

Hi Lukasz
2017-04-20 6:39 GMT+08:00 Lukasz Majewski lukma@denx.de:
Hi Eddie,
add a simple readme to introduce rockusb and tell people how to use it
Signed-off-by: Eddie Cai eddie.cai.linux@gmail.com
doc/README.rockusb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 doc/README.rockusb
diff --git a/doc/README.rockusb b/doc/README.rockusb new file mode 100644 index 0000000..13893d9 --- /dev/null +++ b/doc/README.rockusb @@ -0,0 +1,35 @@ +Rockusb (Rockchip USB protocol) +=====================================================
+Overview +--------
+Rockusb protocol is widely used with Rockchip devices. +It can read/write info,
R/W the info is the differentiator here. What kind of information canwe read from the device? Do you plan to add this in the future?
SoC infor, Storage infor, thins in eFuse like serial number. I did have plan to add this function. But to keep things simple. I want to add minimum function first. It will be easy for me to add new function if everybody agree the framework.
Does it allow for reading/writing the RK soc's env variables ?
What do you mean soc's env variables here? yes If you mean things like cpu model number
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 +is open source, It is maintained by Rockchip.
Ok.
+Usage +-------- +The Usage of Rockusb command is +rockusb <USB_controller> [<devtype>] <devnum> +e.g. rockusb 0 mmc 0 +rockusb 0 usb 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. Then use rkdeveloptool +sudo rkdeveloptool wl <BeginSec> <File> +to flash U-Boot image use command +sudo rkdeveloptool wl 64 <U-Boot binary>
Just informative - this could be achieved with UMS command with using dd.
yes, if you only talk about wl command. But there are many other rockusb command can not achieved with UMS command
+There are plenty of Rockusb command. but wl(write lba) and +rd(reboot) command.
Reboot is also supported - but there is no unification - though each gadget (thor, dfu, fastboot)
These two command can let people flash +image to device.
IMHO reading images (for backup) would be handy as well.
I do have plan to add this function. But I would like this minimum set agreed by everybody. then add more command. If i implemented all the rockusb command. It will be huge work for me when i move from V1 to V2 patch. Please help review my V1 patch. My V3 patch will based on V1 patch. Let me know if you have more comment. https://lists.denx.de/pipermail/u-boot/2017-March/283730.html
+To do +----- +* Fully support Rockusb protocol
For me it is OK, to have a minimal subset of commands supported - let's add the very basic support and extend it latter.
Totally agree.
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de

Hi Eddie,
On 16 April 2017 at 09:54, Eddie Cai eddie.cai.linux@gmail.com wrote:
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.
Eddie Cai (9): usb: ums: split macro and data struct in storage_common.c usb: ums: split macro and data struct in f_mass_storage.c usb: ums: merge storage_common.c into f_mass_storage.c usb: ums: remove static declaration of some ums functions usb: ums: add functions to set and get usb interface descriptor usb: ums: add do_extra_command cmd: add rockusb command rockchip: config: enable rockusb support on rk3288 based board rockusb: add a simple readme
cmd/Kconfig | 5 + cmd/Makefile | 1 + cmd/rockusb.c | 383 +++++++++++++++++++++ configs/evb-rk3288_defconfig | 2 + configs/fennec-rk3288_defconfig | 1 + configs/firefly-rk3288_defconfig | 1 + configs/miqi-rk3288_defconfig | 1 + configs/popmetal-rk3288_defconfig | 1 + configs/rock2_defconfig | 2 + configs/sandbox_defconfig | 1 + configs/tinker-rk3288_defconfig | 1 + doc/README.rockusb | 35 ++ drivers/usb/gadget/f_mass_storage.c | 356 +++++++++++++------ .../storage_common.c => include/f_mass_storage.h | 296 +++++----------- 14 files changed, 775 insertions(+), 311 deletions(-) create mode 100644 cmd/rockusb.c create mode 100644 doc/README.rockusb rename drivers/usb/gadget/storage_common.c => include/f_mass_storage.h (65%)
-- 2.10.2
Can you please send a new version with change logs in each patch?
Regards, Simon
participants (3)
-
Eddie Cai
-
Lukasz Majewski
-
Simon Glass