28 #define OPENDOUS_MAX_VIDS_PIDS 4
41 {
"usbprog-jtag", {0x1781, 0}, {0x0C63, 0}, 0x82, 0x02, 0x00, 510 },
42 {
"opendous", {0x1781, 0x03EB, 0}, {0xC0C0, 0x204F, 0}, 0x81, 0x02, 0x00, 360 },
43 {
"usbvlab", {0x16C0, 0}, {0x05DC, 0}, 0x81, 0x02, 0x01, 360 },
44 {
NULL, {0x0000}, {0x0000}, 0x00, 0x00, 0x00, 0 }
47 #define OPENDOUS_WRITE_ENDPOINT (opendous_probe->WRITE_EP)
48 #define OPENDOUS_READ_ENDPOINT (opendous_probe->READ_EP)
52 #define OPENDOUS_USB_TIMEOUT 1000
54 #define OPENDOUS_USB_BUFFER_SIZE (opendous_probe->BUFFERSIZE)
55 #define OPENDOUS_IN_BUFFER_SIZE (OPENDOUS_USB_BUFFER_SIZE)
56 #define OPENDOUS_OUT_BUFFER_SIZE (OPENDOUS_USB_BUFFER_SIZE)
64 #define OPENDOUS_MAX_SPEED 66
65 #define OPENDOUS_MAX_TAP_TRANSMIT ((opendous_probe->BUFFERSIZE)-10)
66 #define OPENDOUS_MAX_INPUT_DATA (OPENDOUS_MAX_TAP_TRANSMIT*4)
69 #define OPENDOUS_TAP_BUFFER_SIZE 65536
81 #define MAX_PENDING_SCAN_RESULTS (OPENDOUS_MAX_INPUT_DATA)
84 #define JTAG_CMD_TAP_OUTPUT 0x0
85 #define JTAG_CMD_SET_TRST 0x1
86 #define JTAG_CMD_SET_SRST 0x2
87 #define JTAG_CMD_READ_INPUT 0x3
88 #define JTAG_CMD_TAP_OUTPUT_EMU 0x4
89 #define JTAG_CMD_SET_DELAY 0x5
90 #define JTAG_CMD_SET_SRST_TRST 0x6
91 #define JTAG_CMD_READ_CONFIG 0x7
94 #define FUNC_START_BOOTLOADER 30
95 #define FUNC_WRITE_DATA 0x50
96 #define FUNC_READ_DATA 0x51
138 #ifdef _DEBUG_USB_COMMS_
139 static void opendous_debug_buffer(uint8_t *
buffer,
int length);
181 int request_version = atoi(
CMD_ARGV[0]);
182 switch (request_version) {
203 .
name =
"opendous_info",
204 .handler = &opendous_handle_opendous_info_command,
206 .help =
"show opendous info",
210 .name =
"opendous_hw_jtag",
211 .handler = &opendous_handle_opendous_hw_jtag_command,
213 .help =
"access opendous HW JTAG command version",
217 .name =
"opendous_type",
218 .handler = &opendous_handle_opendous_type_command,
220 .help =
"set opendous type",
221 .usage =
"[usbvlab|usbprog-jtag|opendous]",
251 LOG_DEBUG_IO(
"runtest %u cycles, end in %i",
cmd->cmd.runtest->num_cycles,
252 cmd->cmd.runtest->end_state);
254 if (
cmd->cmd.runtest->end_state != -1)
262 if (
cmd->cmd.statemove->end_state != -1)
269 cmd->cmd.pathmove->num_states,
270 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
278 if (
cmd->cmd.scan->end_state != -1)
284 #ifdef _DEBUG_USB_COMMS_
285 opendous_debug_buffer(
buffer, (scan_size + 7) / 8);
296 if (
cmd->cmd.reset->trst == 1)
308 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
325 LOG_WARNING(
"No opendous_type specified, using default 'opendous'");
328 while (cur_opendous_probe->
name) {
333 cur_opendous_probe++;
351 LOG_ERROR(
"Cannot find opendous Interface! Please check connection and permissions.");
356 while (check_cnt < 3) {
366 LOG_INFO(
"opendous JTAG Interface ready");
414 for (i = 0; i < tms_scan_bits; i++) {
415 tms = (tms_scan >> i) & 1;
424 for (
unsigned int i = 0; i < num_states; i++) {
430 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
452 for (
unsigned int i = 0; i < num_cycles; i++)
491 LOG_DEBUG(
"trst: %i, srst: %i", trst, srst);
557 if ((scans > available_scans) || (
bits > available_bits))
564 unsigned char _tms = tms ? 1 : 0;
565 unsigned char _tdi = tdi ? 1 : 0;
579 LOG_ERROR(
"opendous_tap_append_step, overflow");
594 for (i = 0; i <
length; i++)
607 #ifdef _DEBUG_USB_COMMS_
617 #ifdef _DEBUG_USB_COMMS_
619 LOG_DEBUG(
"opendous is sending %d bytes", byte_length);
622 for (j = 0, i = 0; j < byte_length;) {
625 int transmit = byte_length - j;
632 receive = (transmit + 1) / 2;
639 if (result != receive) {
640 LOG_ERROR(
"opendous_tap_execute, wrong result %d, expected %d", result, receive);
649 #ifdef _DEBUG_USB_COMMS_
650 LOG_DEBUG(
"opendous tap result %d", byte_length_out);
651 opendous_debug_buffer(
tdo_buffer, byte_length_out);
668 #ifdef _DEBUG_USB_COMMS_
669 opendous_debug_buffer(
buffer, byte_length_out);
693 struct libusb_device_handle *
devh;
698 libusb_claim_interface(
devh, 0);
700 result = malloc(
sizeof(*result));
717 if (result == out_length) {
719 if (result == in_length)
722 LOG_ERROR(
"usb_bulk_read failed (requested=%d, result=%d)", in_length, result);
726 LOG_ERROR(
"usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
734 int result, transferred;
741 #ifdef _DEBUG_USB_COMMS_
746 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
751 result = transferred;
756 #ifdef _DEBUG_USB_COMMS_
757 LOG_DEBUG(
"USB write end: %d bytes", result);
760 LOG_DEBUG_IO(
"opendous_usb_write, out_length = %d, result = %d", out_length, result);
762 #ifdef _DEBUG_USB_COMMS_
773 #ifdef _DEBUG_USB_COMMS_
779 LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN,
784 result = transferred;
789 #ifdef _DEBUG_USB_COMMS_
790 LOG_DEBUG(
"USB read end: %d bytes", result);
794 #ifdef _DEBUG_USB_COMMS_
800 #ifdef _DEBUG_USB_COMMS_
801 #define BYTES_PER_LINE 16
808 int n = snprintf(line, 9,
"%04x", i);
810 n += snprintf(line + n, 4,
" %02x",
buffer[j]);
const char *const jtag_only[]
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#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_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)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
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...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
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 tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
static struct jaylink_device_handle * devh
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_QUEUE_FAILED
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], const char *product, struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
int jtag_libusb_bulk_write(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_control_transfer(struct libusb_device_handle *dev, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, char *bytes, uint16_t size, unsigned int timeout, int *transferred)
int jtag_libusb_set_configuration(struct libusb_device_handle *devh, int configuration)
void jtag_libusb_close(struct libusb_device_handle *dev)
int jtag_libusb_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
#define JTAG_CMD_TAP_OUTPUT
static void opendous_tap_append_step(int tms, int tdi)
static int opendous_quit(void)
#define MAX_PENDING_SCAN_RESULTS
static void opendous_tap_init(void)
static void opendous_reset(int trst, int srst)
#define OPENDOUS_TAP_BUFFER_SIZE
static int opendous_usb_message(struct opendous_jtag *opendous_jtag, int out_length, int in_length)
static void opendous_path_move(unsigned int num_states, tap_state_t *path)
#define OPENDOUS_USB_TIMEOUT
static int opendous_get_version_info(void)
static int opendous_execute_queue(struct jtag_command *cmd_queue)
static int opendous_init(void)
static const struct opendous_probe * opendous_probe
static void opendous_runtest(unsigned int num_cycles)
static char * opendous_type
#define OPENDOUS_OUT_BUFFER_SIZE
static uint8_t tdo_buffer[OPENDOUS_TAP_BUFFER_SIZE]
static struct opendous_jtag * opendous_usb_open(void)
#define OPENDOUS_MAX_TAP_TRANSMIT
struct adapter_driver opendous_adapter_driver
static struct jtag_interface opendous_interface
static void opendous_end_state(tap_state_t state)
#define OPENDOUS_MAX_VIDS_PIDS
static int opendous_tap_execute(void)
static void opendous_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
COMMAND_HANDLER(opendous_handle_opendous_type_command)
static uint8_t * usb_out_buffer
#define JTAG_CMD_SET_SRST
#define JTAG_CMD_SET_TRST
#define OPENDOUS_IN_BUFFER_SIZE
static void opendous_usb_close(struct opendous_jtag *opendous_jtag)
#define OPENDOUS_WRITE_ENDPOINT
static const struct command_registration opendous_command_handlers[]
static void opendous_tap_ensure_space(int scans, int bits)
static int opendous_usb_write(struct opendous_jtag *opendous_jtag, int out_length)
static uint8_t tms_buffer[OPENDOUS_TAP_BUFFER_SIZE]
#define OPENDOUS_READ_ENDPOINT
static struct opendous_jtag * opendous_jtag_handle
static const struct opendous_probe opendous_probes[]
static struct pending_scan_result * pending_scan_results_buffer
static uint8_t * usb_in_buffer
static void opendous_simple_command(uint8_t command, uint8_t _data)
static void opendous_scan(int ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
static unsigned int opendous_hw_jtag_version
static int pending_scan_results_length
static int opendous_usb_read(struct opendous_jtag *opendous_jtag)
static int opendous_get_status(void)
static void opendous_state_move(void)
#define JTAG_CMD_SET_SRST_TRST
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
Represents a driver for a debugging interface.
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
struct libusb_device_handle * usb_handle
uint16_t PID[OPENDOUS_MAX_VIDS_PIDS]
uint16_t VID[OPENDOUS_MAX_VIDS_PIDS]
int first
First bit position in tdo_buffer to read.
int length
Number of bits to read.
uint8_t * buffer
Location to store the result.
struct scan_command * command
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...