mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* dfu: Does is work for anybody with dfu-util 0.9?
@ 2019-01-11 10:22 Ladislav Michl
  2019-01-11 11:02 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ladislav Michl @ 2019-01-11 10:22 UTC (permalink / raw)
  To: barebox

Hi,

I'm using DFU to download firmware to AT91 based device. Registered
configurations are:
dfu: register alt0(bootstrap) with device /dev/dataflash0.at91bootstrap
dfu: register alt1(bootloader) with device /dev/dataflash0.barebox
dfu: register alt2(system) with device /dev/nand0.bb
So with the bit of luck even bootstrap is upgradable using DFU, however
dfu-util refuses doing anything, bailing out here on dfu_root->next
not being NULL:

	if (dfu_root == NULL) {
		errx(EX_IOERR, "No DFU capable USB device available");
	} else if (dfu_root->next != NULL) {
		/* We cannot safely support more than one DFU capable device
		 * with same vendor/product ID, since during DFU we need to do
		 * a USB bus reset, after which the target device will get a
		 * new address */
		errx(EX_IOERR, "More than one DFU capable USB device found! "
		       "Try `--list' and specify the serial number "
		       "or disconnect all but one device\n");
	}

That comes from src/dfu_util.c:probe_configuration() which check for:

	dfu_mode = (intf->bInterfaceProtocol == 2);
	/* e.g. DSO Nano has bInterfaceProtocol 0 instead of 2 */
	if (func_dfu.bcdDFUVersion == 0x011a && intf->bInterfaceProtocol == 0)
		dfu_mode = 1;

	/* LPC DFU bootloader has bInterfaceProtocol 1 (Runtime) instead of 2 */
	if (desc->idVendor == 0x1fc9 && desc->idProduct == 0x000c && intf->bInterfaceProtocol == 1)
		dfu_mode = 1;

	/*
	 * Old Jabra devices may have bInterfaceProtocol 0 instead of 2.
	 * Also runtime PID and DFU pid are the same.
	 * In DFU mode, the configuration descriptor has only 1 interface.
	 */
	if (desc->idVendor == 0x0b0e && intf->bInterfaceProtocol == 0 && cfg->bNumInterfaces == 1)
		dfu_mode = 1;

and as Barebox sets bInterfaceProtocol to one and it is not listed in
exceptions individual devices are added for each alt settings.

As a quick hack I'd suggest patch bellow, but I'm not sure whenever it will
break someone's setup. DFU code would certainly welcome some
polishing/improvements, but time does not permit that on my side for
the time being :(

diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c
index c2b3d481a..aee86906a 100644
--- a/drivers/usb/gadget/dfu.c
+++ b/drivers/usb/gadget/dfu.c
@@ -233,7 +233,7 @@ dfu_bind(struct usb_configuration *c, struct usb_function *f)
 		desc[i].bNumEndpoints	=	0;
 		desc[i].bInterfaceClass =	0xfe;
 		desc[i].bInterfaceSubClass =	1;
-		desc[i].bInterfaceProtocol =	1;
+		desc[i].bInterfaceProtocol =	2;
 		desc[i].bAlternateSetting = i;
 		desc[i].iInterface = us[i + 1].id;
 		header[i] = (struct usb_descriptor_header *)&desc[i];
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: dfu: Does is work for anybody with dfu-util 0.9?
  2019-01-11 10:22 dfu: Does is work for anybody with dfu-util 0.9? Ladislav Michl
@ 2019-01-11 11:02 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-01-11 11:02 UTC (permalink / raw)
  To: Ladislav Michl; +Cc: barebox

On Fri, Jan 11, 2019 at 11:22:35AM +0100, Ladislav Michl wrote:
> Hi,
> 
> I'm using DFU to download firmware to AT91 based device. Registered
> configurations are:
> dfu: register alt0(bootstrap) with device /dev/dataflash0.at91bootstrap
> dfu: register alt1(bootloader) with device /dev/dataflash0.barebox
> dfu: register alt2(system) with device /dev/nand0.bb
> So with the bit of luck even bootstrap is upgradable using DFU, however
> dfu-util refuses doing anything, bailing out here on dfu_root->next
> not being NULL:
> 

dfu stopped working for me with the following dfu-utils commit. I never
came along fixing it, but a proper patch would surely be welcomed.

Sascha


------------------------------8<--------------------------------

From 377f6f136d3369529f44578acaeee82d7c7d7af9 Mon Sep 17 00:00:00 2001
From: Paul Fertser <fercerpav@gmail.com>
Date: Sun, 10 Aug 2014 14:26:05 +0400
Subject: [PATCH] dfu_util: Ignore alt_index/alt_name specification in runtime
 mode

When the device is in runtime mode it needs to be reset first into DFU
mode for the list of alternate settings to appear, so unless it is
already in the right mode, matching on alt setting number or name
should be skipped.

Fixes regression on OpenMoko Freerunner.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
---
 src/dfu_util.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/dfu_util.c b/src/dfu_util.c
index bb40e94..cc92c19 100644
--- a/src/dfu_util.c
+++ b/src/dfu_util.c
@@ -189,13 +189,17 @@ found_dfu:
 				int dfu_mode;
 
 				intf = &uif->altsetting[alt_idx];
-				if (match_iface_alt_index > -1 && match_iface_alt_index != alt_idx)
-					continue;
+
 				if (intf->bInterfaceClass != 0xfe ||
 				    intf->bInterfaceSubClass != 1)
 					continue;
 
 				dfu_mode = (intf->bInterfaceProtocol == 2);
+
+				if (dfu_mode &&
+				    match_iface_alt_index > -1 && match_iface_alt_index != alt_idx)
+					continue;
+
 				if (dfu_mode) {
 					if ((match_vendor_dfu >= 0 && match_vendor_dfu != desc->idVendor) ||
 					    (match_product_dfu >= 0 && match_product_dfu != desc->idProduct)) {
@@ -228,7 +232,8 @@ found_dfu:
 					strcpy(serial_name, "UNKNOWN");
 				libusb_close(devh);
 
-				if (match_iface_alt_name != NULL && strcmp(alt_name, match_iface_alt_name))
+				if (dfu_mode &&
+				    match_iface_alt_name != NULL && strcmp(alt_name, match_iface_alt_name))
 					continue;
 
 				if (dfu_mode) {
-- 
2.20.1


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-11 11:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 10:22 dfu: Does is work for anybody with dfu-util 0.9? Ladislav Michl
2019-01-11 11:02 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox