allow deferal of init
[openocd.git] / src / openocd.c
index 01e9e79cc8a2b8a18aadb9a9effce15fc96e8ee6..2a65b4d87a198f93306ffe77810d2ec53ae77a87 100644 (file)
@@ -38,9 +38,7 @@
 #include "mflash.h"
 
 #include "server.h"
-#include "telnet_server.h"
 #include "gdb_server.h"
-#include "tcl_server.h"
 #include "httpd.h"
 
 #ifdef HAVE_STRINGS_H
@@ -93,6 +91,16 @@ static int log_target_callback_event_handler(struct target *target, enum target_
 
 int ioutil_init(struct command_context *cmd_ctx);
 
+static bool init_at_startup = true;
+
+COMMAND_HANDLER(handle_noinit_command)
+{
+       if (CMD_ARGC != 0)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       init_at_startup = false;
+       return ERROR_OK;
+}
+
 /* OpenOCD can't really handle failure of this command. Patches welcome! :-) */
 COMMAND_HANDLER(handle_init_command)
 {
@@ -149,13 +157,8 @@ COMMAND_HANDLER(handle_init_command)
                return ERROR_FAIL;
        LOG_DEBUG("pld init complete");
 
-       /* initialize tcp server */
-       server_init();
-
        /* initialize telnet subsystem */
-       telnet_init("Open On-Chip Debugger");
-       gdb_init();
-       tcl_init(); /* allows tcl to just connect without going thru telnet */
+       gdb_target_add_all(all_targets);
 
        target_register_event_callback(log_target_callback_event_handler, CMD_CTX);
 
@@ -166,15 +169,24 @@ static const struct command_registration openocd_command_handlers[] = {
        {
                .name = "version",
                .handler = &handle_version_command,
-               .mode = COMMAND_EXEC,
+               .mode = COMMAND_ANY,
                .help = "show program version",
        },
+       {
+               .name = "noinit",
+               .handler = &handle_noinit_command,
+               .mode = COMMAND_CONFIG,
+               .help = "Prevent 'init' from being called at startup.",
+       },
        {
                .name = "init",
                .handler = &handle_init_command,
-               .mode = COMMAND_ANY,
+               .mode = COMMAND_CONFIG,
                .help = "Initializes configured targets and servers.  "
-                       "If called more than once, does nothing.",
+                       "Changes command mode from CONFIG to EXEC.  "
+                       "Unless 'noinit' is called, this command is "
+                       "called automatically at the end of startup.",
+
        },
        COMMAND_REGISTRATION_DONE
 };
@@ -194,9 +206,7 @@ struct command_context *setup_command_handler(void)
        register_commands(cmd_ctx, NULL, openocd_command_handlers);
        /* register subsystem commands */
        server_register_commands(cmd_ctx);
-       telnet_register_commands(cmd_ctx);
        gdb_register_commands(cmd_ctx);
-       tcl_register_commands(cmd_ctx); /* tcl server commands */
        log_register_commands(cmd_ctx);
        jtag_register_commands(cmd_ctx);
        xsvf_register_commands(cmd_ctx);
@@ -259,7 +269,7 @@ int openocd_main(int argc, char *argv[])
                return EXIT_FAILURE;
 
        ret = parse_config_file(cmd_ctx);
-       if ((ret != ERROR_OK) && (ret != ERROR_COMMAND_CLOSE_CONNECTION))
+       if (ret != ERROR_OK)
                return EXIT_FAILURE;
 
 #if BUILD_HTTPD
@@ -267,16 +277,21 @@ int openocd_main(int argc, char *argv[])
                return EXIT_FAILURE;
 #endif
 
-       if (ret != ERROR_COMMAND_CLOSE_CONNECTION)
+       ret = server_init();
+       if (ERROR_OK != ret)
+               return EXIT_FAILURE;
+
+       if (init_at_startup)
        {
-               if (command_run_line(cmd_ctx, "init") != ERROR_OK)
-                       return EXIT_FAILURE;
+               ret = command_run_line(cmd_ctx, "init");
+               if (ERROR_OK != ret)
+                       ret = EXIT_FAILURE;
+       }
 
-               /* handle network connections */
+       /* handle network connections */
+       if (ERROR_OK == ret)
                server_loop(cmd_ctx);
-       }
 
-       /* shut server down */
        server_quit();
 
 #if BUILD_HTTPD
@@ -288,6 +303,5 @@ int openocd_main(int argc, char *argv[])
        /* free commandline interface */
        command_done(cmd_ctx);
 
-
-       return EXIT_SUCCESS;
+       return ret;
 }

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)