jtag/hla, jtag/stlink: switch to command 'adapter serial'

The driver hla defines the command 'hla_serial' to specify the
serial string of the adapter.
The driver st-link defines the command 'st-link serial' to specify
the serial string of the adapter.

Remove and deprecate the driver commands and use 'adapter serial'.

Change-Id: I9505c398a77125b1ebf4ba71da7baf4d663b75be
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6657
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2021-10-08 12:37:19 +02:00
parent ad18c1a47f
commit c6460ea36d
10 changed files with 36 additions and 81 deletions

View File

@ -2371,9 +2371,7 @@ This command is only available if your libusb1 is at least version 1.0.16.
Specifies the @var{serial_string} of the adapter to use. Specifies the @var{serial_string} of the adapter to use.
If this command is not specified, serial strings are not checked. If this command is not specified, serial strings are not checked.
Only the following adapter drivers use the serial string from this command: Only the following adapter drivers use the serial string from this command:
cmsis_dap, ft232r, ftdi, jlink, kitprog, presto, vsllink, xds110. cmsis_dap, ft232r, ftdi, hla, jlink, kitprog, presto, st-link, vsllink, xds110.
The following adapters have their own command to specify the serial string:
hla, st-link.
@end deffn @end deffn
@section Interface Drivers @section Interface Drivers
@ -3040,10 +3038,6 @@ version reported is V2.J21.S4.
Currently Not Supported. Currently Not Supported.
@end deffn @end deffn
@deffn {Config Command} {hla_serial} serial
Specifies the serial number of the adapter.
@end deffn
@deffn {Config Command} {hla_layout} (@option{stlink}|@option{icdi}|@option{nulink}) @deffn {Config Command} {hla_layout} (@option{stlink}|@option{icdi}|@option{nulink})
Specifies the adapter layout to use. Specifies the adapter layout to use.
@end deffn @end deffn
@ -3092,10 +3086,6 @@ ST-LINK server software module}.
@emph{Note:} ST-Link TCP server does not support the SWIM transport. @emph{Note:} ST-Link TCP server does not support the SWIM transport.
@end deffn @end deffn
@deffn {Config Command} {st-link serial} serial
Specifies the serial number of the adapter.
@end deffn
@deffn {Config Command} {st-link vid_pid} [vid pid]+ @deffn {Config Command} {st-link vid_pid} [vid pid]+
Pairs of vendor IDs and product IDs of the device. Pairs of vendor IDs and product IDs of the device.
@end deffn @end deffn

View File

