* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* *
- * Copyright (C) 2007,2008 Øyvind Harboe *
+ * Copyright (C) 2007-2010 Øyvind Harboe *
* oyvind.harboe@zylin.com *
* *
* Copyright (C) 2008 Richard Missenden *
#include "openocd.h"
#include <jtag/driver.h>
#include <jtag/jtag.h>
+#include <jtag/transport.h>
#include <helper/ioutil.h>
+#include <helper/util.h>
#include <helper/configuration.h>
-#include <xsvf/xsvf.h>
-#include <svf/svf.h>
#include <flash/nor/core.h>
#include <flash/nand/core.h>
#include <pld/pld.h>
#include <server/server.h>
#include <server/gdb_server.h>
-#include <server/httpd.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#define OPENOCD_VERSION \
"Open On-Chip Debugger " VERSION RELSTR " (" PKGBLDDATE ")"
-/* Give TELNET a way to find out what version this is */
-COMMAND_HANDLER(handle_version_command)
+/* Give scripts and TELNET a way to find out what version this is */
+static int jim_version_command(Jim_Interp *interp, int argc,
+ Jim_Obj * const *argv)
{
- if (CMD_ARGC != 0)
- return ERROR_COMMAND_SYNTAX_ERROR;
-
- command_print(CMD_CTX, OPENOCD_VERSION);
+ if (argc > 2)
+ {
+ return JIM_ERR;
+ }
+ const char *str = "";
+ char * version_str;
+ version_str = OPENOCD_VERSION;
+
+ if (argc == 2)
+ str = Jim_GetString(argv[1], NULL);
+
+ if (strcmp("git", str) == 0)
+ {
+ version_str = GITVERSION;
+ }
+
+ Jim_SetResult(interp, Jim_NewStringObj(interp, version_str, -1));
- return ERROR_OK;
+ return JIM_OK;
}
static int log_target_callback_event_handler(struct target *target, enum target_event event, void *priv)
if (ERROR_OK != retval)
return ERROR_FAIL;
- if ((retval = jtag_interface_init(CMD_CTX)) != ERROR_OK)
+ if ((retval = adapter_init(CMD_CTX)) != ERROR_OK)
{
- /* we must be able to set up the jtag interface */
+ /* we must be able to set up the debug adapter */
return retval;
}
- LOG_DEBUG("jtag interface init complete");
- /* Try to initialize & examine the JTAG chain at this point,
- * but continue startup regardless. Note that platforms
- * need to be able to provide JTAG event handlers that use
- * a variety of JTAG operations in order to do that...
+ LOG_DEBUG("Debug Adapter init complete");
+
+ /* "transport init" verifies the expected devices are present;
+ * for JTAG, it checks the list of configured TAPs against
+ * what's discoverable, possibly with help from the platform's
+ * JTAG event handlers. (which require COMMAND_EXEC)
*/
command_context_mode(CMD_CTX, COMMAND_EXEC);
- if (command_run_line(CMD_CTX, "jtag init") == ERROR_OK)
- {
- LOG_DEBUG("Examining targets...");
- if (target_examine() != ERROR_OK)
- LOG_DEBUG("target examination failed");
- }
- else
- LOG_WARNING("jtag initialization failed; try 'jtag init' again.");
+
+ retval = command_run_line(CMD_CTX, "transport init");
+ if (ERROR_OK != retval)
+ return ERROR_FAIL;
+
+ LOG_DEBUG("Examining targets...");
+ if (target_examine() != ERROR_OK)
+ LOG_DEBUG("target examination failed");
+
command_context_mode(CMD_CTX, COMMAND_CONFIG);
if (command_run_line(CMD_CTX, "flash init") != ERROR_OK)
return ERROR_OK;
}
+COMMAND_HANDLER(handle_add_script_search_dir_command)
+{
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ add_script_search_dir(CMD_ARGV[0]);
+
+ return ERROR_OK;
+}
+
+
+static int jim_stacktrace_command(Jim_Interp *interp, int argc,
+ Jim_Obj * const *argv)
+{
+ if (argc != 1)
+ {
+ return JIM_ERR;
+ }
+ Jim_Obj * stacktrace = Jim_DuplicateObj(interp, interp->stackTrace);
+
+ /* insert actual error site at beginning of list*/
+ Jim_Obj *procname = Jim_NewStringObj(interp, "", -1); /* Uhhh... don't know this one. */
+ Jim_ListInsertElements(interp, stacktrace, 0, 1, &procname);
+ Jim_Obj *filename = Jim_NewStringObj(interp, interp->errorFileName, -1);
+ Jim_ListInsertElements(interp, stacktrace, 1, 1, &filename);
+ Jim_Obj *line = Jim_NewIntObj(interp, interp->errorLine);
+ Jim_ListInsertElements(interp, stacktrace, 2, 1, &line);
+
+ Jim_SetResult(interp, stacktrace);
+
+ return JIM_OK;
+}
+
static const struct command_registration openocd_command_handlers[] = {
{
.name = "version",
- .handler = &handle_version_command,
+ .jim_handler = jim_version_command,
.mode = COMMAND_ANY,
.help = "show program version",
},
"called automatically at the end of startup.",
},
+ {
+ .name = "add_script_search_dir",
+ .handler = &handle_add_script_search_dir_command,
+ .mode = COMMAND_ANY,
+ .help = "dir to search for config files and scripts",
+
+ },
+ {
+ .name = "stacktrace",
+ .jim_handler = jim_stacktrace_command,
+ .mode = COMMAND_ANY,
+ .help = "returns the stacktrace as a list of triples: proc, file, line."
+ "The stack trace is reset when a new stack trace is being built after "
+ "a new failure has occurred.",
+ },
COMMAND_REGISTRATION_DONE
};
-int openocd_register_commands(struct command_context *cmd_ctx)
+static int openocd_register_commands(struct command_context *cmd_ctx)
{
return register_commands(cmd_ctx, NULL, openocd_command_handlers);
}
struct command_context *global_cmd_ctx;
-/* NB! this fn can be invoked outside this file for non PC hosted builds */
+/* NB! this fn can be invoked outside this file for non PC hosted builds
+ * NB! do not change to 'static'!!!!
+ */
struct command_context *setup_command_handler(Jim_Interp *interp)
{
log_init();
&server_register_commands,
&gdb_register_commands,
&log_register_commands,
+ &transport_register_commands,
&interface_register_commands,
- &jtag_register_commands,
- &xsvf_register_commands,
- &svf_register_commands,
&target_register_commands,
&flash_register_commands,
&nand_register_commands,
cmd_ctx = setup_command_handler(NULL);
+ if (util_init(cmd_ctx) != ERROR_OK)
+ return EXIT_FAILURE;
+
if (ioutil_init(cmd_ctx) != ERROR_OK)
return EXIT_FAILURE;
if (ret != ERROR_OK)
return EXIT_FAILURE;
- if (httpd_start(cmd_ctx) != ERROR_OK)
- return EXIT_FAILURE;
-
ret = server_init(cmd_ctx);
if (ERROR_OK != ret)
return EXIT_FAILURE;
server_quit();
- httpd_stop();
-
unregister_all_commands(cmd_ctx, NULL);
/* free commandline interface */
command_done(cmd_ctx);
- jtag_interface_quit();
+ adapter_quit();
return ret;
}