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

-- gerrit

commit d92e73fbc8782ecbe13dc8d89a21810488003229
Author: Marc Schink <[email protected]>
Date:   Tue May 12 22:40:22 2026 +0200

    adapter/remote-bitbang: 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 'remote_bitbang host' and 'remote_bitbang 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: I45a66f2d9768b7f49e94f9ab45f95e8c7538d55b
    Signed-off-by: Marc Schink <[email protected]>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index c446fd2a22..5bd704d942 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -2992,16 +2992,6 @@ that process instead of directly driving JTAG and SWD.
 The remote_bitbang driver is useful for debugging software running on
 processors which are being simulated.
 
-@deffn {Config Command} {remote_bitbang port} number
-Specifies the TCP port of the remote process to connect to or 0 to use UNIX
-sockets instead of TCP.
-@end deffn
-
-@deffn {Config Command} {remote_bitbang host} hostname
-Specifies the hostname of the remote process to connect to using TCP, or the
-name of the UNIX socket to use if remote_bitbang port is 0.
-@end deffn
-
 @deffn {Config Command} {remote_bitbang use_remote_sleep} (on|off)
 If this option is enabled, delays will not be executed locally but instead
 forwarded to the remote host. This is useful if the remote host performs its
@@ -3011,31 +3001,28 @@ This is disabled by default. This option must only be 
enabled if the given
 remote_bitbang host supports receiving the delay information.
 @end deffn
 
-For example, to connect remotely via TCP to the host foobar you might have
-something like:
+For example, to connect remotely via TCP to the host @t{foobar} and port 
@t{3335}
+you might have something like:
 
 @example
 adapter driver remote_bitbang
-remote_bitbang port 3335
-remote_bitbang host foobar
+adapter remote foobar:3335
 @end example
 
 And if you also wished to enable remote sleeping:
 
 @example
 adapter driver remote_bitbang
-remote_bitbang port 3335
-remote_bitbang host foobar
+adapter remote foobar:3335
 remote_bitbang use_remote_sleep on
 @end example
 
-To connect to another process running locally via UNIX sockets with socket
-named mysocket:
+To connect to another process running locally via Unix domain socket, for 
example
+@file{/tmp/mysocket.sock}, use:
 
 @example
 adapter driver remote_bitbang
-remote_bitbang port 0
-remote_bitbang host mysocket
+adapter remote unix:/tmp/mysocket.sock
 @end example
 @end deffn
 
diff --git a/src/jtag/drivers/remote_bitbang.c 
b/src/jtag/drivers/remote_bitbang.c
index f3a1073125..fd1835f9df 100644
--- a/src/jtag/drivers/remote_bitbang.c
+++ b/src/jtag/drivers/remote_bitbang.c
@@ -18,11 +18,12 @@
 #endif
 #include "helper/system.h"
 #include "helper/replacements.h"
+#include <jtag/adapter.h>
 #include <jtag/interface.h>
 #include "bitbang.h"
 
 static char *remote_bitbang_host;
-static char *remote_bitbang_port;
+static uint16_t remote_bitbang_port;
 
 static int remote_bitbang_fd;
 static uint8_t remote_bitbang_send_buf[512];
@@ -167,7 +168,6 @@ static int remote_bitbang_quit(void)
        }
 
        free(remote_bitbang_host);
-       free(remote_bitbang_port);
 
        LOG_INFO("remote_bitbang interface quit");
        return ERROR_OK;
@@ -288,18 +288,19 @@ static const struct bitbang_interface 
remote_bitbang_bitbang = {
        .flush = &remote_bitbang_flush,
 };
 
-static int remote_bitbang_init_tcp(void)
+static int remote_bitbang_init_tcp(const char *host, uint16_t port)
 {
        struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = 
SOCK_STREAM };
        struct addrinfo *result, *rp;
        int fd = 0;
 
-       LOG_INFO("Connecting to %s:%s",
-                       remote_bitbang_host ? remote_bitbang_host : "localhost",
-                       remote_bitbang_port);
+       LOG_INFO("Connecting to %s:%" PRIu16, host, port);
+
+       char port_str[5 + 1];
+       snprintf(port_str, sizeof(port_str), "%" PRIu16, port);
 
        /* Obtain address(es) matching host/port */
-       int s = getaddrinfo(remote_bitbang_host, remote_bitbang_port, &hints, 
&result);
+       int s = getaddrinfo(host, port_str, &hints, &result);
        if (s != 0) {
                LOG_ERROR("getaddrinfo: %s\n", gai_strerror(s));
                return ERROR_FAIL;
@@ -338,14 +339,9 @@ static int remote_bitbang_init_tcp(void)
        return fd;
 }
 
-static int remote_bitbang_init_unix(void)
+static int remote_bitbang_init_unix(const char *path)
 {
-       if (!remote_bitbang_host) {
-               LOG_ERROR("host/socket not specified");
-               return ERROR_FAIL;
-       }
-
-       LOG_INFO("Connecting to unix socket %s", remote_bitbang_host);
+       LOG_INFO("Connecting to Unix socket %s", path);
        int fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (fd < 0) {
                log_socket_error("socket");
@@ -354,7 +350,7 @@ static int remote_bitbang_init_unix(void)
 
        struct sockaddr_un addr;
        addr.sun_family = AF_UNIX;
-       strncpy(addr.sun_path, remote_bitbang_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) {
@@ -373,10 +369,35 @@ static int remote_bitbang_init(void)
        remote_bitbang_recv_buf_end = 0;
 
        LOG_INFO("Initializing remote_bitbang driver");
-       if (!remote_bitbang_port)
-               remote_bitbang_fd = remote_bitbang_init_unix();
+
+       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 
'remote_bitbang host' and 'remote_bitbang port'");
+
+               address = remote_bitbang_host;
+               port = remote_bitbang_port;
+               type = (port != 0) ? ADAPTER_REMOTE_TYPE_IP : 
ADAPTER_REMOTE_TYPE_UNIX;
+
+               if (!address) {
+                       if  (!port) {
+                               LOG_ERROR("A Unix domain socket path must be 
specified");
+                               return ERROR_FAIL;
+                       }
+
+                       LOG_WARNING("A hostname must be specified in future 
versions, 'localhost' is used for now because none was provided");
+                       address = "localhost";
+               }
+       }
+
+       if (type == ADAPTER_REMOTE_TYPE_UNIX)
+               remote_bitbang_fd = remote_bitbang_init_unix(address);
        else
-               remote_bitbang_fd = remote_bitbang_init_tcp();
+               remote_bitbang_fd = remote_bitbang_init_tcp(address, port);
 
        if (remote_bitbang_fd < 0)
                return remote_bitbang_fd;
@@ -390,10 +411,7 @@ static int remote_bitbang_init(void)
 COMMAND_HANDLER(remote_bitbang_handle_remote_bitbang_port_command)
 {
        if (CMD_ARGC == 1) {
-               uint16_t port;
-               COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], port);
-               free(remote_bitbang_port);
-               remote_bitbang_port = port == 0 ? NULL : strdup(CMD_ARGV[0]);
+               COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], remote_bitbang_port);
                return ERROR_OK;
        }
        return ERROR_COMMAND_SYNTAX_ERROR;

-- 

Reply via email to