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 void exit_handler(void)
62 /* close JTAG interface */
63 if (jtag && jtag->quit)
67 /* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling
68 * OpenOCD fn's. No-op in vanilla OpenOCD
78 int main(int argc, char *argv[])
80 /* initialize commandline interface */
81 command_context_t *cmd_ctx, *cfg_cmd_ctx;
82 cmd_ctx = command_init();
84 register_command(cmd_ctx, NULL, "version", handle_version_command,
85 COMMAND_EXEC, "show OpenOCD version");
87 /* register subsystem commands */
88 server_register_commands(cmd_ctx);
89 telnet_register_commands(cmd_ctx);
90 gdb_register_commands(cmd_ctx);
91 log_register_commands(cmd_ctx);
92 jtag_register_commands(cmd_ctx);
93 interpreter_register_commands(cmd_ctx);
94 xsvf_register_commands(cmd_ctx);
95 target_register_commands(cmd_ctx);
96 flash_register_commands(cmd_ctx);
97 nand_register_commands(cmd_ctx);
98 pld_register_commands(cmd_ctx);
100 if (log_init(cmd_ctx) != ERROR_OK)
102 LOG_DEBUG("log init complete");
104 LOG_OUTPUT( OPENOCD_VERSION "\n" );
105 LOG_OUTPUT( "$URL$\n");
107 cfg_cmd_ctx = copy_command_context(cmd_ctx);
108 cfg_cmd_ctx->mode = COMMAND_CONFIG;
109 command_set_output_handler(cfg_cmd_ctx, configuration_output_handler, NULL);
111 if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
114 if (parse_config_file(cfg_cmd_ctx) != ERROR_OK)
117 command_done(cfg_cmd_ctx);
119 command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
121 atexit(exit_handler);
123 if (jtag_init(cmd_ctx) != ERROR_OK)
125 LOG_DEBUG("jtag init complete");
127 if (target_init(cmd_ctx) != ERROR_OK)
129 LOG_DEBUG("target init complete");
131 if (flash_init_drivers(cmd_ctx) != ERROR_OK)
133 LOG_DEBUG("flash init complete");
135 if (nand_init(cmd_ctx) != ERROR_OK)
137 LOG_DEBUG("NAND init complete");
139 if (pld_init(cmd_ctx) != ERROR_OK)
141 LOG_DEBUG("pld init complete");
143 /* initialize tcp server */
146 /* initialize telnet subsystem */
147 telnet_init("Open On-Chip Debugger");
150 /* call any target resets */
151 if (target_init_reset(cmd_ctx) != ERROR_OK)
153 LOG_DEBUG("target init reset complete");
155 /* handle network connections */
156 server_loop(cmd_ctx);
158 /* shut server down */
161 /* free commandline interface */
162 command_done(cmd_ctx);