libusb1_common, ftdi: clarify libusb_open error message 30/1430/6
authorPaul Fertser <fercerpav@gmail.com>
Fri, 31 May 2013 10:57:56 +0000 (14:57 +0400)
committerSpencer Oliver <spen@spen-soft.co.uk>
Wed, 12 Jun 2013 14:40:16 +0000 (14:40 +0000)
Print a user-friendly message when libusb_open() fails, e.g.
Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
when there's a permissions problem.

Also output a configure warning if libusb older than 1.0.9 is detected.

Change-Id: I800f71f06672fe06c0a98a4e469f853b5021bcfe
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/1430
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
configure.ac
src/helper/replacements.c
src/helper/replacements.h
src/jtag/drivers/libusb1_common.c
src/jtag/drivers/mpsse.c

index 4388573c012a87bafd107efb26acaa820cdf6c29..2d50bee495fa375a726f3dd562c96a9b42fca60f 100644 (file)
@@ -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
index 2ae87e553355901d6e6ac8d461f96bcb32885a62..d8d8fd0bf663fb972d4ff8f891a92286815cb348 100644 (file)
@@ -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
index 0fe93b26d30dbf5e08d1ca83ea1d56a3ef30988d..565fe9dca83600bb68dc9489ace7b814a5d7eaf8 100644 (file)
@@ -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 */
index 74b8144d2a2d022e76b8939109b4eb1b872519b3..c4478cb9b1ac99b863b91df87b2e9d017699a73c 100644 (file)
@@ -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;
index 13f61d751d5f8413d93c3337cb4227959bed3ccb..82703bf341c73d53889f554bd6affea1abcd6668 100644 (file)
@@ -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;
                }
 

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)