1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #define OPENOCD_VERSION "Open On-Chip Debugger " VERSION " (" PKGBLDDATE ") svn:" PKGBLDREV
30 #include "configuration.h"
31 #include "interpreter.h"
40 #include "telnet_server.h"
41 #include "gdb_server.h"
44 #include <sys/types.h>
52 /* Give TELNET a way to find out what version this is */
53 int handle_version_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
55 command_print(cmd_ctx, OPENOCD_VERSION);
60 static int daemon_startup = 0;
62 int handle_daemon_startup_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
67 return ERROR_COMMAND_SYNTAX_ERROR;
69 daemon_startup = strcmp("reset", args[0])==0;
71 command_print(cmd_ctx, OPENOCD_VERSION);
77 void exit_handler(void)
79 /* close JTAG interface */
80 if (jtag && jtag->quit)
85 /* OpenOCD can't really handle failure of this command. Patches welcome! :-) */
86 int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
88 static int initialized=0;
94 command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
98 /* FIX!!! this should happen *after* target_init(), but
99 * for now there are target initialisations that talk
100 * to JTAG whereas that *should* happen during target_examine()
102 if (jtag_init(cmd_ctx) != ERROR_OK)
104 LOG_DEBUG("jtag init complete");
106 if (target_init(cmd_ctx) != ERROR_OK)
108 LOG_DEBUG("target init complete");
110 if (target_examine(cmd_ctx) != ERROR_OK)
112 LOG_DEBUG("target examine complete");
114 if (flash_init_drivers(cmd_ctx) != ERROR_OK)
116 LOG_DEBUG("flash init complete");
118 if (nand_init(cmd_ctx) != ERROR_OK)
120 LOG_DEBUG("NAND init complete");
122 if (pld_init(cmd_ctx) != ERROR_OK)
124 LOG_DEBUG("pld init complete");
126 /* initialize tcp server */
129 /* initialize telnet subsystem */
130 telnet_init("Open On-Chip Debugger");
137 /* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling
138 * OpenOCD fn's. No-op in vanilla OpenOCD
148 int main(int argc, char *argv[])
150 /* initialize commandline interface */
151 command_context_t *cmd_ctx, *cfg_cmd_ctx;
152 cmd_ctx = command_init();
154 register_command(cmd_ctx, NULL, "version", handle_version_command,
155 COMMAND_EXEC, "show OpenOCD version");
156 register_command(cmd_ctx, NULL, "daemon_startup", handle_daemon_startup_command, COMMAND_CONFIG,
157 "deprecated - use \"init\" and \"reset\" at end of startup script instead");
159 /* register subsystem commands */
160 server_register_commands(cmd_ctx);
161 telnet_register_commands(cmd_ctx);
162 gdb_register_commands(cmd_ctx);
163 log_register_commands(cmd_ctx);
164 jtag_register_commands(cmd_ctx);
165 interpreter_register_commands(cmd_ctx);
166 xsvf_register_commands(cmd_ctx);
167 target_register_commands(cmd_ctx);
168 flash_register_commands(cmd_ctx);
169 nand_register_commands(cmd_ctx);
170 pld_register_commands(cmd_ctx);
172 if (log_init(cmd_ctx) != ERROR_OK)
174 LOG_DEBUG("log init complete");
176 LOG_OUTPUT( OPENOCD_VERSION "\n" );
179 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
180 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
181 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
182 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
183 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
184 LOG_OUTPUT( "$URL$\n");
185 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
186 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
187 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
188 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
189 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
191 register_command(cmd_ctx, NULL, "init", handle_init_command,
192 COMMAND_ANY, "initializes target and servers - nop on subsequent invocations");
194 cfg_cmd_ctx = copy_command_context(cmd_ctx);
195 cfg_cmd_ctx->mode = COMMAND_CONFIG;
196 command_set_output_handler(cfg_cmd_ctx, configuration_output_handler, NULL);
198 if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
201 if (parse_config_file(cfg_cmd_ctx) != ERROR_OK)
204 command_done(cfg_cmd_ctx);
206 if (command_run_line(cmd_ctx, "init")!=ERROR_OK)
210 command_run_line(cmd_ctx, "reset");
212 /* handle network connections */
213 server_loop(cmd_ctx);
215 /* shut server down */
218 /* free commandline interface */
219 command_done(cmd_ctx);