+ if (CMD_ARGC != 0)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ int retval;
+ static int initialized = 0;
+ if (initialized)
+ return ERROR_OK;
+
+ initialized = 1;
+
+ command_context_mode(CMD_CTX, COMMAND_EXEC);
+
+ if (target_init(CMD_CTX) != ERROR_OK)
+ return ERROR_FAIL;
+ LOG_DEBUG("target init complete");
+
+ if ((retval = jtag_interface_init(CMD_CTX)) != ERROR_OK)
+ {
+ /* we must be able to set up the jtag interface */
+ return retval;
+ }
+ LOG_DEBUG("jtag interface init complete");
+
+ /* Try to initialize & examine the JTAG chain at this point, but
+ * continue startup regardless */
+ if (jtag_init(CMD_CTX) == ERROR_OK)
+ {
+ LOG_DEBUG("jtag init complete");
+ if (target_examine() == ERROR_OK)
+ {
+ LOG_DEBUG("jtag examine complete");
+ }
+ }
+
+ if (flash_init_drivers(CMD_CTX) != ERROR_OK)
+ return ERROR_FAIL;
+ LOG_DEBUG("flash init complete");
+
+ command_context_mode(CMD_CTX, COMMAND_CONFIG);
+ if (command_run_line(CMD_CTX, "mflash init") != ERROR_OK)
+ return ERROR_FAIL;
+
+ if (command_run_line(CMD_CTX, "nand init") != ERROR_OK)
+ return ERROR_FAIL;
+
+ if (command_run_line(CMD_CTX, "pld init") != ERROR_OK)
+ return ERROR_FAIL;
+ command_context_mode(CMD_CTX, COMMAND_EXEC);
+
+ /* initialize telnet subsystem */
+ gdb_target_add_all(all_targets);
+
+ target_register_event_callback(log_target_callback_event_handler, CMD_CTX);
+
+ return ERROR_OK;
+}
+
+static const struct command_registration openocd_command_handlers[] = {
+ {
+ .name = "version",
+ .handler = &handle_version_command,
+ .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_CONFIG,
+ .help = "Initializes configured targets and servers. "
+ "Changes command mode from CONFIG to EXEC. "
+ "Unless 'noinit' is called, this command is "
+ "called automatically at the end of startup.",
+
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+struct command_context *global_cmd_ctx;