fix 'jtag interface' behavior
[openocd.git] / src / jtag / tcl.c
index 212be35577bc6a8383c3c3a98fe89f3d2fa6cd75..b86e006abd175af7afec7da1e79ddc73819c7b73 100644 (file)
@@ -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 <ir_length> <ir_expected> <ir_mask>");
-       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 <ms> - delay after deasserting srst in ms");
-       register_command(cmd_ctx, NULL, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command,
-               COMMAND_ANY, "jtag_ntrst_delay <ms> - 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 <ms> - 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 <ms> - 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 <trst> <srst>");
-       register_command(cmd_ctx, NULL, "runtest", handle_runtest_command,
-               COMMAND_EXEC, "move to Run-Test/Idle, and execute <num_cycles>");
-       register_command(cmd_ctx, NULL, "irscan", handle_irscan_command,
-               COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ...");
-       register_jim(cmd_ctx, "drscan", Jim_Command_drscan, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
-       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. <state1>,<state2>,<stat3>...");
-
-       register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command,
-               COMMAND_ANY, "verify value captured during Capture-IR <enable | disable>");
-       register_command(cmd_ctx, NULL, "verify_jtag", handle_verify_jtag_command,
-               COMMAND_ANY, "verify value capture <enable | disable>");
-       register_command(cmd_ctx, NULL, "tms_sequence", handle_tms_sequence_command,
-               COMMAND_ANY, "choose short(default) or long tms_sequence <short | long>");
-       return ERROR_OK;
-}
-
 static int default_khz(int khz, int *jtag_speed)
 {
        LOG_ERROR("Translation from khz to jtag_speed not implemented");
@@ -674,6 +603,22 @@ static int default_srst_asserted(int *srst_asserted)
        return ERROR_OK;
 }
 
+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_interface_command(struct command_context_s *cmd_ctx,
                char *cmd, char **args, int argc)
 {
@@ -719,83 +664,6 @@ static int handle_interface_command(struct command_context_s *cmd_ctx,
        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)
 {
        jtag_tap_t *tap;
@@ -838,9 +706,6 @@ static int handle_reset_config_command(struct command_context_s *cmd_ctx, char *
        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 +717,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,10 +818,81 @@ 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;
 }
@@ -961,9 +905,8 @@ static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx,
        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());
@@ -978,9 +921,8 @@ static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx,
        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());
@@ -995,9 +937,8 @@ static int handle_jtag_nsrst_assert_width_command(struct command_context_s *cmd_
        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());
@@ -1012,40 +953,14 @@ static int handle_jtag_ntrst_assert_width_command(struct command_context_s *cmd_
        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)
 {
        if (argc > 1)
@@ -1055,9 +970,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;
@@ -1085,9 +999,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;
@@ -1142,9 +1055,7 @@ static int handle_runtest_command(struct command_context_s *cmd_ctx,
                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 +1065,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)
 {
@@ -1191,25 +1104,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;
                }
        }
 
@@ -1521,3 +1423,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 <ms> "
+                       "- delay after deasserting srst in ms");
+       register_command(cmd_ctx, NULL, "jtag_ntrst_delay",
+                       handle_jtag_ntrst_delay_command, COMMAND_ANY,
+                       "jtag_ntrst_delay <ms> "
+                       "- 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 <ms> "
+                       "- 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 <ms> "
+                       "- 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 <trst> <srst>");
+       register_command(cmd_ctx, NULL, "runtest",
+                       handle_runtest_command, COMMAND_EXEC,
+                       "move to Run-Test/Idle, and execute <num_cycles>");
+       register_command(cmd_ctx, NULL, "irscan",
+                       handle_irscan_command, COMMAND_EXEC,
+                       "execute IR scan <device> <instr> [dev2] [instr2] ...");
+
+       register_jim(cmd_ctx, "drscan", Jim_Command_drscan,
+                       "execute DR scan <device> "
+                       "<num_bits> <value> <num_bits1> <value2> ...");
+
+       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,
+                       "<state1>,<state2>,<state3>... "
+                       "- 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 <enable | disable>");
+       register_command(cmd_ctx, NULL, "verify_jtag",
+                       handle_verify_jtag_command, COMMAND_ANY,
+                       "verify value capture <enable | disable>");
+
+       register_command(cmd_ctx, NULL, "tms_sequence",
+                       handle_tms_sequence_command, COMMAND_ANY,
+                       "choose short(default) or long tms_sequence <short | long>");
+
+       return ERROR_OK;
+}
+
+

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)