jtag/drivers: Extension of jtag_libusb_open
In jtag_libusb_open I've added a parameter for delivering the device description for which this function should search and adjusted all callers of this function. A new driver for WCH CH347 JTAG chips will use this new parameter. See also: https://review.openocd.org/c/openocd/+/7937 Change-Id: I85e1d7b1f7912ba5e223f0f26323ff3b7600e17d Signed-off-by: EasyDevKits <info@easydevkits.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7938 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
parent
1d555d21d9
commit
a080d9795a
|
@ -257,7 +257,7 @@ static int angie_usb_open(struct angie *device)
|
|||
const uint16_t vids[] = {ANGIE_VID, ANGIE_VID, ANGIE_VID, ANGIE_VID, 0};
|
||||
const uint16_t pids[] = {ANGIE_PID, ANGIE_PID_2, ANGIE_PID_3, ANGIE_PID_4, 0};
|
||||
|
||||
int ret = jtag_libusb_open(vids, pids, &usb_device_handle, NULL);
|
||||
int ret = jtag_libusb_open(vids, pids, NULL, &usb_device_handle, NULL);
|
||||
|
||||
if (ret != ERROR_OK)
|
||||
return ret;
|
||||
|
|
|
@ -677,7 +677,7 @@ static struct armjtagew *armjtagew_usb_open(void)
|
|||
const uint16_t pids[] = { USB_PID, 0 };
|
||||
struct libusb_device_handle *dev;
|
||||
|
||||
if (jtag_libusb_open(vids, pids, &dev, NULL) != ERROR_OK)
|
||||
if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
|
||||
return NULL;
|
||||
|
||||
struct armjtagew *result = malloc(sizeof(struct armjtagew));
|
||||
|
|
|
@ -487,7 +487,7 @@ static int esp_usb_jtag_init(void)
|
|||
bitq_interface->in_rdy = esp_usb_jtag_in_rdy;
|
||||
bitq_interface->in = esp_usb_jtag_in;
|
||||
|
||||
int r = jtag_libusb_open(vids, pids, &priv->usb_device, NULL);
|
||||
int r = jtag_libusb_open(vids, pids, NULL, &priv->usb_device, NULL);
|
||||
if (r != ERROR_OK) {
|
||||
LOG_ERROR("esp_usb_jtag: could not find or open device!");
|
||||
goto out;
|
||||
|
|
|
@ -246,7 +246,7 @@ static int ft232r_init(void)
|
|||
{
|
||||
uint16_t avids[] = {ft232r_vid, 0};
|
||||
uint16_t apids[] = {ft232r_pid, 0};
|
||||
if (jtag_libusb_open(avids, apids, &adapter, NULL)) {
|
||||
if (jtag_libusb_open(avids, apids, NULL, &adapter, NULL)) {
|
||||
const char *ft232r_serial_desc = adapter_get_required_serial();
|
||||
LOG_ERROR("ft232r not found: vid=%04x, pid=%04x, serial=%s\n",
|
||||
ft232r_vid, ft232r_pid, (!ft232r_serial_desc) ? "[any]" : ft232r_serial_desc);
|
||||
|
|
|
@ -275,7 +275,7 @@ static int kitprog_usb_open(void)
|
|||
const uint16_t vids[] = { VID, 0 };
|
||||
const uint16_t pids[] = { PID, 0 };
|
||||
|
||||
if (jtag_libusb_open(vids, pids, &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
|
||||
if (jtag_libusb_open(vids, pids, NULL, &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
|
||||
LOG_ERROR("Failed to open or find the device");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
|
|
@ -146,12 +146,13 @@ static bool jtag_libusb_match_serial(struct libusb_device_handle *device,
|
|||
}
|
||||
|
||||
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
|
||||
struct libusb_device_handle **out,
|
||||
const char *product, struct libusb_device_handle **out,
|
||||
adapter_get_alternate_serial_fn adapter_get_alternate_serial)
|
||||
{
|
||||
int cnt, idx, err_code;
|
||||
int retval = ERROR_FAIL;
|
||||
bool serial_mismatch = false;
|
||||
bool product_mismatch = false;
|
||||
struct libusb_device_handle *libusb_handle = NULL;
|
||||
const char *serial = adapter_get_required_serial();
|
||||
|
||||
|
@ -188,10 +189,18 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
|
|||
continue;
|
||||
}
|
||||
|
||||
if (product &&
|
||||
!string_descriptor_equal(libusb_handle, dev_desc.iProduct, product)) {
|
||||
product_mismatch = true;
|
||||
libusb_close(libusb_handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Success. */
|
||||
*out = libusb_handle;
|
||||
retval = ERROR_OK;
|
||||
serial_mismatch = false;
|
||||
product_mismatch = false;
|
||||
break;
|
||||
}
|
||||
if (cnt >= 0)
|
||||
|
@ -200,6 +209,9 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
|
|||
if (serial_mismatch)
|
||||
LOG_INFO("No device matches the serial string");
|
||||
|
||||
if (product_mismatch)
|
||||
LOG_INFO("No device matches the product string");
|
||||
|
||||
if (retval != ERROR_OK)
|
||||
libusb_exit(jtag_libusb_context);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef char * (*adapter_get_alternate_serial_fn)(struct libusb_device_handle *d
|
|||
bool jtag_libusb_match_ids(struct libusb_device_descriptor *dev_desc,
|
||||
const uint16_t vids[], const uint16_t pids[]);
|
||||
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
|
||||
struct libusb_device_handle **out,
|
||||
const char *product, struct libusb_device_handle **out,
|
||||
adapter_get_alternate_serial_fn adapter_get_alternate_serial);
|
||||
void jtag_libusb_close(struct libusb_device_handle *dev);
|
||||
int jtag_libusb_control_transfer(struct libusb_device_handle *dev,
|
||||
|
|
|
@ -695,7 +695,7 @@ struct opendous_jtag *opendous_usb_open(void)
|
|||
struct opendous_jtag *result;
|
||||
|
||||
struct libusb_device_handle *devh;
|
||||
if (jtag_libusb_open(opendous_probe->VID, opendous_probe->PID, &devh, NULL) != ERROR_OK)
|
||||
if (jtag_libusb_open(opendous_probe->VID, opendous_probe->PID, NULL, &devh, NULL) != ERROR_OK)
|
||||
return NULL;
|
||||
|
||||
jtag_libusb_set_configuration(devh, 0);
|
||||
|
|
|
@ -438,7 +438,7 @@ static int openjtag_init_cy7c65215(void)
|
|||
int ret;
|
||||
|
||||
usbh = NULL;
|
||||
ret = jtag_libusb_open(cy7c65215_vids, cy7c65215_pids, &usbh, NULL);
|
||||
ret = jtag_libusb_open(cy7c65215_vids, cy7c65215_pids, NULL, &usbh, NULL);
|
||||
if (ret != ERROR_OK) {
|
||||
LOG_ERROR("unable to open cy7c65215 device");
|
||||
goto err;
|
||||
|
|
|
@ -363,7 +363,7 @@ static int osbdm_flush(struct osbdm *osbdm, struct queue *queue)
|
|||
static int osbdm_open(struct osbdm *osbdm)
|
||||
{
|
||||
(void)memset(osbdm, 0, sizeof(*osbdm));
|
||||
if (jtag_libusb_open(osbdm_vid, osbdm_pid, &osbdm->devh, NULL) != ERROR_OK)
|
||||
if (jtag_libusb_open(osbdm_vid, osbdm_pid, NULL, &osbdm->devh, NULL) != ERROR_OK)
|
||||
return ERROR_FAIL;
|
||||
|
||||
if (libusb_claim_interface(osbdm->devh, 0) != ERROR_OK)
|
||||
|
|
|
@ -1448,7 +1448,7 @@ static int rlink_init(void)
|
|||
|
||||
const uint16_t vids[] = { USB_IDVENDOR, 0 };
|
||||
const uint16_t pids[] = { USB_IDPRODUCT, 0 };
|
||||
if (jtag_libusb_open(vids, pids, &hdev, NULL) != ERROR_OK)
|
||||
if (jtag_libusb_open(vids, pids, NULL, &hdev, NULL) != ERROR_OK)
|
||||
return ERROR_FAIL;
|
||||
|
||||
struct libusb_device_descriptor descriptor;
|
||||
|
|
|
@ -3406,7 +3406,7 @@ static int stlink_usb_usb_open(void *handle, struct hl_interface_param_s *param)
|
|||
in order to become operational.
|
||||
*/
|
||||
do {
|
||||
if (jtag_libusb_open(param->vid, param->pid,
|
||||
if (jtag_libusb_open(param->vid, param->pid, NULL,
|
||||
&h->usb_backend_priv.fd, stlink_usb_get_alternate_serial) != ERROR_OK) {
|
||||
LOG_ERROR("open failed");
|
||||
return ERROR_FAIL;
|
||||
|
|
|
@ -675,7 +675,7 @@ static int icdi_usb_open(struct hl_interface_param_s *param, void **fd)
|
|||
|
||||
/* TI (Stellaris) ICDI provides its serial number in the USB descriptor;
|
||||
no need to provide a callback here. */
|
||||
jtag_libusb_open(param->vid, param->pid, &h->usb_dev, NULL);
|
||||
jtag_libusb_open(param->vid, param->pid, NULL, &h->usb_dev, NULL);
|
||||
|
||||
if (!h->usb_dev) {
|
||||
LOG_ERROR("open failed");
|
||||
|
|
|
@ -202,7 +202,7 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
|
|||
bool renumeration = false;
|
||||
int ret;
|
||||
|
||||
if (jtag_libusb_open(vids, pids, &temp, NULL) == ERROR_OK) {
|
||||
if (jtag_libusb_open(vids, pids, NULL, &temp, NULL) == ERROR_OK) {
|
||||
LOG_INFO("Altera USB-Blaster II (uninitialized) found");
|
||||
LOG_INFO("Loading firmware...");
|
||||
ret = load_usb_blaster_firmware(temp, low);
|
||||
|
@ -216,13 +216,13 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
|
|||
const uint16_t pids_renum[] = { low->ublast_pid, 0 };
|
||||
|
||||
if (renumeration == false) {
|
||||
if (jtag_libusb_open(vids_renum, pids_renum, &low->libusb_dev, NULL) != ERROR_OK) {
|
||||
if (jtag_libusb_open(vids_renum, pids_renum, NULL, &low->libusb_dev, NULL) != ERROR_OK) {
|
||||
LOG_ERROR("Altera USB-Blaster II not found");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
} else {
|
||||
int retry = 10;
|
||||
while (jtag_libusb_open(vids_renum, pids_renum, &low->libusb_dev, NULL) != ERROR_OK && retry--) {
|
||||
while (jtag_libusb_open(vids_renum, pids_renum, NULL, &low->libusb_dev, NULL) != ERROR_OK && retry--) {
|
||||
usleep(1000000);
|
||||
LOG_INFO("Waiting for reenumerate...");
|
||||
}
|
||||
|
|
|
@ -341,7 +341,7 @@ struct usbprog_jtag *usbprog_jtag_open(void)
|
|||
const uint16_t pids[] = { PID, 0 };
|
||||
struct libusb_device_handle *dev;
|
||||
|
||||
if (jtag_libusb_open(vids, pids, &dev, NULL) != ERROR_OK)
|
||||
if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
|
||||
return NULL;
|
||||
|
||||
struct usbprog_jtag *tmp = malloc(sizeof(struct usbprog_jtag));
|
||||
|
|
Loading…
Reference in New Issue