+#endif
+
+#ifdef PKGBLDDATE
+#define OPENOCD_VERSION \
+ "Open On-Chip Debugger " VERSION RELSTR " (" PKGBLDDATE ")"
+#else
+#define OPENOCD_VERSION \
+ "Open On-Chip Debugger " VERSION RELSTR
+#endif
+
+static const char openocd_startup_tcl[] = {
+#include "startup_tcl.inc"
+0 /* Terminate with zero */
+};
+
+/* Give scripts and TELNET a way to find out what version this is */
+static int jim_version_command(Jim_Interp *interp, int argc,
+ Jim_Obj * const *argv)
+{
+ if (argc > 2)
+ return JIM_ERR;
+ const char *str = "";
+ char *version_str;
+ version_str = OPENOCD_VERSION;
+
+ if (argc == 2)
+ str = Jim_GetString(argv[1], NULL);
+
+ if (strcmp("git", str) == 0)
+ version_str = GITVERSION;
+
+ Jim_SetResult(interp, Jim_NewStringObj(interp, version_str, -1));
+
+ return JIM_OK;
+}
+
+static int log_target_callback_event_handler(struct target *target,
+ enum target_event event,
+ void *priv)
+{
+ switch (event) {
+ case TARGET_EVENT_GDB_START:
+ target->verbose_halt_msg = false;
+ break;
+ case TARGET_EVENT_GDB_END:
+ target->verbose_halt_msg = true;
+ break;
+ case TARGET_EVENT_HALTED:
+ if (target->verbose_halt_msg) {
+ /* do not display information when debugger caused the halt */
+ target_arch_state(target);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return ERROR_OK;
+}
+
+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)
+{
+
+ if (CMD_ARGC != 0)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ int retval;
+ static int initialized;
+ if (initialized)
+ return ERROR_OK;
+
+ initialized = 1;
+
+ retval = command_run_line(CMD_CTX, "target init");
+ if (retval != ERROR_OK)
+ return ERROR_FAIL;
+
+ retval = adapter_init(CMD_CTX);
+ if (retval != ERROR_OK) {
+ /* we must be able to set up the debug adapter */
+ return retval;
+ }
+
+ LOG_DEBUG("Debug Adapter init complete");
+
+ /* "transport init" verifies the expected devices are present;
+ * for JTAG, it checks the list of configured TAPs against
+ * what's discoverable, possibly with help from the platform's
+ * JTAG event handlers. (which require COMMAND_EXEC)
+ */
+ command_context_mode(CMD_CTX, COMMAND_EXEC);
+
+ retval = command_run_line(CMD_CTX, "transport init");
+ if (retval != ERROR_OK)
+ return ERROR_FAIL;
+
+ retval = command_run_line(CMD_CTX, "dap init");
+ if (retval != ERROR_OK)
+ return ERROR_FAIL;
+
+ LOG_DEBUG("Examining targets...");
+ if (target_examine() != ERROR_OK)
+ LOG_DEBUG("target examination failed");
+
+ command_context_mode(CMD_CTX, COMMAND_CONFIG);
+
+ if (command_run_line(CMD_CTX, "flash 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);
+
+ /* in COMMAND_EXEC, after target_examine(), only tpiu or only swo */
+ if (command_run_line(CMD_CTX, "tpiu init") != ERROR_OK)
+ return ERROR_FAIL;
+
+ /* initialize telnet subsystem */
+ gdb_target_add_all(all_targets);
+
+ target_register_event_callback(log_target_callback_event_handler, CMD_CTX);
+
+ if (command_run_line(CMD_CTX, "_run_post_init_commands") != ERROR_OK)
+ return ERROR_FAIL;
+
+ return ERROR_OK;
+}
+
+COMMAND_HANDLER(handle_add_script_search_dir_command)