diff --git a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c index 6f15fa70a..82dc95071 100644 --- a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c +++ b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c @@ -133,6 +133,11 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, return ERROR_FAIL; } + if (libusb_claim_interface(libusb_dev, 0)) { + LOG_ERROR("unable to claim interface"); + return ERROR_JTAG_INIT_FAILED; + } + ublast2_firmware_image.base_address = 0; ublast2_firmware_image.base_address_set = false; @@ -184,6 +189,13 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, image_close(&ublast2_firmware_image); + /* + * Release claimed interface. Most probably it is already disconnected + * and re-enumerated as new devices after firmware upload, so we do + * not need to care about errors. + */ + libusb_release_interface(libusb_dev, 0); + return ERROR_OK; } @@ -228,6 +240,12 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low) } } + if (libusb_claim_interface(low->libusb_dev, 0)) { + LOG_ERROR("unable to claim interface"); + jtag_libusb_close(low->libusb_dev); + return ERROR_JTAG_INIT_FAILED; + } + char buffer[5]; jtag_libusb_control_transfer(low->libusb_dev, LIBUSB_REQUEST_TYPE_VENDOR | @@ -246,6 +264,9 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low) static int ublast2_libusb_quit(struct ublast_lowlevel *low) { + if (libusb_release_interface(low->libusb_dev, 0)) + LOG_ERROR("usb release interface failed"); + jtag_libusb_close(low->libusb_dev); return ERROR_OK; };