diff options
-rw-r--r-- | configure.ac | 11 | ||||
-rw-r--r-- | src/helper/replacements.c | 42 | ||||
-rw-r--r-- | src/helper/replacements.h | 4 | ||||
-rw-r--r-- | src/jtag/drivers/libusb1_common.c | 5 | ||||
-rw-r--r-- | src/jtag/drivers/mpsse.c | 3 |
5 files changed, 60 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index 4388573..2d50bee 100644 --- a/configure.ac +++ b/configure.ac @@ -1200,9 +1200,14 @@ use_libusb0=no use_libusb1=no if test $build_usb = yes -o $build_usb_ng = yes; then if test $check_libusb0 = no -a $build_usb_ng = yes; then - AC_CHECK_HEADER([libusb-1.0/libusb.h], - [AC_DEFINE(HAVE_LIBUSB1, 1, [Define if you have libusb-1.0]) check_libusb0=no use_libusb1=yes ], - [ check_libusb0=yes use_libusb1=no ]) + AC_CHECK_HEADER([libusb-1.0/libusb.h], [ + AC_DEFINE(HAVE_LIBUSB1, 1, [Define if you have libusb-1.0]) + check_libusb0=no use_libusb1=yes + AC_SEARCH_LIBS([libusb_error_name], [usb-1.0], + [AC_DEFINE(HAVE_LIBUSB_ERROR_NAME, 1, [Define if your libusb has libusb_error_name()])], + [AC_MSG_WARN([libusb-1 older than 1.0.9 detected, consider updating])]) + ], [ + check_libusb0=yes use_libusb1=no ]) fi if test $check_libusb0 = yes -o $build_usb = yes; then diff --git a/src/helper/replacements.c b/src/helper/replacements.c index 2ae87e5..d8d8fd0 100644 --- a/src/helper/replacements.c +++ b/src/helper/replacements.c @@ -276,3 +276,45 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time return retcode; } #endif + +#if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME +#include <libusb-1.0/libusb.h> +/* Verbatim from git://git.libusb.org/libusb.git tag 1.0.9 + * The libusb_error enum is compatible down to v0.9.1 + */ +const char *libusb_error_name(int error_code) +{ + enum libusb_error error = error_code; + switch (error) { + case LIBUSB_SUCCESS: + return "LIBUSB_SUCCESS"; + case LIBUSB_ERROR_IO: + return "LIBUSB_ERROR_IO"; + case LIBUSB_ERROR_INVALID_PARAM: + return "LIBUSB_ERROR_INVALID_PARAM"; + case LIBUSB_ERROR_ACCESS: + return "LIBUSB_ERROR_ACCESS"; + case LIBUSB_ERROR_NO_DEVICE: + return "LIBUSB_ERROR_NO_DEVICE"; + case LIBUSB_ERROR_NOT_FOUND: + return "LIBUSB_ERROR_NOT_FOUND"; + case LIBUSB_ERROR_BUSY: + return "LIBUSB_ERROR_BUSY"; + case LIBUSB_ERROR_TIMEOUT: + return "LIBUSB_ERROR_TIMEOUT"; + case LIBUSB_ERROR_OVERFLOW: + return "LIBUSB_ERROR_OVERFLOW"; + case LIBUSB_ERROR_PIPE: + return "LIBUSB_ERROR_PIPE"; + case LIBUSB_ERROR_INTERRUPTED: + return "LIBUSB_ERROR_INTERRUPTED"; + case LIBUSB_ERROR_NO_MEM: + return "LIBUSB_ERROR_NO_MEM"; + case LIBUSB_ERROR_NOT_SUPPORTED: + return "LIBUSB_ERROR_NOT_SUPPORTED"; + case LIBUSB_ERROR_OTHER: + return "LIBUSB_ERROR_OTHER"; + } + return "**UNKNOWN**"; +} +#endif diff --git a/src/helper/replacements.h b/src/helper/replacements.h index 0fe93b2..565fe9d 100644 --- a/src/helper/replacements.h +++ b/src/helper/replacements.h @@ -279,4 +279,8 @@ typedef struct { #endif /* HAVE_ELF_H */ +#if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME +const char *libusb_error_name(int error_code); +#endif /* defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME */ + #endif /* REPLACEMENTS_H */ diff --git a/src/jtag/drivers/libusb1_common.c b/src/jtag/drivers/libusb1_common.c index 74b8144..c4478cb 100644 --- a/src/jtag/drivers/libusb1_common.c +++ b/src/jtag/drivers/libusb1_common.c @@ -62,8 +62,11 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], /** Free the device list **/ libusb_free_device_list(devs, 1); - if (errCode < 0) + if (errCode) { + LOG_ERROR("libusb_open() failed with %s", + libusb_error_name(errCode)); return errCode; + } return 0; } return -ENODEV; diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c index 13f61d7..82703bf 100644 --- a/src/jtag/drivers/mpsse.c +++ b/src/jtag/drivers/mpsse.c @@ -135,7 +135,8 @@ static bool open_matching_device(struct mpsse_ctx *ctx, const uint16_t *vid, con err = libusb_open(device, &ctx->usb_dev); if (err != LIBUSB_SUCCESS) { - LOG_ERROR("libusb_open() failed with %d", err); + LOG_ERROR("libusb_open() failed with %s", + libusb_error_name(err)); continue; } |