This is an automated email from Gerrit. "Vitaly Cheptsov <vit9...@protonmail.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8875
-- gerrit commit a3c153515eb537c421755bed25536d38cd8a3b2c Author: Vitaly Cheptsov <vit9...@protonmail.com> Date: Sun May 18 08:49:30 2025 +0300 jlink: add nickname support Using nicknames provides a human-readable alternative to serial numbers for convenience purposes. Change-Id: I5434144778b1bbf350b22d0b1da197bee87d184a Signed-off-by: Vitaly Cheptsov <vit9...@protonmail.com> diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 9caf37f6f0..2326ed2770 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -23,6 +23,7 @@ #include <stdint.h> #include <math.h> +#include <string.h> #include <jtag/interface.h> #include <jtag/swd.h> @@ -41,6 +42,7 @@ static enum jaylink_jtag_version jtag_command_version; static uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE]; static uint32_t serial_number; +static char *nickname; static bool use_serial_number; static bool use_usb_location; static enum jaylink_usb_address usb_address; @@ -562,7 +564,7 @@ static int jlink_open_device(uint32_t ifaces, bool *found_device) use_usb_location = !!adapter_usb_get_location(); - if (!use_serial_number && !use_usb_address && !use_usb_location && num_devices > 1) { + if (!use_serial_number && !use_usb_address && !use_usb_location && !nickname && num_devices > 1) { LOG_ERROR("Multiple devices found, specify the desired device"); LOG_INFO("Found devices:"); for (size_t i = 0; devs[i]; i++) { @@ -575,7 +577,12 @@ static int jlink_open_device(uint32_t ifaces, bool *found_device) jaylink_strerror(ret)); continue; } - LOG_INFO("Device %zu serial: %" PRIu32, i, serial); + char name[JAYLINK_NICKNAME_MAX_LENGTH]; + int name_ret = jaylink_device_get_nickname(devs[i], name); + if (name_ret == JAYLINK_OK) + LOG_INFO("Device %zu serial: %" PRIu32 ", nickname %s", i, serial, name); + else + LOG_INFO("Device %zu serial: %" PRIu32, i, serial); } jaylink_free_devices(devs, true); @@ -623,6 +630,21 @@ static int jlink_open_device(uint32_t ifaces, bool *found_device) if (use_usb_location && !jlink_usb_location_equal(dev)) continue; + if (nickname) { + char name[JAYLINK_NICKNAME_MAX_LENGTH]; + ret = jaylink_device_get_nickname(dev, name); + if (ret == JAYLINK_ERR_NOT_AVAILABLE) { + continue; + } else if (ret != JAYLINK_OK) { + LOG_WARNING("jaylink_device_get_nickname() failed: %s", + jaylink_strerror(ret)); + continue; + } + + if (strcmp(name, nickname) != 0) + continue; + } + ret = jaylink_open(dev, &devh); if (ret == JAYLINK_OK) { @@ -868,6 +890,8 @@ static int jlink_quit(void) jaylink_close(devh); jaylink_exit(jayctx); + free(nickname); + nickname = NULL; return ERROR_OK; } @@ -992,6 +1016,26 @@ COMMAND_HANDLER(jlink_usb_command) return ERROR_OK; } +COMMAND_HANDLER(jlink_nickname_command) +{ + if (CMD_ARGC != 1) + return ERROR_COMMAND_SYNTAX_ERROR; + + if (strlen(CMD_ARGV[0]) >= JAYLINK_NICKNAME_MAX_LENGTH) { + command_print(CMD, "Invalid nickname: %s", CMD_ARGV[0]); + return ERROR_COMMAND_ARGUMENT_INVALID; + } + + nickname = strdup(CMD_ARGV[0]); + + if (!nickname) { + LOG_ERROR("Failed to allocate nickname buffer"); + return ERROR_FAIL; + } + + return ERROR_OK; +} + COMMAND_HANDLER(jlink_handle_hwstatus_command) { int ret; @@ -1910,6 +1954,13 @@ static const struct command_registration jlink_subcommand_handlers[] = { .help = "set the USB address of the device that should be used", .usage = "<0-3>" }, + { + .name = "nickname", + .handler = &jlink_nickname_command, + .mode = COMMAND_CONFIG, + .help = "set the nickname of the device that should be used", + .usage = "<nickname>" + }, { .name = "config", .handler = &jlink_handle_config_command, --