split "interface" commands from "jtag" ones
[fw/openocd] / src / jtag / tcl.c
index f48993f69d6c8bf489d2f29959bb9ce54d7eed42..3ffa930d0bde08593adfdb14964a7e25b9052e6e 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)
@@ -986,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;
@@ -1039,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;
 }
@@ -1462,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))
@@ -1491,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);
@@ -1510,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));
 
@@ -1523,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();
 
@@ -1600,20 +1607,35 @@ 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",
+               .help = "Select a debug adapter interface (driver)",
                .usage = "driver_name",
        },
        {
                .name = "interface_list",
                .handler = handle_interface_list_command,
                .mode = COMMAND_ANY,
-               .help = "List all built-in interfaces",
+               .help = "List all built-in debug adapter interfaces (drivers)",
        },
+       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_khz",
                .handler = handle_jtag_khz_command,
@@ -1674,7 +1696,7 @@ static const struct command_registration jtag_command_handlers[] = {
        {
                .name = "scan_chain",
                .handler = handle_scan_chain_command,
-               .mode = COMMAND_EXEC,
+               .mode = COMMAND_ANY,
                .help = "print current scan chain configuration",
        },
        {
@@ -1739,6 +1761,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);