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>
56 /* Give TELNET a way to find out what version this is */
57 int handle_version_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
59 command_print(cmd_ctx
, OPENOCD_VERSION
);
64 static int daemon_startup
= 0;
66 int handle_daemon_startup_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
71 return ERROR_COMMAND_SYNTAX_ERROR
;
73 daemon_startup
= strcmp("reset", args
[0])==0;
75 command_print(cmd_ctx
, OPENOCD_VERSION
);
81 void exit_handler(void)
83 /* close JTAG interface */
84 if (jtag
&& jtag
->quit
)
89 /* OpenOCD can't really handle failure of this command. Patches welcome! :-) */
90 int handle_init_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
93 static int initialized
=0;
99 command_set_output_handler(cmd_ctx
, configuration_output_handler
, NULL
);
101 atexit(exit_handler
);
104 if (target_init(cmd_ctx
) != ERROR_OK
)
106 LOG_DEBUG("target init complete");
108 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
110 /* we must be able to set up the jtag interface */
113 LOG_DEBUG("jtag interface init complete");
115 /* Try to initialize & examine the JTAG chain at this point, but
116 * continue startup regardless
118 if (jtag_init(cmd_ctx
) == ERROR_OK
)
120 LOG_DEBUG("jtag init complete");
121 if (target_examine(cmd_ctx
) == ERROR_OK
)
123 LOG_DEBUG("jtag examine complete");
128 if (flash_init_drivers(cmd_ctx
) != ERROR_OK
)
130 LOG_DEBUG("flash init complete");
132 if (nand_init(cmd_ctx
) != ERROR_OK
)
134 LOG_DEBUG("NAND init complete");
136 if (pld_init(cmd_ctx
) != ERROR_OK
)
138 LOG_DEBUG("pld init complete");
140 /* initialize tcp server */
143 /* initialize telnet subsystem */
144 telnet_init("Open On-Chip Debugger");
151 /* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling
152 * OpenOCD fn's. No-op in vanilla OpenOCD
166 command_context_t
*active_cmd_ctx
;
168 static void tcl_output(void *privData
, const char *file
, int line
,
169 const char *function
, const char *string
)
171 Jim_Obj
*tclOutput
=(Jim_Obj
*)privData
;
173 Jim_AppendString(interp
, tclOutput
, string
, strlen(string
));
176 /* try to execute as Jim command, otherwise fall back to standard command.
178 Note that even if the Jim command caused an error, then we succeeded
179 to execute it, hence this fn pretty much always returns ERROR_OK.
182 int jim_command(command_context_t
*context
, char *line
)
185 active_cmd_ctx
=context
;
186 int retcode
=Jim_Eval(interp
, line
);
191 result
= Jim_GetString(Jim_GetResult(interp
), &reslen
);
192 if (retcode
== JIM_ERR
) {
195 LOG_USER_N("Runtime error, file \"%s\", line %d:" JIM_NL
,
196 interp
->errorFileName
, interp
->errorLine
);
197 LOG_USER_N(" %s" JIM_NL
,
198 Jim_GetString(interp
->result
, NULL
));
199 Jim_ListLength(interp
, interp
->stackTrace
, &len
);
200 for (i
= 0; i
< len
; i
+= 3) {
202 const char *proc
, *file
, *line
;
204 Jim_ListIndex(interp
, interp
->stackTrace
, i
, &objPtr
, JIM_NONE
);
205 proc
= Jim_GetString(objPtr
, NULL
);
206 Jim_ListIndex(interp
, interp
->stackTrace
, i
+1, &objPtr
,
208 file
= Jim_GetString(objPtr
, NULL
);
209 Jim_ListIndex(interp
, interp
->stackTrace
, i
+2, &objPtr
,
211 line
= Jim_GetString(objPtr
, NULL
);
212 LOG_USER_N("In procedure '%s' called at file \"%s\", line %s" JIM_NL
,
215 } else if (retcode
== JIM_EXIT
) {
217 //exit(Jim_GetExitCode(interp));
222 for (i
=0; i
<reslen
; i
+=256)
228 strncpy(buff
, result
, chunk
);
230 LOG_USER_N("%s", buff
);
232 LOG_USER_N("%s", "\n");
238 static int startLoop
=0;
241 Jim_Command_openocd_ignore(Jim_Interp
*interp
,
243 Jim_Obj
*const *argv
,
247 char *cmd
= (char*)Jim_GetString(argv
[1], NULL
);
251 Jim_Obj
*tclOutput
= Jim_NewStringObj(interp
, "", 0);
255 // We don't know whether or not the telnet/gdb server is running...
256 target_call_timer_callbacks_now();
259 log_add_callback(tcl_output
, tclOutput
);
260 retval
=command_run_line_internal(active_cmd_ctx
, cmd
);
264 target_call_timer_callbacks_now();
266 log_remove_callback(tcl_output
, tclOutput
);
268 Jim_SetResult(interp
, tclOutput
);
271 return (ignore
||(retval
==ERROR_OK
))?JIM_OK
:JIM_ERR
;
275 Jim_Command_openocd(Jim_Interp
*interp
,
277 Jim_Obj
*const *argv
)
279 return Jim_Command_openocd_ignore(interp
, argc
, argv
, 1);
283 Jim_Command_openocd_throw(Jim_Interp
*interp
,
285 Jim_Obj
*const *argv
)
287 return Jim_Command_openocd_ignore(interp
, argc
, argv
, 0);
293 /* find full path to file */
295 Jim_Command_find(Jim_Interp
*interp
,
297 Jim_Obj
*const *argv
)
301 char *file
= (char*)Jim_GetString(argv
[1], NULL
);
302 char *full_path
=find_file(file
);
305 Jim_Obj
*result
= Jim_NewStringObj(interp
, full_path
, strlen(full_path
));
308 Jim_SetResult(interp
, result
);
317 /* Create an interpreter */
318 interp
= Jim_CreateInterp();
319 /* Add all the Jim core commands */
320 Jim_RegisterCoreCommands(interp
);
321 Jim_CreateCommand(interp
, "openocd", Jim_Command_openocd
, NULL
, NULL
);
322 Jim_CreateCommand(interp
, "openocd_throw", Jim_Command_openocd_throw
, NULL
, NULL
);
323 Jim_CreateCommand(interp
, "find", Jim_Command_find
, NULL
, NULL
);
326 int main(int argc
, char *argv
[])
330 /* initialize commandline interface */
331 command_context_t
*cmd_ctx
, *cfg_cmd_ctx
;
332 cmd_ctx
= command_init();
334 register_command(cmd_ctx
, NULL
, "version", handle_version_command
,
335 COMMAND_EXEC
, "show OpenOCD version");
336 register_command(cmd_ctx
, NULL
, "daemon_startup", handle_daemon_startup_command
, COMMAND_CONFIG
,
337 "deprecated - use \"init\" and \"reset\" at end of startup script instead");
339 /* register subsystem commands */
340 server_register_commands(cmd_ctx
);
341 telnet_register_commands(cmd_ctx
);
342 gdb_register_commands(cmd_ctx
);
343 log_register_commands(cmd_ctx
);
344 jtag_register_commands(cmd_ctx
);
345 interpreter_register_commands(cmd_ctx
);
346 xsvf_register_commands(cmd_ctx
);
347 target_register_commands(cmd_ctx
);
348 flash_register_commands(cmd_ctx
);
349 nand_register_commands(cmd_ctx
);
350 pld_register_commands(cmd_ctx
);
352 if (log_init(cmd_ctx
) != ERROR_OK
)
354 LOG_DEBUG("log init complete");
356 LOG_OUTPUT( OPENOCD_VERSION
"\n" );
359 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
360 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
361 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
362 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
363 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
364 LOG_OUTPUT( "$URL$\n");
365 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
366 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
367 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
368 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
369 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
371 register_command(cmd_ctx
, NULL
, "init", handle_init_command
,
372 COMMAND_ANY
, "initializes target and servers - nop on subsequent invocations");
374 cfg_cmd_ctx
= copy_command_context(cmd_ctx
);
375 cfg_cmd_ctx
->mode
= COMMAND_CONFIG
;
376 command_set_output_handler(cfg_cmd_ctx
, configuration_output_handler
, NULL
);
378 if (parse_cmdline_args(cfg_cmd_ctx
, argc
, argv
) != ERROR_OK
)
381 Jim_Eval(interp
, "source [find tcl/commands.tcl]");
383 if (parse_config_file(cfg_cmd_ctx
) != ERROR_OK
)
386 command_done(cfg_cmd_ctx
);
388 if (command_run_line(cmd_ctx
, "init")!=ERROR_OK
)
392 command_run_line(cmd_ctx
, "reset");
397 /* handle network connections */
398 server_loop(cmd_ctx
);
400 /* shut server down */
403 unregister_all_commands(cmd_ctx
);
405 /* free commandline interface */
406 command_done(cmd_ctx
);
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)