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)
122 }
else if (
count == 0) {
124 }
else if (
count < 0) {
126 if (WSAGetLastError() == WSAEWOULDBLOCK) {
128 if (errno == EAGAIN) {
168 LOG_INFO(
"remote_bitbang interface quit");
181 LOG_ERROR(
"remote_bitbang: invalid read response: %c(%i)", c, c);
209 char c =
'0' + ((tck ? 0x4 : 0x0) | (tms ? 0x2 : 0x0) | (tdi ? 0x1 : 0x0));
215 char c =
'r' + ((trst ? 0x2 : 0x0) | (srst ? 0x1 : 0x0));
229 unsigned int ms = microseconds / 1000;
230 unsigned int us = microseconds % 1000;
232 for (
unsigned int i = 0; i < ms; i++) {
238 for (
unsigned int i = 0; i < us; i++) {
249 char c = on ?
'B' :
'b';
255 char c = is_output ?
'O' :
'o';
257 LOG_ERROR(
"Error setting direction for swdio");
270 char c =
'd' + ((swclk ? 0x2 : 0x0) | (swdio ? 0x1 : 0x0));
289 struct addrinfo hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
290 struct addrinfo *result, *rp;
300 LOG_ERROR(
"getaddrinfo: %s\n", gai_strerror(s));
309 for (rp = result; rp ; rp = rp->ai_next) {
310 fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
314 if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1)
325 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (
const char *)&one,
sizeof(one));
327 freeaddrinfo(result);
345 int fd = socket(PF_UNIX, SOCK_STREAM, 0);
351 struct sockaddr_un
addr;
352 addr.sun_family = AF_UNIX;
354 addr.sun_path[
sizeof(
addr.sun_path)-1] =
'\0';
356 if (connect(fd, (
struct sockaddr *)&
addr,
sizeof(
struct sockaddr_un)) < 0) {
371 LOG_INFO(
"Initializing remote_bitbang driver");
382 LOG_INFO(
"remote_bitbang driver initialized");
423 .handler = remote_bitbang_handle_remote_bitbang_port_command,
425 .help =
"Set the port to use to connect to the remote jtag.\n"
426 " if 0 or unset, use unix sockets to connect to the remote jtag.",
427 .usage =
"port_number",
431 .handler = remote_bitbang_handle_remote_bitbang_host_command,
433 .help =
"Set the host to use to connect to the remote jtag.\n"
434 " if port is 0 or unset, this is the name of the unix socket to use.",
435 .usage =
"host_name",
438 .name =
"use_remote_sleep",
439 .handler = remote_bitbang_handle_remote_bitbang_use_remote_sleep_command,
441 .help =
"Rather than executing sleep locally, include delays in the "
442 "instruction stream for the remote host.",
450 .
name =
"remote_bitbang",
452 .help =
"perform remote_bitbang management",
479 .
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 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_blink(int on)
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.
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)(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.