move "reset_config" out of JTAG command group
[openocd.git] / src / jtag / tcl.c
index 00b1038e250d5a54ffb550fca9a85094a73d3489..90081cdcc6e82c8e38124367b887b6547cb175c0 100644 (file)
@@ -175,7 +175,6 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
                Jim_GetLong(interp, args[i], &bits);
                str = Jim_GetString(args[i + 1], &len);
 
-               fields[field_count].tap = tap;
                fields[field_count].num_bits = bits;
                fields[field_count].out_value = malloc(DIV_ROUND_UP(bits, 8));
                str_to_buf(str, len, fields[field_count].out_value, bits, 0);
@@ -183,7 +182,7 @@ static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args
                field_count++;
        }
 
-       jtag_add_dr_scan(num_fields, fields, endstate);
+       jtag_add_dr_scan(tap, num_fields, fields, endstate);
 
        retval = jtag_execute_queue();
        if (retval != ERROR_OK)
@@ -269,26 +268,39 @@ static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const
        return JIM_OK;
 }
 
+/* REVISIT Just what about these should "move" ... ?
+ * These registrations, into the main JTAG table?
+ *
+ * There's a minor compatibility issue, these all show up twice;
+ * that's not desirable:
+ *  - jtag drscan ... NOT DOCUMENTED!
+ *  - drscan ...
+ *
+ * The "irscan" command (for example) doesn't show twice.
+ */
 static const struct command_registration jtag_command_handlers_to_move[] = {
        {
                .name = "drscan",
                .mode = COMMAND_EXEC,
-               .jim_handler = &Jim_Command_drscan,
-               .help = "execute DR scan <device> "
-                       "<num_bits> <value> <num_bits1> <value2> ...",
+               .jim_handler = Jim_Command_drscan,
+               .help = "Execute Data Register (DR) scan for one TAP.  "
+                       "Other TAPs must be in BYPASS mode.",
+               .usage = "tap_name [num_bits value]* ['-endstate' state_name]",
        },
        {
                .name = "flush_count",
                .mode = COMMAND_EXEC,
-               .jim_handler = &Jim_Command_flush_count,
-               .help = "returns number of times the JTAG queue has been flushed",
+               .jim_handler = Jim_Command_flush_count,
+               .help = "Returns the number of times the JTAG queue "
+                       "has been flushed.",
        },
        {
                .name = "pathmove",
                .mode = COMMAND_EXEC,
-               .jim_handler = &Jim_Command_pathmove,
-               .usage = "<state1>,<state2>,<state3>... ",
-               .help = "move JTAG to state1 then to state2, state3, etc.",
+               .jim_handler = Jim_Command_pathmove,
+               .usage = "start_state state1 [state2 [state3 ...]]",
+               .help = "Move JTAG state machine from current state "
+                       "(start_state) to state1, then state2, state3, etc.",
        },
        COMMAND_REGISTRATION_DONE
 };
@@ -610,7 +622,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi)
        if (pTap->ir_length != 0)
        {
                jtag_tap_init(pTap);
-               return ERROR_OK;
+               return JIM_OK;
        }
 
        Jim_SetResult_sprintf(goi->interp,
@@ -658,7 +670,8 @@ static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
        }
 }
 
