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/+/9714

-- gerrit

commit 9bedcb384c08ac0433e2408d2d581d6fb830bcc8
Author: Marc Schink <[email protected]>
Date:   Wed May 13 01:35:18 2026 +0200

    adapter/cmsis-dap: 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 'cmsis-dap tcp host' and 'cmsis-dap tcp port'
    for backwards compatibility, but mark them as deprecated.
    
    Change-Id: Ifdf788196639fb916c78928404155262e96f22fa
    Signed-off-by: Marc Schink <[email protected]>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index 5bd704d942..b0480442dd 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -2680,7 +2680,7 @@ Specifies how to communicate with the adapter:
 @item @option{usb_bulk} Use USB bulk - CMSIS-DAP v2
 @item @option{tcp} Use TCP/IP instead of USB
 @item @option{auto} First try USB bulk CMSIS-DAP v2, if not found try USB HID
-CMSIS-DAP v1, if not found try TCP (if @command{cmsis-dap tcp host} is
+CMSIS-DAP v1, if not found try TCP (if @command{adapter remote} is
 configured). This is the default if @command{cmsis-dap backend} is not
 specified.
 @end itemize
@@ -2692,24 +2692,23 @@ In most cases need not to be specified and interfaces 
are searched by
 interface string or for user class interface.
 @end deffn
 
-@deffn {Config Command} {cmsis-dap tcp host} hostname
-Specifies the @var{hostname} or IP address of the remote programmer. For use
-with 'tcp' backend only.
+To connect to a CMSIS-DAP adapter, use the @command{adapter remote} command.
+Use this command only when using the @option{tcp} backend.
+
 @example
 cmsis-dap backend tcp
-cmsis-dap tcp host 192.168.1.4
+adapter remote 192.168.1.4
 @end example
-@end deffn
 
-@deffn {Config Command} {cmsis-dap tcp port} port
-Specifies the TCP @var{port} number used by the remote programmer for DAP
-commands. The default port is 4441. For use with 'tcp' backend only.
+By default, port 4441 is used. To use a different port, specify the port like 
in
+this example:
+
 @example
 cmsis-dap backend tcp
-cmsis-dap tcp host 192.168.1.4
-cmsis-dap tcp port 4441
+adapter remote 192.168.1.4:4492
 @end example
-@end deffn
+
+The adapter does not support Unix domain sockets.
 
 @deffn {Config Command} {cmsis-dap tcp min_timeout} milliseconds
 Sets a lower bound on the requested timeout in @var{milliseconds} to wait for
diff --git a/src/jtag/drivers/cmsis_dap_tcp.c b/src/jtag/drivers/cmsis_dap_tcp.c
index 124c774209..37980a0d29 100644
--- a/src/jtag/drivers/cmsis_dap_tcp.c
+++ b/src/jtag/drivers/cmsis_dap_tcp.c
@@ -48,14 +48,13 @@
 #include <ws2tcpip.h>
 #endif
 
+#include "jtag/adapter.h"
 #include "helper/command.h"
 #include "helper/log.h"
 #include "helper/replacements.h"
 #include "helper/system.h"
 #include "cmsis_dap.h"
 
-#define STRINGIFY(x) #x
-
 // If the protocol changes in the future, the SIGNATURE should also be changed.
 #define DAP_PKT_HDR_SIGNATURE  0x00504144      // "DAP"
 #define DAP_PKT_TYPE_REQUEST   0x01
@@ -104,8 +103,7 @@ struct cmsis_dap_backend_data {
 };
 
 static char *cmsis_dap_tcp_host;
-static char cmsis_dap_tcp_port_default[] = STRINGIFY(CMSIS_DAP_TCP_PORT);
-static char *cmsis_dap_tcp_port = cmsis_dap_tcp_port_default;
+static uint16_t cmsis_dap_tcp_port = CMSIS_DAP_TCP_PORT;
 static int cmsis_dap_tcp_min_timeout_ms = DEFAULT_MIN_TIMEOUT_MS;
 
 static void cmsis_dap_tcp_close(struct cmsis_dap *dap);
@@ -117,12 +115,32 @@ static int cmsis_dap_tcp_open(struct cmsis_dap *dap,
                const uint16_t pids[] __attribute__((unused)),
                const char *serial __attribute__((unused)))
 {
-       // Skip the open if the user has not provided a hostname.
-       if (!cmsis_dap_tcp_host) {
-               LOG_ERROR("The hostname or IP address of the CMSIS-DAP adapter 
must be specified");
+       const struct adapter_remote *remote = adapter_get_remote();
+
+       const char *address = remote->address;
+       uint16_t port = remote->port;
+
+       if (remote->address && remote->type == ADAPTER_REMOTE_TYPE_UNIX) {
+               LOG_ERROR("Unix domain socket is not supported by this 
adapter");
                return ERROR_FAIL;
        }
 
+       if (!remote->address) {
+               LOG_WARNING("DEPRECATED! use 'adapter remote' not 'cmsis-dap 
tcp host' and 'cmsis-dap tcp port'");
+               address = cmsis_dap_tcp_host;
+               port = cmsis_dap_tcp_port;
+       }
+
+       if (!address) {
+               LOG_ERROR("Adapter address not specified, use 'adapter 
remote'");
+               return ERROR_FAIL;
+       }
+
+       if (!port) {
+               port = CMSIS_DAP_TCP_PORT;
+               LOG_DEBUG("No port specified, using default port %" PRIu16, 
port);
+       }
+
        // Ignore vids, pids, serial. We use host and port subcommands instead.
 
        dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
@@ -138,13 +156,14 @@ static int cmsis_dap_tcp_open(struct cmsis_dap *dap,
        struct addrinfo *result, *rp;
        int fd = 0;
 
-       LOG_INFO("CMSIS-DAP: Connecting to %s:%s using TCP backend",
-                       cmsis_dap_tcp_host, cmsis_dap_tcp_port);
+       LOG_INFO("CMSIS-DAP: Connecting to %s:%d using TCP backend", address, 
port);
+
+       char port_str[5 + 1];
+       snprintf(port_str, sizeof(port_str), "%" PRIu16, cmsis_dap_tcp_port);
 
        /* Some of the following code was taken from remote_bitbang.c */
        /* Obtain address(es) matching host/port */
-       int s = getaddrinfo(cmsis_dap_tcp_host, cmsis_dap_tcp_port, &hints,
-                       &result);
+       int s = getaddrinfo(address, port_str, &hints, &result);
        if (s != 0) {
                LOG_ERROR("CMSIS-DAP: getaddrinfo: %s\n", gai_strerror(s));
                free(dap->bdata);
@@ -172,8 +191,8 @@ static int cmsis_dap_tcp_open(struct cmsis_dap *dap,
        freeaddrinfo(result);
 
        if (!rp) { /* No address succeeded */
-               LOG_ERROR("CMSIS-DAP: unable to connect to device %s:%s",
-                       cmsis_dap_tcp_host, cmsis_dap_tcp_port);
+               LOG_ERROR("CMSIS-DAP: unable to connect to device %s:%" PRIu16,
+                       address, port);
                log_socket_error("Failed to connect");
                free(dap->bdata);
                dap->bdata = NULL;
@@ -465,14 +484,8 @@ COMMAND_HANDLER(cmsis_dap_handle_tcp_port)
        if (CMD_ARGC != 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       if (cmsis_dap_tcp_port != cmsis_dap_tcp_port_default)
-               free(cmsis_dap_tcp_port);
+       COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], cmsis_dap_tcp_port);
 
-       cmsis_dap_tcp_port = strdup(CMD_ARGV[0]);
-       if (!cmsis_dap_tcp_port) {
-               LOG_ERROR("CMSIS-DAP: out of memory");
-               return ERROR_FAIL;
-       }
        return ERROR_OK;
 }
 
diff --git a/tcl/interface/cmsis-dap-tcp.cfg b/tcl/interface/cmsis-dap-tcp.cfg
index 7889fb9444..e175b043e4 100644
--- a/tcl/interface/cmsis-dap-tcp.cfg
+++ b/tcl/interface/cmsis-dap-tcp.cfg
@@ -8,10 +8,10 @@ adapter driver cmsis-dap
 cmsis-dap backend tcp
 
 # Specify the hostname or IP address of your programmer.
-# cmsis-dap tcp host 192.168.1.4
+# adapter remote 192.168.1.4
 
 # Optionally specify a port number. Default port is 4441.
-# cmsis-dap tcp port 4441
+# adapter remote 192.168.1.4:4441
 
 # Optionally set a lower bound on packet timeouts (milliseconds), if using a
 # slow network.

-- 

Reply via email to