33 LOG_ERROR(
"BUG: sequences with zero length are not allowed");
98 #define OSBDM_USB_BUFSIZE 64
100 #define OSBDM_USB_TIMEOUT 1000
102 #define OSBDM_USB_EP_WRITE 0x01
104 #define OSBDM_USB_EP_READ 0x82
107 #define OSBDM_CMD_INIT 0x11
110 #define OSBDM_CMD_SPECIAL 0x27
112 #define OSBDM_CMD_SPECIAL_SWAP 0x05
114 #define OSBDM_CMD_SPECIAL_SRST 0x01
116 #define OSBDM_SWAP_MAX (((OSBDM_USB_BUFSIZE - 6) / 5) * 16)
120 static const uint16_t
osbdm_vid[] = { 0x15a2, 0x15a2, 0x15a2, 0 };
121 static const uint16_t
osbdm_pid[] = { 0x0042, 0x0058, 0x005e, 0 };
124 struct libusb_device_handle *
devh;
142 LOG_ERROR(
"OSBDM communication error: can't write");
156 LOG_ERROR(
"OSBDM communication error: can't read");
161 LOG_ERROR(
"OSBDM communication error: reply too small");
166 LOG_ERROR(
"OSBDM communication error: reply size mismatch");
171 LOG_ERROR(
"OSBDM communication error: reply command mismatch");
210 LOG_ERROR(
"BUG: bit sequence equal or less than 0");
232 for (
int bit_idx = 0; bit_idx <
length; ) {
234 int bit_count =
length - bit_idx;
241 uint32_t tms_data =
buf_get_u32(tms, bit_idx, bit_count);
242 uint32_t tdi_data =
buf_get_u32(tdi, bit_idx, bit_count);
249 bit_idx += bit_count;
262 LOG_ERROR(
"OSBDM communication error: invalid swap command reply");
269 for (
int bit_idx = 0; bit_idx <
length; ) {
270 int bit_count =
length - bit_idx;
275 uint32_t tdo_data = 0;
276 tdo_data |= (*
buffer++) << 8;
278 tdo_data >>= (16 - bit_count);
283 bit_idx += bit_count;
295 int seq_back_len = 0;
298 (void)memset(tms, 0,
sizeof(tms));
299 (void)memset(tdi, 0,
sizeof(tdi));
300 (void)memset(tdo, 0,
sizeof(tdo));
309 seq_len = seq_back_len;
317 int len = seq->
len - seq_len;
330 if (seq_len == seq->
len) {
342 for (
int swap_back_len = 0; swap_back_len < swap_len; ) {
344 if (
len > swap_len - swap_back_len)
345 len = swap_len - swap_back_len;
350 swap_back_len +=
len;
384 unsigned int num_states)
386 assert(num_states <= 32);
390 LOG_ERROR(
"BUG: can't allocate bit sequence");
395 for (
unsigned int i = 0; i < num_states; i++) {
401 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP state transition",
434 if (
len && skip_first) {
442 LOG_ERROR(
"BUG: can't allocate bit sequence");
457 LOG_ERROR(
"BUG: current state (%s) is not stable",
464 LOG_ERROR(
"BUG: can't allocate bit sequence");
481 LOG_ERROR(
"BUG: can't allocate bit sequence");
492 unsigned int num_fields,
511 for (
unsigned int idx = 0; idx < num_fields; idx++) {
514 LOG_ERROR(
"Can't allocate bit sequence");
539 unsigned int num_cycles,
563 if (
cmd->cmd.reset->trst) {
564 LOG_ERROR(
"BUG: nTRST signal is not supported");
576 cmd->cmd.pathmove->path,
577 cmd->cmd.pathmove->num_states);
583 cmd->cmd.statemove->end_state,
590 cmd->cmd.stableclocks->num_cycles);
597 cmd->cmd.tms->num_bits);
603 cmd->cmd.scan->fields,
604 cmd->cmd.scan->num_fields,
605 cmd->cmd.scan->end_state,
606 cmd->cmd.scan->ir_scan);
618 cmd->cmd.runtest->num_cycles,
619 cmd->cmd.runtest->end_state);
623 LOG_ERROR(
"BUG: unknown JTAG command type encountered");
637 LOG_ERROR(
"BUG: can't allocate bit queue");
654 LOG_ERROR(
"FATAL: can't execute jtag command");
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)
Support functions to access arbitrary bits in a byte array.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
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.
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...
void jtag_sleep(uint32_t us)
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)
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_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
static struct osbdm osbdm_context
static int osbdm_add_pathmove(struct queue *queue, tap_state_t *path, unsigned int num_states)
#define OSBDM_USB_EP_READ
static int osbdm_flush(struct osbdm *osbdm, struct queue *queue)
static struct sequence * queue_add_tail(struct queue *queue, int len)
#define OSBDM_USB_BUFSIZE
static const uint16_t osbdm_pid[]
static int osbdm_init(void)
struct adapter_driver osbdm_adapter_driver
static int osbdm_add_tms(struct queue *queue, const uint8_t *tms, int num_bits)
static void queue_free(struct queue *queue)
static int osbdm_add_stableclocks(struct queue *queue, unsigned int count)
static int osbdm_open(struct osbdm *osbdm)
static int osbdm_send_and_recv(struct osbdm *osbdm)
#define OSBDM_CMD_SPECIAL
static void queue_drop_head(struct queue *queue)
static int osbdm_execute_command(struct osbdm *osbdm, struct queue *queue, struct jtag_command *cmd)
static struct queue * queue_alloc(void)
#define OSBDM_USB_TIMEOUT
#define OSBDM_USB_EP_WRITE
static int osbdm_quit(void)
static int osbdm_add_runtest(struct queue *queue, unsigned int num_cycles, tap_state_t end_state)
static int osbdm_add_statemove(struct queue *queue, tap_state_t new_state, int skip_first)
static struct jtag_interface osbdm_interface
static int osbdm_srst(struct osbdm *osbdm, int srst)
static int osbdm_add_scan(struct queue *queue, struct scan_field *fields, unsigned int num_fields, tap_state_t end_state, bool ir_scan)
#define OSBDM_CMD_SPECIAL_SRST
#define OSBDM_CMD_SPECIAL_SWAP
static const uint16_t osbdm_vid[]
static int osbdm_execute_queue(struct jtag_command *cmd_queue)
static int osbdm_swap(struct osbdm *osbdm, void *tms, void *tdi, void *tdo, int length)
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 * devh
uint8_t buffer[OSBDM_USB_BUFSIZE]
This structure defines a single scan field in the scan.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.