-static int jim_jtag_interface(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+static int
+jim_jtag_interface(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
        Jim_GetOptInfo goi;
        Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1);
@@ -845,73 +858,88 @@ static const struct command_registration jtag_subcommand_handlers[] = {
        {
                .name = "init",
                .mode = COMMAND_ANY,
-               .handler = &handle_jtag_init_command,
+               .handler = handle_jtag_init_command,
                .help = "initialize jtag scan chain",
        },
        {
                .name = "interface",
                .mode = COMMAND_ANY,
-               .jim_handler = &jim_jtag_interface,
-               .help = "Returns the selected interface",
+               .jim_handler = jim_jtag_interface,
+               .help = "Returns the name of the currently selected interface.",
        },
        {
                .name = "arp_init",
                .mode = COMMAND_ANY,
-               .jim_handler = &jim_jtag_arp_init,
+               .jim_handler = jim_jtag_arp_init,
+               .help = "Validates JTAG scan chain against the list of "
+                       "declared TAPs using just the four standard JTAG "
+                       "signals.",
        },
        {
                .name = "arp_init-reset",
                .mode = COMMAND_ANY,
-               .jim_handler = &jim_jtag_arp_init_reset,
+               .jim_handler = jim_jtag_arp_init_reset,
+               .help = "Uses TRST and SRST to try resetting everything on "
+                       "the JTAG scan chain, then performs 'jtag arp_init'."
        },
        {
                .name = "newtap",
                .mode = COMMAND_CONFIG,
-               .jim_handler = &jim_jtag_newtap,
-               .help = "Create a new TAP instance",
-               .usage = "<name> <type> -irlen <count> [-ircapture <count>] "
-                       "[-irmask <count>] [-enable|-disable]",
+               .jim_handler = jim_jtag_newtap,
+               .help = "Create a new TAP instance named basename.tap_type, "
+                       "and appends it to the scan chain.",
+               .usage = "basename tap_type '-irlen' count "
+                       "['-enable'|'-disable'] "
+                       "['-expected_id' number] "
+                       "['-ignore-version'] "
+                       "['-ircapture' number] "
+                       "['-mask' number] ",
        },
        {
                .name = "tapisenabled",
                .mode = COMMAND_EXEC,
-               .jim_handler = &jim_jtag_tap_enabler,
-               .help = "Returns a integer indicating TAP state (0/1)",
-               .usage = "<name>",
+               .jim_handler = jim_jtag_tap_enabler,
+               .help = "Returns a Tcl boolean (0/1) indicating whether "
+                       "the TAP is enabled (1) or not (0).",
+               .usage = "tap_name",
        },
        {
                .name = "tapenable",
                .mode = COMMAND_EXEC,
-               .jim_handler = &jim_jtag_tap_enabler,
-               .help = "Enable the specified TAP",
-               .usage = "<name>",
+               .jim_handler = jim_jtag_tap_enabler,
+               .help = "Try to enable the specified TAP using the "
+                       "'tap-enable' TAP event.",
+               .usage = "tap_name",
        },
        {
                .name = "tapdisable",
                .mode = COMMAND_EXEC,
-               .jim_handler = &jim_jtag_tap_enabler,
-               .help = "Enable the specified TAP",
-               .usage = "<name>",
+               .jim_handler = jim_jtag_tap_enabler,
+               .help = "Try to disable the specified TAP using the "
+                       "'tap-disable' TAP event.",
+               .usage = "tap_name",
        },
        {
                .name = "configure",
                .mode = COMMAND_EXEC,
-               .jim_handler = &jim_jtag_configure,
-               .help = "Enable the specified TAP",
-               .usage = "<name> [<key> <value> ...]",
+               .jim_handler = jim_jtag_configure,
+               .help = "Provide a Tcl handler for the specified "
+                       "TAP event.",
+               .usage = "tap_name '-event' event_name handler",
        },
        {
                .name = "cget",
                .mode = COMMAND_EXEC,
-               .jim_handler = &jim_jtag_configure,
-               .help = "Enable the specified TAP",
-               .usage = "<name> [<key> <value> ...]",
+               .jim_handler = jim_jtag_configure,
+               .help = "Return any Tcl handler for the specified "
+                       "TAP event.",
+               .usage = "tap_name '-event' event_name",
        },
        {
                .name = "names",
                .mode = COMMAND_ANY,
-               .jim_handler = &jim_jtag_names,
-               .help = "Returns list of all JTAG tap names",
+               .jim_handler = jim_jtag_names,
+               .help = "Returns list of all JTAG tap names.",
        },
        {
                .chain = jtag_command_handlers_to_move,
@@ -957,7 +985,7 @@ COMMAND_HANDLER(handle_interface_list_command)
        if (strcmp(CMD_NAME, "interface_list") == 0 && CMD_ARGC > 0)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       command_print(CMD_CTX, "The following JTAG interfaces are available:");
+       command_print(CMD_CTX, "The following debug interfaces are available:");
        for (unsigned i = 0; NULL != jtag_interfaces[i]; i++)
        {
                const char *name = jtag_interfaces[i]->name;
@@ -1010,7 +1038,7 @@ COMMAND_HANDLER(handle_interface_command)
        /* no valid interface was found (i.e. the configuration option,
         * didn't match one of the compiled-in interfaces
         */
-       LOG_ERROR("The specified JTAG interface was not found (%s)", CMD_ARGV[0]);
+       LOG_ERROR("The specified debug interface was not found (%s)", CMD_ARGV[0]);
        CALL_COMMAND_HANDLER(handle_interface_list_command);
        return ERROR_JTAG_INVALID_INTERFACE;
 }
@@ -1263,7 +1291,7 @@ next:
        return ERROR_OK;
 }
 
-COMMAND_HANDLER(handle_jtag_nsrst_delay_command)
+COMMAND_HANDLER(handle_adapter_nsrst_delay_command)
 {
        if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1274,7 +1302,7 @@ COMMAND_HANDLER(handle_jtag_nsrst_delay_command)
 
                jtag_set_nsrst_delay(delay);
        }
-       command_print(CMD_CTX, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
+       command_print(CMD_CTX, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay());
        return ERROR_OK;
 }
 
@@ -1293,7 +1321,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_delay_command)
        return ERROR_OK;
 }
 
