1 /***************************************************************************
2 * Copyright (C) 2011 by Richard Uhler *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
29 #include <jtag/interface.h>
33 #define UNIX_PATH_LEN 108
36 /* arbitrary limit on host name length: */
37 #define REMOTE_BITBANG_HOST_MAX 255
39 #define REMOTE_BITBANG_RAISE_ERROR(expr ...) \
42 LOG_ERROR("Terminating openocd."); \
46 static char *remote_bitbang_host
;
47 static char *remote_bitbang_port
;
49 FILE *remote_bitbang_in
;
50 FILE *remote_bitbang_out
;
52 static void remote_bitbang_putc(int c
)
54 if (EOF
== fputc(c
, remote_bitbang_out
))
55 REMOTE_BITBANG_RAISE_ERROR("remote_bitbang_putc: %s", strerror(errno
));
58 static int remote_bitbang_quit(void)
60 if (EOF
== fputc('Q', remote_bitbang_out
)) {
61 LOG_ERROR("fputs: %s", strerror(errno
));
65 if (EOF
== fflush(remote_bitbang_out
)) {
66 LOG_ERROR("fflush: %s", strerror(errno
));
70 /* We only need to close one of the FILE*s, because they both use the same */
71 /* underlying file descriptor. */
72 if (EOF
== fclose(remote_bitbang_out
)) {
73 LOG_ERROR("fclose: %s", strerror(errno
));
77 free(remote_bitbang_host
);
78 free(remote_bitbang_port
);
80 LOG_INFO("remote_bitbang interface quit");
84 /* Get the next read response. */
85 static int remote_bitbang_rread(void)
87 if (EOF
== fflush(remote_bitbang_out
)) {
88 remote_bitbang_quit();
89 REMOTE_BITBANG_RAISE_ERROR("fflush: %s", strerror(errno
));
92 int c
= fgetc(remote_bitbang_in
);
99 remote_bitbang_quit();
100 REMOTE_BITBANG_RAISE_ERROR(
101 "remote_bitbang: invalid read response: %c(%i)", c
, c
);
105 static int remote_bitbang_read(void)
107 remote_bitbang_putc('R');
108 return remote_bitbang_rread();
111 static void remote_bitbang_write(int tck
, int tms
, int tdi
)
113 char c
= '0' + ((tck
? 0x4 : 0x0) | (tms
? 0x2 : 0x0) | (tdi
? 0x1 : 0x0));
114 remote_bitbang_putc(c
);
117 static void remote_bitbang_reset(int trst
, int srst
)
119 char c
= 'r' + ((trst
? 0x2 : 0x0) | (srst
? 0x1 : 0x0));
120 remote_bitbang_putc(c
);
123 static void remote_bitbang_blink(int on
)
125 char c
= on
? 'B' : 'b';
126 remote_bitbang_putc(c
);
129 static struct bitbang_interface remote_bitbang_bitbang
= {
130 .read
= &remote_bitbang_read
,
131 .write
= &remote_bitbang_write
,
132 .reset
= &remote_bitbang_reset
,
133 .blink
= &remote_bitbang_blink
,
136 static int remote_bitbang_init_tcp(void)
138 struct addrinfo hints
= { .ai_family
= AF_UNSPEC
, .ai_socktype
= SOCK_STREAM
};
139 struct addrinfo
*result
, *rp
;
142 LOG_INFO("Connecting to %s:%s",
143 remote_bitbang_host
? remote_bitbang_host
: "localhost",
144 remote_bitbang_port
);
146 /* Obtain address(es) matching host/port */
147 int s
= getaddrinfo(remote_bitbang_host
, remote_bitbang_port
, &hints
, &result
);
149 LOG_ERROR("getaddrinfo: %s\n", gai_strerror(s
));
153 /* getaddrinfo() returns a list of address structures.
154 Try each address until we successfully connect(2).
155 If socket(2) (or connect(2)) fails, we (close the socket
156 and) try the next address. */
158 for (rp
= result
; rp
!= NULL
; rp
= rp
->ai_next
) {
159 fd
= socket(rp
->ai_family
, rp
->ai_socktype
, rp
->ai_protocol
);
163 if (connect(fd
, rp
->ai_addr
, rp
->ai_addrlen
) != -1)
169 freeaddrinfo(result
); /* No longer needed */
171 if (rp
== NULL
) { /* No address succeeded */
172 LOG_ERROR("Failed to connect: %s", strerror(errno
));
176 remote_bitbang_in
= fdopen(fd
, "r");
177 if (remote_bitbang_in
== NULL
) {
178 LOG_ERROR("fdopen: failed to open read stream");
182 remote_bitbang_out
= fdopen(fd
, "w");
183 if (remote_bitbang_out
== NULL
) {
184 LOG_ERROR("fdopen: failed to open write stream");
188 LOG_INFO("remote_bitbang driver initialized");
192 static int remote_bitbang_init_unix(void)
194 if (remote_bitbang_host
== NULL
) {
195 LOG_ERROR("host/socket not specified");
199 LOG_INFO("Connecting to unix socket %s", remote_bitbang_host
);
200 int fd
= socket(PF_UNIX
, SOCK_STREAM
, 0);
202 LOG_ERROR("socket: %s", strerror(errno
));
206 struct sockaddr_un addr
;
207 addr
.sun_family
= AF_UNIX
;
208 strncpy(addr
.sun_path
, remote_bitbang_host
, UNIX_PATH_LEN
);
209 addr
.sun_path
[UNIX_PATH_LEN
-1] = '\0';
211 if (connect(fd
, (struct sockaddr
*)&addr
, sizeof(struct sockaddr_un
)) < 0) {
212 LOG_ERROR("connect: %s", strerror(errno
));
216 remote_bitbang_in
= fdopen(fd
, "r");
217 if (remote_bitbang_in
== NULL
) {
218 LOG_ERROR("fdopen: failed to open read stream");
222 remote_bitbang_out
= fdopen(fd
, "w");
223 if (remote_bitbang_out
== NULL
) {
224 LOG_ERROR("fdopen: failed to open write stream");
228 LOG_INFO("remote_bitbang driver initialized");
232 static int remote_bitbang_init(void)
234 bitbang_interface
= &remote_bitbang_bitbang
;
236 LOG_INFO("Initializing remote_bitbang driver");
237 if (remote_bitbang_port
== NULL
)
238 return remote_bitbang_init_unix();
239 return remote_bitbang_init_tcp();
242 COMMAND_HANDLER(remote_bitbang_handle_remote_bitbang_port_command
)
246 COMMAND_PARSE_NUMBER(u16
, CMD_ARGV
[0], port
);
247 free(remote_bitbang_port
);
248 remote_bitbang_port
= port
== 0 ? NULL
: strdup(CMD_ARGV
[0]);
251 return ERROR_COMMAND_SYNTAX_ERROR
;
254 COMMAND_HANDLER(remote_bitbang_handle_remote_bitbang_host_command
)
257 free(remote_bitbang_host
);
258 remote_bitbang_host
= strdup(CMD_ARGV
[0]);
261 return ERROR_COMMAND_SYNTAX_ERROR
;
264 static const struct command_registration remote_bitbang_command_handlers
[] = {
266 .name
= "remote_bitbang_port",
267 .handler
= remote_bitbang_handle_remote_bitbang_port_command
,
268 .mode
= COMMAND_CONFIG
,
269 .help
= "Set the port to use to connect to the remote jtag.\n"
270 " if 0 or unset, use unix sockets to connect to the remote jtag.",
271 .usage
= "port_number",
274 .name
= "remote_bitbang_host",
275 .handler
= remote_bitbang_handle_remote_bitbang_host_command
,
276 .mode
= COMMAND_CONFIG
,
277 .help
= "Set the host to use to connect to the remote jtag.\n"
278 " if port is 0 or unset, this is the name of the unix socket to use.",
279 .usage
= "host_name",
281 COMMAND_REGISTRATION_DONE
,
284 struct jtag_interface remote_bitbang_interface
= {
285 .name
= "remote_bitbang",
286 .execute_queue
= &bitbang_execute_queue
,
287 .commands
= remote_bitbang_command_handlers
,
288 .init
= &remote_bitbang_init
,
289 .quit
= &remote_bitbang_quit
,
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)