diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/openocd.c | 114 | ||||
-rw-r--r-- | src/server/tcl_server.c | 7 |
4 files changed, 95 insertions, 39 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a518077e..ff0eb6e5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,11 +3,11 @@ bin_PROGRAMS = openocd if ECOSBOARD MAINFILE = ecosboard.c else -MAINFILE = main.c +MAINFILE = main.c jim.c endif -openocd_SOURCES = $(MAINFILE) openocd.c jim.c +openocd_SOURCES = $(MAINFILE) openocd.c # set the include path found by configure INCLUDES = -I$(top_srcdir)/src/helper \ @@ -18,6 +18,15 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+/* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling
+ * OpenOCD fn's. No-op in vanilla OpenOCD
+ */
+void lockBigLock()
+{
+}
+void unlockBigLock()
+{
+}
/*
This is the main entry for developer PC hosted OpenOCD.
diff --git a/src/openocd.c b/src/openocd.c index 197c2e32..b4a9704c 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -39,6 +39,7 @@ #include "server.h" #include "telnet_server.h" #include "gdb_server.h" +#include "tcl_server.h" #include <sys/time.h> #include <sys/types.h> @@ -49,9 +50,44 @@ #include <unistd.h> #include <errno.h> +#ifdef __ECOS +/* Jim is provied by eCos */ +#include <cyg/jimtcl/jim.h> +#else #define JIM_EMBEDDED #include "jim.h" +#endif + + + + +int launchTarget(struct command_context_s *cmd_ctx) +{ + int retval; + /* Try to examine & validate jtag chain, though this may require a reset first + * in which case we continue setup */ + jtag_init(cmd_ctx); + + /* try to examine target at this point. If it fails, perhaps a reset will + * bring it up later on via a telnet/gdb session */ + target_examine(cmd_ctx); + retval=flash_init_drivers(cmd_ctx); + if (retval!=ERROR_OK) + return retval; + LOG_DEBUG("flash init complete"); + + retval=nand_init(cmd_ctx); + if (retval!=ERROR_OK) + return retval; + LOG_DEBUG("NAND init complete"); + + retval=pld_init(cmd_ctx); + if (retval!=ERROR_OK) + return retval; + LOG_DEBUG("pld init complete"); + return retval; +} /* Give TELNET a way to find out what version this is */ int handle_version_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) @@ -149,17 +185,8 @@ int handle_init_command(struct command_context_s *cmd_ctx, char *cmd, char **arg } -/* implementations of OpenOCD that uses multithreading needs to lock OpenOCD while calling - * OpenOCD fn's. No-op in vanilla OpenOCD - */ -void lockBigLock() -{ -} -void unlockBigLock() -{ -} - - +void lockBigLock(); +void unlockBigLock(); @@ -176,8 +203,7 @@ new_int_array_element( Jim_Interp * interp, Jim_Obj *nameObjPtr, *valObjPtr; int result; - namebuf = alloca( strlen(varname) + 30 ); - sprintf( namebuf, "%s(%d)", varname, idx ); + namebuf = alloc_printf("%s(%d)", varname, idx ); nameObjPtr = Jim_NewStringObj(interp, namebuf, -1); @@ -187,6 +213,7 @@ new_int_array_element( Jim_Interp * interp, result = Jim_SetVariable(interp, nameObjPtr, valObjPtr); Jim_DecrRefCount(interp, nameObjPtr); Jim_DecrRefCount(interp, valObjPtr); + free(namebuf); // printf( "%s = 0%08x\n", namebuf, val ); return result; } @@ -197,7 +224,6 @@ Jim_Command_mem2array( Jim_Interp *interp, int argc, Jim_Obj *const *argv) target_t *target; long l; u32 width; - u32 endian; u32 len; u32 addr; u32 count; @@ -423,7 +449,7 @@ int jim_command(command_context_t *context, char *line) return retval; } -static int startLoop=0; +int startLoop=0; static int Jim_Command_openocd_ignore(Jim_Interp *interp, @@ -509,6 +535,8 @@ Jim_Command_echo(Jim_Interp *interp, return JIM_OK; } +void command_output_text( command_context_t *context, const char *data ); + static size_t openocd_jim_fwrite( const void *_ptr, size_t size, size_t n, void *cookie ) { @@ -533,7 +561,7 @@ openocd_jim_fwrite( const void *_ptr, size_t size, size_t n, void *cookie ) if( ptr[ nbytes ] == 0 ){ /* no it is a C style string */ command_output_text( active_cmd_ctx, ptr ); - return; + return strlen(ptr); } /* GRR we must chunk - not null terminated */ while( nbytes ){ @@ -602,12 +630,6 @@ openocd_jim_fgets( char *s, int size, void *cookie ) void initJim(void) { - Jim_InitEmbedded(); - - /* Create an interpreter */ - interp = Jim_CreateInterp(); - /* Add all the Jim core commands */ - Jim_RegisterCoreCommands(interp); Jim_CreateCommand(interp, "openocd", Jim_Command_openocd, NULL, NULL); Jim_CreateCommand(interp, "openocd_throw", Jim_Command_openocd_throw, NULL, NULL); Jim_CreateCommand(interp, "find", Jim_Command_find, NULL, NULL); @@ -625,17 +647,16 @@ void initJim(void) interp->cb_fgets = openocd_jim_fgets; } -/* -normally this is the main() function entry, but if OpenOCD is linked -into application, then this fn will not be invoked, but rather that -application will have it's own implementation of main(). -*/ -int openocd_main(int argc, char *argv[]) +/* after command line parsing */ +void initJim2(void) { - initJim(); + Jim_Eval(interp, "source [find tcl/commands.tcl]"); +} + +command_context_t *setup_command_handler() +{ + command_context_t *cmd_ctx; - /* initialize commandline interface */ - command_context_t *cmd_ctx, *cfg_cmd_ctx; cmd_ctx = command_init(); register_command(cmd_ctx, NULL, "version", handle_version_command, @@ -658,7 +679,9 @@ int openocd_main(int argc, char *argv[]) pld_register_commands(cmd_ctx); if (log_init(cmd_ctx) != ERROR_OK) - return EXIT_FAILURE; + { + exit(-1); + } LOG_DEBUG("log init complete"); LOG_OUTPUT( OPENOCD_VERSION "\n" ); @@ -679,6 +702,31 @@ int openocd_main(int argc, char *argv[]) register_command(cmd_ctx, NULL, "init", handle_init_command, COMMAND_ANY, "initializes target and servers - nop on subsequent invocations"); + return cmd_ctx; +} + +/* +normally this is the main() function entry, but if OpenOCD is linked +into application, then this fn will not be invoked, but rather that +application will have it's own implementation of main(). +*/ +int openocd_main(int argc, char *argv[]) +{ +#ifdef JIM_EMBEDDED + Jim_InitEmbedded(); + /* Create an interpreter */ + interp = Jim_CreateInterp(); + /* Add all the Jim core commands */ + Jim_RegisterCoreCommands(interp); +#endif + + initJim(); + + /* initialize commandline interface */ + command_context_t *cmd_ctx; + cmd_ctx=setup_command_handler(); + + command_context_t *cfg_cmd_ctx; cfg_cmd_ctx = copy_command_context(cmd_ctx); cfg_cmd_ctx->mode = COMMAND_CONFIG; command_set_output_handler(cfg_cmd_ctx, configuration_output_handler, NULL); @@ -686,7 +734,7 @@ int openocd_main(int argc, char *argv[]) if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK) return EXIT_FAILURE; - Jim_Eval(interp, "source [find tcl/commands.tcl]"); + initJim2(); if (parse_config_file(cfg_cmd_ctx) != ERROR_OK) return EXIT_FAILURE; diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index cfdb8d07..8c47eafe 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -75,7 +75,7 @@ int tcl_output(connection_t *connection, const void *data, ssize_t len) if (wlen == len)
return ERROR_OK;
- LOG_ERROR("error during write: %d != %d", wlen, len);
+ LOG_ERROR("error during write: %d != %d", (int)wlen, (int)len);
tclc->tc_outerror = 1;
return ERROR_SERVER_REMOTE_CLOSED;
}
@@ -84,7 +84,6 @@ int tcl_output(connection_t *connection, const void *data, ssize_t len) /* connections */
static int tcl_new_connection(connection_t *connection)
{
- int i;
tcl_connection_t *tclc;
tclc = malloc(sizeof(tcl_connection_t));
@@ -177,8 +176,8 @@ int tcl_init(void) if (tcl_port == 0)
{
- LOG_WARNING("no tcl port specified, using default port 5555");
- tcl_port = 5555;
+ LOG_WARNING("no tcl port specified, using default port 6666");
+ tcl_port = 6666;
}
retval = add_service("tcl", CONNECTION_TCL, tcl_port, 1, tcl_new_connection, tcl_input, tcl_closed, NULL);
|