OpenOCD
arm-jtag-ew.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2009 by Dimitar Dimitrov <dinuxbg@gmail.com> *
5  * based on Dominic Rath's and Benedikt Sauter's usbprog.c *
6  ***************************************************************************/
7 
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11 
12 #include <jtag/interface.h>
13 #include <jtag/commands.h>
14 #include "helper/system.h"
15 #include "libusb_helper.h"
16 
17 #define USB_VID 0x15ba
18 #define USB_PID 0x001e
19 
20 #define ARMJTAGEW_EPT_BULK_OUT 0x01u
21 #define ARMJTAGEW_EPT_BULK_IN 0x82u
22 
23 #define ARMJTAGEW_USB_TIMEOUT 2000
24 
25 #define ARMJTAGEW_IN_BUFFER_SIZE (4*1024)
26 #define ARMJTAGEW_OUT_BUFFER_SIZE (4*1024)
27 
28 /* USB command request codes. */
29 #define CMD_GET_VERSION 0x00
30 #define CMD_SELECT_DPIMPL 0x10
31 #define CMD_SET_TCK_FREQUENCY 0x11
32 #define CMD_GET_TCK_FREQUENCY 0x12
33 #define CMD_MEASURE_MAX_TCK_FREQ 0x15
34 #define CMD_MEASURE_RTCK_RESPONSE 0x16
35 #define CMD_TAP_SHIFT 0x17
36 #define CMD_SET_TAPHW_STATE 0x20
37 #define CMD_GET_TAPHW_STATE 0x21
38 #define CMD_TGPWR_SETUP 0x22
39 
40 /* Global USB buffers */
43 
44 /* Queue command functions */
45 static void armjtagew_end_state(enum tap_state state);
46 static void armjtagew_state_move(void);
47 static void armjtagew_path_move(unsigned int num_states, enum tap_state *path);
48 static void armjtagew_runtest(unsigned int num_cycles);
49 static void armjtagew_scan(bool ir_scan,
50  enum scan_type type,
51  uint8_t *buffer,
52  int scan_size,
53  struct scan_command *command);
54 static void armjtagew_reset(int trst, int srst);
55 /* static void armjtagew_simple_command(uint8_t command); */
56 static int armjtagew_get_status(void);
57 
58 /* tap buffer functions */
59 static void armjtagew_tap_init(void);
60 static int armjtagew_tap_execute(void);
61 static void armjtagew_tap_ensure_space(int scans, int bits);
62 static void armjtagew_tap_append_step(int tms, int tdi);
63 static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command);
64 
65 /* ARM-JTAG-EW lowlevel functions */
66 struct armjtagew {
67  struct libusb_device_handle *usb_handle;
68 };
69 
70 static struct armjtagew *armjtagew_usb_open(void);
71 static void armjtagew_usb_close(struct armjtagew *armjtagew);
72 static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length);
73 static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length);
74 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length);
75 
76 /* helper functions */
77 static int armjtagew_get_version_info(void);
78 
79 static void armjtagew_debug_buffer(uint8_t *buffer, int length);
80 
81 static struct armjtagew *armjtagew_handle;
82 
83 /**************************************************************************
84  * External interface implementation */
85 
86 static int armjtagew_execute_queue(struct jtag_command *cmd_queue)
87 {
88  struct jtag_command *cmd = cmd_queue;
89  int scan_size;
90  enum scan_type type;
91  uint8_t *buffer;
92 
93  while (cmd) {
94  switch (cmd->type) {
95  case JTAG_RUNTEST:
96  LOG_DEBUG_IO("runtest %u cycles, end in %i",
97  cmd->cmd.runtest->num_cycles,
98  cmd->cmd.runtest->end_state);
99 
100  armjtagew_end_state(cmd->cmd.runtest->end_state);
101  armjtagew_runtest(cmd->cmd.runtest->num_cycles);
102  break;
103 
104  case JTAG_TLR_RESET:
105  LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state);
106 
107  armjtagew_end_state(cmd->cmd.statemove->end_state);
109  break;
110 
111  case JTAG_PATHMOVE:
112  LOG_DEBUG_IO("pathmove: %u states, end in %i",
113  cmd->cmd.pathmove->num_states,
114  cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]);
115 
116  armjtagew_path_move(cmd->cmd.pathmove->num_states,
117  cmd->cmd.pathmove->path);
118  break;
119 
120  case JTAG_SCAN:
121  LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state);
122 
123  armjtagew_end_state(cmd->cmd.scan->end_state);
124 
125  scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer);
126  LOG_DEBUG_IO("scan input, length = %d", scan_size);
127 
128  armjtagew_debug_buffer(buffer, (scan_size + 7) / 8);
129 
130  type = jtag_scan_type(cmd->cmd.scan);
131  armjtagew_scan(cmd->cmd.scan->ir_scan,
132  type, buffer,
133  scan_size, cmd->cmd.scan);
134  break;
135 
136  case JTAG_RESET:
137  LOG_DEBUG_IO("reset trst: %i srst %i",
138  cmd->cmd.reset->trst,
139  cmd->cmd.reset->srst);
140 
142 
143  if (cmd->cmd.reset->trst == 1)
145  armjtagew_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst);
146  break;
147 
148  case JTAG_SLEEP:
149  LOG_DEBUG_IO("sleep %" PRIu32, cmd->cmd.sleep->us);
151  jtag_sleep(cmd->cmd.sleep->us);
152  break;
153 
154  default:
155  LOG_ERROR("BUG: unknown JTAG command type encountered");
156  exit(-1);
157  }
158  cmd = cmd->next;
159  }
160 
161  return armjtagew_tap_execute();
162 }
163 
164 /* Sets speed in kHz. */
165 static int armjtagew_speed(int speed)
166 {
167  int result;
168  int speed_real;
169 
170 
172  buf_set_u32(usb_out_buffer + 1, 0, 32, speed*1000);
173 
174  result = armjtagew_usb_message(armjtagew_handle, 5, 4);
175 
176  if (result < 0) {
177  LOG_ERROR("ARM-JTAG-EW setting speed failed (%d)", result);
179  }
180 
182  result = armjtagew_usb_message(armjtagew_handle, 1, 4);
183  speed_real = (int)buf_get_u32(usb_in_buffer, 0, 32) / 1000;
184  if (result < 0) {
185  LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result);
187  } else
188  LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real);
189 
190  return ERROR_OK;
191 }
192 
193 static int armjtagew_khz(int khz, int *jtag_speed)
194 {
195  *jtag_speed = khz;
196 
197  return ERROR_OK;
198 }
199 
200 static int armjtagew_speed_div(int speed, int *khz)
201 {
202  *khz = speed;
203 
204  return ERROR_OK;
205 }
206 
207 static int armjtagew_init(void)
208 {
209  int check_cnt;
210 
212 
213  if (!armjtagew_handle) {
214  LOG_ERROR(
215  "Cannot find ARM-JTAG-EW Interface! Please check connection and permissions.");
216  return ERROR_JTAG_INIT_FAILED;
217  }
218 
219  check_cnt = 0;
220  while (check_cnt < 3) {
222  /* attempt to get status */
224  break;
225  }
226 
227  check_cnt++;
228  }
229 
230  if (check_cnt == 3)
231  LOG_INFO("ARM-JTAG-EW initial read failed, don't worry");
232 
233  /* Initial JTAG speed (for reset and initialization): 32 kHz */
234  armjtagew_speed(32);
235 
236  LOG_INFO("ARM-JTAG-EW JTAG Interface ready");
237 
238  armjtagew_reset(0, 0);
240 
241  return ERROR_OK;
242 }
243 
244 static int armjtagew_quit(void)
245 {
247  return ERROR_OK;
248 }
249 
250 /**************************************************************************
251  * Queue command implementations */
252 
254 {
257  else {
258  LOG_ERROR("BUG: %i is not a valid end state", state);
259  exit(-1);
260  }
261 }
262 
263 /* Goes to the end state. */
264 static void armjtagew_state_move(void)
265 {
266  int i;
267  int tms = 0;
268  uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
270 
271  for (i = 0; i < tms_count; i++) {
272  tms = (tms_scan >> i) & 1;
274  }
275 
277 }
278 
279 static void armjtagew_path_move(unsigned int num_states, enum tap_state *path)
280 {
281  for (unsigned int i = 0; i < num_states; i++) {
282  /*
283  * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode.
284  * Either handle that here, or update the documentation with examples
285  * how to fix that in the configuration files.
286  */
287  if (path[i] == tap_state_transition(tap_get_state(), false))
289  else if (path[i] == tap_state_transition(tap_get_state(), true))
291  else {
292  LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
294  exit(-1);
295  }
296 
297  tap_set_state(path[i]);
298  }
299 
301 }
302 
303 static void armjtagew_runtest(unsigned int num_cycles)
304 {
305  enum tap_state saved_end_state = tap_get_end_state();
306 
307  /* only do a state_move when we're not already in IDLE */
308  if (tap_get_state() != TAP_IDLE) {
311  }
312 
313  /* execute num_cycles */
314  for (unsigned int i = 0; i < num_cycles; i++)
316 
317  /* finish in end_state */
318  armjtagew_end_state(saved_end_state);
319  if (tap_get_state() != tap_get_end_state())
321 }
322 
323 static void armjtagew_scan(bool ir_scan,
324  enum scan_type type,
325  uint8_t *buffer,
326  int scan_size,
327  struct scan_command *command)
328 {
329  enum tap_state saved_end_state;
330 
331  armjtagew_tap_ensure_space(1, scan_size + 8);
332 
333  saved_end_state = tap_get_end_state();
334 
335  /* Move to appropriate scan state */
337 
338  /* Only move if we're not already there */
339  if (tap_get_state() != tap_get_end_state())
341 
342  armjtagew_end_state(saved_end_state);
343 
344  /* Scan */
346 
347  /* We are in Exit1, go to Pause */
349 
351 
352  if (tap_get_state() != tap_get_end_state())
354 }
355 
356 static void armjtagew_reset(int trst, int srst)
357 {
358  const uint8_t trst_mask = (1u << 5);
359  const uint8_t srst_mask = (1u << 6);
360  uint8_t val = 0;
361  uint8_t outp_en = 0;
362  uint8_t change_mask = 0;
363  int result;
364 
365  LOG_DEBUG("trst: %i, srst: %i", trst, srst);
366 
367  if (srst == 0) {
368  val |= srst_mask;
369  outp_en &= ~srst_mask; /* tristate */
370  change_mask |= srst_mask;
371  } else if (srst == 1) {
372  val &= ~srst_mask;
373  outp_en |= srst_mask;
374  change_mask |= srst_mask;
375  }
376 
377  if (trst == 0) {
378  val |= trst_mask;
379  outp_en &= ~trst_mask; /* tristate */
380  change_mask |= trst_mask;
381  } else if (trst == 1) {
382  val &= ~trst_mask;
383  outp_en |= trst_mask;
384  change_mask |= trst_mask;
385  }
386 
388  usb_out_buffer[1] = val;
389  usb_out_buffer[2] = outp_en;
390  usb_out_buffer[3] = change_mask;
392  if (result != 4)
393  LOG_ERROR("ARM-JTAG-EW TRST/SRST pin set failed failed (%d)", result);
394 }
395 
396 static int armjtagew_get_status(void)
397 {
398  int result;
399 
401  result = armjtagew_usb_message(armjtagew_handle, 1, 12);
402 
403  if (result == 0) {
404  unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16);
405  LOG_INFO(
406  "U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s",
407  (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)),
408  (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)),
409  (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)),
410  (int)(buf_get_u32(usb_in_buffer + 6, 0, 16)),
411  usb_in_buffer[9],
412  usb_in_buffer[11] ? "OVERCURRENT" : "OK",
413  usb_in_buffer[10] ? "enabled" : "disabled");
414 
415  if (u_tg < 1500)
416  LOG_ERROR("Vref too low. Check Target Power");
417  } else
418  LOG_ERROR("ARM-JTAG-EW command CMD_GET_TAPHW_STATE failed (%d)", result);
419 
420  return ERROR_OK;
421 }
422 
424 {
425  int result;
426  char sn[16];
427  char auxinfo[257];
428 
429  /* query hardware version */
431  result = armjtagew_usb_message(armjtagew_handle, 1, 4 + 15 + 256);
432 
433  if (result != 0) {
434  LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)", result);
436  }
437 
438  memcpy(sn, usb_in_buffer + 4, 15);
439  sn[15] = '\0';
440  memcpy(auxinfo, usb_in_buffer + 4+15, 256);
441  auxinfo[256] = '\0';
442 
443  LOG_INFO(
444  "ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s",
445  usb_in_buffer[1],
446  usb_in_buffer[0],
447  isgraph(usb_in_buffer[2]) ? usb_in_buffer[2] : 'X',
448  sn,
449  auxinfo);
450 
451  if (1 != usb_in_buffer[1] || 6 != usb_in_buffer[0])
452  LOG_WARNING(
453  "ARM-JTAG-EW firmware version %d.%d is untested with this version of OpenOCD. You might experience unexpected behavior.",
454  usb_in_buffer[1],
455  usb_in_buffer[0]);
456  return ERROR_OK;
457 }
458 
459 COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
460 {
462  /* attempt to get status */
464  }
465 
466  return ERROR_OK;
467 }
468 
469 static const struct command_registration armjtagew_command_handlers[] = {
470  {
471  .name = "armjtagew_info",
472  .handler = &armjtagew_handle_armjtagew_info_command,
473  .mode = COMMAND_EXEC,
474  .help = "query armjtagew info",
475  .usage = "",
476  },
478 };
479 
480 static struct jtag_interface armjtagew_interface = {
482 };
483 
485  .name = "arm-jtag-ew",
486  .transport_ids = TRANSPORT_JTAG,
487  .transport_preferred_id = TRANSPORT_JTAG,
488  .commands = armjtagew_command_handlers,
489 
490  .init = armjtagew_init,
491  .quit = armjtagew_quit,
492  .speed = armjtagew_speed,
493  .khz = armjtagew_khz,
494  .speed_div = armjtagew_speed_div,
495 
496  .jtag_ops = &armjtagew_interface,
497 };
498 
499 /**************************************************************************
500  * ARM-JTAG-EW tap functions */
501 
502 /* 2048 is the max value we can use here */
503 #define ARMJTAGEW_TAP_BUFFER_SIZE 2048
504 
505 static int tap_length;
509 
511  int first; /* First bit position in tdo_buffer to read */
512  int length; /* Number of bits to read */
513  struct scan_command *command; /* Corresponding scan command */
514  uint8_t *buffer;
515 };
516 
517 #define MAX_PENDING_SCAN_RESULTS 256
518 
521 
522 static int last_tms;
523 
524 static void armjtagew_tap_init(void)
525 {
526  tap_length = 0;
528 }
529 
530 static void armjtagew_tap_ensure_space(int scans, int bits)
531 {
533  int available_bits = ARMJTAGEW_TAP_BUFFER_SIZE * 8 - tap_length;
534 
535  if (scans > available_scans || bits > available_bits)
537 }
538 
539 static void armjtagew_tap_append_step(int tms, int tdi)
540 {
541  last_tms = tms;
542  int index_local = tap_length / 8;
543 
544  if (index_local < ARMJTAGEW_TAP_BUFFER_SIZE) {
545  int bit_index = tap_length % 8;
546  uint8_t bit = 1 << bit_index;
547 
548  if (tms)
549  tms_buffer[index_local] |= bit;
550  else
551  tms_buffer[index_local] &= ~bit;
552 
553  if (tdi)
554  tdi_buffer[index_local] |= bit;
555  else
556  tdi_buffer[index_local] &= ~bit;
557 
558  tap_length++;
559  } else
560  LOG_ERROR("armjtagew_tap_append_step, overflow");
561 }
562 
564 {
567  int i;
568 
573 
574  for (i = 0; i < length; i++)
575  armjtagew_tap_append_step((i < length-1 ? 0 : 1), (buffer[i/8] >> (i%8)) & 1);
577 }
578 
579 /* Pad and send a tap sequence to the device, and receive the answer.
580  * For the purpose of padding we assume that we are in idle or pause state. */
581 static int armjtagew_tap_execute(void)
582 {
583  int byte_length;
584  int tms_offset;
585  int tdi_offset;
586  int i;
587  int result;
588 
589  if (tap_length > 0) {
590  /* Pad last byte so that tap_length is divisible by 8 */
591  while (tap_length % 8 != 0) {
592  /* More of the last TMS value keeps us in the same state,
593  * analogous to free-running JTAG interfaces. */
595  }
596 
597  byte_length = tap_length / 8;
598 
600  buf_set_u32(usb_out_buffer + 1, 0, 16, byte_length);
601 
602  tms_offset = 3;
603  for (i = 0; i < byte_length; i++)
604  usb_out_buffer[tms_offset + i] = flip_u32(tms_buffer[i], 8);
605 
606  tdi_offset = tms_offset + byte_length;
607  for (i = 0; i < byte_length; i++)
608  usb_out_buffer[tdi_offset + i] = flip_u32(tdi_buffer[i], 8);
609 
611  3 + 2 * byte_length,
612  byte_length + 4);
613 
614  if (result == 0) {
615  int stat_local;
616 
617  stat_local = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32);
618  if (stat_local) {
619  LOG_ERROR(
620  "armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command",
621  stat_local);
623  }
624 
625  for (i = 0; i < byte_length; i++)
626  tdo_buffer[i] = flip_u32(usb_in_buffer[i], 8);
627 
628  for (i = 0; i < pending_scan_results_length; i++) {
631  uint8_t *buffer = pending_scan_result->buffer;
635 
636  /* Copy to buffer */
637  buf_set_buf(tdo_buffer, first, buffer, 0, length);
638 
639  LOG_DEBUG_IO("pending scan result, length = %d", length);
640 
641  armjtagew_debug_buffer(buffer, byte_length);
642 
646  }
647 
649  }
650  } else {
651  LOG_ERROR("armjtagew_tap_execute, wrong result %d, expected %d",
652  result,
653  byte_length);
655  }
656 
658  }
659 
660  return ERROR_OK;
661 }
662 
663 /****************************************************************************
664  * JLink USB low-level functions */
665 
666 static struct armjtagew *armjtagew_usb_open(void)
667 {
668  const uint16_t vids[] = { USB_VID, 0 };
669  const uint16_t pids[] = { USB_PID, 0 };
670  struct libusb_device_handle *dev;
671 
672  if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
673  return NULL;
674 
675  struct armjtagew *result = malloc(sizeof(struct armjtagew));
676  result->usb_handle = dev;
677 
678 #if 0
679  /* libusb_set_configuration required under win32 */
680  struct libusb_config_descriptor *config;
681  struct libusb_device *usb_dev = libusb_get_device(dev);
682  libusb_get_config_descriptor(usb_dev, 0, &config);
683  libusb_set_configuration(dev, config->bConfigurationValue);
684 #endif
685  libusb_claim_interface(dev, 0);
686 #if 0
687  /*
688  * This makes problems under Mac OS X. And is not needed
689  * under Windows. Hopefully this will not break a linux build
690  */
691  libusb_set_interface_alt_setting(dev, 0, 0);
692 #endif
693  return result;
694 }
695 
697 {
698  libusb_close(armjtagew->usb_handle);
699  free(armjtagew);
700 }
701 
702 /* Send a message and receive the reply. */
703 static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length)
704 {
705  int result;
706 
707  result = armjtagew_usb_write(armjtagew, out_length);
708  if (result == out_length) {
709  result = armjtagew_usb_read(armjtagew, in_length);
710  if (result != in_length) {
711  LOG_ERROR("jtag_libusb_bulk_read failed (requested=%d, result=%d)",
712  in_length,
713  result);
714  return -1;
715  }
716  } else {
717  LOG_ERROR("jtag_libusb_bulk_write failed (requested=%d, result=%d)", out_length, result);
718  return -1;
719  }
720  return 0;
721 }
722 
723 /* Write data from out_buffer to USB. */
724 static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
725 {
726  int result;
727  int transferred;
728 
729  if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) {
730  LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)",
731  out_length,
733  return -1;
734  }
735 
737  (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT, &transferred);
738 
739  LOG_DEBUG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result);
740 
742 
743  if (result != ERROR_OK)
744  return -1;
745  return transferred;
746 }
747 
748 /* Read data from USB into in_buffer. */
749 static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
750 {
751  int transferred;
753  (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT, &transferred);
754 
755  LOG_DEBUG_IO("armjtagew_usb_read, result = %d", result);
756 
758 
759  if (result != ERROR_OK)
760  return -1;
761  return transferred;
762 }
763 
764 #define BYTES_PER_LINE 16
765 
766 static void armjtagew_debug_buffer(uint8_t *buffer, int length)
767 {
769  return;
770 
771  char line[8 + 3 * BYTES_PER_LINE + 1];
772 
773  for (int i = 0; i < length; i += BYTES_PER_LINE) {
774  int n = snprintf(line, 9, "%04x", i);
775  for (int j = i; j < i + BYTES_PER_LINE && j < length; j++)
776  n += snprintf(line + n, 4, " %02x", buffer[j]);
777  LOG_DEBUG_USB("%s", line);
778 
779  /* Prevent GDB timeout (writing to log might take some time) */
780  keep_alive();
781  }
782 }
static uint8_t tms_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:506
#define MAX_PENDING_SCAN_RESULTS
Definition: arm-jtag-ew.c:517
static int armjtagew_init(void)
Definition: arm-jtag-ew.c:207
static uint8_t usb_in_buffer[ARMJTAGEW_IN_BUFFER_SIZE]
Definition: arm-jtag-ew.c:41
static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command)
Definition: arm-jtag-ew.c:323
static void armjtagew_tap_ensure_space(int scans, int bits)
Definition: arm-jtag-ew.c:530
#define CMD_GET_TAPHW_STATE
Definition: arm-jtag-ew.c:37
static int armjtagew_tap_execute(void)
Definition: arm-jtag-ew.c:581
static int armjtagew_execute_queue(struct jtag_command *cmd_queue)
Definition: arm-jtag-ew.c:86
static int last_tms
Definition: arm-jtag-ew.c:522
static void armjtagew_path_move(unsigned int num_states, enum tap_state *path)
Definition: arm-jtag-ew.c:279
#define USB_VID
Definition: arm-jtag-ew.c:17
static struct armjtagew * armjtagew_usb_open(void)
Definition: arm-jtag-ew.c:666
static uint8_t tdi_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:507
#define CMD_SET_TCK_FREQUENCY
Definition: arm-jtag-ew.c:31
static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]
Definition: arm-jtag-ew.c:508
static int tap_length
Definition: arm-jtag-ew.c:505
#define ARMJTAGEW_USB_TIMEOUT
Definition: arm-jtag-ew.c:23
static void armjtagew_reset(int trst, int srst)
Definition: arm-jtag-ew.c:356
#define ARMJTAGEW_OUT_BUFFER_SIZE
Definition: arm-jtag-ew.c:26
static uint8_t usb_out_buffer[ARMJTAGEW_OUT_BUFFER_SIZE]
Definition: arm-jtag-ew.c:42
static void armjtagew_end_state(enum tap_state state)
Definition: arm-jtag-ew.c:253
static struct pending_scan_result pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS]
Definition: arm-jtag-ew.c:520
static void armjtagew_tap_append_step(int tms, int tdi)
Definition: arm-jtag-ew.c:539
static void armjtagew_runtest(unsigned int num_cycles)
Definition: arm-jtag-ew.c:303
static void armjtagew_state_move(void)
Definition: arm-jtag-ew.c:264
static int armjtagew_khz(int khz, int *jtag_speed)
Definition: arm-jtag-ew.c:193
#define CMD_SET_TAPHW_STATE
Definition: arm-jtag-ew.c:36
#define ARMJTAGEW_EPT_BULK_OUT
Definition: arm-jtag-ew.c:20
static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, int in_length)
Definition: arm-jtag-ew.c:703
#define CMD_TAP_SHIFT
Definition: arm-jtag-ew.c:35
static struct armjtagew * armjtagew_handle
Definition: arm-jtag-ew.c:81
static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command)
Definition: arm-jtag-ew.c:563
struct adapter_driver armjtagew_adapter_driver
Definition: arm-jtag-ew.c:484
#define CMD_GET_TCK_FREQUENCY
Definition: arm-jtag-ew.c:32
static int armjtagew_speed_div(int speed, int *khz)
Definition: arm-jtag-ew.c:200
#define USB_PID
Definition: arm-jtag-ew.c:18
#define ARMJTAGEW_EPT_BULK_IN
Definition: arm-jtag-ew.c:21
static void armjtagew_tap_init(void)
Definition: arm-jtag-ew.c:524
static const struct command_registration armjtagew_command_handlers[]
Definition: arm-jtag-ew.c:469
static struct jtag_interface armjtagew_interface
Definition: arm-jtag-ew.c:480
static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length)
Definition: arm-jtag-ew.c:724
#define BYTES_PER_LINE
Definition: arm-jtag-ew.c:764
static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length)
Definition: arm-jtag-ew.c:749
static int armjtagew_get_version_info(void)
Definition: arm-jtag-ew.c:423
static int armjtagew_quit(void)
Definition: arm-jtag-ew.c:244
static int armjtagew_speed(int speed)
Definition: arm-jtag-ew.c:165
#define CMD_GET_VERSION
Definition: arm-jtag-ew.c:29
static int pending_scan_results_length
Definition: arm-jtag-ew.c:519
#define ARMJTAGEW_TAP_BUFFER_SIZE
Definition: arm-jtag-ew.c:503
#define ARMJTAGEW_IN_BUFFER_SIZE
Definition: arm-jtag-ew.c:25
static void armjtagew_debug_buffer(uint8_t *buffer, int length)
Definition: arm-jtag-ew.c:766
static int armjtagew_get_status(void)
Definition: arm-jtag-ew.c:396
COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
Definition: arm-jtag-ew.c:459
static void armjtagew_usb_close(struct armjtagew *armjtagew)
Definition: arm-jtag-ew.c:696
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
Definition: binarybuffer.c:120
uint32_t flip_u32(uint32_t value, unsigned int num)
Inverts the ordering of bits inside a 32-bit word (e.g.
Definition: binarybuffer.c:165
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.
Definition: binarybuffer.h:104
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.
Definition: binarybuffer.h:34
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:256
@ 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
#define ERROR_JTAG_DEVICE_ERROR
Definition: jtag.h:558
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_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
void keep_alive(void)
Definition: log.c:432
#define LOG_DEBUG_IO(expr ...)
Definition: log.h:109
#define LOG_DEBUG_USB(expr,...)
Definition: log.h:107
#define LOG_WARNING(expr ...)
Definition: log.h:137
#define LOG_ERROR(expr ...)
Definition: log.h:140
#define LOG_LEVEL_IS(FOO)
Definition: log.h:105
#define LOG_INFO(expr ...)
Definition: log.h:134
#define LOG_DEBUG(expr ...)
Definition: log.h:117
#define ERROR_OK
Definition: log.h:175
@ LOG_LVL_DEBUG_USB
Definition: log.h:53
static uint32_t bit(uint32_t value, unsigned int b)
Definition: opcodes.h:39
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
struct libusb_device_handle * usb_handle
Definition: arm-jtag-ew.c:67
const char * name
Definition: command.h:239
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
int first
First bit position in tdo_buffer to read.
Definition: arm-jtag-ew.c:511
int length
Number of bits to read.
Definition: arm-jtag-ew.c:512
uint8_t * buffer
Location to store the result.
Definition: arm-jtag-ew.c:514
struct scan_command * command
Definition: arm-jtag-ew.c:513
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