X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Ftcl.c;h=923542f8e35bf422966595277c54f9e6b885afe5;hp=212be35577bc6a8383c3c3a98fe89f3d2fa6cd75;hb=a585bdf7269ce5c861c83ee3294ba1f074e9c877;hpb=7c7467b34f11939fbce41e39dfa1b6b0e110a89c diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 212be35577..923542f8e3 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -51,34 +51,6 @@ static const Jim_Nvp nvp_jtag_tap_event[] = { extern jtag_interface_t *jtag_interface; -/* jtag commands */ -static int handle_interface_list_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc); -static int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_rclk_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_nsrst_assert_width_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_jtag_ntrst_assert_width_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); - -static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); - -static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *argv); -static int Jim_Command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *argv); -static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args); - -static int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_verify_jtag_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int handle_tms_sequence_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); - - enum jtag_tap_cfg_param { JCFG_EVENT }; @@ -197,7 +169,6 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) jim_wide w; int x; int e; - int reqbits; Jim_Nvp *n; char *cp; const Jim_Nvp opts[] = { @@ -252,9 +223,6 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) pTap->ir_capture_mask = 0x03; pTap->ir_capture_value = 0x01; - /* clear flags for "required options" them as we find them */ - reqbits = 1; - while (goi->argc) { e = Jim_GetOpt_Nvp(goi, opts, &n); if (e != JIM_OK) { @@ -317,7 +285,6 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) pTap->dotted_name, (int) w); pTap->ir_length = w; - reqbits = 0; break; case NTAP_OPT_IRMASK: if (is_bad_irval(pTap->ir_length, w)) { @@ -355,14 +322,14 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) pTap->enabled = !pTap->disabled_after_reset; /* Did all the required option bits get cleared? */ - if (0 == reqbits) + if (pTap->ir_length != 0) { jtag_tap_init(pTap); return ERROR_OK; } Jim_SetResult_sprintf(goi->interp, - "newtap: %s missing required parameters", + "newtap: %s missing IR length", pTap->dotted_name); jtag_tap_free(pTap); return JIM_ERR; @@ -410,6 +377,7 @@ static int jim_jtag_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) enum { JTAG_CMD_INTERFACE, + JTAG_CMD_INIT, JTAG_CMD_INIT_RESET, JTAG_CMD_NEWTAP, JTAG_CMD_TAPENABLE, @@ -422,6 +390,7 @@ static int jim_jtag_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) const Jim_Nvp jtag_cmds[] = { { .name = "interface" , .value = JTAG_CMD_INTERFACE }, + { .name = "arp_init" , .value = JTAG_CMD_INIT }, { .name = "arp_init-reset", .value = JTAG_CMD_INIT_RESET }, { .name = "newtap" , .value = JTAG_CMD_NEWTAP }, { .name = "tapisenabled" , .value = JTAG_CMD_TAPISENABLED }, @@ -453,7 +422,19 @@ static int jim_jtag_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)"); return JIM_ERR; } - Jim_SetResultString(goi.interp, jtag_interface->name, -1); + const char *name = jtag_interface ? jtag_interface->name : NULL; + Jim_SetResultString(goi.interp, name ? : "undefined", -1); + return JIM_OK; + case JTAG_CMD_INIT: + if (goi.argc != 0) { + Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)"); + return JIM_ERR; + } + e = jtag_init_inner(context); + if (e != ERROR_OK) { + Jim_SetResult_sprintf(goi.interp, "error: %d", e); + return JIM_ERR; + } return JIM_OK; case JTAG_CMD_INIT_RESET: if (goi.argc != 0) { @@ -598,58 +579,6 @@ void jtag_notify_event(enum jtag_event event) } -int jtag_register_commands(struct command_context_s *cmd_ctx) -{ - register_jim(cmd_ctx, "jtag", jim_jtag_command, "perform jtag tap actions"); - - register_command(cmd_ctx, NULL, "interface", handle_interface_command, - COMMAND_CONFIG, "try to configure interface"); - register_command(cmd_ctx, NULL, - "interface_list", &handle_interface_list_command, - COMMAND_ANY, "list all built-in interfaces"); - register_command(cmd_ctx, NULL, "jtag_speed", handle_jtag_speed_command, - COMMAND_ANY, "(DEPRECATED) set jtag speed (if supported)"); - register_command(cmd_ctx, NULL, "jtag_khz", handle_jtag_khz_command, - COMMAND_ANY, "set maximum jtag speed (if supported); " - "parameter is maximum khz, or 0 for adaptive clocking (RTCK)."); - register_command(cmd_ctx, NULL, "jtag_rclk", handle_jtag_rclk_command, - COMMAND_ANY, "fallback_speed_khz - set JTAG speed to RCLK or use fallback speed"); - register_command(cmd_ctx, NULL, "jtag_device", handle_jtag_device_command, - COMMAND_CONFIG, "(DEPRECATED) jtag_device "); - register_command(cmd_ctx, NULL, "reset_config", handle_reset_config_command, - COMMAND_ANY, - "[none/trst_only/srst_only/trst_and_srst] [srst_pulls_trst/trst_pulls_srst] [combined/separate] [trst_push_pull/trst_open_drain] [srst_push_pull/srst_open_drain]"); - register_command(cmd_ctx, NULL, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command, - COMMAND_ANY, "jtag_nsrst_delay - delay after deasserting srst in ms"); - register_command(cmd_ctx, NULL, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command, - COMMAND_ANY, "jtag_ntrst_delay - delay after deasserting trst in ms"); - register_command(cmd_ctx, NULL, "jtag_nsrst_assert_width", handle_jtag_nsrst_assert_width_command, - COMMAND_ANY, "jtag_nsrst_assert_width - delay after asserting srst in ms"); - register_command(cmd_ctx, NULL, "jtag_ntrst_assert_width", handle_jtag_ntrst_assert_width_command, - COMMAND_ANY, "jtag_ntrst_assert_width - delay after asserting trst in ms"); - - register_command(cmd_ctx, NULL, "scan_chain", handle_scan_chain_command, - COMMAND_EXEC, "print current scan chain configuration"); - - register_command(cmd_ctx, NULL, "jtag_reset", handle_jtag_reset_command, - COMMAND_EXEC, "toggle reset lines "); - register_command(cmd_ctx, NULL, "runtest", handle_runtest_command, - COMMAND_EXEC, "move to Run-Test/Idle, and execute "); - register_command(cmd_ctx, NULL, "irscan", handle_irscan_command, - COMMAND_EXEC, "execute IR scan [dev2] [instr2] ..."); - register_jim(cmd_ctx, "drscan", Jim_Command_drscan, "execute DR scan ..."); - register_jim(cmd_ctx, "flush_count", Jim_Command_flush_count, "returns number of times the JTAG queue has been flushed"); - register_jim(cmd_ctx, "pathmove", Jim_Command_pathmove, "move JTAG to state1 then to state2, state3, etc. ,,..."); - - register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command, - COMMAND_ANY, "verify value captured during Capture-IR "); - register_command(cmd_ctx, NULL, "verify_jtag", handle_verify_jtag_command, - COMMAND_ANY, "verify value capture "); - register_command(cmd_ctx, NULL, "tms_sequence", handle_tms_sequence_command, - COMMAND_ANY, "choose short(default) or long tms_sequence "); - return ERROR_OK; -} - static int default_khz(int khz, int *jtag_speed) { LOG_ERROR("Translation from khz to jtag_speed not implemented"); @@ -674,8 +603,22 @@ static int default_srst_asserted(int *srst_asserted) return ERROR_OK; } -static int handle_interface_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_interface_list_command) +{ + if (strcmp(CMD_NAME, "interface_list") == 0 && argc > 0) + return ERROR_COMMAND_SYNTAX_ERROR; + + command_print(cmd_ctx, "The following JTAG interfaces are available:"); + for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) + { + const char *name = jtag_interfaces[i]->name; + command_print(cmd_ctx, "%u: %s", i + 1, name); + } + + return ERROR_OK; +} + +COMMAND_HANDLER(handle_interface_command) { /* check whether the interface is already configured */ if (jtag_interface) @@ -715,88 +658,11 @@ static int handle_interface_command(struct command_context_s *cmd_ctx, * didn't match one of the compiled-in interfaces */ LOG_ERROR("The specified JTAG interface was not found (%s)", args[0]); - handle_interface_list_command(cmd_ctx, cmd, args, argc); + CALL_COMMAND_HANDLER(handle_interface_list_command); return ERROR_JTAG_INVALID_INTERFACE; } -static int handle_interface_list_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) -{ - if (strcmp(cmd, "interface_list") == 0 && argc > 0) - return ERROR_COMMAND_SYNTAX_ERROR; - - command_print(cmd_ctx, "The following JTAG interfaces are available:"); - for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) - { - const char *name = jtag_interfaces[i]->name; - command_print(cmd_ctx, "%u: %s", i + 1, name); - } - - return ERROR_OK; -} - -static int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) -{ - int e; - char buf[1024]; - Jim_Obj *newargs[ 10 ]; - /* - * CONVERT SYNTAX - * argv[-1] = command - * argv[ 0] = ir length - * argv[ 1] = ir capture - * argv[ 2] = ir mask - * argv[ 3] = not actually used by anything but in the docs - */ - - if (argc < 4) { - command_print(cmd_ctx, "OLD DEPRECATED SYNTAX: Please use the NEW syntax"); - return ERROR_OK; - } - command_print(cmd_ctx, "OLD SYNTAX: DEPRECATED - translating to new syntax"); - command_print(cmd_ctx, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s", - args[0], - args[1], - args[2]); - command_print(cmd_ctx, "Example: STM32 has 2 taps, the cortexM3(len4) + boundaryscan(len5)"); - command_print(cmd_ctx, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\""); - command_print(cmd_ctx, "jtag newtap stm32 boundary ....., and the tap: \"stm32.boundary\""); - command_print(cmd_ctx, "And then refer to the taps by the dotted name."); - - newargs[0] = Jim_NewStringObj(interp, "jtag", -1); - newargs[1] = Jim_NewStringObj(interp, "newtap", -1); - sprintf(buf, "chip%d", jtag_tap_count()); - newargs[2] = Jim_NewStringObj(interp, buf, -1); - sprintf(buf, "tap%d", jtag_tap_count()); - newargs[3] = Jim_NewStringObj(interp, buf, -1); - newargs[4] = Jim_NewStringObj(interp, "-irlen", -1); - newargs[5] = Jim_NewStringObj(interp, args[0], -1); - newargs[6] = Jim_NewStringObj(interp, "-ircapture", -1); - newargs[7] = Jim_NewStringObj(interp, args[1], -1); - newargs[8] = Jim_NewStringObj(interp, "-irmask", -1); - newargs[9] = Jim_NewStringObj(interp, args[2], -1); - - command_print(cmd_ctx, "NEW COMMAND:"); - sprintf(buf, "%s %s %s %s %s %s %s %s %s %s", - Jim_GetString(newargs[0], NULL), - Jim_GetString(newargs[1], NULL), - Jim_GetString(newargs[2], NULL), - Jim_GetString(newargs[3], NULL), - Jim_GetString(newargs[4], NULL), - Jim_GetString(newargs[5], NULL), - Jim_GetString(newargs[6], NULL), - Jim_GetString(newargs[7], NULL), - Jim_GetString(newargs[8], NULL), - Jim_GetString(newargs[9], NULL)); - - e = jim_jtag_command(interp, 10, newargs); - if (e != JIM_OK) { - command_print(cmd_ctx, "%s", Jim_GetString(Jim_GetResult(interp), NULL)); - } - return e; -} - -static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_scan_chain_command) { jtag_tap_t *tap; @@ -833,14 +699,11 @@ static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cm return ERROR_OK; } -static int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_reset_config_command) { int new_cfg = 0; int mask = 0; - if (argc < 1) - return ERROR_COMMAND_SYNTAX_ERROR; - /* Original versions cared about the order of these tokens: * reset_config signals [combination [trst_type [srst_type]]] * They also clobbered the previous configuration even on error. @@ -852,13 +715,21 @@ static int handle_reset_config_command(struct command_context_s *cmd_ctx, char * int tmp = 0; int m; - m = RESET_SRST_GATES_JTAG; - tmp = 0; + /* gating */ + m = RESET_SRST_NO_GATING; if (strcmp(*args, "srst_gates_jtag") == 0) - { - tmp = RESET_SRST_GATES_JTAG; - goto next; + /* default: don't use JTAG while SRST asserted */; + else if (strcmp(*args, "srst_nogate") == 0) + tmp = RESET_SRST_NO_GATING; + else + m = 0; + if (mask & m) { + LOG_ERROR("extra reset_config %s spec (%s)", + "gating", *args); + return ERROR_INVALID_ARGUMENTS; } + if (m) + goto next; /* signals */ m = RESET_HAS_TRST | RESET_HAS_SRST; @@ -945,108 +816,146 @@ next: } /* clear previous values of those bits, save new values */ - enum reset_types old_cfg = jtag_get_reset_config(); - old_cfg &= ~mask; - new_cfg |= old_cfg; - jtag_set_reset_config(new_cfg); + if (mask) { + int old_cfg = jtag_get_reset_config(); + + old_cfg &= ~mask; + new_cfg |= old_cfg; + jtag_set_reset_config(new_cfg); + } else + new_cfg = jtag_get_reset_config(); + + + /* + * Display the (now-)current reset mode + */ + char *modes[5]; + + /* minimal JTAG has neither SRST nor TRST (so that's the default) */ + switch (new_cfg & (RESET_HAS_TRST | RESET_HAS_SRST)) { + case RESET_HAS_SRST: + modes[0] = "srst_only"; + break; + case RESET_HAS_TRST: + modes[0] = "trst_only"; + break; + case RESET_TRST_AND_SRST: + modes[0] = "trst_and_srst"; + break; + default: + modes[0] = "none"; + break; + } + + /* normally SRST and TRST are decoupled; but bugs happen ... */ + switch (new_cfg & (RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST)) { + case RESET_SRST_PULLS_TRST: + modes[1] = "srst_pulls_trst"; + break; + case RESET_TRST_PULLS_SRST: + modes[1] = "trst_pulls_srst"; + break; + case RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST: + modes[1] = "combined"; + break; + default: + modes[1] = "separate"; + break; + } + + /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */ + if (new_cfg & RESET_HAS_TRST) { + if (new_cfg & RESET_TRST_OPEN_DRAIN) + modes[3] = " trst_open_drain"; + else + modes[3] = " trst_push_pull"; + } else + modes[3] = ""; + + /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */ + if (new_cfg & RESET_HAS_SRST) { + if (new_cfg & RESET_SRST_NO_GATING) + modes[2] = " srst_nogate"; + else + modes[2] = " srst_gates_jtag"; + + if (new_cfg & RESET_SRST_PUSH_PULL) + modes[4] = " srst_push_pull"; + else + modes[4] = " srst_open_drain"; + } else { + modes[2] = ""; + modes[4] = ""; + } + + command_print(cmd_ctx, "%s %s%s%s%s", + modes[0], modes[1], + modes[2], modes[3], modes[4]); return ERROR_OK; } -static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_jtag_nsrst_delay_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; if (argc == 1) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_nsrst_delay(delay); } command_print(cmd_ctx, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay()); return ERROR_OK; } -static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_jtag_ntrst_delay_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; if (argc == 1) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_ntrst_delay(delay); } command_print(cmd_ctx, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay()); return ERROR_OK; } -static int handle_jtag_nsrst_assert_width_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_jtag_nsrst_assert_width_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; if (argc == 1) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_nsrst_assert_width(delay); } command_print(cmd_ctx, "jtag_nsrst_assert_width: %u", jtag_get_nsrst_assert_width()); return ERROR_OK; } -static int handle_jtag_ntrst_assert_width_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; if (argc == 1) { unsigned delay; - int retval = parse_uint(args[0], &delay); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], delay); + jtag_set_ntrst_assert_width(delay); } command_print(cmd_ctx, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width()); return ERROR_OK; } -static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) -{ - int retval = ERROR_OK; - - command_print(cmd_ctx, "OLD SYNTAX: DEPRECATED - " - "use jtag_khz, not jtag_speed"); - - if (argc > 1) - return ERROR_COMMAND_SYNTAX_ERROR; - if (argc == 1) - { - LOG_DEBUG("handle jtag speed"); - - unsigned cur_speed = 0; - int retval = parse_uint(args[0], &cur_speed); - if (ERROR_OK != retval) - return retval; - retval = jtag_config_speed(cur_speed); - - } - command_print(cmd_ctx, "jtag_speed: %d", jtag_get_speed()); - - return retval; -} - -static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_jtag_khz_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1055,9 +964,8 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, if (argc == 1) { unsigned khz = 0; - int retval = parse_uint(args[0], &khz); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], khz); + retval = jtag_config_khz(khz); if (ERROR_OK != retval) return retval; @@ -1076,7 +984,7 @@ static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, return retval; } -static int handle_jtag_rclk_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_jtag_rclk_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1085,9 +993,8 @@ static int handle_jtag_rclk_command(struct command_context_s *cmd_ctx, char *cmd if (argc == 1) { unsigned khz = 0; - int retval = parse_uint(args[0], &khz); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], khz); + retval = jtag_config_rclk(khz); if (ERROR_OK != retval) return retval; @@ -1106,8 +1013,7 @@ static int handle_jtag_rclk_command(struct command_context_s *cmd_ctx, char *cmd return retval; } -static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_jtag_reset_command) { if (argc != 2) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1135,16 +1041,13 @@ static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, return jtag_execute_queue(); } -static int handle_runtest_command(struct command_context_s *cmd_ctx, - char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_runtest_command) { if (argc != 1) return ERROR_COMMAND_SYNTAX_ERROR; unsigned num_clocks; - int retval = parse_uint(args[0], &num_clocks); - if (ERROR_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(uint, args[0], num_clocks); jtag_add_runtest(num_clocks, TAP_IDLE); return jtag_execute_queue(); @@ -1154,6 +1057,8 @@ static int handle_runtest_command(struct command_context_s *cmd_ctx, * For "irscan" or "drscan" commands, the "end" (really, "next") state * should be stable ... and *NOT* a shift state, otherwise free-running * jtag clocks could change the values latched by the update state. + * Not surprisingly, this is the same constraint as SVF; the "irscan" + * and "drscan" commands are a write-only subset of what SVF provides. */ static bool scan_is_safe(tap_state_t state) { @@ -1170,7 +1075,7 @@ static bool scan_is_safe(tap_state_t state) } -static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_irscan_command) { int i; scan_field_t *fields; @@ -1191,25 +1096,14 @@ static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, c if (argc >= 4) { /* have at least one pair of numbers. */ /* is last pair the magic text? */ - if (0 == strcmp("-endstate", args[ argc - 2 ])) { - const char *cpA; - const char *cpS; - cpA = args[ argc-1 ]; - for (endstate = 0 ; endstate < TAP_NUM_STATES ; endstate++) { - cpS = tap_state_name(endstate); - if (0 == strcmp(cpA, cpS)) { - break; - } - } - if (endstate >= TAP_NUM_STATES) { + if (strcmp("-endstate", args[argc - 2]) == 0) { + endstate = tap_state_by_name(args[argc - 1]); + if (endstate == TAP_INVALID) return ERROR_COMMAND_SYNTAX_ERROR; - } else { - if (!scan_is_safe(endstate)) - LOG_WARNING("irscan with unsafe " - "endstate \"%s\"", cpA); - /* found - remove the last 2 args */ - argc -= 2; - } + if (!scan_is_safe(endstate)) + LOG_WARNING("unstable irscan endstate \"%s\"", + args[argc - 1]); + argc -= 2; } } @@ -1456,7 +1350,7 @@ static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const } -static int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_verify_ircapture_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1477,7 +1371,7 @@ static int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, ch return ERROR_OK; } -static int handle_verify_jtag_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_verify_jtag_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1498,7 +1392,7 @@ static int handle_verify_jtag_command(struct command_context_s *cmd_ctx, char *c return ERROR_OK; } -static int handle_tms_sequence_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(handle_tms_sequence_command) { if (argc > 1) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1521,3 +1415,90 @@ static int handle_tms_sequence_command(struct command_context_s *cmd_ctx, char * return ERROR_OK; } + +int jtag_register_commands(struct command_context_s *cmd_ctx) +{ + register_jim(cmd_ctx, "jtag", jim_jtag_command, + "perform jtag tap actions"); + + register_command(cmd_ctx, NULL, "interface", + handle_interface_command, COMMAND_CONFIG, + "try to configure interface"); + register_command(cmd_ctx, NULL, "interface_list", + &handle_interface_list_command, COMMAND_ANY, + "list all built-in interfaces"); + + register_command(cmd_ctx, NULL, "jtag_khz", + handle_jtag_khz_command, COMMAND_ANY, + "set maximum jtag speed (if supported); " + "parameter is maximum khz, or 0 for adaptive clocking (RTCK)."); + register_command(cmd_ctx, NULL, "jtag_rclk", + handle_jtag_rclk_command, COMMAND_ANY, + "fallback_speed_khz - set JTAG speed to RCLK or use fallback speed"); + register_command(cmd_ctx, NULL, "reset_config", + handle_reset_config_command, COMMAND_ANY, + "reset_config " + "[none|trst_only|srst_only|trst_and_srst] " + "[srst_pulls_trst|trst_pulls_srst|combined|separate] " + "[srst_gates_jtag|srst_nogate] " + "[trst_push_pull|trst_open_drain] " + "[srst_push_pull|srst_open_drain]"); + + register_command(cmd_ctx, NULL, "jtag_nsrst_delay", + handle_jtag_nsrst_delay_command, COMMAND_ANY, + "jtag_nsrst_delay " + "- delay after deasserting srst in ms"); + register_command(cmd_ctx, NULL, "jtag_ntrst_delay", + handle_jtag_ntrst_delay_command, COMMAND_ANY, + "jtag_ntrst_delay " + "- delay after deasserting trst in ms"); + + register_command(cmd_ctx, NULL, "jtag_nsrst_assert_width", + handle_jtag_nsrst_assert_width_command, COMMAND_ANY, + "jtag_nsrst_assert_width " + "- delay after asserting srst in ms"); + register_command(cmd_ctx, NULL, "jtag_ntrst_assert_width", + handle_jtag_ntrst_assert_width_command, COMMAND_ANY, + "jtag_ntrst_assert_width " + "- delay after asserting trst in ms"); + + register_command(cmd_ctx, NULL, "scan_chain", + handle_scan_chain_command, COMMAND_EXEC, + "print current scan chain configuration"); + + register_command(cmd_ctx, NULL, "jtag_reset", + handle_jtag_reset_command, COMMAND_EXEC, + "toggle reset lines "); + register_command(cmd_ctx, NULL, "runtest", + handle_runtest_command, COMMAND_EXEC, + "move to Run-Test/Idle, and execute "); + register_command(cmd_ctx, NULL, "irscan", + handle_irscan_command, COMMAND_EXEC, + "execute IR scan [dev2] [instr2] ..."); + + register_jim(cmd_ctx, "drscan", Jim_Command_drscan, + "execute DR scan " + " ..."); + + register_jim(cmd_ctx, "flush_count", Jim_Command_flush_count, + "returns number of times the JTAG queue has been flushed"); + + register_jim(cmd_ctx, "pathmove", Jim_Command_pathmove, + ",,... " + "- move JTAG to state1 then to state2, state3, etc."); + + register_command(cmd_ctx, NULL, "verify_ircapture", + handle_verify_ircapture_command, COMMAND_ANY, + "verify value captured during Capture-IR "); + register_command(cmd_ctx, NULL, "verify_jtag", + handle_verify_jtag_command, COMMAND_ANY, + "verify value capture "); + + register_command(cmd_ctx, NULL, "tms_sequence", + handle_tms_sequence_command, COMMAND_ANY, + "choose short(default) or long tms_sequence "); + + return ERROR_OK; +} + +