+ switch (event)
+ {
+ case TARGET_EVENT_GDB_START:
+ target->display = 0;
+ break;
+ case TARGET_EVENT_GDB_END:
+ target->display = 1;
+ break;
+ case TARGET_EVENT_HALTED:
+ if (target->display)
+ {
+ /* do not display information when debugger caused the halt */
+ target_arch_state(target);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return ERROR_OK;
+}
+
+int ioutil_init(struct command_context *cmd_ctx);
+
+/* 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 = 0;
+ if (initialized)
+ return ERROR_OK;
+
+ initialized = 1;
+
+ atexit(exit_handler);
+
+ 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");
+
+ if (mflash_init_drivers(CMD_CTX) != ERROR_OK)
+ return ERROR_FAIL;
+ LOG_DEBUG("mflash init complete");
+
+ if (nand_init(CMD_CTX) != ERROR_OK)
+ return ERROR_FAIL;
+ LOG_DEBUG("NAND init complete");
+
+ if (pld_init(CMD_CTX) != ERROR_OK)
+ 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 */
+
+ target_register_event_callback(log_target_callback_event_handler, CMD_CTX);
+
+ return ERROR_OK;
+}
+
+struct command_context *global_cmd_ctx;
+
+/// src/hello.c gives a simple example for writing new command modules
+int hello_register_commands(struct command_context *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 *cmd_ctx;
+
+ global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl);