tip on checking with supplier for binaries
[openocd.git] / doc / README_TARGET_COMMAND.txt
blobb02e4881e2a10da0a2c1fdab85a387c67abf8901
1 To be incorporated in openocd.texi...
4 ==
5 Current as of Aug 30, 2008 - Duane Ellis
6 ==
8 ===================================================
9 Overview - History
11   Pre "tcl" - many commands in openocd where implimented as C
12   functions.  Post "tcl" (Jim-Tcl to be more exact, June 2008 ...) TCL
13   became a bigger part of OpenOCD.
15 One of the biggest changes is the introduction of 'target specific'
16 commands. When every you create a target, a special command name is
17 created specifically for that target.
19         For example - in Tcl/Tk - if you create a button (or any other
20         screen object) you can specify various "button configuration
21         parameters". One of those parameters is the "object cmd/name"
22         [ In TK - this is refered to as the object path ]. Later you
23         can use that 'path' as a command to modify the button, for
24         example to make it "grey", or change the color.
26 In effect, the "path" function is an 'object oriented command'
28 The TCL change in OpenOCD follows the same principle, you create a
29 target, and a specific "targetname" command is created.
31 There are two methods of creating a target.
33   (1) Depricated: Using the old syntax Target names are autogenerated
34       as: "target0", "target1" etc..
36   (2) Using the new syntax, you can specify the name of the target.
38 As most users will have a single JTAG target, and by default the
39 command name will probably default to "target0", thus for reasons of
40 simplicity the instructions below use the name 'target0'
42 Overview - History *END*
43 ==================================================
45 OpenOCD has the following 'target' or 'target-like' commands.
47 (1) targets -(plural) lists all known targets and a little bit of
48     information about each target, most importantly the target
49     *COMMAND*NAME* (it also lists the target number)
51 (2) target -(singular) used to create, configure list, etc the targets
53 (3) target0 - the command object for the first target.
54     Unless you specified another name.
56 ===================================================
58 The "targets" (plural, 1 above) command has 2 functions.
60 With a parameter, you can change the current command line target.
62      NOTE: "with a parameter" is really only useful with 'multiple
63      jtag targets' not something you normally encounter (ie: If you
64      had 2 arm chips - sharing the same JTAG chain)
66      # using a target name..
67     (gdb) mon targets target0
68      # or a target by number.
69     (gdb) mon targets 3
71 Or - plain, without any parameter lists targets, for example:
73     (gdb) mon targets
74               CmdName    Type       Endian     ChainPos State     
75           --  ---------- ---------- ---------- -------- ----------
76            0: target0    arm7tdmi   little     0        halted
78 This shows:
79    (a) in this example, a single target
80    (b) target number 0 (1st column)
81    (c) the 'object name' is target0 (the default name)
82    (d) it is an arm7tdmi
83    (e) little endian 
84    (f) The position in the JTAG chain
85    (g) and is currently halted.
87 ====================================================
89 The "target" (singular, 2 above) command has the following options:
91     target create CMDNAME TYPE  ... config options ...
92           argv[0] = 'target'
93           argv[1] = 'create'
94           argv[2] = the 'object command'
95                   (normally, target0, see (3) above)
96           argv[3] = the target type, ie: arm7tdmi
97           argv[4..N] = configuration parameters
98     
99     target types
100            Lists all supported target types.
101            ie: arm7tdmi, xscale, fericon, cortex-m3
102            
103            The result TCL List of all known target types (and is human
104            readable)
106     target names
108            Returns a TCL list of all known target commands (and is
109            human readable)
111            Example:
112                 foreach t [target names] {
113                     puts [format "Target: %s\n" $t]
114                 }
117     target current
119            Returns the TCL command name of the current target.
121            Example:
122                 set ct [target current]
123                 set t  [$ct cget -type]
124                 
125                 puts "Current target name is: $ct, and is a: $t"
128     target number <VALUE>
130            Returns the TCL command name of the specified target.
131            For example 
133                set thename [target number $x]
134                puts [format "Target %d is: %s\n" $x $thename]
136            For instance, assuming the defaults
138                target number 0
140            Would return 'target0' (or whatever you called it)
142     target count
144            Returns the larget+1 target number.
145            For example:
147                set c [target count]
148                for { set x 0 } { $x < $c } { incr x } {
149                    # Assuming you have this function..
150                    print_target_details $x
151                }
153 ====================================================
155 "target0" - (#3 above) the "Target Object" command.
157   Once a target is 'created' a command object by that targets name is
158   created, for example
160   target create BiGRed arm7tdmi -endian little -chain-position 3
162 Would create a [case sensative] "command" BiGRed
164 If you use the old [deprecated] syntax, the name is automatically
165 generated and is in the form:
167           target0, target1, target2, target3, .... etc.
169 ====================================================
171 ** Target CREATE, CONFIGURE and CGET options **
173 The commands:
174     
175     target create CMDNAME TYPE  [configure-options]
176     CMDNAME configure [configure-options]
177     CMDNAME cget      [configure-options]
179 In the 'create' case, one is creating the target and can specify any
180 number of configuration parameters.
182 In the 'CMDNAME cget' case, the goal is to query the target for a
183 specific configuration option.
185 In the 'CMDNAME configure' case, one can change the setting.
186 [Not all things can, or should be changed]
188 In the above, the "default" name target0 is 'target0'
190 Example:
192    From the (gdb) prompt, one can type this:
194        (gdb) mon target0 configure -endian big
196    And change target0 to 'big-endian'.  This is a contrived example,
197    specifically for this document - don't expect changing endian
198    'mid-operation' to work you should set the endian at creation.
200 Known options [30/august/2008] are:
202 [Manditory 'create' Options]
203        -type arm7tdmi|arm720|etc ...
204        -chain-position NUMBER
205        -endian ENDIAN
207 Optional
209        -event EVENTNAME  "tcl-action"
210        -reset RESETACTION
211        -work-area-virt ADDR
212        -work-area-phys ADDR
213        -work-area-size ADDR
214        -work-area-backup BOOLEAN
216 [Hint: To get a list of avaialable options, try this]
218        (gdb) mon target0 cget -BLAHBLAHBLAH
220     the abov causes an error - and a helpful list of valid options.
222 ==================================================
223 ** Example Target Configure Query **
225 One can query any of the above options at run time, for example:
227  (gdb) mon target0 cget -OPTION [param]
229 Example TCL script
231     # For all targets...
232     set c [target count]
233     for { set x 0 } { $x < $c } { incr x ] {
234       set n [target number $x]
235       set t [$n cget -type]
236       set e [$n cget -endian]
237       puts [format "%d: %s, %s, endian: %s\n" $x $n $t $n]
238    }
240 Might produce:
241       0: pic32chip, mips_m4k, endain: little
242       1: arm7, arm7tdmi, endian: big
243       2: blackfin, bf534, endian: little
245 Notice the above example is not target0, target1, target2 Why? Because
246 in this contrived multi-target example - more human understandable
247 target names might be helpful. 
249 For example these two are the same:
251    (gdb) mon blackfin configure -event FOO {puts "Hi mom"}
254    (gdb) mon [target number 2] configure -event FOO {puts "Hi mom"}
256 In the second case, we use [] to get the command name of target #2, in
257 this contrived example - it is "blackfin"
259 ====================================================
260 ** TWO Important Configure Options Are: **
262 Two important configuration options are:
264     "-event" and "-reset"
266 The "-reset" option specifies what should happen when the chip is
267 reset, for example should it 'halt', 're-init', or what.
269 The "-event" option less you specifiy a TCL command to occur when a
270 specific event occurs.
272 ====================================================
273 ** Target Events * Overview **
275 At various points in time - certian 'target' events happen.  You can
276 create a custom event action to occur at that time.
278 For example - after reset, the PLLs and CLOCKs may need to be
279 reconfigured, or perhaps the SDRAM needs to be re-initialized
281 Often the easiest way to do that is to create a simple script file
282 containing the series of (mww [poke memory]) commands you would type
283 by hand, to reconfigure the target clocks. You could specify the
284 "event action" like this:
286    (gdb) mon target0 configure -event reset-init "script cfg.clocks"
288 In the above example, when the event "reset-init" occurs, the
289 "action-string" will be evaluated as if you typed it at the console
291 Option1 - 
293         The simple approach (above) is to create a script file with
294         lots of "mww" (memory write word) commands to configure your
295         targets clocks and/or external memory.
297 Option2 -
299         You can instead create a fancy Tcl procedure and invoke that
300         procedure instead of sourcing a file.
302         [Infact, "script" is a TCL procedure that loads a file]
304 ==================================================
306 ** Target Events * Details **
308 There are many events one could use, to get a current list of events
309 type the following invalid command, you'll get a helpful "runtime
310 error" message, see below: [list valid as of 30/august/2008]
312    (gdb) mon target0 cget -event FAFA
314 Runtime error, file "../../../openocd23/src/helper/command.c", line 433:
315     -event: Unknown: FAFA, try one of: old-pre_reset, 
316     old-gdb_program_config, old-post_reset, halted, 
317     resumed, resume-start, resume-end, reset-start, 
318     reset-assert-pre, reset-assert-post, 
319     reset-deassert-pre, reset-deassert-post, 
320     reset-halt-pre, reset-halt-post, reset-wait-pre, 
321     reset-wait-post, reset-init, reset-end, 
322     examine-start, examine-end, debug-halted, 
323     debug-resumed, gdb-attach, gdb-detach, 
324     gdb-flash-write-start, gdb-flash-write-end, 
325     gdb-flash-erase-start, gdb-flash-erase-end, 
326     resume-start, resume-ok, or resume-end
328 NOTE:
330     The event-names "old-*" are deprecated and exist only to help old
331     scripts continue to function, and the old "target_script" command
332     to work. Please do not rely on them.
334 These are some other important names.
336     gdb-flash-erase-start
337     gdb-flash-erase-end
338     gdb-flash-write-start
339     gdb-flash-write-end
341     These occur when GDB/OpenOCD attempts to erase & program the FLASH
342     chip via GDB.
344     For example - some PCBs may have a simple GPIO pin that acts like
345     a "flash write protect" you might need to write a script that
346     disables "write protect"
348 ==================================================
350 ** How to get a list of current event actions **
352 To get a list of current 'event actions', type the following command:
354    (gdb) mon target0 eventlist
356     Event actions for target (0) target0
358     Event                     | Body
359     ------------------------- | ----------------------------------------
360     old-post_reset            | script event/sam7x256_reset.script
361     ***END***
363 Here is a simple example for all targets:
365    (gdb)  mon foreach x [target names] { $x eventlist }
367 The above uses some TCL tricks:
369    (a) foreach VARIABLE  LIST  BODY
371    (b) to generate the list, we use [target names]
372    
373    (c) the BODY, contains $x - the loop variable
374        and expands to the target specific name
376 ====================================================
378 Recalling the earlier discussion - the "object command" there are 
379 other things you can do besides "configure" the target.
381 Note: Many of these commands exist as "global" commands, and they also
382 exist as target specific commands.
384 For example, the "mww" (memory write word) operates on the current target
385 if you have more then 1 target, you must switch
387 In contrast to the normal commands, these commands operate on the
388 specific target. For example, the command "mww" writes data to the
389 *current* command line target. 
391 Often, you have only a single target - but if you have multiple
392 targets (ie: a PIC32 and an at91sam7 - your reset-init scripts might
393 get a bit more complicated, ie: you must specify which of the two
394 chips you want to write to. Writing 'pic32' clock configuration to an
395 at91sam7 does not work)
397 The commands are: [as of 30/august/2008]
399     TNAME  mww ADDRESS VALUE
400     TNAME  mwh ADDRESS VALUE
401     TNAME  mwb ADDRESS VALUE
402            Write(poke): 32, 16, 8bit values to memory.
404     TNAME  mdw ADDRESS VALUE
405     TNAME  mdh ADDRESS VALUE
406     TNAME  mdb ADDRESS VALUE
407            Human 'hexdump' with ascii 32, 16, 8bit values
409     TNAME  mem2array  [see mem2array command]
410     TNAME  array2mem  [see array2mem command]
412     TNAME  curstate
413           Returns the current state of the target.
416     TNAME examine
417           See 'advanced target reset'
418     TNAME poll
419           See 'advanced target reset'
420     TNAME reset assert
421           See 'advanced target reset'
422     TNAME reset deassert
423           See 'advanced target reset'
424     TNAME halt
425           See 'advanced target reset'
426     TNAME waitstate STATENAME
427           See 'advanced target reset'