All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pantelis Antoniou <panto@antoniou-consulting.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 6/9] dfu: Send correct DFU response from composite_setup
Date: Mon, 10 Dec 2012 20:21:18 +0200	[thread overview]
Message-ID: <5BA5AE75-F714-47D8-938F-AF2E8CE0D6B4@antoniou-consulting.com> (raw)
In-Reply-To: <20121210181146.51631226@amdc308.digital.local>

Hi Lukasz,

On Dec 10, 2012, at 7:11 PM, Lukasz Majewski wrote:

> Hi Pantelis,
> 
>> DFU is a bit peculiar. It needs to hook to composite setup and
>> return it's function descriptor.
>> 
>> So when get-descriptor request comes with a type of DFU_DT_FUNC
>> we iterate over the configs, and functions, and when we find
>> the DFU function we call the setup method which is prepared
>> to return the appropriate function descriptor.
> 
> Sorry, but could you be more informative here? Have you had any non
> standard problems? I wonder why dfu-util on my linux works OK without
> this patch?
> 

I have absolutely no idea why it works at your side.

At our side it just didn't work at all without the patches.

If I had to guess maybe your gadget h/w takes care of replying
properly for the DFU case.

>> 
>> Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
>> ---
>> drivers/usb/gadget/composite.c | 27 +++++++++++++++++++++++++++
>> drivers/usb/gadget/ep0.c       |  1 +
>> drivers/usb/gadget/f_dfu.c     |  6 ++++--
>> 3 files changed, 32 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/usb/gadget/composite.c
>> b/drivers/usb/gadget/composite.c index ebb5131..6496436 100644
>> --- a/drivers/usb/gadget/composite.c
>> +++ b/drivers/usb/gadget/composite.c
>> @@ -773,6 +773,33 @@ composite_setup(struct usb_gadget *gadget, const
>> struct usb_ctrlrequest *ctrl) if (value >= 0)
>> 				value = min(w_length, (u16) value);
>> 			break;
>> +
>> +#ifdef CONFIG_DFU_FUNCTION
>> +		/* DFU is mighty weird */
> 				^^^^^^ - please explain this
> 				"wiredness". 
> 
> I don't recall such a hacks in linux kernel composite.c (any special
> #ifdef). Am I missing something important in DFU?
> 
> 
> Does your device have any special requirement, so you need this hack?
> 
> I generally don't like the idea to "patch" composite gadget code with
> #ifdefs for special function. Please convince me.

It doesn't work otherwise. I have no idea why you think I would be hacking
around there if the thing worked at all. And trust me on that, it just doesn't
without those patches, not to mention the way it unceremoniously blows up if
you transfer anything larger than the buffer set aside originally.

The way I see it, instead of complaining you should be rejoicing since now
DFU will be used in an actual production environment. 

More users == less bugs.

When I get a few free cycles I will post a tcpdump capture of the DFU USB
transaction hanging.

> 
>> +		case DFU_DT_FUNC:
>> +			w_value &= 0xff;
>> +			list_for_each_entry(c, &cdev->configs, list)
>> {
>> +				if (w_value != 0) {
>> +					w_value--;
>> +					continue;
>> +				}
>> +
>> +				list_for_each_entry(f,
>> &c->functions, list) { +
>> +					/* DFU function only */
>> +					if (strcmp(f->name,
>> "dfu") != 0)
>> +						continue;
>> +
>> +					value = f->setup(f, ctrl);
>> +					goto dfu_func_done;
>> +				}
>> +			}
>> +dfu_func_done:
>> +			if (value >= 0)
>> +				value = min(w_length, (u16) value);
>> +			break;
>> +#endif
>> +
>> 		default:
>> 			goto unknown;
>> 		}
>> diff --git a/drivers/usb/gadget/ep0.c b/drivers/usb/gadget/ep0.c
>> index aa8f916..971d846 100644
>> --- a/drivers/usb/gadget/ep0.c
>> +++ b/drivers/usb/gadget/ep0.c
>> @@ -221,6 +221,7 @@ static int ep0_get_descriptor (struct
>> usb_device_instance *device, break;
>> 
>> 	case USB_DESCRIPTOR_TYPE_CONFIGURATION:
>> +	case USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION:
> 				^^^^^^^^^^^^^- why do you need that?
>> 		{
>> 			struct usb_configuration_descriptor
>> 				*configuration_descriptor;
>> diff --git a/drivers/usb/gadget/f_dfu.c b/drivers/usb/gadget/f_dfu.c
>> index 10547e3..6494f5e 100644
>> --- a/drivers/usb/gadget/f_dfu.c
>> +++ b/drivers/usb/gadget/f_dfu.c
>> @@ -534,8 +534,10 @@ dfu_handle(struct usb_function *f, const struct
>> usb_ctrlrequest *ctrl) value = min(len, (u16) sizeof(dfu_func));
>> 			memcpy(req->buf, &dfu_func, value);
>> 		}
>> -	} else /* DFU specific request */
>> -		value = dfu_state[f_dfu->dfu_state] (f_dfu, ctrl,
>> gadget, req);
>> +		return value;
>> +	}
>> +
>> +	value = dfu_state[f_dfu->dfu_state] (f_dfu, ctrl, gadget,
>> req); 
> 
> Why do you change state even after receiving req_type ==
> USB_TYPE_STANDARD? I would expect to change the dfu state only when DFU
> specific request appears.
> 
> 

