This is an automated email from Gerrit. "Marc Schink <[email protected]>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9715
-- gerrit commit 04b8f6ead4b5dd423f8048e6eab93fbb00122bb1 Author: Marc Schink <[email protected]> Date: Wed May 13 18:19:08 2026 +0200 adapter/xvc: Use adapter core for remote address handling Use the remote address handling provided by the adapter core instead of implementing it directly in the driver. Keep the legacy commands 'xvc host' and 'xvc port' for backwards compatibility, but mark them as deprecated. Remove the implicit 'localhost' default for 'adapter remote' and require an explicit address, matching USB behavior where no connection is made to the first available USB device. Legacy commands keep the 'localhost' default but now emit a deprecation warning. Change-Id: I7a0f7a1484435914120b7a4fd94e416aa0504aa3 Signed-off-by: Marc Schink <[email protected]> diff --git a/doc/openocd.texi b/doc/openocd.texi index b0480442dd..e78c599d22 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -3924,21 +3924,20 @@ An implementation of XVC server to gpiod is available in @url{https://pypi.org/project/xvc-gpiod} and is suitable for testing this driver. -Example configuration: +To connect to the server on @t{192.168.3.192} and port @t{5000}, use: @example -xvc host 192.168.3.192 -xvc port 5000 +adapter driver xvc +adapter remote 192.168.3.192:5000 @end example -@end deffn -@deffn {Config Command} {xvc host} @var{hostname} -Specifies the hostname of the remote debugger or UNIX socket to connect to. -@end deffn +To connect via a Unix domain socket, for example @file{/tmp/xvc.sock}, use: + +@example +adapter driver xvc +adapter remote unix:/tmp/xvc.sock +@end example -@deffn {Config Command} {xvc port} @var{number} -Specifies the port of the remote process to connect to. -'0' is a special case where UNIX sockets are used. @end deffn @end deffn diff --git a/src/jtag/drivers/xvc.c b/src/jtag/drivers/xvc.c index 6e875e4815..b7e856d7f9 100644 --- a/src/jtag/drivers/xvc.c +++ b/src/jtag/drivers/xvc.c @@ -24,6 +24,7 @@ #include "helper/bits.h" #include "helper/replacements.h" #include <jtag/interface.h> +#include <jtag/adapter.h> #include <jtag/commands.h> #include "helper/log.h" #include <stdio.h> @@ -34,7 +35,7 @@ #include <time.h> static char *xvc_host; -static char *xvc_port; +static uint16_t xvc_port; static uint32_t xvc_tck; static int xvc_fd; @@ -322,18 +323,21 @@ static int xvc_reset(int trst, int srst) return ERROR_OK; } -static int xvc_init_tcp(int *fd) +static int xvc_init_tcp(const char *address, uint16_t port, int *fd) { - LOG_INFO("Connecting to %s:%s", xvc_host ? xvc_host : "localhost", xvc_port); + LOG_INFO("Connecting to %s:%d", address, port); const struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM }; + char port_str[5 + 1]; + snprintf(port_str, sizeof(port_str), "%" PRIu16, port); + struct addrinfo *result; // Obtain address(es) matching host/port. - int s = getaddrinfo(xvc_host, xvc_port, &hints, &result); + int s = getaddrinfo(address, port_str, &hints, &result); if (s != 0) { LOG_ERROR("getaddrinfo: %s", gai_strerror(s)); return ERROR_FAIL; @@ -376,14 +380,9 @@ static int xvc_init_tcp(int *fd) return ERROR_OK; } -static int xvc_init_unix(int *fd) +static int xvc_init_unix(const char *path, int *fd) { - if (!xvc_host) { - LOG_ERROR("host/socket not specified"); - return ERROR_FAIL; - } - - LOG_INFO("Connecting to unix socket %s", xvc_host); + LOG_INFO("Connecting to unix socket %s", path); *fd = socket(PF_UNIX, SOCK_STREAM, 0); if (*fd < 0) { LOG_ERROR("socket"); @@ -392,7 +391,7 @@ static int xvc_init_unix(int *fd) struct sockaddr_un addr; addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, xvc_host, sizeof(addr.sun_path)); + strncpy(addr.sun_path, path, sizeof(addr.sun_path)); addr.sun_path[sizeof(addr.sun_path) - 1] = '\0'; if (connect(*fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) { @@ -408,10 +407,7 @@ COMMAND_HANDLER(xvc_handle_port_command) { if (CMD_ARGC != 1) return ERROR_COMMAND_SYNTAX_ERROR; - uint16_t port; - COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], port); - free(xvc_port); - xvc_port = (port == 0) ? NULL : strdup(CMD_ARGV[0]); + COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], xvc_port); return ERROR_OK; } @@ -466,10 +462,38 @@ static int xvc_init(void) LOG_DEBUG("Initializing XVC driver"); int ret; - if (!xvc_port) - ret = xvc_init_unix(&xvc_fd); + const struct adapter_remote *remote = adapter_get_remote(); + const char *address = remote->address; + uint16_t port = remote->port; + enum adapter_remote_type type = remote->type; + + if (!remote->address) { + LOG_WARNING("DEPRECATED! use 'adapter remote' not 'xvc host' and 'xvc port'"); + + if (!xvc_host) { + if (xvc_port != 0) { + LOG_WARNING("A hostname must be specified in future versions, 'localhost' is used for now because none was provided"); + xvc_host = strdup("localhost"); + } else { + LOG_ERROR("A Unix domain socket path must be specified"); + return ERROR_FAIL; + } + } + + address = xvc_host; + port = xvc_port; + type = (port != 0) ? ADAPTER_REMOTE_TYPE_IP : ADAPTER_REMOTE_TYPE_UNIX; + } + + if (type == ADAPTER_REMOTE_TYPE_IP && !port) { + LOG_ERROR("A port number must be specified"); + return ERROR_FAIL; + } + + if (type == ADAPTER_REMOTE_TYPE_UNIX) + ret = xvc_init_unix(address, &xvc_fd); else - ret = xvc_init_tcp(&xvc_fd); + ret = xvc_init_tcp(address, port, &xvc_fd); if (ret != ERROR_OK) return ret; @@ -493,7 +517,6 @@ static int xvc_quit(void) LOG_ERROR("close_socket"); return ERROR_FAIL; } - free(xvc_port); free(xvc_host); free(xvc_tms_buf); free(xvc_tdi_buf); --
