openocd: add support for libftdi 1.5 91/5891/3
authorAntonio Borneo <borneo.antonio@gmail.com>
Tue, 27 Oct 2020 23:51:30 +0000 (00:51 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Wed, 4 Nov 2020 17:38:45 +0000 (17:38 +0000)
The new libftdi 1.5 (2020-07-07) changes some API, deprecating the
old ones. This cause a warning at compile time.

Detect in configure the version of libftdi.
Use the new API in the driver's code.
Add an helper include file 'libftdi_helper.h' that wraps the old
API for backward compatibility with old libftdi.

Change-Id: I7800fbebe17dd0ce62e55b3598d8c08be8875bb7
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: https://sourceforge.net/p/openocd/tickets/286/
Reviewed-on: http://openocd.zylin.com/5891
Tested-by: jenkins
configure.ac
src/jtag/drivers/Makefile.am
src/jtag/drivers/libftdi_helper.h [new file with mode: 0644]
src/jtag/drivers/openjtag.c
src/jtag/drivers/presto.c

index 47a167e282e44baba8d78e21daa1c7acaba2b345..055833a7fb5aa30d1f5d890aff1bcf065685a1f8 100644 (file)
@@ -669,7 +669,11 @@ for hidapi_lib in hidapi hidapi-hidraw hidapi-libusb; do
        ])
 done
 
-PKG_CHECK_MODULES([LIBFTDI], [libftdi1], [use_libftdi=yes], [
+PKG_CHECK_MODULES([LIBFTDI], [libftdi1], [
+       use_libftdi=yes
+       PKG_CHECK_EXISTS([libftdi1 >= 1.5],
+               [AC_DEFINE([HAVE_LIBFTDI_TCIOFLUSH], [1], [Define if your libftdi has ftdi_tcioflush()])])
+  ], [
        PKG_CHECK_MODULES([LIBFTDI], [libftdi], [use_libftdi=yes], [use_libftdi=no])
 ])
 
index e8d20ccf8914db4718a232be15937a5c2bdebf79..1a5ab4a2d92ae5bf97adf05dbfc828663bb0d01b 100644 (file)
@@ -187,6 +187,7 @@ DRIVERHEADERS = \
        %D%/bitbang.h \
        %D%/bitq.h \
        %D%/jtag_usb_common.h \
+       %D%/libftdi_helper.h \
        %D%/libusb_helper.h \
        %D%/minidriver_imp.h \
        %D%/mpsse.h \
diff --git a/src/jtag/drivers/libftdi_helper.h b/src/jtag/drivers/libftdi_helper.h
new file mode 100644 (file)
index 0000000..e187b57
--- /dev/null
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef OPENOCD_JTAG_DRIVERS_LIBFTDI_HELPER_H
+#define OPENOCD_JTAG_DRIVERS_LIBFTDI_HELPER_H
+
+#include <ftdi.h>
+
+#ifndef HAVE_LIBFTDI_TCIOFLUSH
+/* Backward compatibility with libftdi pre 1.5 */
+
+static inline int ftdi_tciflush(struct ftdi_context *ftdi)
+{
+       return ftdi_usb_purge_rx_buffer(ftdi);
+}
+
+static inline int ftdi_tcoflush(struct ftdi_context *ftdi)
+{
+       return ftdi_usb_purge_tx_buffer(ftdi);
+}
+
+static inline int ftdi_tcioflush(struct ftdi_context *ftdi)
+{
+       return ftdi_usb_purge_buffers(ftdi);
+}
+#endif
+
+#endif /* OPENOCD_JTAG_DRIVERS_LIBFTDI_HELPER_H */
index 2cf5751d6b515debcf97b57339254387f3f5d3fe..6940c8870619a8f09352a4ad8d814a4b20c7c133 100644 (file)
@@ -82,7 +82,7 @@ typedef enum openjtag_tap_state {
 } openjtag_tap_state_t;
 
 /* OPENJTAG access library includes */
-#include <ftdi.h>
+#include "libftdi_helper.h"
 
 /* OpenJTAG vid/pid */
 static uint16_t openjtag_vid = 0x0403;
@@ -436,8 +436,8 @@ static int openjtag_init_standard(void)
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
-       if (ftdi_usb_purge_buffers(&ftdic) < 0) {
-               LOG_ERROR("ftdi_purge_buffers: %s", ftdic.error_str);
+       if (ftdi_tcioflush(&ftdic) < 0) {
+               LOG_ERROR("ftdi flush: %s", ftdic.error_str);
                return ERROR_JTAG_INIT_FAILED;
        }
 
index 6c3a187dbcbc70cbadf959f8775ec7737d1c9ee0..43d669e3ee5b7960dcd796ecd80c64e776c54180 100644 (file)
@@ -34,7 +34,7 @@
 #include "bitq.h"
 
 /* PRESTO access library includes */
-#include <ftdi.h>
+#include "libftdi_helper.h"
 
 /* -------------------------------------------------------------------------- */
 
@@ -160,8 +160,8 @@ static int presto_open_libftdi(char *req_serial)
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
-       if (ftdi_usb_purge_buffers(&presto->ftdic) < 0) {
-               LOG_ERROR("unable to purge PRESTO buffers");
+       if (ftdi_tcioflush(&presto->ftdic) < 0) {
+               LOG_ERROR("unable to flush PRESTO buffers");
                return ERROR_JTAG_DEVICE_ERROR;
        }
 
@@ -174,7 +174,7 @@ static int presto_open_libftdi(char *req_serial)
        if (presto_read(&presto_data, 1) != ERROR_OK) {
                LOG_DEBUG("no response from PRESTO, retrying");
 
-               if (ftdi_usb_purge_buffers(&presto->ftdic) < 0)
+               if (ftdi_tcioflush(&presto->ftdic) < 0)
                        return ERROR_JTAG_DEVICE_ERROR;
 
                presto_data = 0xD0;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)