- bumped version information
[fw/openocd] / src / openocd.c
1 /***************************************************************************
2  *   Copyright (C) 2005 by Dominic Rath                                    *
3  *   Dominic.Rath@gmx.de                                                   *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #define OPENOCD_VERSION "Open On-Chip Debugger (2007-08-10 22:30 CEST)"
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "log.h"
28 #include "types.h"
29 #include "jtag.h"
30 #include "configuration.h"
31 #include "interpreter.h"
32 #include "xsvf.h"
33 #include "target.h"
34 #include "flash.h"
35 #include "nand.h"
36 #include "pld.h"
37
38 #include "command.h"
39 #include "server.h"
40 #include "telnet_server.h"
41 #include "gdb_server.h"
42
43 #include <sys/time.h>
44 #include <sys/types.h>
45 #include <strings.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 #include <unistd.h>
50 #include <errno.h>
51
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)
54 {
55         command_print(cmd_ctx, OPENOCD_VERSION);
56
57         return ERROR_OK;
58 }
59
60 void exit_handler(void)
61 {
62         /* close JTAG interface */
63         if (jtag && jtag->quit) jtag->quit();
64 }
65
66 int main(int argc, char *argv[])
67 {
68         /* initialize commandline interface */
69         command_context_t *cmd_ctx, *cfg_cmd_ctx;
70         cmd_ctx = command_init();
71
72         register_command(cmd_ctx, NULL, "version", handle_version_command,
73                                          COMMAND_EXEC, "show OpenOCD version");
74         
75         /* register subsystem commands */
76         server_register_commands(cmd_ctx);
77         telnet_register_commands(cmd_ctx);
78         gdb_register_commands(cmd_ctx);
79         log_register_commands(cmd_ctx);
80         jtag_register_commands(cmd_ctx);
81         interpreter_register_commands(cmd_ctx);
82         xsvf_register_commands(cmd_ctx);
83         target_register_commands(cmd_ctx);
84         flash_register_commands(cmd_ctx);
85         nand_register_commands(cmd_ctx);
86         pld_register_commands(cmd_ctx);
87         
88         if (log_init(cmd_ctx) != ERROR_OK)
89                 return EXIT_FAILURE;
90         DEBUG("log init complete");
91         
92         INFO( OPENOCD_VERSION );
93
94         cfg_cmd_ctx = copy_command_context(cmd_ctx);
95         cfg_cmd_ctx->mode = COMMAND_CONFIG;
96         command_set_output_handler(cfg_cmd_ctx, configuration_output_handler, NULL);
97         
98         if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
99                 return EXIT_FAILURE;
100
101         if (parse_config_file(cfg_cmd_ctx) != ERROR_OK)
102                 return EXIT_FAILURE;
103         
104         command_done(cfg_cmd_ctx);
105
106         command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
107
108         atexit(exit_handler);
109
110         if (jtag_init(cmd_ctx) != ERROR_OK)
111                 return EXIT_FAILURE;
112         DEBUG("jtag init complete");
113
114         if (target_init(cmd_ctx) != ERROR_OK)
115                 return EXIT_FAILURE;
116         DEBUG("target init complete");
117
118         if (flash_init(cmd_ctx) != ERROR_OK)
119                 return EXIT_FAILURE;
120         DEBUG("flash init complete");
121
122         if (nand_init(cmd_ctx) != ERROR_OK)
123                 return EXIT_FAILURE;
124         DEBUG("NAND init complete");
125
126         if (pld_init(cmd_ctx) != ERROR_OK)
127                 return EXIT_FAILURE;
128         DEBUG("pld init complete");
129
130         /* initialize tcp server */
131         server_init();
132         
133         /* initialize telnet subsystem */
134         telnet_init("Open On-Chip Debugger");
135         gdb_init();
136
137         /* handle network connections */
138         server_loop(cmd_ctx);
139         
140         /* shut server down */
141         server_quit();
142         
143         /* free commandline interface */
144         command_done(cmd_ctx);
145         
146         return EXIT_SUCCESS;
147 }