pld: factor init to 'pld init'
[openocd.git] / src / openocd.c
index 287a819bae37cef1742416812f0df60cf60b2120..777e630664a883792781713ec7e946b4b513f5d5 100644 (file)
@@ -60,10 +60,6 @@ COMMAND_HANDLER(handle_version_command)
        return ERROR_OK;
 }
 
-static void exit_handler(void)
-{
-       jtag_interface_quit();
-}
 
 static int log_target_callback_event_handler(struct target *target, enum target_event event, void *priv)
 {
@@ -91,6 +87,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)
 {
@@ -105,8 +111,6 @@ COMMAND_HANDLER(handle_init_command)
 
        initialized = 1;
 
-       atexit(exit_handler);
-
        command_context_mode(CMD_CTX, COMMAND_EXEC);
 
        if (target_init(CMD_CTX) != ERROR_OK)
@@ -143,9 +147,10 @@ COMMAND_HANDLER(handle_init_command)
                return ERROR_FAIL;
        LOG_DEBUG("NAND init complete");
 
-       if (pld_init(CMD_CTX) != ERROR_OK)
+       command_context_mode(CMD_CTX, COMMAND_CONFIG);
+       if (command_run_line(CMD_CTX, "pld init") != ERROR_OK)
                return ERROR_FAIL;
-       LOG_DEBUG("pld init complete");
+       command_context_mode(CMD_CTX, COMMAND_EXEC);
 
        /* initialize telnet subsystem */
        gdb_target_add_all(all_targets);
@@ -159,15 +164,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
 };
@@ -175,14 +189,14 @@ static const struct command_registration openocd_command_handlers[] = {
 struct command_context *global_cmd_ctx;
 
 /* NB! this fn can be invoked outside this file for non PC hosted builds */
-struct command_context *setup_command_handler(void)
+struct command_context *setup_command_handler(Jim_Interp *interp)
 {
        log_init();
        LOG_DEBUG("log_init: complete");
 
        struct command_context *cmd_ctx;
 
-       global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl);
+       global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl, interp);
 
        register_commands(cmd_ctx, NULL, openocd_command_handlers);
        /* register subsystem commands */
@@ -229,7 +243,7 @@ int openocd_main(int argc, char *argv[])
        /* initialize commandline interface */
        struct command_context *cmd_ctx;
 
-       cmd_ctx = setup_command_handler();
+       cmd_ctx = setup_command_handler(NULL);
 
 #if BUILD_IOUTIL
        if (ioutil_init(cmd_ctx) != ERROR_OK)
@@ -258,11 +272,11 @@ int openocd_main(int argc, char *argv[])
                return EXIT_FAILURE;
 #endif
 
-       ret = server_init();
+       ret = server_init(cmd_ctx);
        if (ERROR_OK != ret)
                return EXIT_FAILURE;
 
-       if (1)
+       if (init_at_startup)
        {
                ret = command_run_line(cmd_ctx, "init");
                if (ERROR_OK != ret)
@@ -284,5 +298,7 @@ int openocd_main(int argc, char *argv[])
        /* free commandline interface */
        command_done(cmd_ctx);
 
+       jtag_interface_quit();
+
        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)