19 #include <netinet/tcp.h>
68 #define MAX_BUF_SIZE (BIT(31) - 11)
69 #define MAX_SHIFT_RESULTS 256
97 static int xvc_khz(
int khz,
int *jtag_speed)
106 unsigned int i =
size;
110 LOG_ERROR(
"No data available in socket at %s", __func__);
114 LOG_ERROR(
"Reading error in %s", __func__);
128 LOG_DEBUG(
"XVC flush: no bits to flush");
135 const char *shift =
"shift:";
136 size_t shift_len = strlen(shift);
137 size_t cp_offset = 0;
141 cp_offset += shift_len;
147 cp_offset += number_of_bytes;
150 cp_offset += number_of_bytes;
152 LOG_DEBUG(
"XVC flush: cp_offset: %zu", cp_offset);
156 if (written != (
int)cp_offset) {
157 LOG_ERROR(
"Error writing socket in %s", __func__);
169 static int xvc_queue(
const uint8_t *tms,
unsigned int tms_offset,
const uint8_t *tdi,
170 unsigned int tdi_offset, uint8_t *tdo,
unsigned int tdo_offset,
unsigned int length)
173 unsigned int available_length =
182 unsigned int scan_length =
196 tdi_offset += scan_length;
197 tms_offset += scan_length;
198 tdo_offset += scan_length;
207 const char *getinfo =
"getinfo:";
208 size_t len = strlen(getinfo);
211 if (written != (
int)len) {
222 char info_recv_buf[26] = {0};
224 unsigned long idx = 0;
225 while (idx <
sizeof(info_recv_buf) - 1) {
231 if (info_recv_buf[idx] ==
'\n')
235 info_recv_buf[idx] =
'\0';
237 if (strncmp(info_recv_buf,
"xvcServer_v1.0:", 15) != 0 &&
238 strncmp(info_recv_buf,
"xvcServer_v1.1:", 15) != 0) {
239 LOG_ERROR(
"Unexpected response from XVC server_ %s", info_recv_buf);
242 LOG_INFO(
"XVC HW server version: %s", info_recv_buf);
245 LOG_DEBUG(
"Exceeded maximum vector size, outputting to %lu bytes",
276 const char *header =
"settck:";
277 memcpy(set_tck, header, strlen(header));
284 uint32_t tck_recv_buf;
291 uint32_t xvc_tck_period_ns;
292 xvc_tck_period_ns =
le_to_h_u32((uint8_t *)&tck_recv_buf);
293 LOG_INFO(
"XVC tck period ns: %u", xvc_tck_period_ns);
316 static bool first_time =
true;
318 LOG_WARNING(
"Adapter has no reset lines. Fix \"reset_config\" command in "
329 const struct addrinfo hints = {
330 .ai_family = AF_UNSPEC,
331 .ai_socktype = SOCK_STREAM
334 struct addrinfo *result;
338 LOG_ERROR(
"getaddrinfo: %s", gai_strerror(s));
347 for (rp = result; rp; rp = rp->ai_next) {
348 *fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
353 if (*fd == (
int)INVALID_SOCKET)
356 if (connect(*fd, rp->ai_addr, rp->ai_addrlen) != -1)
362 freeaddrinfo(result);
374 setsockopt(*fd, IPPROTO_TCP, TCP_NODELAY, (
const char *)&one,
sizeof(one));
387 *fd = socket(PF_UNIX, SOCK_STREAM, 0);
393 struct sockaddr_un
addr;
394 addr.sun_family = AF_UNIX;
396 addr.sun_path[
sizeof(
addr.sun_path) - 1] =
'\0';
398 if (connect(*fd, (
struct sockaddr *)&
addr,
sizeof(
struct sockaddr_un)) < 0) {
430 .handler = xvc_handle_port_command,
433 "Set the port to use to connect to the XVC remote server.\n"
434 " If 0 or unset, use unix sockets to connect to the remote server.",
435 .usage =
"port_number",
439 .handler = xvc_handle_host_command,
441 .help =
"Set the host to use or UNIX socket to connect to the remote XVC server.",
442 .usage =
"host_name",
451 .help =
"perform XVC driver configuration",
529 unsigned int num_bits =
cmd->cmd.tms->num_bits;
530 const uint8_t *
bits =
cmd->cmd.tms->bits;
534 for (
unsigned int i = 0; i < num_bits; i++) {
536 tms = ((
bits[i / 8] >> (i % 8)) & 1);
546 unsigned int num_states =
cmd->num_states;
547 unsigned int state_count = 0;
554 cmd->path[state_count]) {
557 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
576 for (
unsigned int i = 0; i < num_cycles; i++)
608 while (
cmd->num_fields > 0 &&
cmd->fields[
cmd->num_fields - 1].num_bits == 0) {
610 LOG_DEBUG(
"discarding trailing empty field");
612 if (
cmd->num_fields == 0) {
617 bool ir_scan =
cmd->ir_scan;
631 for (
unsigned int i = 0; i <
cmd->num_fields; i++) {
636 cmd->fields[i].num_bits - 1);
638 uint8_t last_bit = 0;
639 if (
cmd->fields[i].out_value)
641 cmd->fields[i].num_bits - 1, 1);
643 uint8_t tms_bits = 0x01;
644 xvc_queue(&tms_bits, 0, &last_bit, 0,
cmd->fields[i].in_value,
645 cmd->fields[i].num_bits - 1, 1);
651 cmd->fields[i].num_bits);
674 LOG_DEBUG_IO(
"runtest %i cycles, end in %s",
cmd->cmd.runtest->num_cycles,
696 cmd->cmd.pathmove->num_states,
716 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
static void bit_copy(uint8_t *dst, unsigned int dst_offset, const uint8_t *src, unsigned int src_offset, unsigned int bit_count)
#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.
uint32_t size
Size of dw_spi_transaction::buffer.
enum tap_state tap_get_end_state(void)
For more information,.
enum tap_state tap_state_transition(enum tap_state cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
const char * tap_state_name(enum tap_state state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
int tap_get_tms_path_len(enum tap_state from, enum tap_state to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
void tap_set_end_state(enum tap_state new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
enum tap_state tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
bool tap_is_state_stable(enum tap_state astate)
Function tap_is_state_stable returns true if the astate is stable.
int tap_get_tms_path(enum tap_state from, enum tap_state to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
#define DEBUG_CAP_TMS_SEQ
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
void jtag_sleep(uint32_t us)
tap_state
Defines JTAG Test Access Port states.
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
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)
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.
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.
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
unsigned int buffer_offset
static void h_u32_to_le(uint8_t *buf, uint32_t val)
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static uint32_t le_to_h_u32(const uint8_t *buf)
static int xvc_tap_path_move(struct pathmove_command *cmd)
static int xvc_init_tcp(int *fd)
static int xvc_reset(int trst, int srst)
static uint8_t * xvc_tms_buf
static int xvc_quit(void)
static struct jtag_interface xvc_interface
static unsigned int xvc_max_usable_vector_size
static int xvc_khz(int khz, int *jtag_speed)
static int xvc_tap_execute_queue(struct jtag_command *cmd_queue)
static int xvc_getinfo(void)
static int xvc_tap_execute_tms(struct jtag_command *cmd)
static int xvc_queue(const uint8_t *tms, unsigned int tms_offset, const uint8_t *tdi, unsigned int tdi_offset, uint8_t *tdo, unsigned int tdo_offset, unsigned int length)
static uint8_t * xvc_tdo_buf
static unsigned int xvc_max_vector_size
static int xvc_speed_div(int speed, int *khz)
static struct shift_result shift_result_buffer[MAX_SHIFT_RESULTS]
static const struct command_registration xvc_command_handlers[]
COMMAND_HANDLER(xvc_handle_port_command)
static int xvc_init(void)
static uint8_t * xvc_send_buf
static int xvc_init_unix(int *fd)
static int xvc_speed(int speed)
static uint8_t * xvc_tdi_buf
static unsigned int xvc_tap_stableclocks(unsigned int num_cycles)
static int xvc_tap_runtest(unsigned int num_cycles)
static int read_frame(int sock_id, unsigned char *ptr, unsigned int size)
static void xvc_tap_end_state(enum tap_state state)
static int xvc_fill_buffer(void)
struct adapter_driver xvc_adapter_driver
static int xvc_tap_state_move(int skip)
#define MAX_SHIFT_RESULTS
static int xvc_tap_scan_write(struct scan_command *cmd)
static uint32_t xvc_used_bits
static int xvc_flush(void)
static unsigned int pending_shift_results
static unsigned int xvc_bits_to_bytes(unsigned int bits)
static unsigned int last_used_bits
static int xvc_set_tck(void)
static const struct command_registration xvc_subcommand_handlers[]