Re: [U-Boot] [PATCH v2 2/8] usb: gadget: add SDP driver

2017-08-17 Thread Łukasz Majewski

On 08/17/2017 03:54 PM, Marek Vasut wrote:

On 08/17/2017 03:49 PM, Stefano Babic wrote:

On 16/08/2017 20:00, Stefan Agner wrote:

From: Stefan Agner 

Add SDP (Serial Downloader Protocol) implementation for U-Boot. The
protocol is used in NXP SoC's boot ROM and allows to download program
images. Beside that, it can also be used to read/write registers and
download complete Device Configuration Data (DCD) sets. This basic
implementation supports downloading images with the imx header format
reading and writing registers.

Signed-off-by: Stefan Agner 


Reviewed by : Stefano Babic ysba...@denx.de>

Marek, this is related to USB. Anyway, I will prefer that the whole
patchset will be merged at once, and not split between u-boot-imx and
u-boot-usb. If you agree (and after the patchset is ok for you, of
course !), I will propose that I will merge the whole patchset into
u-boot-imx to avoid breakages.


This is gadget stuff, so it's Lukasz's call, not mine.


I'm fine with this approach (as I've already reviewed those patches).

Stefano, please merge it to your's -imx tree.






--
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: w...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 2/8] usb: gadget: add SDP driver

2017-08-17 Thread Stefano Babic
On 17/08/2017 15:54, Marek Vasut wrote:
> On 08/17/2017 03:49 PM, Stefano Babic wrote:
>> On 16/08/2017 20:00, Stefan Agner wrote:
>>> From: Stefan Agner 
>>>
>>> Add SDP (Serial Downloader Protocol) implementation for U-Boot. The
>>> protocol is used in NXP SoC's boot ROM and allows to download program
>>> images. Beside that, it can also be used to read/write registers and
>>> download complete Device Configuration Data (DCD) sets. This basic
>>> implementation supports downloading images with the imx header format
>>> reading and writing registers.
>>>
>>> Signed-off-by: Stefan Agner 
>>
>> Reviewed by : Stefano Babic ysba...@denx.de>
>>
>> Marek, this is related to USB. Anyway, I will prefer that the whole
>> patchset will be merged at once, and not split between u-boot-imx and
>> u-boot-usb. If you agree (and after the patchset is ok for you, of
>> course !), I will propose that I will merge the whole patchset into
>> u-boot-imx to avoid breakages.
> 
> This is gadget stuff, so it's Lukasz's call, not mine.

Sorry for noise, you're right.

Lukasz, is it ok for you ?

Regards,
Stefano

-- 
=
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 2/8] usb: gadget: add SDP driver

2017-08-17 Thread Marek Vasut
On 08/17/2017 03:49 PM, Stefano Babic wrote:
> On 16/08/2017 20:00, Stefan Agner wrote:
>> From: Stefan Agner 
>>
>> Add SDP (Serial Downloader Protocol) implementation for U-Boot. The
>> protocol is used in NXP SoC's boot ROM and allows to download program
>> images. Beside that, it can also be used to read/write registers and
>> download complete Device Configuration Data (DCD) sets. This basic
>> implementation supports downloading images with the imx header format
>> reading and writing registers.
>>
>> Signed-off-by: Stefan Agner 
> 
> Reviewed by : Stefano Babic ysba...@denx.de>
> 
> Marek, this is related to USB. Anyway, I will prefer that the whole
> patchset will be merged at once, and not split between u-boot-imx and
> u-boot-usb. If you agree (and after the patchset is ok for you, of
> course !), I will propose that I will merge the whole patchset into
> u-boot-imx to avoid breakages.

This is gadget stuff, so it's Lukasz's call, not mine.

-- 
Best regards,
Marek Vasut
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v2 2/8] usb: gadget: add SDP driver

2017-08-17 Thread Stefano Babic
On 16/08/2017 20:00, Stefan Agner wrote:
> From: Stefan Agner 
> 
> Add SDP (Serial Downloader Protocol) implementation for U-Boot. The
> protocol is used in NXP SoC's boot ROM and allows to download program
> images. Beside that, it can also be used to read/write registers and
> download complete Device Configuration Data (DCD) sets. This basic
> implementation supports downloading images with the imx header format
> reading and writing registers.
> 
> Signed-off-by: Stefan Agner 

