Hi
I integrated READ_TARGET_COMMENT.txt content into openocd general
documentation (outputted as openocd.pdf).
Index: openocd.texi
===================================================================
--- openocd.texi        (revision 1065)
+++ openocd.texi        (working copy)
@@ -941,6 +941,449 @@
 @end itemize
 
 @page
[EMAIL PROTECTED] Target Commands
[EMAIL PROTECTED] Target Commands
+
[EMAIL PROTECTED] Overview
[EMAIL PROTECTED] Overview
+Pre "TCL" - many commands in OpenOCD where implemented 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 time 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 referred 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:
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]
+Using the old syntax (deprecated). Target names are autogenerated as: 
+  "target0", "target1", etc.;
[EMAIL PROTECTED] old syntax
[EMAIL PROTECTED]
+Using the new syntax, you can specify the name of the target.
[EMAIL PROTECTED] new syntax
[EMAIL PROTECTED] enumerate
+
+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".
+
[EMAIL PROTECTED] Commands
[EMAIL PROTECTED] Commands
+OpenOCD has the following 'target' or 'target-like' commands:
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED] (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);
[EMAIL PROTECTED] targets
[EMAIL PROTECTED]
[EMAIL PROTECTED] (singular)} - used to create, configure list, etc the targets;
[EMAIL PROTECTED] target
[EMAIL PROTECTED]
[EMAIL PROTECTED] - the command object for the first target. Unless you 
specified another name.
[EMAIL PROTECTED] target0
[EMAIL PROTECTED] enumerate
+
[EMAIL PROTECTED] Targets Command
[EMAIL PROTECTED] Targets Command
+The "targets" command has 2 functions:
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]
+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).
[EMAIL PROTECTED]
+# using a target name.
+(gdb) mon targets target0
+# or a target by number.
+(gdb) mon targets 3
[EMAIL PROTECTED] verbatim
[EMAIL PROTECTED] with a parameter
[EMAIL PROTECTED]
+Plain, without any parameter lists targets, for example:
+
[EMAIL PROTECTED]
+(gdb) mon targets
+      CmdName     Type     Endian    ChainPos   State     
+--  ---------- ---------- ---------- -------- ----------
+    0: target0  arm7tdmi   little        0      halted
[EMAIL PROTECTED] verbatim
+
+This shows:
[EMAIL PROTECTED] a
[EMAIL PROTECTED]
+in this example, a single target;
[EMAIL PROTECTED]
+target number 0 (1st column);
[EMAIL PROTECTED]
+the 'object name' is target0 (the default name);
[EMAIL PROTECTED]
+it is an arm7tdmi;
[EMAIL PROTECTED]
+little endian;
[EMAIL PROTECTED]
+the position in the JTAG chain;
[EMAIL PROTECTED] 
+and is currently halted.
[EMAIL PROTECTED] enumerate
[EMAIL PROTECTED] without any parameter
[EMAIL PROTECTED] itemize
+
[EMAIL PROTECTED] Target Command
[EMAIL PROTECTED] Target Command
+
+The "target" command has the following options:
[EMAIL PROTECTED]
[EMAIL PROTECTED]
+target create
+
[EMAIL PROTECTED]
+       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
[EMAIL PROTECTED] verbatim
[EMAIL PROTECTED]
+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 readable).
[EMAIL PROTECTED]
+target names
+
+       Returns a TCL list of all known target commands (and is human readable).
+
+       Example:
[EMAIL PROTECTED]  
+       foreach t [target names] {
+           puts [format "Target: %s\n" $t]
+       }
[EMAIL PROTECTED] verbatim
[EMAIL PROTECTED]   
+target current
+
+    Returns the TCL command name of the current target.
+
+       Example:
[EMAIL PROTECTED] 
+       set ct [target current]
+       set t  [$ct cget -type]
+               
+       puts "Current target name is: $ct, and is a: $t"
[EMAIL PROTECTED] verbatim
[EMAIL PROTECTED]
+target number <VALUE>
+
+       Returns the TCL command name of the specified target.
+          
+       Example 
[EMAIL PROTECTED]
+    set thename [target number $x]
+    puts [format "Target %d is: %s\n" $x $thename]
[EMAIL PROTECTED] verbatim
+       For instance, assuming the defaults
[EMAIL PROTECTED]
+    target number 0
[EMAIL PROTECTED] verbatim
+       Would return 'target0' (or whatever you called it)
[EMAIL PROTECTED]
+target count
+
+       Returns the larget+1 target number.
+       
+       Example:
[EMAIL PROTECTED]
+    set c [target count]
+    for { set x 0 } { $x < $c } { incr x } {
+               # Assuming you have this function..
+               print_target_details $x
+    }
[EMAIL PROTECTED] verbatim
[EMAIL PROTECTED] itemize
+
[EMAIL PROTECTED] Target0 Command
[EMAIL PROTECTED] Target0 Command
+The "target0" command (the "Target Object" command):
+
+Once a target is 'created' a command object by that targets name is created, 
for example
[EMAIL PROTECTED]
+       target create BiGRed arm7tdmi -endian little -chain-position 3
[EMAIL PROTECTED] verbatim
+
+Would create a [case sensitive] "command" BiGRed
+
+If you use the old [deprecated] syntax, the name is automatically
+generated and is in the form:
[EMAIL PROTECTED]
+       target0, target1, target2, target3, ... etc.
[EMAIL PROTECTED] verbatim
+
[EMAIL PROTECTED] Target CREATE, CONFIGURE and CGET Options Command
[EMAIL PROTECTED] Target CREATE, CONFIGURE and CGET Options Command
+The commands:
[EMAIL PROTECTED]
+    target create CMDNAME TYPE  [configure-options]    
+    CMDNAME configure [configure-options]
+    CMDNAME cget      [configure-options]
[EMAIL PROTECTED] verbatim
[EMAIL PROTECTED]
[EMAIL PROTECTED]
+In the 'create' case, one is creating the target and can specify any
+number of configuration parameters.
[EMAIL PROTECTED]
+In the 'CMDNAME configure' case, one can change the setting [Not all things 
can, or should be changed].
[EMAIL PROTECTED]
+In the 'CMDNAME cget' case, the goal is to query the target for a
+specific configuration option.
[EMAIL PROTECTED] itemize
+
+In the above, the "default" name target0 is 'target0'.
+
+       Example:
+
+               From the (gdb) prompt, one can type this:
+
[EMAIL PROTECTED]
+       (gdb) mon target0 configure -endian big
[EMAIL PROTECTED] verbatim
+
+               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:
[EMAIL PROTECTED]
[EMAIL PROTECTED]
+[Mandatory 'create' Options]
+       @itemize
+       @item
+    type arm7tdmi|arm720|etc ...
+       @item
+    chain-position NUMBER
+       @item
+    endian ENDIAN
+       @end itemize
[EMAIL PROTECTED]
+Optional
+       @itemize
+       @item
+    event EVENTNAME  "tcl-action"
+       @item
+    reset RESETACTION
+       @item
+    work-area-virt ADDR
+       @item
+    work-area-phys ADDR
+       @item
+    work-area-size ADDR
+       @item
+    work-area-backup BOOLEAN
+       @end itemize
[EMAIL PROTECTED] itemize
+Hint: To get a list of available options, try this:
[EMAIL PROTECTED]
+       (gdb) mon target0 cget -BLAHBLAHBLAH
[EMAIL PROTECTED] verbatim
+
+    the above causes an error - and a helpful list of valid options.
+       
+One can query any of the above options at run time, for example:
[EMAIL PROTECTED]
+ (gdb) mon target0 cget -OPTION [param]
[EMAIL PROTECTED] verbatim
+
+Example TCL script
+
[EMAIL PROTECTED]
+    # 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]
+   }
[EMAIL PROTECTED] verbatim
+
+Might produce:
+
[EMAIL PROTECTED]
+    0: pic32chip, mips_m4k, endain: little
+    1: arm7, arm7tdmi, endian: big
+    2: blackfin, bf534, endian: little
[EMAIL PROTECTED] verbatim
+
+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:
+
[EMAIL PROTECTED]
+   (gdb) mon blackfin configure -event FOO {puts "Hi mom"}
[EMAIL PROTECTED] verbatim
+
+or:
+
[EMAIL PROTECTED]
+   (gdb) mon [target number 2] configure -event FOO {puts "Hi mom"}
[EMAIL PROTECTED] verbatim
+   
+In the second case, we use [] to get the command name of target #2, in this 
contrived example - it is "blackfin".
+
+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 specify a TCL command to occur when a specific 
event occurs.
+
[EMAIL PROTECTED] Target Events
[EMAIL PROTECTED] Target Events
+
[EMAIL PROTECTED] Overview
[EMAIL PROTECTED] Overview
+At various points in time - certain '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:
+
[EMAIL PROTECTED]
+   (gdb) mon target0 configure -event reset-init "script cfg.clocks"
[EMAIL PROTECTED] verbatim
+
+In the above example, when the event "reset-init" occurs, the "action-string" 
will be evaluated as if you typed it at the 
+console:
[EMAIL PROTECTED]
[EMAIL PROTECTED] @b{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;
[EMAIL PROTECTED] @b{Option2} - You can instead create a fancy TCL procedure 
and invoke that procedure instead of sourcing a file [In fact, 
+       "script" is a TCL procedure that loads a file].
[EMAIL PROTECTED] itemize
+
[EMAIL PROTECTED] Details
[EMAIL PROTECTED] 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]:
+
[EMAIL PROTECTED]
+(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
[EMAIL PROTECTED] verbatim
+
+NOTE: 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:
[EMAIL PROTECTED]
[EMAIL PROTECTED] gdb-flash-erase-start
[EMAIL PROTECTED] gdb-flash-erase-end
[EMAIL PROTECTED] gdb-flash-write-start
[EMAIL PROTECTED] gdb-flash-write-end
[EMAIL PROTECTED] itemize
+
+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".
+
+To get a list of current 'event actions', type the following command:
+
[EMAIL PROTECTED]
+   (gdb) mon target0 eventlist
+
+    Event actions for target (0) target0
+
+    Event                     | Body
+    ------------------------- | ----------------------------------------
+    old-post_reset            | script event/sam7x256_reset.script    
[EMAIL PROTECTED] verbatim
+
+Here is a simple example for all targets:
+
[EMAIL PROTECTED]
+   (gdb)  mon foreach x [target names] { $x eventlist }
[EMAIL PROTECTED] verbatim
+
+The above uses some TCL tricks:
[EMAIL PROTECTED] a
[EMAIL PROTECTED] foreach VARIABLE  LIST  BODY
[EMAIL PROTECTED] to generate the list, we use [target names]
[EMAIL PROTECTED] the BODY, contains $x - the loop variable and expands to the 
target specific name
[EMAIL PROTECTED] enumerate
+
+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]:
[EMAIL PROTECTED]
+    TNAME  mww ADDRESS VALUE
+    TNAME  mwh ADDRESS VALUE
+    TNAME  mwb ADDRESS VALUE
+          Write(poke): 32, 16, 8bit values to memory.
+
+    TNAME  mdw ADDRESS VALUE
+    TNAME  mdh ADDRESS VALUE
+    TNAME  mdb ADDRESS VALUE
+          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'
+    TNAME  waitstate STATENAME
+          See 'advanced target reset'
[EMAIL PROTECTED] verbatim
+
[EMAIL PROTECTED]
 @section Target Specific Commands
 @cindex Target Specific Commands
 
_______________________________________________
Openocd-development mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to