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.
 
 
 
 
 
 

1897 lines
51 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "replacements.h"
  24. #include "jtag.h"
  25. #include "command.h"
  26. #include "log.h"
  27. #include "interpreter.h"
  28. #include "stdlib.h"
  29. #include "string.h"
  30. #include <unistd.h>
  31. char* tap_state_strings[16] =
  32. {
  33. "tlr",
  34. "sds", "cd", "sd", "e1d", "pd", "e2d", "ud",
  35. "rti",
  36. "sis", "ci", "si", "e1i", "pi", "e2i", "ui"
  37. };
  38. typedef struct cmd_queue_page_s
  39. {
  40. void *address;
  41. size_t used;
  42. struct cmd_queue_page_s *next;
  43. } cmd_queue_page_t;
  44. #define CMD_QUEUE_PAGE_SIZE (1024 * 1024)
  45. static cmd_queue_page_t *cmd_queue_pages = NULL;
  46. /* tap_move[i][j]: tap movement command to go from state i to state j
  47. * 0: Test-Logic-Reset
  48. * 1: Run-Test/Idle
  49. * 2: Shift-DR
  50. * 3: Pause-DR
  51. * 4: Shift-IR
  52. * 5: Pause-IR
  53. *
  54. * SD->SD and SI->SI have to be caught in interface specific code
  55. */
  56. u8 tap_move[6][6] =
  57. {
  58. /* TLR RTI SD PD SI PI */
  59. {0x7f, 0x00, 0x17, 0x0a, 0x1b, 0x16}, /* TLR */
  60. {0x7f, 0x00, 0x25, 0x05, 0x2b, 0x0b}, /* RTI */
  61. {0x7f, 0x31, 0x00, 0x01, 0x0f, 0x2f}, /* SD */
  62. {0x7f, 0x30, 0x20, 0x17, 0x1e, 0x2f}, /* PD */
  63. {0x7f, 0x31, 0x07, 0x17, 0x00, 0x01}, /* SI */
  64. {0x7f, 0x30, 0x1c, 0x17, 0x20, 0x2f} /* PI */
  65. };
  66. int tap_move_map[16] = {
  67. 0, -1, -1, 2, -1, 3, -1, -1,
  68. 1, -1, -1, 4, -1, 5, -1, -1
  69. };
  70. tap_transition_t tap_transitions[16] =
  71. {
  72. {TAP_TLR, TAP_RTI}, /* TLR */
  73. {TAP_SIS, TAP_CD}, /* SDS */
  74. {TAP_E1D, TAP_SD}, /* CD */
  75. {TAP_E1D, TAP_SD}, /* SD */
  76. {TAP_UD, TAP_PD}, /* E1D */
  77. {TAP_E2D, TAP_PD}, /* PD */
  78. {TAP_UD, TAP_SD}, /* E2D */
  79. {TAP_SDS, TAP_RTI}, /* UD */
  80. {TAP_SDS, TAP_RTI}, /* RTI */
  81. {TAP_TLR, TAP_CI}, /* SIS */
  82. {TAP_E1I, TAP_SI}, /* CI */
  83. {TAP_E1I, TAP_SI}, /* SI */
  84. {TAP_UI, TAP_PI}, /* E1I */
  85. {TAP_E2I, TAP_PI}, /* PI */
  86. {TAP_UI, TAP_SI}, /* E2I */
  87. {TAP_SDS, TAP_RTI} /* UI */
  88. };
  89. char* jtag_event_strings[] =
  90. {
  91. "SRST asserted",
  92. "TRST asserted",
  93. "SRST released",
  94. "TRST released"
  95. };
  96. enum tap_state end_state = TAP_TLR;
  97. enum tap_state cur_state = TAP_TLR;
  98. int jtag_trst = 0;
  99. int jtag_srst = 0;
  100. jtag_command_t *jtag_command_queue = NULL;
  101. jtag_command_t **last_comand_pointer = &jtag_command_queue;
  102. jtag_device_t *jtag_devices = NULL;
  103. int jtag_num_devices = 0;
  104. int jtag_ir_scan_size = 0;
  105. enum reset_types jtag_reset_config = RESET_NONE;
  106. enum tap_state cmd_queue_end_state = TAP_TLR;
  107. enum tap_state cmd_queue_cur_state = TAP_TLR;
  108. int jtag_verify_capture_ir = 1;
  109. /* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
  110. int jtag_nsrst_delay = 0; /* default to no nSRST delay */
  111. int jtag_ntrst_delay = 0; /* default to no nTRST delay */
  112. /* maximum number of JTAG devices expected in the chain
  113. */
  114. #define JTAG_MAX_CHAIN_SIZE 20
  115. /* callbacks to inform high-level handlers about JTAG state changes */
  116. jtag_event_callback_t *jtag_event_callbacks;
  117. /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
  118. */
  119. #if BUILD_PARPORT == 1
  120. extern jtag_interface_t parport_interface;
  121. #endif
  122. #if BUILD_FT2232_FTD2XX == 1
  123. extern jtag_interface_t ft2232_interface;
  124. #endif
  125. #if BUILD_FT2232_LIBFTDI == 1
  126. extern jtag_interface_t ft2232_interface;
  127. #endif
  128. #if BUILD_AMTJTAGACCEL == 1
  129. extern jtag_interface_t amt_jtagaccel_interface;
  130. #endif
  131. #if BUILD_EP93XX == 1
  132. extern jtag_interface_t ep93xx_interface;
  133. #endif
  134. #if BUILD_AT91RM9200 == 1
  135. extern jtag_interface_t at91rm9200_interface;
  136. #endif
  137. #if BUILD_GW16012 == 1
  138. extern jtag_interface_t gw16012_interface;
  139. #endif
  140. #if BUILD_PRESTO == 1
  141. extern jtag_interface_t presto_interface;
  142. #endif
  143. #if BUILD_USBPROG == 1
  144. extern jtag_interface_t usbprog_interface;
  145. #endif
  146. jtag_interface_t *jtag_interfaces[] = {
  147. #if BUILD_PARPORT == 1
  148. &parport_interface,
  149. #endif
  150. #if BUILD_FT2232_FTD2XX == 1
  151. &ft2232_interface,
  152. #endif
  153. #if BUILD_FT2232_LIBFTDI == 1
  154. &ft2232_interface,
  155. #endif
  156. #if BUILD_AMTJTAGACCEL == 1
  157. &amt_jtagaccel_interface,
  158. #endif
  159. #if BUILD_EP93XX == 1
  160. &ep93xx_interface,
  161. #endif
  162. #if BUILD_AT91RM9200 == 1
  163. &at91rm9200_interface,
  164. #endif
  165. #if BUILD_GW16012 == 1
  166. &gw16012_interface,
  167. #endif
  168. #if BUILD_PRESTO == 1
  169. &presto_interface,
  170. #endif
  171. #if BUILD_USBPROG == 1
  172. &usbprog_interface,
  173. #endif
  174. NULL,
  175. };
  176. jtag_interface_t *jtag = NULL;
  177. /* configuration */
  178. char* jtag_interface = NULL;
  179. int jtag_speed = -1;
  180. /* forward declarations */
  181. int jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state endstate, error_handler_t *error_handler);
  182. int jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state endstate, error_handler_t *error_handler);
  183. int jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state endstate, error_handler_t *error_handler);
  184. int jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state endstate, error_handler_t *error_handler);
  185. int jtag_add_statemove(enum tap_state endstate);
  186. int jtag_add_pathmove(int num_states, enum tap_state *path);
  187. int jtag_add_runtest(int num_cycles, enum tap_state endstate);
  188. int jtag_add_reset(int trst, int srst);
  189. int jtag_add_end_state(enum tap_state endstate);
  190. int jtag_add_sleep(u32 us);
  191. int jtag_execute_queue(void);
  192. int jtag_cancel_queue(void);
  193. /* jtag commands */
  194. int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  195. int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  196. int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  197. int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  198. int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  199. int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  200. int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  201. int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  202. int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  203. int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  204. int handle_statemove_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  205. int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  206. int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  207. int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
  208. int jtag_register_event_callback(int (*callback)(enum jtag_event event, void *priv), void *priv)
  209. {
  210. jtag_event_callback_t **callbacks_p = &jtag_event_callbacks;
  211. if (callback == NULL)
  212. {
  213. return ERROR_INVALID_ARGUMENTS;
  214. }
  215. if (*callbacks_p)
  216. {
  217. while ((*callbacks_p)->next)
  218. callbacks_p = &((*callbacks_p)->next);
  219. callbacks_p = &((*callbacks_p)->next);
  220. }
  221. (*callbacks_p) = malloc(sizeof(jtag_event_callback_t));
  222. (*callbacks_p)->callback = callback;
  223. (*callbacks_p)->priv = priv;
  224. (*callbacks_p)->next = NULL;
  225. return ERROR_OK;
  226. }
  227. int jtag_unregister_event_callback(int (*callback)(enum jtag_event event, void *priv))
  228. {
  229. jtag_event_callback_t **callbacks_p = &jtag_event_callbacks;
  230. if (callback == NULL)
  231. {
  232. return ERROR_INVALID_ARGUMENTS;
  233. }
  234. while (*callbacks_p)
  235. {
  236. jtag_event_callback_t **next = &((*callbacks_p)->next);
  237. if ((*callbacks_p)->callback == callback)
  238. {
  239. free(*callbacks_p);
  240. *callbacks_p = *next;
  241. }
  242. callbacks_p = next;
  243. }
  244. return ERROR_OK;
  245. }
  246. int jtag_call_event_callbacks(enum jtag_event event)
  247. {
  248. jtag_event_callback_t *callback = jtag_event_callbacks;
  249. DEBUG("jtag event: %s", jtag_event_strings[event]);
  250. while (callback)
  251. {
  252. callback->callback(event, callback->priv);
  253. callback = callback->next;
  254. }
  255. return ERROR_OK;
  256. }
  257. /* returns a pointer to the pointer of the last command in queue
  258. * this may be a pointer to the root pointer (jtag_command_queue)
  259. * or to the next member of the last but one command
  260. */
  261. jtag_command_t** jtag_get_last_command_p(void)
  262. {
  263. /* jtag_command_t *cmd = jtag_command_queue;
  264. if (cmd)
  265. while (cmd->next)
  266. cmd = cmd->next;
  267. else
  268. return &jtag_command_queue;
  269. return &cmd->next;*/
  270. return last_comand_pointer;
  271. }
  272. /* returns a pointer to the n-th device in the scan chain */
  273. jtag_device_t* jtag_get_device(int num)
  274. {
  275. jtag_device_t *device = jtag_devices;
  276. int i = 0;
  277. while (device)
  278. {
  279. if (num == i)
  280. return device;
  281. device = device->next;
  282. i++;
  283. }
  284. return NULL;
  285. }
  286. void* cmd_queue_alloc(size_t size)
  287. {
  288. cmd_queue_page_t **p_page = &cmd_queue_pages;
  289. int offset;
  290. if (*p_page)
  291. {
  292. while ((*p_page)->next)
  293. p_page = &((*p_page)->next);
  294. if (CMD_QUEUE_PAGE_SIZE - (*p_page)->used < size)
  295. p_page = &((*p_page)->next);
  296. }
  297. if (!*p_page)
  298. {
  299. *p_page = malloc(sizeof(cmd_queue_page_t));
  300. (*p_page)->used = 0;
  301. (*p_page)->address = malloc(CMD_QUEUE_PAGE_SIZE);
  302. (*p_page)->next = NULL;
  303. }
  304. offset = (*p_page)->used;
  305. (*p_page)->used += size;
  306. return ((*p_page)->address) + offset;
  307. }
  308. void cmd_queue_free()
  309. {
  310. cmd_queue_page_t *page = cmd_queue_pages;
  311. while (page)
  312. {
  313. cmd_queue_page_t *last = page;
  314. free(page->address);
  315. page = page->next;
  316. free(last);
  317. }
  318. cmd_queue_pages = NULL;
  319. }
  320. int jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state, error_handler_t *error_handler)
  321. {
  322. jtag_command_t **last_cmd;
  323. jtag_device_t *device;
  324. int i, j;
  325. int scan_size = 0;
  326. if (jtag_trst == 1)
  327. {
  328. WARNING("JTAG command queued, while TRST is low (TAP in reset)");
  329. return ERROR_JTAG_TRST_ASSERTED;
  330. }
  331. last_cmd = jtag_get_last_command_p();
  332. /* allocate memory for a new list member */
  333. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  334. (*last_cmd)->next = NULL;
  335. last_comand_pointer = &((*last_cmd)->next);
  336. (*last_cmd)->type = JTAG_SCAN;
  337. /* allocate memory for ir scan command */
  338. (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
  339. (*last_cmd)->cmd.scan->ir_scan = 1;
  340. (*last_cmd)->cmd.scan->num_fields = jtag_num_devices; /* one field per device */
  341. (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(jtag_num_devices * sizeof(scan_field_t));
  342. (*last_cmd)->cmd.scan->end_state = state;
  343. if (error_handler)
  344. {
  345. (*last_cmd)->cmd.scan->error_handler = cmd_queue_alloc(sizeof(error_handler_t));
  346. *(*last_cmd)->cmd.scan->error_handler = *error_handler;
  347. }
  348. else
  349. {
  350. (*last_cmd)->cmd.scan->error_handler = NULL;
  351. }
  352. if (state != -1)
  353. cmd_queue_end_state = state;
  354. if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
  355. jtag_call_event_callbacks(JTAG_TRST_RELEASED);
  356. if (cmd_queue_end_state == TAP_TLR)
  357. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  358. cmd_queue_cur_state = cmd_queue_end_state;
  359. for (i=0; i < jtag_num_devices; i++)
  360. {
  361. int found = 0;
  362. device = jtag_get_device(i);
  363. scan_size = device->ir_length;
  364. (*last_cmd)->cmd.scan->fields[i].device = i;
  365. (*last_cmd)->cmd.scan->fields[i].num_bits = scan_size;
  366. (*last_cmd)->cmd.scan->fields[i].in_value = NULL;
  367. if (jtag_verify_capture_ir)
  368. {
  369. (*last_cmd)->cmd.scan->fields[i].in_check_value = buf_cpy(device->expected, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  370. (*last_cmd)->cmd.scan->fields[i].in_check_mask = buf_cpy(device->expected_mask, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  371. }
  372. else
  373. {
  374. (*last_cmd)->cmd.scan->fields[i].in_check_value = NULL;
  375. (*last_cmd)->cmd.scan->fields[i].in_check_mask = NULL;
  376. }
  377. (*last_cmd)->cmd.scan->fields[i].in_handler = NULL;
  378. (*last_cmd)->cmd.scan->fields[i].in_handler_priv = NULL;
  379. /* search the list */
  380. for (j=0; j < num_fields; j++)
  381. {
  382. if (i == fields[j].device)
  383. {
  384. found = 1;
  385. (*last_cmd)->cmd.scan->fields[i].out_value = buf_cpy(fields[j].out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  386. (*last_cmd)->cmd.scan->fields[i].out_mask = buf_cpy(fields[j].out_mask, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  387. device->bypass = 0;
  388. break;
  389. }
  390. }
  391. if (!found)
  392. {
  393. /* if a device isn't listed, set it to BYPASS */
  394. (*last_cmd)->cmd.scan->fields[i].out_value = buf_set_ones(cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  395. (*last_cmd)->cmd.scan->fields[i].out_mask = NULL;
  396. device->bypass = 1;
  397. }
  398. /* update device information */
  399. buf_cpy((*last_cmd)->cmd.scan->fields[i].out_value, jtag_get_device(i)->cur_instr, scan_size);
  400. }
  401. return ERROR_OK;
  402. }
  403. int jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state, error_handler_t *error_handler)
  404. {
  405. jtag_command_t **last_cmd;
  406. int i;
  407. if (jtag_trst == 1)
  408. {
  409. WARNING("JTAG command queued, while TRST is low (TAP in reset)");
  410. return ERROR_JTAG_TRST_ASSERTED;
  411. }
  412. last_cmd = jtag_get_last_command_p();
  413. /* allocate memory for a new list member */
  414. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  415. (*last_cmd)->next = NULL;
  416. last_comand_pointer = &((*last_cmd)->next);
  417. (*last_cmd)->type = JTAG_SCAN;
  418. /* allocate memory for ir scan command */
  419. (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
  420. (*last_cmd)->cmd.scan->ir_scan = 1;
  421. (*last_cmd)->cmd.scan->num_fields = num_fields;
  422. (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(num_fields * sizeof(scan_field_t));
  423. (*last_cmd)->cmd.scan->end_state = state;
  424. if (error_handler)
  425. {
  426. (*last_cmd)->cmd.scan->error_handler = cmd_queue_alloc(sizeof(error_handler_t));
  427. *(*last_cmd)->cmd.scan->error_handler = *error_handler;
  428. }
  429. else
  430. {
  431. (*last_cmd)->cmd.scan->error_handler = NULL;
  432. }
  433. if (state != -1)
  434. cmd_queue_end_state = state;
  435. if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
  436. jtag_call_event_callbacks(JTAG_TRST_RELEASED);
  437. if (cmd_queue_end_state == TAP_TLR)
  438. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  439. cmd_queue_cur_state = cmd_queue_end_state;
  440. for (i = 0; i < num_fields; i++)
  441. {
  442. int num_bits = fields[i].num_bits;
  443. int num_bytes = CEIL(fields[i].num_bits, 8);
  444. (*last_cmd)->cmd.scan->fields[i].device = fields[i].device;
  445. (*last_cmd)->cmd.scan->fields[i].num_bits = num_bits;
  446. (*last_cmd)->cmd.scan->fields[i].out_value = buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
  447. (*last_cmd)->cmd.scan->fields[i].out_mask = buf_cpy(fields[i].out_mask, cmd_queue_alloc(num_bytes), num_bits);
  448. (*last_cmd)->cmd.scan->fields[i].in_value = fields[i].in_value;
  449. (*last_cmd)->cmd.scan->fields[i].in_check_value = buf_cpy(fields[i].in_check_value, cmd_queue_alloc(num_bytes), num_bits);
  450. (*last_cmd)->cmd.scan->fields[i].in_check_mask = buf_cpy(fields[i].in_check_mask, cmd_queue_alloc(num_bytes), num_bits);
  451. (*last_cmd)->cmd.scan->fields[i].in_handler = NULL;
  452. (*last_cmd)->cmd.scan->fields[i].in_handler_priv = NULL;
  453. }
  454. return ERROR_OK;
  455. }
  456. int jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state, error_handler_t *error_handler)
  457. {
  458. int i, j;
  459. int bypass_devices = 0;
  460. int field_count = 0;
  461. jtag_command_t **last_cmd = jtag_get_last_command_p();
  462. jtag_device_t *device = jtag_devices;
  463. int scan_size;
  464. if (jtag_trst == 1)
  465. {
  466. WARNING("JTAG command queued, while TRST is low (TAP in reset)");
  467. return ERROR_JTAG_TRST_ASSERTED;
  468. }
  469. /* count devices in bypass */
  470. while (device)
  471. {
  472. if (device->bypass)
  473. bypass_devices++;
  474. device = device->next;
  475. }
  476. /* allocate memory for a new list member */
  477. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  478. last_comand_pointer = &((*last_cmd)->next);
  479. (*last_cmd)->next = NULL;
  480. (*last_cmd)->type = JTAG_SCAN;
  481. /* allocate memory for dr scan command */
  482. (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
  483. (*last_cmd)->cmd.scan->ir_scan = 0;
  484. (*last_cmd)->cmd.scan->num_fields = num_fields + bypass_devices;
  485. (*last_cmd)->cmd.scan->fields = cmd_queue_alloc((num_fields + bypass_devices) * sizeof(scan_field_t));
  486. (*last_cmd)->cmd.scan->end_state = state;
  487. if (error_handler)
  488. {
  489. (*last_cmd)->cmd.scan->error_handler = cmd_queue_alloc(sizeof(error_handler_t));
  490. *(*last_cmd)->cmd.scan->error_handler = *error_handler;
  491. }
  492. else
  493. {
  494. (*last_cmd)->cmd.scan->error_handler = NULL;
  495. }
  496. if (state != -1)
  497. cmd_queue_end_state = state;
  498. if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
  499. jtag_call_event_callbacks(JTAG_TRST_RELEASED);
  500. if (cmd_queue_end_state == TAP_TLR)
  501. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  502. cmd_queue_cur_state = cmd_queue_end_state;
  503. for (i=0; i < jtag_num_devices; i++)
  504. {
  505. int found = 0;
  506. (*last_cmd)->cmd.scan->fields[field_count].device = i;
  507. for (j=0; j < num_fields; j++)
  508. {
  509. if (i == fields[j].device)
  510. {
  511. found = 1;
  512. scan_size = fields[j].num_bits;
  513. (*last_cmd)->cmd.scan->fields[field_count].num_bits = scan_size;
  514. (*last_cmd)->cmd.scan->fields[field_count].out_value = buf_cpy(fields[j].out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  515. (*last_cmd)->cmd.scan->fields[field_count].out_mask = buf_cpy(fields[j].out_mask, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  516. (*last_cmd)->cmd.scan->fields[field_count].in_value = fields[j].in_value;
  517. (*last_cmd)->cmd.scan->fields[field_count].in_check_value = buf_cpy(fields[j].in_check_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  518. (*last_cmd)->cmd.scan->fields[field_count].in_check_mask = buf_cpy(fields[j].in_check_mask, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
  519. (*last_cmd)->cmd.scan->fields[field_count].in_handler = fields[j].in_handler;
  520. (*last_cmd)->cmd.scan->fields[field_count++].in_handler_priv = fields[j].in_handler_priv;
  521. }
  522. }
  523. if (!found)
  524. {
  525. /* if a device isn't listed, the BYPASS register should be selected */
  526. if (!jtag_get_device(i)->bypass)
  527. {
  528. ERROR("BUG: no scan data for a device not in BYPASS");
  529. exit(-1);
  530. }
  531. /* program the scan field to 1 bit length, and ignore it's value */
  532. (*last_cmd)->cmd.scan->fields[field_count].num_bits = 1;
  533. (*last_cmd)->cmd.scan->fields[field_count].out_value = NULL;
  534. (*last_cmd)->cmd.scan->fields[field_count].out_mask = NULL;
  535. (*last_cmd)->cmd.scan->fields[field_count].in_value = NULL;
  536. (*last_cmd)->cmd.scan->fields[field_count].in_check_value = NULL;
  537. (*last_cmd)->cmd.scan->fields[field_count].in_check_mask = NULL;
  538. (*last_cmd)->cmd.scan->fields[field_count].in_handler = NULL;
  539. (*last_cmd)->cmd.scan->fields[field_count++].in_handler_priv = NULL;
  540. }
  541. else
  542. {
  543. /* if a device is listed, the BYPASS register must not be selected */
  544. if (jtag_get_device(i)->bypass)
  545. {
  546. WARNING("scan data for a device in BYPASS");
  547. }
  548. }
  549. }
  550. return ERROR_OK;
  551. }
  552. int jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state, error_handler_t *error_handler)
  553. {
  554. int i;
  555. jtag_command_t **last_cmd = jtag_get_last_command_p();
  556. if (jtag_trst == 1)
  557. {
  558. WARNING("JTAG command queued, while TRST is low (TAP in reset)");
  559. return ERROR_JTAG_TRST_ASSERTED;
  560. }
  561. /* allocate memory for a new list member */
  562. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  563. last_comand_pointer = &((*last_cmd)->next);
  564. (*last_cmd)->next = NULL;
  565. (*last_cmd)->type = JTAG_SCAN;
  566. /* allocate memory for scan command */
  567. (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
  568. (*last_cmd)->cmd.scan->ir_scan = 0;
  569. (*last_cmd)->cmd.scan->num_fields = num_fields;
  570. (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(num_fields * sizeof(scan_field_t));
  571. (*last_cmd)->cmd.scan->end_state = state;
  572. if (error_handler)
  573. {
  574. (*last_cmd)->cmd.scan->error_handler = cmd_queue_alloc(sizeof(error_handler_t));
  575. *(*last_cmd)->cmd.scan->error_handler = *error_handler;
  576. }
  577. else
  578. {
  579. (*last_cmd)->cmd.scan->error_handler = NULL;
  580. }
  581. if (state != -1)
  582. cmd_queue_end_state = state;
  583. if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
  584. jtag_call_event_callbacks(JTAG_TRST_RELEASED);
  585. if (cmd_queue_end_state == TAP_TLR)
  586. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  587. cmd_queue_cur_state = cmd_queue_end_state;
  588. for (i = 0; i < num_fields; i++)
  589. {
  590. int num_bits = fields[i].num_bits;
  591. int num_bytes = CEIL(fields[i].num_bits, 8);
  592. (*last_cmd)->cmd.scan->fields[i].device = fields[i].device;
  593. (*last_cmd)->cmd.scan->fields[i].num_bits = num_bits;
  594. (*last_cmd)->cmd.scan->fields[i].out_value = buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
  595. (*last_cmd)->cmd.scan->fields[i].out_mask = buf_cpy(fields[i].out_mask, cmd_queue_alloc(num_bytes), num_bits);
  596. (*last_cmd)->cmd.scan->fields[i].in_value = fields[i].in_value;
  597. (*last_cmd)->cmd.scan->fields[i].in_check_value = buf_cpy(fields[i].in_check_value, cmd_queue_alloc(num_bytes), num_bits);
  598. (*last_cmd)->cmd.scan->fields[i].in_check_mask = buf_cpy(fields[i].in_check_mask, cmd_queue_alloc(num_bytes), num_bits);
  599. (*last_cmd)->cmd.scan->fields[i].in_handler = fields[i].in_handler;
  600. (*last_cmd)->cmd.scan->fields[i].in_handler_priv = fields[i].in_handler_priv;
  601. }
  602. return ERROR_OK;
  603. }
  604. int jtag_add_statemove(enum tap_state state)
  605. {
  606. jtag_command_t **last_cmd = jtag_get_last_command_p();
  607. if (jtag_trst == 1)
  608. {
  609. WARNING("JTAG command queued, while TRST is low (TAP in reset)");
  610. return ERROR_JTAG_TRST_ASSERTED;
  611. }
  612. /* allocate memory for a new list member */
  613. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  614. last_comand_pointer = &((*last_cmd)->next);
  615. (*last_cmd)->next = NULL;
  616. (*last_cmd)->type = JTAG_STATEMOVE;
  617. (*last_cmd)->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
  618. (*last_cmd)->cmd.statemove->end_state = state;
  619. if (state != -1)
  620. cmd_queue_end_state = state;
  621. if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
  622. jtag_call_event_callbacks(JTAG_TRST_RELEASED);
  623. if (cmd_queue_end_state == TAP_TLR)
  624. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  625. cmd_queue_cur_state = cmd_queue_end_state;
  626. return ERROR_OK;
  627. }
  628. int jtag_add_pathmove(int num_states, enum tap_state *path)
  629. {
  630. jtag_command_t **last_cmd = jtag_get_last_command_p();
  631. int i;
  632. if (jtag_trst == 1)
  633. {
  634. WARNING("JTAG command queued, while TRST is low (TAP in reset)");
  635. return ERROR_JTAG_TRST_ASSERTED;
  636. }
  637. /* the last state has to be a stable state */
  638. if (tap_move_map[path[num_states - 1]] == -1)
  639. {
  640. ERROR("TAP path doesn't finish in a stable state");
  641. return ERROR_JTAG_NOT_IMPLEMENTED;
  642. }
  643. if (jtag->support_pathmove)
  644. {
  645. /* allocate memory for a new list member */
  646. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  647. last_comand_pointer = &((*last_cmd)->next);
  648. (*last_cmd)->next = NULL;
  649. (*last_cmd)->type = JTAG_PATHMOVE;
  650. (*last_cmd)->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
  651. (*last_cmd)->cmd.pathmove->num_states = num_states;
  652. (*last_cmd)->cmd.pathmove->path = cmd_queue_alloc(sizeof(enum tap_state) * num_states);
  653. for (i = 0; i < num_states; i++)
  654. (*last_cmd)->cmd.pathmove->path[i] = path[i];
  655. }
  656. else
  657. {
  658. /* validate the desired path, and see if it fits a default path */
  659. int begin = 0;
  660. int end = 0;
  661. int j;
  662. for (i = 0; i < num_states; i++)
  663. {
  664. for (j = i; j < num_states; j++)
  665. {
  666. if (tap_move_map[path[j]] != -1)
  667. {
  668. end = j;
  669. break;
  670. }
  671. }
  672. if (begin - end <= 7) /* a default path spans no more than 7 states */
  673. {
  674. jtag_add_statemove(path[end]);
  675. }
  676. else
  677. {
  678. ERROR("encountered a TAP path that can't be fulfilled by default paths");
  679. return ERROR_JTAG_NOT_IMPLEMENTED;
  680. }
  681. i = end;
  682. }
  683. }
  684. if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
  685. jtag_call_event_callbacks(JTAG_TRST_RELEASED);
  686. if (cmd_queue_end_state == TAP_TLR)
  687. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  688. cmd_queue_cur_state = path[num_states - 1];
  689. return ERROR_OK;
  690. }
  691. int jtag_add_runtest(int num_cycles, enum tap_state state)
  692. {
  693. jtag_command_t **last_cmd = jtag_get_last_command_p();
  694. if (jtag_trst == 1)
  695. {
  696. WARNING("JTAG command queued, while TRST is low (TAP in reset)");
  697. return ERROR_JTAG_TRST_ASSERTED;
  698. }
  699. /* allocate memory for a new list member */
  700. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  701. (*last_cmd)->next = NULL;
  702. last_comand_pointer = &((*last_cmd)->next);
  703. (*last_cmd)->type = JTAG_RUNTEST;
  704. (*last_cmd)->cmd.runtest = cmd_queue_alloc(sizeof(runtest_command_t));
  705. (*last_cmd)->cmd.runtest->num_cycles = num_cycles;
  706. (*last_cmd)->cmd.runtest->end_state = state;
  707. if (state != -1)
  708. cmd_queue_end_state = state;
  709. if (cmd_queue_cur_state == TAP_TLR && cmd_queue_end_state != TAP_TLR)
  710. jtag_call_event_callbacks(JTAG_TRST_RELEASED);
  711. if (cmd_queue_end_state == TAP_TLR)
  712. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  713. cmd_queue_cur_state = cmd_queue_end_state;
  714. return ERROR_OK;
  715. }
  716. int jtag_add_reset(int req_trst, int req_srst)
  717. {
  718. int trst_with_tms = 0;
  719. jtag_command_t **last_cmd = jtag_get_last_command_p();
  720. if (req_trst == -1)
  721. req_trst = jtag_trst;
  722. if (req_srst == -1)
  723. req_srst = jtag_srst;
  724. /* Make sure that jtag_reset_config allows the requested reset */
  725. /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
  726. if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (req_trst == 0))
  727. return ERROR_JTAG_RESET_WOULD_ASSERT_TRST;
  728. /* if TRST pulls SRST, we reset with TAP T-L-R */
  729. if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_trst == 1)) && (req_srst == 0))
  730. {
  731. req_trst = 0;
  732. trst_with_tms = 1;
  733. }
  734. if (req_srst && !(jtag_reset_config & RESET_HAS_SRST))
  735. {
  736. ERROR("requested nSRST assertion, but the current configuration doesn't support this");
  737. return ERROR_JTAG_RESET_CANT_SRST;
  738. }
  739. if (req_trst && !(jtag_reset_config & RESET_HAS_TRST))
  740. {
  741. req_trst = 0;
  742. trst_with_tms = 1;
  743. }
  744. /* allocate memory for a new list member */
  745. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  746. (*last_cmd)->next = NULL;
  747. last_comand_pointer = &((*last_cmd)->next);
  748. (*last_cmd)->type = JTAG_RESET;
  749. (*last_cmd)->cmd.reset = cmd_queue_alloc(sizeof(reset_command_t));
  750. (*last_cmd)->cmd.reset->trst = req_trst;
  751. (*last_cmd)->cmd.reset->srst = req_srst;
  752. jtag_trst = req_trst;
  753. jtag_srst = req_srst;
  754. if (jtag_srst)
  755. {
  756. jtag_call_event_callbacks(JTAG_SRST_ASSERTED);
  757. }
  758. else
  759. {
  760. jtag_call_event_callbacks(JTAG_SRST_RELEASED);
  761. if (jtag_nsrst_delay)
  762. jtag_add_sleep(jtag_nsrst_delay * 1000);
  763. }
  764. if (trst_with_tms)
  765. {
  766. last_cmd = &((*last_cmd)->next);
  767. /* allocate memory for a new list member */
  768. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  769. (*last_cmd)->next = NULL;
  770. last_comand_pointer = &((*last_cmd)->next);
  771. (*last_cmd)->type = JTAG_STATEMOVE;
  772. (*last_cmd)->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
  773. (*last_cmd)->cmd.statemove->end_state = TAP_TLR;
  774. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  775. cmd_queue_cur_state = TAP_TLR;
  776. cmd_queue_end_state = TAP_TLR;
  777. return ERROR_OK;
  778. }
  779. else
  780. {
  781. if (jtag_trst)
  782. {
  783. /* we just asserted nTRST, so we're now in Test-Logic-Reset,
  784. * and inform possible listeners about this
  785. */
  786. cmd_queue_cur_state = TAP_TLR;
  787. jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
  788. }
  789. else
  790. {
  791. /* the nTRST line got deasserted, so we're still in Test-Logic-Reset,
  792. * but we might want to add a delay to give the TAP time to settle
  793. */
  794. if (jtag_ntrst_delay)
  795. jtag_add_sleep(jtag_ntrst_delay * 1000);
  796. }
  797. }
  798. return ERROR_OK;
  799. }
  800. int jtag_add_end_state(enum tap_state state)
  801. {
  802. jtag_command_t **last_cmd = jtag_get_last_command_p();
  803. /* allocate memory for a new list member */
  804. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  805. (*last_cmd)->next = NULL;
  806. last_comand_pointer = &((*last_cmd)->next);
  807. (*last_cmd)->type = JTAG_END_STATE;
  808. (*last_cmd)->cmd.end_state = cmd_queue_alloc(sizeof(end_state_command_t));
  809. (*last_cmd)->cmd.end_state->end_state = state;
  810. if (state != -1)
  811. cmd_queue_end_state = state;
  812. return ERROR_OK;
  813. }
  814. int jtag_add_sleep(u32 us)
  815. {
  816. jtag_command_t **last_cmd = jtag_get_last_command_p();
  817. /* allocate memory for a new list member */
  818. *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
  819. (*last_cmd)->next = NULL;
  820. last_comand_pointer = &((*last_cmd)->next);
  821. (*last_cmd)->type = JTAG_SLEEP;
  822. (*last_cmd)->cmd.sleep = cmd_queue_alloc(sizeof(sleep_command_t));
  823. (*last_cmd)->cmd.sleep->us = us;
  824. return ERROR_OK;
  825. }
  826. int jtag_scan_size(scan_command_t *cmd)
  827. {
  828. int bit_count = 0;
  829. int i;
  830. /* count bits in scan command */
  831. for (i=0; i<cmd->num_fields; i++)
  832. {
  833. bit_count += cmd->fields[i].num_bits;
  834. }
  835. return bit_count;
  836. }
  837. int jtag_build_buffer(scan_command_t *cmd, u8 **buffer)
  838. {
  839. int bit_count = 0;
  840. int i;
  841. bit_count = jtag_scan_size(cmd);
  842. *buffer = malloc(CEIL(bit_count, 8));
  843. bit_count = 0;
  844. for (i = 0; i < cmd->num_fields; i++)
  845. {
  846. if (cmd->fields[i].out_value)
  847. {
  848. #ifdef _DEBUG_JTAG_IO_
  849. char* char_buf = buf_to_str(cmd->fields[i].out_value, (cmd->fields[i].num_bits > 64) ? 64 : cmd->fields[i].num_bits, 16);
  850. #endif
  851. buf_set_buf(cmd->fields[i].out_value, 0, *buffer, bit_count, cmd->fields[i].num_bits);
  852. #ifdef _DEBUG_JTAG_IO_
  853. DEBUG("fields[%i].out_value: 0x%s", i, char_buf);
  854. free(char_buf);
  855. #endif
  856. }
  857. bit_count += cmd->fields[i].num_bits;
  858. }
  859. return bit_count;
  860. }
  861. int jtag_read_buffer(u8 *buffer, scan_command_t *cmd)
  862. {
  863. int i;
  864. int bit_count = 0;
  865. int retval;
  866. /* we return ERROR_OK, unless a check fails, or a handler reports a problem */
  867. retval = ERROR_OK;
  868. for (i=0; i < cmd->num_fields; i++)
  869. {
  870. /* if neither in_value, in_check_value nor in_handler
  871. * are specified we don't have to examine this field
  872. */
  873. if (cmd->fields[i].in_value || cmd->fields[i].in_check_value || cmd->fields[i].in_handler)
  874. {
  875. int num_bits = cmd->fields[i].num_bits;
  876. u8 *captured = buf_set_buf(buffer, bit_count, malloc(CEIL(num_bits, 8)), 0, num_bits);
  877. #ifdef _DEBUG_JTAG_IO_
  878. char *char_buf;
  879. char_buf = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
  880. DEBUG("fields[%i].in_value: 0x%s", i, char_buf);
  881. free(char_buf);
  882. #endif
  883. if (cmd->fields[i].in_value)
  884. {
  885. buf_cpy(captured, cmd->fields[i].in_value, num_bits);
  886. if (cmd->fields[i].in_handler)
  887. {
  888. if (cmd->fields[i].in_handler(cmd->fields[i].in_value, cmd->fields[i].in_handler_priv) != ERROR_OK)
  889. {
  890. WARNING("in_handler reported a failed check");
  891. retval = ERROR_JTAG_QUEUE_FAILED;
  892. }
  893. }
  894. }
  895. /* no in_value specified, but a handler takes care of the scanned data */
  896. if (cmd->fields[i].in_handler && (!cmd->fields[i].in_value))
  897. {
  898. if (cmd->fields[i].in_handler(captured, cmd->fields[i].in_handler_priv) != ERROR_OK)
  899. {
  900. /* We're going to call the error:handler later, but if the in_handler
  901. * reported an error we report this failure upstream
  902. */
  903. WARNING("in_handler reported a failed check");
  904. retval = ERROR_JTAG_QUEUE_FAILED;
  905. }
  906. }
  907. if (cmd->fields[i].in_check_value)
  908. {
  909. int compare_failed = 0;
  910. if (cmd->fields[i].in_check_mask)
  911. compare_failed = buf_cmp_mask(captured, cmd->fields[i].in_check_value, cmd->fields[i].in_check_mask, num_bits);
  912. else
  913. compare_failed = buf_cmp(captured, cmd->fields[i].in_check_value, num_bits);
  914. if (compare_failed)
  915. {
  916. if (cmd->error_handler)
  917. {
  918. /* ask the error handler if once has been specified if this is a real problem */
  919. if (cmd->error_handler->error_handler(captured, cmd->error_handler->error_handler_priv) != ERROR_OK)
  920. retval = ERROR_JTAG_QUEUE_FAILED;
  921. else
  922. compare_failed = 0;
  923. }
  924. else
  925. {
  926. /* if there wasn't a handler specified, we report a failure */
  927. retval = ERROR_JTAG_QUEUE_FAILED;
  928. }
  929. /* An error handler could have caught the failing check
  930. * only report a problem when there wasn't a handler, or if the handler
  931. * acknowledged the error
  932. */
  933. if (compare_failed)
  934. {
  935. char *captured_char = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
  936. char *in_check_value_char = buf_to_str(cmd->fields[i].in_check_value, (num_bits > 64) ? 64 : num_bits, 16);
  937. if (cmd->fields[i].in_check_mask)
  938. {
  939. char *in_check_mask_char;
  940. in_check_mask_char = buf_to_str(cmd->fields[i].in_check_mask, (num_bits > 64) ? 64 : num_bits, 16);
  941. WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s check_mask: 0x%s", captured_char, in_check_value_char, in_check_mask_char);
  942. free(in_check_mask_char);
  943. }
  944. else
  945. {
  946. WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s", captured_char, in_check_value_char);
  947. }
  948. free(captured_char);
  949. free(in_check_value_char);
  950. }
  951. }
  952. }
  953. free(captured);
  954. }
  955. bit_count += cmd->fields[i].num_bits;
  956. }
  957. return retval;
  958. }
  959. enum scan_type jtag_scan_type(scan_command_t *cmd)
  960. {
  961. int i;
  962. int type = 0;
  963. for (i=0; i < cmd->num_fields; i++)
  964. {
  965. if (cmd->fields[i].in_check_value || cmd->fields[i].in_value || cmd->fields[i].in_handler)
  966. type |= SCAN_IN;
  967. if (cmd->fields[i].out_value)
  968. type |= SCAN_OUT;
  969. }
  970. return type;
  971. }
  972. int jtag_execute_queue(void)
  973. {
  974. int retval;
  975. retval = jtag->execute_queue();
  976. cmd_queue_free();
  977. jtag_command_queue = NULL;
  978. last_comand_pointer = &jtag_command_queue;
  979. return retval;
  980. }
  981. int jtag_cancel_queue(void)
  982. {
  983. cmd_queue_free();
  984. jtag_command_queue = NULL;
  985. last_comand_pointer = &jtag_command_queue;
  986. return ERROR_OK;
  987. }
  988. int jtag_reset_callback(enum jtag_event event, void *priv)
  989. {
  990. jtag_device_t *device = priv;
  991. DEBUG("-");
  992. if (event == JTAG_TRST_ASSERTED)
  993. {
  994. buf_set_ones(device->cur_instr, device->ir_length);
  995. device->bypass = 1;
  996. }
  997. return ERROR_OK;
  998. }
  999. void jtag_sleep(u32 us)
  1000. {
  1001. usleep(us);
  1002. }
  1003. /* Try to examine chain layout according to IEEE 1149.1 ยง12
  1004. */
  1005. int jtag_examine_chain()
  1006. {
  1007. jtag_device_t *device = jtag_devices;
  1008. scan_field_t field;
  1009. u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
  1010. int i;
  1011. int bit_count;
  1012. int device_count = 0;
  1013. u8 zero_check = 0x0;
  1014. u8 one_check = 0xff;
  1015. field.device = 0;
  1016. field.num_bits = sizeof(idcode_buffer) * 8;
  1017. field.out_value = idcode_buffer;
  1018. field.out_mask = NULL;
  1019. field.in_value = idcode_buffer;
  1020. field.in_check_value = NULL;
  1021. field.in_check_mask = NULL;
  1022. field.in_handler = NULL;
  1023. field.in_handler_priv = NULL;
  1024. for (i = 0; i < JTAG_MAX_CHAIN_SIZE; i++)
  1025. {
  1026. buf_set_u32(idcode_buffer, i * 32, 32, 0x000000FF);
  1027. }
  1028. jtag_add_plain_dr_scan(1, &field, TAP_TLR, NULL);
  1029. jtag_execute_queue();
  1030. for (i = 0; i < JTAG_MAX_CHAIN_SIZE * 4; i++)
  1031. {
  1032. zero_check |= idcode_buffer[i];
  1033. one_check &= idcode_buffer[i];
  1034. }
  1035. /* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
  1036. if ((zero_check == 0x00) || (one_check == 0xff))
  1037. {
  1038. ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
  1039. exit(-1);
  1040. }
  1041. for (bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;)
  1042. {
  1043. u32 idcode = buf_get_u32(idcode_buffer, bit_count, 32);
  1044. if ((idcode & 1) == 0)
  1045. {
  1046. /* LSB must not be 0, this indicates a device in bypass */
  1047. device_count++;
  1048. bit_count += 1;
  1049. }
  1050. else
  1051. {
  1052. u32 manufacturer;
  1053. u32 part;
  1054. u32 version;
  1055. if (idcode == 0x000000FF)
  1056. {
  1057. /* End of chain (invalid manufacturer ID) */
  1058. break;
  1059. }
  1060. if (device)
  1061. {
  1062. device->idcode = idcode;
  1063. device = device->next;
  1064. }
  1065. device_count++;
  1066. manufacturer = (idcode & 0xffe) >> 1;
  1067. part = (idcode & 0xffff000) >> 12;
  1068. version = (idcode & 0xf0000000) >> 28;
  1069. DEBUG("JTAG device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x",
  1070. idcode, manufacturer, part, version);
  1071. bit_count += 32;
  1072. }
  1073. }
  1074. /* see if number of discovered devices matches configuration */
  1075. if (device_count != jtag_num_devices)
  1076. {
  1077. ERROR("number of discovered devices in JTAG chain (%i) doesn't match configuration (%i)",
  1078. device_count, jtag_num_devices);
  1079. ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
  1080. exit(-1);
  1081. }
  1082. return ERROR_OK;
  1083. }
  1084. int jtag_validate_chain()
  1085. {
  1086. jtag_device_t *device = jtag_devices;
  1087. int total_ir_length = 0;
  1088. u8 *ir_test = NULL;
  1089. scan_field_t field;
  1090. int chain_pos = 0;
  1091. while (device)
  1092. {
  1093. total_ir_length += device->ir_length;
  1094. device = device->next;
  1095. }
  1096. total_ir_length += 2;
  1097. ir_test = malloc(CEIL(total_ir_length, 8));
  1098. buf_set_ones(ir_test, total_ir_length);
  1099. field.device = 0;
  1100. field.num_bits = total_ir_length;
  1101. field.out_value = ir_test;
  1102. field.out_mask = NULL;
  1103. field.in_value = ir_test;
  1104. field.in_check_value = NULL;
  1105. field.in_check_mask = NULL;
  1106. field.in_handler = NULL;
  1107. field.in_handler_priv = NULL;
  1108. jtag_add_plain_ir_scan(1, &field, TAP_TLR, NULL);
  1109. jtag_execute_queue();
  1110. device = jtag_devices;
  1111. while (device)
  1112. {
  1113. if (buf_get_u32(ir_test, chain_pos, 2) != 0x1)
  1114. {
  1115. char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
  1116. ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
  1117. free(cbuf);
  1118. return ERROR_JTAG_INIT_FAILED;
  1119. }
  1120. chain_pos += device->ir_length;
  1121. device = device->next;
  1122. }
  1123. if (buf_get_u32(ir_test, chain_pos, 2) != 0x3)
  1124. {
  1125. char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
  1126. ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
  1127. free(cbuf);
  1128. return ERROR_JTAG_INIT_FAILED;
  1129. }
  1130. free(ir_test);
  1131. return ERROR_OK;
  1132. }
  1133. int jtag_register_commands(struct command_context_s *cmd_ctx)
  1134. {
  1135. register_command(cmd_ctx, NULL, "interface", handle_interface_command,
  1136. COMMAND_CONFIG, NULL);
  1137. register_command(cmd_ctx, NULL, "jtag_speed", handle_jtag_speed_command,
  1138. COMMAND_ANY, "set jtag speed (if supported) <speed>");
  1139. register_command(cmd_ctx, NULL, "jtag_device", handle_jtag_device_command,
  1140. COMMAND_CONFIG, NULL);
  1141. register_command(cmd_ctx, NULL, "reset_config", handle_reset_config_command,
  1142. COMMAND_CONFIG, NULL);
  1143. register_command(cmd_ctx, NULL, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command,
  1144. COMMAND_CONFIG, NULL);
  1145. register_command(cmd_ctx, NULL, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command,
  1146. COMMAND_CONFIG, NULL);
  1147. register_command(cmd_ctx, NULL, "scan_chain", handle_scan_chain_command,
  1148. COMMAND_EXEC, "print current scan chain configuration");
  1149. register_command(cmd_ctx, NULL, "endstate", handle_endstate_command,
  1150. COMMAND_EXEC, "finish JTAG operations in <tap_state>");
  1151. register_command(cmd_ctx, NULL, "jtag_reset", handle_jtag_reset_command,
  1152. COMMAND_EXEC, "toggle reset lines <trst> <srst>");
  1153. register_command(cmd_ctx, NULL, "runtest", handle_runtest_command,
  1154. COMMAND_EXEC, "move to Run-Test/Idle, and execute <num_cycles>");
  1155. register_command(cmd_ctx, NULL, "statemove", handle_statemove_command,
  1156. COMMAND_EXEC, "move to current endstate or [tap_state]");
  1157. register_command(cmd_ctx, NULL, "irscan", handle_irscan_command,
  1158. COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ...");
  1159. register_command(cmd_ctx, NULL, "drscan", handle_drscan_command,
  1160. COMMAND_EXEC, "execute DR scan <device> <var> [dev2] [var2] ...");
  1161. register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command,
  1162. COMMAND_ANY, "verify value captured during Capture-IR <enable|disable>");
  1163. return ERROR_OK;
  1164. }
  1165. int jtag_init(struct command_context_s *cmd_ctx)
  1166. {
  1167. int i, validate_tries = 0;
  1168. DEBUG("-");
  1169. if (jtag_speed == -1)
  1170. jtag_speed = 0;
  1171. if (jtag_interface && (jtag_interface[0] != 0))
  1172. /* configuration var 'jtag_interface' is set, and not empty */
  1173. for (i = 0; jtag_interfaces[i]; i++)
  1174. {
  1175. if (strcmp(jtag_interface, jtag_interfaces[i]->name) == 0)
  1176. {
  1177. jtag_device_t *device;
  1178. device = jtag_devices;
  1179. if (jtag_interfaces[i]->init() != ERROR_OK)
  1180. return ERROR_JTAG_INIT_FAILED;
  1181. jtag = jtag_interfaces[i];
  1182. jtag_ir_scan_size = 0;
  1183. jtag_num_devices = 0;
  1184. while (device != NULL)
  1185. {
  1186. jtag_ir_scan_size += device->ir_length;
  1187. jtag_num_devices++;
  1188. device = device->next;
  1189. }
  1190. jtag_add_statemove(TAP_TLR);
  1191. jtag_execute_queue();
  1192. while (jtag_validate_chain() != ERROR_OK)
  1193. {
  1194. validate_tries++;
  1195. if (validate_tries > 5)
  1196. {
  1197. ERROR("Could not validate JTAG chain, exit");
  1198. exit(-1);
  1199. }
  1200. usleep(10000);
  1201. }
  1202. jtag_examine_chain();
  1203. return ERROR_OK;
  1204. }
  1205. }
  1206. /* no valid interface was found (i.e. the configuration option,
  1207. * didn't match one of the compiled-in interfaces
  1208. */
  1209. ERROR("No valid jtag interface found (%s)", jtag_interface);
  1210. ERROR("compiled-in jtag interfaces:");
  1211. for (i = 0; jtag_interfaces[i]; i++)
  1212. {
  1213. ERROR("%i: %s", i, jtag_interfaces[i]->name);
  1214. }
  1215. jtag = NULL;
  1216. return ERROR_JTAG_INVALID_INTERFACE;
  1217. }
  1218. int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1219. {
  1220. int i;
  1221. /* only if the configuration var isn't overwritten from cmdline */
  1222. if (!jtag_interface)
  1223. {
  1224. if (args[0] && (args[0][0] != 0))
  1225. {
  1226. for (i=0; jtag_interfaces[i]; i++)
  1227. {
  1228. if (strcmp(args[0], jtag_interfaces[i]->name) == 0)
  1229. {
  1230. if (jtag_interfaces[i]->register_commands(cmd_ctx) != ERROR_OK)
  1231. exit(-1);
  1232. jtag_interface = jtag_interfaces[i]->name;
  1233. return ERROR_OK;
  1234. }
  1235. }
  1236. }
  1237. /* remember the requested interface name, so we can complain about it later */
  1238. jtag_interface = strdup(args[0]);
  1239. DEBUG("'interface' command didn't specify a valid interface");
  1240. }
  1241. return ERROR_OK;
  1242. }
  1243. int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1244. {
  1245. jtag_device_t **last_device_p = &jtag_devices;
  1246. if (*last_device_p)
  1247. {
  1248. while ((*last_device_p)->next)
  1249. last_device_p = &((*last_device_p)->next);
  1250. last_device_p = &((*last_device_p)->next);
  1251. }
  1252. if (argc < 3)
  1253. return ERROR_OK;
  1254. *last_device_p = malloc(sizeof(jtag_device_t));
  1255. (*last_device_p)->ir_length = strtoul(args[0], NULL, 0);
  1256. (*last_device_p)->expected = malloc((*last_device_p)->ir_length);
  1257. buf_set_u32((*last_device_p)->expected, 0, (*last_device_p)->ir_length, strtoul(args[1], NULL, 0));
  1258. (*last_device_p)->expected_mask = malloc((*last_device_p)->ir_length);
  1259. buf_set_u32((*last_device_p)->expected_mask, 0, (*last_device_p)->ir_length, strtoul(args[2], NULL, 0));
  1260. (*last_device_p)->cur_instr = malloc((*last_device_p)->ir_length);
  1261. (*last_device_p)->bypass = 1;
  1262. buf_set_ones((*last_device_p)->cur_instr, (*last_device_p)->ir_length);
  1263. (*last_device_p)->next = NULL;
  1264. jtag_register_event_callback(jtag_reset_callback, (*last_device_p));
  1265. jtag_num_devices++;
  1266. return ERROR_OK;
  1267. }
  1268. int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1269. {
  1270. jtag_device_t *device = jtag_devices;
  1271. int device_count = 0;
  1272. while (device)
  1273. {
  1274. u32 expected, expected_mask, cur_instr;
  1275. expected = buf_get_u32(device->expected, 0, device->ir_length);
  1276. expected_mask = buf_get_u32(device->expected_mask, 0, device->ir_length);
  1277. cur_instr = buf_get_u32(device->cur_instr, 0, device->ir_length);
  1278. command_print(cmd_ctx, "%i: idcode: 0x%8.8x ir length %i, ir capture 0x%x, ir mask 0x%x, current instruction 0x%x", device_count, device->idcode, device->ir_length, expected, expected_mask, cur_instr);
  1279. device = device->next;
  1280. device_count++;
  1281. }
  1282. return ERROR_OK;
  1283. }
  1284. int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1285. {
  1286. if (argc >= 1)
  1287. {
  1288. if (strcmp(args[0], "none") == 0)
  1289. jtag_reset_config = RESET_NONE;
  1290. else if (strcmp(args[0], "trst_only") == 0)
  1291. jtag_reset_config = RESET_HAS_TRST;
  1292. else if (strcmp(args[0], "srst_only") == 0)
  1293. jtag_reset_config = RESET_HAS_SRST;
  1294. else if (strcmp(args[0], "trst_and_srst") == 0)
  1295. jtag_reset_config = RESET_TRST_AND_SRST;
  1296. else
  1297. {
  1298. ERROR("invalid reset_config argument");
  1299. exit(-1);
  1300. }
  1301. }
  1302. if (argc >= 2)
  1303. {
  1304. if (strcmp(args[1], "srst_pulls_trst") == 0)
  1305. jtag_reset_config |= RESET_SRST_PULLS_TRST;
  1306. else if (strcmp(args[1], "trst_pulls_srst") == 0)
  1307. jtag_reset_config |= RESET_TRST_PULLS_SRST;
  1308. else if (strcmp(args[1], "combined") == 0)
  1309. jtag_reset_config |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
  1310. else if (strcmp(args[1], "separate") == 0)
  1311. jtag_reset_config &= ~(RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST);
  1312. else
  1313. {
  1314. ERROR("invalid reset_config argument");
  1315. exit(-1);
  1316. }
  1317. }
  1318. if (argc >= 3)
  1319. {
  1320. if (strcmp(args[2], "trst_open_drain") == 0)
  1321. jtag_reset_config |= RESET_TRST_OPEN_DRAIN;
  1322. else if (strcmp(args[2], "trst_push_pull") == 0)
  1323. jtag_reset_config &= ~RESET_TRST_OPEN_DRAIN;
  1324. else
  1325. {
  1326. ERROR("invalid reset_config argument");
  1327. exit(-1);
  1328. }
  1329. }
  1330. if (argc >= 4)
  1331. {
  1332. if (strcmp(args[3], "srst_push_pull") == 0)
  1333. jtag_reset_config |= RESET_SRST_PUSH_PULL;
  1334. else if (strcmp(args[3], "srst_open_drain") == 0)
  1335. jtag_reset_config &= ~RESET_SRST_PUSH_PULL;
  1336. else
  1337. {
  1338. ERROR("invalid reset_config argument");
  1339. exit(-1);
  1340. }
  1341. }
  1342. return ERROR_OK;
  1343. }
  1344. int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1345. {
  1346. if (argc < 1)
  1347. {
  1348. ERROR("jtag_nsrst_delay <ms> command takes one required argument");
  1349. exit(-1);
  1350. }
  1351. else
  1352. {
  1353. jtag_nsrst_delay = strtoul(args[0], NULL, 0);
  1354. }
  1355. return ERROR_OK;
  1356. }
  1357. int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1358. {
  1359. if (argc < 1)
  1360. {
  1361. ERROR("jtag_ntrst_delay <ms> command takes one required argument");
  1362. exit(-1);
  1363. }
  1364. else
  1365. {
  1366. jtag_ntrst_delay = strtoul(args[0], NULL, 0);
  1367. }
  1368. return ERROR_OK;
  1369. }
  1370. int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1371. {
  1372. if (argc == 0)
  1373. command_print(cmd_ctx, "jtag_speed: %i", jtag_speed);
  1374. if (argc > 0)
  1375. {
  1376. /* this command can be called during CONFIG,
  1377. * in which case jtag isn't initialized */
  1378. if (jtag)
  1379. jtag->speed(strtoul(args[0], NULL, 0));
  1380. else
  1381. jtag_speed = strtoul(args[0], NULL, 0);
  1382. }
  1383. return ERROR_OK;
  1384. }
  1385. int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1386. {
  1387. enum tap_state state;
  1388. if (argc < 1)
  1389. {
  1390. command_print(cmd_ctx, "usage: endstate <tap_state>");
  1391. }
  1392. else
  1393. {
  1394. for (state = 0; state < 16; state++)
  1395. {
  1396. if (strcmp(args[0], tap_state_strings[state]) == 0)
  1397. {
  1398. jtag_add_end_state(state);
  1399. jtag_execute_queue();
  1400. }
  1401. }
  1402. }
  1403. command_print(cmd_ctx, "current endstate: %s", tap_state_strings[end_state]);
  1404. return ERROR_OK;
  1405. }
  1406. int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1407. {
  1408. int trst = -1;
  1409. int srst = -1;
  1410. char *usage = "usage: jtag_reset <trst> <srst>";
  1411. int retval;
  1412. if (argc < 1)
  1413. {
  1414. command_print(cmd_ctx, usage);
  1415. return ERROR_OK;
  1416. }
  1417. if (args[0][0] == '1')
  1418. trst = 1;
  1419. else if (args[0][0] == '0')
  1420. trst = 0;
  1421. else
  1422. {
  1423. command_print(cmd_ctx, usage);
  1424. return ERROR_OK;
  1425. }
  1426. if (args[1][0] == '1')
  1427. srst = 1;
  1428. else if (args[1][0] == '0')
  1429. srst = 0;
  1430. else
  1431. {
  1432. command_print(cmd_ctx, usage);
  1433. return ERROR_OK;
  1434. }
  1435. if ((retval = jtag_add_reset(trst, srst)) != ERROR_OK)
  1436. {
  1437. switch (retval)
  1438. {
  1439. case ERROR_JTAG_RESET_WOULD_ASSERT_TRST:
  1440. command_print(cmd_ctx, "requested reset would assert trst\nif this is acceptable, use jtag_reset 1 %c", args[1][0]);
  1441. break;
  1442. case ERROR_JTAG_RESET_CANT_SRST:
  1443. command_print(cmd_ctx, "can't assert srst because the current reset_config doesn't support it");
  1444. break;
  1445. default:
  1446. command_print(cmd_ctx, "unknown error");
  1447. }
  1448. }
  1449. jtag_execute_queue();
  1450. return ERROR_OK;
  1451. }
  1452. int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1453. {
  1454. if (argc < 1)
  1455. {
  1456. command_print(cmd_ctx, "usage: runtest <num_cycles>");
  1457. return ERROR_OK;
  1458. }
  1459. jtag_add_runtest(strtol(args[0], NULL, 0), -1);
  1460. jtag_execute_queue();
  1461. return ERROR_OK;
  1462. }
  1463. int handle_statemove_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1464. {
  1465. enum tap_state state;
  1466. state = -1;
  1467. if (argc == 1)
  1468. {
  1469. for (state = 0; state < 16; state++)
  1470. {
  1471. if (strcmp(args[0], tap_state_strings[state]) == 0)
  1472. {
  1473. break;
  1474. }
  1475. }
  1476. }
  1477. jtag_add_statemove(state);
  1478. jtag_execute_queue();
  1479. return ERROR_OK;
  1480. }
  1481. int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1482. {
  1483. int i;
  1484. scan_field_t *fields;
  1485. if ((argc < 2) || (argc % 2))
  1486. {
  1487. command_print(cmd_ctx, "usage: irscan <device> <instr> [dev2] [instr2] ...");
  1488. return ERROR_OK;
  1489. }
  1490. fields = malloc(sizeof(scan_field_t) * argc / 2);
  1491. for (i = 0; i < argc / 2; i++)
  1492. {
  1493. int device = strtoul(args[i*2], NULL, 0);
  1494. int field_size = jtag_get_device(device)->ir_length;
  1495. fields[i].device = device;
  1496. fields[i].out_value = malloc(CEIL(field_size, 8));
  1497. buf_set_u32(fields[i].out_value, 0, field_size, strtoul(args[i*2+1], NULL, 0));
  1498. fields[i].out_mask = NULL;
  1499. fields[i].in_value = NULL;
  1500. fields[i].in_check_mask = NULL;
  1501. fields[i].in_handler = NULL;
  1502. fields[i].in_handler_priv = NULL;
  1503. }
  1504. jtag_add_ir_scan(argc / 2, fields, -1, NULL);
  1505. jtag_execute_queue();
  1506. for (i = 0; i < argc / 2; i++)
  1507. free(fields[i].out_value);
  1508. free (fields);
  1509. return ERROR_OK;
  1510. }
  1511. int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1512. {
  1513. scan_field_t *fields;
  1514. int num_fields = 0;
  1515. int field_count = 0;
  1516. var_t *var;
  1517. int i, j;
  1518. if ((argc < 2) || (argc % 2))
  1519. {
  1520. command_print(cmd_ctx, "usage: drscan <device> <var> [dev2] [var2]");
  1521. return ERROR_OK;
  1522. }
  1523. for (i = 0; i < argc; i+=2)
  1524. {
  1525. var = get_var_by_namenum(args[i+1]);
  1526. if (var)
  1527. {
  1528. num_fields += var->num_fields;
  1529. }
  1530. else
  1531. {
  1532. command_print(cmd_ctx, "variable %s doesn't exist", args[i+1]);
  1533. return ERROR_OK;
  1534. }
  1535. }
  1536. fields = malloc(sizeof(scan_field_t) * num_fields);
  1537. for (i = 0; i < argc; i+=2)
  1538. {
  1539. var = get_var_by_namenum(args[i+1]);
  1540. for (j = 0; j < var->num_fields; j++)
  1541. {
  1542. fields[field_count].device = strtol(args[i], NULL, 0);
  1543. fields[field_count].num_bits = var->fields[j].num_bits;
  1544. fields[field_count].out_value = malloc(CEIL(var->fields[j].num_bits, 8));
  1545. buf_set_u32(fields[field_count].out_value, 0, var->fields[j].num_bits, var->fields[j].value);
  1546. fields[field_count].out_mask = NULL;
  1547. fields[field_count].in_value = fields[field_count].out_value;
  1548. fields[field_count].in_check_mask = NULL;
  1549. fields[field_count].in_check_value = NULL;
  1550. fields[field_count].in_handler = field_le_to_host;
  1551. fields[field_count++].in_handler_priv = &(var->fields[j]);
  1552. }
  1553. }
  1554. jtag_add_dr_scan(num_fields, fields, -1, NULL);
  1555. jtag_execute_queue();
  1556. for (i = 0; i < argc / 2; i++)
  1557. free(fields[i].out_value);
  1558. free(fields);
  1559. return ERROR_OK;
  1560. }
  1561. int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
  1562. {
  1563. if (argc == 0)
  1564. {
  1565. command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");
  1566. return ERROR_OK;
  1567. }
  1568. if (strcmp(args[0], "enable") == 0)
  1569. {
  1570. jtag_verify_capture_ir = 1;
  1571. }
  1572. else if (strcmp(args[0], "disable") == 0)
  1573. {
  1574. jtag_verify_capture_ir = 0;
  1575. }
  1576. return ERROR_OK;
  1577. }