From 207237b92005d604b75ff5280042a6c286a685f8 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sat, 22 Mar 2014 16:47:37 +0400 Subject: tcl: introduce init_target_events and use it for gdb flashing events This introduces a new global Tcl procedure that is run just after init_targets and before init_boards. Its default behaviour is to assign gdb-flash-erase-start and gdb-flash-write-end to reasonable defaults. The rationale for doing "reset init" before gdb erases and flashes memory is that all flash drivers are written in assumption that they can safely be used only after chip reset (plus chip-specific configuration in the init handler if any). The need to use "reset halt" after flashing is because a user expects running firmware after loading to be the same as running it from power-on-reset. Change-Id: I9ddc4047611904ca4ca779b73376d2739611948a Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/2062 Tested-by: jenkins Reviewed-by: Spencer Oliver --- src/target/startup.tcl | 15 +++++++++++++++ src/target/target.c | 4 ++++ 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/target/startup.tcl b/src/target/startup.tcl index 56fcbaa7..033e9c9c 100644 --- a/src/target/startup.tcl +++ b/src/target/startup.tcl @@ -164,6 +164,21 @@ proc armv4_5 params { proc init_targets {} { } +proc set_default_target_event {t e s} { + if {[$t cget -event $e] == ""} { + $t configure -event $e $s + } +} + +proc init_target_events {} { + set targets [target names] + + foreach t $targets { + set_default_target_event $t gdb-flash-erase-start "reset init" + set_default_target_event $t gdb-flash-write-end "reset halt" + } +} + # Additionally board config scripts can define a procedure init_board that will be executed after init and init_targets proc init_board {} { } diff --git a/src/target/target.c b/src/target/target.c index f5a8666b..98201554 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -1274,6 +1274,10 @@ COMMAND_HANDLER(handle_target_init_command) if (ERROR_OK != retval) return retval; + retval = command_run_line(CMD_CTX, "init_target_events"); + if (ERROR_OK != retval) + return retval; + retval = command_run_line(CMD_CTX, "init_board"); if (ERROR_OK != retval) return retval; -- cgit v1.2.3-18-g5258