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 int 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 (
unsigned 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 unsigned int cycles_remain = num_cycles;
464 const unsigned int cycles_one_batch =
sizeof(tms_bits) * 8;
470 while (cycles_remain > 0) {
471 nb_bits = (cycles_remain < cycles_one_batch) ? cycles_remain : cycles_one_batch;
494 cmd->cmd.runtest->end_state);
515 LOG_ERROR(
"BUG: unknown JTAG command type 0x%X",
529 sockfd = socket(AF_INET, SOCK_STREAM, 0);
531 LOG_ERROR(
"jtag_vpi: Could not create client socket");
545 if (
serv_addr.sin_addr.s_addr == INADDR_NONE) {
546 LOG_ERROR(
"jtag_vpi: inet_addr error occurred");
556 if (
serv_addr.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) {
560 setsockopt(
sockfd, IPPROTO_TCP, TCP_NODELAY, (
char *)&
flag,
sizeof(
int));
582 LOG_WARNING(
"jtag_vpi: failed to send \"stop simulation\" command");
585 LOG_WARNING(
"jtag_vpi: could not close jtag_vpi client socket");
628 .handler = &jtag_vpi_set_port,
630 .help =
"set the TCP port number of the jtag_vpi server (default: 5555)",
631 .usage =
"tcp_port_num",
634 .name =
"set_address",
635 .handler = &jtag_vpi_set_address,
637 .help =
"set the IP address of the jtag_vpi server (default: 127.0.0.1)",
638 .usage =
"ipv4_addr",
641 .name =
"stop_sim_on_exit",
642 .handler = &jtag_vpi_stop_sim_on_exit_handler,
644 .help =
"Configure if simulation stop command shall be sent "
645 "before OpenOCD exits (default: off)",
655 .help =
"perform jtag_vpi management",
const char *const jtag_only[]
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 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.
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(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_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 int jtag_vpi_execute_queue(struct jtag_command *cmd_queue)
static int jtag_vpi_runtest(unsigned int num_cycles, tap_state_t 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 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 ...)
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)