Fix a bunch of typos.
[openocd.git] / src / jtag / transport.c
index cee8ffb3934dfb8376c9c3cbd0d9adf0c2505a96..60228803342ef2ed81441f91ceeb58c3449a8630 100644 (file)
@@ -46,6 +46,9 @@
 
 #include "transport.h"
 
+extern struct command_context *global_cmd_ctx;
+
+
 /*-----------------------------------------------------------------------*/
 
 /*
@@ -79,8 +82,8 @@ static  int transport_select(struct command_context *ctx, const char *name)
                        if (retval == ERROR_OK)
                                session = t;
                        else
-                               LOG_ERROR("Error %d selecting '%s' as "
-                                       "transport", retval, t->name);
+                               LOG_ERROR("Error selecting '%s' as "
+                                       "transport", t->name);
                        return retval;
                }
        }
@@ -101,6 +104,10 @@ int allow_transports(struct command_context *ctx, const char **vector)
         *
         * REVISIT should we validate that?  and insist there's
         * at least one non-NULL element in that list?
+        *
+        * ... allow removals, e.g. external strapping prevents use
+        * of one transport; C code should be definitive about what
+        * can be used when all goes well.
         */
        if (allowed_transports != NULL || session) {
                LOG_ERROR("Can't modify the set of allowed transports.");
@@ -116,8 +123,12 @@ int allow_transports(struct command_context *ctx, const char **vector)
                                vector[0]);
                return transport_select(ctx, vector [0]);
        } else {
-               while (*vector)
-                       LOG_DEBUG("allow transport '%s'", *vector++);
+               /* guard against user config errors */
+               LOG_WARNING("must select a transport.");
+               while (*vector) {
+                       LOG_DEBUG("allow transport '%s'", *vector);
+                       vector++;
+               }
                return ERROR_OK;
        }
 }
@@ -166,7 +177,7 @@ int transport_register(struct transport *new_transport)
        /* splice this into the list */
        new_transport->next = transport_list;
        transport_list = new_transport;
-       LOG_DEBUG("register '%s'", t->name);
+       LOG_DEBUG("register '%s'", new_transport->name);
 
        return ERROR_OK;
 }
@@ -266,67 +277,53 @@ COMMAND_HANDLER(handle_transport_list)
 /**
  * Implements the Tcl "transport select" command, choosing the
  * transport to be used in this debug session from among the
- * set supported by the debug adapter being used.
+ * set supported by the debug adapter being used.  Return value
+ * is scriptable (allowing "if swd then..." etc).
  */
-COMMAND_HANDLER(handle_transport_select)
+static int jim_transport_select(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 {
-       int retval = ERROR_OK;;
-
-       switch (CMD_ARGC) {
-       case 0:                 /* "select" */
-               if (session) {
-                       goto show;
-               }
-               LOG_ERROR("session's transport is not selected.");
-               return ERROR_FAIL;
-
-       case 1:                 /* "select FOO" */
-               if(strcmp(session->name, CMD_ARGV[0]) == 0) {
-                       /* NOP */
-                       LOG_DEBUG("transport '%s' is already selected",
-                                       CMD_ARGV[0]);
-                       return ERROR_OK;
+       switch (argc) {
+       case 1:                 /* return/display */
+               if (!session) {
+                       LOG_ERROR("session's transport is not selected.");
+                       return JIM_ERR;
                } else {
-
-               /* we can't change this session's transport after-the-fact */
-               if (session) {
-                       LOG_ERROR("session's transport is already selected.");
-                       return ERROR_FAIL;
-               }
+                       Jim_SetResultString(interp, session->name, -1);
+                       return JIM_OK;
                }
                break;
-
-       default:                /* select FOO BAR */
-               /* we only select *one* transport per session */
-               LOG_ERROR("may only select one transport!");
-               return ERROR_COMMAND_SYNTAX_ERROR;
+       case 2:                 /* assign */
+       if (session) {
+               /* can't change session's transport after-the-fact */
+               LOG_ERROR("session's transport is already selected.");
+               return JIM_ERR;
        }
 
        /* Is this transport supported by our debug adapter?
         * Example, "JTAG-only" means SWD is not supported.
         *
-        * NOTE:  requires adapter to have been set up, including
-        * declaring transport via C code or Tcl script.
+        * NOTE:  requires adapter to have been set up, with
+        * transports declared via C.
         */
        if (!allowed_transports) {
                LOG_ERROR("Debug adapter doesn't support any transports?");
-               return ERROR_FAIL;
+               return JIM_ERR;
        }
+
        for (unsigned i = 0; allowed_transports[i]; i++) {
 
-               if (strcmp(allowed_transports[i], CMD_ARGV[0]) == 0)
-                       return transport_select(CMD_CTX, CMD_ARGV[0]);
+               if (strcmp(allowed_transports[i], argv[1]->bytes) == 0)
+               return transport_select(global_cmd_ctx, argv[1]->bytes);
        }
 
-       LOG_ERROR("Debug adapter doesn't support '%s' "
-                       "transport?", CMD_ARGV[0]);
-       return ERROR_FAIL;
-
-
-show:
-       /* report the current transport selection */
-       command_print(CMD_CTX, "%s", session->name);
-       return retval;
+               LOG_ERROR("Debug adapter doesn't support '%s' "
+                       "transport", argv[1]->bytes);
+               return JIM_ERR;
+               break;
+       default:
+               Jim_WrongNumArgs(interp, 1, argv, "[too many parameters]");
+               return JIM_ERR;
+       }
 }
 
 static const struct command_registration transport_commands[] = {
@@ -348,7 +345,7 @@ static const struct command_registration transport_commands[] = {
        },
        {
                .name = "select",
-               .handler = handle_transport_select,
+               .jim_handler = jim_transport_select,
                .mode = COMMAND_ANY,
                .help = "Select this session's transport",
                .usage = "[transport_name]",

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)