-COMMAND_HANDLER(handle_jtag_nsrst_assert_width_command)
+COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command)
 {
        if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1304,7 +1332,7 @@ COMMAND_HANDLER(handle_jtag_nsrst_assert_width_command)
 
                jtag_set_nsrst_assert_width(delay);
        }
-       command_print(CMD_CTX, "jtag_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
+       command_print(CMD_CTX, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
        return ERROR_OK;
 }
 
@@ -1323,7 +1351,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command)
        return ERROR_OK;
 }
 
-COMMAND_HANDLER(handle_jtag_khz_command)
+COMMAND_HANDLER(handle_adapter_khz_command)
 {
        if (CMD_ARGC > 1)
                return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1402,7 +1430,7 @@ COMMAND_HANDLER(handle_jtag_reset_command)
        else
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-       if (jtag_interface_init(CMD_CTX) != ERROR_OK)
+       if (adapter_init(CMD_CTX) != ERROR_OK)
                return ERROR_JTAG_INIT_FAILED;
 
        jtag_add_reset(trst, srst);
@@ -1433,7 +1461,7 @@ COMMAND_HANDLER(handle_irscan_command)
 {
        int i;
        struct scan_field *fields;
-       struct jtag_tap *tap;
+       struct jtag_tap *tap = NULL;
        tap_state_t endstate;
 
        if ((CMD_ARGC < 2) || (CMD_ARGC % 2))
@@ -1462,6 +1490,15 @@ COMMAND_HANDLER(handle_irscan_command)
        }
 
        int num_fields = CMD_ARGC / 2;
+       if (num_fields > 1)
+       {
+               /* we really should be looking at plain_ir_scan if we want
+                * anything more fancy.
+                */
+               LOG_ERROR("Specify a single value for tap");
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
+
        size_t fields_len = sizeof(struct scan_field) * num_fields;
        fields = malloc(fields_len);
        memset(fields, 0, fields_len);
@@ -1481,7 +1518,6 @@ COMMAND_HANDLER(handle_irscan_command)
                        return ERROR_FAIL;
                }
                int field_size = tap->ir_length;
-               fields[i].tap = tap;
                fields[i].num_bits = field_size;
                fields[i].out_value = malloc(DIV_ROUND_UP(field_size, 8));
 
@@ -1494,7 +1530,7 @@ COMMAND_HANDLER(handle_irscan_command)
        }
 
        /* did we have an endstate? */
