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"
42 #include "tcl_server.h"
45 #include <sys/types.h>
60 /* Jim is provied by eCos */
61 #include <cyg/jimtcl/jim.h>
67 #include "replacements.h"
69 int launchTarget(struct command_context_s
*cmd_ctx
)
72 /* Try to examine & validate jtag chain, though this may require a reset first
73 * in which case we continue setup */
76 /* try to examine target at this point. If it fails, perhaps a reset will
77 * bring it up later on via a telnet/gdb session */
78 target_examine(cmd_ctx
);
80 retval
=flash_init_drivers(cmd_ctx
);
83 LOG_DEBUG("flash init complete");
85 retval
=nand_init(cmd_ctx
);
88 LOG_DEBUG("NAND init complete");
90 retval
=pld_init(cmd_ctx
);
93 LOG_DEBUG("pld init complete");
97 /* Give TELNET a way to find out what version this is */
98 int handle_version_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
100 command_print(cmd_ctx
, OPENOCD_VERSION
);
105 static int daemon_startup
= 0;
107 int handle_daemon_startup_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
112 return ERROR_COMMAND_SYNTAX_ERROR
;
114 daemon_startup
= strcmp("reset", args
[0])==0;
116 command_print(cmd_ctx
, OPENOCD_VERSION
);
121 void exit_handler(void)
123 /* close JTAG interface */
124 if (jtag
&& jtag
->quit
)
128 /* OpenOCD can't really handle failure of this command. Patches welcome! :-) */
129 int handle_init_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
132 static int initialized
=0;
138 command_set_output_handler(cmd_ctx
, configuration_output_handler
, NULL
);
140 atexit(exit_handler
);
142 if (target_init(cmd_ctx
) != ERROR_OK
)
144 LOG_DEBUG("target init complete");
146 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
148 /* we must be able to set up the jtag interface */
151 LOG_DEBUG("jtag interface init complete");
153 /* Try to initialize & examine the JTAG chain at this point, but
154 * continue startup regardless */
155 if (jtag_init(cmd_ctx
) == ERROR_OK
)
157 LOG_DEBUG("jtag init complete");
158 if (target_examine(cmd_ctx
) == ERROR_OK
)
160 LOG_DEBUG("jtag examine complete");
164 if (flash_init_drivers(cmd_ctx
) != ERROR_OK
)
166 LOG_DEBUG("flash init complete");
168 if (nand_init(cmd_ctx
) != ERROR_OK
)
170 LOG_DEBUG("NAND init complete");
172 if (pld_init(cmd_ctx
) != ERROR_OK
)
174 LOG_DEBUG("pld init complete");
176 /* initialize tcp server */
179 /* initialize telnet subsystem */
180 telnet_init("Open On-Chip Debugger");
182 tcl_init(); /* allows tcl to just connect without going thru telnet */
188 command_context_t
*active_cmd_ctx
;
190 static int new_int_array_element(Jim_Interp
* interp
, const char *varname
, int idx
, u32 val
)
193 Jim_Obj
*nameObjPtr
, *valObjPtr
;
196 namebuf
= alloc_printf("%s(%d)", varname
, idx
);
198 nameObjPtr
= Jim_NewStringObj(interp
, namebuf
, -1);
199 valObjPtr
= Jim_NewIntObj(interp
, val
);
200 Jim_IncrRefCount(nameObjPtr
);
201 Jim_IncrRefCount(valObjPtr
);
202 result
= Jim_SetVariable(interp
, nameObjPtr
, valObjPtr
);
203 Jim_DecrRefCount(interp
, nameObjPtr
);
204 Jim_DecrRefCount(interp
, valObjPtr
);
206 /* printf( "%s = 0%08x\n", namebuf, val ); */
210 static int Jim_Command_mem2array(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
223 /* argv[1] = name of array to receive the data
224 * argv[2] = desired width
225 * argv[3] = memory address
226 * argv[4] = length in bytes to read
229 Jim_WrongNumArgs(interp
, 1, argv
, "varname width addr nelems");
232 varname
= Jim_GetString(argv
[1], &len
);
233 /* given "foo" get space for worse case "foo(%d)" .. add 20 */
235 e
= Jim_GetLong(interp
, argv
[2], &l
);
241 e
= Jim_GetLong(interp
, argv
[3], &l
);
246 e
= Jim_GetLong(interp
, argv
[4], &l
);
262 Jim_SetResult(interp
, Jim_NewEmptyStringObj(interp
));
263 Jim_AppendStrings( interp
, Jim_GetResult(interp
), "Invalid width param, must be 8/16/32", NULL
);
267 Jim_SetResult(interp
, Jim_NewEmptyStringObj(interp
));
268 Jim_AppendStrings(interp
, Jim_GetResult(interp
), "mem2array: zero width read?", NULL
);
271 if ((addr
+ (len
* width
)) < addr
) {
272 Jim_SetResult(interp
, Jim_NewEmptyStringObj(interp
));
273 Jim_AppendStrings(interp
, Jim_GetResult(interp
), "mem2array: addr + len - wraps to zero?", NULL
);
276 /* absurd transfer size? */
278 Jim_SetResult(interp
, Jim_NewEmptyStringObj(interp
));
279 Jim_AppendStrings(interp
, Jim_GetResult(interp
), "mem2array: absurd > 64K item request", NULL
);
284 ((width
== 2) && ((addr
& 1) == 0)) ||
285 ((width
== 4) && ((addr
& 3) == 0))) {
289 Jim_SetResult(interp
, Jim_NewEmptyStringObj(interp
));
290 sprintf(buf
, "mem2array address: 0x%08x is not aligned for %d byte reads", addr
, width
);
291 Jim_AppendStrings(interp
, Jim_GetResult(interp
), buf
, NULL
);
295 target
= get_current_target(active_cmd_ctx
);
304 /* Slurp... in buffer size chunks */
306 count
= len
; /* in objects.. */
307 if (count
> (sizeof(buffer
)/width
)) {
308 count
= (sizeof(buffer
)/width
);
311 retval
= target
->type
->read_memory( target
, addr
, width
, count
, buffer
);
313 if (retval
!= ERROR_OK
) {
315 LOG_ERROR("mem2array: Read @ 0x%08x, w=%d, cnt=%d, failed", addr
, width
, count
);
316 Jim_SetResult(interp
, Jim_NewEmptyStringObj(interp
));
317 Jim_AppendStrings(interp
, Jim_GetResult(interp
), "mem2array: cannot read memory", NULL
);
321 v
= 0; /* shut up gcc */
322 for (i
= 0 ;i
< count
;i
++, n
++) {
325 v
= target_buffer_get_u32(target
, &buffer
[i
*width
]);
328 v
= target_buffer_get_u16(target
, &buffer
[i
*width
]);
331 v
= buffer
[i
] & 0x0ff;
334 new_int_array_element(interp
, varname
, n
, v
);
340 Jim_SetResult(interp
, Jim_NewEmptyStringObj(interp
));
345 static void tcl_output(void *privData
, const char *file
, int line
, const char *function
, const char *string
)
347 Jim_Obj
*tclOutput
=(Jim_Obj
*)privData
;
349 Jim_AppendString(interp
, tclOutput
, string
, strlen(string
));
352 /* try to execute as Jim command, otherwise fall back to standard command.
353 * Note that even if the Jim command caused an error, then we succeeded
354 * to execute it, hence this fn pretty much always returns ERROR_OK. */
355 int jim_command(command_context_t
*context
, char *line
)
358 int retcode
=Jim_Eval(interp
, line
);
360 if (retcode
== JIM_ERR
) {
361 Jim_PrintErrorMessage(interp
);
363 Jim_Obj
*openocd_result
=Jim_GetVariableStr(interp
, "openocd_result", JIM_ERRMSG
);
366 if (Jim_GetLong(interp
, openocd_result
, &t
)==JIM_OK
)
375 result
= Jim_GetString(Jim_GetResult(interp
), &reslen
);
377 if (retcode
== JIM_EXIT
) {
379 /* exit(Jim_GetExitCode(interp)); */
384 for (i
= 0; i
< reslen
; i
+= 256)
390 strncpy(buff
, result
+i
, chunk
);
392 LOG_USER_N("%s", buff
);
394 LOG_USER_N("%s", "\n");
402 static int Jim_Command_openocd_ignore(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
, int ignore
)
405 char *cmd
= (char*)Jim_GetString(argv
[1], NULL
);
407 Jim_Obj
*tclOutput
= Jim_NewStringObj(interp
, "", 0);
411 /* We don't know whether or not the telnet/gdb server is running... */
412 target_call_timer_callbacks_now();
415 log_add_callback(tcl_output
, tclOutput
);
416 retval
=command_run_line_internal(active_cmd_ctx
, cmd
);
418 /* we need to be able to get at the retval, so we store in a variable
420 Jim_Obj
*resultvar
=Jim_NewIntObj(interp
, retval
);
421 Jim_IncrRefCount(resultvar
);
422 Jim_SetGlobalVariableStr(interp
, "openocd_result", resultvar
);
423 Jim_DecrRefCount(interp
, resultvar
);
427 target_call_timer_callbacks_now();
429 log_remove_callback(tcl_output
, tclOutput
);
431 Jim_SetResult(interp
, tclOutput
);
433 return (ignore
||(retval
==ERROR_OK
))?JIM_OK
:JIM_ERR
;
436 static int Jim_Command_openocd(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
438 return Jim_Command_openocd_ignore(interp
, argc
, argv
, 1);
441 static int Jim_Command_openocd_throw(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
443 return Jim_Command_openocd_ignore(interp
, argc
, argv
, 0);
446 /* find full path to file */
447 static int Jim_Command_find(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
451 char *file
= (char*)Jim_GetString(argv
[1], NULL
);
452 char *full_path
= find_file(file
);
453 if (full_path
== NULL
)
455 Jim_Obj
*result
= Jim_NewStringObj(interp
, full_path
, strlen(full_path
));
458 Jim_SetResult(interp
, result
);
462 static int Jim_Command_echo(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
466 char *str
= (char*)Jim_GetString(argv
[1], NULL
);
471 static size_t openocd_jim_fwrite(const void *_ptr
, size_t size
, size_t n
, void *cookie
)
476 /* make it a char easier to read code */
484 if (!active_cmd_ctx
) {
485 /* TODO: Where should this go? */
489 /* do we have to chunk it? */
490 if (ptr
[nbytes
] == 0) {
491 /* no it is a C style string */
492 command_output_text(active_cmd_ctx
, ptr
);
495 /* GRR we must chunk - not null terminated */
505 memcpy(chunk
, ptr
, x
);
509 command_output_text(active_cmd_ctx
, chunk
);
517 static size_t openocd_jim_fread(void *ptr
, size_t size
, size_t n
, void *cookie
)
519 /* TCL wants to read... tell him no */
523 static int openocd_jim_vfprintf(void *cookie
, const char *fmt
, va_list ap
)
529 if (active_cmd_ctx
) {
530 cp
= alloc_vprintf(fmt
, ap
);
532 command_output_text(active_cmd_ctx
, cp
);
540 static int openocd_jim_fflush(void *cookie
)
542 /* nothing to flush */
546 static char* openocd_jim_fgets(char *s
, int size
, void *cookie
)
555 Jim_CreateCommand(interp
, "openocd", Jim_Command_openocd
, NULL
, NULL
);
556 Jim_CreateCommand(interp
, "openocd_throw", Jim_Command_openocd_throw
, NULL
, NULL
);
557 Jim_CreateCommand(interp
, "find", Jim_Command_find
, NULL
, NULL
);
558 Jim_CreateCommand(interp
, "echo", Jim_Command_echo
, NULL
, NULL
);
559 Jim_CreateCommand(interp
, "mem2array", Jim_Command_mem2array
, NULL
, NULL
);
561 /* Set Jim's STDIO */
562 interp
->cookie_stdin
= NULL
;
563 interp
->cookie_stdout
= NULL
;
564 interp
->cookie_stderr
= NULL
;
565 interp
->cb_fwrite
= openocd_jim_fwrite
;
566 interp
->cb_fread
= openocd_jim_fread
;
567 interp
->cb_vfprintf
= openocd_jim_vfprintf
;
568 interp
->cb_fflush
= openocd_jim_fflush
;
569 interp
->cb_fgets
= openocd_jim_fgets
;
572 /* after command line parsing */
575 if (Jim_Eval(interp
, "source [find tcl/commands.tcl]")==JIM_ERR
)
577 LOG_ERROR("Can not find tcl/commands.tcl - check installation");
582 command_context_t
*setup_command_handler(void)
584 command_context_t
*cmd_ctx
;
586 cmd_ctx
= command_init();
588 register_command(cmd_ctx
, NULL
, "version", handle_version_command
,
589 COMMAND_EXEC
, "show OpenOCD version");
590 register_command(cmd_ctx
, NULL
, "daemon_startup", handle_daemon_startup_command
, COMMAND_CONFIG
,
591 "deprecated - use \"init\" and \"reset\" at end of startup script instead");
593 /* register subsystem commands */
594 server_register_commands(cmd_ctx
);
595 telnet_register_commands(cmd_ctx
);
596 gdb_register_commands(cmd_ctx
);
597 tcl_register_commands(cmd_ctx
); /* tcl server commands */
598 log_register_commands(cmd_ctx
);
599 jtag_register_commands(cmd_ctx
);
600 interpreter_register_commands(cmd_ctx
);
601 xsvf_register_commands(cmd_ctx
);
602 target_register_commands(cmd_ctx
);
603 flash_register_commands(cmd_ctx
);
604 nand_register_commands(cmd_ctx
);
605 pld_register_commands(cmd_ctx
);
607 if (log_init(cmd_ctx
) != ERROR_OK
)
611 LOG_DEBUG("log init complete");
613 LOG_OUTPUT( OPENOCD_VERSION
"\n" );
616 register_command(cmd_ctx
, NULL
, "init", handle_init_command
,
617 COMMAND_ANY
, "initializes target and servers - nop on subsequent invocations");
622 /* normally this is the main() function entry, but if OpenOCD is linked
623 * into application, then this fn will not be invoked, but rather that
624 * application will have it's own implementation of main(). */
625 int openocd_main(int argc
, char *argv
[])
629 /* Create an interpreter */
630 interp
= Jim_CreateInterp();
631 /* Add all the Jim core commands */
632 Jim_RegisterCoreCommands(interp
);
637 /* initialize commandline interface */
638 command_context_t
*cmd_ctx
;
639 cmd_ctx
=setup_command_handler();
641 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
642 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
643 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
644 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
645 /* DANGER!!! make sure that the line below does not appear in a patch, do not remove */
646 LOG_OUTPUT( "$URL$\n");
647 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
648 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
649 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
650 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
651 /* DANGER!!! make sure that the line above does not appear in a patch, do not remove */
653 command_context_t
*cfg_cmd_ctx
;
654 cfg_cmd_ctx
= copy_command_context(cmd_ctx
);
655 cfg_cmd_ctx
->mode
= COMMAND_CONFIG
;
656 command_set_output_handler(cfg_cmd_ctx
, configuration_output_handler
, NULL
);
658 active_cmd_ctx
=cfg_cmd_ctx
;
664 if (parse_cmdline_args(cfg_cmd_ctx
, argc
, argv
) != ERROR_OK
)
667 if (parse_config_file(cfg_cmd_ctx
) != ERROR_OK
)
670 active_cmd_ctx
=cmd_ctx
;
672 command_done(cfg_cmd_ctx
);
674 if (command_run_line(cmd_ctx
, "init")!=ERROR_OK
)
678 command_run_line(cmd_ctx
, "reset");
682 /* handle network connections */
683 server_loop(cmd_ctx
);
685 /* shut server down */
688 unregister_all_commands(cmd_ctx
);
690 /* free commandline interface */
691 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)