OpenOCD
opendous.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * *
5  * Copyright (C) 2009 by Cahya Wirawan <cahya@gmx.at> *
6  * Based on opendous driver by Vladimir Fonov *
7  * *
8  * Copyright (C) 2009 by Vladimir Fonov <vladimir.fonov@gmai.com> *
9  * Based on J-link driver by Juergen Stuber *
10  * *
11  * Copyright (C) 2007 by Juergen Stuber <juergen@jstuber.net> *
12  * based on Dominic Rath's and Benedikt Sauter's usbprog.c *
13  * *
14  * Copyright (C) 2008 by Spencer Oliver *
15  * spen@spen-soft.co.uk *
16  ***************************************************************************/
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include <jtag/interface.h>
23 #include <jtag/commands.h>
24 #include "libusb_helper.h"
25 #include <string.h>
26 #include <time.h>
27 
28 #define OPENDOUS_MAX_VIDS_PIDS 4
29 /* define some probes with similar interface */
31  const char *name;
34  uint8_t READ_EP;
35  uint8_t WRITE_EP;
38 };
39 
40 static const struct opendous_probe opendous_probes[] = {
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 }
45 };
46 
47 #define OPENDOUS_WRITE_ENDPOINT (opendous_probe->WRITE_EP)
48 #define OPENDOUS_READ_ENDPOINT (opendous_probe->READ_EP)
49 
50 static unsigned int opendous_hw_jtag_version = 1;
51 
52 #define OPENDOUS_USB_TIMEOUT 1000
53 
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)
57 
58 /* Global USB buffers */
59 static uint8_t *usb_in_buffer;
60 static uint8_t *usb_out_buffer;
61 
62 /* Constants for OPENDOUS command */
63 
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)
67 
68 /* TAP */
69 #define OPENDOUS_TAP_BUFFER_SIZE 65536
70 
71 struct pending_scan_result {
72  int first; /* First bit position in tdo_buffer to read */
73  int length; /* Number of bits to read */
74  struct scan_command *command; /* Corresponding scan command */
75  uint8_t *buffer;
76 };
77 
80 
81 #define MAX_PENDING_SCAN_RESULTS (OPENDOUS_MAX_INPUT_DATA)
82 
83 /* JTAG usb commands */
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
92 
93 /* usbvlab control transfer */
94 #define FUNC_START_BOOTLOADER 30
95 #define FUNC_WRITE_DATA 0x50
96 #define FUNC_READ_DATA 0x51
97 
98 static char *opendous_type;
99 static const struct opendous_probe *opendous_probe;
100 
101 /* External interface functions */
102 static int opendous_execute_queue(struct jtag_command *cmd_queue);
103 static int opendous_init(void);
104 static int opendous_quit(void);
105 
106 /* Queue command functions */
107 static void opendous_end_state(enum tap_state state);
108 static void opendous_state_move(void);
109 static void opendous_path_move(unsigned int num_states, enum tap_state *path);
110 static void opendous_runtest(unsigned int num_cycles);
111 static void opendous_scan(int ir_scan, enum scan_type type, uint8_t *buffer,
112  int scan_size, struct scan_command *command);
113 static void opendous_reset(int trst, int srst);
114 static void opendous_simple_command(uint8_t command, uint8_t _data);
115 static int opendous_get_status(void);
116 
117 /* opendous tap buffer functions */
118 static void opendous_tap_init(void);
119 static int opendous_tap_execute(void);
120 static void opendous_tap_ensure_space(int scans, int bits);
121 static void opendous_tap_append_step(int tms, int tdi);
122 static void opendous_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command);
123 
124 /* opendous lowlevel functions */
126  struct libusb_device_handle *usb_handle;
127 };
128 
129 static struct opendous_jtag *opendous_usb_open(void);
130 static void opendous_usb_close(struct opendous_jtag *opendous_jtag);
131 static int opendous_usb_message(struct opendous_jtag *opendous_jtag, int out_length, int in_length);
132 static int opendous_usb_write(struct opendous_jtag *opendous_jtag, int out_length);
133 static int opendous_usb_read(struct opendous_jtag *opendous_jtag);
134 
135 /* helper functions */
136 static int opendous_get_version_info(void);
137 
138 #ifdef _DEBUG_USB_COMMS_
139 static void opendous_debug_buffer(uint8_t *buffer, int length);
140 #endif
141 
143 
144 /***************************************************************************/
145 /* External interface implementation */
146 
147 COMMAND_HANDLER(opendous_handle_opendous_type_command)
148 {
149  if (CMD_ARGC == 0)
150  return ERROR_OK;
151 
152  /* only if the cable name wasn't overwritten by cmdline */
153  if (!opendous_type) {
154  /* REVISIT first verify that it's listed in cables[] ... */
155  opendous_type = strdup(CMD_ARGV[0]);
156  }
157 
158  /* REVISIT it's probably worth returning the current value ... */
159 
160  return ERROR_OK;
161 }
162 
163 COMMAND_HANDLER(opendous_handle_opendous_info_command)
164 {
166  /* attempt to get status */
168  }
169 
170  return ERROR_OK;
171 }
172 
173 COMMAND_HANDLER(opendous_handle_opendous_hw_jtag_command)
174 {
175  switch (CMD_ARGC) {
176  case 0:
177  command_print(CMD, "opendous hw jtag %i", opendous_hw_jtag_version);
178  break;
179 
180  case 1: {
181  int request_version = atoi(CMD_ARGV[0]);
182  switch (request_version) {
183  case 2:
184  case 3:
185  opendous_hw_jtag_version = request_version;
186  break;
187 
188  default:
190  }
191  break;
192  }
193 
194  default:
196  }
197 
198  return ERROR_OK;
199 }
200 
201 static const struct command_registration opendous_command_handlers[] = {
202  {
203  .name = "opendous_info",
204  .handler = &opendous_handle_opendous_info_command,
205  .mode = COMMAND_EXEC,
206  .help = "show opendous info",
207  .usage = "",
208  },
209  {
210  .name = "opendous_hw_jtag",
211  .handler = &opendous_handle_opendous_hw_jtag_command,
212  .mode = COMMAND_EXEC,
213  .help = "access opendous HW JTAG command version",
214  .usage = "[2|3]",
215  },
216  {
217  .name = "opendous_type",
218  .handler = &opendous_handle_opendous_type_command,
219  .mode = COMMAND_CONFIG,
220  .help = "set opendous type",
221  .usage = "[usbvlab|usbprog-jtag|opendous]",
222  },
224 };
225 
226 static struct jtag_interface opendous_interface = {
228 };
229 
231  .name = "opendous",
232  .transport_ids = TRANSPORT_JTAG,
233  .transport_preferred_id = TRANSPORT_JTAG,
234  .commands = opendous_command_handlers,
235 
236  .init = opendous_init,
237  .quit = opendous_quit,
238 
239  .jtag_ops = &opendous_interface,
240 };
241 
242 static int opendous_execute_queue(struct jtag_command *cmd_queue)
243 {
244  struct jtag_command *cmd = cmd_queue;
245  int scan_size;
246  enum scan_type type;
247  uint8_t *buffer;
248 
249  while (cmd) {
250  switch (cmd->type) {
251  case JTAG_RUNTEST:
252  LOG_DEBUG_IO("runtest %u cycles, end in %i", cmd->cmd.runtest->num_cycles,
253  cmd->cmd.runtest->end_state);
254 
255  if (cmd->cmd.runtest->end_state != -1)
256  opendous_end_state(cmd->cmd.runtest->end_state);
257  opendous_runtest(cmd->cmd.runtest->num_cycles);
258  break;
259 
260  case JTAG_TLR_RESET:
261  LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state);
262 
263  if (cmd->cmd.statemove->end_state != -1)
264  opendous_end_state(cmd->cmd.statemove->end_state);
266  break;
267 
268  case JTAG_PATHMOVE:
269  LOG_DEBUG_IO("pathmove: %u states, end in %i",
270  cmd->cmd.pathmove->num_states,
271  cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
272 
273  opendous_path_move(cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path);
274  break;
275 
276  case JTAG_SCAN:
277  LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state);
278 
279  if (cmd->cmd.scan->end_state != -1)
280  opendous_end_state(cmd->cmd.scan->end_state);
281 
282  scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
283  LOG_DEBUG_IO("scan input, length = %d", scan_size);
284 
285 #ifdef _DEBUG_USB_COMMS_
286  opendous_debug_buffer(buffer, (scan_size + 7) / 8);
287 #endif
288  type = jtag_scan_type(cmd->cmd.scan);
289  opendous_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size, cmd->cmd.scan);
290  break;
291 
292  case JTAG_RESET:
293  LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst);
294 
296 
297  if (cmd->cmd.reset->trst == 1)
299  opendous_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
300  break;
301 
302  case JTAG_SLEEP:
303  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
305  jtag_sleep(cmd->cmd.sleep->us);
306  break;
307 
308  default:
309  LOG_ERROR("BUG: unknown JTAG command type encountered");
310  exit(-1);
311  }
312  cmd = cmd->next;
313  }
314  return opendous_tap_execute();
315 }
316 
317 static int opendous_init(void)
318 {
319  int check_cnt;
320  const struct opendous_probe *cur_opendous_probe;
321 
322  cur_opendous_probe = opendous_probes;
323 
324  if (!opendous_type) {
325  opendous_type = strdup("opendous");
326  LOG_WARNING("No opendous_type specified, using default 'opendous'");
327  }
328 
329  while (cur_opendous_probe->name) {
330  if (strcmp(cur_opendous_probe->name, opendous_type) == 0) {
331  opendous_probe = cur_opendous_probe;
332  break;
333  }
334  cur_opendous_probe++;
335  }
336 
337  if (!opendous_probe) {
338  LOG_ERROR("No matching cable found for %s", opendous_type);
339  return ERROR_JTAG_INIT_FAILED;
340  }
341 
342 
345 
348 
350 
351  if (!opendous_jtag_handle) {
352  LOG_ERROR("Cannot find opendous Interface! Please check connection and permissions.");
353  return ERROR_JTAG_INIT_FAILED;
354  }
355 
356  check_cnt = 0;
357  while (check_cnt < 3) {
359  /* attempt to get status */
361  break;
362  }
363 
364  check_cnt++;
365  }
366 
367  LOG_INFO("opendous JTAG Interface ready");
368 
369  opendous_reset(0, 0);
371 
372  return ERROR_OK;
373 }
374 
375 static int opendous_quit(void)
376 {
378 
379  free(usb_out_buffer);
381 
382  free(usb_in_buffer);
384 
387 
388  free(opendous_type);
390 
391  return ERROR_OK;
392 }
393 
394 /***************************************************************************/
395 /* Queue command implementations */
396 
398 {
401  else {
402  LOG_ERROR("BUG: %i is not a valid end state", state);
403  exit(-1);
404  }
405 }
406 
407 /* Goes to the end state. */
409 {
410  int i;
411  int tms = 0;
412  uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
413  uint8_t tms_scan_bits = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
414 
415  for (i = 0; i < tms_scan_bits; i++) {
416  tms = (tms_scan >> i) & 1;
417  opendous_tap_append_step(tms, 0);
418  }
419 
421 }
422 
423 void opendous_path_move(unsigned int num_states, enum tap_state *path)
424 {
425  for (unsigned int i = 0; i < num_states; i++) {
426  if (path[i] == tap_state_transition(tap_get_state(), false))
428  else if (path[i] == tap_state_transition(tap_get_state(), true))
430  else {
431  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
433  exit(-1);
434  }
435 
436  tap_set_state(path[i]);
437  }
438 
440 }
441 
442 void opendous_runtest(unsigned int num_cycles)
443 {
444  enum tap_state saved_end_state = tap_get_end_state();
445 
446  /* only do a state_move when we're not already in IDLE */
447  if (tap_get_state() != TAP_IDLE) {
450  }
451 
452  /* execute num_cycles */
453  for (unsigned int i = 0; i < num_cycles; i++)
455 
456  /* finish in end_state */
457  opendous_end_state(saved_end_state);
458  if (tap_get_state() != tap_get_end_state())
460 }
461 
462 void opendous_scan(int ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
463 {
464  enum tap_state saved_end_state;
465 
466  opendous_tap_ensure_space(1, scan_size + 8);
467 
468  saved_end_state = tap_get_end_state();
469 
470  /* Move to appropriate scan state */
472 
473  if (tap_get_state() != tap_get_end_state())
475 
476  opendous_end_state(saved_end_state);
477 
478  /* Scan */
480 
481  /* We are in Exit1, go to Pause */
483 
485 
486  if (tap_get_state() != tap_get_end_state())
488 }
489 
490 void opendous_reset(int trst, int srst)
491 {
492  LOG_DEBUG("trst: %i, srst: %i", trst, srst);
493 
494  /* Signals are active low */
495 #if 0
496  if (srst == 0)
498  else if (srst == 1)
500 
501  if (trst == 0)
503  else if (trst == 1)
505 #endif
506 
507  srst = srst ? 0 : 1;
508  trst = trst ? 0 : 2;
510 }
511 
512 void opendous_simple_command(uint8_t command, uint8_t _data)
513 {
514  int result;
515 
516  LOG_DEBUG_IO("0x%02x 0x%02x", command, _data);
517 
518  usb_out_buffer[0] = 2;
519  usb_out_buffer[1] = 0;
520  usb_out_buffer[2] = command;
521  usb_out_buffer[3] = _data;
522 
524  if (result != 1)
525  LOG_ERROR("opendous command 0x%02x failed (%d)", command, result);
526 }
527 
529 {
530  return ERROR_OK;
531 }
532 
534 {
535  return ERROR_OK;
536 }
537 
538 /***************************************************************************/
539 /* Estick tap functions */
540 
541 static int tap_length;
544 
545 static int last_tms;
546 
548 {
549  tap_length = 0;
551 }
552 
553 void opendous_tap_ensure_space(int scans, int bits)
554 {
556  int available_bits = OPENDOUS_TAP_BUFFER_SIZE / 2 - tap_length;
557 
558  if ((scans > available_scans) || (bits > available_bits))
560 }
561 
562 void opendous_tap_append_step(int tms, int tdi)
563 {
564  last_tms = tms;
565  unsigned char _tms = tms ? 1 : 0;
566  unsigned char _tdi = tdi ? 1 : 0;
567 
569 
570  int tap_index = tap_length / 4;
571  int bits = (tap_length % 4) * 2;
572 
574  if (!bits)
575  tms_buffer[tap_index] = 0;
576 
577  tms_buffer[tap_index] |= (_tdi << bits)|(_tms << (bits + 1));
578  tap_length++;
579  } else
580  LOG_ERROR("opendous_tap_append_step, overflow");
581 }
582 
584 {
585  LOG_DEBUG_IO("append scan, length = %d", length);
586 
588  int i;
589 
594 
595  for (i = 0; i < length; i++)
596  opendous_tap_append_step((i < length-1 ? 0 : 1), (buffer[i / 8] >> (i % 8)) & 1);
598 }
599 
600 /* Pad and send a tap sequence to the device, and receive the answer.
601  * For the purpose of padding we assume that we are in idle or pause state. */
603 {
604  int byte_length;
605  int i, j;
606  int result;
607 
608 #ifdef _DEBUG_USB_COMMS_
609  int byte_length_out;
610 #endif
611 
612  if (tap_length > 0) {
613 
614  /* memset(tdo_buffer,0,OPENDOUS_TAP_BUFFER_SIZE); */
615  /* LOG_INFO("OPENDOUS tap execute %d",tap_length); */
616  byte_length = (tap_length + 3) / 4;
617 
618 #ifdef _DEBUG_USB_COMMS_
619  byte_length_out = (tap_length + 7) / 8;
620  LOG_DEBUG("opendous is sending %d bytes", byte_length);
621 #endif
622 
623  for (j = 0, i = 0; j < byte_length;) {
624 
625  int receive;
626  int transmit = byte_length - j;
627  if (transmit > OPENDOUS_MAX_TAP_TRANSMIT) {
628  transmit = OPENDOUS_MAX_TAP_TRANSMIT;
629  receive = (OPENDOUS_MAX_TAP_TRANSMIT) / 2;
631  } else {
632  usb_out_buffer[2] = JTAG_CMD_TAP_OUTPUT | ((tap_length % 4) << 4);
633  receive = (transmit + 1) / 2;
634  }
635  usb_out_buffer[0] = (transmit + 1) & 0xff;
636  usb_out_buffer[1] = ((transmit + 1) >> 8) & 0xff;
637 
638  memmove(usb_out_buffer + 3, tms_buffer + j, transmit);
639  result = opendous_usb_message(opendous_jtag_handle, 3 + transmit, receive);
640  if (result != receive) {
641  LOG_ERROR("opendous_tap_execute, wrong result %d, expected %d", result, receive);
643  }
644 
645  memmove(tdo_buffer + i, usb_in_buffer, receive);
646  i += receive;
647  j += transmit;
648  }
649 
650 #ifdef _DEBUG_USB_COMMS_
651  LOG_DEBUG("opendous tap result %d", byte_length_out);
652  opendous_debug_buffer(tdo_buffer, byte_length_out);
653 #endif
654 
655  /* LOG_INFO("eStick tap execute %d",tap_length); */
656  for (i = 0; i < pending_scan_results_length; i++) {
657 
659  uint8_t *buffer = pending_scan_result->buffer;
663 
664  /* Copy to buffer */
665  buf_set_buf(tdo_buffer, first, buffer, 0, length);
666 
667  LOG_DEBUG_IO("pending scan result, length = %d", length);
668 
669 #ifdef _DEBUG_USB_COMMS_
670  opendous_debug_buffer(buffer, byte_length_out);
671 #endif
672 
676  }
677 
679  }
680 
682  }
683 
684  return ERROR_OK;
685 }
686 
687 /*****************************************************************************/
688 /* Estick USB low-level functions */
689 
691 {
692  struct opendous_jtag *result;
693 
694  struct libusb_device_handle *devh;
696  return NULL;
697 
699  libusb_claim_interface(devh, 0);
700 
701  result = malloc(sizeof(*result));
702  result->usb_handle = devh;
703  return result;
704 }
705 
707 {
709  free(opendous_jtag);
710 }
711 
712 /* Send a message and receive the reply. */
713 int opendous_usb_message(struct opendous_jtag *opendous_jtag, int out_length, int in_length)
714 {
715  int result;
716 
717  result = opendous_usb_write(opendous_jtag, out_length);
718  if (result == out_length) {
720  if (result == in_length)
721  return result;
722  else {
723  LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", in_length, result);
724  return -1;
725  }
726  } else {
727  LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result);
728  return -1;
729  }
730 }
731 
732 /* Write data from out_buffer to USB. */
733 int opendous_usb_write(struct opendous_jtag *opendous_jtag, int out_length)
734 {
735  int result, transferred;
736 
737  if (out_length > OPENDOUS_OUT_BUFFER_SIZE) {
738  LOG_ERROR("opendous_jtag_write illegal out_length=%d (max=%d)", out_length, OPENDOUS_OUT_BUFFER_SIZE);
739  return -1;
740  }
741 
742 #ifdef _DEBUG_USB_COMMS_
743  LOG_DEBUG("USB write begin");
744 #endif
747  LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT,
748  FUNC_WRITE_DATA, 0, 0, (char *)usb_out_buffer, out_length, OPENDOUS_USB_TIMEOUT,
749  &transferred);
750  /* FIXME: propagate error separately from transferred */
751  if (result == ERROR_OK)
752  result = transferred;
753  } else {
755  (char *)usb_out_buffer, out_length, OPENDOUS_USB_TIMEOUT, &result);
756  }
757 #ifdef _DEBUG_USB_COMMS_
758  LOG_DEBUG("USB write end: %d bytes", result);
759 #endif
760 
761  LOG_DEBUG_IO("opendous_usb_write, out_length = %d, result = %d", out_length, result);
762 
763 #ifdef _DEBUG_USB_COMMS_
764  opendous_debug_buffer(usb_out_buffer, out_length);
765 #endif
766  return result;
767 }
768 
769 /* Read data from USB into in_buffer. */
771 {
772  int transferred;
773 
774 #ifdef _DEBUG_USB_COMMS_
775  LOG_DEBUG("USB read begin");
776 #endif
777  int result;
780  LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN,
782  &transferred);
783  /* FIXME: propagate error separately from transferred */
784  if (result == ERROR_OK)
785  result = transferred;
786  } else {
789  }
790 #ifdef _DEBUG_USB_COMMS_
791  LOG_DEBUG("USB read end: %d bytes", result);
792 #endif
793  LOG_DEBUG_IO("opendous_usb_read, result = %d", result);
794 
795 #ifdef _DEBUG_USB_COMMS_
796  opendous_debug_buffer(usb_in_buffer, result);
797 #endif
798  return result;
799 }
800 
801 #ifdef _DEBUG_USB_COMMS_
802 #define BYTES_PER_LINE 16
803 
804 void opendous_debug_buffer(uint8_t *buffer, int length)
805 {
806  char line[8 + 3 * BYTES_PER_LINE + 1];
807 
808  for (int i = 0; i < length; i += BYTES_PER_LINE) {
809  int n = snprintf(line, 9, "%04x", i);
810  for (int j = i; j < i + BYTES_PER_LINE && j < length; j++)
811  n += snprintf(line + n, 4, " %02x", buffer[j]);
812  LOG_DEBUG("%s", line);
813  }
814 }
815 #endif
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
Definition: binarybuffer.c:120
#define BYTES_PER_LINE
Definition: buspirate.c:1266
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:376
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_EXEC
Definition: command.h:40
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
Definition: commands.c:192
enum scan_type jtag_scan_type(const struct scan_command *cmd)
Definition: commands.c:167
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
Definition: commands.c:230
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
Definition: commands.h:22
@ JTAG_TLR_RESET
Definition: commands.h:137
@ JTAG_SCAN
Definition: commands.h:129
@ JTAG_PATHMOVE
Definition: commands.h:140
@ JTAG_RUNTEST
Definition: commands.h:138
@ JTAG_SLEEP
Definition: commands.h:141
@ JTAG_RESET
Definition: commands.h:139
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint8_t type
Definition: esp_usb_jtag.c:0
uint8_t length
Definition: esp_usb_jtag.c:1
enum tap_state tap_get_end_state(void)
For more information,.
Definition: interface.c:56
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...
Definition: interface.c:223
const char * tap_state_name(enum tap_state state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
Definition: interface.c:344
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...
Definition: interface.c:195
void tap_set_end_state(enum tap_state new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
Definition: interface.c:48
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 ...
Definition: interface.c:37
bool tap_is_state_stable(enum tap_state astate)
Function tap_is_state_stable returns true if the astate is stable.
Definition: interface.c:200
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 ...
Definition: interface.c:190
#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...
Definition: interface.h:50
void jtag_sleep(uint32_t us)
Definition: jtag/core.c:1075
tap_state
Defines JTAG Test Access Port states.
Definition: jtag.h:37
@ TAP_RESET
Definition: jtag.h:56
@ TAP_DRPAUSE
Definition: jtag.h:44
@ TAP_IRSHIFT
Definition: jtag.h:51
@ TAP_IDLE
Definition: jtag.h:53
@ TAP_DRSHIFT
Definition: jtag.h:43
@ TAP_IRPAUSE
Definition: jtag.h:52
#define ERROR_JTAG_QUEUE_FAILED
Definition: jtag.h:556
#define ERROR_JTAG_INIT_FAILED
Definition: jtag.h:552
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 ...)
Definition: log.h:102
#define LOG_WARNING(expr ...)
Definition: log.h:130
#define LOG_ERROR(expr ...)
Definition: log.h:133
#define LOG_INFO(expr ...)
Definition: log.h:127
#define LOG_DEBUG(expr ...)
Definition: log.h:110
#define ERROR_OK
Definition: log.h:168
#define JTAG_CMD_TAP_OUTPUT
Definition: opendous.c:84
static void opendous_tap_append_step(int tms, int tdi)
Definition: opendous.c:562
static int opendous_quit(void)
Definition: opendous.c:375
#define MAX_PENDING_SCAN_RESULTS
Definition: opendous.c:81
static void opendous_end_state(enum tap_state state)
Definition: opendous.c:397
static void opendous_tap_init(void)
Definition: opendous.c:547
static void opendous_reset(int trst, int srst)
Definition: opendous.c:490
#define OPENDOUS_TAP_BUFFER_SIZE
Definition: opendous.c:69
static int opendous_usb_message(struct opendous_jtag *opendous_jtag, int out_length, int in_length)
Definition: opendous.c:713
#define OPENDOUS_USB_TIMEOUT
Definition: opendous.c:52
static int opendous_get_version_info(void)
Definition: opendous.c:533
static int last_tms
Definition: opendous.c:545
static int opendous_execute_queue(struct jtag_command *cmd_queue)
Definition: opendous.c:242
static int opendous_init(void)
Definition: opendous.c:317
static const struct opendous_probe * opendous_probe
Definition: opendous.c:99
static int tap_length
Definition: opendous.c:541
static void opendous_runtest(unsigned int num_cycles)
Definition: opendous.c:442
static char * opendous_type
Definition: opendous.c:98
#define OPENDOUS_OUT_BUFFER_SIZE
Definition: opendous.c:56
static uint8_t tdo_buffer[OPENDOUS_TAP_BUFFER_SIZE]
Definition: opendous.c:543
static void opendous_path_move(unsigned int num_states, enum tap_state *path)
Definition: opendous.c:423
static struct opendous_jtag * opendous_usb_open(void)
Definition: opendous.c:690
#define OPENDOUS_MAX_TAP_TRANSMIT
Definition: opendous.c:65
struct adapter_driver opendous_adapter_driver
Definition: opendous.c:230
static struct jtag_interface opendous_interface
Definition: opendous.c:226
#define OPENDOUS_MAX_VIDS_PIDS
Definition: opendous.c:28
static int opendous_tap_execute(void)
Definition: opendous.c:602
static void opendous_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
Definition: opendous.c:583
COMMAND_HANDLER(opendous_handle_opendous_type_command)
Definition: opendous.c:147
static uint8_t * usb_out_buffer
Definition: opendous.c:60
#define JTAG_CMD_SET_SRST
Definition: opendous.c:86
#define JTAG_CMD_SET_TRST
Definition: opendous.c:85
#define FUNC_READ_DATA
Definition: opendous.c:96
#define OPENDOUS_IN_BUFFER_SIZE
Definition: opendous.c:55
static void opendous_usb_close(struct opendous_jtag *opendous_jtag)
Definition: opendous.c:706
#define OPENDOUS_WRITE_ENDPOINT
Definition: opendous.c:47
static const struct command_registration opendous_command_handlers[]
Definition: opendous.c:201
static void opendous_tap_ensure_space(int scans, int bits)
Definition: opendous.c:553
static int opendous_usb_write(struct opendous_jtag *opendous_jtag, int out_length)
Definition: opendous.c:733
static uint8_t tms_buffer[OPENDOUS_TAP_BUFFER_SIZE]
Definition: opendous.c:542
#define OPENDOUS_READ_ENDPOINT
Definition: opendous.c:48
static struct opendous_jtag * opendous_jtag_handle
Definition: opendous.c:142
static const struct opendous_probe opendous_probes[]
Definition: opendous.c:40
static struct pending_scan_result * pending_scan_results_buffer
Definition: opendous.c:79
static uint8_t * usb_in_buffer
Definition: opendous.c:59
static void opendous_simple_command(uint8_t command, uint8_t _data)
Definition: opendous.c:512
#define FUNC_WRITE_DATA
Definition: opendous.c:95
static void opendous_scan(int ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
Definition: opendous.c:462
static unsigned int opendous_hw_jtag_version
Definition: opendous.c:50
static int pending_scan_results_length
Definition: opendous.c:78
static int opendous_usb_read(struct opendous_jtag *opendous_jtag)
Definition: opendous.c:770
static int opendous_get_status(void)
Definition: opendous.c:528
static void opendous_state_move(void)
Definition: opendous.c:408
#define JTAG_CMD_SET_SRST_TRST
Definition: opendous.c:90
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
Definition: qn908x.c:0
Represents a driver for a debugging interface.
Definition: interface.h:208
const char *const name
The name of the interface driver.
Definition: interface.h:210
const char * name
Definition: command.h:235
Represents a driver for a debugging interface.
Definition: interface.h:183
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
Definition: interface.h:196
struct libusb_device_handle * usb_handle
Definition: opendous.c:126
uint8_t WRITE_EP
Definition: opendous.c:35
uint16_t PID[OPENDOUS_MAX_VIDS_PIDS]
Definition: opendous.c:33
const char * name
Definition: opendous.c:31
int BUFFERSIZE
Definition: opendous.c:37
uint8_t READ_EP
Definition: opendous.c:34
uint8_t CONTROL_TRANSFER
Definition: opendous.c:36
uint16_t VID[OPENDOUS_MAX_VIDS_PIDS]
Definition: opendous.c:32
int first
First bit position in tdo_buffer to read.
Definition: arm-jtag-ew.c:514
int length
Number of bits to read.
Definition: arm-jtag-ew.c:515
uint8_t * buffer
Location to store the result.
Definition: arm-jtag-ew.c:517
struct scan_command * command
Definition: arm-jtag-ew.c:516
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
Definition: commands.h:35
#define TRANSPORT_JTAG
Definition: transport.h:19
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1
uint8_t state[4]
Definition: vdebug.c:21