Reviewed by : Stefano Babic ysba...@denx.de>

Marek, this is related to USB. Anyway, I will prefer that the whole
patchset will be merged at once, and not split between u-boot-imx and
u-boot-usb. If you agree (and after the patchset is ok for you, of
course !), I will propose that I will merge the whole patchset into
u-boot-imx to avoid breakages.

Best regards,
Stefano

> ---
> 
> Changes in v2:
> - Changed function signature of sdp_init/sdp_handle to allow specifying
>   which USB controller should be used.
> - Use #defines for security mode
> - Improved types used in format strings
> 
>  drivers/usb/gadget/Kconfig  |   7 +
>  drivers/usb/gadget/Makefile |   1 +
>  drivers/usb/gadget/f_sdp.c  | 721 
> 
>  include/sdp.h   |  16 +
>  4 files changed, 745 insertions(+)
>  create mode 100644 drivers/usb/gadget/f_sdp.c
>  create mode 100644 include/sdp.h
> 
> diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
> index 261ed128ac..225b66bc95 100644
> --- a/drivers/usb/gadget/Kconfig
> +++ b/drivers/usb/gadget/Kconfig
> @@ -103,6 +103,13 @@ config USB_GADGET_DOWNLOAD
>  
>  if USB_GADGET_DOWNLOAD
>  
> +config USB_FUNCTION_SDP
> + bool "Enable USB SDP (Serial Download Protocol)"
> + help
> +   Enable Serial Download Protocol (SDP) device support in U-Boot. This
> +   allows to download images into memory and execute (jump to) them
> +   using the same protocol as implemented by the i.MX family's boot ROM.
> +
>  config G_DNL_MANUFACTURER
>   string "Vendor name of USB device"
>  
> diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
> index 5e316a7cff..6a007d1bcb 100644
> --- a/drivers/usb/gadget/Makefile
> +++ b/drivers/usb/gadget/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o
>  obj-$(CONFIG_USB_FUNCTION_DFU) += f_dfu.o
>  obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o
>  obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o
> +obj-$(CONFIG_USB_FUNCTION_SDP) += f_sdp.o
>  endif
>  endif
>  ifdef CONFIG_USB_ETHER
> diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
> new file mode 100644
> index 00..9d82abcd69
> --- /dev/null
> +++ b/drivers/usb/gadget/f_sdp.c
> @@ -0,0 +1,721 @@
> +/*
> + * f_sdp.c -- USB HID Serial Download Protocol
> + *
> + * Copyright (C) 2017 Toradex
> + * Author: Stefan Agner 
> + *
> + * This file implements the Serial Download Protocol (SDP) as specified in
> + * the i.MX 6 Reference Manual. The SDP is a USB HID based protocol and
> + * allows to download images directly to memory. The implementation
> + * works with the imx_loader (imx_usb) USB client software on host side.
> + *
> + * Not all commands are implemented, e.g. WRITE_REGISTER, DCD_WRITE and
> + * SKIP_DCD_HEADER are only stubs.
> + *
> + * Parts of the implementation are based on f_dfu and f_thor.
> + *
> + * SPDX-License-Identifier:  GPL-2.0+
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define HID_REPORT_ID_MASK   0x00ff
> +
> +/*
> + * HID class requests
> + */
> +#define HID_REQ_GET_REPORT   0x01
> +#define HID_REQ_GET_IDLE 0x02
> +#define HID_REQ_GET_PROTOCOL 0x03
> +#define HID_REQ_SET_REPORT   0x09
> +#define HID_REQ_SET_IDLE 0x0A
> +#define HID_REQ_SET_PROTOCOL 0x0B
> +
> +#define HID_USAGE_PAGE_LEN   76
> +
> +struct hid_report {
> + u8 usage_page[HID_USAGE_PAGE_LEN];
> +} __packed;
> +
> +#define SDP_READ_REGISTER0x0101
> +#define SDP_WRITE_REGISTER   0x0202
> +#define SDP_WRITE_FILE   0x0404
> +#define SDP_ERROR_STATUS 0x0505
> +#define SDP_DCD_WRITE0x0a0a
> +#define SDP_JUMP_ADDRESS 0x0b0b
> +#define SDP_SKIP_DCD_HEADER  0x0c0c
> +
> +#define SDP_SECURITY_CLOSED  0x12343412
> +#define SDP_SECURITY_OPEN0x56787856
> +
> +#define SDP_WRITE_FILE_COMPLETE  0x
> +#define SDP_WRITE_REGISTER_COMPLETE  0x128A8A12
> +#define SDP_SKIP_DCD_HEADER_COMPLETE 0x900DD009
> +#define SDP_ERROR_IMXHEADER  0x000a0533
> +
> +#define SDP_COMMAND_LEN  16
> +
> +struct sdp_command {
> + u16 cmd;
> + u32 addr;
> + u8 format;
> + u32 cnt;
> + u32 data;
> + u8 rsvd;
> +} __packed;
> +
> 