-       jtag_add_ir_scan(num_fields, fields, endstate);
+       jtag_add_ir_scan(tap, fields, endstate);
 
        retval = jtag_execute_queue();
 
@@ -1571,120 +1607,148 @@ COMMAND_HANDLER(handle_tms_sequence_command)
        return ERROR_OK;
 }
 
-static const struct command_registration jtag_command_handlers[] = {
+static const struct command_registration interface_command_handlers[] = {
        {
-               .name = "interface",
-               .handler = &handle_interface_command,
-               .mode = COMMAND_CONFIG,
-               .help = "select a JTAG interface",
-               .usage = "<driver_name>",
+               .name = "adapter_khz",
+               .handler = handle_adapter_khz_command,
+               .mode = COMMAND_ANY,
+               .help = "With an argument, change to the specified maximum "
+                       "jtag speed.  For JTAG, 0 KHz signifies adaptive "
+                       " clocking. "
+                       "With or without argument, display current setting.",
+               .usage = "[khz]",
        },
        {
-               .name = "interface_list",
-               .handler = &handle_interface_list_command,
+               .name = "adapter_nsrst_assert_width",
+               .handler = handle_adapter_nsrst_assert_width_command,
                .mode = COMMAND_ANY,
-               .help = "list all built-in interfaces",
+               .help = "delay after asserting SRST in ms",
+               .usage = "[milliseconds]",
        },
        {
-               .name = "jtag_khz",
-               .handler = &handle_jtag_khz_command,
+               .name = "adapter_nsrst_delay",
+               .handler = handle_adapter_nsrst_delay_command,
                .mode = COMMAND_ANY,
-               .help = "set maximum jtag speed (if supported)",
-               .usage = "<khz:0=rtck>",
+               .help = "delay after deasserting SRST in ms",
+               .usage = "[milliseconds]",
        },
        {
-               .name = "jtag_rclk",
-               .handler = &handle_jtag_rclk_command,
+               .name = "interface",
+               .handler = handle_interface_command,
+               .mode = COMMAND_CONFIG,
+               .help = "Select a debug adapter interface (driver)",
+               .usage = "driver_name",
+       },
+       {
+               .name = "interface_list",
+               .handler = handle_interface_list_command,
                .mode = COMMAND_ANY,
-               .help = "set JTAG speed to RCLK or use fallback speed",
-               .usage = "<fallback_speed_khz>",
+               .help = "List all built-in debug adapter interfaces (drivers)",
        },
        {
                .name = "reset_config",
-               .handler = &handle_reset_config_command,
+               .handler = handle_reset_config_command,
                .mode = COMMAND_ANY,
-               .help = "configure JTAG reset behavior",
+               .help = "configure adapter reset behavior",
                .usage = "[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]",
        },
+       COMMAND_REGISTRATION_DONE
+};
+
+/**
+ * Register the commands which deal with arbitrary debug adapter drivers.
+ *
+ * @todo Remove internal assumptions that all debug adapters use JTAG for
+ * transport.  Various types and data structures are not named generically.
+ */
+int interface_register_commands(struct command_context *ctx)
+{
+       return register_commands(ctx, NULL, interface_command_handlers);
+}
+
+static const struct command_registration jtag_command_handlers[] = {
        {
-               .name = "jtag_nsrst_delay",
-               .handler = &handle_jtag_nsrst_delay_command,
+               .name = "jtag_rclk",
+               .handler = handle_jtag_rclk_command,
                .mode = COMMAND_ANY,
-               .help = "delay after deasserting srst in ms",
-               .usage = "<ms>",
+               .help = "With an argument, change to to use adaptive clocking "
+                       "if possible; else to use the fallback speed.  "
+                       "With or without argument, display current setting.",
+               .usage = "[fallback_speed_khz]",
        },
        {
                .name = "jtag_ntrst_delay",
-               .handler = &handle_jtag_ntrst_delay_command,
+               .handler = handle_jtag_ntrst_delay_command,
                .mode = COMMAND_ANY,
                .help = "delay after deasserting trst in ms",
-               .usage = "<ms>"
-       },
-       {
-               .name = "jtag_nsrst_assert_width",
-               .handler = &handle_jtag_nsrst_assert_width_command,
-               .mode = COMMAND_ANY,
-               .help = "delay after asserting srst in ms",
-               .usage = "<ms>"
+               .usage = "[milliseconds]",
        },
        {
                .name = "jtag_ntrst_assert_width",
-               .handler = &handle_jtag_ntrst_assert_width_command,
+               .handler = handle_jtag_ntrst_assert_width_command,
                .mode = COMMAND_ANY,
                .help = "delay after asserting trst in ms",
-               .usage = "<ms>"
+               .usage = "[milliseconds]",
        },
        {
                .name = "scan_chain",
-               .handler = &handle_scan_chain_command,
-               .mode = COMMAND_EXEC,
+               .handler = handle_scan_chain_command,
+               .mode = COMMAND_ANY,
                .help = "print current scan chain configuration",
        },
        {
                .name = "jtag_reset",
-               .handler = &handle_jtag_reset_command,
+               .handler = handle_jtag_reset_command,
                .mode = COMMAND_EXEC,
-               .help = "toggle reset lines",
-               .usage = "<trst> <srst>",
+               .help = "Set reset line values.  Value '1' is active, "
+                       "value '0' is inactive.",
+               .usage = "trst_active srst_active",
        },
        {
                .name = "runtest",
-               .handler = &handle_runtest_command,
+               .handler = handle_runtest_command,
                .mode = COMMAND_EXEC,
-               .help = "move to Run-Test/Idle, and execute <num_cycles>",
-               .usage = "<num_cycles>"
+               .help = "Move to Run-Test/Idle, and issue TCK for num_cycles.",
+               .usage = "num_cycles"
        },
        {
                .name = "irscan",
-               .handler = &handle_irscan_command,
+               .handler = handle_irscan_command,
                .mode = COMMAND_EXEC,
-               .help = "execute IR scan",
-               .usage = "<device> <instr> [dev2] [instr2] ...",
+               .help = "Execute Instruction Register (DR) scan.  The "
+                       "specified opcodes are put into each TAP's IR, "
+                       "and other TAPs are put in BYPASS.",
+               .usage = "[tap_name instruction]* ['-endstate' state_name]",
        },
        {
                .name = "verify_ircapture",
-               .handler = &handle_verify_ircapture_command,
+               .handler = handle_verify_ircapture_command,
                .mode = COMMAND_ANY,
-               .help = "verify value captured during Capture-IR",
-               .usage = "<enable | disable>",
+               .help = "Display or assign flag controlling whether to "
+                       "verify values captured during Capture-IR.",
+               .usage = "['enable'|'disable']",
        },
        {
                .name = "verify_jtag",
-               .handler = &handle_verify_jtag_command,
+               .handler = handle_verify_jtag_command,
                .mode = COMMAND_ANY,
-               .help = "verify value capture",
-               .usage = "<enable | disable>",
+               .help = "Display or assign flag controlling whether to "
+                       "verify values captured during IR and DR scans.",
+               .usage = "['enable'|'disable']",
        },
        {
                .name = "tms_sequence",
-               .handler = &handle_tms_sequence_command,
+               .handler = handle_tms_sequence_command,
                .mode = COMMAND_ANY,
-               .help = "choose short(default) or long tms_sequence",
-               .usage = "<short | long>",
+               .help = "Display or change what style TMS sequences to use "
+                       "for JTAG state transitions:  short (default) or "
+                       "long.  Only for working around JTAG bugs.",
+                       /* Specifically for working around DRIVER bugs... */
+               .usage = "['short'|'long']",
        },
        {
                .name = "jtag",
@@ -1698,6 +1762,7 @@ static const struct command_registration jtag_command_handlers[] = {
        },
        COMMAND_REGISTRATION_DONE
 };
+
 int jtag_register_commands(struct command_context *cmd_ctx)
 {
        return register_commands(cmd_ctx, NULL, jtag_command_handlers);

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)