20 #ifdef HAVE_ARPA_INET_H
21 #include <arpa/inet.h>
25 #include <netinet/tcp.h>
30 #define NO_TAP_SHIFT 0
33 #define DEFAULT_SERVER_ADDRESS "127.0.0.1"
34 #define DEFAULT_SERVER_PORT 5555
36 #define XFERT_MAX_SIZE 512
40 #define CMD_SCAN_CHAIN 2
41 #define CMD_SCAN_CHAIN_FLIP_TMS 3
42 #define CMD_STOP_SIMU 4
79 return "CMD_SCAN_CHAIN";
81 return "CMD_SCAN_CHAIN_FLIP_TMS";
83 return "CMD_STOP_SIMU";
102 "length=%" PRIu32
", "
103 "nb_bits=%" PRIu32
", "
114 "length=%" PRIu32
", "
136 int wsa_err = WSAGetLastError();
137 if (wsa_err == WSAEINTR)
149 }
else if (retval < (
int)
sizeof(
struct vpi_cmd)) {
153 LOG_ERROR(
"jtag_vpi: Could not send all data through jtag_vpi connection.");
163 unsigned int bytes_buffered = 0;
164 while (bytes_buffered <
sizeof(
struct vpi_cmd)) {
165 int bytes_to_receive =
sizeof(
struct vpi_cmd) - bytes_buffered;
166 int retval =
read_socket(
sockfd, ((
char *)vpi) + bytes_buffered, bytes_to_receive);
169 int wsa_err = WSAGetLastError();
170 if (wsa_err == WSAEINTR) {
175 if (errno == EINTR) {
183 }
else if (retval == 0) {
185 LOG_ERROR(
"Connection prematurely closed by jtag_vpi server.");
189 bytes_buffered += retval;
208 memset(&vpi, 0,
sizeof(
struct vpi_cmd));
231 memset(&vpi, 0,
sizeof(
struct vpi_cmd));
259 for (
unsigned int i = 0; i <
cmd->num_states; i++) {
299 memset(&vpi, 0,
sizeof(
struct vpi_cmd));
323 LOG_DEBUG_IO(
"recvd JTAG VPI data: nb_bits=%d, buf_in=0x%s%s",
373 const uint8_t tms_0 = 0;
374 const uint8_t tms_1 = 1;
463 unsigned int cycles_remain = num_cycles;
466 const unsigned int cycles_one_batch =
sizeof(tms_bits) * 8;
472 while (cycles_remain > 0) {
473 nb_bits = (cycles_remain < cycles_one_batch) ? cycles_remain : cycles_one_batch;
496 cmd->cmd.runtest->end_state);
517 LOG_ERROR(
"BUG: unknown JTAG command type 0x%X",
532 const struct addrinfo hints = {
533 .ai_family = AF_UNSPEC,
534 .ai_socktype = SOCK_STREAM
537 char port_str[5 + 1];
538 snprintf(port_str,
sizeof(port_str),
"%" PRIu16,
server_port);
540 struct addrinfo *result;
544 LOG_ERROR(
"getaddrinfo: %s", gai_strerror(ret));
549 for (rp = result; rp ; rp = rp->ai_next) {
550 sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
554 if (connect(
sockfd, rp->ai_addr, rp->ai_addrlen) != -1)
561 LOG_ERROR(
"jtag_vpi: Can't connect to %s : %" PRIu16,
563 freeaddrinfo(result);
567 bool is_loopback =
false;
568 if (rp->ai_family == AF_INET) {
569 struct sockaddr_in sa;
570 memcpy(&sa, rp->ai_addr,
sizeof(sa));
571 is_loopback = (sa.sin_addr.s_addr == htonl(INADDR_LOOPBACK));
572 }
else if (rp->ai_family == AF_INET6) {
573 struct sockaddr_in6 sa;
574 memcpy(&sa, rp->ai_addr,
sizeof(sa));
575 is_loopback = IN6_IS_ADDR_LOOPBACK(&sa.sin6_addr);
582 LOG_DEBUG(
"Enabling TCP_NODELAY to enhance the speed of local connections");
585 setsockopt(
sockfd, IPPROTO_TCP, TCP_NODELAY, (
char *)&
flag,
589 freeaddrinfo(result);
591 LOG_INFO(
"jtag_vpi: Connection to %s : %" PRIu16
" successful",
611 LOG_WARNING(
"jtag_vpi: failed to send \"stop simulation\" command");
614 LOG_WARNING(
"jtag_vpi: could not close jtag_vpi client socket");
657 .handler = &jtag_vpi_set_port,
659 .help =
"set the TCP port number of the jtag_vpi server (default: 5555)",
660 .usage =
"tcp_port_num",
663 .name =
"set_address",
664 .handler = &jtag_vpi_set_address,
666 .help =
"set the hostname or IP address of the jtag_vpi server (default: 127.0.0.1)",
667 .usage =
"ipv4_addr",
670 .name =
"stop_sim_on_exit",
671 .handler = &jtag_vpi_stop_sim_on_exit_handler,
673 .help =
"Configure if simulation stop command shall be sent "
674 "before OpenOCD exits (default: off)",
684 .help =
"perform jtag_vpi management",
char * buf_to_hex_str(const void *_buf, unsigned int buf_len)
static void buf_set_u32(uint8_t *_buffer, unsigned int first, unsigned int num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
#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.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
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...
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...
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 ...
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.
static int jtag_vpi_init(void)
#define CMD_SCAN_CHAIN_FLIP_TMS
static int jtag_vpi_tms(struct tms_command *cmd)
jtag_vpi_tms - ask a tms command
struct adapter_driver jtag_vpi_adapter_driver
static int jtag_vpi_stableclocks(unsigned int num_cycles)
static int jtag_vpi_scan(struct scan_command *cmd)
jtag_vpi_scan - launches a DR-scan or IR-scan
static int jtag_vpi_send_cmd(struct vpi_cmd *vpi)
static int jtag_vpi_queue_tdi(uint8_t *bits, int nb_bits, int tap_shift)
jtag_vpi_queue_tdi - short description
static int jtag_vpi_runtest(unsigned int num_cycles, enum tap_state state)
static int jtag_vpi_tms_seq(const uint8_t *bits, int nb_bits)
jtag_vpi_tms_seq - ask a TMS sequence transition to JTAG
static const struct command_registration jtag_vpi_command_handlers[]
static uint16_t server_port
static struct jtag_interface jtag_vpi_interface
static int jtag_vpi_execute_queue(struct jtag_command *cmd_queue)
static int jtag_vpi_state_move(enum tap_state state)
static char * jtag_vpi_cmd_to_str(int cmd_num)
static int jtag_vpi_reset(int trst, int srst)
jtag_vpi_reset - ask to reset the JTAG device
#define DEFAULT_SERVER_ADDRESS
static int jtag_vpi_receive_cmd(struct vpi_cmd *vpi)
static int jtag_vpi_queue_tdi_xfer(uint8_t *bits, int nb_bits, int tap_shift)
static int jtag_vpi_quit(void)
static int jtag_vpi_clock_tms(int tms)
jtag_vpi_clock_tms - clock a TMS transition
COMMAND_HANDLER(jtag_vpi_set_port)
static int jtag_vpi_stop_simulation(void)
static int jtag_vpi_path_move(struct pathmove_command *cmd)
jtag_vpi_path_move - ask a TMS sequence transition to JTAG
static const struct command_registration jtag_vpi_subcommand_handlers[]
static bool stop_sim_on_exit
#define DEFAULT_SERVER_PORT
static char * server_address
void log_socket_error(const char *socket_desc)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_LEVEL_IS(FOO)
#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)
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.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
Encapsulates a series of bits to be clocked out, affecting state and mode of the interface.
unsigned char nb_bits_buf[4]
unsigned char buffer_in[XFERT_MAX_SIZE]
unsigned char length_buf[4]
unsigned char buffer_out[XFERT_MAX_SIZE]
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)