This is an automated email from Gerrit. "Antonio Borneo <borneo.anto...@gmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7467
-- gerrit commit e89afee044c43b2a3de09f91a6c86261341b9354 Author: Antonio Borneo <borneo.anto...@gmail.com> Date: Sat Jan 28 22:28:51 2023 +0100 jtag: drivers: fix for libusb API change During the development phase for next libusb v1.0.27, some API of libusb has changed, marking as deprecated the obsoleted API. Due to such libusb change, OpenOCD build fails with a warning on the deprecated API. Use the new API in the code, detect the API change through the macro LIBUSB_API_VERSION and provide a safe fallback for old libusb versions. Change-Id: Ib2482a671cc98cddec8eff7f1cb2720d93fa0910 Signed-off-by: Antonio Borneo <borneo.anto...@gmail.com> Reported-by: Xiaofan Chen <xiaof...@gmail.com> Fixes: https://github.com/libusb/libusb/issues/1236 diff --git a/src/jtag/drivers/cmsis_dap_usb_bulk.c b/src/jtag/drivers/cmsis_dap_usb_bulk.c index 6599c414ce..b9f164deae 100644 --- a/src/jtag/drivers/cmsis_dap_usb_bulk.c +++ b/src/jtag/drivers/cmsis_dap_usb_bulk.c @@ -31,6 +31,10 @@ #include "cmsis_dap.h" +#if LIBUSB_API_VERSION < 0x0100010A +#define libusb_init_context(a, b, c) libusb_init(a) +#endif + struct cmsis_dap_backend_data { struct libusb_context *usb_ctx; struct libusb_device_handle *dev_handle; @@ -50,7 +54,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p struct libusb_context *ctx; struct libusb_device **device_list; - err = libusb_init(&ctx); + err = libusb_init_context(&ctx, NULL, 0); if (err) { LOG_ERROR("libusb initialization failed: %s", libusb_strerror(err)); return ERROR_FAIL; diff --git a/src/jtag/drivers/libusb_helper.c b/src/jtag/drivers/libusb_helper.c index 53dfd502d3..33497a4b9c 100644 --- a/src/jtag/drivers/libusb_helper.c +++ b/src/jtag/drivers/libusb_helper.c @@ -16,6 +16,10 @@ #include <jtag/adapter.h> #include "libusb_helper.h" +#if LIBUSB_API_VERSION < 0x0100010A +#define libusb_init_context(a, b, c) libusb_init(a) +#endif + /* * comment from libusb: * As per the USB 3.0 specs, the current maximum limit for the depth is 7. @@ -155,7 +159,7 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], struct libusb_device_handle *libusb_handle = NULL; const char *serial = adapter_get_required_serial(); - if (libusb_init(&jtag_libusb_context) < 0) + if (libusb_init_context(&jtag_libusb_context, NULL, 0) < 0) return ERROR_FAIL; cnt = libusb_get_device_list(jtag_libusb_context, &devs); diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c index 18aeb38a48..a11bf19b98 100644 --- a/src/jtag/drivers/mpsse.c +++ b/src/jtag/drivers/mpsse.c @@ -20,6 +20,10 @@ #define LIBUSB_CALL #endif +#if LIBUSB_API_VERSION < 0x0100010A +#define libusb_init_context(a, b, c) libusb_init(a) +#endif + #define DEBUG_PRINT_BUF(buf, len) \ do { \ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) { \ @@ -337,9 +341,9 @@ struct mpsse_ctx *mpsse_open(const uint16_t *vid, const uint16_t *pid, const cha ctx->usb_read_timeout = 5000; ctx->usb_write_timeout = 5000; - err = libusb_init(&ctx->usb_ctx); + err = libusb_init_context(&ctx->usb_ctx, NULL, 0); if (err != LIBUSB_SUCCESS) { - LOG_ERROR("libusb_init() failed with %s", libusb_error_name(err)); + LOG_ERROR("libusb_init_context() failed with %s", libusb_error_name(err)); goto error; } diff --git a/src/jtag/drivers/ulink.c b/src/jtag/drivers/ulink.c index fd29f126e2..f7cd76e72c 100644 --- a/src/jtag/drivers/ulink.c +++ b/src/jtag/drivers/ulink.c @@ -18,6 +18,10 @@ #include "libusb_helper.h" #include "OpenULINK/include/msgtypes.h" +#if LIBUSB_API_VERSION < 0x0100010A +#define libusb_init_context(a, b, c) libusb_init(a) +#endif + /** USB Vendor ID of ULINK device in unconfigured state (no firmware loaded * yet) or with OpenULINK firmware. */ #define ULINK_VID 0xC251 @@ -2109,7 +2113,7 @@ static int ulink_init(void) if (!ulink_handle) return ERROR_FAIL; - libusb_init(&ulink_handle->libusb_ctx); + libusb_init_context(&ulink_handle->libusb_ctx, NULL, 0); ret = ulink_usb_open(&ulink_handle); if (ret != ERROR_OK) { diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index 255ff88a2f..6e0198216f 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -22,6 +22,10 @@ #include "versaloon/versaloon_include.h" #include "versaloon/versaloon.h" +#if LIBUSB_API_VERSION < 0x0100010A +#define libusb_init_context(a, b, c) libusb_init(a) +#endif + static int vsllink_tms_offset; struct pending_scan_result { @@ -276,7 +280,7 @@ static int vsllink_interface_init(void) return ERROR_FAIL; } - libusb_init(&vsllink_handle->libusb_ctx); + libusb_init_context(&vsllink_handle->libusb_ctx, NULL, 0); if (vsllink_usb_open(vsllink_handle) != ERROR_OK) { LOG_ERROR("Can't find USB JTAG Interface!" diff --git a/src/jtag/drivers/xds110.c b/src/jtag/drivers/xds110.c index 8e5d638db1..6a0da7243d 100644 --- a/src/jtag/drivers/xds110.c +++ b/src/jtag/drivers/xds110.c @@ -16,6 +16,10 @@ #include <jtag/tcl.h> #include <libusb.h> +#if LIBUSB_API_VERSION < 0x0100010A +#define libusb_init_context(a, b, c) libusb_init(a) +#endif + /* XDS110 stand-alone probe voltage supply limits */ #define XDS110_MIN_VOLTAGE 1800 #define XDS110_MAX_VOLTAGE 3600 @@ -323,7 +327,7 @@ static bool usb_connect(void) bool match = false; /* Initialize libusb context */ - result = libusb_init(&ctx); + result = libusb_init_context(&ctx, NULL, 0); if (result == 0) { /* Get list of USB devices attached to system */ --