@ -22,6 +22,7 @@
/* project specific includes */ /* project specific includes */
#include <helper/binarybuffer.h> #include <helper/binarybuffer.h>
#include <jtag/adapter.h>
#include <jtag/interface.h> #include <jtag/interface.h>
#include <jtag/hla/hla_layout.h> #include <jtag/hla/hla_layout.h>
#include <jtag/hla/hla_transport.h> #include <jtag/hla/hla_transport.h>
@ -1054,8 +1055,9 @@ static int nulink_usb_open(struct hl_interface_param_s *param, void **fd)
goto error_open; goto error_open;
} }
if (param->serial) { const char *serial = adapter_get_required_serial();
size_t len = mbstowcs(NULL, param->serial, 0); if (serial) {
size_t len = mbstowcs(NULL, serial, 0);
target_serial = calloc(len + 1, sizeof(wchar_t)); target_serial = calloc(len + 1, sizeof(wchar_t));
if (!target_serial) { if (!target_serial) {
@ -1063,7 +1065,7 @@ static int nulink_usb_open(struct hl_interface_param_s *param, void **fd)
goto error_open; goto error_open;
} }
if (mbstowcs(target_serial, param->serial, len + 1) == (size_t)(-1)) { if (mbstowcs(target_serial, serial, len + 1) == (size_t)(-1)) {
LOG_WARNING("unable to convert serial"); LOG_WARNING("unable to convert serial");
free(target_serial); free(target_serial);
target_serial = NULL; target_serial = NULL;

View File

@ -38,6 +38,7 @@
#include <helper/bits.h> #include <helper/bits.h>
#include <helper/system.h> #include <helper/system.h>
#include <helper/time_support.h> #include <helper/time_support.h>
#include <jtag/adapter.h>
#include <jtag/interface.h> #include <jtag/interface.h>
#include <jtag/hla/hla_layout.h> #include <jtag/hla/hla_layout.h>
#include <jtag/hla/hla_transport.h> #include <jtag/hla/hla_transport.h>
@ -3363,7 +3364,7 @@ static int stlink_usb_usb_open(void *handle, struct hl_interface_param_s *param)
in order to become operational. in order to become operational.
*/ */
do { do {
if (jtag_libusb_open(param->vid, param->pid, param->serial, if (jtag_libusb_open(param->vid, param->pid, adapter_get_required_serial(),
&h->usb_backend_priv.fd, stlink_usb_get_alternate_serial) != ERROR_OK) { &h->usb_backend_priv.fd, stlink_usb_get_alternate_serial) != ERROR_OK) {
LOG_ERROR("open failed"); LOG_ERROR("open failed");
return ERROR_FAIL; return ERROR_FAIL;
@ -3574,7 +3575,8 @@ static int stlink_tcp_open(void *handle, struct hl_interface_param_s *param)
char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0}; char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0};
uint8_t stlink_used; uint8_t stlink_used;
bool stlink_id_matched = false; bool stlink_id_matched = false;
bool stlink_serial_matched = (!param->serial); const char *adapter_serial = adapter_get_required_serial();
bool stlink_serial_matched = !adapter_serial;
for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) { for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) {
/* get the stlink info */ /* get the stlink info */
@ -3604,27 +3606,28 @@ static int stlink_tcp_open(void *handle, struct hl_interface_param_s *param)
continue; continue;
/* check the serial if specified */ /* check the serial if specified */
if (param->serial) { if (adapter_serial) {
/* ST-Link server fixes the buggy serial returned by old ST-Link DFU /* ST-Link server fixes the buggy serial returned by old ST-Link DFU
* for further details refer to stlink_usb_get_alternate_serial * for further details refer to stlink_usb_get_alternate_serial
* so if the user passes the buggy serial, we need to fix it before * so if the user passes the buggy serial, we need to fix it before
* comparing with the serial returned by ST-Link server */ * comparing with the serial returned by ST-Link server */
if (strlen(param->serial) == STLINK_SERIAL_LEN / 2) { if (strlen(adapter_serial) == STLINK_SERIAL_LEN / 2) {
char fixed_serial[STLINK_SERIAL_LEN + 1]; char fixed_serial[STLINK_SERIAL_LEN + 1];
for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2) for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2)
sprintf(fixed_serial + i, "%02X", param->serial[i / 2]); sprintf(fixed_serial + i, "%02X", adapter_serial[i / 2]);
fixed_serial[STLINK_SERIAL_LEN] = '\0'; fixed_serial[STLINK_SERIAL_LEN] = '\0';
stlink_serial_matched = strcmp(fixed_serial, serial) == 0; stlink_serial_matched = strcmp(fixed_serial, serial) == 0;
} else } else {
stlink_serial_matched = strcmp(param->serial, serial) == 0; stlink_serial_matched = strcmp(adapter_serial, serial) == 0;
}
} }
if (!stlink_serial_matched) if (!stlink_serial_matched)
LOG_DEBUG("Device serial number '%s' doesn't match requested serial '%s'", LOG_DEBUG("Device serial number '%s' doesn't match requested serial '%s'",
serial, param->serial); serial, adapter_serial);
else /* exit the search loop if there is match */ else /* exit the search loop if there is match */
break; break;
} }
@ -3693,7 +3696,7 @@ static int stlink_open(struct hl_interface_param_s *param, enum stlink_mode mode
for (unsigned i = 0; param->vid[i]; i++) { for (unsigned i = 0; param->vid[i]; i++) {
LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s", LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s",
h->st_mode, param->vid[i], param->pid[i], h->st_mode, param->vid[i], param->pid[i],
param->serial ? param->serial : ""); adapter_get_required_serial() ? adapter_get_required_serial() : "");
} }
if (param->use_stlink_tcp) if (param->use_stlink_tcp)
@ -4916,25 +4919,6 @@ static int stlink_dap_trace_read(uint8_t *buf, size_t *size)
return stlink_usb_trace_read(stlink_dap_handle, buf, size); return stlink_usb_trace_read(stlink_dap_handle, buf, size);
} }
/** */
COMMAND_HANDLER(stlink_dap_serial_command)
{
LOG_DEBUG("stlink_dap_serial_command");
if (CMD_ARGC != 1) {
LOG_ERROR("Expected exactly one argument for \"st-link serial <serial-number>\".");
return ERROR_COMMAND_SYNTAX_ERROR;
}
if (stlink_dap_param.serial) {
LOG_WARNING("Command \"st-link serial\" already used. Replacing previous value");
free((void *)stlink_dap_param.serial);
}
stlink_dap_param.serial = strdup(CMD_ARGV[0]);
return ERROR_OK;
}
/** */ /** */
COMMAND_HANDLER(stlink_dap_vid_pid) COMMAND_HANDLER(stlink_dap_vid_pid)
{ {
@ -5025,13 +5009,6 @@ COMMAND_HANDLER(stlink_dap_cmd_command)
/** */ /** */
static const struct command_registration stlink_dap_subcommand_handlers[] = { static const struct command_registration stlink_dap_subcommand_handlers[] = {
{
.name = "serial",
.handler = stlink_dap_serial_command,
.mode = COMMAND_CONFIG,
.help = "set the serial number of the adapter",
.usage = "<serial_number>",
},
{ {
.name = "vid_pid", .name = "vid_pid",
.handler = stlink_dap_vid_pid, .handler = stlink_dap_vid_pid,
@ -5112,9 +5089,6 @@ static int stlink_dap_quit(void)
{ {
LOG_DEBUG("stlink_dap_quit()"); LOG_DEBUG("stlink_dap_quit()");
free((void *)stlink_dap_param.serial);
stlink_dap_param.serial = NULL;
return stlink_close(stlink_dap_handle); return stlink_close(stlink_dap_handle);
} }

View File

@ -23,6 +23,7 @@
/* project specific includes */ /* project specific includes */
#include <helper/binarybuffer.h> #include <helper/binarybuffer.h>
#include <jtag/adapter.h>
#include <jtag/interface.h> #include <jtag/interface.h>
#include <jtag/hla/hla_layout.h> #include <jtag/hla/hla_layout.h>
#include <jtag/hla/hla_transport.h> #include <jtag/hla/hla_transport.h>
@ -681,11 +682,11 @@ static int icdi_usb_open(struct hl_interface_param_s *param, void **fd)
for (uint8_t i = 0; param->vid[i] && param->pid[i]; ++i) for (uint8_t i = 0; param->vid[i] && param->pid[i]; ++i)
LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s", param->transport, LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s", param->transport,
param->vid[i], param->pid[i], param->serial ? param->serial : ""); param->vid[i], param->pid[i], adapter_get_required_serial() ? adapter_get_required_serial() : "");
/* TI (Stellaris) ICDI provides its serial number in the USB descriptor; /* TI (Stellaris) ICDI provides its serial number in the USB descriptor;
no need to provide a callback here. */ no need to provide a callback here. */
jtag_libusb_open(param->vid, param->pid, param->serial, &h->usb_dev, NULL); jtag_libusb_open(param->vid, param->pid, adapter_get_required_serial(), &h->usb_dev, NULL);
if (!h->usb_dev) { if (!h->usb_dev) {
LOG_ERROR("open failed"); LOG_ERROR("open failed");

View File

@ -38,7 +38,6 @@
static struct hl_interface_s hl_if = { static struct hl_interface_s hl_if = {
.param = { .param = {
.device_desc = NULL, .device_desc = NULL,
.serial = NULL,
.vid = { 0 }, .vid = { 0 },
.pid = { 0 }, .pid = { 0 },
.transport = HL_TRANSPORT_UNKNOWN, .transport = HL_TRANSPORT_UNKNOWN,
@ -136,7 +135,6 @@ static int hl_interface_quit(void)
jtag_command_queue_reset(); jtag_command_queue_reset();
free((void *)hl_if.param.device_desc); free((void *)hl_if.param.device_desc);
free((void *)hl_if.param.serial);
return ERROR_OK; return ERROR_OK;
} }
@ -238,19 +236,6 @@ COMMAND_HANDLER(hl_interface_handle_device_desc_command)
return ERROR_OK; return ERROR_OK;
} }
COMMAND_HANDLER(hl_interface_handle_serial_command)
{
LOG_DEBUG("hl_interface_handle_serial_command");
if (CMD_ARGC == 1) {
hl_if.param.serial = strdup(CMD_ARGV[0]);
} else {
LOG_ERROR("expected exactly one argument to hl_serial <serial-number>");
}
return ERROR_OK;
}
COMMAND_HANDLER(hl_interface_handle_layout_command) COMMAND_HANDLER(hl_interface_handle_layout_command)
{ {
LOG_DEBUG("hl_interface_handle_layout_command"); LOG_DEBUG("hl_interface_handle_layout_command");
@ -354,13 +339,6 @@ static const struct command_registration hl_interface_command_handlers[] = {
.help = "set the device description of the adapter", .help = "set the device description of the adapter",
.usage = "description_string", .usage = "description_string",
}, },
{
.name = "hla_serial",
.handler = &hl_interface_handle_serial_command,
.mode = COMMAND_CONFIG,
.help = "set the serial number of the adapter",
.usage = "serial_string",
},
{ {
.name = "hla_layout", .name = "hla_layout",
.handler = &hl_interface_handle_layout_command, .handler = &hl_interface_handle_layout_command,

View File

@ -34,8 +34,6 @@ extern const char *hl_transports[];
struct hl_interface_param_s { struct hl_interface_param_s {
/** */ /** */
const char *device_desc; const char *device_desc;
/** */
const char *serial;
/** List of recognised VIDs */ /** List of recognised VIDs */
uint16_t vid[HLA_MAX_USB_IDS + 1]; uint16_t vid[HLA_MAX_USB_IDS + 1];
/** List of recognised PIDs */ /** List of recognised PIDs */

View File

@ -759,6 +759,12 @@ proc "ftdi serial" {args} {
eval adapter serial $args eval adapter serial $args
} }
lappend _telnet_autocomplete_skip hla_serial
proc hla_serial args {
echo "DEPRECATED! use 'adapter serial' not 'hla_serial'"
eval adapter serial $args
}
lappend _telnet_autocomplete_skip "jlink serial" lappend _telnet_autocomplete_skip "jlink serial"
proc "jlink serial" {args} { proc "jlink serial" {args} {
echo "DEPRECATED! use 'adapter serial' not 'jlink serial'" echo "DEPRECATED! use 'adapter serial' not 'jlink serial'"
@ -777,6 +783,12 @@ proc "presto serial" {args} {
eval adapter serial $args eval adapter serial $args
} }
lappend _telnet_autocomplete_skip "st-link serial"
proc "st-link serial" {args} {
echo "DEPRECATED! use 'adapter serial' not 'st-link serial'"
eval adapter serial $args
}
lappend _telnet_autocomplete_skip "vsllink usb_serial" lappend _telnet_autocomplete_skip "vsllink usb_serial"
proc "vsllink usb_serial" {args} { proc "vsllink usb_serial" {args} {
echo "DEPRECATED! use 'adapter serial' not 'vsllink usb_serial'" echo "DEPRECATED! use 'adapter serial' not 'vsllink usb_serial'"

View File

@ -17,4 +17,4 @@ st-link vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0
# Optionally specify the serial number of usb device # Optionally specify the serial number of usb device
# e.g. # e.g.
# st-link serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f" # adapter serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f"

View File

@ -13,4 +13,4 @@ hla_vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374
# firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial # firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial
# number reset issues. # number reset issues.
# eg. # eg.
#hla_serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f" # adapter serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f"

View File

@ -14,4 +14,4 @@ hla_vid_pid 0x1cbe 0x00fd
# Optionally specify the serial number of TI-ICDI devices, for when using # Optionally specify the serial number of TI-ICDI devices, for when using
# multiple devices. Serial numbers can be obtained using lsusb -v # multiple devices. Serial numbers can be obtained using lsusb -v
# Ex. # Ex.
#hla_serial "0F003065" # adapter serial "0F003065"