summaryrefslogtreecommitdiff
path: root/src/target/target.c
diff options
context:
space:
mode:
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-07-06 19:17:43 +0000
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-07-06 19:17:43 +0000
commitdc796a209113c3fdc27de0211edcaa67faed7b5f (patch)
treeea4090346c30947e3b688338b886e40ffdfd49d0 /src/target/target.c
parent71460ba9a59503bdf7780962b93143021d423958 (diff)
downloadopenocd+libswd-dc796a209113c3fdc27de0211edcaa67faed7b5f.tar.gz
openocd+libswd-dc796a209113c3fdc27de0211edcaa67faed7b5f.tar.bz2
openocd+libswd-dc796a209113c3fdc27de0211edcaa67faed7b5f.tar.xz
openocd+libswd-dc796a209113c3fdc27de0211edcaa67faed7b5f.zip
src/helper/configuration.h
- Log output handlers now get a "const char *line" - Added "const" to parameter. src/helper/command.c src/helper/command.h - New function: 'command_output_text()' - Log output handlers now get a "const char *line" src/helper/options.c - Log output handlers now get a "const char *line" src/server/telnet_server.c - DO not transmit NULL bytes via TELNET. - Log output handlers now get a "const char *line" src/server/gdb_server.c - Log output handlers now get a "const char *line" *** THIS INCLUDES PORTIONS OF A PATCH FROM Oyvind sent previously to the mailing list for TCL users try src/target/target.c *** THIS INCLUDES PORTIONS OF A PATCH FROM Oyvind sent previously to the mailing list for TCL users try src/target/target.h *** THIS INCLUDES PORTIONS OF A PATCH FROM Oyvind sent previously to the mailing list for TCL users try src/openocd.c - **MAJOR** Work: New TCL/Jim function: mem2array - **MAJOR** Work: Redirect Tcl/Jim stdio output to remote users. - Previously: TCL output did not go to GDB. - Previously: TCL output did not go to TELNET - Previously: TCL output only goes to control console. - This fixes that problem. + Created callbacks: +openocd_jim_fwrite() +openocd_jim_fread() +openocd_jim_vfprintf() +openocd_jim_fflush() +openocd_jim_fgets() src/Makefile.am - New TCL files. - Future note: This should be more automated. As the list of 'tcl' files grows maintaning this list will suck. src/Jim.c - ** THIS INCLUDES A PREVIOUS PATCH I SENT EARLIER ** - that impliments many [format] specifies JIM did not support. - Jim_FormatString() - **MAJOR** work. - Previously only supported "%s" "%d" and "%c" - And what support existed had bugs. - NEW: *MANY* formating parameters are now supported. - TODO: The "precision" specifier is not supported. ** NEW ** This patch. - Jim_StringToWide() test if no conversion occured. - Jim_StringToIndex() test if no conversion occured. - Jim_StringToDouble() test if no conversion occured. ** NEW ** This Patch. Major Work. - Previously output from JIM did not get sent to GDB - Ditto: Output to Telnet session. - Above items are now fixed - By introducing callbacks new function pointers in the "interp" structure. - Helpers that call the callbacks. - New function: Jim_fprintf() - New function: Jim_vfprintf() - New function: Jim_fwrite() - New function: Jim_fread() - New function: Jim_fflush() - New function: Jim_fgets() By default: the output is to STDIO as previous. The "openocd.c" - redirects the output as needed. - Jim_Panic() - Send panic to both STDERR and the interps specified STDERR output as a 2nd choice. - Now JIM's "stdin/stdout/stderr" paramters are "void *" and are no longer "FILE *". src/Jim.h - **MAJOR** - New JIM STDIO callbacks in the "interp" structure. - change: "stdin/stdout/stderr" are now "void *" cookies. - New JIM stdio helper functions. git-svn-id: svn://svn.berlios.de/openocd/trunk@755 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/target/target.c')
-rw-r--r--src/target/target.c87
1 files changed, 21 insertions, 66 deletions
diff --git a/src/target/target.c b/src/target/target.c
index 0237fd66..86b42db2 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -215,23 +215,6 @@ target_t* get_current_target(command_context_t *cmd_ctx)
return target;
}
-static void execute_script(struct command_context_s *cmd_ctx, char *reset_script)
-{
- if (reset_script==NULL)
- return;
- FILE *script;
- script = open_file_from_path(reset_script, "r");
- if (!script)
- {
- LOG_ERROR("couldn't open script file %s", reset_script);
- return;
- }
-
- LOG_INFO("executing script '%s'", reset_script);
- command_run_file(cmd_ctx, script, COMMAND_EXEC);
- fclose(script);
-}
-
/* Process target initialization, when target entered debug out of reset
* the handler is unregistered at the end of this function, so it's only called once
*/
@@ -243,7 +226,7 @@ int target_init_handler(struct target_s *target, enum target_event event, void *
{
target_unregister_event_callback(target_init_handler, priv);
- execute_script(cmd_ctx, target->reset_script);
+ target_invoke_script(cmd_ctx, target, "reset");
jtag_execute_queue();
}
@@ -305,7 +288,7 @@ int target_process_reset(struct command_context_s *cmd_ctx)
target = targets;
while (target)
{
- execute_script(cmd_ctx, target->pre_reset_script);
+ target_invoke_script(cmd_ctx, target, "pre_reset");
target = target->next;
}
@@ -950,7 +933,8 @@ int target_register_commands(struct command_context_s *cmd_ctx)
{
register_command(cmd_ctx, NULL, "target", handle_target_command, COMMAND_CONFIG, "target <cpu> [reset_init default - DEPRECATED] <chainpos> <endianness> <variant> [cpu type specifc args]");
register_command(cmd_ctx, NULL, "targets", handle_targets_command, COMMAND_EXEC, NULL);
- register_command(cmd_ctx, NULL, "target_script", handle_target_script_command, COMMAND_CONFIG, NULL);
+ register_command(cmd_ctx, NULL, "target_script", handle_target_script_command, COMMAND_CONFIG,
+ "target_script <target#> <event=reset/pre_reset/post_halt/pre_resume/gdb_program_config> <script_file>");
register_command(cmd_ctx, NULL, "run_and_halt_time", handle_run_and_halt_time_command, COMMAND_CONFIG, "<target> <run time ms>");
register_command(cmd_ctx, NULL, "working_area", handle_working_area_command, COMMAND_ANY, "working_area <target#> <address> <size> <'backup'|'nobackup'> [virtual address]");
register_command(cmd_ctx, NULL, "virt2phys", handle_virt2phys_command, COMMAND_ANY, "virt2phys <virtual address>");
@@ -1437,12 +1421,6 @@ int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **a
}
(*last_target_p)->run_and_halt_time = 1000; /* default 1s */
- (*last_target_p)->reset_script = NULL;
- (*last_target_p)->pre_reset_script = NULL;
- (*last_target_p)->post_halt_script = NULL;
- (*last_target_p)->pre_resume_script = NULL;
- (*last_target_p)->gdb_program_script = NULL;
-
(*last_target_p)->working_area = 0x0;
(*last_target_p)->working_area_size = 0x0;
(*last_target_p)->working_areas = NULL;
@@ -1487,7 +1465,14 @@ int handle_target_command(struct command_context_s *cmd_ctx, char *cmd, char **a
return ERROR_OK;
}
-/* usage: target_script <target#> <event> <script_file> */
+int target_invoke_script(struct command_context_s *cmd_ctx, target_t *target, char *name)
+{
+ return command_run_linef(cmd_ctx, " if {[catch {info body target_%s_%d} t]==0} {target_%s_%d}",
+ name, get_num_by_target(target),
+ name, get_num_by_target(target));
+}
+
+
int handle_target_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
target_t *target = NULL;
@@ -1505,41 +1490,14 @@ int handle_target_script_command(struct command_context_s *cmd_ctx, char *cmd, c
return ERROR_COMMAND_SYNTAX_ERROR;
}
- if ((strcmp(args[1], "reset") == 0)||(strcmp(args[1], "post_reset") == 0))
- {
- if (target->reset_script)
- free(target->reset_script);
- target->reset_script = strdup(args[2]);
- }
- else if (strcmp(args[1], "pre_reset") == 0)
- {
- if (target->pre_reset_script)
- free(target->pre_reset_script);
- target->pre_reset_script = strdup(args[2]);
- }
- else if (strcmp(args[1], "post_halt") == 0)
- {
- if (target->post_halt_script)
- free(target->post_halt_script);
- target->post_halt_script = strdup(args[2]);
- }
- else if (strcmp(args[1], "pre_resume") == 0)
- {
- if (target->pre_resume_script)
- free(target->pre_resume_script);
- target->pre_resume_script = strdup(args[2]);
- }
- else if (strcmp(args[1], "gdb_program_config") == 0)
- {
- if (target->gdb_program_script)
- free(target->gdb_program_script);
- target->gdb_program_script = strdup(args[2]);
- }
- else
- {
- LOG_ERROR("unknown event type: '%s", args[1]);
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
+ /* Define a tcl procedure which we'll invoke upon some event */
+ command_run_linef(cmd_ctx,
+ "proc target_%s_%d {} {"
+ "openocd {script %s}"
+ "}",
+ args[1],
+ get_num_by_target(target),
+ args[2]);
return ERROR_OK;
}
@@ -2021,14 +1979,11 @@ int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char **args,
output_len = 0;
}
}
- } else
- {
- LOG_ERROR("Failure examining memory");
}
free(buffer);
- return ERROR_OK;
+ return retval;
}
int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)