f_sdp: fix and update
Subsystems (4)
v2 cover f_sdp: fix and update
This is to upstream NXP downstream f_sdp fix/update.
V2:
Fix build break
Frank Li (1):
sdp: call board_usb_init at spl_sdp_load_image
Peng Fan (2):
f_sdp: Support searching and loading FIT or container image
spl: add g_dnl_get_board_bcd_device_number
Sherry Sun (2):
f_sdp: Add EP1_OUT as default data receive pipe in sdp
f_sdp: Change bInterval of interrupt endpoint to 3
Ye Li (2):
f_sdp: Add high speed endpoint descriptor
f_sdp: Fix wrong usb request size
arch/arm/mach-imx/spl.c | 6 ++ common/spl/spl_sdp.c | 2 + drivers/usb/gadget/f_sdp.c | 219 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 199 insertions(+), 28 deletions(-)
Signature · 1 line
2.16.4
PATCH v2 1/7 sdp: call board_usb_init at spl_sdp_load_image
From: Frank Li <[email protected]>
Need initialize UDC before run sdp download
--- common/spl/spl_sdp.c | 2 ++ 1 file changed, 2 insertions(+)
common/spl/spl_sdp.c +2 -0
@@ -19,6 +19,8 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,usb_gadget_initialize (controller_index); +board_usb_init (0 ,USB_INIT_DEVICE ); +g_dnl_clear_detach (); ret =g_dnl_register ("usb_dnl_sdp" );if (ret) {
Signature · 1 line
2.16.4
PATCH v2 1/7 sdp: call board_usb_init at spl_sdp_load_image
Hi Peng,
Quoted 15 lines
From: Frank Li <[email protected]>
Need initialize UDC before run sdp download
Signed-off-by Frank Li <[email protected]>Signed-off-by Peng Fan <[email protected]>--- common/spl/spl_sdp.c | 2 ++ 1 file changed, 2 insertions(+)common/spl/spl_sdp.c +0
-0
common/spl/spl_sdp.c static int spl_sdp_load_image(struct spl_image_info · line 23
Quoted 5 lines
common/spl/spl_sdp.c +2
-0@@ -19,6 +19,8 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,usb_gadget_initialize (controller_index); +board_usb_init (0 ,USB_INIT_DEVICE ); +
Is your board supporting device tree? And the 0 shall be adjustable - so others could re-use it.
common/spl/spl_sdp.c static int spl_sdp_load_image(struct spl_image_info *spl_image, · line 26
Quoted 3 lines
common/spl/spl_sdp.c +0
-0g_dnl_clear_detach (); ret =g_dnl_register ("usb_dnl_sdp" );if (ret) {
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-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200818/aa0072ea/attachment.sig>
PATCH v2 1/7 sdp: call board_usb_init at spl_sdp_load_image
Quoted 22 lines
Subject: Re: [PATCH v2 1/7] sdp: call
board_usb_initatspl_sdp_load_imageHi Peng,
Quoted 18 lines
From: Frank Li <[email protected]>
Need initialize UDC before run sdp download
Signed-off-by Frank Li <[email protected]>Signed-off-by Peng Fan <[email protected]>--- common/spl/spl_sdp.c | 2 ++ 1 file changed, 2 insertions(+)common/spl/spl_sdp.c index renamed from common/spl/spl_sdp.c +0
-0
e7f7b68411..ae9c09883a100644common/spl/spl_sdp.c +0
-0@@ -19,6 +19,8 @@ static int spl_sdp_load_image(struct spl_image_info *spl_image,usb_gadget_initialize (controller_index);
Quoted 5 lines
common/spl/spl_sdp.c static int spl_sdp_load_image(struct spl_image_info *spl_image, · line 23
Quoted 2 lines
common/spl/spl_sdp.c +2
-0+board_usb_init (0 ,USB_INIT_DEVICE ); +Is your board supporting device tree? And the 0 shall be adjustable - so others could re-use it.
Ok. Will add that.
Thanks,
Peng.
Quoted 18 lines
common/spl/spl_sdp.c static int spl_sdp_load_image(struct spl_image_info *spl_image, · line 26
Quoted 4 lines
common/spl/spl_sdp.c +0
-0g_dnl_clear_detach (); ret =g_dnl_register ("usb_dnl_sdp" );if (ret) {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-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de
PATCH v2 2/7 f_sdp: Add high speed endpoint descriptor
In reply to Peng FanFrom: Ye Li <[email protected]>
Add HS endpoint descriptor for SDP. So that we can use high speed endpoint, and the SDP device can send packet with 512 byte size.
--- drivers/usb/gadget/f_sdp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
drivers/usb/gadget/f_sdp.c +28 -2
@@ -159,6 +159,16 @@ static struct usb_endpoint_descriptor in_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor in_hs_desc = { + .bLength =USB_DT_ENDPOINT_SIZE , + .bDescriptorType =USB_DT_ENDPOINT ,/*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress =1 |USB_DIR_IN , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =512 , + .bInterval =1 , +}; +static struct usb_descriptor_header *sdp_runtime_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc,
@@ -166,6 +176,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = { NULL, }; +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = { + (struct usb_descriptor_header *)&sdp_intf_runtime, + (struct usb_descriptor_header *)&sdp_hid_desc, + (struct usb_descriptor_header *)&in_hs_desc, +NULL , +}; +/* This is synchronized with what the SoC implementation reports */ static struct hid_report sdp_hid_report = { .usage_page = {
@@ -489,6 +506,11 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f) goto error; } +if (gadget_is_dualspeed (gadget)) { +/* Assume endpoint addresses are the same for both speeds */ + in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress; + } + sdp->in_ep = ep;/* Store IN EP for enabling @ setup */ cdev->req->context = sdp;
@@ -541,11 +563,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt) {struct f_sdp *sdp =func_to_sdp (f);struct usb_composite_dev *cdev = f->config->cdev; +struct usb_gadget *gadget = cdev->gadget;int result;debug ("%s: intf: %d alt: %d\n" , __func__, intf, alt); - result =usb_ep_enable (sdp->in_ep, &in_desc); +if (gadget_is_dualspeed (gadget) && gadget->speed ==USB_SPEED_HIGH ) + result =usb_ep_enable (sdp->in_ep, &in_hs_desc); +else + result =usb_ep_enable (sdp->in_ep, &in_desc);if (result)return result; sdp->in_req =sdp_start_ep (sdp->in_ep);
@@ -591,7 +617,7 @@ static int sdp_bind_config(struct usb_configuration *c)memset (sdp_func,0 ,sizeof (*sdp_func)); sdp_func->usb_function.name ="sdp" ; - sdp_func->usb_function.hs_descriptors = sdp_runtime_descs; + sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs; sdp_func->usb_function.descriptors = sdp_runtime_descs; sdp_func->usb_function.bind = sdp_bind; sdp_func->usb_function.unbind = sdp_unbind;
Signature · 1 line
2.16.4
PATCH v2 2/7 f_sdp: Add high speed endpoint descriptor
Quoted 4 lines · On Tue, 18 Aug 2020 18:16:44 +0800 Peng Fan <[email protected]> wrote:
From: Ye Li <[email protected]>
Add HS endpoint descriptor for SDP. So that we can use high speed endpoint, and the SDP device can send packet with 512 byte size.
Do you use uuu for it? On which board do you perform tests?
Quoted 75 lines
Signed-off-by Ye Li <[email protected]>Signed-off-by Peng Fan <[email protected]>--- drivers/usb/gadget/f_sdp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)drivers/usb/gadget/f_sdp.c +18
-0@@ -159,6 +159,16 @@ static struct usb_endpoint_descriptor in_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor in_hs_desc = { + .bLength =USB_DT_ENDPOINT_SIZE , + .bDescriptorType =USB_DT_ENDPOINT , /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress =1 |USB_DIR_IN , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =512 , + .bInterval =1 , +}; +static struct usb_descriptor_header *sdp_runtime_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc,@@ -166,6 +176,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = { NULL, }; +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = { + (struct usb_descriptor_header *)&sdp_intf_runtime, + (struct usb_descriptor_header *)&sdp_hid_desc, + (struct usb_descriptor_header *)&in_hs_desc, +NULL , +}; +/* This is synchronized with what the SoC implementation reports */ static struct hid_report sdp_hid_report = { .usage_page = {@@ -489,6 +506,11 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f) goto error; } +if (gadget_is_dualspeed (gadget)) { +/* Assume endpoint addresses are the same for both speeds */
drivers/usb/gadget/f_sdp.c +1
-0+ in_hs_desc.bEndpointAddress =in_desc.bEndpointAddress;
drivers/usb/gadget/f_sdp.c +7
-1+ } + sdp->in_ep = ep;/* Store IN EP for enabling @ setup */ cdev->req->context = sdp;@@ -541,11 +563,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt) {struct f_sdp *sdp =func_to_sdp (f);struct usb_composite_dev *cdev = f->config->cdev; +struct usb_gadget *gadget = cdev->gadget;int result;debug ("%s: intf: %d alt: %d\n" , __func__, intf, alt); - result =usb_ep_enable (sdp->in_ep, &in_desc); +if (gadget_is_dualspeed (gadget) && gadget->speed ==USB_SPEED_HIGH ) + result =usb_ep_enable (sdp->in_ep, &in_hs_desc); +else + result =usb_ep_enable (sdp->in_ep, &in_desc);if (result)return result;drivers/usb/gadget/f_sdp.c +0
-0sdp->in_req =sdp_start_ep (sdp->in_ep);
drivers/usb/gadget/f_sdp.c static int sdp_bind_config(struct · line 623
Quoted 8 lines
drivers/usb/gadget/f_sdp.c +1
-1@@ -591,7 +617,7 @@ static int sdp_bind_config(struct usb_configuration *c) memset(sdp_func, 0, sizeof(*sdp_func)); sdp_func->usb_function.name ="sdp" ; - sdp_func->usb_function.hs_descriptors = sdp_runtime_descs; + sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs; sdp_func->usb_function.descriptors = sdp_runtime_descs; sdp_func->usb_function.bind = sdp_bind; sdp_func->usb_function.unbind = sdp_unbind;
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-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200818/60dcc3a6/attachment.sig>
PATCH v2 3/7 f_sdp: Fix wrong usb request size
In reply to Peng FanFrom: Ye Li <[email protected]>
Because the buffer length of sdp usb request is 65, we have to allocate 65 bytes not 64 bytes. Otherwise there is potential buffer overflow.
--- drivers/usb/gadget/f_sdp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/f_sdp.c +1 -1
@@ -548,7 +548,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep) {struct usb_request *req; - req =alloc_ep_req (ep,64 ); + req =alloc_ep_req (ep,65 );debug ("%s: ep:%p req:%p\n" , __func__, ep, req);if (!req)
Signature · 1 line
2.16.4
PATCH v2 3/7 f_sdp: Fix wrong usb request size
Quoted 17 lines · On Tue, 18 Aug 2020 18:16:45 +0800 Peng Fan <[email protected]> wrote:
From: Ye Li <[email protected]>
Because the buffer length of sdp usb request is 65, we have to allocate 65 bytes not 64 bytes. Otherwise there is potential buffer overflow.
Signed-off-by Ye Li <[email protected]>Signed-off-by Peng Fan <[email protected]>--- drivers/usb/gadget/f_sdp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/usb/gadget/f_sdp.c +0
-0
drivers/usb/gadget/f_sdp.c static struct usb_request *sdp_start_ep(struct · line 554
Quoted 8 lines
drivers/usb/gadget/f_sdp.c +1
-1@@ -548,7 +548,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep) {struct usb_request *req; - req =alloc_ep_req (ep,64 ); + req =alloc_ep_req (ep,65 );debug ("%s: ep:%p req:%p\n" , __func__, ep, req);if (!req)
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-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200818/8ededa38/attachment.sig>
PATCH v2 4/7 f_sdp: Support searching and loading FIT or container image
In reply to Peng FanAdd support to f_sdp to search and load iMX8 container image or iMX8M FIT image by new UUU command SDPV.
When using the SDPV, the uuu will continue to send out data after first level boot loader used by ROM. This means uuu won't skip to the offset of the second boot loader, and the padding data before second boot loader will be sent out. So we have to search the FIT header or container header in the buffer that SDP received.
Also change to more common method to exit f_sdp handler not depending on SPL_FIT_FOUND flag because container loader won't set this.
--- drivers/usb/gadget/f_sdp.c | 70 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-)
drivers/usb/gadget/f_sdp.c +58 -12
@@ -71,6 +71,8 @@ struct hid_report {#define SDP_COMMAND_LEN 16 +#define SDP_EXIT 1 +struct sdp_command {u16 cmd;u32 addr;
@@ -667,19 +669,43 @@ static u32 sdp_jump_imxheader(void *address) }#ifdef CONFIG_SPL_BUILD -#ifdef CONFIG_SPL_LOAD_FIT -static ulong sdp_fit_read (struct spl_load_info *load,ulong sector, -ulong count,void *buf) +static ulong sdp_load_read (struct spl_load_info *load,ulong sector, +ulong count,void *buf) {debug ("%s: sector %lx, count %lx, buf %lx\n" , __func__, sector, count, (ulong )buf);memcpy (buf, (void *)(load->dev + sector), count);return count; } -#endif + +static ulong search_fit_header (ulong p,int size) +{ +int i; + +for (i =0 ; i < size; i +=4 ) { +if (genimg_get_format ((const void *)(p + i)) ==IMAGE_FORMAT_FIT ) +return p + i; + } + +return 0 ; +} + +static ulong search_container_header (ulong p,int size) +{ +int i; +u8 *hdr; + +for (i =0 ; i < size; i +=4 ) { + hdr = (u8 *)(p + i); +if (*(hdr +3 ) ==0x87 && *hdr ==0 ) +if (*(hdr +1 ) !=0 || *(hdr +2 ) !=0 ) +return p + i; + } +return 0 ; +}#endif -static void sdp_handle_in_ep (struct spl_image_info *spl_image) +static int sdp_handle_in_ep (struct spl_image_info *spl_image) {u8 *data = sdp_func->in_req->buf;u32 status;
@@ -731,6 +757,15 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image)/* If imx header fails, try some U-Boot specific headers */ if (status) {#ifdef CONFIG_SPL_BUILD +if (IS_ENABLED (CONFIG_SPL_LOAD_IMX_CONTAINER )) + sdp_func->jmp_address = (u32 )search_container_header ((ulong )sdp_func->jmp_address, sdp_func->dnl_bytes); +else if (IS_ENABLED (CONFIG_SPL_LOAD_FIT )) + sdp_func->jmp_address = (u32 )search_fit_header ((ulong )sdp_func->jmp_address, sdp_func->dnl_bytes); +if (sdp_func->jmp_address ==0 ) +panic ("Error in search header, failed to jump\n" ); + +printf ("Found header at 0x%08x\n" , sdp_func->jmp_address); +image_header_t *header =sdp_ptr (sdp_func->jmp_address);#ifdef CONFIG_SPL_LOAD_FIT
@@ -740,13 +775,23 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image)debug ("Found FIT\n" ); load.dev = header; load.bl_len =1 ; - load.read = sdp_fit_read; + load.read = sdp_load_read;spl_load_simple_fit (spl_image, &load,0 , header); - return; + return SDP_EXIT; }#endif +if (IS_ENABLED (CONFIG_SPL_LOAD_IMX_CONTAINER )) { +struct spl_load_info load; + + load.dev = header; + load.bl_len =1 ; + load.read = sdp_load_read; +spl_load_imx_container (spl_image, &load,0 ); +return SDP_EXIT ; + } +/* In SPL, allow jumps to U-Boot images */ struct spl_image_info spl_image = {};spl_parse_image_header (&spl_image, header);
@@ -769,6 +814,8 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image)default :break ; }; + +return 0 ; }#ifndef CONFIG_SPL_BUILD
@@ -777,6 +824,7 @@ int sdp_handle(int controller_index) int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image)#endif { +int flag =0 ;printf ("SDP: handle requests...\n" );while (1 ) {if (ctrlc ()) {
@@ -784,18 +832,16 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image)return -EINVAL ; } -#ifdef CONFIG_SPL_BUILD -if (spl_image->flags &SPL_FIT_FOUND ) +if (flag ==SDP_EXIT )return 0 ; -#endif WATCHDOG_RESET ();usb_gadget_handle_interrupts (controller_index);#ifdef CONFIG_SPL_BUILD -sdp_handle_in_ep (spl_image); + flag =sdp_handle_in_ep (spl_image);#else -sdp_handle_in_ep (NULL ); + flag =sdp_handle_in_ep (NULL );#endif } }
Signature · 1 line
2.16.4
PATCH v2 4/7 f_sdp: Support searching and loading FIT or container image
Hi Peng,
Quoted 9 lines
Add support to
f_sdpto search and load iMX8 container image or iMX8M FIT image by new UUU command SDPV.When using the SDPV, the uuu will continue to send out data after first level boot loader used by ROM. This means uuu won't skip to the offset of the second boot loader, and the padding data before second boot loader will be sent out. So we have to search the FIT header or container header in the buffer that SDP received.
Please correct me if I'm wrong, but is there any documentation entry on using uuu with i.MX8* and this feature? If not - I would be very grateful if you could add a good tutorial/explanation for it.
(as I personally use uuu for iMX28 and iMX6Q).
Thanks in advance.
Quoted 150 lines
Also change to more common method to exit
f_sdphandler not depending onSPL_FIT_FOUNDflag because container loader won't set this.Signed-off-by Peng Fan <[email protected]>--- drivers/usb/gadget/f_sdp.c | 70++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-)
drivers/usb/gadget/f_sdp.c +31
-5@@ -71,6 +71,8 @@ struct hid_report {#define SDP_COMMAND_LEN 16 +#define SDP_EXIT 1 +struct sdp_command {u16 cmd;u32 addr;@@ -667,19 +669,43 @@ static u32 sdp_jump_imxheader(void *address) }#ifdef CONFIG_SPL_BUILD -#ifdef CONFIG_SPL_LOAD_FIT -static ulong sdp_fit_read (struct spl_load_info *load,ulong sector, -ulong count,void *buf) +static ulong sdp_load_read (struct spl_load_info *load,ulong sector, +ulong count,void *buf) {debug ("%s: sector %lx, count %lx, buf %lx\n" , __func__, sector, count, (ulong )buf);memcpy (buf, (void *)(load->dev + sector), count);return count; } -#endif + +static ulong search_fit_header (ulong p,int size) +{ +int i; + +for (i =0 ; i < size; i +=4 ) { +if (genimg_get_format ((const void *)(p + i)) ==IMAGE_FORMAT_FIT ) +return p + i; + } + +return 0 ; +} + +static ulong search_container_header (ulong p,int size) +{ +int i; +u8 *hdr; + +for (i =0 ; i < size; i +=4 ) { + hdr = (u8 *)(p + i); +if (*(hdr +3 ) ==0x87 && *hdr ==0 ) +if (*(hdr +1 ) !=0 || *(hdr +2 ) !=0 ) +return p + i; + } +return 0 ; +}#endif -static void sdp_handle_in_ep (struct spl_image_info *spl_image) +static int sdp_handle_in_ep (struct spl_image_info *spl_image) {u8 *data = sdp_func->in_req->buf;drivers/usb/gadget/f_sdp.c +0
-0u32 status;@@ -731,6 +757,15 @@ static void sdp_handle_in_ep(struct
spl_image_info*spl_image) /* If imx header fails, try some U-Boot specific headers */ if (status) {
#ifdefCONFIG_SPL_BUILDdrivers/usb/gadget/f_sdp.c +1
-0+ if(
IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER))drivers/usb/gadget/f_sdp.c +1
-0+ sdp_func->jmp_address =(u32)search_container_header((ulong)sdp_func->jmp_address,
sdp_func->dnl_bytes);drivers/usb/gadget/f_sdp.c +2
-0+else if (IS_ENABLED (CONFIG_SPL_LOAD_FIT )) + sdp_func->jmp_address =(u32)search_fit_header((ulong)sdp_func->jmp_address,
sdp_func->dnl_bytes);drivers/usb/gadget/f_sdp.c +2
-0+if (sdp_func->jmp_address ==0 ) + panic("Error in search header,failed to jump\n"); +
drivers/usb/gadget/f_sdp.c +1
-0+ printf("Found header at 0x%08x\n",
sdp_func->jmp_address); +drivers/usb/gadget/f_sdp.c +12
-2image_header_t *header =sdp_ptr (sdp_func->jmp_address);#ifdef CONFIG_SPL_LOAD_FIT @@ -740,13 +775,23 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) debug("Found FIT\n"); load.dev = header; load.bl_len =1 ; - load.read = sdp_fit_read; + load.read = sdp_load_read;spl_load_simple_fit (spl_image, &load,0 , header); -return ; + return SDP_EXIT; }#endif +if (IS_ENABLED (CONFIG_SPL_LOAD_IMX_CONTAINER )) { +struct spl_load_info load; + + load.dev = header; + load.bl_len =1 ; + load.read = sdp_load_read; +spl_load_imx_container (spl_image, &load,0 ); +return SDP_EXIT ; + } +/* In SPL, allow jumps to U-Boot images */ drivers/usb/gadget/f_sdp.c +0
-0struct spl_image_info spl_image = {};spl_parse_image_header (&spl_image, header);@@ -769,6 +814,8 @@ static void sdp_handle_in_ep(struct
spl_image_info*spl_image) default:drivers/usb/gadget/f_sdp.c +4
-3break ; }; + +return 0 ; }#ifndef CONFIG_SPL_BUILD @@ -777,6 +824,7 @@ int sdp_handle(int controller_index)int spl_sdp_handle (int controller_index,struct spl_image_info *spl_image) #endif { +int flag =0 ;printf ("SDP: handle requests...\n" );while (1 ) {if (ctrlc ()) {@@ -784,18 +832,16 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) return -EINVAL; } -#ifdef CONFIG_SPL_BUILD -if (spl_image->flags &SPL_FIT_FOUND ) +if (flag ==SDP_EXIT )return 0 ; -#endif WATCHDOG_RESET ();usb_gadget_handle_interrupts (controller_index);
drivers/usb/gadget/f_sdp.c int spl_sdp_handle(int controller_index, struct · line 847
Quoted 10 lines
drivers/usb/gadget/f_sdp.c +2
-2#ifdef CONFIG_SPL_BUILD -sdp_handle_in_ep (spl_image); + flag =sdp_handle_in_ep (spl_image);#else -sdp_handle_in_ep (NULL ); + flag =sdp_handle_in_ep (NULL );#endif } }
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-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200818/009f2331/attachment.sig>
PATCH v2 4/7 f_sdp: Support searching and loading FIT or container image
Quoted 15 lines
Subject: Re: [PATCH v2 4/7]
f_sdp: Support searching and loading FIT or container imageHi Peng,
Quoted 9 lines
Add support to
f_sdpto search and load iMX8 container image or iMX8M FIT image by new UUU command SDPV.When using the SDPV, the uuu will continue to send out data after first level boot loader used by ROM. This means uuu won't skip to the offset of the second boot loader, and the padding data before second boot loader will be sent out. So we have to search the FIT header or container header in the buffer that SDP received.
Quoted 3 lines
Please correct me if I'm wrong, but is there any documentation entry on using uuu with i.MX8* and this feature? If not - I would be very grateful if you could add a good tutorial/explanation for it.
uuu code is here: https://github.com/NXPmicro/mfgtools
It has documentation on using it.
For i.MX8*, the major stuff is just uuu only support flash.bin which is packed by imx-mkimage. For using upstream U-Boot to generate flash.bin, there are still features not ported.
What kind documentation do you expect?
There are still lots stuff in downstream.. I am trying to upstream every bit to make it work, but without usb in upstream, it would not work.
Thanks,
Peng.
Quoted 177 lines
(as I personally use uuu for iMX28 and iMX6Q).
Thanks in advance.
drivers/usb/gadget/f_sdp.c static u32 sdp_jump_imxheader(void
Quoted 23 lines
Also change to more common method to exit
f_sdphandler not depending onSPL_FIT_FOUNDflag because container loader won't set this.Signed-off-by Peng Fan <[email protected]>--- drivers/usb/gadget/f_sdp.c | 70++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-)
drivers/usb/gadget/f_sdp.c +2
-0@@ -71,6 +71,8 @@ struct hid_report {#define SDP_COMMAND_LEN 16 +#define SDP_EXIT 1 +struct sdp_command {u16 cmd;u32 addr;@@ -667,19 +669,43 @@ static u32 sdp_jump_imxheader(void*address) }
Quoted 92 lines
drivers/usb/gadget/f_sdp.c +27
-5#ifdef CONFIG_SPL_BUILD -#ifdef CONFIG_SPL_LOAD_FIT -static ulong sdp_fit_read (struct spl_load_info *load,ulong sector, -ulong count,void *buf) +static ulong sdp_load_read (struct spl_load_info *load,ulong sector, +ulong count,void *buf) {debug ("%s: sector %lx, count %lx, buf %lx\n" , __func__, sector, count, (ulong )buf);memcpy (buf, (void *)(load->dev + sector), count);return count; } -#endif + +static ulong search_fit_header (ulong p,int size) { +int i; + +for (i =0 ; i < size; i +=4 ) { +if (genimg_get_format ((const void *)(p + i)) ==IMAGE_FORMAT_FIT ) +return p + i; + } + +return 0 ; +} + +static ulong search_container_header (ulong p,int size) { +int i; +u8 *hdr; + +for (i =0 ; i < size; i +=4 ) { + hdr = (u8 *)(p + i); +if (*(hdr +3 ) ==0x87 && *hdr ==0 ) +if (*(hdr +1 ) !=0 || *(hdr +2 ) !=0 ) +return p + i; + } +return 0 ; +}#endif -static void sdp_handle_in_ep (struct spl_image_info *spl_image) +static int sdp_handle_in_ep (struct spl_image_info *spl_image) {u8 *data = sdp_func->in_req->buf;u32 status;@@ -731,6 +757,15 @@ static void sdp_handle_in_ep(struct
spl_image_info*spl_image) /* If imx header fails, try some U-Boot specific headers */ if (status) { #ifdefCONFIG_SPL_BUILDdrivers/usb/gadget/f_sdp.c +1
-0+ if(
IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER))drivers/usb/gadget/f_sdp.c +1
-0+ sdp_func->jmp_address =(u32)search_container_header((ulong)sdp_func->jmp_address,
sdp_func->dnl_bytes);drivers/usb/gadget/f_sdp.c +2
-0+else if (IS_ENABLED (CONFIG_SPL_LOAD_FIT )) + sdp_func->jmp_address =(u32)search_fit_header((ulong)sdp_func->jmp_address,
sdp_func->dnl_bytes);drivers/usb/gadget/f_sdp.c +2
-0+if (sdp_func->jmp_address ==0 ) + panic("Error in search header,failed to jump\n"); +
drivers/usb/gadget/f_sdp.c +1
-0+ printf("Found header at 0x%08x\n",
sdp_func->jmp_address); +drivers/usb/gadget/f_sdp.c +12
-2image_header_t *header =sdp_ptr (sdp_func->jmp_address);#ifdef CONFIG_SPL_LOAD_FIT @@ -740,13 +775,23 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) debug("Found FIT\n"); load.dev = header; load.bl_len =1 ; - load.read = sdp_fit_read; + load.read = sdp_load_read;spl_load_simple_fit (spl_image, &load,0 , header); -return ; + return SDP_EXIT; }#endif +if (IS_ENABLED (CONFIG_SPL_LOAD_IMX_CONTAINER )) { +struct spl_load_info load; + + load.dev = header; + load.bl_len =1 ; + load.read = sdp_load_read; +spl_load_imx_container (spl_image, &load,0 ); +return SDP_EXIT ; + } +/* In SPL, allow jumps to U-Boot images */ drivers/usb/gadget/f_sdp.c
Quoted 2 lines
drivers/usb/gadget/f_sdp.c +0
-0struct spl_image_info spl_image = {}; spl_parse_image_header(&spl_image, header); @@ -769,6+814,8 @@
Quoted 29 lines
static void
sdp_handle_in_ep(struct spl_image_info *spl_image)default:drivers/usb/gadget/f_sdp.c +2
-0break ; }; + +return 0 ; }#ifndef CONFIG_SPL_BUILD @@ -777,6 +824,7 @@ int sdp_handle(int controller_index) int
spl_sdp_handle(int controller_index, struct spl_image_info *spl_image)#endif
{drivers/usb/gadget/f_sdp.c +2
-3+int flag =0 ;printf ("SDP: handle requests...\n" );while (1 ) {if (ctrlc ()) {@@ -784,18 +832,16 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) return -EINVAL; } -#ifdef CONFIG_SPL_BUILD -if (spl_image->flags &SPL_FIT_FOUND ) +if (flag ==SDP_EXIT )return 0 ; -#endif WATCHDOG_RESET ();usb_gadget_handle_interrupts (controller_index);drivers/usb/gadget/f_sdp.c int spl_sdp_handle(int controller_index, struct · line 847
Quoted 10 lines
drivers/usb/gadget/f_sdp.c +2
-2#ifdef CONFIG_SPL_BUILD -sdp_handle_in_ep (spl_image); + flag =sdp_handle_in_ep (spl_image);#else -sdp_handle_in_ep (NULL ); + flag =sdp_handle_in_ep (NULL );#endif } }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-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de
PATCH v2 4/7 f_sdp: Support searching and loading FIT or container image
Hi Peng,
Quoted 15 lines
Quoted 15 lines
Subject: Re: [PATCH v2 4/7]
f_sdp: Support searching and loading FIT or container imageHi Peng,
Quoted 9 lines
Add support to
f_sdpto search and load iMX8 container image or iMX8M FIT image by new UUU command SDPV.When using the SDPV, the uuu will continue to send out data after first level boot loader used by ROM. This means uuu won't skip to the offset of the second boot loader, and the padding data before second boot loader will be sent out. So we have to search the FIT header or container header in the buffer that SDP received.
Quoted 8 lines
Quoted 4 lines
Please correct me if I'm wrong, but is there any documentation entry on using uuu with i.MX8* and this feature? If not - I would be very grateful if you could add a good tutorial/explanation for it.
uuu code is here: https://github.com/NXPmicro/mfgtools
It has documentation on using it.
Yes.
Quoted 3 lines
For i.MX8*, the major stuff is just uuu only support flash.bin which is packed by imx-mkimage.
Ok. So support to mkimage is not yet added.
Quoted 2 lines
For using upstream U-Boot to generate
flash.bin, there are still features not ported.
Ok.
Quoted 2 lines
What kind documentation do you expect?
I would like to have documentation entries being added with every bit of code ported from downstream to upstream.
As I do know that it is very handy to have it around - not in NXP's forum or webpage, which can disappear - like pdfs for i.MX28.
Quoted 3 lines
There are still lots stuff in downstream.. I am trying to upstream every bit to make it work,
Great :-)
Quoted 2 lines
but without usb in upstream, it would not
work.
Ok.
Quoted 185 lines
Thanks,
Peng.Quoted 181 lines
(as I personally use uuu for iMX28 and iMX6Q).
Thanks in advance.
drivers/usb/gadget/f_sdp.c static u32 sdp_jump_imxheader(void
Quoted 24 lines
Also change to more common method to exit
f_sdphandler not depending onSPL_FIT_FOUNDflag because container loader won't set this.Signed-off-by Peng Fan <[email protected]>--- drivers/usb/gadget/f_sdp.c | 70++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 12 deletions(-)
(quoted diff) +0
-0
b/drivers/usb/gadget/f_sdp.cindexeec7560fc2..9b7372815d100644drivers/usb/gadget/f_sdp.c +2
-0@@ -71,6 +71,8 @@ struct hid_report {#define SDP_COMMAND_LEN 16 +#define SDP_EXIT 1 +struct sdp_command {u16 cmd;u32 addr;@@ -667,19 +669,43 @@ static u32 sdp_jump_imxheader(void*address) }
Quoted 94 lines
drivers/usb/gadget/f_sdp.c +27
-5#ifdef CONFIG_SPL_BUILD -#ifdef CONFIG_SPL_LOAD_FIT -static ulong sdp_fit_read (struct spl_load_info *load,ulong sector, -ulong count,void *buf) +static ulong sdp_load_read(struct spl_load_info *load, ulong sector, +ulong count,void *buf) {debug ("%s: sector %lx, count %lx, buf %lx\n" , __func__, sector, count, (ulong )buf);memcpy (buf, (void *)(load->dev + sector), count);return count; } -#endif + +static ulong search_fit_header (ulong p,int size) { +int i; + +for (i =0 ; i < size; i +=4 ) { +if (genimg_get_format ((const void *)(p + i)) ==IMAGE_FORMAT_FIT ) +return p + i; + } + +return 0 ; +} + +static ulong search_container_header (ulong p,int size) { +int i; +u8 *hdr; + +for (i =0 ; i < size; i +=4 ) { + hdr = (u8 *)(p + i); +if (*(hdr +3 ) ==0x87 && *hdr ==0 ) +if (*(hdr +1 ) !=0 || *(hdr +2 ) !=0 ) +return p + i; + } +return 0 ; +}#endif -static void sdp_handle_in_ep (struct spl_image_info *spl_image) +static int sdp_handle_in_ep (struct spl_image_info *spl_image) {u8 *data = sdp_func->in_req->buf;u32 status;@@ -731,6 +757,15 @@ static void sdp_handle_in_ep(struct
spl_image_info*spl_image) /* If imx header fails, try some U-Boot specific headers */ if (status) { #ifdefCONFIG_SPL_BUILDdrivers/usb/gadget/f_sdp.c +1
-0+ if(
IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER))drivers/usb/gadget/f_sdp.c +1
-0+ sdp_func->jmp_address =(u32)search_container_header((ulong)sdp_func->jmp_address,
sdp_func->dnl_bytes);drivers/usb/gadget/f_sdp.c +2
-0+else if (IS_ENABLED (CONFIG_SPL_LOAD_FIT )) + sdp_func->jmp_address =(u32)search_fit_header((ulong)sdp_func->jmp_address,
sdp_func->dnl_bytes);drivers/usb/gadget/f_sdp.c +2
-0+if (sdp_func->jmp_address ==0 ) + panic("Error in search header,failed to jump\n"); +
drivers/usb/gadget/f_sdp.c +1
-0+ printf("Found header at 0x%08x\n",
sdp_func->jmp_address); +drivers/usb/gadget/f_sdp.c +12
-2image_header_t *header =sdp_ptr (sdp_func->jmp_address);#ifdef CONFIG_SPL_LOAD_FIT @@ -740,13 +775,23 @@ static void sdp_handle_in_ep(struct spl_image_info *spl_image) debug("Found FIT\n"); load.dev = header; load.bl_len =1 ; - load.read = sdp_fit_read; + load.read = sdp_load_read;spl_load_simple_fit (spl_image, &load,0 , header); -return ; + return SDP_EXIT; }#endif +if (IS_ENABLED (CONFIG_SPL_LOAD_IMX_CONTAINER )) { +struct spl_load_info load; + + load.dev = header; + load.bl_len =1 ; + load.read = sdp_load_read; +spl_load_imx_container (spl_image, &load,0 ); +return SDP_EXIT ; + } +/* In SPL, allow jumps to U-Boot images Quoted 3 lines
*/ struct
spl_image_infospl_image= {};
spl_parse_image_header(&spl_image,
header); @@ -769,6+814,8 @@
Quoted 29 lines
static void
sdp_handle_in_ep(struct spl_image_info *spl_image)default:drivers/usb/gadget/f_sdp.c +2
-0break ; }; + +return 0 ; }#ifndef CONFIG_SPL_BUILD @@ -777,6 +824,7 @@ int sdp_handle(int controller_index) int
spl_sdp_handle(int controller_index, struct spl_image_info *spl_image)#endif
{drivers/usb/gadget/f_sdp.c +2
-3+int flag =0 ;printf ("SDP: handle requests...\n" );while (1 ) {if (ctrlc ()) {@@ -784,18 +832,16 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image) return -EINVAL; } -#ifdef CONFIG_SPL_BUILD -if (spl_image->flags &SPL_FIT_FOUND ) +if (flag ==SDP_EXIT )return 0 ; -#endif WATCHDOG_RESET ();usb_gadget_handle_interrupts (controller_index);drivers/usb/gadget/f_sdp.c int spl_sdp_handle(int controller_index, · line 847
Quoted 10 lines
drivers/usb/gadget/f_sdp.c +2
-2#ifdef CONFIG_SPL_BUILD -sdp_handle_in_ep (spl_image); + flag =sdp_handle_in_ep (spl_image);#else -sdp_handle_in_ep (NULL ); + flag =sdp_handle_in_ep (NULL );#endif } }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-59 Fax: (+49)-8142-66989-80 Email:
lukma at 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-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200818/72a3431f/attachment.sig>
PATCH v2 5/7 spl: add g_dnl_get_board_bcd_device_number
In reply to Peng FanAdd g_dnl_get_board_bcd_device_number, the new BCD value is used by uuu to distinguish if the SPL supports the SDPV.
--- arch/arm/mach-imx/spl.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/arm/mach-imx/spl.c +6 -0
@@ -187,6 +187,12 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) return 0; } + +#define SDPV_BCD_DEVICE 0x500 +int g_dnl_get_board_bcd_device_number (int gcnum) +{ +return SDPV_BCD_DEVICE ; +}#endif #if defined(CONFIG_SPL_MMC_SUPPORT )
Signature · 1 line
2.16.4
PATCH v2 5/7 spl: add g_dnl_get_board_bcd_device_number
Quoted 15 lines · On Tue, 18 Aug 2020 18:16:47 +0800 Peng Fan <[email protected]> wrote:
Add
g_dnl_get_board_bcd_device_number, the new BCD value is used by uuu to distinguish if the SPL supports the SDPV.Signed-off-by Peng Fan <[email protected]>--- arch/arm/mach-imx/spl.c | 6 ++++++ 1 file changed, 6 insertions(+)arch/arm/mach-imx/spl.c +0
-0@@ -187,6 +187,12 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) return 0;
arch/arm/mach-imx/spl.c int g_dnl_bind_fixup(struct · line 198
Quoted 10 lines
arch/arm/mach-imx/spl.c +6
-0} + +#define SDPV_BCD_DEVICE 0x500 +int g_dnl_get_board_bcd_device_number (int gcnum) +{ +return SDPV_BCD_DEVICE ; +}#endif #if defined(CONFIG_SPL_MMC_SUPPORT )
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-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200818/ecb32429/attachment.sig>
PATCH v2 6/7 f_sdp: Add EP1_OUT as default data receive pipe in sdp
In reply to Peng FanFrom: Sherry Sun <[email protected]>
EP0 has been used to transfer file data in sdp before, but the max packetsize of ep0 is 64 bytes. So in order to improve the file transfer speed, here add the EP1_OUT interrupt endpoint which max packetsize is set to 1024 byte.
After testing, it turns out that using ep1out is twice as fast as using ep0 while receiving data in sdp.
--- drivers/usb/gadget/f_sdp.c | 123 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 16 deletions(-)
drivers/usb/gadget/f_sdp.c +107 -16
@@ -71,6 +71,8 @@ struct hid_report {#define SDP_COMMAND_LEN 16 +#define SDP_HID_PACKET_SIZE_EP1 1024 +#define SDP_EXIT 1struct sdp_command {
@@ -84,8 +86,10 @@ struct sdp_command {enum sdp_state {SDP_STATE_IDLE , +SDP_STATE_RX_CMD ,SDP_STATE_RX_DCD_DATA ,SDP_STATE_RX_FILE_DATA , +SDP_STATE_RX_FILE_DATA_BUSY ,SDP_STATE_TX_SEC_CONF ,SDP_STATE_TX_SEC_CONF_BUSY ,SDP_STATE_TX_REGISTER ,
@@ -116,8 +120,12 @@ struct f_sdp {/* EP1 IN */ struct usb_ep *in_ep;struct usb_request *in_req; +/* EP1 OUT */ +struct usb_ep *out_ep; +struct usb_request *out_req;bool configuration_done; +bool ep_int_enable; };static struct f_sdp *sdp_func;
@@ -131,7 +139,7 @@ static struct usb_interface_descriptor sdp_intf_runtime = { .bLength = sizeof(sdp_intf_runtime), .bDescriptorType = USB_DT_INTERFACE, .bAlternateSetting = 0, - .bNumEndpoints = 1, + .bNumEndpoints = 2, .bInterfaceClass = USB_CLASS_HID, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0,
@@ -161,6 +169,16 @@ static struct usb_endpoint_descriptor in_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor out_desc = { + .bLength =USB_DT_ENDPOINT_SIZE , + .bDescriptorType =USB_DT_ENDPOINT ,/*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress =1 |USB_DIR_OUT , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =64 , + .bInterval =1 , +}; +static struct usb_endpoint_descriptor in_hs_desc = { .bLength =USB_DT_ENDPOINT_SIZE , .bDescriptorType =USB_DT_ENDPOINT ,/*USB_DT_CS_ENDPOINT*/
@@ -171,10 +189,21 @@ static struct usb_endpoint_descriptor in_hs_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor out_hs_desc = { + .bLength =USB_DT_ENDPOINT_SIZE , + .bDescriptorType =USB_DT_ENDPOINT ,/*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress =1 |USB_DIR_OUT , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =SDP_HID_PACKET_SIZE_EP1 , + .bInterval =1 , +}; +static struct usb_descriptor_header *sdp_runtime_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc, (struct usb_descriptor_header *)&in_desc, + (struct usb_descriptor_header *)&out_desc,NULL , };
@@ -182,6 +211,7 @@ static struct usb_descriptor_header *sdp_runtime_hs_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc, (struct usb_descriptor_header *)&in_hs_desc, + (struct usb_descriptor_header *)&out_hs_desc, NULL, };
@@ -347,7 +377,7 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req)int status = req->status;u8 *data = req->buf;u8 report = data[0 ]; -int datalen = req->length -1 ; +int datalen = req->actual -1 ;if (status !=0 ) {pr_err ("Status: %d\n" , status);
@@ -370,13 +400,15 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) sdp->dnl_bytes_remaining -= datalen; } -if (sdp->state ==SDP_STATE_RX_FILE_DATA ) { +if (sdp->state ==SDP_STATE_RX_FILE_DATA_BUSY ) {memcpy (sdp_ptr (sdp->dnl_address), req->buf +1 , datalen); sdp->dnl_address += datalen; } -if (sdp->dnl_bytes_remaining) +if (sdp->dnl_bytes_remaining) { + sdp->state =SDP_STATE_RX_FILE_DATA ;return ; + }#ifndef CONFIG_SPL_BUILD env_set_hex ("filesize" , sdp->dnl_bytes);
@@ -384,7 +416,7 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req)printf ("done\n" );switch (sdp->state) { -case SDP_STATE_RX_FILE_DATA : +case SDP_STATE_RX_FILE_DATA_BUSY : sdp->state =SDP_STATE_TX_SEC_CONF ;break ;case SDP_STATE_RX_DCD_DATA :
@@ -465,10 +497,12 @@ static int sdp_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)case 1 : value =SDP_COMMAND_LEN +1 ; req->complete = sdp_rx_command_complete; + sdp_func->ep_int_enable = false;break ;case 2 : value = len; req->complete = sdp_rx_data_complete; + sdp_func->state =SDP_STATE_RX_FILE_DATA_BUSY ;break ; } }
@@ -499,11 +533,17 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f)return id; sdp_intf_runtime.bInterfaceNumber = id; -struct usb_ep *ep; +struct usb_ep *ep_in, *ep_out;/* allocate instance-specific endpoints */ - ep =usb_ep_autoconfig (gadget, &in_desc); -if (!ep) { + ep_in =usb_ep_autoconfig (gadget, &in_desc); +if (!ep_in) { + rv = -ENODEV ; + goto error; + } + + ep_out =usb_ep_autoconfig (gadget, &out_desc); +if (!ep_out) { rv = -ENODEV ; goto error; }
@@ -511,9 +551,11 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f)if (gadget_is_dualspeed (gadget)) {/* Assume endpoint addresses are the same for both speeds */ in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress; + out_hs_desc.bEndpointAddress = out_desc.bEndpointAddress; } - sdp->in_ep = ep;/* Store IN EP for enabling @ setup */ + sdp->in_ep = ep_in;/* Store IN EP for enabling @ setup */ + sdp->out_ep = ep_out; cdev->req->context = sdp;
@@ -546,18 +588,29 @@ static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length) } -static struct usb_request *sdp_start_ep (struct usb_ep *ep) +static struct usb_request *sdp_start_ep (struct usb_ep *ep,bool in) {struct usb_request *req; - req =alloc_ep_req (ep,65 ); +if (in) + req =alloc_ep_req (ep,65 ); +else + req =alloc_ep_req (ep,2048 ); +/* +* OUT endpoint request length should be an integral multiple of +* maxpacket size 1024, else we break on certain controllers like +* DWC3 that expect bulk OUT requests to be divisible by maxpacket size. +*/ debug ("%s: ep:%p req:%p\n" , __func__, ep, req);if (!req)return NULL ;memset (req->buf,0 , req->length); - req->complete = sdp_tx_complete; +if (in) + req->complete = sdp_tx_complete; +else + req->complete = sdp_rx_command_complete;return req; }
@@ -570,19 +623,27 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt)debug ("%s: intf: %d alt: %d\n" , __func__, intf, alt); -if (gadget_is_dualspeed (gadget) && gadget->speed ==USB_SPEED_HIGH ) +if (gadget_is_dualspeed (gadget) && gadget->speed ==USB_SPEED_HIGH ) { result =usb_ep_enable (sdp->in_ep, &in_hs_desc); -else + result |=usb_ep_enable (sdp->out_ep, &out_hs_desc); + }else { result =usb_ep_enable (sdp->in_ep, &in_desc); + result |=usb_ep_enable (sdp->out_ep, &out_desc); + }if (result)return result; - sdp->in_req =sdp_start_ep (sdp->in_ep); + + sdp->in_req =sdp_start_ep (sdp->in_ep, true); sdp->in_req->context = sdp; + sdp->out_req =sdp_start_ep (sdp->out_ep, false); + sdp->out_req->context = sdp; sdp->in_ep->driver_data = cdev;/* claim */ + sdp->out_ep->driver_data = cdev;/* claim */ sdp->altsetting = alt; sdp->state =SDP_STATE_IDLE ; + sdp->ep_int_enable = true;return 0 ; }
@@ -599,11 +660,18 @@ static void sdp_disable(struct usb_function *f)struct f_sdp *sdp =func_to_sdp (f);usb_ep_disable (sdp->in_ep); +usb_ep_disable (sdp->out_ep);if (sdp->in_req) { -free (sdp->in_req); +free (sdp->in_req->buf); +usb_ep_free_request (sdp->in_ep, sdp->in_req); sdp->in_req =NULL ; } +if (sdp->out_req) { +free (sdp->out_req->buf); +usb_ep_free_request (sdp->out_ep, sdp->out_req); + sdp->out_req =NULL ; + } }static int sdp_bind_config (struct usb_configuration *c)
@@ -818,6 +886,27 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image)return 0 ; } +static void sdp_handle_out_ep (void ) +{ +int rc; + +if (sdp_func->state ==SDP_STATE_IDLE ) { + sdp_func->out_req->complete = sdp_rx_command_complete; + rc =usb_ep_queue (sdp_func->out_ep, sdp_func->out_req,0 ); +if (rc) +printf ("error in submission: %s\n" , + sdp_func->out_ep->name); + sdp_func->state =SDP_STATE_RX_CMD ; + }else if (sdp_func->state ==SDP_STATE_RX_FILE_DATA ) { + sdp_func->out_req->complete = sdp_rx_data_complete; + rc =usb_ep_queue (sdp_func->out_ep, sdp_func->out_req,0 ); +if (rc) +printf ("error in submission: %s\n" , + sdp_func->out_ep->name); + sdp_func->state =SDP_STATE_RX_FILE_DATA_BUSY ; + } +} +#ifndef CONFIG_SPL_BUILD int sdp_handle (int controller_index) #else
@@ -843,6 +932,8 @@ int spl_sdp_handle(int controller_index, struct spl_image_info *spl_image)#else flag =sdp_handle_in_ep (NULL );#endif +if (sdp_func->ep_int_enable) +sdp_handle_out_ep (); } }
Signature · 1 line
2.16.4
PATCH v2 7/7 f_sdp: Change bInterval of interrupt endpoint to 3
In reply to Peng FanFrom: Sherry Sun <[email protected]>
Since the USB HID limits the maximum bandwidth(3072) for interrupt endpoint transfers, when the bInterval set to 1, we can only support 3 boards to run sdp at the same time. In order to support more boards, change the bInterval of interrupt endpoint to 3, which will not affect the transmission speed.
--- drivers/usb/gadget/f_sdp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/f_sdp.c +2 -2
@@ -186,7 +186,7 @@ static struct usb_endpoint_descriptor in_hs_desc = { .bEndpointAddress = 1 | USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_INT, .wMaxPacketSize = 512, - .bInterval = 1, + .bInterval = 3, };static struct usb_endpoint_descriptor out_hs_desc = {
@@ -196,7 +196,7 @@ static struct usb_endpoint_descriptor out_hs_desc = { .bEndpointAddress = 1 | USB_DIR_OUT, .bmAttributes = USB_ENDPOINT_XFER_INT, .wMaxPacketSize = SDP_HID_PACKET_SIZE_EP1, - .bInterval = 1, + .bInterval = 3, };static struct usb_descriptor_header *sdp_runtime_descs[] = {
Signature · 1 line
2.16.4