15 #include <netinet/tcp.h>
23 #define REMOTE_BITBANG_HOST_MAX 255
106 unsigned int contiguous_available_space =
110 contiguous_available_space);
111 if (first && block ==
BLOCK)
118 }
else if (
count == 0) {
120 }
else if (
count < 0) {
122 if (WSAGetLastError() == WSAEWOULDBLOCK) {
124 if (errno == EAGAIN) {
164 LOG_INFO(
"remote_bitbang interface quit");
177 LOG_ERROR(
"remote_bitbang: invalid read response: %c(%i)", c, c);
205 char c =
'0' + ((tck ? 0x4 : 0x0) | (tms ? 0x2 : 0x0) | (tdi ? 0x1 : 0x0));
211 char c =
'r' + ((trst ? 0x2 : 0x0) | (srst ? 0x1 : 0x0));
219 char c = on ?
'B' :
'b';
233 struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
234 struct addrinfo *result, *rp;
244 LOG_ERROR(
"getaddrinfo: %s\n", gai_strerror(s));
253 for (rp = result; rp ; rp = rp->ai_next) {
254 fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
258 if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1)
269 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (
const char *)&one,
sizeof(one));
271 freeaddrinfo(result);
289 int fd = socket(PF_UNIX, SOCK_STREAM, 0);
295 struct sockaddr_un
addr;
296 addr.sun_family = AF_UNIX;
298 addr.sun_path[
sizeof(
addr.sun_path)-1] =
'\0';
300 if (connect(fd, (
struct sockaddr *)&
addr,
sizeof(
struct sockaddr_un)) < 0) {
315 LOG_INFO(
"Initializing remote_bitbang driver");
326 LOG_INFO(
"remote_bitbang driver initialized");
355 .handler = remote_bitbang_handle_remote_bitbang_port_command,
357 .help =
"Set the port to use to connect to the remote jtag.\n"
358 " if 0 or unset, use unix sockets to connect to the remote jtag.",
359 .usage =
"port_number",
363 .handler = remote_bitbang_handle_remote_bitbang_host_command,
365 .help =
"Set the host to use to connect to the remote jtag.\n"
366 " if port is 0 or unset, this is the name of the unix socket to use.",
367 .usage =
"host_name",
374 .
name =
"remote_bitbang",
376 .help =
"perform remote_bitbang management",
403 .
name =
"remote_bitbang",
const char *const jtag_only[]
int bitbang_execute_queue(void)
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
void log_socket_error(const char *socket_desc)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
static int remote_bitbang_queue(int c, flush_bool_t flush)
static char remote_bitbang_recv_buf[256]
static int remote_bitbang_init_tcp(void)
static int remote_bitbang_sample(void)
static const struct command_registration remote_bitbang_subcommand_handlers[]
static bool remote_bitbang_recv_buf_empty(void)
static struct bitbang_interface remote_bitbang_bitbang
static unsigned int remote_bitbang_recv_buf_contiguous_available_space(void)
static uint8_t remote_bitbang_send_buf[512]
static int remote_bitbang_fill_buf(enum block_bool block)
static int remote_bitbang_init(void)
static struct jtag_interface remote_bitbang_interface
static unsigned int remote_bitbang_recv_buf_end
static bool remote_bitbang_recv_buf_full(void)
static int remote_bitbang_init_unix(void)
static int remote_bitbang_reset(int trst, int srst)
static const struct command_registration remote_bitbang_command_handlers[]
static unsigned int remote_bitbang_recv_buf_start
static bb_value_t char_to_int(int c)
static int remote_bitbang_quit(void)
static bb_value_t remote_bitbang_read_sample(void)
static int remote_bitbang_blink(int on)
static int remote_bitbang_write(int tck, int tms, int tdi)
COMMAND_HANDLER(remote_bitbang_handle_remote_bitbang_port_command)
static int remote_bitbang_flush(void)
static char * remote_bitbang_port
static int remote_bitbang_fd
static unsigned int remote_bitbang_send_buf_used
static int remote_bitbang_execute_queue(void)
static char * remote_bitbang_host
struct adapter_driver remote_bitbang_adapter_driver
static void socket_block(int fd)
static int read_socket(int handle, void *buffer, unsigned int count)
static int close_socket(int sock)
static int write_socket(int handle, const void *buffer, unsigned int count)
static void socket_nonblock(int fd)
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Low level callbacks (for bitbang).
int(* sample)(void)
Sample TDO and put the result in a buffer.
bb_value_t(* read_sample)(void)
Return the next unread value from the buffer.
int(* write)(int tck, int tms, int tdi)
Set TCK, TMS, and TDI to the given values.
size_t buf_size
The number of TDO samples that can be buffered up before the caller has to call read_sample.
int(* blink)(int on)
Blink led (optional).
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
int(* execute_queue)(void)
Execute queued commands.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.