Re: [U-Boot] [PATCH v2 2/8] usb: gadget: add SDP driver

2017-08-17 Thread Łukasz Majewski

On 08/16/2017 08:00 PM, Stefan Agner wrote:

From: Stefan Agner 

Add SDP (Serial Downloader Protocol) implementation for U-Boot. The
protocol is used in NXP SoC's boot ROM and allows to download program
images. Beside that, it can also be used to read/write registers and
download complete Device Configuration Data (DCD) sets. This basic
implementation supports downloading images with the imx header format
reading and writing registers.

Signed-off-by: Stefan Agner 


Reviewed-by: Łukasz Majewski 


---

Changes in v2:
- Changed function signature of sdp_init/sdp_handle to allow specifying
  which USB controller should be used.
- Use #defines for security mode
- Improved types used in format strings

 drivers/usb/gadget/Kconfig  |   7 +
 drivers/usb/gadget/Makefile |   1 +
 drivers/usb/gadget/f_sdp.c  | 721 
 include/sdp.h   |  16 +
 4 files changed, 745 insertions(+)
 create mode 100644 drivers/usb/gadget/f_sdp.c
 create mode 100644 include/sdp.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 261ed128ac..225b66bc95 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -103,6 +103,13 @@ config USB_GADGET_DOWNLOAD

 if USB_GADGET_DOWNLOAD

+config USB_FUNCTION_SDP
+   bool "Enable USB SDP (Serial Download Protocol)"
+   help
+ Enable Serial Download Protocol (SDP) device support in U-Boot. This
+ allows to download images into memory and execute (jump to) them
+ using the same protocol as implemented by the i.MX family's boot ROM.
+
 config G_DNL_MANUFACTURER
string "Vendor name of USB device"

diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 5e316a7cff..6a007d1bcb 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o
 obj-$(CONFIG_USB_FUNCTION_DFU) += f_dfu.o
 obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o
 obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o
