diff options
author | Oleksij Rempel <o.rempel@pengutronix.de> | 2019-02-12 13:51:54 +0100 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2021-03-19 22:01:23 +0000 |
commit | 08c7b904c38b97f9de72a19196b295652f051268 (patch) | |
tree | 46a79e8c76c3644b343f4d7503d5c0d217561825 /src/jtag | |
parent | eca4f964b47d317a0eb4b148f11588cec0e3bf60 (diff) | |
download | riscv-openocd-08c7b904c38b97f9de72a19196b295652f051268.zip riscv-openocd-08c7b904c38b97f9de72a19196b295652f051268.tar.gz riscv-openocd-08c7b904c38b97f9de72a19196b295652f051268.tar.bz2 |
drivers: USB Blaster II: claim interface before using it
If not, multiple instances of OOCD can concurrently use it.
Change-Id: I48cc9d90521d1dcc7720c6e8bec74f45972d16f7
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4589
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Diffstat (limited to 'src/jtag')
-rw-r--r-- | src/jtag/drivers/usb_blaster/ublast2_access_libusb.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c index 6f15fa7..82dc950 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; }; |