Hi,

I discovered this little correctness bug when messing with trying to work out why my flyswatter was unreliable.

in ft2232.c

ftdi_set_interface needs to be called to set the active interface BEFORE ftdi_usb_open_desc, because ftdi_usb_open_desc needs to know which interface to open.

There is no bug exhibited in openocd, because the interface defaults to Interface A. But the code as wrote is still incorrect, and if libftdi ever changes the default, then it will break. Also, this will cause problems if anyone makes a jtag device using Interface B of the new 2232H chip from FTDI.

Patch attached.

Note: I haven't tested this yet, because SVN Head is segfaulting for me. More on that later. Yet, I am confident that it will work OK.

Strontium


Index: src/jtag/ft2232.c
===================================================================
--- src/jtag/ft2232.c	(revision 1743)
+++ src/jtag/ft2232.c	(working copy)
@@ -1766,6 +1766,12 @@
 	if (ftdi_init(&ftdic) < 0)
 		return ERROR_JTAG_INIT_FAILED;
 
+	if (ftdi_set_interface(&ftdic, INTERFACE_A) < 0)
+	{
+		LOG_ERROR("unable to select FT2232 channel A: %s", ftdic.error_str);
+		return ERROR_JTAG_INIT_FAILED;
+	}
+
 	/* context, vendor id, product id */
 	if (ftdi_usb_open_desc(&ftdic, vid, pid, ft2232_device_desc,
 				ft2232_serial) < 0)
@@ -1779,12 +1785,6 @@
 		return ERROR_JTAG_INIT_FAILED;
 	}
 
-	if (ftdi_set_interface(&ftdic, INTERFACE_A) < 0)
-	{
-		LOG_ERROR("unable to select FT2232 channel A: %s", ftdic.error_str);
-		return ERROR_JTAG_INIT_FAILED;
-	}
-
 	if (ftdi_usb_reset(&ftdic) < 0)
 	{
 		LOG_ERROR("unable to reset ftdi device");
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to