This is an automated email from Gerrit. "zapb <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9584
-- gerrit commit cf53fbd49d8d166917bf5e0ea6ed78fac92b08b6 Author: Marc Schink <[email protected]> Date: Wed Apr 22 17:08:20 2026 +0200 adapter: Implement USB VID/PID parsing Currently, eight adapter drivers each implement their own USB VID/PID parsing, leading to duplicated code. Implement VID/PID parsing in the adapter core, similar to how device serials are handled. Driver specific changes will follow in a separate patch series. Change-Id: I314915f79874f9d7becba0d4094efcd2c694f0f0 Signed-off-by: Marc Schink <[email protected]> diff --git a/doc/openocd.texi b/doc/openocd.texi index a21a3e4bda..ee97868508 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2496,6 +2496,14 @@ mapping may not support all of the listed options. Returns the name of the debug adapter driver being used. @end deffn +@deffn {Config Command} {adapter usb vid_pid} [vid pid]+ +Specifies the USB vendor and product IDs of the adapter to use. +Currently, up to 16 [@var{vid}, @var{pid}] pairs may be given, e.g. +@example +adapter usb vid_pid 0xc251 0xf001 0x0d28 0x0204 +@end example +@end deffn + @deffn {Config Command} {adapter usb location} [<bus>-<port>[.<port>]...] Displays or specifies the physical USB port of the adapter to use. The path roots at @var{bus} and walks down the physical ports, with each diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index 7bf049cd86..a023438528 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -34,12 +34,17 @@ enum adapter_clk_mode { #define DEFAULT_CLOCK_SPEED_KHZ 100U +#define MAX_USB_IDS 16 + /** * Adapter configuration */ static struct { bool adapter_initialized; char *usb_location; + // vid = pid = 0 marks the end of the list. + uint16_t usb_vids[MAX_USB_IDS + 1]; + uint16_t usb_pids[MAX_USB_IDS + 1]; char *serial; enum adapter_clk_mode clock_mode; int speed_khz; @@ -325,6 +330,16 @@ static void adapter_usb_set_location(const char *location) } #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */ +const uint16_t *adapter_usb_get_vids(void) +{ + return adapter_config.usb_vids; +} + +const uint16_t *adapter_usb_get_pids(void) +{ + return adapter_config.usb_pids; +} + const char *adapter_usb_get_location(void) { return adapter_config.usb_location; @@ -1104,7 +1119,38 @@ COMMAND_HANDLER(handle_usb_location_command) } #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */ +COMMAND_HANDLER(handle_usb_vid_pid_command) +{ + if (MAX_USB_IDS * 2 < CMD_ARGC) { + LOG_WARNING("ignoring extra IDs in vid_pid " + "(maximum is %d pairs)", MAX_USB_IDS); + CMD_ARGC = MAX_USB_IDS * 2; + } + if (CMD_ARGC < 2 || (CMD_ARGC & 1)) { + LOG_WARNING("incomplete vid_pid configuration directive"); + return ERROR_COMMAND_SYNTAX_ERROR; + } + unsigned int i; + for (i = 0; i < CMD_ARGC; i += 2) { + COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i], adapter_config.usb_vids[i / 2]); + COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], adapter_config.usb_pids[i / 2]); + } + + /* null termination */ + adapter_config.usb_vids[i / 2] = 0; + adapter_config.usb_pids[i / 2] = 0; + + return ERROR_OK; +} + static const struct command_registration adapter_usb_command_handlers[] = { + { + .name = "vid_pid", + .handler = &handle_usb_vid_pid_command, + .mode = COMMAND_CONFIG, + .help = "display or set the USB VID and PID of the USB device", + .usage = "(vid pid)*", + }, #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS { .name = "location", diff --git a/src/jtag/adapter.h b/src/jtag/adapter.h index 6e957cbdc0..4254ae96dc 100644 --- a/src/jtag/adapter.h +++ b/src/jtag/adapter.h @@ -95,6 +95,11 @@ const char *adapter_usb_get_location(void); /** @returns true if USB location string is "<dev_bus>-<port_path[0]>[.<port_path[1]>[...]]" */ bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len); +/** @returns USB VIDs set with command 'adapter usb vid_pid' */ +const uint16_t *adapter_usb_get_vids(void); +/** @returns USB PIDs set with command 'adapter usb vid_pid' */ +const uint16_t *adapter_usb_get_pids(void); + /** @returns The current adapter speed setting. */ int adapter_get_speed(int *speed); --
