Edgar Grimberg plugged a leak found w/Valgrind.
[openocd.git] / 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 " VERSION " (" PKGBLDDATE ") svn:" PKGBLDREV
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 static int daemon_startup = 0;
61
62 int handle_daemon_startup_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
63 {
64 if (argc==0)
65 return ERROR_OK;
66 if (argc > 1 )
67 return ERROR_COMMAND_SYNTAX_ERROR;
68
69 daemon_startup = strcmp("reset", args[0])==0;
70
71 command_print(cmd_ctx, OPENOCD_VERSION);
72
73 return ERROR_OK;
74 }
75
76
77 void exit_handler(void)
78 {
79 /* close JTAG interface */
80 if (jtag && jtag->quit)
81 jtag->quit();
82 }
83
84
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)
87 {
88 int retval;
89 static int initialized=0;
90 if (initialized)
91 return ERROR_OK;
92
93 initialized=1;
94
95 command_set_output_handler(cmd_ctx, configuration_output_handler, NULL);
96
97 atexit(exit_handler);
98
99
100 if (target_init(cmd_ctx) != ERROR_OK)
101 return ERROR_FAIL;
102 LOG_DEBUG("target init complete");
103
104 if ((retval=jtag_interface_init(cmd_ctx)) != ERROR_OK)
105 {
106 /* we must be able to set up the jtag interface */
107 return retval;
108 }
109 LOG_DEBUG("jtag interface init complete");
110
111 /* Try to initialize & examine the JTAG chain at this point, but
112 * continue startup regardless
113 */
114 if (jtag_init(cmd_ctx) == ERROR_OK)
115 {
116 LOG_DEBUG("jtag init complete");
117 if (target_examine(cmd_ctx) == ERROR_OK)
118 {
119 LOG_DEBUG("jtag examine complete");
120 }
121 }
122
123
124 if (flash_init_drivers(cmd_ctx) != ERROR_OK)
125 return ERROR_FAIL;
126 LOG_DEBUG("flash init complete");
127
128 if (nand_init(cmd_ctx) != ERROR_OK)
129 return ERROR_FAIL;
130 LOG_DEBUG("NAND init complete");
131
132 if (pld_init(cmd_ctx) != ERROR_OK)
133 return ERROR_FAIL;
134 LOG_DEBUG("pld init complete");
135
136 /* initialize tcp server */
137 server_init();
138
139 /* initialize telnet subsystem */
140 telnet_init("Open On-Chip Debugger");
141 gdb_init();
142
143 return ERROR_OK;
144 }
145
146
147 /* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling
148 * OpenOCD fn's. No-op in vanilla OpenOCD
149 */
150 void lockBigLock()
151 {
152 }
153 void unlockBigLock()
154 {
155 }
156
157
158 int main(int argc, char *argv[])
159 {
160 /* initialize commandline interface */
161 command_context_t *cmd_ctx, *cfg_cmd_ctx;
162 cmd_ctx = command_init();
163
164 register_command(cmd_ctx, NULL, "version", handle_version_command,
165 COMMAND_EXEC, "show OpenOCD version");
166 register_command(cmd_ctx, NULL, "daemon_startup", handle_daemon_startup_command, COMMAND_CONFIG,
167 "deprecated - use \"init\" and \"reset\" at end of startup script instead");
168
169 /* register subsystem commands */
170 server_register_commands(cmd_ctx);
171 telnet_register_commands(cmd_ctx);
172 gdb_register_commands(cmd_ctx);
173 log_register_commands(cmd_ctx);
174 jtag_register_commands(cmd_ctx);
175 interpreter_register_commands(cmd_ctx);
176 xsvf_register_commands(cmd_ctx);
177 target_register_commands(cmd_ctx);
178 flash_register_commands(cmd_ctx);
179 nand_register_commands(cmd_ctx);
180 pld_register_commands(cmd_ctx);
181
182 if (log_init(cmd_ctx) != ERROR_OK)
183 return EXIT_FAILURE;
184 LOG_DEBUG("log init complete");
185
186 LOG_OUTPUT( OPENOCD_VERSION "\n" );
187
188
189 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
190 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
191 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
192 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
193 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
194 LOG_OUTPUT( "$URL$\n");
195 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
196 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
197 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
198 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
199 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
200
201 register_command(cmd_ctx, NULL, "init", handle_init_command,
202 COMMAND_ANY, "initializes target and servers - nop on subsequent invocations");
203
204 cfg_cmd_ctx = copy_command_context(cmd_ctx);
205 cfg_cmd_ctx->mode = COMMAND_CONFIG;
206 command_set_output_handler(cfg_cmd_ctx, configuration_output_handler, NULL);
207
208 if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
209 return EXIT_FAILURE;
210
211 if (parse_config_file(cfg_cmd_ctx) != ERROR_OK)
212 return EXIT_FAILURE;
213
214 command_done(cfg_cmd_ctx);
215
216 if (command_run_line(cmd_ctx, "init")!=ERROR_OK)
217 return EXIT_FAILURE;
218
219 if (daemon_startup)
220 command_run_line(cmd_ctx, "reset");
221
222 /* handle network connections */
223 server_loop(cmd_ctx);
224
225 /* shut server down */
226 server_quit();
227
228 unregister_all_commands(cmd_ctx);
229
230 /* free commandline interface */
231 command_done(cmd_ctx);
232
233 return EXIT_SUCCESS;
234 }
235

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)