You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1388 lines
35 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * Copyright (C) 2007-2010 Øyvind Harboe *
  6. * oyvind.harboe@zylin.com *
  7. * *
  8. * Copyright (C) 2009 SoftPLC Corporation *
  9. * http://softplc.com *
  10. * dick@softplc.com *
  11. * *
  12. * Copyright (C) 2009 Zachary T Welch *
  13. * zw@superlucidity.net *
  14. * *
  15. * This program is free software; you can redistribute it and/or modify *
  16. * it under the terms of the GNU General Public License as published by *
  17. * the Free Software Foundation; either version 2 of the License, or *
  18. * (at your option) any later version. *
  19. * *
  20. * This program is distributed in the hope that it will be useful, *
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  23. * GNU General Public License for more details. *
  24. * *
  25. * You should have received a copy of the GNU General Public License *
  26. * along with this program; if not, write to the *
  27. * Free Software Foundation, Inc., *
  28. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  29. ***************************************************************************/
  30. #ifdef HAVE_CONFIG_H
  31. #include "config.h"
  32. #endif
  33. #include "jtag.h"
  34. #include "swd.h"
  35. #include "minidriver.h"
  36. #include "interface.h"
  37. #include "interfaces.h"
  38. #include "tcl.h"
  39. #ifdef HAVE_STRINGS_H
  40. #include <strings.h>
  41. #endif
  42. #include <helper/time_support.h>
  43. /**
  44. * @file
  45. * Holds support for accessing JTAG-specific mechanisms from TCl scripts.
  46. */
  47. static const Jim_Nvp nvp_jtag_tap_event[] = {
  48. { .value = JTAG_TRST_ASSERTED, .name = "post-reset" },
  49. { .value = JTAG_TAP_EVENT_SETUP, .name = "setup" },
  50. { .value = JTAG_TAP_EVENT_ENABLE, .name = "tap-enable" },
  51. { .value = JTAG_TAP_EVENT_DISABLE, .name = "tap-disable" },
  52. { .name = NULL, .value = -1 }
  53. };
  54. struct jtag_tap *jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
  55. {
  56. const char *cp = Jim_GetString(o, NULL);
  57. struct jtag_tap *t = cp ? jtag_tap_by_string(cp) : NULL;
  58. if (NULL == cp)
  59. cp = "(unknown)";
  60. if (NULL == t)
  61. Jim_SetResultFormatted(interp, "Tap '%s' could not be found", cp);
  62. return t;
  63. }
  64. static bool scan_is_safe(tap_state_t state)
  65. {
  66. switch (state) {
  67. case TAP_RESET:
  68. case TAP_IDLE:
  69. case TAP_DRPAUSE:
  70. case TAP_IRPAUSE:
  71. return true;
  72. default:
  73. return false;
  74. }
  75. }
  76. static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
  77. {
  78. int retval;
  79. struct scan_field *fields;
  80. int num_fields;
  81. int field_count = 0;
  82. int i, e;
  83. struct jtag_tap *tap;
  84. tap_state_t endstate;
  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. endstate = TAP_IDLE;
  99. script_debug(interp, "drscan", argc, args);
  100. /* validate arguments as numbers */
  101. e = JIM_OK;
  102. for (i = 2; i < argc; i += 2) {
  103. long bits;
  104. const char *cp;
  105. e = Jim_GetLong(interp, args[i], &bits);
  106. /* If valid - try next arg */
  107. if (e == JIM_OK)
  108. continue;
  109. /* Not valid.. are we at the end? */
  110. if (((i + 2) != argc)) {
  111. /* nope, then error */
  112. return e;
  113. }
  114. /* it could be: "-endstate FOO"
  115. * e.g. DRPAUSE so we can issue more instructions
  116. * before entering RUN/IDLE and executing them.
  117. */
  118. /* get arg as a string. */
  119. cp = Jim_GetString(args[i], NULL);
  120. /* is it the magic? */
  121. if (0 == strcmp("-endstate", cp)) {
  122. /* is the statename valid? */
  123. cp = Jim_GetString(args[i + 1], NULL);
  124. /* see if it is a valid state name */
  125. endstate = tap_state_by_name(cp);
  126. if (endstate < 0) {
  127. /* update the error message */
  128. Jim_SetResultFormatted(interp, "endstate: %s invalid", cp);
  129. } else {
  130. if (!scan_is_safe(endstate))
  131. LOG_WARNING("drscan with unsafe "
  132. "endstate \"%s\"", cp);
  133. /* valid - so clear the error */
  134. e = JIM_OK;
  135. /* and remove the last 2 args */
  136. argc -= 2;
  137. }
  138. }
  139. /* Still an error? */
  140. if (e != JIM_OK)
  141. return e; /* too bad */
  142. } /* validate args */
  143. assert(e == JIM_OK);
  144. tap = jtag_tap_by_jim_obj(interp, args[1]);
  145. if (tap == NULL)
  146. return JIM_ERR;
  147. num_fields = (argc-2)/2;
  148. if (num_fields <= 0) {
  149. Jim_SetResultString(interp, "drscan: no scan fields supplied", -1);
  150. return JIM_ERR;
  151. }
  152. fields = malloc(sizeof(struct scan_field) * num_fields);
  153. for (i = 2; i < argc; i += 2) {
  154. long bits;
  155. int len;
  156. const char *str;
  157. Jim_GetLong(interp, args[i], &bits);
  158. str = Jim_GetString(args[i + 1], &len);
  159. fields[field_count].num_bits = bits;
  160. void *t = malloc(DIV_ROUND_UP(bits, 8));
  161. fields[field_count].out_value = t;
  162. str_to_buf(str, len, t, bits, 0);
  163. fields[field_count].in_value = t;
  164. field_count++;
  165. }
  166. jtag_add_dr_scan(tap, num_fields, fields, endstate);
  167. retval = jtag_execute_queue();
  168. if (retval != ERROR_OK) {
  169. Jim_SetResultString(interp, "drscan: jtag execute failed", -1);
  170. return JIM_ERR;
  171. }
  172. field_count = 0;
  173. Jim_Obj *list = Jim_NewListObj(interp, NULL, 0);
  174. for (i = 2; i < argc; i += 2) {
  175. long bits;
  176. char *str;
  177. Jim_GetLong(interp, args[i], &bits);
  178. str = buf_to_str(fields[field_count].in_value, bits, 16);
  179. free(fields[field_count].in_value);
  180. Jim_ListAppendElement(interp, list, Jim_NewStringObj(interp, str, strlen(str)));
  181. free(str);
  182. field_count++;
  183. }
  184. Jim_SetResult(interp, list);
  185. free(fields);
  186. return JIM_OK;
  187. }
  188. static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *args)
  189. {
  190. tap_state_t states[8];
  191. if ((argc < 2) || ((size_t)argc > (ARRAY_SIZE(states) + 1))) {
  192. Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
  193. return JIM_ERR;
  194. }
  195. script_debug(interp, "pathmove", argc, args);
  196. int i;
  197. for (i = 0; i < argc-1; i++) {
  198. const char *cp;
  199. cp = Jim_GetString(args[i + 1], NULL);
  200. states[i] = tap_state_by_name(cp);
  201. if (states[i] < 0) {
  202. /* update the error message */
  203. Jim_SetResultFormatted(interp, "endstate: %s invalid", cp);
  204. return JIM_ERR;
  205. }
  206. }
  207. if ((jtag_add_statemove(states[0]) != ERROR_OK) || (jtag_execute_queue() != ERROR_OK)) {
  208. Jim_SetResultString(interp, "pathmove: jtag execute failed", -1);
  209. return JIM_ERR;
  210. }
  211. jtag_add_pathmove(argc - 2, states + 1);
  212. if (jtag_execute_queue() != ERROR_OK) {
  213. Jim_SetResultString(interp, "pathmove: failed", -1);
  214. return JIM_ERR;
  215. }
  216. return JIM_OK;
  217. }
  218. static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args)
  219. {
  220. script_debug(interp, "flush_count", argc, args);
  221. Jim_SetResult(interp, Jim_NewIntObj(interp, jtag_get_flush_queue_count()));
  222. return JIM_OK;
  223. }
  224. /* REVISIT Just what about these should "move" ... ?
  225. * These registrations, into the main JTAG table?
  226. *
  227. * There's a minor compatibility issue, these all show up twice;
  228. * that's not desirable:
  229. * - jtag drscan ... NOT DOCUMENTED!
  230. * - drscan ...
  231. *
  232. * The "irscan" command (for example) doesn't show twice.
  233. */
  234. static const struct command_registration jtag_command_handlers_to_move[] = {
  235. {
  236. .name = "drscan",
  237. .mode = COMMAND_EXEC,
  238. .jim_handler = Jim_Command_drscan,
  239. .help = "Execute Data Register (DR) scan for one TAP. "
  240. "Other TAPs must be in BYPASS mode.",
  241. .usage = "tap_name [num_bits value]* ['-endstate' state_name]",
  242. },
  243. {
  244. .name = "flush_count",
  245. .mode = COMMAND_EXEC,
  246. .jim_handler = Jim_Command_flush_count,
  247. .help = "Returns the number of times the JTAG queue "
  248. "has been flushed.",
  249. },
  250. {
  251. .name = "pathmove",
  252. .mode = COMMAND_EXEC,
  253. .jim_handler = Jim_Command_pathmove,
  254. .usage = "start_state state1 [state2 [state3 ...]]",
  255. .help = "Move JTAG state machine from current state "
  256. "(start_state) to state1, then state2, state3, etc.",
  257. },
  258. COMMAND_REGISTRATION_DONE
  259. };
  260. enum jtag_tap_cfg_param {
  261. JCFG_EVENT
  262. };
  263. static Jim_Nvp nvp_config_opts[] = {
  264. { .name = "-event", .value = JCFG_EVENT },
  265. { .name = NULL, .value = -1 }
  266. };
  267. static int jtag_tap_configure_event(Jim_GetOptInfo *goi, struct jtag_tap *tap)
  268. {
  269. if (goi->argc == 0) {
  270. Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event <event-name> ...");
  271. return JIM_ERR;
  272. }
  273. Jim_Nvp *n;
  274. int e = Jim_GetOpt_Nvp(goi, nvp_jtag_tap_event, &n);
  275. if (e != JIM_OK) {
  276. Jim_GetOpt_NvpUnknown(goi, nvp_jtag_tap_event, 1);
  277. return e;
  278. }
  279. if (goi->isconfigure) {
  280. if (goi->argc != 1) {
  281. Jim_WrongNumArgs(goi->interp,
  282. goi->argc,
  283. goi->argv,
  284. "-event <event-name> <event-body>");
  285. return JIM_ERR;
  286. }
  287. } else {
  288. if (goi->argc != 0) {
  289. Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event <event-name>");
  290. return JIM_ERR;
  291. }
  292. }
  293. struct jtag_tap_event_action *jteap = tap->event_action;
  294. /* replace existing event body */
  295. bool found = false;
  296. while (jteap) {
  297. if (jteap->event == (enum jtag_event)n->value) {
  298. found = true;
  299. break;
  300. }
  301. jteap = jteap->next;
  302. }
  303. Jim_SetEmptyResult(goi->interp);
  304. if (goi->isconfigure) {
  305. if (!found)
  306. jteap = calloc(1, sizeof(*jteap));
  307. else if (NULL != jteap->body)
  308. Jim_DecrRefCount(goi->interp, jteap->body);
  309. jteap->interp = goi->interp;
  310. jteap->event = n->value;
  311. Jim_Obj *o;
  312. Jim_GetOpt_Obj(goi, &o);
  313. jteap->body = Jim_DuplicateObj(goi->interp, o);
  314. Jim_IncrRefCount(jteap->body);
  315. if (!found) {
  316. /* add to head of event list */
  317. jteap->next = tap->event_action;
  318. tap->event_action = jteap;
  319. }
  320. } else if (found) {
  321. jteap->interp = goi->interp;
  322. Jim_SetResult(goi->interp,
  323. Jim_DuplicateObj(goi->interp, jteap->body));
  324. }
  325. return JIM_OK;
  326. }
  327. static int jtag_tap_configure_cmd(Jim_GetOptInfo *goi, struct jtag_tap *tap)
  328. {
  329. /* parse config or cget options */
  330. while (goi->argc > 0) {
  331. Jim_SetEmptyResult(goi->interp);
  332. Jim_Nvp *n;
  333. int e = Jim_GetOpt_Nvp(goi, nvp_config_opts, &n);
  334. if (e != JIM_OK) {
  335. Jim_GetOpt_NvpUnknown(goi, nvp_config_opts, 0);
  336. return e;
  337. }
  338. switch (n->value) {
  339. case JCFG_EVENT:
  340. e = jtag_tap_configure_event(goi, tap);
  341. if (e != JIM_OK)
  342. return e;
  343. break;
  344. default:
  345. Jim_SetResultFormatted(goi->interp, "unknown event: %s", n->name);
  346. return JIM_ERR;
  347. }
  348. }
  349. return JIM_OK;
  350. }
  351. static int is_bad_irval(int ir_length, jim_wide w)
  352. {
  353. jim_wide v = 1;
  354. v <<= ir_length;
  355. v -= 1;
  356. v = ~v;
  357. return (w & v) != 0;
  358. }
  359. static int jim_newtap_expected_id(Jim_Nvp *n, Jim_GetOptInfo *goi,
  360. struct jtag_tap *pTap)
  361. {
  362. jim_wide w;
  363. int e = Jim_GetOpt_Wide(goi, &w);
  364. if (e != JIM_OK) {
  365. Jim_SetResultFormatted(goi->interp, "option: %s bad parameter", n->name);
  366. return e;
  367. }
  368. uint32_t *p = realloc(pTap->expected_ids,
  369. (pTap->expected_ids_cnt + 1) * sizeof(uint32_t));
  370. if (!p) {
  371. Jim_SetResultFormatted(goi->interp, "no memory");
  372. return JIM_ERR;
  373. }
  374. pTap->expected_ids = p;
  375. pTap->expected_ids[pTap->expected_ids_cnt++] = w;
  376. return JIM_OK;
  377. }
  378. #define NTAP_OPT_IRLEN 0
  379. #define NTAP_OPT_IRMASK 1
  380. #define NTAP_OPT_IRCAPTURE 2
  381. #define NTAP_OPT_ENABLED 3
  382. #define NTAP_OPT_DISABLED 4
  383. #define NTAP_OPT_EXPECTED_ID 5
  384. #define NTAP_OPT_VERSION 6
  385. static int jim_newtap_ir_param(Jim_Nvp *n, Jim_GetOptInfo *goi,
  386. struct jtag_tap *pTap)
  387. {
  388. jim_wide w;
  389. int e = Jim_GetOpt_Wide(goi, &w);
  390. if (e != JIM_OK) {
  391. Jim_SetResultFormatted(goi->interp,
  392. "option: %s bad parameter", n->name);
  393. return e;
  394. }
  395. switch (n->value) {
  396. case NTAP_OPT_IRLEN:
  397. if (w > (jim_wide) (8 * sizeof(pTap->ir_capture_value))) {
  398. LOG_WARNING("%s: huge IR length %d",
  399. pTap->dotted_name, (int) w);
  400. }
  401. pTap->ir_length = w;
  402. break;
  403. case NTAP_OPT_IRMASK:
  404. if (is_bad_irval(pTap->ir_length, w)) {
  405. LOG_ERROR("%s: IR mask %x too big",
  406. pTap->dotted_name,
  407. (int) w);
  408. return JIM_ERR;
  409. }
  410. if ((w & 3) != 3)
  411. LOG_WARNING("%s: nonstandard IR mask", pTap->dotted_name);
  412. pTap->ir_capture_mask = w;
  413. break;
  414. case NTAP_OPT_IRCAPTURE:
  415. if (is_bad_irval(pTap->ir_length, w)) {
  416. LOG_ERROR("%s: IR capture %x too big",
  417. pTap->dotted_name, (int) w);
  418. return JIM_ERR;
  419. }
  420. if ((w & 3) != 1)
  421. LOG_WARNING("%s: nonstandard IR value",
  422. pTap->dotted_name);
  423. pTap->ir_capture_value = w;
  424. break;
  425. default:
  426. return JIM_ERR;
  427. }
  428. return JIM_OK;
  429. }
  430. static int jim_newtap_cmd(Jim_GetOptInfo *goi)
  431. {
  432. struct jtag_tap *pTap;
  433. int x;
  434. int e;
  435. Jim_Nvp *n;
  436. char *cp;
  437. const Jim_Nvp opts[] = {
  438. { .name = "-irlen", .value = NTAP_OPT_IRLEN },
  439. { .name = "-irmask", .value = NTAP_OPT_IRMASK },
  440. { .name = "-ircapture", .value = NTAP_OPT_IRCAPTURE },
  441. { .name = "-enable", .value = NTAP_OPT_ENABLED },
  442. { .name = "-disable", .value = NTAP_OPT_DISABLED },
  443. { .name = "-expected-id", .value = NTAP_OPT_EXPECTED_ID },
  444. { .name = "-ignore-version", .value = NTAP_OPT_VERSION },
  445. { .name = NULL, .value = -1 },
  446. };
  447. pTap = calloc(1, sizeof(struct jtag_tap));
  448. if (!pTap) {
  449. Jim_SetResultFormatted(goi->interp, "no memory");
  450. return JIM_ERR;
  451. }
  452. /*
  453. * we expect CHIP + TAP + OPTIONS
  454. * */
  455. if (goi->argc < 3) {
  456. Jim_SetResultFormatted(goi->interp, "Missing CHIP TAP OPTIONS ....");
  457. free(pTap);
  458. return JIM_ERR;
  459. }
  460. Jim_GetOpt_String(goi, &cp, NULL);
  461. pTap->chip = strdup(cp);
  462. Jim_GetOpt_String(goi, &cp, NULL);
  463. pTap->tapname = strdup(cp);
  464. /* name + dot + name + null */
  465. x = strlen(pTap->chip) + 1 + strlen(pTap->tapname) + 1;
  466. cp = malloc(x);
  467. sprintf(cp, "%s.%s", pTap->chip, pTap->tapname);
  468. pTap->dotted_name = cp;
  469. LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
  470. pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc);
  471. if (!transport_is_jtag()) {
  472. /* SWD doesn't require any JTAG tap parameters */
  473. pTap->enabled = true;
  474. jtag_tap_init(pTap);
  475. return JIM_OK;
  476. }
  477. /* IEEE specifies that the two LSBs of an IR scan are 01, so make
  478. * that the default. The "-ircapture" and "-irmask" options are only
  479. * needed to cope with nonstandard TAPs, or to specify more bits.
  480. */
  481. pTap->ir_capture_mask = 0x03;
  482. pTap->ir_capture_value = 0x01;
  483. while (goi->argc) {
  484. e = Jim_GetOpt_Nvp(goi, opts, &n);
  485. if (e != JIM_OK) {
  486. Jim_GetOpt_NvpUnknown(goi, opts, 0);
  487. free(cp);
  488. free(pTap);
  489. return e;
  490. }
  491. LOG_DEBUG("Processing option: %s", n->name);
  492. switch (n->value) {
  493. case NTAP_OPT_ENABLED:
  494. pTap->disabled_after_reset = false;
  495. break;
  496. case NTAP_OPT_DISABLED:
  497. pTap->disabled_after_reset = true;
  498. break;
  499. case NTAP_OPT_EXPECTED_ID:
  500. e = jim_newtap_expected_id(n, goi, pTap);
  501. if (JIM_OK != e) {
  502. free(cp);
  503. free(pTap);
  504. return e;
  505. }
  506. break;
  507. case NTAP_OPT_IRLEN:
  508. case NTAP_OPT_IRMASK:
  509. case NTAP_OPT_IRCAPTURE:
  510. e = jim_newtap_ir_param(n, goi, pTap);
  511. if (JIM_OK != e) {
  512. free(cp);
  513. free(pTap);
  514. return e;
  515. }
  516. break;
  517. case NTAP_OPT_VERSION:
  518. pTap->ignore_version = true;
  519. break;
  520. } /* switch (n->value) */
  521. } /* while (goi->argc) */
  522. /* default is enabled-after-reset */
  523. pTap->enabled = !pTap->disabled_after_reset;
  524. /* Did all the required option bits get cleared? */
  525. if (pTap->ir_length != 0) {
  526. jtag_tap_init(pTap);
  527. return JIM_OK;
  528. }
  529. Jim_SetResultFormatted(goi->interp,
  530. "newtap: %s missing IR length",
  531. pTap->dotted_name);
  532. jtag_tap_free(pTap);
  533. return JIM_ERR;
  534. }
  535. static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
  536. {
  537. struct jtag_tap_event_action *jteap;
  538. for (jteap = tap->event_action; jteap != NULL; jteap = jteap->next) {
  539. if (jteap->event != e)
  540. continue;
  541. Jim_Nvp *nvp = Jim_Nvp_value2name_simple(nvp_jtag_tap_event, e);
  542. LOG_DEBUG("JTAG tap: %s event: %d (%s)\n\taction: %s",
  543. tap->dotted_name, e, nvp->name,
  544. Jim_GetString(jteap->body, NULL));
  545. if (Jim_EvalObj(jteap->interp, jteap->body) != JIM_OK) {
  546. Jim_MakeErrorMessage(jteap->interp);
  547. LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap->interp), NULL));
  548. continue;
  549. }
  550. switch (e) {
  551. case JTAG_TAP_EVENT_ENABLE:
  552. case JTAG_TAP_EVENT_DISABLE:
  553. /* NOTE: we currently assume the handlers
  554. * can't fail. Right here is where we should
  555. * really be verifying the scan chains ...
  556. */
  557. tap->enabled = (e == JTAG_TAP_EVENT_ENABLE);
  558. LOG_INFO("JTAG tap: %s %s", tap->dotted_name,
  559. tap->enabled ? "enabled" : "disabled");
  560. break;
  561. default:
  562. break;
  563. }
  564. }
  565. }
  566. static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
  567. {
  568. Jim_GetOptInfo goi;
  569. Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
  570. if (goi.argc != 0) {
  571. Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
  572. return JIM_ERR;
  573. }
  574. struct command_context *context = current_command_context(interp);
  575. int e = jtag_init_inner(context);
  576. if (e != ERROR_OK) {
  577. Jim_Obj *eObj = Jim_NewIntObj(goi.interp, e);
  578. Jim_SetResultFormatted(goi.interp, "error: %#s", eObj);
  579. Jim_FreeNewObj(goi.interp, eObj);
  580. return JIM_ERR;
  581. }
  582. return JIM_OK;
  583. }
  584. static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
  585. {
  586. int e = ERROR_OK;
  587. Jim_GetOptInfo goi;
  588. Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
  589. if (goi.argc != 0) {
  590. Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
  591. return JIM_ERR;
  592. }
  593. struct command_context *context = current_command_context(interp);
  594. if (transport_is_jtag())
  595. e = jtag_init_reset(context);
  596. else if (transport_is_swd())
  597. e = swd_init_reset(context);
  598. if (e != ERROR_OK) {
  599. Jim_Obj *eObj = Jim_NewIntObj(goi.interp, e);
  600. Jim_SetResultFormatted(goi.interp, "error: %#s", eObj);
  601. Jim_FreeNewObj(goi.interp, eObj);
  602. return JIM_ERR;
  603. }
  604. return JIM_OK;
  605. }
  606. int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
  607. {
  608. Jim_GetOptInfo goi;
  609. Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
  610. return jim_newtap_cmd(&goi);
  611. }
  612. static bool jtag_tap_enable(struct jtag_tap *t)
  613. {
  614. if (t->enabled)
  615. return false;
  616. jtag_tap_handle_event(t, JTAG_TAP_EVENT_ENABLE);
  617. if (!t->enabled)
  618. return false;
  619. /* FIXME add JTAG sanity checks, w/o TLR
  620. * - scan chain length grew by one (this)
  621. * - IDs and IR lengths are as expected
  622. */
  623. jtag_call_event_callbacks(JTAG_TAP_EVENT_ENABLE);
  624. return true;
  625. }
  626. static bool jtag_tap_disable(struct jtag_tap *t)
  627. {
  628. if (!t->enabled)
  629. return false;
  630. jtag_tap_handle_event(t, JTAG_TAP_EVENT_DISABLE);
  631. if (t->enabled)
  632. return false;
  633. /* FIXME add JTAG sanity checks, w/o TLR
  634. * - scan chain length shrank by one (this)
  635. * - IDs and IR lengths are as expected
  636. */
  637. jtag_call_event_callbacks(JTAG_TAP_EVENT_DISABLE);
  638. return true;
  639. }
  640. int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
  641. {
  642. const char *cmd_name = Jim_GetString(argv[0], NULL);
  643. Jim_GetOptInfo goi;
  644. Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
  645. if (goi.argc != 1) {
  646. Jim_SetResultFormatted(goi.interp, "usage: %s <name>", cmd_name);
  647. return JIM_ERR;
  648. }
  649. struct jtag_tap *t;
  650. t = jtag_tap_by_jim_obj(goi.interp, goi.argv[0]);
  651. if (t == NULL)
  652. return JIM_ERR;
  653. if (strcasecmp(cmd_name, "tapisenabled") == 0) {
  654. /* do nothing, just return the value */
  655. } else if (strcasecmp(cmd_name, "tapenable") == 0) {
  656. if (!jtag_tap_enable(t)) {
  657. LOG_WARNING("failed to enable tap %s", t->dotted_name);
  658. return JIM_ERR;
  659. }
  660. } else if (strcasecmp(cmd_name, "tapdisable") == 0) {
  661. if (!jtag_tap_disable(t)) {
  662. LOG_WARNING("failed to disable tap %s", t->dotted_name);
  663. return JIM_ERR;
  664. }
  665. } else {
  666. LOG_ERROR("command '%s' unknown", cmd_name);
  667. return JIM_ERR;
  668. }
  669. bool e = t->enabled;
  670. Jim_SetResult(goi.interp, Jim_NewIntObj(goi.interp, e));
  671. return JIM_OK;
  672. }
  673. int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
  674. {
  675. const char *cmd_name = Jim_GetString(argv[0], NULL);
  676. Jim_GetOptInfo goi;
  677. Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
  678. goi.isconfigure = !strcmp(cmd_name, "configure");
  679. if (goi.argc < 2 + goi.isconfigure) {
  680. Jim_WrongNumArgs(goi.interp, 0, NULL,
  681. "<tap_name> <attribute> ...");
  682. return JIM_ERR;
  683. }
  684. struct jtag_tap *t;
  685. Jim_Obj *o;
  686. Jim_GetOpt_Obj(&goi, &o);
  687. t = jtag_tap_by_jim_obj(goi.interp, o);
  688. if (t == NULL)
  689. return JIM_ERR;
  690. return jtag_tap_configure_cmd(&goi, t);
  691. }
  692. static int jim_jtag_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
  693. {
  694. Jim_GetOptInfo goi;
  695. Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
  696. if (goi.argc != 0) {
  697. Jim_WrongNumArgs(goi.interp, 1, goi.argv, "Too many parameters");
  698. return JIM_ERR;
  699. }
  700. Jim_SetResult(goi.interp, Jim_NewListObj(goi.interp, NULL, 0));
  701. struct jtag_tap *tap;
  702. for (tap = jtag_all_taps(); tap; tap = tap->next_tap) {
  703. Jim_ListAppendElement(goi.interp,
  704. Jim_GetResult(goi.interp),
  705. Jim_NewStringObj(goi.interp,
  706. tap->dotted_name, -1));
  707. }
  708. return JIM_OK;
  709. }
  710. COMMAND_HANDLER(handle_jtag_init_command)
  711. {
  712. if (CMD_ARGC != 0)
  713. return ERROR_COMMAND_SYNTAX_ERROR;
  714. static bool jtag_initialized;
  715. if (jtag_initialized) {
  716. LOG_INFO("'jtag init' has already been called");
  717. return ERROR_OK;
  718. }
  719. jtag_initialized = true;
  720. LOG_DEBUG("Initializing jtag devices...");
  721. return jtag_init(CMD_CTX);
  722. }
  723. static const struct command_registration jtag_subcommand_handlers[] = {
  724. {
  725. .name = "init",
  726. .mode = COMMAND_ANY,
  727. .handler = handle_jtag_init_command,
  728. .help = "initialize jtag scan chain",
  729. .usage = ""
  730. },
  731. {
  732. .name = "arp_init",
  733. .mode = COMMAND_ANY,
  734. .jim_handler = jim_jtag_arp_init,
  735. .help = "Validates JTAG scan chain against the list of "
  736. "declared TAPs using just the four standard JTAG "
  737. "signals.",
  738. },
  739. {
  740. .name = "arp_init-reset",
  741. .mode = COMMAND_ANY,
  742. .jim_handler = jim_jtag_arp_init_reset,
  743. .help = "Uses TRST and SRST to try resetting everything on "
  744. "the JTAG scan chain, then performs 'jtag arp_init'."
  745. },
  746. {
  747. .name = "newtap",
  748. .mode = COMMAND_CONFIG,
  749. .jim_handler = jim_jtag_newtap,
  750. .help = "Create a new TAP instance named basename.tap_type, "
  751. "and appends it to the scan chain.",
  752. .usage = "basename tap_type '-irlen' count "
  753. "['-enable'|'-disable'] "
  754. "['-expected_id' number] "
  755. "['-ignore-version'] "
  756. "['-ircapture' number] "
  757. "['-mask' number] ",
  758. },
  759. {
  760. .name = "tapisenabled",
  761. .mode = COMMAND_EXEC,
  762. .jim_handler = jim_jtag_tap_enabler,
  763. .help = "Returns a Tcl boolean (0/1) indicating whether "
  764. "the TAP is enabled (1) or not (0).",
  765. .usage = "tap_name",
  766. },
  767. {
  768. .name = "tapenable",
  769. .mode = COMMAND_EXEC,
  770. .jim_handler = jim_jtag_tap_enabler,
  771. .help = "Try to enable the specified TAP using the "
  772. "'tap-enable' TAP event.",
  773. .usage = "tap_name",
  774. },
  775. {
  776. .name = "tapdisable",
  777. .mode = COMMAND_EXEC,
  778. .jim_handler = jim_jtag_tap_enabler,
  779. .help = "Try to disable the specified TAP using the "
  780. "'tap-disable' TAP event.",
  781. .usage = "tap_name",
  782. },
  783. {
  784. .name = "configure",
  785. .mode = COMMAND_EXEC,
  786. .jim_handler = jim_jtag_configure,
  787. .help = "Provide a Tcl handler for the specified "
  788. "TAP event.",
  789. .usage = "tap_name '-event' event_name handler",
  790. },
  791. {
  792. .name = "cget",
  793. .mode = COMMAND_EXEC,
  794. .jim_handler = jim_jtag_configure,
  795. .help = "Return any Tcl handler for the specified "
  796. "TAP event.",
  797. .usage = "tap_name '-event' event_name",
  798. },
  799. {
  800. .name = "names",
  801. .mode = COMMAND_ANY,
  802. .jim_handler = jim_jtag_names,
  803. .help = "Returns list of all JTAG tap names.",
  804. },
  805. {
  806. .chain = jtag_command_handlers_to_move,
  807. },
  808. COMMAND_REGISTRATION_DONE
  809. };
  810. void jtag_notify_event(enum jtag_event event)
  811. {
  812. struct jtag_tap *tap;
  813. for (tap = jtag_all_taps(); tap; tap = tap->next_tap)
  814. jtag_tap_handle_event(tap, event);
  815. }
  816. COMMAND_HANDLER(handle_scan_chain_command)
  817. {
  818. struct jtag_tap *tap;
  819. char expected_id[12];
  820. tap = jtag_all_taps();
  821. command_print(CMD_CTX,
  822. " TapName Enabled IdCode Expected IrLen IrCap IrMask");
  823. command_print(CMD_CTX,
  824. "-- ------------------- -------- ---------- ---------- ----- ----- ------");
  825. while (tap) {
  826. uint32_t expected, expected_mask, ii;
  827. snprintf(expected_id, sizeof expected_id, "0x%08x",
  828. (unsigned)((tap->expected_ids_cnt > 0)
  829. ? tap->expected_ids[0]
  830. : 0));
  831. if (tap->ignore_version)
  832. expected_id[2] = '*';
  833. expected = buf_get_u32(tap->expected, 0, tap->ir_length);
  834. expected_mask = buf_get_u32(tap->expected_mask, 0, tap->ir_length);
  835. command_print(CMD_CTX,
  836. "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x",
  837. tap->abs_chain_position,
  838. tap->dotted_name,
  839. tap->enabled ? 'Y' : 'n',
  840. (unsigned int)(tap->idcode),
  841. expected_id,
  842. (unsigned int)(tap->ir_length),
  843. (unsigned int)(expected),
  844. (unsigned int)(expected_mask));
  845. for (ii = 1; ii < tap->expected_ids_cnt; ii++) {
  846. snprintf(expected_id, sizeof expected_id, "0x%08x",
  847. (unsigned) tap->expected_ids[ii]);
  848. if (tap->ignore_version)
  849. expected_id[2] = '*';
  850. command_print(CMD_CTX,
  851. " %s",
  852. expected_id);
  853. }
  854. tap = tap->next_tap;
  855. }
  856. return ERROR_OK;
  857. }
  858. COMMAND_HANDLER(handle_jtag_ntrst_delay_command)
  859. {
  860. if (CMD_ARGC > 1)
  861. return ERROR_COMMAND_SYNTAX_ERROR;
  862. if (CMD_ARGC == 1) {
  863. unsigned delay;
  864. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
  865. jtag_set_ntrst_delay(delay);
  866. }
  867. command_print(CMD_CTX, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
  868. return ERROR_OK;
  869. }
  870. COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command)
  871. {
  872. if (CMD_ARGC > 1)
  873. return ERROR_COMMAND_SYNTAX_ERROR;
  874. if (CMD_ARGC == 1) {
  875. unsigned delay;
  876. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
  877. jtag_set_ntrst_assert_width(delay);
  878. }
  879. command_print(CMD_CTX, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
  880. return ERROR_OK;
  881. }
  882. COMMAND_HANDLER(handle_jtag_rclk_command)
  883. {
  884. if (CMD_ARGC > 1)
  885. return ERROR_COMMAND_SYNTAX_ERROR;
  886. int retval = ERROR_OK;
  887. if (CMD_ARGC == 1) {
  888. unsigned khz = 0;
  889. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
  890. retval = jtag_config_rclk(khz);
  891. if (ERROR_OK != retval)
  892. return retval;
  893. }
  894. int cur_khz = jtag_get_speed_khz();
  895. retval = jtag_get_speed_readable(&cur_khz);
  896. if (ERROR_OK != retval)
  897. return retval;
  898. if (cur_khz)
  899. command_print(CMD_CTX, "RCLK not supported - fallback to %d kHz", cur_khz);
  900. else
  901. command_print(CMD_CTX, "RCLK - adaptive");
  902. return retval;
  903. }
  904. COMMAND_HANDLER(handle_jtag_reset_command)
  905. {
  906. if (CMD_ARGC != 2)
  907. return ERROR_COMMAND_SYNTAX_ERROR;
  908. int trst = -1;
  909. if (CMD_ARGV[0][0] == '1')
  910. trst = 1;
  911. else if (CMD_ARGV[0][0] == '0')
  912. trst = 0;
  913. else
  914. return ERROR_COMMAND_SYNTAX_ERROR;
  915. int srst = -1;
  916. if (CMD_ARGV[1][0] == '1')
  917. srst = 1;
  918. else if (CMD_ARGV[1][0] == '0')
  919. srst = 0;
  920. else
  921. return ERROR_COMMAND_SYNTAX_ERROR;
  922. if (adapter_init(CMD_CTX) != ERROR_OK)
  923. return ERROR_JTAG_INIT_FAILED;
  924. jtag_add_reset(trst, srst);
  925. return jtag_execute_queue();
  926. }
  927. COMMAND_HANDLER(handle_runtest_command)
  928. {
  929. if (CMD_ARGC != 1)
  930. return ERROR_COMMAND_SYNTAX_ERROR;
  931. unsigned num_clocks;
  932. COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num_clocks);
  933. jtag_add_runtest(num_clocks, TAP_IDLE);
  934. return jtag_execute_queue();
  935. }
  936. /*
  937. * For "irscan" or "drscan" commands, the "end" (really, "next") state
  938. * should be stable ... and *NOT* a shift state, otherwise free-running
  939. * jtag clocks could change the values latched by the update state.
  940. * Not surprisingly, this is the same constraint as SVF; the "irscan"
  941. * and "drscan" commands are a write-only subset of what SVF provides.
  942. */
  943. COMMAND_HANDLER(handle_irscan_command)
  944. {
  945. int i;
  946. struct scan_field *fields;
  947. struct jtag_tap *tap = NULL;
  948. tap_state_t endstate;
  949. if ((CMD_ARGC < 2) || (CMD_ARGC % 2))
  950. return ERROR_COMMAND_SYNTAX_ERROR;
  951. /* optional "-endstate" "statename" at the end of the arguments,
  952. * so that e.g. IRPAUSE can let us load the data register before
  953. * entering RUN/IDLE to execute the instruction we load here.
  954. */
  955. endstate = TAP_IDLE;
  956. if (CMD_ARGC >= 4) {
  957. /* have at least one pair of numbers.
  958. * is last pair the magic text? */
  959. if (strcmp("-endstate", CMD_ARGV[CMD_ARGC - 2]) == 0) {
  960. endstate = tap_state_by_name(CMD_ARGV[CMD_ARGC - 1]);
  961. if (endstate == TAP_INVALID)
  962. return ERROR_COMMAND_SYNTAX_ERROR;
  963. if (!scan_is_safe(endstate))
  964. LOG_WARNING("unstable irscan endstate \"%s\"",
  965. CMD_ARGV[CMD_ARGC - 1]);
  966. CMD_ARGC -= 2;
  967. }
  968. }
  969. int num_fields = CMD_ARGC / 2;
  970. if (num_fields > 1) {
  971. /* we really should be looking at plain_ir_scan if we want
  972. * anything more fancy.
  973. */
  974. LOG_ERROR("Specify a single value for tap");
  975. return ERROR_COMMAND_SYNTAX_ERROR;
  976. }
  977. fields = calloc(num_fields, sizeof(*fields));
  978. int retval;
  979. for (i = 0; i < num_fields; i++) {
  980. tap = jtag_tap_by_string(CMD_ARGV[i*2]);
  981. if (tap == NULL) {
  982. free(fields);
  983. command_print(CMD_CTX, "Tap: %s unknown", CMD_ARGV[i*2]);
  984. return ERROR_FAIL;
  985. }
  986. int field_size = tap->ir_length;
  987. fields[i].num_bits = field_size;
  988. uint8_t *v = malloc(DIV_ROUND_UP(field_size, 8));
  989. uint64_t value;
  990. retval = parse_u64(CMD_ARGV[i * 2 + 1], &value);
  991. if (ERROR_OK != retval)
  992. goto error_return;
  993. buf_set_u64(v, 0, field_size, value);
  994. fields[i].out_value = v;
  995. fields[i].in_value = NULL;
  996. }
  997. /* did we have an endstate? */
  998. jtag_add_ir_scan(tap, fields, endstate);
  999. retval = jtag_execute_queue();
  1000. error_return:
  1001. for (i = 0; i < num_fields; i++) {
  1002. if (NULL != fields[i].out_value)
  1003. free((void *)fields[i].out_value);
  1004. }
  1005. free(fields);
  1006. return retval;
  1007. }
  1008. COMMAND_HANDLER(handle_verify_ircapture_command)
  1009. {
  1010. if (CMD_ARGC > 1)
  1011. return ERROR_COMMAND_SYNTAX_ERROR;
  1012. if (CMD_ARGC == 1) {
  1013. bool enable;
  1014. COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
  1015. jtag_set_verify_capture_ir(enable);
  1016. }
  1017. const char *status = jtag_will_verify_capture_ir() ? "enabled" : "disabled";
  1018. command_print(CMD_CTX, "verify Capture-IR is %s", status);
  1019. return ERROR_OK;
  1020. }
  1021. COMMAND_HANDLER(handle_verify_jtag_command)
  1022. {
  1023. if (CMD_ARGC > 1)
  1024. return ERROR_COMMAND_SYNTAX_ERROR;
  1025. if (CMD_ARGC == 1) {
  1026. bool enable;
  1027. COMMAND_PARSE_ENABLE(CMD_ARGV[0], enable);
  1028. jtag_set_verify(enable);
  1029. }
  1030. const char *status = jtag_will_verify() ? "enabled" : "disabled";
  1031. command_print(CMD_CTX, "verify jtag capture is %s", status);
  1032. return ERROR_OK;
  1033. }
  1034. COMMAND_HANDLER(handle_tms_sequence_command)
  1035. {
  1036. if (CMD_ARGC > 1)
  1037. return ERROR_COMMAND_SYNTAX_ERROR;
  1038. if (CMD_ARGC == 1) {
  1039. bool use_new_table;
  1040. if (strcmp(CMD_ARGV[0], "short") == 0)
  1041. use_new_table = true;
  1042. else if (strcmp(CMD_ARGV[0], "long") == 0)
  1043. use_new_table = false;
  1044. else
  1045. return ERROR_COMMAND_SYNTAX_ERROR;
  1046. tap_use_new_tms_table(use_new_table);
  1047. }
  1048. command_print(CMD_CTX, "tms sequence is %s",
  1049. tap_uses_new_tms_table() ? "short" : "long");
  1050. return ERROR_OK;
  1051. }
  1052. COMMAND_HANDLER(handle_jtag_flush_queue_sleep)
  1053. {
  1054. if (CMD_ARGC != 1)
  1055. return ERROR_COMMAND_SYNTAX_ERROR;
  1056. int sleep_ms;
  1057. COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], sleep_ms);
  1058. jtag_set_flush_queue_sleep(sleep_ms);
  1059. return ERROR_OK;
  1060. }
  1061. COMMAND_HANDLER(handle_wait_srst_deassert)
  1062. {
  1063. if (CMD_ARGC != 1)
  1064. return ERROR_COMMAND_SYNTAX_ERROR;
  1065. int timeout_ms;
  1066. COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], timeout_ms);
  1067. if ((timeout_ms <= 0) || (timeout_ms > 100000)) {
  1068. LOG_ERROR("Timeout must be an integer between 0 and 100000");
  1069. return ERROR_FAIL;
  1070. }
  1071. LOG_USER("Waiting for srst assert + deassert for at most %dms", timeout_ms);
  1072. int asserted_yet;
  1073. long long then = timeval_ms();
  1074. while (jtag_srst_asserted(&asserted_yet) == ERROR_OK) {
  1075. if ((timeval_ms() - then) > timeout_ms) {
  1076. LOG_ERROR("Timed out");
  1077. return ERROR_FAIL;
  1078. }
  1079. if (asserted_yet)
  1080. break;
  1081. }
  1082. while (jtag_srst_asserted(&asserted_yet) == ERROR_OK) {
  1083. if ((timeval_ms() - then) > timeout_ms) {
  1084. LOG_ERROR("Timed out");
  1085. return ERROR_FAIL;
  1086. }
  1087. if (!asserted_yet)
  1088. break;
  1089. }
  1090. return ERROR_OK;
  1091. }
  1092. static const struct command_registration jtag_command_handlers[] = {
  1093. {
  1094. .name = "jtag_flush_queue_sleep",
  1095. .handler = handle_jtag_flush_queue_sleep,
  1096. .mode = COMMAND_ANY,
  1097. .help = "For debug purposes(simulate long delays of interface) "
  1098. "to test performance or change in behavior. Default 0ms.",
  1099. .usage = "[sleep in ms]",
  1100. },
  1101. {
  1102. .name = "jtag_rclk",
  1103. .handler = handle_jtag_rclk_command,
  1104. .mode = COMMAND_ANY,
  1105. .help = "With an argument, change to to use adaptive clocking "
  1106. "if possible; else to use the fallback speed. "
  1107. "With or without argument, display current setting.",
  1108. .usage = "[fallback_speed_khz]",
  1109. },
  1110. {
  1111. .name = "jtag_ntrst_delay",
  1112. .handler = handle_jtag_ntrst_delay_command,
  1113. .mode = COMMAND_ANY,
  1114. .help = "delay after deasserting trst in ms",
  1115. .usage = "[milliseconds]",
  1116. },
  1117. {
  1118. .name = "jtag_ntrst_assert_width",
  1119. .handler = handle_jtag_ntrst_assert_width_command,
  1120. .mode = COMMAND_ANY,
  1121. .help = "delay after asserting trst in ms",
  1122. .usage = "[milliseconds]",
  1123. },
  1124. {
  1125. .name = "scan_chain",
  1126. .handler = handle_scan_chain_command,
  1127. .mode = COMMAND_ANY,
  1128. .help = "print current scan chain configuration",
  1129. .usage = ""
  1130. },
  1131. {
  1132. .name = "jtag_reset",
  1133. .handler = handle_jtag_reset_command,
  1134. .mode = COMMAND_EXEC,
  1135. .help = "Set reset line values. Value '1' is active, "
  1136. "value '0' is inactive.",
  1137. .usage = "trst_active srst_active",
  1138. },
  1139. {
  1140. .name = "runtest",
  1141. .handler = handle_runtest_command,
  1142. .mode = COMMAND_EXEC,
  1143. .help = "Move to Run-Test/Idle, and issue TCK for num_cycles.",
  1144. .usage = "num_cycles"
  1145. },
  1146. {
  1147. .name = "irscan",
  1148. .handler = handle_irscan_command,
  1149. .mode = COMMAND_EXEC,
  1150. .help = "Execute Instruction Register (DR) scan. The "
  1151. "specified opcodes are put into each TAP's IR, "
  1152. "and other TAPs are put in BYPASS.",
  1153. .usage = "[tap_name instruction]* ['-endstate' state_name]",
  1154. },
  1155. {
  1156. .name = "verify_ircapture",
  1157. .handler = handle_verify_ircapture_command,
  1158. .mode = COMMAND_ANY,
  1159. .help = "Display or assign flag controlling whether to "
  1160. "verify values captured during Capture-IR.",
  1161. .usage = "['enable'|'disable']",
  1162. },
  1163. {
  1164. .name = "verify_jtag",
  1165. .handler = handle_verify_jtag_command,
  1166. .mode = COMMAND_ANY,
  1167. .help = "Display or assign flag controlling whether to "
  1168. "verify values captured during IR and DR scans.",
  1169. .usage = "['enable'|'disable']",
  1170. },
  1171. {
  1172. .name = "tms_sequence",
  1173. .handler = handle_tms_sequence_command,
  1174. .mode = COMMAND_ANY,
  1175. .help = "Display or change what style TMS sequences to use "
  1176. "for JTAG state transitions: short (default) or "
  1177. "long. Only for working around JTAG bugs.",
  1178. /* Specifically for working around DRIVER bugs... */
  1179. .usage = "['short'|'long']",
  1180. },
  1181. {
  1182. .name = "wait_srst_deassert",
  1183. .handler = handle_wait_srst_deassert,
  1184. .mode = COMMAND_ANY,
  1185. .help = "Wait for an SRST deassert. "
  1186. "Useful for cases where you need something to happen within ms "
  1187. "of an srst deassert. Timeout in ms ",
  1188. .usage = "ms",
  1189. },
  1190. {
  1191. .name = "jtag",
  1192. .mode = COMMAND_ANY,
  1193. .help = "perform jtag tap actions",
  1194. .usage = "",
  1195. .chain = jtag_subcommand_handlers,
  1196. },
  1197. {
  1198. .chain = jtag_command_handlers_to_move,
  1199. },
  1200. COMMAND_REGISTRATION_DONE
  1201. };
  1202. int jtag_register_commands(struct command_context *cmd_ctx)
  1203. {
  1204. return register_commands(cmd_ctx, NULL, jtag_command_handlers);
  1205. }