Commit 5ac8036b authored by oharboe's avatar oharboe
Browse files

Removed target->reset_mode, no longer used

git-svn-id: svn:// b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent ef1cfb23
To be incorporated in openocd.texi...
Current as of Aug 30, 2008 - Duane Ellis
Overview - History
Pre "tcl" - many commands in openocd where implimented as C
functions. Post "tcl" (Jim-Tcl to be more exact, June 2008 ...) TCL
became a bigger part of OpenOCD.
One of the biggest changes is the introduction of 'target specific'
commands. When every you create a target, a special command name is
created specifically for that target.
For example - in Tcl/Tk - if you create a button (or any other
screen object) you can specify various "button configuration
parameters". One of those parameters is the "object cmd/name"
[ In TK - this is refered to as the object path ]. Later you
can use that 'path' as a command to modify the button, for
example to make it "grey", or change the color.
In effect, the "path" function is an 'object oriented command'
The TCL change in OpenOCD follows the same principle, you create a
target, and a specific "targetname" command is created.
There are two methods of creating a target.
(1) Depricated: Using the old syntax Target names are autogenerated
as: "target0", "target1" etc..
(2) Using the new syntax, you can specify the name of the target.
As most users will have a single JTAG target, and by default the
command name will probably default to "target0", thus for reasons of
simplicity the instructions below use the name 'target0'
Overview - History *END*
OpenOCD has the following 'target' or 'target-like' commands.
(1) targets -(plural) lists all known targets and a little bit of
information about each target, most importantly the target
*COMMAND*NAME* (it also lists the target number)
(2) target -(singular) used to create, configure list, etc the targets
(3) target0 - the command object for the first target.
Unless you specified another name.
The "targets" (plural, 1 above) command has 2 functions.
With a parameter, you can change the current command line target.
NOTE: "with a parameter" is really only useful with 'multiple
jtag targets' not something you normally encounter (ie: If you
had 2 arm chips - sharing the same JTAG chain)
# using a target name..
(gdb) mon targets target0
# or a target by number.
(gdb) mon targets 3
Or - plain, without any parameter lists targets, for example:
(gdb) mon targets
CmdName Type Endian ChainPos State
-- ---------- ---------- ---------- -------- ----------
0: target0 arm7tdmi little 0 halted
This shows:
(a) in this example, a single target
(b) target number 0 (1st column)
(c) the 'object name' is target0 (the default name)
(d) it is an arm7tdmi
(e) little endian
(f) The position in the JTAG chain
(g) and is currently halted.
The "target" (singular, 2 above) command has the following options:
target create CMDNAME TYPE ... config options ...
argv[0] = 'target'
argv[1] = 'create'
argv[2] = the 'object command'
(normally, target0, see (3) above)
argv[3] = the target type, ie: arm7tdmi
argv[4..N] = configuration parameters
target types
Lists all supported target types.
ie: arm7tdmi, xscale, fericon, cortex-m3
The result TCL List of all known target types (and is human
target names
Returns a TCL list of all known target commands (and is
human readable)
foreach t [target names] {
puts [format "Target: %s\n" $t]
target current
Returns the TCL command name of the current target.
set ct [target current]
set t [$ct cget -type]
puts "Current target name is: $ct, and is a: $t"
target number <VALUE>
Returns the TCL command name of the specified target.
For example
set thename [target number $x]
puts [format "Target %d is: %s\n" $x $thename]
For instance, assuming the defaults
target number 0
Would return 'target0' (or whatever you called it)
target count
Returns the larget+1 target number.
For example:
set c [target count]
for { set x 0 } { $x < $c } { incr x } {
# Assuming you have this function..
print_target_details $x
"target0" - (#3 above) the "Target Object" command.
Once a target is 'created' a command object by that targets name is
created, for example
target create BiGRed arm7tdmi -endian little -chain-position 3
Would create a [case sensative] "command" BiGRed
If you use the old [deprecated] syntax, the name is automatically
generated and is in the form:
target0, target1, target2, target3, .... etc.
** Target CREATE, CONFIGURE and CGET options **
The commands:
target create CMDNAME TYPE [configure-options]
CMDNAME configure [configure-options]
CMDNAME cget [configure-options]
In the 'create' case, one is creating the target and can specify any
number of configuration parameters.
In the 'CMDNAME cget' case, the goal is to query the target for a
specific configuration option.
In the 'CMDNAME configure' case, one can change the setting.
[Not all things can, or should be changed]
In the above, the "default" name target0 is 'target0'
From the (gdb) prompt, one can type this:
(gdb) mon target0 configure -endian big
And change target0 to 'big-endian'. This is a contrived example,
specifically for this document - don't expect changing endian
'mid-operation' to work you should set the endian at creation.
Known options [30/august/2008] are:
[Manditory 'create' Options]
-type arm7tdmi|arm720|etc ...
-chain-position NUMBER
-endian ENDIAN
-event EVENTNAME "tcl-action"
-work-area-virt ADDR
-work-area-phys ADDR
-work-area-size ADDR
-work-area-backup BOOLEAN
[Hint: To get a list of avaialable options, try this]
(gdb) mon target0 cget -BLAHBLAHBLAH
the abov causes an error - and a helpful list of valid options.
** Example Target Configure Query **
One can query any of the above options at run time, for example:
(gdb) mon target0 cget -OPTION [param]
Example TCL script
# For all targets...
set c [target count]
for { set x 0 } { $x < $c } { incr x ] {
set n [target number $x]
set t [$n cget -type]
set e [$n cget -endian]
puts [format "%d: %s, %s, endian: %s\n" $x $n $t $n]
Might produce:
0: pic32chip, mips_m4k, endain: little
1: arm7, arm7tdmi, endian: big
2: blackfin, bf534, endian: little
Notice the above example is not target0, target1, target2 Why? Because
in this contrived multi-target example - more human understandable
target names might be helpful.
For example these two are the same:
(gdb) mon blackfin configure -event FOO {puts "Hi mom"}
(gdb) mon [target number 2] configure -event FOO {puts "Hi mom"}
In the second case, we use [] to get the command name of target #2, in
this contrived example - it is "blackfin"
** TWO Important Configure Options Are: **
Two important configuration options are:
"-event" and "-reset"
The "-reset" option specifies what should happen when the chip is
reset, for example should it 'halt', 're-init', or what.
The "-event" option less you specifiy a TCL command to occur when a
specific event occurs.
** Target Events * Overview **
At various points in time - certian 'target' events happen. You can
create a custom event action to occur at that time.
For example - after reset, the PLLs and CLOCKs may need to be
reconfigured, or perhaps the SDRAM needs to be re-initialized
Often the easiest way to do that is to create a simple script file
containing the series of (mww [poke memory]) commands you would type
by hand, to reconfigure the target clocks. You could specify the
"event action" like this:
(gdb) mon target0 configure -event reset-init "script cfg.clocks"
In the above example, when the event "reset-init" occurs, the
"action-string" will be evaluated as if you typed it at the console
Option1 -
The simple approach (above) is to create a script file with
lots of "mww" (memory write word) commands to configure your
targets clocks and/or external memory.
Option2 -
You can instead create a fancy Tcl procedure and invoke that
procedure instead of sourcing a file.
[Infact, "script" is a TCL procedure that loads a file]
** Target Events * Details **
There are many events one could use, to get a current list of events
type the following invalid command, you'll get a helpful "runtime
error" message, see below: [list valid as of 30/august/2008]
(gdb) mon target0 cget -event FAFA
Runtime error, file "../../../openocd23/src/helper/command.c", line 433:
-event: Unknown: FAFA, try one of: old-pre_reset,
old-gdb_program_config, old-post_reset, halted,
resumed, resume-start, resume-end, reset-start,
reset-assert-pre, reset-assert-post,
reset-deassert-pre, reset-deassert-post,
reset-halt-pre, reset-halt-post, reset-wait-pre,
reset-wait-post, reset-init, reset-end,
examine-start, examine-end, debug-halted,
debug-resumed, gdb-attach, gdb-detach,
gdb-flash-write-start, gdb-flash-write-end,
gdb-flash-erase-start, gdb-flash-erase-end,
resume-start, resume-ok, or resume-end
The event-names "old-*" are deprecated and exist only to help old
scripts continue to function, and the old "target_script" command
to work. Please do not rely on them.
These are some other important names.
These occur when GDB/OpenOCD attempts to erase & program the FLASH
chip via GDB.
For example - some PCBs may have a simple GPIO pin that acts like
a "flash write protect" you might need to write a script that
disables "write protect"
** How to get a list of current event actions **
To get a list of current 'event actions', type the following command:
(gdb) mon target0 eventlist
Event actions for target (0) target0
Event | Body
------------------------- | ----------------------------------------
old-post_reset | script event/sam7x256_reset.script
Here is a simple example for all targets:
(gdb) mon foreach x [target names] { $x eventlist }
The above uses some TCL tricks:
(b) to generate the list, we use [target names]
(c) the BODY, contains $x - the loop variable
and expands to the target specific name
Recalling the earlier discussion - the "object command" there are
other things you can do besides "configure" the target.
Note: Many of these commands exist as "global" commands, and they also
exist as target specific commands.
For example, the "mww" (memory write word) operates on the current target
if you have more then 1 target, you must switch
In contrast to the normal commands, these commands operate on the
specific target. For example, the command "mww" writes data to the
*current* command line target.
Often, you have only a single target - but if you have multiple
targets (ie: a PIC32 and an at91sam7 - your reset-init scripts might
get a bit more complicated, ie: you must specify which of the two
chips you want to write to. Writing 'pic32' clock configuration to an
at91sam7 does not work)
The commands are: [as of 30/august/2008]
Write(poke): 32, 16, 8bit values to memory.
Human 'hexdump' with ascii 32, 16, 8bit values
TNAME mem2array [see mem2array command]
TNAME array2mem [see array2mem command]
TNAME curstate
Returns the current state of the target.
TNAME examine
See 'advanced target reset'
TNAME poll
See 'advanced target reset'
TNAME reset assert
See 'advanced target reset'
TNAME reset deassert
See 'advanced target reset'
TNAME halt
See 'advanced target reset'
See 'advanced target reset'
......@@ -160,7 +160,7 @@ const Jim_Nvp nvp_target_event[] = {
{ .value = TARGET_EVENT_OLD_gdb_program_config , .name = "old-gdb_program_config" },
{ .value = TARGET_EVENT_OLD_post_reset , .name = "old-post_reset" },
{ .value = TARGET_EVENT_OLD_pre_resume , .name = "old-pre_resume" },
{ .value = TARGET_EVENT_HALTED, .name = "halted" },
{ .value = TARGET_EVENT_RESUMED, .name = "resumed" },
......@@ -188,7 +188,7 @@ const Jim_Nvp nvp_target_event[] = {
{ .value = TARGET_EVENT_EXAMINE_START, .name = "examine-start" },
{ .value = TARGET_EVENT_EXAMINE_START, .name = "examine-end" },
{ .value = TARGET_EVENT_DEBUG_HALTED, .name = "debug-halted" },
{ .value = TARGET_EVENT_DEBUG_RESUMED, .name = "debug-resumed" },
......@@ -342,7 +342,7 @@ target_t* get_target_by_num(int num)
while (target){
if( target->target_number == num ){
return target;
target = target->next;
......@@ -758,8 +758,8 @@ int target_call_event_callbacks(target_t *target, enum target_event event)
target_event_callback_t *callback = target_event_callbacks;
target_event_callback_t *next_callback;
LOG_DEBUG("target event %i (%s)",
LOG_DEBUG("target event %i (%s)",
Jim_Nvp_value2name_simple( nvp_target_event, event )->name );
target_handle_event( target, event );
......@@ -1000,7 +1000,7 @@ int target_arch_state(struct target_s *target)
return ERROR_OK;
LOG_USER("target state: %s",
LOG_USER("target state: %s",
if (target->state!=TARGET_HALTED)
......@@ -1394,18 +1394,18 @@ int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **
if( 0 == strcmp( args[0], target->cmd_name ) ){
/* MATCH */
goto Match;
/* no match, try as number */
int num = strtoul(args[0], &cp, 0 );
if( *cp != 0 ){
/* then it was not a number */
command_print( cmd_ctx, "Target: %s unknown, try one of:\n", args[0] );
goto DumpTargets;
target = get_target_by_num( num );
if( target == NULL ){
command_print(cmd_ctx,"Target: %s is unknown, try one of:\n", args[0] );
......@@ -1422,11 +1422,11 @@ int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **
while (target)
/* XX: abcdefghij abcdefghij abcdefghij abcdefghij */
command_print(cmd_ctx, "%2d: %-10s %-10s %-10s %8d %s",
command_print(cmd_ctx, "%2d: %-10s %-10s %-10s %8d %s",
Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness )->name,
Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness )->name,
Jim_Nvp_value2name_simple( nvp_target_state, target->state )->name );
target = target->next;
......@@ -1689,14 +1689,14 @@ int target_wait_state(target_t *target, enum target_state state, int ms)
if (once)
LOG_DEBUG("waiting for target %s...",
LOG_DEBUG("waiting for target %s...",
gettimeofday(&now, NULL);
if ((now.tv_sec > timeout.tv_sec) || ((now.tv_sec == timeout.tv_sec) && (now.tv_usec >= timeout.tv_usec)))
LOG_ERROR("timed out while waiting for target %s",
LOG_ERROR("timed out while waiting for target %s",
return ERROR_FAIL;
......@@ -2801,7 +2801,7 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
command_context_t *context;
target_t *target;
context = Jim_GetAssocData(interp, "context");
if (context == NULL){
LOG_ERROR("array2mem: no command context");
......@@ -2812,10 +2812,10 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
LOG_ERROR("array2mem: no current target");
return JIM_ERR;
return target_array2mem( interp,target, argc, argv );
static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
......@@ -2955,7 +2955,7 @@ target_all_handle_event( enum target_event e )
target_t *target;
LOG_DEBUG( "**all*targets: event: %d, %s",
LOG_DEBUG( "**all*targets: event: %d, %s",
Jim_Nvp_value2name_simple( nvp_target_event, e )->name );
......@@ -2990,7 +2990,7 @@ target_handle_event( target_t *target, enum target_event e )
teap = teap->next;
if( !done ){
LOG_DEBUG( "event: %d %s - no action",
LOG_DEBUG( "event: %d %s - no action",
Jim_Nvp_value2name_simple( nvp_target_event, e )->name );
......@@ -2998,7 +2998,7 @@ target_handle_event( target_t *target, enum target_event e )
enum target_cfg_param {
......@@ -3021,10 +3021,10 @@ static Jim_Nvp nvp_config_opts[] = {
{ .name = "-endian" , .value = TCFG_ENDIAN },
{ .name = "-variant", .value = TCFG_VARIANT },
{ .name = "-chain-position", .value = TCFG_CHAIN_POSITION },
{ .name = NULL, .value = -1 }
static int
target_configure( Jim_GetOptInfo *goi,
......@@ -3093,7 +3093,7 @@ target_configure( Jim_GetOptInfo *goi,
if( goi->argc == 0 ){
Jim_WrongNumArgs( goi->interp, goi->argc, goi->argv, "-event ?event-name? ?EVENT-BODY?");
return JIM_ERR;
} else {
if( goi->argc != 0 ){
Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name?");
......@@ -3101,10 +3101,10 @@ target_configure( Jim_GetOptInfo *goi,
target_event_action_t *teap;
teap = target->event_action;
/* replace existing? */
while( teap ){
......@@ -3113,7 +3113,7 @@ target_configure( Jim_GetOptInfo *goi,
teap = teap->next;
if( goi->isconfigure ){
if( teap == NULL ){
/* create new */
......@@ -3126,7 +3126,7 @@ target_configure( Jim_GetOptInfo *goi,
teap->body = Jim_DuplicateObj( goi->interp, o );
* Tcl/TK - "tk events" have a nice feature.
* See the "BIND" command.
* We should support that here.
......@@ -3153,32 +3153,6 @@ target_configure( Jim_GetOptInfo *goi,
/* loop for more */
if( goi->isconfigure ){
e = Jim_GetOpt_Nvp( goi, nvp_reset_modes, &n );
if( e != JIM_OK ){
Jim_GetOpt_NvpUnknown( goi, nvp_reset_modes, 1 );
return e;
if( n->value == RESET_UNKNOWN ){
Jim_SetResultString( interp, "'unknown' is not a valid selection",-1);
return JIM_ERR;
target->reset_mode = n->value;
} else {
if( goi->argc != 0 ){
goto no_params;
n = Jim_Nvp_value2name_simple( nvp_reset_modes, target->reset_mode );
if( n->name == NULL ){
target->reset_mode = RESET_HALT;