From 5bb0f6befb3c3f06903cee93f14bdd917abf21e7 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 28 Oct 2020 00:51:30 +0100 Subject: [PATCH] openocd: add support for libftdi 1.5 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 Fixes: https://sourceforge.net/p/openocd/tickets/286/ Reviewed-on: http://openocd.zylin.com/5891 Tested-by: jenkins --- configure.ac | 6 +++++- src/jtag/drivers/Makefile.am | 1 + src/jtag/drivers/libftdi_helper.h | 27 +++++++++++++++++++++++++++ src/jtag/drivers/openjtag.c | 6 +++--- src/jtag/drivers/presto.c | 8 ++++---- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 src/jtag/drivers/libftdi_helper.h diff --git a/configure.ac b/configure.ac index 47a167e28..055833a7f 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) ]) diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am index e8d20ccf8..1a5ab4a2d 100644 --- a/src/jtag/drivers/Makefile.am +++ b/src/jtag/drivers/Makefile.am @@ -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 index 000000000..e187b5727 --- /dev/null +++ b/src/jtag/drivers/libftdi_helper.h @@ -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 + +#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 */ diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c index 2cf5751d6..6940c8870 100644 --- a/src/jtag/drivers/openjtag.c +++ b/src/jtag/drivers/openjtag.c @@ -82,7 +82,7 @@ typedef enum openjtag_tap_state { } openjtag_tap_state_t; /* OPENJTAG access library includes */ -#include +#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; } diff --git a/src/jtag/drivers/presto.c b/src/jtag/drivers/presto.c index 6c3a187db..43d669e3e 100644 --- a/src/jtag/drivers/presto.c +++ b/src/jtag/drivers/presto.c @@ -34,7 +34,7 @@ #include "bitq.h" /* PRESTO access library includes */ -#include +#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;