[PATCH dfu-util] main: Retrieve run-time and DFU mode functional descriptor

Stefan Schmidt stefan at datenfreihafen.org
Sat Sep 24 12:50:10 CEST 2011


I picked up your idea of keeping lsusb logs of the device in the git
repo. A first patch that adds logs for all devices plus a short readme
that describes what I know about the DFU device side implementations
on this devices just hit the repo.

Would be great to add logs for your devices once you find time for
doing it. Actually anybody who uses dfu-util successfully with some
devices that are not listed should take the moment and prepare a log
for us. Just send them here.

On Wed, 2011-09-21 at 22:42, Tormod Volden wrote:
> From: Tormod Volden <debian.tormod at gmail.com>
> Previously we only retrieved the DFU mode descriptor and only if the
> user had not specified the transfer size option.
> We will try to get the run-time mode descriptor as cached by libusb,
> without asking the device (which would upset e.g. the Freerunner).
> This way we can determine e.g. the DFU version before dealing more
> with the device.
> After device transition to DFU mode we will retrieve the DFU mode
> descriptor, first by trying to get it cached from libusb, and if that
> fails, by asking the device. If that also fails, we'll guess wisely.
> ---
> OK, so forget the previous small patches. Here is the big fat one
> that should be idiot-device-proof :)


> This should work without disturbing the Freerunner, and it should fall
> back to reasonable defaults on devices such as the TAS1020B chip which do
> not have any DFU functional descriptor at all.

It works fine on the Freerunner and all other devices I have here.
Great work! The mising functional descriptor is also the case for the
Qi Hardware ATUSB device I have here. And the wrong handling of 1.1
features and DFU version number seems to have spread into all OSS
implemtations. Smeels like a crusade to get it fixed in all
implementations out there. :)

> The way git has structured the patch context it is not so easy to see 
> what I have done, so looking at the whole code might be easier. I have
> made some functions that are general USB helpers:
> 1 factored out a find_descriptor() to search through a descriptor list
> 2 get_cached_extra_descriptor() searches for an extra descriptor
> 3 get_any_descriptor() queries a device for any kind of descriptor
> So we use (2) while in run-time mode, and (2) || (3) in DFU mode.

I switched a bit back and forth between the patch and the whole code.
It all looked good to me and the testing for all devices worked
without problem. Just a small nitpick below.

> +
> +	ret = libusb_get_active_config_descriptor(dfu_if->dev, &cfg);
> +	if (ret == LIBUSB_ERROR_NOT_FOUND) {
> +		fprintf(stderr, "Error: Device is unconfigured\n");
> +		return -1;
> +	} else if (ret) {
> +		fprintf(stderr, "Error: failed "
> +			"libusb_get_config_descriptor_by_value()\n");

Here should go the correct function we fail on. :) I fixed that up for
you after I merged the patch.

Stefan Schmidt

More information about the devel mailing list