17 #include <netinet/tcp.h>
25 #define REMOTE_BITBANG_HOST_MAX 255
102 if (block ==
BLOCK) {
110 unsigned int contiguous_available_space =
114 contiguous_available_space);
115 if (first && block ==
BLOCK)
121 }
else if (
count == 0) {
125 if (first && block ==
BLOCK) {
126 LOG_ERROR(
"remote_bitbang: socket closed by remote");
130 }
else if (
count < 0) {
132 if (WSAGetLastError() == WSAEWOULDBLOCK) {
134 if (errno == EAGAIN) {
175 LOG_INFO(
"remote_bitbang interface quit");
188 LOG_ERROR(
"remote_bitbang: invalid read response: %c(%i)", c, c);
216 char c =
'0' + ((tck ? 0x4 : 0x0) | (tms ? 0x2 : 0x0) | (tdi ? 0x1 : 0x0));
222 char c =
'r' + ((trst ? 0x2 : 0x0) | (srst ? 0x1 : 0x0));
236 unsigned int ms = microseconds / 1000;
237 unsigned int us = microseconds % 1000;
239 for (
unsigned int i = 0; i < ms; i++) {
245 for (
unsigned int i = 0; i < us; i++) {
256 char c = on ?
'B' :
'b';
262 char c = is_output ?
'O' :
'o';
264 LOG_ERROR(
"Error setting direction for swdio");
277 char c =
'd' + ((swclk ? 0x2 : 0x0) | (swdio ? 0x1 : 0x0));
296 struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
297 struct addrinfo *result, *rp;
307 LOG_ERROR(
"getaddrinfo: %s\n", gai_strerror(s));
316 for (rp = result; rp ; rp = rp->ai_next) {
317 fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
321 if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1)
332 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (
const char *)&one,
sizeof(one));
334 freeaddrinfo(result);
352 int fd = socket(PF_UNIX, SOCK_STREAM, 0);
358 struct sockaddr_un
addr;
359 addr.sun_family = AF_UNIX;
361 addr.sun_path[
sizeof(
addr.sun_path)-1] =
'\0';
363 if (connect(fd, (
struct sockaddr *)&
addr,
sizeof(
struct sockaddr_un)) < 0) {
378 LOG_INFO(
"Initializing remote_bitbang driver");
389 LOG_INFO(
"remote_bitbang driver initialized");
430 .handler = remote_bitbang_handle_remote_bitbang_port_command,
432 .help =
"Set the port to use to connect to the remote jtag.\n"
433 " if 0 or unset, use unix sockets to connect to the remote jtag.",
434 .usage =
"port_number",
438 .handler = remote_bitbang_handle_remote_bitbang_host_command,
440 .help =
"Set the host to use to connect to the remote jtag.\n"
441 " if port is 0 or unset, this is the name of the unix socket to use.",
442 .usage =
"host_name",
445 .name =
"use_remote_sleep",
446 .handler = remote_bitbang_handle_remote_bitbang_use_remote_sleep_command,
448 .help =
"Rather than executing sleep locally, include delays in the "
449 "instruction stream for the remote host.",
457 .
name =
"remote_bitbang",
459 .help =
"perform remote_bitbang management",
486 .
name =
"remote_bitbang",
int bitbang_execute_queue(struct jtag_command *cmd_queue)
const struct swd_driver bitbang_swd
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
#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 jtag_sleep(uint32_t us)
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 int remote_bitbang_swdio_read(void)
static const char *const remote_bitbang_transports[]
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 int remote_bitbang_execute_queue(struct jtag_command *cmd_queue)
static int remote_bitbang_swd_write(int swclk, int swdio)
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 int remote_bitbang_blink(bool on)
static void remote_bitbang_swdio_drive(bool is_output)
static unsigned int remote_bitbang_recv_buf_end
static bool remote_bitbang_recv_buf_full(void)
static int remote_bitbang_sleep(unsigned int microseconds)
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_write(int tck, int tms, int tdi)
static bool use_remote_sleep
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 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)
target_addr_t addr
Start address to search for the control block.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Low level callbacks (for bitbang).
int(* sleep)(unsigned int microseconds)
Sleep for some number of microseconds.
int(* swdio_read)(void)
Sample SWDIO and return the value.
int(* swd_write)(int swclk, int swdio)
Set SWCLK and SWDIO to the given value.
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(* flush)(void)
Force a flush.
int(* write)(int tck, int tms, int tdi)
Set TCK, TMS, and TDI to the given values.
void(* swdio_drive)(bool on)
Set direction of SWDIO.
int(* blink)(bool on)
Blink led (optional).
size_t buf_size
The number of TDO samples that can be buffered up before the caller has to call read_sample.
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.