> 
>> 	if (value >= 0) {
>> 		req->length = value;
> 
> 
> 
> -- 
> Best regards,
> 
> Lukasz Majewski
> 
> Samsung Poland R&D Center | Linux Platform Group

Regards

-- Pantelis

  reply	other threads:[~2012-12-10 18:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-30 18:01 [U-Boot] [PATCH v3 0/9] USB: Gadget & DFU related fixes Pantelis Antoniou
2012-11-30 18:01 ` [U-Boot] [PATCH v3 1/9] usb: Fix bug when both DFU & ETHER are defined Pantelis Antoniou
2012-12-01  5:30   ` Marek Vasut
2012-12-03 10:10     ` Pantelis Antoniou
2012-11-30 18:01 ` [U-Boot] [PATCH v3 2/9] g_dnl: Issue connect/disconnect as appropriate Pantelis Antoniou
2012-11-30 18:01 ` [U-Boot] [PATCH v3 3/9] g_dnl: Properly terminate string list Pantelis Antoniou
2012-11-30 18:01 ` [U-Boot] [PATCH v3 4/9] dfu: Only perform DFU board_usb_init() for TRATS Pantelis Antoniou
2012-12-01  5:31   ` Marek Vasut
2012-11-30 18:01 ` [U-Boot] [PATCH v3 5/9] dfu: Fix crash when wrong number of arguments given Pantelis Antoniou
2012-11-30 18:01 ` [U-Boot] [PATCH v3 6/9] dfu: Send correct DFU response from composite_setup Pantelis Antoniou
2012-12-10 17:11   ` Lukasz Majewski
2012-12-10 18:21     ` Pantelis Antoniou [this message]
2012-12-10 19:26       ` Lukasz Majewski
2012-12-11  0:47         ` Marek Vasut
2012-12-11  8:40           ` Lukasz Majewski
2012-12-11 10:47           ` Wolfgang Denk
2012-12-11 13:44           ` Tom Rini
2012-12-12 17:55             ` Marek Vasut
2012-12-12 18:03               ` Tom Rini
2012-12-11 11:02         ` Lukasz Majewski
2012-12-11 11:23           ` Pantelis Antoniou
2012-12-11 11:28           ` Robert P. J. Day
2012-12-12 21:42             ` Marek Vasut
2012-12-12 21:40           ` Marek Vasut
2012-12-11 11:18         ` Lukasz Majewski
2012-11-30 18:01 ` [U-Boot] [PATCH v3 7/9] dfu: Properly zero out timeout value Pantelis Antoniou
2012-11-30 18:01 ` [U-Boot] [PATCH v3 8/9] dfu: Add a partition type target Pantelis Antoniou
2012-11-30 18:01 ` [U-Boot] [PATCH v3 9/9] dfu: Support larger than memory transfers Pantelis Antoniou
2013-02-12 20:51   ` Tom Rini
2013-02-18 10:01     ` Lukasz Majewski
2013-02-18 12:38       ` Marek Vasut
2013-02-18 13:51       ` Tom Rini
2013-02-18 21:08       ` Tom Rini
2013-02-20  7:17         ` Lukasz Majewski
2012-12-01  5:32 ` [U-Boot] [PATCH v3 0/9] USB: Gadget & DFU related fixes Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5BA5AE75-F714-47D8-938F-AF2E8CE0D6B4@antoniou-consulting.com \
    --to=panto@antoniou-consulting.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.