From: Joerg Fischer Date: Sat, 31 Jan 2015 12:00:12 +0000 (+0100) Subject: J-Link serial number config option X-Git-Tag: v0.9.0-rc1~142 X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff_plain;h=fb9277191b715566c82b633a474a5c7c78fcfe1a J-Link serial number config option Add serial option to jlink config commands, handy when there is more than one adapter connected. To select adapter 0123456 for OpenOCD, use jlink serial 0123456 Change-Id: Ib29ce3f0c4975e1169211721a4531bf4db61f1ee Signed-off-by: Joerg Fischer Reviewed-on: http://openocd.zylin.com/2521 Tested-by: jenkins Reviewed-by: Paul Fertser --- diff --git a/doc/openocd.texi b/doc/openocd.texi index 9f9753930a..9734e3f036 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2953,6 +2953,16 @@ Save the current configuration to the internal persistent storage. @deffn {Config} {jlink pid} val Set the USB PID of the interface. As a configuration command, it can be used only before 'init'. @end deffn +@deffn {Config} {jlink serial} serial-number +Set the @var{serial-number} of the interface, in case more than one adapter is connected to the host. +If not specified, serial numbers are not considered. + +Note that there may be leading zeros in the @var{serial-number} string +that will not show in the Segger software, but must be specified here. +Debug level 3 output contains serial numbers if there is a mismatch. + +As a configuration command, it can be used only before 'init'. +@end deffn @end deffn @deffn {Interface Driver} {parport} diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 63580f7f6e..40665c3e78 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -256,6 +256,8 @@ static struct jlink *jlink_handle; static uint16_t vids[] = { 0x1366, 0x1366, 0x1366, 0x1366, 0x1366, 0 }; static uint16_t pids[] = { 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0 }; +static char *jlink_serial; + static uint32_t jlink_caps; static uint32_t jlink_hw_type; @@ -1019,6 +1021,19 @@ COMMAND_HANDLER(jlink_pid_command) return ERROR_OK; } +COMMAND_HANDLER(jlink_serial_command) +{ + if (CMD_ARGC != 1) { + LOG_ERROR("Need exactly one argument to jlink_serial"); + return ERROR_FAIL; + } + if (jlink_serial) + free(jlink_serial); + jlink_serial = strdup(CMD_ARGV[0]); + + return ERROR_OK; +} + COMMAND_HANDLER(jlink_handle_jlink_info_command) { if (jlink_get_version_info() == ERROR_OK) { @@ -1335,6 +1350,12 @@ static const struct command_registration jlink_subcommand_handlers[] = { .mode = COMMAND_CONFIG, .help = "set the pid of the interface we want to use", }, + { + .name = "serial", + .handler = &jlink_serial_command, + .mode = COMMAND_CONFIG, + .help = "set the serial number of the J-Link adapter we want to use" + }, COMMAND_REGISTRATION_DONE }; @@ -1744,7 +1765,7 @@ static void jlink_swd_queue_cmd(struct adiv5_dap *dap, uint8_t cmd, uint32_t *ds static struct jlink *jlink_usb_open() { struct jtag_libusb_device_handle *devh; - if (jtag_libusb_open(vids, pids, NULL, &devh) != ERROR_OK) + if (jtag_libusb_open(vids, pids, jlink_serial, &devh) != ERROR_OK) return NULL; /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS @@ -1776,7 +1797,7 @@ static struct jlink *jlink_usb_open() /* reopen jlink after usb_reset * on win32 this may take a second or two to re-enumerate */ int retval; - while ((retval = jtag_libusb_open(vids, pids, NULL, &devh)) != ERROR_OK) { + while ((retval = jtag_libusb_open(vids, pids, jlink_serial, &devh)) != ERROR_OK) { usleep(1000); timeout--; if (!timeout) diff --git a/tcl/interface/jlink.cfg b/tcl/interface/jlink.cfg index f5ff7c7be3..3d83362a6b 100644 --- a/tcl/interface/jlink.cfg +++ b/tcl/interface/jlink.cfg @@ -6,3 +6,14 @@ interface jlink + +# The serial number can be used to select a specific interface in case more than one +# is connected to the host. +# +# Segger software omits leading zeros in serial number displays, +# OpenOCD requires them. +# +# Example: Select J-Link with serial 123456789 +# +# jlink serial 000123456789 +