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.
 
 
 
 
 
 

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