All of lore.kernel.org
 help / color / mirror / Atom feed
* Flashing USB2CAN devices under Linux and change the serial number
       [not found] <0AD3D310E3BB3A45B6040EDF5C9897723F6A7188@VWAGWOXB0401.vw.vwg>
@ 2015-03-21  8:54 ` Oliver Hartkopp
  2015-05-23  8:06   ` Bernd Krumboeck
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Hartkopp @ 2015-03-21  8:54 UTC (permalink / raw)
  To: Bernd Krumboeck, linux-can; +Cc: Gediminas Simanskis

[-- Attachment #1: Type: text/plain, Size: 1720 bytes --]

Hello Bernd,

my colleague Eike wanted to change the USB2CAN serial numbers of his devices
to have a proper differentiation between them.

For that reason Gediminas provided on the 8device download section

	http://www.8devices.com/usb2can#downloads

This file:

http://www.8devices.com/media/files/usb2can_eeproms_dfu_ED000100-ED000226.zip
(EEPROM images for devices with serial numbers ED000100-ED000226)

The zip contains 37 dfu files named ED000xxx_1_0.dfu (xxx = different numbers)

As I was successful on my setup with flashing the firmware 1.5

	http://www.8devices.com/media/files/usb2can_flash_1_5.zip

Eike tried to flash the serial number dfu's in the same way which didn't work.

The adapter was stuck in the bootloader and he wasn't able to flash it.
It turned out that this was a timing issue on his specific hardware and
Gediminas suggested to *put an USB hub between the PC and the CAN adapter*
as some new high speed USB ports create problems with the timing.

That made it work!

So here are the command line options from Eike to flash the adapters.

Firmware: dfu-util –d 0483:df11 –a 0 –D usb2can_1_5.dfu
SerialNo: dfu-util –d 0483:df11 –a 1 –D E000xxx_1_0.dfu

Together with the two attached patches applied on the dfu-util 0.8 at

	http://sourceforge.net/p/dfu-util/dfu-util/ci/master/tree/

we now have a working solution to flash firmware and serial numbers with Linux.

Maybe you can update the README.md at

	https://github.com/krumboeck/usb2can_firmware

to add these infos.

(Especially link to the attachments in this post e.g. on
http://marc.info/?l=linux-can and change the URL to the dfu-util which has
moved from gitorious to sourceforge due to gitorious shutdown)

Best regards,
Oliver

[-- Attachment #2: 0001-dfu-util-remove-vendor-check.patch --]
[-- Type: text/x-patch, Size: 2371 bytes --]

From 84b3810c5af45185a7d09b771c2378c59fefa653 Mon Sep 17 00:00:00 2001
From: Oliver Hartkopp <socketcan@hartkopp.net>
Date: Fri, 30 Jan 2015 22:29:22 +0100
Subject: [PATCH 1/2] dfu-util: remove vendor check

To flash the 8devices.com USB2CAN adapter we need to remove the vendor check.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 src/main.c | 21 ---------------------
 1 file changed, 21 deletions(-)

diff --git a/src/main.c b/src/main.c
index acaed2f..67da6d9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -249,8 +249,6 @@ int main(int argc, char **argv)
 	int fd;
 	const char *dfuse_options = NULL;
 	int detach_delay = 5;
-	uint16_t runtime_vendor;
-	uint16_t runtime_product;
 
 	memset(&file, 0, sizeof(file));
 
@@ -417,8 +415,6 @@ int main(int argc, char **argv)
 
 		/* FIXME: check if the selected device really has only one */
 
-		runtime_vendor = dfu_root->vendor;
-		runtime_product = dfu_root->product;
 
 		printf("Claiming USB DFU Runtime Interface...\n");
 		if (libusb_claim_interface(dfu_root->dev_handle, dfu_root->interface) < 0) {
@@ -517,13 +513,6 @@ int main(int argc, char **argv)
 		if (ret || !dfu_root->dev_handle) {
 			errx(EX_IOERR, "Cannot open device");
 		}
-	} else {
-		/* we're already in DFU mode, so we can skip the detach/reset
-		 * procedure */
-		/* If a match vendor/product was specified, use that as the runtime
-		 * vendor/product, otherwise use the DFU mode vendor/product */
-		runtime_vendor = match_vendor < 0 ? dfu_root->vendor : match_vendor;
-		runtime_product = match_product < 0 ? dfu_root->product : match_product;
 	}
 
 dfustate:
@@ -649,16 +638,6 @@ status_again:
 		break;
 
 	case MODE_DOWNLOAD:
-		if (((file.idVendor  != 0xffff && file.idVendor  != runtime_vendor) ||
-		     (file.idProduct != 0xffff && file.idProduct != runtime_product)) &&
-		    ((file.idVendor  != 0xffff && file.idVendor  != dfu_root->vendor) ||
-		     (file.idProduct != 0xffff && file.idProduct != dfu_root->product))) {
-			errx(EX_IOERR, "Error: File ID %04x:%04x does "
-				"not match device (%04x:%04x or %04x:%04x)",
-				file.idVendor, file.idProduct,
-				runtime_vendor, runtime_product,
-				dfu_root->vendor, dfu_root->product);
-		}
 		if (dfuse_device || dfuse_options || file.bcdDFU == 0x11a) {
 		        if (dfuse_do_dnload(dfu_root, transfer_size, &file,
 							dfuse_options) < 0)
-- 
2.1.4


[-- Attachment #3: 0002-dfu-util-change-erase-process.patch --]
[-- Type: text/x-patch, Size: 2631 bytes --]

From 4d951839578f04b01ecea3185fad6a72b488ba18 Mon Sep 17 00:00:00 2001
From: Oliver Hartkopp <socketcan@hartkopp.net>
Date: Fri, 30 Jan 2015 22:32:14 +0100
Subject: [PATCH 2/2] dfu-util: change erase process

This patch is based on a hunk provided at
http://lists.gnumonks.org/pipermail/dfu-util/attachments/20140124/1abbc049/attachment.bin

I don't know what's the idea behind - but it is needed due to the documentation
to flash the USB2CAN adapter here:
https://github.com/krumboeck/usb2can_firmware

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
 src/dfuse.c | 35 +++++++++--------------------------
 1 file changed, 9 insertions(+), 26 deletions(-)

diff --git a/src/dfuse.c b/src/dfuse.c
index fce29fe..5741a71 100644
--- a/src/dfuse.c
+++ b/src/dfuse.c
@@ -387,11 +387,18 @@ int dfuse_dnload_element(struct dfu_if *dif, unsigned int dwElementAddress,
 			dwElementAddress + dwElementSize - 1);
 	}
 
+	for (p = 0; p < (int)dwElementSize;) {
+		unsigned int address = dwElementAddress + p;
+		segment = find_segment(mem_layout, address);
+		if ((segment->memtype & DFUSE_ERASABLE) && !dfuse_mass_erase) {
+			dfuse_special_command(dif, address, ERASE_PAGE);
+		}
+		p = p + segment->pagesize;
+	}
+
 	dfu_progress_bar("Download", 0, 1);
 
 	for (p = 0; p < (int)dwElementSize; p += xfer_size) {
-		int page_size;
-		unsigned int erase_address;
 		unsigned int address = dwElementAddress + p;
 		int chunk_size = xfer_size;
 
@@ -400,35 +407,11 @@ int dfuse_dnload_element(struct dfu_if *dif, unsigned int dwElementAddress,
 			errx(EX_IOERR, "Page at 0x%08x is not writeable",
 				address);
 		}
-		page_size = segment->pagesize;
 
 		/* check if this is the last chunk */
 		if (p + chunk_size > (int)dwElementSize)
 			chunk_size = dwElementSize - p;
 
-		/* Erase only for flash memory downloads */
-		if ((segment->memtype & DFUSE_ERASABLE) && !dfuse_mass_erase) {
-			/* erase all involved pages */
-			for (erase_address = address;
-			     erase_address < address + chunk_size;
-			     erase_address += page_size)
-				if ((erase_address & ~(page_size - 1)) !=
-				    last_erased_page)
-					dfuse_special_command(dif,
-							      erase_address,
-							      ERASE_PAGE);
-
-			if (((address + chunk_size - 1) & ~(page_size - 1)) !=
-			    last_erased_page) {
-				if (verbose > 2)
-					printf(" Chunk extends into next page,"
-					       " erase it as well\n");
-				dfuse_special_command(dif,
-						      address + chunk_size - 1,
-						      ERASE_PAGE);
-			}
-		}
-
 		if (verbose) {
 			printf(" Download from image offset "
 			       "%08x to memory %08x-%08x, size %i\n",
-- 
2.1.4


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

* Re: Flashing USB2CAN devices under Linux and change the serial number
  2015-03-21  8:54 ` Flashing USB2CAN devices under Linux and change the serial number Oliver Hartkopp
@ 2015-05-23  8:06   ` Bernd Krumboeck
  0 siblings, 0 replies; 2+ messages in thread
From: Bernd Krumboeck @ 2015-05-23  8:06 UTC (permalink / raw)
  To: Oliver Hartkopp, linux-can; +Cc: Gediminas Simanskis

Sorry for the long delay.

I've updated the README.md file.

regards,
Bernd


Am 2015-03-21 um 09:54 schrieb Oliver Hartkopp:
> Hello Bernd,
>
> my colleague Eike wanted to change the USB2CAN serial numbers of his devices
> to have a proper differentiation between them.
>
> For that reason Gediminas provided on the 8device download section
>
>      http://www.8devices.com/usb2can#downloads
>
> This file:
>
> http://www.8devices.com/media/files/usb2can_eeproms_dfu_ED000100-ED000226.zip
> (EEPROM images for devices with serial numbers ED000100-ED000226)
>
> The zip contains 37 dfu files named ED000xxx_1_0.dfu (xxx = different numbers)
>
> As I was successful on my setup with flashing the firmware 1.5
>
>      http://www.8devices.com/media/files/usb2can_flash_1_5.zip
>
> Eike tried to flash the serial number dfu's in the same way which didn't work.
>
> The adapter was stuck in the bootloader and he wasn't able to flash it.
> It turned out that this was a timing issue on his specific hardware and
> Gediminas suggested to *put an USB hub between the PC and the CAN adapter*
> as some new high speed USB ports create problems with the timing.
>
> That made it work!
>
> So here are the command line options from Eike to flash the adapters.
>
> Firmware: dfu-util –d 0483:df11 –a 0 –D usb2can_1_5.dfu
> SerialNo: dfu-util –d 0483:df11 –a 1 –D E000xxx_1_0.dfu
>
> Together with the two attached patches applied on the dfu-util 0.8 at
>
>      http://sourceforge.net/p/dfu-util/dfu-util/ci/master/tree/
>
> we now have a working solution to flash firmware and serial numbers with Linux.
>
> Maybe you can update the README.md at
>
>      https://github.com/krumboeck/usb2can_firmware
>
> to add these infos.
>
> (Especially link to the attachments in this post e.g. on
> http://marc.info/?l=linux-can and change the URL to the dfu-util which has
> moved from gitorious to sourceforge due to gitorious shutdown)
>
> Best regards,
> Oliver


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

end of thread, other threads:[~2015-05-23  8:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <0AD3D310E3BB3A45B6040EDF5C9897723F6A7188@VWAGWOXB0401.vw.vwg>
2015-03-21  8:54 ` Flashing USB2CAN devices under Linux and change the serial number Oliver Hartkopp
2015-05-23  8:06   ` Bernd Krumboeck

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.