OpenOCD
jtag/tcl.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2007-2010 Øyvind Harboe *
8  * oyvind.harboe@zylin.com *
9  * *
10  * Copyright (C) 2009 SoftPLC Corporation *
11  * http://softplc.com *
12  * dick@softplc.com *
13  * *
14  * Copyright (C) 2009 Zachary T Welch *
15  * zw@superlucidity.net *
16  ***************************************************************************/
17 
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21 
22 #include "adapter.h"
23 #include "jtag.h"
24 #include "swd.h"
25 #include "minidriver.h"
26 #include "interface.h"
27 #include "interfaces.h"
28 #include "tcl.h"
29 
30 #ifdef HAVE_STRINGS_H
31 #include <strings.h>
32 #endif
33 
34 #include <helper/time_support.h>
35 #include "transport/transport.h"
36 
42 static const struct jim_nvp nvp_jtag_tap_event[] = {
43  { .value = JTAG_TRST_ASSERTED, .name = "post-reset" },
44  { .value = JTAG_TAP_EVENT_SETUP, .name = "setup" },
45  { .value = JTAG_TAP_EVENT_ENABLE, .name = "tap-enable" },
46  { .value = JTAG_TAP_EVENT_DISABLE, .name = "tap-disable" },
47 
48  { .name = NULL, .value = -1 }
49 };
50 
51 struct jtag_tap *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
52 {
53  const char *cp = Jim_GetString(o, NULL);
54  struct jtag_tap *t = cp ? jtag_tap_by_string(cp) : NULL;
55  if (!cp)
56  cp = "(unknown)";
57  if (!t)
58  Jim_SetResultFormatted(interp, "Tap '%s' could not be found", cp);
59  return t;
60 }
61 
63 {
64  switch (state) {
65  case TAP_RESET:
66  case TAP_IDLE:
67  case TAP_DRPAUSE:
68  case TAP_IRPAUSE:
69  return true;
70  default:
71  return false;
72  }
73 }
74 
75 static int jim_command_drscan(Jim_Interp *interp, int argc, Jim_Obj * const *args)
76 {
77  int retval;
78  struct scan_field *fields;
79  int num_fields;
80  int field_count = 0;
81  int i, e;
82  struct jtag_tap *tap;
83  tap_state_t endstate;
84 
85  /* args[1] = device
86  * args[2] = num_bits
87  * args[3] = hex string
88  * ... repeat num bits and hex string ...
89  *
90  * .. optionally:
91  * args[N-2] = "-endstate"
92  * args[N-1] = statename
93  */
94  if ((argc < 4) || ((argc % 2) != 0)) {
95  Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
96  return JIM_ERR;
97  }
98 
99  endstate = TAP_IDLE;
100 
101  /* validate arguments as numbers */
102  e = JIM_OK;
103  for (i = 2; i < argc; i += 2) {
104  long bits;
105  const char *cp;
106 
107  e = Jim_GetLong(interp, args[i], &bits);
108  /* If valid - try next arg */
109  if (e == JIM_OK)
110  continue;
111 
112  /* Not valid.. are we at the end? */
113  if (((i + 2) != argc)) {
114  /* nope, then error */
115  return e;
116  }
117 
118  /* it could be: "-endstate FOO"
119  * e.g. DRPAUSE so we can issue more instructions
120  * before entering RUN/IDLE and executing them.
121  */
122 
123  /* get arg as a string. */
124  cp = Jim_GetString(args[i], NULL);
125  /* is it the magic? */
126  if (strcmp("-endstate", cp) == 0) {
127  /* is the statename valid? */
128  cp = Jim_GetString(args[i + 1], NULL);
129 
130  /* see if it is a valid state name */
131  endstate = tap_state_by_name(cp);
132  if (endstate < 0) {
133  /* update the error message */
134  Jim_SetResultFormatted(interp, "endstate: %s invalid", cp);
135  } else {
136  if (!scan_is_safe(endstate))
137  LOG_WARNING("drscan with unsafe "
138  "endstate \"%s\"", cp);
139 
140  /* valid - so clear the error */
141  e = JIM_OK;
142  /* and remove the last 2 args */
143  argc -= 2;
144  }
145  }
146 
147  /* Still an error? */
148  if (e != JIM_OK)
149  return e; /* too bad */
150  } /* validate args */
151 
152  assert(e == JIM_OK);
153 
154  tap = jtag_tap_by_jim_obj(interp, args[1]);
155  if (!tap)
156  return JIM_ERR;
157 
158  num_fields = (argc-2)/2;
159  if (num_fields <= 0) {
160  Jim_SetResultString(interp, "drscan: no scan fields supplied", -1);
161  return JIM_ERR;
162  }
163  fields = malloc(sizeof(struct scan_field) * num_fields);
164  for (i = 2; i < argc; i += 2) {
165  long bits;
166  int len;
167  const char *str;
168 
169  Jim_GetLong(interp, args[i], &bits);
170  str = Jim_GetString(args[i + 1], &len);
171 
172  fields[field_count].num_bits = bits;
173  void *t = malloc(DIV_ROUND_UP(bits, 8));
174  fields[field_count].out_value = t;
175  str_to_buf(str, len, t, bits, 0);
176  fields[field_count].in_value = t;
177  field_count++;
178  }
179 
180  jtag_add_dr_scan(tap, num_fields, fields, endstate);
181 
182  retval = jtag_execute_queue();
183  if (retval != ERROR_OK) {
184  Jim_SetResultString(interp, "drscan: jtag execute failed", -1);
185 
186  for (i = 0; i < field_count; i++)
187  free(fields[i].in_value);
188  free(fields);
189 
190  return JIM_ERR;
191  }
192 
193  field_count = 0;
194  Jim_Obj *list = Jim_NewListObj(interp, NULL, 0);
195  for (i = 2; i < argc; i += 2) {
196  long bits;
197  char *str;
198 
199  Jim_GetLong(interp, args[i], &bits);
200  str = buf_to_hex_str(fields[field_count].in_value, bits);
201  free(fields[field_count].in_value);
202 
203  Jim_ListAppendElement(interp, list, Jim_NewStringObj(interp, str, strlen(str)));
204  free(str);
205  field_count++;
206  }
207 
208  Jim_SetResult(interp, list);
209 
210  free(fields);
211 
212  return JIM_OK;
213 }
214 
215 
216 static int jim_command_pathmove(Jim_Interp *interp, int argc, Jim_Obj * const *args)
217 {
218  tap_state_t states[8];
219 
220  if ((argc < 2) || ((size_t)argc > (ARRAY_SIZE(states) + 1))) {
221  Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
222  return JIM_ERR;
223  }
224 
225  int i;
226  for (i = 0; i < argc-1; i++) {
227  const char *cp;
228  cp = Jim_GetString(args[i + 1], NULL);
229  states[i] = tap_state_by_name(cp);
230  if (states[i] < 0) {
231  /* update the error message */
232  Jim_SetResultFormatted(interp, "endstate: %s invalid", cp);
233  return JIM_ERR;
234  }
235  }
236 
237  if ((jtag_add_statemove(states[0]) != ERROR_OK) || (jtag_execute_queue() != ERROR_OK)) {
238  Jim_SetResultString(interp, "pathmove: jtag execute failed", -1);
239  return JIM_ERR;
240  }
241 
242  jtag_add_pathmove(argc - 2, states + 1);
243 
244  if (jtag_execute_queue() != ERROR_OK) {
245  Jim_SetResultString(interp, "pathmove: failed", -1);
246  return JIM_ERR;
247  }
248 
249  return JIM_OK;
250 }
251 
252 
253 static int jim_command_flush_count(Jim_Interp *interp, int argc, Jim_Obj * const *args)
254 {
255  Jim_SetResult(interp, Jim_NewIntObj(interp, jtag_get_flush_queue_count()));
256 
257  return JIM_OK;
258 }
259 
260 /* REVISIT Just what about these should "move" ... ?
261  * These registrations, into the main JTAG table?
262  *
263  * There's a minor compatibility issue, these all show up twice;
264  * that's not desirable:
265  * - jtag drscan ... NOT DOCUMENTED!
266  * - drscan ...
267  *
268  * The "irscan" command (for example) doesn't show twice.
269  */
270 static const struct command_registration jtag_command_handlers_to_move[] = {
271  {
272  .name = "drscan",
273  .mode = COMMAND_EXEC,
274  .jim_handler = jim_command_drscan,
275  .help = "Execute Data Register (DR) scan for one TAP. "
276  "Other TAPs must be in BYPASS mode.",
277  .usage = "tap_name [num_bits value]* ['-endstate' state_name]",
278  },
279  {
280  .name = "flush_count",
281  .mode = COMMAND_EXEC,
282  .jim_handler = jim_command_flush_count,
283  .help = "Returns the number of times the JTAG queue "
284  "has been flushed.",
285  },
286  {
287  .name = "pathmove",
288  .mode = COMMAND_EXEC,
289  .jim_handler = jim_command_pathmove,
290  .usage = "start_state state1 [state2 [state3 ...]]",
291  .help = "Move JTAG state machine from current state "
292  "(start_state) to state1, then state2, state3, etc.",
293  },
295 };
296 
297 
301 };
302 
303 static struct jim_nvp nvp_config_opts[] = {
304  { .name = "-event", .value = JCFG_EVENT },
305  { .name = "-idcode", .value = JCFG_IDCODE },
306 
307  { .name = NULL, .value = -1 }
308 };
309 
310 static int jtag_tap_configure_event(struct jim_getopt_info *goi, struct jtag_tap *tap)
311 {
312  if (goi->argc == 0) {
313  Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event <event-name> ...");
314  return JIM_ERR;
315  }
316 
317  struct jim_nvp *n;
318  int e = jim_getopt_nvp(goi, nvp_jtag_tap_event, &n);
319  if (e != JIM_OK) {
321  return e;
322  }
323 
324  if (goi->isconfigure) {
325  if (goi->argc != 1) {
326  Jim_WrongNumArgs(goi->interp,
327  goi->argc,
328  goi->argv,
329  "-event <event-name> <event-body>");
330  return JIM_ERR;
331  }
332  } else {
333  if (goi->argc != 0) {
334  Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event <event-name>");
335  return JIM_ERR;
336  }
337  }
338 
339  struct jtag_tap_event_action *jteap = tap->event_action;
340  /* replace existing event body */
341  bool found = false;
342  while (jteap) {
343  if (jteap->event == (enum jtag_event)n->value) {
344  found = true;
345  break;
346  }
347  jteap = jteap->next;
348  }
349 
350  Jim_SetEmptyResult(goi->interp);
351 
352  if (goi->isconfigure) {
353  if (!found)
354  jteap = calloc(1, sizeof(*jteap));
355  else if (jteap->body)
356  Jim_DecrRefCount(goi->interp, jteap->body);
357 
358  jteap->interp = goi->interp;
359  jteap->event = n->value;
360 
361  Jim_Obj *o;
362  jim_getopt_obj(goi, &o);
363  jteap->body = Jim_DuplicateObj(goi->interp, o);
364  Jim_IncrRefCount(jteap->body);
365 
366  if (!found) {
367  /* add to head of event list */
368  jteap->next = tap->event_action;
369  tap->event_action = jteap;
370  }
371  } else if (found) {
372  jteap->interp = goi->interp;
373  Jim_SetResult(goi->interp,
374  Jim_DuplicateObj(goi->interp, jteap->body));
375  }
376  return JIM_OK;
377 }
378 
379 static int jtag_tap_configure_cmd(struct jim_getopt_info *goi, struct jtag_tap *tap)
380 {
381  /* parse config or cget options */
382  while (goi->argc > 0) {
383  Jim_SetEmptyResult(goi->interp);
384 
385  struct jim_nvp *n;
386  int e = jim_getopt_nvp(goi, nvp_config_opts, &n);
387  if (e != JIM_OK) {
389  return e;
390  }
391 
392  switch (n->value) {
393  case JCFG_EVENT:
394  e = jtag_tap_configure_event(goi, tap);
395  if (e != JIM_OK)
396  return e;
397  break;
398  case JCFG_IDCODE:
399  if (goi->isconfigure) {
400  Jim_SetResultFormatted(goi->interp,
401  "not settable: %s", n->name);
402  return JIM_ERR;
403  } else {
404  if (goi->argc != 0) {
405  Jim_WrongNumArgs(goi->interp,
406  goi->argc, goi->argv,
407  "NO PARAMS");
408  return JIM_ERR;
409  }
410  }
411  Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, tap->idcode));
412  break;
413  default:
414  Jim_SetResultFormatted(goi->interp, "unknown value: %s", n->name);
415  return JIM_ERR;
416  }
417  }
418 
419  return JIM_OK;
420 }
421 
422 static int is_bad_irval(int ir_length, jim_wide w)
423 {
424  jim_wide v = 1;
425 
426  v <<= ir_length;
427  v -= 1;
428  v = ~v;
429  return (w & v) != 0;
430 }
431 
432 static int jim_newtap_expected_id(struct jim_nvp *n, struct jim_getopt_info *goi,
433  struct jtag_tap *tap)
434 {
435  jim_wide w;
436  int e = jim_getopt_wide(goi, &w);
437  if (e != JIM_OK) {
438  Jim_SetResultFormatted(goi->interp, "option: %s bad parameter", n->name);
439  return e;
440  }
441 
442  uint32_t *p = realloc(tap->expected_ids,
443  (tap->expected_ids_cnt + 1) * sizeof(uint32_t));
444  if (!p) {
445  Jim_SetResultFormatted(goi->interp, "no memory");
446  return JIM_ERR;
447  }
448 
449  tap->expected_ids = p;
450  tap->expected_ids[tap->expected_ids_cnt++] = w;
451 
452  return JIM_OK;
453 }
454 
455 #define NTAP_OPT_IRLEN 0
456 #define NTAP_OPT_IRMASK 1
457 #define NTAP_OPT_IRCAPTURE 2
458 #define NTAP_OPT_ENABLED 3
459 #define NTAP_OPT_DISABLED 4
460 #define NTAP_OPT_EXPECTED_ID 5
461 #define NTAP_OPT_VERSION 6
462 #define NTAP_OPT_BYPASS 7
463 
464 static int jim_newtap_ir_param(struct jim_nvp *n, struct jim_getopt_info *goi,
465  struct jtag_tap *tap)
466 {
467  jim_wide w;
468  int e = jim_getopt_wide(goi, &w);
469  if (e != JIM_OK) {
470  Jim_SetResultFormatted(goi->interp,
471  "option: %s bad parameter", n->name);
472  return e;
473  }
474  switch (n->value) {
475  case NTAP_OPT_IRLEN:
476  if (w > (jim_wide) (8 * sizeof(tap->ir_capture_value))) {
477  LOG_WARNING("%s: huge IR length %d",
478  tap->dotted_name, (int) w);
479  }
480  tap->ir_length = w;
481  break;
482  case NTAP_OPT_IRMASK:
483  if (is_bad_irval(tap->ir_length, w)) {
484  LOG_ERROR("%s: IR mask %x too big",
485  tap->dotted_name,
486  (int) w);
487  return JIM_ERR;
488  }
489  if ((w & 3) != 3)
490  LOG_WARNING("%s: nonstandard IR mask", tap->dotted_name);
491  tap->ir_capture_mask = w;
492  break;
493  case NTAP_OPT_IRCAPTURE:
494  if (is_bad_irval(tap->ir_length, w)) {
495  LOG_ERROR("%s: IR capture %x too big",
496  tap->dotted_name, (int) w);
497  return JIM_ERR;
498  }
499  if ((w & 3) != 1)
500  LOG_WARNING("%s: nonstandard IR value",
501  tap->dotted_name);
502  tap->ir_capture_value = w;
503  break;
504  default:
505  return JIM_ERR;
506  }
507  return JIM_OK;
508 }
509 
510 static int jim_newtap_cmd(struct jim_getopt_info *goi)
511 {
512  struct jtag_tap *tap;
513  int x;
514  int e;
515  struct jim_nvp *n;
516  char *cp;
517  const struct jim_nvp opts[] = {
518  { .name = "-irlen", .value = NTAP_OPT_IRLEN },
519  { .name = "-irmask", .value = NTAP_OPT_IRMASK },
520  { .name = "-ircapture", .value = NTAP_OPT_IRCAPTURE },
521  { .name = "-enable", .value = NTAP_OPT_ENABLED },
522  { .name = "-disable", .value = NTAP_OPT_DISABLED },
523  { .name = "-expected-id", .value = NTAP_OPT_EXPECTED_ID },
524  { .name = "-ignore-version", .value = NTAP_OPT_VERSION },
525  { .name = "-ignore-bypass", .value = NTAP_OPT_BYPASS },
526  { .name = NULL, .value = -1 },
527  };
528 
529  tap = calloc(1, sizeof(struct jtag_tap));
530  if (!tap) {
531  Jim_SetResultFormatted(goi->interp, "no memory");
532  return JIM_ERR;
533  }
534 
535  /*
536  * we expect CHIP + TAP + OPTIONS
537  * */
538  if (goi->argc < 3) {
539  Jim_SetResultFormatted(goi->interp, "Missing CHIP TAP OPTIONS ....");
540  free(tap);
541  return JIM_ERR;
542  }
543 
544  const char *tmp;
545  jim_getopt_string(goi, &tmp, NULL);
546  tap->chip = strdup(tmp);
547 
548  jim_getopt_string(goi, &tmp, NULL);
549  tap->tapname = strdup(tmp);
550 
551  /* name + dot + name + null */
552  x = strlen(tap->chip) + 1 + strlen(tap->tapname) + 1;
553  cp = malloc(x);
554  sprintf(cp, "%s.%s", tap->chip, tap->tapname);
555  tap->dotted_name = cp;
556 
557  LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
558  tap->chip, tap->tapname, tap->dotted_name, goi->argc);
559 
560  if (!transport_is_jtag()) {
561  /* SWD doesn't require any JTAG tap parameters */
562  tap->enabled = true;
563  jtag_tap_init(tap);
564  return JIM_OK;
565  }
566 
567  /* IEEE specifies that the two LSBs of an IR scan are 01, so make
568  * that the default. The "-ircapture" and "-irmask" options are only
569  * needed to cope with nonstandard TAPs, or to specify more bits.
570  */
571  tap->ir_capture_mask = 0x03;
572  tap->ir_capture_value = 0x01;
573 
574  while (goi->argc) {
575  e = jim_getopt_nvp(goi, opts, &n);
576  if (e != JIM_OK) {
577  jim_getopt_nvp_unknown(goi, opts, 0);
578  free(cp);
579  free(tap);
580  return e;
581  }
582  LOG_DEBUG("Processing option: %s", n->name);
583  switch (n->value) {
584  case NTAP_OPT_ENABLED:
585  tap->disabled_after_reset = false;
586  break;
587  case NTAP_OPT_DISABLED:
588  tap->disabled_after_reset = true;
589  break;
591  e = jim_newtap_expected_id(n, goi, tap);
592  if (e != JIM_OK) {
593  free(cp);
594  free(tap);
595  return e;
596  }
597  break;
598  case NTAP_OPT_IRLEN:
599  case NTAP_OPT_IRMASK:
600  case NTAP_OPT_IRCAPTURE:
601  e = jim_newtap_ir_param(n, goi, tap);
602  if (e != JIM_OK) {
603  free(cp);
604  free(tap);
605  return e;
606  }
607  break;
608  case NTAP_OPT_VERSION:
609  tap->ignore_version = true;
610  break;
611  case NTAP_OPT_BYPASS:
612  tap->ignore_bypass = true;
613  break;
614  } /* switch (n->value) */
615  } /* while (goi->argc) */
616 
617  /* default is enabled-after-reset */
618  tap->enabled = !tap->disabled_after_reset;
619 
620  /* Did all the required option bits get cleared? */
621  if (tap->ir_length != 0) {
622  jtag_tap_init(tap);
623  return JIM_OK;
624  }
625 
626  Jim_SetResultFormatted(goi->interp,
627  "newtap: %s missing IR length",
628  tap->dotted_name);
629  jtag_tap_free(tap);
630  return JIM_ERR;
631 }
632 
633 static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
634 {
635  struct jtag_tap_event_action *jteap;
636  int retval;
637 
638  for (jteap = tap->event_action; jteap; jteap = jteap->next) {
639  if (jteap->event != e)
640  continue;
641 
643  LOG_DEBUG("JTAG tap: %s event: %d (%s)\n\taction: %s",
644  tap->dotted_name, e, nvp->name,
645  Jim_GetString(jteap->body, NULL));
646 
647  retval = Jim_EvalObj(jteap->interp, jteap->body);
648  if (retval == JIM_RETURN)
649  retval = jteap->interp->returnCode;
650 
651  if (retval != JIM_OK) {
652  Jim_MakeErrorMessage(jteap->interp);
653  LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap->interp), NULL));
654  continue;
655  }
656 
657  switch (e) {
660  /* NOTE: we currently assume the handlers
661  * can't fail. Right here is where we should
662  * really be verifying the scan chains ...
663  */
664  tap->enabled = (e == JTAG_TAP_EVENT_ENABLE);
665  LOG_INFO("JTAG tap: %s %s", tap->dotted_name,
666  tap->enabled ? "enabled" : "disabled");
667  break;
668  default:
669  break;
670  }
671  }
672 }
673 
674 static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
675 {
676  struct jim_getopt_info goi;
677  jim_getopt_setup(&goi, interp, argc-1, argv + 1);
678  if (goi.argc != 0) {
679  Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
680  return JIM_ERR;
681  }
683  int e = jtag_init_inner(context);
684  if (e != ERROR_OK) {
685  Jim_Obj *obj = Jim_NewIntObj(goi.interp, e);
686  Jim_SetResultFormatted(goi.interp, "error: %#s", obj);
687  return JIM_ERR;
688  }
689  return JIM_OK;
690 }
691 
692 static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
693 {
694  int e = ERROR_OK;
695  struct jim_getopt_info goi;
696  jim_getopt_setup(&goi, interp, argc-1, argv + 1);
697  if (goi.argc != 0) {
698  Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
699  return JIM_ERR;
700  }
702  if (transport_is_jtag())
703  e = jtag_init_reset(context);
704  else if (transport_is_swd())
705  e = swd_init_reset(context);
706 
707  if (e != ERROR_OK) {
708  Jim_Obj *obj = Jim_NewIntObj(goi.interp, e);
709  Jim_SetResultFormatted(goi.interp, "error: %#s", obj);
710  return JIM_ERR;
711  }
712  return JIM_OK;
713 }
714 
715 int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
716 {
717  struct jim_getopt_info goi;
718  jim_getopt_setup(&goi, interp, argc-1, argv + 1);
719  return jim_newtap_cmd(&goi);
720 }
721 
722 static bool jtag_tap_enable(struct jtag_tap *t)
723 {
724  if (t->enabled)
725  return false;
727  if (!t->enabled)
728  return false;
729 
730  /* FIXME add JTAG sanity checks, w/o TLR
731  * - scan chain length grew by one (this)
732  * - IDs and IR lengths are as expected
733  */
735  return true;
736 }
737 static bool jtag_tap_disable(struct jtag_tap *t)
738 {
739  if (!t->enabled)
740  return false;
742  if (t->enabled)
743  return false;
744 
745  /* FIXME add JTAG sanity checks, w/o TLR
746  * - scan chain length shrank by one (this)
747  * - IDs and IR lengths are as expected
748  */
750  return true;
751 }
752 
753 int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
754 {
755  struct command *c = jim_to_command(interp);
756  const char *cmd_name = c->name;
757  struct jim_getopt_info goi;
758  jim_getopt_setup(&goi, interp, argc-1, argv + 1);
759  if (goi.argc != 1) {
760  Jim_SetResultFormatted(goi.interp, "usage: %s <name>", cmd_name);
761  return JIM_ERR;
762  }
763 
764  struct jtag_tap *t;
765 
766  t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
767  if (!t)
768  return JIM_ERR;
769 
770  if (strcasecmp(cmd_name, "tapisenabled") == 0) {
771  /* do nothing, just return the value */
772  } else if (strcasecmp(cmd_name, "tapenable") == 0) {
773  if (!jtag_tap_enable(t)) {
774  LOG_WARNING("failed to enable tap %s", t->dotted_name);
775  return JIM_ERR;
776  }
777  } else if (strcasecmp(cmd_name, "tapdisable") == 0) {
778  if (!jtag_tap_disable(t)) {
779  LOG_WARNING("failed to disable tap %s", t->dotted_name);
780  return JIM_ERR;
781  }
782  } else {
783  LOG_ERROR("command '%s' unknown", cmd_name);
784  return JIM_ERR;
785  }
786  bool e = t->enabled;
787  Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, e));
788  return JIM_OK;
789 }
790 
791 int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
792 {
793  struct command *c = jim_to_command(interp);
794  const char *cmd_name = c->name;
795  struct jim_getopt_info goi;
796  jim_getopt_setup(&goi, interp, argc-1, argv + 1);
797  goi.isconfigure = !strcmp(cmd_name, "configure");
798  if (goi.argc < 2 + goi.isconfigure) {
799  Jim_WrongNumArgs(goi.interp, 0, NULL,
800  "<tap_name> <attribute> ...");
801  return JIM_ERR;
802  }
803 
804  struct jtag_tap *t;
805 
806  Jim_Obj *o;
807  jim_getopt_obj(&goi, &o);
808  t = jtag_tap_by_jim_obj(goi.interp, o);
809  if (!t)
810  return JIM_ERR;
811 
812  return jtag_tap_configure_cmd(&goi, t);
813 }
814 
815 static int jim_jtag_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
816 {
817  struct jim_getopt_info goi;
818  jim_getopt_setup(&goi, interp, argc-1, argv + 1);
819  if (goi.argc != 0) {
820  Jim_WrongNumArgs(goi.interp, 1, goi.argv, "Too many parameters");
821  return JIM_ERR;
822  }
823  Jim_SetResult(goi.interp, Jim_NewListObj(goi.interp, NULL, 0));
824  struct jtag_tap *tap;
825 
826  for (tap = jtag_all_taps(); tap; tap = tap->next_tap) {
827  Jim_ListAppendElement(goi.interp,
828  Jim_GetResult(goi.interp),
829  Jim_NewStringObj(goi.interp,
830  tap->dotted_name, -1));
831  }
832  return JIM_OK;
833 }
834 
835 COMMAND_HANDLER(handle_jtag_init_command)
836 {
837  if (CMD_ARGC != 0)
839 
840  static bool jtag_initialized;
841  if (jtag_initialized) {
842  LOG_INFO("'jtag init' has already been called");
843  return ERROR_OK;
844  }
845  jtag_initialized = true;
846 
847  LOG_DEBUG("Initializing jtag devices...");
848  return jtag_init(CMD_CTX);
849 }
850 
851 static const struct command_registration jtag_subcommand_handlers[] = {
852  {
853  .name = "init",
854  .mode = COMMAND_ANY,
855  .handler = handle_jtag_init_command,
856  .help = "initialize jtag scan chain",
857  .usage = ""
858  },
859  {
860  .name = "arp_init",
861  .mode = COMMAND_ANY,
862  .jim_handler = jim_jtag_arp_init,
863  .help = "Validates JTAG scan chain against the list of "
864  "declared TAPs using just the four standard JTAG "
865  "signals.",
866  },
867  {
868  .name = "arp_init-reset",
869  .mode = COMMAND_ANY,
870  .jim_handler = jim_jtag_arp_init_reset,
871  .help = "Uses TRST and SRST to try resetting everything on "
872  "the JTAG scan chain, then performs 'jtag arp_init'."
873  },
874  {
875  .name = "newtap",
876  .mode = COMMAND_CONFIG,
877  .jim_handler = jim_jtag_newtap,
878  .help = "Create a new TAP instance named basename.tap_type, "
879  "and appends it to the scan chain.",
880  .usage = "basename tap_type '-irlen' count "
881  "['-enable'|'-disable'] "
882  "['-expected_id' number] "
883  "['-ignore-version'] "
884  "['-ignore-bypass'] "
885  "['-ircapture' number] "
886  "['-mask' number]",
887  },
888  {
889  .name = "tapisenabled",
890  .mode = COMMAND_EXEC,
891  .jim_handler = jim_jtag_tap_enabler,
892  .help = "Returns a Tcl boolean (0/1) indicating whether "
893  "the TAP is enabled (1) or not (0).",
894  .usage = "tap_name",
895  },
896  {
897  .name = "tapenable",
898  .mode = COMMAND_EXEC,
899  .jim_handler = jim_jtag_tap_enabler,
900  .help = "Try to enable the specified TAP using the "
901  "'tap-enable' TAP event.",
902  .usage = "tap_name",
903  },
904  {
905  .name = "tapdisable",
906  .mode = COMMAND_EXEC,
907  .jim_handler = jim_jtag_tap_enabler,
908  .help = "Try to disable the specified TAP using the "
909  "'tap-disable' TAP event.",
910  .usage = "tap_name",
911  },
912  {
913  .name = "configure",
914  .mode = COMMAND_ANY,
915  .jim_handler = jim_jtag_configure,
916  .help = "Provide a Tcl handler for the specified "
917  "TAP event.",
918  .usage = "tap_name '-event' event_name handler",
919  },
920  {
921  .name = "cget",
922  .mode = COMMAND_EXEC,
923  .jim_handler = jim_jtag_configure,
924  .help = "Return any Tcl handler for the specified "
925  "TAP event.",
926  .usage = "tap_name '-event' event_name",
927  },
928  {
929  .name = "names",
930  .mode = COMMAND_ANY,
931  .jim_handler = jim_jtag_names,
932  .help = "Returns list of all JTAG tap names.",
933  },
934  {
936  },
938 };
939 
941 {
942  struct jtag_tap *tap;
943 
944  for (tap = jtag_all_taps(); tap; tap = tap->next_tap)
945  jtag_tap_handle_event(tap, event);
946 }
947 
948 
949 COMMAND_HANDLER(handle_scan_chain_command)
950 {
951  struct jtag_tap *tap;
952  char expected_id[12];
953 
954  tap = jtag_all_taps();
956  " TapName Enabled IdCode Expected IrLen IrCap IrMask");
958  "-- ------------------- -------- ---------- ---------- ----- ----- ------");
959 
960  while (tap) {
961  uint32_t expected, expected_mask, ii;
962 
963  snprintf(expected_id, sizeof(expected_id), "0x%08x",
964  (unsigned)((tap->expected_ids_cnt > 0)
965  ? tap->expected_ids[0]
966  : 0));
967  if (tap->ignore_version)
968  expected_id[2] = '*';
969 
970  expected = buf_get_u32(tap->expected, 0, tap->ir_length);
972 
974  "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x",
975  tap->abs_chain_position,
976  tap->dotted_name,
977  tap->enabled ? 'Y' : 'n',
978  (unsigned int)(tap->idcode),
979  expected_id,
980  (unsigned int)(tap->ir_length),
981  (unsigned int)(expected),
982  (unsigned int)(expected_mask));
983 
984  for (ii = 1; ii < tap->expected_ids_cnt; ii++) {
985  snprintf(expected_id, sizeof(expected_id), "0x%08x",
986  (unsigned) tap->expected_ids[ii]);
987  if (tap->ignore_version)
988  expected_id[2] = '*';
989 
991  " %s",
992  expected_id);
993  }
994 
995  tap = tap->next_tap;
996  }
997 
998  return ERROR_OK;
999 }
1000 
1001 COMMAND_HANDLER(handle_jtag_ntrst_delay_command)
1002 {
1003  if (CMD_ARGC > 1)
1005  if (CMD_ARGC == 1) {
1006  unsigned delay;
1007  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
1008 
1009  jtag_set_ntrst_delay(delay);
1010  }
1011  command_print(CMD, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
1012  return ERROR_OK;
1013 }
1014 
1015 COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command)
1016 {
1017  if (CMD_ARGC > 1)
1019  if (CMD_ARGC == 1) {
1020  unsigned delay;
1021  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
1022 
1024  }
1025  command_print(CMD, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
1026  return ERROR_OK;
1027 }
1028 
1029 COMMAND_HANDLER(handle_jtag_rclk_command)
1030 {
1031  if (CMD_ARGC > 1)
1033 
1034  int retval = ERROR_OK;
1035  if (CMD_ARGC == 1) {
1036  unsigned khz = 0;
1037  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
1038 
1039  retval = adapter_config_rclk(khz);
1040  if (retval != ERROR_OK)
1041  return retval;
1042  }
1043 
1044  int cur_khz = adapter_get_speed_khz();
1045  retval = adapter_get_speed_readable(&cur_khz);
1046  if (retval != ERROR_OK)
1047  return retval;
1048 
1049  if (cur_khz)
1050  command_print(CMD, "RCLK not supported - fallback to %d kHz", cur_khz);
1051  else
1052  command_print(CMD, "RCLK - adaptive");
1053 
1054  return retval;
1055 }
1056 
1057 COMMAND_HANDLER(handle_runtest_command)
1058 {
1059  if (CMD_ARGC != 1)
1061 
1062  unsigned num_clocks;
1063  COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num_clocks);
1064 
1065  jtag_add_runtest(num_clocks, TAP_IDLE);
1066  return jtag_execute_queue();
1067 }
1068 
1069 /*
1070  * For "irscan" or "drscan" commands, the "end" (really, "next") state
1071  * should be stable ... and *NOT* a shift state, otherwise free-running
1072  * jtag clocks could change the values latched by the update state.
1073  * Not surprisingly, this is the same constraint as SVF; the "irscan"
1074  * and "drscan" commands are a write-only subset of what SVF provides.
1075  */
1076 
1077 COMMAND_HANDLER(handle_irscan_command)
1078 {
1079  int i;
1080  struct scan_field *fields;
1081  struct jtag_tap *tap = NULL;
1082  tap_state_t endstate;
1083 
1084  if ((CMD_ARGC < 2) || (CMD_ARGC % 2))
1086 
1087  /* optional "-endstate" "statename" at the end of the arguments,
1088  * so that e.g. IRPAUSE can let us load the data register before
1089  * entering RUN/IDLE to execute the instruction we load here.
1090  */
1091  endstate = TAP_IDLE;
1092 
1093  if (CMD_ARGC >= 4) {
1094  /* have at least one pair of numbers.
1095  * is last pair the magic text? */
1096  if (strcmp("-endstate", CMD_ARGV[CMD_ARGC - 2]) == 0) {
1097  endstate = tap_state_by_name(CMD_ARGV[CMD_ARGC - 1]);
1098  if (endstate == TAP_INVALID)
1100  if (!scan_is_safe(endstate))
1101  LOG_WARNING("unstable irscan endstate \"%s\"",
1102  CMD_ARGV[CMD_ARGC - 1]);
1103  CMD_ARGC -= 2;
1104  }
1105  }
1106 
1107  int num_fields = CMD_ARGC / 2;
1108  if (num_fields > 1) {
1109  /* we really should be looking at plain_ir_scan if we want
1110  * anything more fancy.
1111  */
1112  LOG_ERROR("Specify a single value for tap");
1114  }
1115 
1116  fields = calloc(num_fields, sizeof(*fields));
1117 
1118  int retval;
1119  for (i = 0; i < num_fields; i++) {
1120  tap = jtag_tap_by_string(CMD_ARGV[i*2]);
1121  if (!tap) {
1122  free(fields);
1123  command_print(CMD, "Tap: %s unknown", CMD_ARGV[i*2]);
1124 
1125  return ERROR_FAIL;
1126  }
1127  uint64_t value;
1128  retval = parse_u64(CMD_ARGV[i * 2 + 1], &value);
1129  if (retval != ERROR_OK)
1130  goto error_return;
1131 
1132  int field_size = tap->ir_length;
1133  fields[i].num_bits = field_size;
1134  uint8_t *v = calloc(1, DIV_ROUND_UP(field_size, 8));
1135  if (!v) {
1136  LOG_ERROR("Out of memory");
1137  goto error_return;
1138  }
1139 
1140  buf_set_u64(v, 0, field_size, value);
1141  fields[i].out_value = v;
1142  fields[i].in_value = NULL;
1143  }
1144 
1145  /* did we have an endstate? */
1146  jtag_add_ir_scan(tap, fields, endstate);
1147 
1148  retval = jtag_execute_queue();
1149 
1150 error_return:
1151  for (i = 0; i < num_fields; i++)
1152  free((void *)fields[i].out_value);
1153 
1154  free(fields);
1155 
1156  return retval;
1157 }
1158 
1159 COMMAND_HANDLER(handle_verify_ircapture_command)
1160 {
1161  if (CMD_ARGC > 1)
1163 
1164  if (CMD_ARGC == 1) {
1165  bool enable;
1166  COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
1168  }
1169 
1170  const char *status = jtag_will_verify_capture_ir() ? "enabled" : "disabled";
1171  command_print(CMD, "verify Capture-IR is %s", status);
1172 
1173  return ERROR_OK;
1174 }
1175 
1176 COMMAND_HANDLER(handle_verify_jtag_command)
1177 {
1178  if (CMD_ARGC > 1)
1180 
1181  if (CMD_ARGC == 1) {
1182  bool enable;
1183  COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
1184  jtag_set_verify(enable);
1185  }
1186 
1187  const char *status = jtag_will_verify() ? "enabled" : "disabled";
1188  command_print(CMD, "verify jtag capture is %s", status);
1189 
1190  return ERROR_OK;
1191 }
1192 
1193 COMMAND_HANDLER(handle_tms_sequence_command)
1194 {
1195  if (CMD_ARGC > 1)
1197 
1198  if (CMD_ARGC == 1) {
1199  bool use_new_table;
1200  if (strcmp(CMD_ARGV[0], "short") == 0)
1201  use_new_table = true;
1202  else if (strcmp(CMD_ARGV[0], "long") == 0)
1203  use_new_table = false;
1204  else
1206 
1207  tap_use_new_tms_table(use_new_table);
1208  }
1209 
1210  command_print(CMD, "tms sequence is %s",
1211  tap_uses_new_tms_table() ? "short" : "long");
1212 
1213  return ERROR_OK;
1214 }
1215 
1216 COMMAND_HANDLER(handle_jtag_flush_queue_sleep)
1217 {
1218  if (CMD_ARGC != 1)
1220 
1221  int sleep_ms;
1223 
1225 
1226  return ERROR_OK;
1227 }
1228 
1229 COMMAND_HANDLER(handle_wait_srst_deassert)
1230 {
1231  if (CMD_ARGC != 1)
1233 
1234  int timeout_ms;
1235  COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], timeout_ms);
1236  if ((timeout_ms <= 0) || (timeout_ms > 100000)) {
1237  LOG_ERROR("Timeout must be an integer between 0 and 100000");
1238  return ERROR_FAIL;
1239  }
1240 
1241  LOG_USER("Waiting for srst assert + deassert for at most %dms", timeout_ms);
1242  int asserted_yet;
1243  int64_t then = timeval_ms();
1244  while (jtag_srst_asserted(&asserted_yet) == ERROR_OK) {
1245  if ((timeval_ms() - then) > timeout_ms) {
1246  LOG_ERROR("Timed out");
1247  return ERROR_FAIL;
1248  }
1249  if (asserted_yet)
1250  break;
1251  }
1252  while (jtag_srst_asserted(&asserted_yet) == ERROR_OK) {
1253  if ((timeval_ms() - then) > timeout_ms) {
1254  LOG_ERROR("Timed out");
1255  return ERROR_FAIL;
1256  }
1257  if (!asserted_yet)
1258  break;
1259  }
1260 
1261  return ERROR_OK;
1262 }
1263 
1264 static const struct command_registration jtag_command_handlers[] = {
1265 
1266  {
1267  .name = "jtag_flush_queue_sleep",
1268  .handler = handle_jtag_flush_queue_sleep,
1269  .mode = COMMAND_ANY,
1270  .help = "For debug purposes(simulate long delays of interface) "
1271  "to test performance or change in behavior. Default 0ms.",
1272  .usage = "[sleep in ms]",
1273  },
1274  {
1275  .name = "jtag_rclk",
1276  .handler = handle_jtag_rclk_command,
1277  .mode = COMMAND_ANY,
1278  .help = "With an argument, change to to use adaptive clocking "
1279  "if possible; else to use the fallback speed. "
1280  "With or without argument, display current setting.",
1281  .usage = "[fallback_speed_khz]",
1282  },
1283  {
1284  .name = "jtag_ntrst_delay",
1285  .handler = handle_jtag_ntrst_delay_command,
1286  .mode = COMMAND_ANY,
1287  .help = "delay after deasserting trst in ms",
1288  .usage = "[milliseconds]",
1289  },
1290  {
1291  .name = "jtag_ntrst_assert_width",
1292  .handler = handle_jtag_ntrst_assert_width_command,
1293  .mode = COMMAND_ANY,
1294  .help = "delay after asserting trst in ms",
1295  .usage = "[milliseconds]",
1296  },
1297  {
1298  .name = "scan_chain",
1299  .handler = handle_scan_chain_command,
1300  .mode = COMMAND_ANY,
1301  .help = "print current scan chain configuration",
1302  .usage = ""
1303  },
1304  {
1305  .name = "runtest",
1306  .handler = handle_runtest_command,
1307  .mode = COMMAND_EXEC,
1308  .help = "Move to Run-Test/Idle, and issue TCK for num_cycles.",
1309  .usage = "num_cycles"
1310  },
1311  {
1312  .name = "irscan",
1313  .handler = handle_irscan_command,
1314  .mode = COMMAND_EXEC,
1315  .help = "Execute Instruction Register (IR) scan. The "
1316  "specified opcodes are put into each TAP's IR, "
1317  "and other TAPs are put in BYPASS.",
1318  .usage = "[tap_name instruction]* ['-endstate' state_name]",
1319  },
1320  {
1321  .name = "verify_ircapture",
1322  .handler = handle_verify_ircapture_command,
1323  .mode = COMMAND_ANY,
1324  .help = "Display or assign flag controlling whether to "
1325  "verify values captured during Capture-IR.",
1326  .usage = "['enable'|'disable']",
1327  },
1328  {
1329  .name = "verify_jtag",
1330  .handler = handle_verify_jtag_command,
1331  .mode = COMMAND_ANY,
1332  .help = "Display or assign flag controlling whether to "
1333  "verify values captured during IR and DR scans.",
1334  .usage = "['enable'|'disable']",
1335  },
1336  {
1337  .name = "tms_sequence",
1338  .handler = handle_tms_sequence_command,
1339  .mode = COMMAND_ANY,
1340  .help = "Display or change what style TMS sequences to use "
1341  "for JTAG state transitions: short (default) or "
1342  "long. Only for working around JTAG bugs.",
1343  /* Specifically for working around DRIVER bugs... */
1344  .usage = "['short'|'long']",
1345  },
1346  {
1347  .name = "wait_srst_deassert",
1348  .handler = handle_wait_srst_deassert,
1349  .mode = COMMAND_ANY,
1350  .help = "Wait for an SRST deassert. "
1351  "Useful for cases where you need something to happen within ms "
1352  "of an srst deassert. Timeout in ms",
1353  .usage = "ms",
1354  },
1355  {
1356  .name = "jtag",
1357  .mode = COMMAND_ANY,
1358  .help = "perform jtag tap actions",
1359  .usage = "",
1360 
1361  .chain = jtag_subcommand_handlers,
1362  },
1363  {
1365  },
1367 };
1368 
1370 {
1371  return register_commands(cmd_ctx, NULL, jtag_command_handlers);
1372 }
int adapter_config_rclk(unsigned int fallback_speed_khz)
Attempt to enable RTCK/RCLK.
Definition: adapter.c:258
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
Definition: adapter.c:208
int adapter_get_speed_readable(int *khz)
Given a speed setting, use the interface speed_div callback to adjust the setting.
Definition: adapter.c:284
bool transport_is_swd(void)
Returns true if the current debug session is using SWD as its transport.
Definition: adi_v5_swd.c:728
uint32_t bits
Definition: armv4_5.c:359
char * buf_to_hex_str(const void *_buf, unsigned buf_len)
Definition: binarybuffer.c:192
int str_to_buf(const char *str, unsigned str_len, void *_buf, unsigned buf_len, unsigned radix)
Definition: binarybuffer.c:233
static void buf_set_u64(uint8_t *_buffer, unsigned first, unsigned num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:60
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
Definition: binarybuffer.h:98
struct command_context * current_command_context(Jim_Interp *interp)
Definition: command.c:187
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:473
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:140
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:155
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:385
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:150
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
Definition: command.h:507
#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...
Definition: command.h:425
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:145
static struct command * jim_to_command(Jim_Interp *interp)
Definition: command.h:206
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
Definition: command.h:268
@ COMMAND_CONFIG
Definition: command.h:41
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
void tap_use_new_tms_table(bool use_new)
Allow switching between old and new TMS tables.
Definition: interface.c:447
bool tap_uses_new_tms_table(void)
Definition: interface.c:451
tap_state_t tap_state_by_name(const char *name)
Provides user-friendly name lookup of TAP states.
Definition: interface.c:355
Exports the list of JTAG interface drivers, along with routines for loading and unloading them dynami...
int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Remove argv[0] as wide.
Definition: jim-nvp.c:221
int jim_getopt_setup(struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
Definition: jim-nvp.c:148
int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len)
Remove argv[0] as string.
Definition: jim-nvp.c:187
int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *nvp, struct jim_nvp **puthere)
Remove argv[0] as NVP.
Definition: jim-nvp.c:236
void jim_getopt_nvp_unknown(struct jim_getopt_info *goi, const struct jim_nvp *nvptable, int hadprefix)
Create an appropriate error message for an NVP.
Definition: jim-nvp.c:252
int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
Remove argv[0] from the list.
Definition: jim-nvp.c:168
struct jim_nvp * jim_nvp_value2name_simple(const struct jim_nvp *p, int value)
Definition: jim-nvp.c:123
struct jtag_tap * jtag_tap_by_string(const char *s)
Definition: jtag/core.c:237
int jtag_init_inner(struct command_context *cmd_ctx)
Definition: jtag/core.c:1503
void jtag_set_ntrst_assert_width(unsigned delay)
Definition: jtag/core.c:1778
void jtag_add_pathmove(int num_states, const tap_state_t *path)
Application code must assume that interfaces will implement transitions between states with different...
Definition: jtag/core.c:517
void jtag_set_ntrst_delay(unsigned delay)
Definition: jtag/core.c:1760
int jtag_init(struct command_context *cmd_ctx)
Initialize JTAG chain using only a RESET reset.
Definition: jtag/core.c:1664
int jtag_srst_asserted(int *srst_asserted)
Definition: jtag/core.c:1725
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
Definition: jtag/core.c:1828
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1037
unsigned jtag_get_ntrst_delay(void)
Definition: jtag/core.c:1764
void jtag_set_flush_queue_sleep(int ms)
Set ms to sleep after jtag_execute_queue() flushes queue.
Definition: jtag/core.c:118
struct jtag_tap * jtag_all_taps(void)
Definition: jtag/core.c:184
int jtag_add_statemove(tap_state_t goal_state)
jtag_add_statemove() moves from the current state to goal_state.
Definition: jtag/core.c:551
int swd_init_reset(struct command_context *cmd_ctx)
Definition: jtag/core.c:1583
int jtag_get_flush_queue_count(void)
Definition: jtag/core.c:1032
int jtag_init_reset(struct command_context *cmd_ctx)
reset, then initialize JTAG chain
Definition: jtag/core.c:1600
bool jtag_will_verify(void)
Definition: jtag/core.c:1695
int jtag_call_event_callbacks(enum jtag_event event)
Definition: jtag/core.c:324
unsigned jtag_get_ntrst_assert_width(void)
Definition: jtag/core.c:1782
void jtag_set_verify_capture_ir(bool enable)
Enable or disable verification of IR scan checking.
Definition: jtag/core.c:1700
bool jtag_will_verify_capture_ir(void)
Definition: jtag/core.c:1705
void jtag_tap_free(struct jtag_tap *tap)
Definition: jtag/core.c:1481
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap_state_t state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
Definition: jtag/core.c:374
void jtag_add_runtest(int num_cycles, tap_state_t state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
Definition: jtag/core.c:592
void jtag_tap_init(struct jtag_tap *tap)
Definition: jtag/core.c:1446
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
Definition: jtag/core.c:451
void jtag_set_verify(bool enable)
Enable or disable data scan verification checking.
Definition: jtag/core.c:1690
int jtag_register_commands(struct command_context *cmd_ctx)
Definition: jtag/tcl.c:1369
static int jtag_tap_configure_cmd(struct jim_getopt_info *goi, struct jtag_tap *tap)
Definition: jtag/tcl.c:379
static const struct command_registration jtag_command_handlers_to_move[]
Definition: jtag/tcl.c:270
int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:753
static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
Definition: jtag/tcl.c:633
int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:791
static int jim_command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args)
Definition: jtag/tcl.c:253
#define NTAP_OPT_IRMASK
Definition: jtag/tcl.c:456
#define NTAP_OPT_DISABLED
Definition: jtag/tcl.c:459
static const struct jim_nvp nvp_jtag_tap_event[]
Definition: jtag/tcl.c:42
static int is_bad_irval(int ir_length, jim_wide w)
Definition: jtag/tcl.c:422
static int jim_jtag_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:815
#define NTAP_OPT_IRLEN
Definition: jtag/tcl.c:455
jtag_tap_cfg_param
Definition: jtag/tcl.c:298
@ JCFG_IDCODE
Definition: jtag/tcl.c:300
@ JCFG_EVENT
Definition: jtag/tcl.c:299
static struct jim_nvp nvp_config_opts[]
Definition: jtag/tcl.c:303
#define NTAP_OPT_BYPASS
Definition: jtag/tcl.c:462
static bool jtag_tap_disable(struct jtag_tap *t)
Definition: jtag/tcl.c:737
static int jtag_tap_configure_event(struct jim_getopt_info *goi, struct jtag_tap *tap)
Definition: jtag/tcl.c:310
static int jim_newtap_ir_param(struct jim_nvp *n, struct jim_getopt_info *goi, struct jtag_tap *tap)
Definition: jtag/tcl.c:464
#define NTAP_OPT_ENABLED
Definition: jtag/tcl.c:458
static int jim_newtap_cmd(struct jim_getopt_info *goi)
Definition: jtag/tcl.c:510
static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:674
#define NTAP_OPT_EXPECTED_ID
Definition: jtag/tcl.c:460
#define NTAP_OPT_IRCAPTURE
Definition: jtag/tcl.c:457
COMMAND_HANDLER(handle_jtag_init_command)
Definition: jtag/tcl.c:835
static int jim_command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *args)
Definition: jtag/tcl.c:216
static int jim_command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
Definition: jtag/tcl.c:75
static bool scan_is_safe(tap_state_t state)
Definition: jtag/tcl.c:62
#define NTAP_OPT_VERSION
Definition: jtag/tcl.c:461
static int jim_newtap_expected_id(struct jim_nvp *n, struct jim_getopt_info *goi, struct jtag_tap *tap)
Definition: jtag/tcl.c:432
static const struct command_registration jtag_subcommand_handlers[]
Definition: jtag/tcl.c:851
static bool jtag_tap_enable(struct jtag_tap *t)
Definition: jtag/tcl.c:722
int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:715
static const struct command_registration jtag_command_handlers[]
Definition: jtag/tcl.c:1264
void jtag_notify_event(enum jtag_event event)
Report Tcl event to all TAPs.
Definition: jtag/tcl.c:940
struct jtag_tap * jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
Definition: jtag/tcl.c:51
static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Definition: jtag/tcl.c:692
The JTAG interface can be implemented with a software or hardware fifo.
@ TAP_RESET
Definition: jtag.h:55
@ TAP_DRPAUSE
Definition: jtag.h:43
@ TAP_IDLE
Definition: jtag.h:52
@ TAP_IRPAUSE
Definition: jtag.h:51
@ TAP_INVALID
Definition: jtag.h:37
jtag_event
Definition: jtag.h:176
@ JTAG_TAP_EVENT_ENABLE
Definition: jtag.h:179
@ JTAG_TAP_EVENT_SETUP
Definition: jtag.h:178
@ JTAG_TRST_ASSERTED
Definition: jtag.h:177
@ JTAG_TAP_EVENT_DISABLE
Definition: jtag.h:180
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_USER(expr ...)
Definition: log.h:126
#define LOG_WARNING(expr ...)
Definition: log.h:120
#define ERROR_FAIL
Definition: log.h:161
#define LOG_ERROR(expr ...)
Definition: log.h:123
#define LOG_INFO(expr ...)
Definition: log.h:117
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
Jim_Interp * interp
Definition: command.h:53
const char * name
Definition: command.h:229
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
Definition: command.h:243
char * name
Definition: command.h:192
A TCL -ish GetOpt like code.
Definition: jim-nvp.h:135
Jim_Interp * interp
Definition: jim-nvp.h:136
Jim_Obj *const * argv
Definition: jim-nvp.h:138
Name Value Pairs, aka: NVP.
Definition: jim-nvp.h:59
const char * name
Definition: jim-nvp.h:60
int value
Definition: jim-nvp.h:61
struct jtag_tap_event_action * next
Definition: jtag.h:191
enum jtag_event event
The event for which this action will be triggered.
Definition: jtag.h:185
Jim_Obj * body
Contains a script to 'eval' when the event is triggered.
Definition: jtag.h:189
Jim_Interp * interp
The interpreter to use for evaluating the body.
Definition: jtag.h:187
Definition: jtag.h:100
uint32_t ir_capture_value
Definition: jtag.h:110
int abs_chain_position
Definition: jtag.h:104
uint8_t * expected_mask
Capture-IR expected mask.
Definition: jtag.h:113
char * chip
Definition: jtag.h:101
bool ignore_version
Flag saying whether to ignore version field in expected_ids[].
Definition: jtag.h:125
bool disabled_after_reset
Is this TAP disabled after JTAG reset?
Definition: jtag.h:106
struct jtag_tap_event_action * event_action
Definition: jtag.h:135
int ir_length
size of instruction register
Definition: jtag.h:109
uint8_t * expected
Capture-IR expected value.
Definition: jtag.h:111
uint32_t ir_capture_mask
Definition: jtag.h:112
uint8_t expected_ids_cnt
Number of expected identification codes.
Definition: jtag.h:122
char * tapname
Definition: jtag.h:102
bool ignore_bypass
Flag saying whether to ignore the bypass bit in the code.
Definition: jtag.h:128
bool enabled
Is this TAP currently enabled?
Definition: jtag.h:108
uint32_t * expected_ids
Array of expected identification codes.
Definition: jtag.h:120
struct jtag_tap * next_tap
Definition: jtag.h:137
uint32_t idcode
device identification code
Definition: jtag.h:114
char * dotted_name
Definition: jtag.h:103
This structure defines a single scan field in the scan.
Definition: jtag.h:86
int num_bits
The number of bits this field specifies.
Definition: jtag.h:88
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:92
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:90
int64_t timeval_ms(void)
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
#define NULL
Definition: usb.h:16
uint8_t status[4]
Definition: vdebug.c:17
uint8_t state[4]
Definition: vdebug.c:21
#define sleep_ms(ms)