+obj-$(CONFIG_USB_FUNCTION_SDP) += f_sdp.o
 endif
 endif
 ifdef CONFIG_USB_ETHER
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
new file mode 100644
index 00..9d82abcd69
--- /dev/null
+++ b/drivers/usb/gadget/f_sdp.c
@@ -0,0 +1,721 @@
+/*
+ * f_sdp.c -- USB HID Serial Download Protocol
+ *
+ * Copyright (C) 2017 Toradex
+ * Author: Stefan Agner 
+ *
+ * This file implements the Serial Download Protocol (SDP) as specified in
+ * the i.MX 6 Reference Manual. The SDP is a USB HID based protocol and
+ * allows to download images directly to memory. The implementation
+ * works with the imx_loader (imx_usb) USB client software on host side.
+ *
+ * Not all commands are implemented, e.g. WRITE_REGISTER, DCD_WRITE and
+ * SKIP_DCD_HEADER are only stubs.
+ *
+ * Parts of the implementation are based on f_dfu and f_thor.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define HID_REPORT_ID_MASK 0x00ff
+
+/*
+ * HID class requests
+ */
+#define HID_REQ_GET_REPORT 0x01
+#define HID_REQ_GET_IDLE   0x02
+#define HID_REQ_GET_PROTOCOL   0x03
+#define HID_REQ_SET_REPORT 0x09
+#define HID_REQ_SET_IDLE   0x0A
+#define HID_REQ_SET_PROTOCOL   0x0B
+
+#define HID_USAGE_PAGE_LEN 76
+
+struct hid_report {
+   u8 usage_page[HID_USAGE_PAGE_LEN];
+} __packed;
+
+#define SDP_READ_REGISTER  0x0101
+#define SDP_WRITE_REGISTER 0x0202
+#define SDP_WRITE_FILE 0x0404
+#define SDP_ERROR_STATUS   0x0505
+#define SDP_DCD_WRITE  0x0a0a
+#define SDP_JUMP_ADDRESS   0x0b0b
+#define SDP_SKIP_DCD_HEADER0x0c0c
+
+#define SDP_SECURITY_CLOSED0x12343412
+#define SDP_SECURITY_OPEN  0x56787856
+
+#define SDP_WRITE_FILE_COMPLETE0x
+#define SDP_WRITE_REGISTER_COMPLETE0x128A8A12
+#define SDP_SKIP_DCD_HEADER_COMPLETE   0x900DD009
+#define SDP_ERROR_IMXHEADER0x000a0533
+
+#define SDP_COMMAND_LEN16
+
+struct sdp_command {
+   u16 cmd;
+   u32 addr;
+   u8 format;
+   u32 cnt;
+   u32 data;
+   u8 rsvd;
+} __packed;
+
+enum sdp_state {
+   SDP_STATE_IDLE,
+   SDP_STATE_RX_DCD_DATA,
+   SDP_STATE_RX_FILE_DATA,
+   SDP_STATE_TX_SEC_CONF,
+   SDP_STATE_TX_SEC_CONF_BUSY,
+   SDP_STATE_TX_REGISTER,
+   SDP_STATE_TX_REGISTER_BUSY,
+   SDP_STATE_TX_STATUS,
+   SDP_STATE_TX_STATUS_BUSY,
+   SDP_STATE_JUMP,
+};
+
+struct f_sdp {
+   struct usb_function usb_function;
+
+   struct usb_descriptor_header**function;
+
+   u8  altsetting;
+   enum sdp_state  state;

[U-Boot] [PATCH v2 2/8] usb: gadget: add SDP driver

2017-08-16 Thread Stefan Agner
From: Stefan Agner 

Add SDP (Serial Downloader Protocol) implementation for U-Boot. The
protocol is used in NXP SoC's boot ROM and allows to download program
images. Beside that, it can also be used to read/write registers and
download complete Device Configuration Data (DCD) sets. This basic
implementation supports downloading images with the imx header format
reading and writing registers.

Signed-off-by: Stefan Agner 
---

Changes in v2:
- Changed function signature of sdp_init/sdp_handle to allow specifying
  which USB controller should be used.
- Use #defines for security mode
- Improved types used in format strings

 drivers/usb/gadget/Kconfig  |   7 +
 drivers/usb/gadget/Makefile |   1 +
 drivers/usb/gadget/f_sdp.c  | 721 
 include/sdp.h   |  16 +
 4 files changed, 745 insertions(+)
 create mode 100644 drivers/usb/gadget/f_sdp.c
 create mode 100644 include/sdp.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 261ed128ac..225b66bc95 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -103,6 +103,13 @@ config USB_GADGET_DOWNLOAD
 
 if USB_GADGET_DOWNLOAD
 
+config USB_FUNCTION_SDP
+   bool "Enable USB SDP (Serial Download Protocol)"
+   help
+ Enable Serial Download Protocol (SDP) device support in U-Boot. This
+ allows to download images into memory and execute (jump to) them
+ using the same protocol as implemented by the i.MX family's boot ROM.
+
 config G_DNL_MANUFACTURER
string "Vendor name of USB device"
 
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 5e316a7cff..6a007d1bcb 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_USB_FUNCTION_THOR) += f_thor.o
 obj-$(CONFIG_USB_FUNCTION_DFU) += f_dfu.o
 obj-$(CONFIG_USB_FUNCTION_MASS_STORAGE) += f_mass_storage.o
 obj-$(CONFIG_USB_FUNCTION_FASTBOOT) += f_fastboot.o
