17 #ifdef HAVE_ARPA_INET_H
18 #include <arpa/inet.h>
22 #include <netinet/tcp.h>
27 #define NO_TAP_SHIFT 0
30 #define DEFAULT_SERVER_ADDRESS "127.0.0.1"
31 #define DEFAULT_SERVER_PORT 5555
33 #define XFERT_MAX_SIZE 512
37 #define CMD_SCAN_CHAIN 2
38 #define CMD_SCAN_CHAIN_FLIP_TMS 3
39 #define CMD_STOP_SIMU 4
77 return "CMD_SCAN_CHAIN";
79 return "CMD_SCAN_CHAIN_FLIP_TMS";
81 return "CMD_STOP_SIMU";
100 "length=%" PRIu32
", "
101 "nb_bits=%" PRIu32
", "
112 "length=%" PRIu32
", "
134 int wsa_err = WSAGetLastError();
135 if (wsa_err == WSAEINTR)
147 }
else if (retval < (
int)
sizeof(
struct vpi_cmd)) {
151 LOG_ERROR(
"jtag_vpi: Could not send all data through jtag_vpi connection.");
161 unsigned bytes_buffered = 0;
162 while (bytes_buffered <
sizeof(
struct vpi_cmd)) {
163 int bytes_to_receive =
sizeof(
struct vpi_cmd) - bytes_buffered;
164 int retval =
read_socket(
sockfd, ((
char *)vpi) + bytes_buffered, bytes_to_receive);
167 int wsa_err = WSAGetLastError();
168 if (wsa_err == WSAEINTR) {
173 if (errno == EINTR) {
181 }
else if (retval == 0) {
183 LOG_ERROR(
"Connection prematurely closed by jtag_vpi server.");
187 bytes_buffered += retval;
206 memset(&vpi, 0,
sizeof(
struct vpi_cmd));
229 memset(&vpi, 0,
sizeof(
struct vpi_cmd));
257 for (
int i = 0; i <
cmd->num_states; i++) {
297 memset(&vpi, 0,
sizeof(
struct vpi_cmd));
321 LOG_DEBUG_IO(
"recvd JTAG VPI data: nb_bits=%d, buf_in=0x%s%s",
371 const uint8_t tms_0 = 0;
372 const uint8_t tms_1 = 1;
461 int cycles_remain = cycles;
464 const 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",
531 sockfd = socket(AF_INET, SOCK_STREAM, 0);
533 LOG_ERROR(
"jtag_vpi: Could not create client socket");
547 if (
serv_addr.sin_addr.s_addr == INADDR_NONE) {
548 LOG_ERROR(
"jtag_vpi: inet_addr error occurred");
558 if (
serv_addr.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) {
562 setsockopt(
sockfd, IPPROTO_TCP, TCP_NODELAY, (
char *)&
flag,
sizeof(
int));
584 LOG_WARNING(
"jtag_vpi: failed to send \"stop simulation\" command");
587 LOG_WARNING(
"jtag_vpi: could not close jtag_vpi client socket");
597 LOG_ERROR(
"Command \"jtag_vpi set_port\" expects 1 argument (TCP port number)");
611 LOG_ERROR(
"Command \"jtag_vpi set_address\" expects 1 argument (IP address)");
625 LOG_ERROR(
"Command \"jtag_vpi stop_sim_on_exit\" expects 1 argument (on|off)");
636 .handler = &jtag_vpi_set_port,
638 .help =
"set the TCP port number of the jtag_vpi server (default: 5555)",
639 .usage =
"tcp_port_num",
642 .name =
"set_address",
643 .handler = &jtag_vpi_set_address,
645 .help =
"set the IP address of the jtag_vpi server (default: 127.0.0.1)",
646 .usage =
"ipv4_addr",
649 .name =
"stop_sim_on_exit",
650 .handler = &jtag_vpi_stop_sim_on_exit_handler,
652 .help =
"Configure if simulation stop command shall be sent "
653 "before OpenOCD exits (default: off)",
663 .help =
"perform jtag_vpi management",
const char *const jtag_only[]
char * buf_to_hex_str(const void *_buf, unsigned buf_len)
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned 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 ERROR_COMMAND_CLOSE_CONNECTION
#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.
struct jtag_command * jtag_command_queue
The current queue of jtag_command_s structures.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
tap_state_t tap_state_transition(tap_state_t 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(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#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)
enum tap_state tap_state_t
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(int 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_runtest(int cycles, tap_state_t state)
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_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 struct jtag_interface jtag_vpi_interface
static char * jtag_vpi_cmd_to_str(int cmd_num)
static int jtag_vpi_execute_queue(void)
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 struct sockaddr_in serv_addr
static const struct command_registration jtag_vpi_subcommand_handlers[]
static bool stop_sim_on_exit
static int jtag_vpi_state_move(tap_state_t state)
#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 ...)
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 supported
Bit vector listing capabilities exposed by this driver.
The scan_command provide a means of encapsulating a set of scan_field_s structures that should be sca...
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)