1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007-2010 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
8 * Copyright (C) 2008 Richard Missenden *
9 * richard.missenden@googlemail.com *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
21 * You should have received a copy of the GNU General Public License *
22 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
23 ***************************************************************************/
30 #include <jtag/driver.h>
31 #include <jtag/jtag.h>
32 #include <transport/transport.h>
33 #include <helper/ioutil.h>
34 #include <helper/util.h>
35 #include <helper/configuration.h>
36 #include <flash/nor/core.h>
37 #include <flash/nand/core.h>
39 #include <target/arm_cti.h>
40 #include <target/arm_adi_v5.h>
42 #include <server/server.h>
43 #include <server/gdb_server.h>
50 #define OPENOCD_VERSION \
51 "Open On-Chip Debugger " VERSION RELSTR " (" PKGBLDDATE ")"
53 #define OPENOCD_VERSION \
54 "Open On-Chip Debugger " VERSION RELSTR
57 static const char openocd_startup_tcl
[] = {
58 #include "startup_tcl.inc"
59 0 /* Terminate with zero */
62 /* Give scripts and TELNET a way to find out what version this is */
63 static int jim_version_command(Jim_Interp
*interp
, int argc
,
64 Jim_Obj
* const *argv
)
70 version_str
= OPENOCD_VERSION
;
73 str
= Jim_GetString(argv
[1], NULL
);
75 if (strcmp("git", str
) == 0)
76 version_str
= GITVERSION
;
78 Jim_SetResult(interp
, Jim_NewStringObj(interp
, version_str
, -1));
83 static int log_target_callback_event_handler(struct target
*target
,
84 enum target_event event
,
88 case TARGET_EVENT_GDB_START
:
89 target
->verbose_halt_msg
= false;
91 case TARGET_EVENT_GDB_END
:
92 target
->verbose_halt_msg
= true;
94 case TARGET_EVENT_HALTED
:
95 if (target
->verbose_halt_msg
) {
96 /* do not display information when debugger caused the halt */
97 target_arch_state(target
);
107 static bool init_at_startup
= true;
109 COMMAND_HANDLER(handle_noinit_command
)
112 return ERROR_COMMAND_SYNTAX_ERROR
;
113 init_at_startup
= false;
117 /* OpenOCD can't really handle failure of this command. Patches welcome! :-) */
118 COMMAND_HANDLER(handle_init_command
)
122 return ERROR_COMMAND_SYNTAX_ERROR
;
125 static int initialized
;
131 retval
= command_run_line(CMD_CTX
, "target init");
132 if (ERROR_OK
!= retval
)
135 retval
= adapter_init(CMD_CTX
);
136 if (retval
!= ERROR_OK
) {
137 /* we must be able to set up the debug adapter */
141 LOG_DEBUG("Debug Adapter init complete");
143 /* "transport init" verifies the expected devices are present;
144 * for JTAG, it checks the list of configured TAPs against
145 * what's discoverable, possibly with help from the platform's
146 * JTAG event handlers. (which require COMMAND_EXEC)
148 command_context_mode(CMD_CTX
, COMMAND_EXEC
);
150 retval
= command_run_line(CMD_CTX
, "transport init");
151 if (ERROR_OK
!= retval
)
154 retval
= command_run_line(CMD_CTX
, "dap init");
155 if (ERROR_OK
!= retval
)
158 LOG_DEBUG("Examining targets...");
159 if (target_examine() != ERROR_OK
)
160 LOG_DEBUG("target examination failed");
162 command_context_mode(CMD_CTX
, COMMAND_CONFIG
);
164 if (command_run_line(CMD_CTX
, "flash init") != ERROR_OK
)
167 if (command_run_line(CMD_CTX
, "nand init") != ERROR_OK
)
170 if (command_run_line(CMD_CTX
, "pld init") != ERROR_OK
)
172 command_context_mode(CMD_CTX
, COMMAND_EXEC
);
174 /* initialize telnet subsystem */
175 gdb_target_add_all(all_targets
);
177 target_register_event_callback(log_target_callback_event_handler
, CMD_CTX
);
182 COMMAND_HANDLER(handle_add_script_search_dir_command
)
185 return ERROR_COMMAND_SYNTAX_ERROR
;
187 add_script_search_dir(CMD_ARGV
[0]);
192 static const struct command_registration openocd_command_handlers
[] = {
195 .jim_handler
= jim_version_command
,
197 .help
= "show program version",
201 .handler
= &handle_noinit_command
,
202 .mode
= COMMAND_CONFIG
,
203 .help
= "Prevent 'init' from being called at startup.",
208 .handler
= &handle_init_command
,
210 .help
= "Initializes configured targets and servers. "
211 "Changes command mode from CONFIG to EXEC. "
212 "Unless 'noinit' is called, this command is "
213 "called automatically at the end of startup.",
217 .name
= "add_script_search_dir",
218 .handler
= &handle_add_script_search_dir_command
,
220 .help
= "dir to search for config files and scripts",
221 .usage
= "<directory>"
223 COMMAND_REGISTRATION_DONE
226 static int openocd_register_commands(struct command_context
*cmd_ctx
)
228 return register_commands(cmd_ctx
, NULL
, openocd_command_handlers
);
231 struct command_context
*global_cmd_ctx
;
233 static struct command_context
*setup_command_handler(Jim_Interp
*interp
)
236 LOG_DEBUG("log_init: complete");
238 struct command_context
*cmd_ctx
= command_init(openocd_startup_tcl
, interp
);
240 /* register subsystem commands */
241 typedef int (*command_registrant_t
)(struct command_context
*cmd_ctx_value
);
242 static const command_registrant_t command_registrants
[] = {
243 &openocd_register_commands
,
244 &server_register_commands
,
245 &gdb_register_commands
,
246 &log_register_commands
,
247 &transport_register_commands
,
248 &interface_register_commands
,
249 &target_register_commands
,
250 &flash_register_commands
,
251 &nand_register_commands
,
252 &pld_register_commands
,
253 &cti_register_commands
,
254 &dap_register_commands
,
257 for (unsigned i
= 0; NULL
!= command_registrants
[i
]; i
++) {
258 int retval
= (*command_registrants
[i
])(cmd_ctx
);
259 if (ERROR_OK
!= retval
) {
260 command_done(cmd_ctx
);
264 LOG_DEBUG("command registration: complete");
266 LOG_OUTPUT(OPENOCD_VERSION
"\n"
267 "Licensed under GNU GPL v2\n");
269 global_cmd_ctx
= cmd_ctx
;
274 /** OpenOCD runtime meat that can become single-thread in future. It parse
275 * commandline, reads configuration, sets up the target and starts server loop.
276 * Commandline arguments are passed into this function from openocd_main().
278 static int openocd_thread(int argc
, char *argv
[], struct command_context
*cmd_ctx
)
282 if (parse_cmdline_args(cmd_ctx
, argc
, argv
) != ERROR_OK
)
285 if (server_preinit() != ERROR_OK
)
288 ret
= parse_config_file(cmd_ctx
);
289 if (ret
== ERROR_COMMAND_CLOSE_CONNECTION
) {
290 server_quit(); /* gdb server may be initialized by -c init */
292 } else if (ret
!= ERROR_OK
) {
293 server_quit(); /* gdb server may be initialized by -c init */
297 ret
= server_init(cmd_ctx
);
301 if (init_at_startup
) {
302 ret
= command_run_line(cmd_ctx
, "init");
303 if (ERROR_OK
!= ret
) {
309 ret
= server_loop(cmd_ctx
);
311 int last_signal
= server_quit();
312 if (last_signal
!= ERROR_OK
)
320 /* normally this is the main() function entry, but if OpenOCD is linked
321 * into application, then this fn will not be invoked, but rather that
322 * application will have it's own implementation of main(). */
323 int openocd_main(int argc
, char *argv
[])
327 /* initialize commandline interface */
328 struct command_context
*cmd_ctx
;
330 cmd_ctx
= setup_command_handler(NULL
);
332 if (util_init(cmd_ctx
) != ERROR_OK
)
335 if (ioutil_init(cmd_ctx
) != ERROR_OK
)
338 LOG_OUTPUT("For bug reports, read\n\t"
339 "http://openocd.org/doc/doxygen/bugs.html"
342 command_context_mode(cmd_ctx
, COMMAND_CONFIG
);
343 command_set_output_handler(cmd_ctx
, configuration_output_handler
, NULL
);
345 server_host_os_entry();
347 /* Start the executable meat that can evolve into thread in future. */
348 ret
= openocd_thread(argc
, argv
, cmd_ctx
);
350 flash_free_all_banks();
354 unregister_all_commands(cmd_ctx
, NULL
);
356 /* free all DAP and CTI objects */
358 arm_cti_cleanup_all();
362 server_host_os_close();
364 /* Shutdown commandline interface */
365 command_exit(cmd_ctx
);
369 if (ERROR_FAIL
== ret
)
371 else if (ERROR_OK
!= ret
)
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)