diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 535f803d..c1db33b8 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,9 @@ +2008-09-04 Arnim Laeuger + + * configure.ac, src/tap/usbconn/libftd2xx.c, + src/tap/usbconn/libftdi.c: forward and use the desc= paramter + [ 2085244 ] Wrong device chosen by ftd2xx driver + 2008-09-03 Arnim Laeuger * src/tap/usbconn/libftd2xx.c, src/tap/usbconn/libftdi.c: diff --git a/jtag/configure.ac b/jtag/configure.ac index c4d028ce..d8ee3e39 100644 --- a/jtag/configure.ac +++ b/jtag/configure.ac @@ -209,7 +209,7 @@ AC_ARG_WITH([ftd2xx], FTD2XXLIB= AS_IF([test "x$with_ftd2xx" = xyes -o "x$with_ftd2xx" = xcheck], [ - AC_CHECK_LIB([ftd2xx], [FT_Open], [ + AC_CHECK_LIB([ftd2xx], [FT_OpenEx], [ HAVELIBFTD2XX=yes LIBS="-lftd2xx $LIBS" ],[ diff --git a/jtag/src/tap/usbconn/libftd2xx.c b/jtag/src/tap/usbconn/libftd2xx.c index 10c2cf8e..ba15a3f7 100644 --- a/jtag/src/tap/usbconn/libftd2xx.c +++ b/jtag/src/tap/usbconn/libftd2xx.c @@ -290,7 +290,7 @@ usbconn_ftd2xx_connect( const char **param, int paramc, usbconn_cable_t *templat p->fc = NULL; p->pid = template->pid; p->vid = template->vid; - p->serial = NULL; + p->serial = template->desc ? strdup( template->desc ) : NULL; c->params = p; c->driver = &usbconn_ftd2xx_driver; @@ -328,7 +328,23 @@ usbconn_ftd2xx_common_open( usbconn_t *conn ) fprintf( stderr, "Warning: couldn't add %4.4x:%4.4x", p->vid, p->pid ); #endif - if ((status = FT_Open( 0, &(p->fc) )) != FT_OK) + /* try various methods to open a FTDI device */ + if (p->serial) + { + /* serial number/description is specified */ + + /* first try to match against the serial string */ + status = FT_OpenEx( p->serial, FT_OPEN_BY_SERIAL_NUMBER, &(p->fc) ); + + if (status != FT_OK) + /* then try to match against the description string */ + status = FT_OpenEx( p->serial, FT_OPEN_BY_DESCRIPTION, &(p->fc) ); + } + else + /* give it a plain try */ + status = FT_Open( 0, &(p->fc) ); + + if (status != FT_OK) { printf( "Unable to open FTDI device.\n" ); /* mark ftd2xx layer as not initialized */ diff --git a/jtag/src/tap/usbconn/libftdi.c b/jtag/src/tap/usbconn/libftdi.c index b19ac729..64b1a2b5 100644 --- a/jtag/src/tap/usbconn/libftdi.c +++ b/jtag/src/tap/usbconn/libftdi.c @@ -262,7 +262,7 @@ usbconn_ftdi_connect( const char **param, int paramc, usbconn_cable_t *template p->fc = fc; p->pid = template->pid; p->vid = template->vid; - p->serial = NULL; + p->serial = template->desc ? strdup( template->desc ) : NULL; c->params = p; c->driver = &usbconn_ftdi_driver; @@ -293,8 +293,16 @@ usbconn_ftdi_common_open( usbconn_t *conn ) { ftdi_param_t *p = conn->params; struct ftdi_context *fc = p->fc; + int status; - if (ftdi_usb_open_desc( fc, p->vid, p->pid, NULL, p->serial ) < 0) + /* use command line string for desc= as serial number and try to + open a matching device */ + status = ftdi_usb_open_desc( fc, p->vid, p->pid, NULL, p->serial ); + if (status < 0) + /* try again with matching the string against the description */ + status = ftdi_usb_open_desc( fc, p->vid, p->pid, p->serial, NULL ); + + if (status < 0) { puts( ftdi_get_error_string( fc ) ); ftdi_deinit( fc );