+obj-$(CONFIG_USB_FUNCTION_SDP) += f_sdp.o
 endif
 endif
 ifdef CONFIG_USB_ETHER
diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c
new file mode 100644
index 00..9d82abcd69
--- /dev/null
+++ b/drivers/usb/gadget/f_sdp.c
@@ -0,0 +1,721 @@
+/*
+ * f_sdp.c -- USB HID Serial Download Protocol
+ *
+ * Copyright (C) 2017 Toradex
+ * Author: Stefan Agner 
+ *
+ * This file implements the Serial Download Protocol (SDP) as specified in
+ * the i.MX 6 Reference Manual. The SDP is a USB HID based protocol and
+ * allows to download images directly to memory. The implementation
+ * works with the imx_loader (imx_usb) USB client software on host side.
+ *
+ * Not all commands are implemented, e.g. WRITE_REGISTER, DCD_WRITE and
+ * SKIP_DCD_HEADER are only stubs.
+ *
+ * Parts of the implementation are based on f_dfu and f_thor.
+ *
+ * SPDX-License-Identifier:GPL-2.0+
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#define HID_REPORT_ID_MASK 0x00ff
+
+/*
+ * HID class requests
+ */
+#define HID_REQ_GET_REPORT 0x01
+#define HID_REQ_GET_IDLE   0x02
+#define HID_REQ_GET_PROTOCOL   0x03
+#define HID_REQ_SET_REPORT 0x09
+#define HID_REQ_SET_IDLE   0x0A
+#define HID_REQ_SET_PROTOCOL   0x0B
+
+#define HID_USAGE_PAGE_LEN 76
+
+struct hid_report {
+   u8 usage_page[HID_USAGE_PAGE_LEN];
+} __packed;
+
+#define SDP_READ_REGISTER  0x0101
+#define SDP_WRITE_REGISTER 0x0202
+#define SDP_WRITE_FILE 0x0404
+#define SDP_ERROR_STATUS   0x0505
+#define SDP_DCD_WRITE  0x0a0a
+#define SDP_JUMP_ADDRESS   0x0b0b
+#define SDP_SKIP_DCD_HEADER0x0c0c
+
+#define SDP_SECURITY_CLOSED0x12343412
+#define SDP_SECURITY_OPEN  0x56787856
+
+#define SDP_WRITE_FILE_COMPLETE0x
+#define SDP_WRITE_REGISTER_COMPLETE0x128A8A12
+#define SDP_SKIP_DCD_HEADER_COMPLETE   0x900DD009
+#define SDP_ERROR_IMXHEADER0x000a0533
+
+#define SDP_COMMAND_LEN16
+
+struct sdp_command {
+   u16 cmd;
+   u32 addr;
+   u8 format;
+   u32 cnt;
+   u32 data;
+   u8 rsvd;
+} __packed;
+
+enum sdp_state {
+   SDP_STATE_IDLE,
+   SDP_STATE_RX_DCD_DATA,
+   SDP_STATE_RX_FILE_DATA,
+   SDP_STATE_TX_SEC_CONF,
+   SDP_STATE_TX_SEC_CONF_BUSY,
+   SDP_STATE_TX_REGISTER,
+   SDP_STATE_TX_REGISTER_BUSY,
+   SDP_STATE_TX_STATUS,
+   SDP_STATE_TX_STATUS_BUSY,
+   SDP_STATE_JUMP,
+};
+
+struct f_sdp {
+   struct usb_function usb_function;
+
+   struct usb_descriptor_header**function;
+
+   u8  altsetting;
+   enum sdp_state  state;
+   enum sdp_state  next_state;
+   u32