User's Guide: update GDB info
[openocd.git] / doc / openocd.texi
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename openocd.info
4 @settitle OpenOCD User's Guide
5 @dircategory Development
6 @direntry
7 * OpenOCD: (openocd). OpenOCD User's Guide
8 @end direntry
9 @paragraphindent 0
10 @c %**end of header
11
12 @include version.texi
13
14 @copying
15
16 This User's Guide documents
17 release @value{VERSION},
18 dated @value{UPDATED},
19 of the Open On-Chip Debugger (OpenOCD).
20
21 @itemize @bullet
22 @item Copyright @copyright{} 2008 The OpenOCD Project
23 @item Copyright @copyright{} 2007-2008 Spencer Oliver @email{spen@@spen-soft.co.uk}
24 @item Copyright @copyright{} 2008 Oyvind Harboe @email{oyvind.harboe@@zylin.com}
25 @item Copyright @copyright{} 2008 Duane Ellis @email{openocd@@duaneellis.com}
26 @item Copyright @copyright{} 2009 David Brownell
27 @end itemize
28
29 @quotation
30 Permission is granted to copy, distribute and/or modify this document
31 under the terms of the GNU Free Documentation License, Version 1.2 or
32 any later version published by the Free Software Foundation; with no
33 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
34 Texts. A copy of the license is included in the section entitled ``GNU
35 Free Documentation License''.
36 @end quotation
37 @end copying
38
39 @titlepage
40 @titlefont{@emph{Open On-Chip Debugger:}}
41 @sp 1
42 @title OpenOCD User's Guide
43 @subtitle for release @value{VERSION}
44 @subtitle @value{UPDATED}
45
46 @page
47 @vskip 0pt plus 1filll
48 @insertcopying
49 @end titlepage
50
51 @summarycontents
52 @contents
53
54 @ifnottex
55 @node Top
56 @top OpenOCD User's Guide
57
58 @insertcopying
59 @end ifnottex
60
61 @menu
62 * About:: About OpenOCD
63 * Developers:: OpenOCD Developers
64 * JTAG Hardware Dongles:: JTAG Hardware Dongles
65 * About JIM-Tcl:: About JIM-Tcl
66 * Running:: Running OpenOCD
67 * OpenOCD Project Setup:: OpenOCD Project Setup
68 * Config File Guidelines:: Config File Guidelines
69 * Daemon Configuration:: Daemon Configuration
70 * Interface - Dongle Configuration:: Interface - Dongle Configuration
71 * Reset Configuration:: Reset Configuration
72 * TAP Declaration:: TAP Declaration
73 * CPU Configuration:: CPU Configuration
74 * Flash Commands:: Flash Commands
75 * NAND Flash Commands:: NAND Flash Commands
76 * PLD/FPGA Commands:: PLD/FPGA Commands
77 * General Commands:: General Commands
78 * Architecture and Core Commands:: Architecture and Core Commands
79 * JTAG Commands:: JTAG Commands
80 * Boundary Scan Commands:: Boundary Scan Commands
81 * TFTP:: TFTP
82 * GDB and OpenOCD:: Using GDB and OpenOCD
83 * Tcl Scripting API:: Tcl Scripting API
84 * FAQ:: Frequently Asked Questions
85 * Tcl Crash Course:: Tcl Crash Course
86 * License:: GNU Free Documentation License
87
88 @comment DO NOT use the plain word ``Index'', reason: CYGWIN filename
89 @comment case issue with ``Index.html'' and ``index.html''
90 @comment Occurs when creating ``--html --no-split'' output
91 @comment This fix is based on: http://sourceware.org/ml/binutils/2006-05/msg00215.html
92 * OpenOCD Concept Index:: Concept Index
93 * Command and Driver Index:: Command and Driver Index
94 @end menu
95
96 @node About
97 @unnumbered About
98 @cindex about
99
100 OpenOCD was created by Dominic Rath as part of a diploma thesis written at the
101 University of Applied Sciences Augsburg (@uref{http://www.fh-augsburg.de}).
102 Since that time, the project has grown into an active open-source project,
103 supported by a diverse community of software and hardware developers from
104 around the world.
105
106 @section What is OpenOCD?
107 @cindex TAP
108 @cindex JTAG
109
110 The Open On-Chip Debugger (OpenOCD) aims to provide debugging,
111 in-system programming and boundary-scan testing for embedded target
112 devices.
113
114 @b{JTAG:} OpenOCD uses a ``hardware interface dongle'' to communicate
115 with the JTAG (IEEE 1149.1) compliant TAPs on your target board.
116 A @dfn{TAP} is a ``Test Access Port'', a module which processes
117 special instructions and data. TAPs are daisy-chained within and
118 between chips and boards.
119
120 @b{Dongles:} OpenOCD currently supports many types of hardware dongles: USB
121 based, parallel port based, and other standalone boxes that run
122 OpenOCD internally. @xref{JTAG Hardware Dongles}.
123
124 @b{GDB Debug:} It allows ARM7 (ARM7TDMI and ARM720t), ARM9 (ARM920T,
125 ARM922T, ARM926EJ--S, ARM966E--S), XScale (PXA25x, IXP42x) and
126 Cortex-M3 (Stellaris LM3 and ST STM32) based cores to be
127 debugged via the GDB protocol.
128
129 @b{Flash Programing:} Flash writing is supported for external CFI
130 compatible NOR flashes (Intel and AMD/Spansion command set) and several
131 internal flashes (LPC1700, LPC2000, AT91SAM7, AT91SAM3U, STR7x, STR9x, LM3, and
132 STM32x). Preliminary support for various NAND flash controllers
133 (LPC3180, Orion, S3C24xx, more) controller is included.
134
135 @section OpenOCD Web Site
136
137 The OpenOCD web site provides the latest public news from the community:
138
139 @uref{http://openocd.berlios.de/web/}
140
141 @section Latest User's Guide:
142
143 The user's guide you are now reading may not be the latest one
144 available. A version for more recent code may be available.
145 Its HTML form is published irregularly at:
146
147 @uref{http://openocd.berlios.de/doc/html/index.html}
148
149 PDF form is likewise published at:
150
151 @uref{http://openocd.berlios.de/doc/pdf/openocd.pdf}
152
153 @section OpenOCD User's Forum
154
155 There is an OpenOCD forum (phpBB) hosted by SparkFun:
156
157 @uref{http://forum.sparkfun.com/viewforum.php?f=18}
158
159
160 @node Developers
161 @chapter OpenOCD Developer Resources
162 @cindex developers
163
164 If you are interested in improving the state of OpenOCD's debugging and
165 testing support, new contributions will be welcome. Motivated developers
166 can produce new target, flash or interface drivers, improve the
167 documentation, as well as more conventional bug fixes and enhancements.
168
169 The resources in this chapter are available for developers wishing to explore
170 or expand the OpenOCD source code.
171
172 @section OpenOCD GIT Repository
173
174 During the 0.3.x release cycle, OpenOCD switched from Subversion to
175 a GIT repository hosted at SourceForge. The repository URL is:
176
177 @uref{git://openocd.git.sourceforge.net/gitroot/openocd/openocd}
178
179 You may prefer to use a mirror and the HTTP protocol:
180
181 @uref{http://repo.or.cz/r/openocd.git}
182
183 With standard GIT tools, use @command{git clone} to initialize
184 a local repository, and @command{git pull} to update it.
185 There are also gitweb pages letting you browse the repository
186 with a web browser, or download arbitrary snapshots without
187 needing a GIT client:
188
189 @uref{http://openocd.git.sourceforge.net/git/gitweb.cgi?p=openocd/openocd}
190
191 @uref{http://repo.or.cz/w/openocd.git}
192
193 The @file{README} file contains the instructions for building the project
194 from the repository or a snapshot.
195
196 Developers that want to contribute patches to the OpenOCD system are
197 @b{strongly} encouraged to work against mainline.
198 Patches created against older versions may require additional
199 work from their submitter in order to be updated for newer releases.
200
201 @section Doxygen Developer Manual
202
203 During the 0.2.x release cycle, the OpenOCD project began
204 providing a Doxygen reference manual. This document contains more
205 technical information about the software internals, development
206 processes, and similar documentation:
207
208 @uref{http://openocd.berlios.de/doc/doxygen/index.html}
209
210 This document is a work-in-progress, but contributions would be welcome
211 to fill in the gaps. All of the source files are provided in-tree,
212 listed in the Doxyfile configuration in the top of the source tree.
213
214 @section OpenOCD Developer Mailing List
215
216 The OpenOCD Developer Mailing List provides the primary means of
217 communication between developers:
218
219 @uref{https://lists.berlios.de/mailman/listinfo/openocd-development}
220
221 Discuss and submit patches to this list.
222 The @file{PATCHES} file contains basic information about how
223 to prepare patches.
224
225
226 @node JTAG Hardware Dongles
227 @chapter JTAG Hardware Dongles
228 @cindex dongles
229 @cindex FTDI
230 @cindex wiggler
231 @cindex zy1000
232 @cindex printer port
233 @cindex USB Adapter
234 @cindex RTCK
235
236 Defined: @b{dongle}: A small device that plugins into a computer and serves as
237 an adapter .... [snip]
238
239 In the OpenOCD case, this generally refers to @b{a small adapater} one
240 attaches to your computer via USB or the Parallel Printer Port. The
241 execption being the Zylin ZY1000 which is a small box you attach via
242 an ethernet cable. The Zylin ZY1000 has the advantage that it does not
243 require any drivers to be installed on the developer PC. It also has
244 a built in web interface. It supports RTCK/RCLK or adaptive clocking
245 and has a built in relay to power cycle targets remotely.
246
247
248 @section Choosing a Dongle
249
250 There are several things you should keep in mind when choosing a dongle.
251
252 @enumerate
253 @item @b{Voltage} What voltage is your target - 1.8, 2.8, 3.3, or 5V?
254 Does your dongle support it? You might need a level converter.
255 @item @b{Pinout} What pinout does your target board use?
256 Does your dongle support it? You may be able to use jumper
257 wires, or an "octopus" connector, to convert pinouts.
258 @item @b{Connection} Does your computer have the USB, printer, or
259 Ethernet port needed?
260 @item @b{RTCK} Do you require RTCK? Also known as ``adaptive clocking''
261 @end enumerate
262
263 @section Stand alone Systems
264
265 @b{ZY1000} See: @url{http://www.zylin.com/zy1000.html} Technically, not a
266 dongle, but a standalone box. The ZY1000 has the advantage that it does
267 not require any drivers installed on the developer PC. It also has
268 a built in web interface. It supports RTCK/RCLK or adaptive clocking
269 and has a built in relay to power cycle targets remotely.
270
271 @section USB FT2232 Based
272
273 There are many USB JTAG dongles on the market, many of them are based
274 on a chip from ``Future Technology Devices International'' (FTDI)
275 known as the FTDI FT2232; this is a USB full speed (12 Mbps) chip.
276 See: @url{http://www.ftdichip.com} for more information.
277 In summer 2009, USB high speed (480 Mbps) versions of these FTDI
278 chips are starting to become available in JTAG adapters.
279
280 @itemize @bullet
281 @item @b{usbjtag}
282 @* Link @url{http://www.hs-augsburg.de/~hhoegl/proj/usbjtag/usbjtag.html}
283 @item @b{jtagkey}
284 @* See: @url{http://www.amontec.com/jtagkey.shtml}
285 @item @b{jtagkey2}
286 @* See: @url{http://www.amontec.com/jtagkey2.shtml}
287 @item @b{oocdlink}
288 @* See: @url{http://www.oocdlink.com} By Joern Kaipf
289 @item @b{signalyzer}
290 @* See: @url{http://www.signalyzer.com}
291 @item @b{evb_lm3s811}
292 @* See: @url{http://www.luminarymicro.com} - The Stellaris LM3S811 eval board has an FTD2232C chip built in.
293 @item @b{luminary_icdi}
294 @* See: @url{http://www.luminarymicro.com} - Luminary In-Circuit Debug Interface (ICDI) Board, included in the Stellaris LM3S9B90 and LM3S9B92 Evaluation Kits.
295 @item @b{olimex-jtag}
296 @* See: @url{http://www.olimex.com}
297 @item @b{flyswatter}
298 @* See: @url{http://www.tincantools.com}
299 @item @b{turtelizer2}
300 @* See:
301 @uref{http://www.ethernut.de/en/hardware/turtelizer/index.html, Turtelizer 2}, or
302 @url{http://www.ethernut.de}
303 @item @b{comstick}
304 @* Link: @url{http://www.hitex.com/index.php?id=383}
305 @item @b{stm32stick}
306 @* Link @url{http://www.hitex.com/stm32-stick}
307 @item @b{axm0432_jtag}
308 @* Axiom AXM-0432 Link @url{http://www.axman.com}
309 @item @b{cortino}
310 @* Link @url{http://www.hitex.com/index.php?id=cortino}
311 @end itemize
312
313 @section USB JLINK based
314 There are several OEM versions of the Segger @b{JLINK} adapter. It is
315 an example of a micro controller based JTAG adapter, it uses an
316 AT91SAM764 internally.
317
318 @itemize @bullet
319 @item @b{ATMEL SAMICE} Only works with ATMEL chips!
320 @* Link: @url{http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3892}
321 @item @b{SEGGER JLINK}
322 @* Link: @url{http://www.segger.com/jlink.html}
323 @item @b{IAR J-Link}
324 @* Link: @url{http://www.iar.com/website1/1.0.1.0/369/1/index.php}
325 @end itemize
326
327 @section USB RLINK based
328 Raisonance has an adapter called @b{RLink}. It exists in a stripped-down form on the STM32 Primer, permanently attached to the JTAG lines. It also exists on the STM32 Primer2, but that is wired for SWD and not JTAG, thus not supported.
329
330 @itemize @bullet
331 @item @b{Raisonance RLink}
332 @* Link: @url{http://www.raisonance.com/products/RLink.php}
333 @item @b{STM32 Primer}
334 @* Link: @url{http://www.stm32circle.com/resources/stm32primer.php}
335 @item @b{STM32 Primer2}
336 @* Link: @url{http://www.stm32circle.com/resources/stm32primer2.php}
337 @end itemize
338
339 @section USB Other
340 @itemize @bullet
341 @item @b{USBprog}
342 @* Link: @url{http://www.embedded-projects.net/usbprog} - which uses an Atmel MEGA32 and a UBN9604
343
344 @item @b{USB - Presto}
345 @* Link: @url{http://tools.asix.net/prg_presto.htm}
346
347 @item @b{Versaloon-Link}
348 @* Link: @url{http://www.simonqian.com/en/Versaloon}
349
350 @item @b{ARM-JTAG-EW}
351 @* Link: @url{http://www.olimex.com/dev/arm-jtag-ew.html}
352 @end itemize
353
354 @section IBM PC Parallel Printer Port Based
355
356 The two well known ``JTAG Parallel Ports'' cables are the Xilnx DLC5
357 and the MacGraigor Wiggler. There are many clones and variations of
358 these on the market.
359
360 Note that parallel ports are becoming much less common, so if you
361 have the choice you should probably avoid these adapters in favor
362 of USB-based ones.
363
364 @itemize @bullet
365
366 @item @b{Wiggler} - There are many clones of this.
367 @* Link: @url{http://www.macraigor.com/wiggler.htm}
368
369 @item @b{DLC5} - From XILINX - There are many clones of this
370 @* Link: Search the web for: ``XILINX DLC5'' - it is no longer
371 produced, PDF schematics are easily found and it is easy to make.
372
373 @item @b{Amontec - JTAG Accelerator}
374 @* Link: @url{http://www.amontec.com/jtag_accelerator.shtml}
375
376 @item @b{GW16402}
377 @* Link: @url{http://www.gateworks.com/products/avila_accessories/gw16042.php}
378
379 @item @b{Wiggler2}
380 @*@uref{http://www.ccac.rwth-aachen.de/@/~michaels/@/index.php/hardware/@/armjtag,
381 Improved parallel-port wiggler-style JTAG adapter}
382
383 @item @b{Wiggler_ntrst_inverted}
384 @* Yet another variation - See the source code, src/jtag/parport.c
385
386 @item @b{old_amt_wiggler}
387 @* Unknown - probably not on the market today
388
389 @item @b{arm-jtag}
390 @* Link: Most likely @url{http://www.olimex.com/dev/arm-jtag.html} [another wiggler clone]
391
392 @item @b{chameleon}
393 @* Link: @url{http://www.amontec.com/chameleon.shtml}
394
395 @item @b{Triton}
396 @* Unknown.
397
398 @item @b{Lattice}
399 @* ispDownload from Lattice Semiconductor
400 @url{http://www.latticesemi.com/lit/docs/@/devtools/dlcable.pdf}
401
402 @item @b{flashlink}
403 @* From ST Microsystems;
404 @uref{http://www.st.com/stonline/@/products/literature/um/7889.pdf,
405 FlashLINK JTAG programing cable for PSD and uPSD}
406
407 @end itemize
408
409 @section Other...
410 @itemize @bullet
411
412 @item @b{ep93xx}
413 @* An EP93xx based Linux machine using the GPIO pins directly.
414
415 @item @b{at91rm9200}
416 @* Like the EP93xx - but an ATMEL AT91RM9200 based solution using the GPIO pins on the chip.
417
418 @end itemize
419
420 @node About JIM-Tcl
421 @chapter About JIM-Tcl
422 @cindex JIM Tcl
423 @cindex tcl
424
425 OpenOCD includes a small ``Tcl Interpreter'' known as JIM-Tcl.
426 This programming language provides a simple and extensible
427 command interpreter.
428
429 All commands presented in this Guide are extensions to JIM-Tcl.
430 You can use them as simple commands, without needing to learn
431 much of anything about Tcl.
432 Alternatively, can write Tcl programs with them.
433
434 You can learn more about JIM at its website, @url{http://jim.berlios.de}.
435
436 @itemize @bullet
437 @item @b{JIM vs. Tcl}
438 @* JIM-TCL is a stripped down version of the well known Tcl language,
439 which can be found here: @url{http://www.tcl.tk}. JIM-Tcl has far
440 fewer features. JIM-Tcl is a single .C file and a single .H file and
441 implements the basic Tcl command set. In contrast: Tcl 8.6 is a
442 4.2 MB .zip file containing 1540 files.
443
444 @item @b{Missing Features}
445 @* Our practice has been: Add/clone the real Tcl feature if/when
446 needed. We welcome JIM Tcl improvements, not bloat.
447
448 @item @b{Scripts}
449 @* OpenOCD configuration scripts are JIM Tcl Scripts. OpenOCD's
450 command interpreter today is a mixture of (newer)
451 JIM-Tcl commands, and (older) the orginal command interpreter.
452
453 @item @b{Commands}
454 @* At the OpenOCD telnet command line (or via the GDB mon command) one
455 can type a Tcl for() loop, set variables, etc.
456 Some of the commands documented in this guide are implemented
457 as Tcl scripts, from a @file{startup.tcl} file internal to the server.
458
459 @item @b{Historical Note}
460 @* JIM-Tcl was introduced to OpenOCD in spring 2008.
461
462 @item @b{Need a crash course in Tcl?}
463 @*@xref{Tcl Crash Course}.
464 @end itemize
465
466 @node Running
467 @chapter Running
468 @cindex command line options
469 @cindex logfile
470 @cindex directory search
471
472 The @option{--help} option shows:
473 @verbatim
474 bash$ openocd --help
475
476 --help | -h display this help
477 --version | -v display OpenOCD version
478 --file | -f use configuration file <name>
479 --search | -s dir to search for config files and scripts
480 --debug | -d set debug level <0-3>
481 --log_output | -l redirect log output to file <name>
482 --command | -c run <command>
483 --pipe | -p use pipes when talking to gdb
484 @end verbatim
485
486 By default OpenOCD reads the configuration file @file{openocd.cfg}.
487 To specify a different (or multiple)
488 configuration file, you can use the @option{-f} option. For example:
489
490 @example
491 openocd -f config1.cfg -f config2.cfg -f config3.cfg
492 @end example
493
494 Configuration files and scripts are searched for in
495 @enumerate
496 @item the current directory,
497 @item any search dir specified on the command line using the @option{-s} option,
498 @item @file{$HOME/.openocd} (not on Windows),
499 @item the site wide script library @file{$pkgdatadir/site} and
500 @item the OpenOCD-supplied script library @file{$pkgdatadir/scripts}.
501 @end enumerate
502 The first found file with a matching file name will be used.
503
504 @section Simple setup, no customization
505
506 In the best case, you can use two scripts from one of the script
507 libraries, hook up your JTAG adapter, and start the server ... and
508 your JTAG setup will just work "out of the box". Always try to
509 start by reusing those scripts, but assume you'll need more
510 customization even if this works. @xref{OpenOCD Project Setup}.
511
512 If you find a script for your JTAG adapter, and for your board or
513 target, you may be able to hook up your JTAG adapter then start
514 the server like:
515
516 @example
517 openocd -f interface/ADAPTER.cfg -f board/MYBOARD.cfg
518 @end example
519
520 You might also need to configure which reset signals are present,
521 using @option{-c 'reset_config trst_and_srst'} or something similar.
522 If all goes well you'll see output something like
523
524 @example
525 Open On-Chip Debugger 0.4.0 (2010-01-14-15:06)
526 For bug reports, read
527 http://openocd.berlios.de/doc/doxygen/bugs.html
528 Info : JTAG tap: lm3s.cpu tap/device found: 0x3ba00477
529 (mfg: 0x23b, part: 0xba00, ver: 0x3)
530 @end example
531
532 Seeing that "tap/device found" message, and no warnings, means
533 the JTAG communication is working. That's a key milestone, but
534 you'll probably need more project-specific setup.
535
536 @section What OpenOCD does as it starts
537
538 OpenOCD starts by processing the configuration commands provided
539 on the command line or, if there were no @option{-c command} or
540 @option{-f file.cfg} options given, in @file{openocd.cfg}.
541 @xref{Configuration Stage}.
542 At the end of the configuration stage it verifies the JTAG scan
543 chain defined using those commands; your configuration should
544 ensure that this always succeeds.
545 Normally, OpenOCD then starts running as a daemon.
546 Alternatively, commands may be used to terminate the configuration
547 stage early, perform work (such as updating some flash memory),
548 and then shut down without acting as a daemon.
549
550 Once OpenOCD starts running as a daemon, it waits for connections from
551 clients (Telnet, GDB, Other) and processes the commands issued through
552 those channels.
553
554 If you are having problems, you can enable internal debug messages via
555 the @option{-d} option.
556
557 Also it is possible to interleave JIM-Tcl commands w/config scripts using the
558 @option{-c} command line switch.
559
560 To enable debug output (when reporting problems or working on OpenOCD
561 itself), use the @option{-d} command line switch. This sets the
562 @option{debug_level} to "3", outputting the most information,
563 including debug messages. The default setting is "2", outputting only
564 informational messages, warnings and errors. You can also change this
565 setting from within a telnet or gdb session using @command{debug_level
566 <n>} (@pxref{debug_level}).
567
568 You can redirect all output from the daemon to a file using the
569 @option{-l <logfile>} switch.
570
571 For details on the @option{-p} option. @xref{Connecting to GDB}.
572
573 Note! OpenOCD will launch the GDB & telnet server even if it can not
574 establish a connection with the target. In general, it is possible for
575 the JTAG controller to be unresponsive until the target is set up
576 correctly via e.g. GDB monitor commands in a GDB init script.
577
578 @node OpenOCD Project Setup
579 @chapter OpenOCD Project Setup
580
581 To use OpenOCD with your development projects, you need to do more than
582 just connecting the JTAG adapter hardware (dongle) to your development board
583 and then starting the OpenOCD server.
584 You also need to configure that server so that it knows
585 about that adapter and board, and helps your work.
586 You may also want to connect OpenOCD to GDB, possibly
587 using Eclipse or some other GUI.
588
589 @section Hooking up the JTAG Adapter
590
591 Today's most common case is a dongle with a JTAG cable on one side
592 (such as a ribbon cable with a 10-pin or 20-pin IDC connector)
593 and a USB cable on the other.
594 Instead of USB, some cables use Ethernet;
595 older ones may use a PC parallel port, or even a serial port.
596
597 @enumerate
598 @item @emph{Start with power to your target board turned off},
599 and nothing connected to your JTAG adapter.
600 If you're particularly paranoid, unplug power to the board.
601 It's important to have the ground signal properly set up,
602 unless you are using a JTAG adapter which provides
603 galvanic isolation between the target board and the
604 debugging host.
605
606 @item @emph{Be sure it's the right kind of JTAG connector.}
607 If your dongle has a 20-pin ARM connector, you need some kind
608 of adapter (or octopus, see below) to hook it up to
609 boards using 14-pin or 10-pin connectors ... or to 20-pin
610 connectors which don't use ARM's pinout.
611
612 In the same vein, make sure the voltage levels are compatible.
613 Not all JTAG adapters have the level shifters needed to work
614 with 1.2 Volt boards.
615
616 @item @emph{Be certain the cable is properly oriented} or you might
617 damage your board. In most cases there are only two possible
618 ways to connect the cable.
619 Connect the JTAG cable from your adapter to the board.
620 Be sure it's firmly connected.
621
622 In the best case, the connector is keyed to physically
623 prevent you from inserting it wrong.
624 This is most often done using a slot on the board's male connector
625 housing, which must match a key on the JTAG cable's female connector.
626 If there's no housing, then you must look carefully and
627 make sure pin 1 on the cable hooks up to pin 1 on the board.
628 Ribbon cables are frequently all grey except for a wire on one
629 edge, which is red. The red wire is pin 1.
630
631 Sometimes dongles provide cables where one end is an ``octopus'' of
632 color coded single-wire connectors, instead of a connector block.
633 These are great when converting from one JTAG pinout to another,
634 but are tedious to set up.
635 Use these with connector pinout diagrams to help you match up the
636 adapter signals to the right board pins.
637
638 @item @emph{Connect the adapter's other end} once the JTAG cable is connected.
639 A USB, parallel, or serial port connector will go to the host which
640 you are using to run OpenOCD.
641 For Ethernet, consult the documentation and your network administrator.
642
643 For USB based JTAG adapters you have an easy sanity check at this point:
644 does the host operating system see the JTAG adapter? If that host is an
645 MS-Windows host, you'll need to install a driver before OpenOCD works.
646
647 @item @emph{Connect the adapter's power supply, if needed.}
648 This step is primarily for non-USB adapters,
649 but sometimes USB adapters need extra power.
650
651 @item @emph{Power up the target board.}
652 Unless you just let the magic smoke escape,
653 you're now ready to set up the OpenOCD server
654 so you can use JTAG to work with that board.
655
656 @end enumerate
657
658 Talk with the OpenOCD server using
659 telnet (@code{telnet localhost 4444} on many systems) or GDB.
660 @xref{GDB and OpenOCD}.
661
662 @section Project Directory
663
664 There are many ways you can configure OpenOCD and start it up.
665
666 A simple way to organize them all involves keeping a
667 single directory for your work with a given board.
668 When you start OpenOCD from that directory,
669 it searches there first for configuration files, scripts,
670 files accessed through semihosting,
671 and for code you upload to the target board.
672 It is also the natural place to write files,
673 such as log files and data you download from the board.
674
675 @section Configuration Basics
676
677 There are two basic ways of configuring OpenOCD, and
678 a variety of ways you can mix them.
679 Think of the difference as just being how you start the server:
680
681 @itemize
682 @item Many @option{-f file} or @option{-c command} options on the command line
683 @item No options, but a @dfn{user config file}
684 in the current directory named @file{openocd.cfg}
685 @end itemize
686
687 Here is an example @file{openocd.cfg} file for a setup
688 using a Signalyzer FT2232-based JTAG adapter to talk to
689 a board with an Atmel AT91SAM7X256 microcontroller:
690
691 @example
692 source [find interface/signalyzer.cfg]
693
694 # GDB can also flash my flash!
695 gdb_memory_map enable
696 gdb_flash_program enable
697
698 source [find target/sam7x256.cfg]
699 @end example
700
701 Here is the command line equivalent of that configuration:
702
703 @example
704 openocd -f interface/signalyzer.cfg \
705 -c "gdb_memory_map enable" \
706 -c "gdb_flash_program enable" \
707 -f target/sam7x256.cfg
708 @end example
709
710 You could wrap such long command lines in shell scripts,
711 each supporting a different development task.
712 One might re-flash the board with a specific firmware version.
713 Another might set up a particular debugging or run-time environment.
714
715 @quotation Important
716 At this writing (October 2009) the command line method has
717 problems with how it treats variables.
718 For example, after @option{-c "set VAR value"}, or doing the
719 same in a script, the variable @var{VAR} will have no value
720 that can be tested in a later script.
721 @end quotation
722
723 Here we will focus on the simpler solution: one user config
724 file, including basic configuration plus any TCL procedures
725 to simplify your work.
726
727 @section User Config Files
728 @cindex config file, user
729 @cindex user config file
730 @cindex config file, overview
731
732 A user configuration file ties together all the parts of a project
733 in one place.
734 One of the following will match your situation best:
735
736 @itemize
737 @item Ideally almost everything comes from configuration files
738 provided by someone else.
739 For example, OpenOCD distributes a @file{scripts} directory
740 (probably in @file{/usr/share/openocd/scripts} on Linux).
741 Board and tool vendors can provide these too, as can individual
742 user sites; the @option{-s} command line option lets you say
743 where to find these files. (@xref{Running}.)
744 The AT91SAM7X256 example above works this way.
745
746 Three main types of non-user configuration file each have their
747 own subdirectory in the @file{scripts} directory:
748
749 @enumerate
750 @item @b{interface} -- one for each kind of JTAG adapter/dongle
751 @item @b{board} -- one for each different board
752 @item @b{target} -- the chips which integrate CPUs and other JTAG TAPs
753 @end enumerate
754
755 Best case: include just two files, and they handle everything else.
756 The first is an interface config file.
757 The second is board-specific, and it sets up the JTAG TAPs and
758 their GDB targets (by deferring to some @file{target.cfg} file),
759 declares all flash memory, and leaves you nothing to do except
760 meet your deadline:
761
762 @example
763 source [find interface/olimex-jtag-tiny.cfg]
764 source [find board/csb337.cfg]
765 @end example
766
767 Boards with a single microcontroller often won't need more
768 than the target config file, as in the AT91SAM7X256 example.
769 That's because there is no external memory (flash, DDR RAM), and
770 the board differences are encapsulated by application code.
771
772 @item Maybe you don't know yet what your board looks like to JTAG.
773 Once you know the @file{interface.cfg} file to use, you may
774 need help from OpenOCD to discover what's on the board.
775 Once you find the TAPs, you can just search for appropriate
776 configuration files ... or write your own, from the bottom up.
777 @xref{Autoprobing}.
778
779 @item You can often reuse some standard config files but
780 need to write a few new ones, probably a @file{board.cfg} file.
781 You will be using commands described later in this User's Guide,
782 and working with the guidelines in the next chapter.
783
784 For example, there may be configuration files for your JTAG adapter
785 and target chip, but you need a new board-specific config file
786 giving access to your particular flash chips.
787 Or you might need to write another target chip configuration file
788 for a new chip built around the Cortex M3 core.
789
790 @quotation Note
791 When you write new configuration files, please submit
792 them for inclusion in the next OpenOCD release.
793 For example, a @file{board/newboard.cfg} file will help the
794 next users of that board, and a @file{target/newcpu.cfg}
795 will help support users of any board using that chip.
796 @end quotation
797
798 @item
799 You may may need to write some C code.
800 It may be as simple as a supporting a new ft2232 or parport
801 based dongle; a bit more involved, like a NAND or NOR flash
802 controller driver; or a big piece of work like supporting
803 a new chip architecture.
804 @end itemize
805
806 Reuse the existing config files when you can.
807 Look first in the @file{scripts/boards} area, then @file{scripts/targets}.
808 You may find a board configuration that's a good example to follow.
809
810 When you write config files, separate the reusable parts
811 (things every user of that interface, chip, or board needs)
812 from ones specific to your environment and debugging approach.
813 @itemize
814
815 @item
816 For example, a @code{gdb-attach} event handler that invokes
817 the @command{reset init} command will interfere with debugging
818 early boot code, which performs some of the same actions
819 that the @code{reset-init} event handler does.
820
821 @item
822 Likewise, the @command{arm9 vector_catch} command (or
823 @cindex vector_catch
824 its siblings @command{xscale vector_catch}
825 and @command{cortex_m3 vector_catch}) can be a timesaver
826 during some debug sessions, but don't make everyone use that either.
827 Keep those kinds of debugging aids in your user config file,
828 along with messaging and tracing setup.
829 (@xref{Software Debug Messages and Tracing}.)
830
831 @item
832 You might need to override some defaults.
833 For example, you might need to move, shrink, or back up the target's
834 work area if your application needs much SRAM.
835
836 @item
837 TCP/IP port configuration is another example of something which
838 is environment-specific, and should only appear in
839 a user config file. @xref{TCP/IP Ports}.
840 @end itemize
841
842 @section Project-Specific Utilities
843
844 A few project-specific utility
845 routines may well speed up your work.
846 Write them, and keep them in your project's user config file.
847
848 For example, if you are making a boot loader work on a
849 board, it's nice to be able to debug the ``after it's
850 loaded to RAM'' parts separately from the finicky early
851 code which sets up the DDR RAM controller and clocks.
852 A script like this one, or a more GDB-aware sibling,
853 may help:
854
855 @example
856 proc ramboot @{ @} @{
857 # Reset, running the target's "reset-init" scripts
858 # to initialize clocks and the DDR RAM controller.
859 # Leave the CPU halted.
860 reset init
861
862 # Load CONFIG_SKIP_LOWLEVEL_INIT version into DDR RAM.
863 load_image u-boot.bin 0x20000000
864
865 # Start running.
866 resume 0x20000000
867 @}
868 @end example
869
870 Then once that code is working you will need to make it
871 boot from NOR flash; a different utility would help.
872 Alternatively, some developers write to flash using GDB.
873 (You might use a similar script if you're working with a flash
874 based microcontroller application instead of a boot loader.)
875
876 @example
877 proc newboot @{ @} @{
878 # Reset, leaving the CPU halted. The "reset-init" event
879 # proc gives faster access to the CPU and to NOR flash;
880 # "reset halt" would be slower.
881 reset init
882
883 # Write standard version of U-Boot into the first two
884 # sectors of NOR flash ... the standard version should
885 # do the same lowlevel init as "reset-init".
886 flash protect 0 0 1 off
887 flash erase_sector 0 0 1
888 flash write_bank 0 u-boot.bin 0x0
889 flash protect 0 0 1 on
890
891 # Reboot from scratch using that new boot loader.
892 reset run
893 @}
894 @end example
895
896 You may need more complicated utility procedures when booting
897 from NAND.
898 That often involves an extra bootloader stage,
899 running from on-chip SRAM to perform DDR RAM setup so it can load
900 the main bootloader code (which won't fit into that SRAM).
901
902 Other helper scripts might be used to write production system images,
903 involving considerably more than just a three stage bootloader.
904
905 @section Target Software Changes
906
907 Sometimes you may want to make some small changes to the software
908 you're developing, to help make JTAG debugging work better.
909 For example, in C or assembly language code you might
910 use @code{#ifdef JTAG_DEBUG} (or its converse) around code
911 handling issues like:
912
913 @itemize @bullet
914
915 @item @b{ARM Semihosting}...
916 @cindex ARM semihosting
917 When linked with a special runtime library provided with many
918 toolchains@footnote{See chapter 8 "Semihosting" in
919 @uref{http://infocenter.arm.com/help/topic/com.arm.doc.dui0203i/DUI0203I_rvct_developer_guide.pdf,
920 ARM DUI 0203I}, the "RealView Compilation Tools Developer Guide".
921 The CodeSourcery EABI toolchain also includes a semihosting library.},
922 your target code can use I/O facilities on the debug host. That library
923 provides a small set of system calls which are handled by OpenOCD.
924 It can let the debugger provide your system console and a file system,
925 helping with early debugging or providing a more capable environment
926 for sometimes-complex tasks like installing system firmware onto
927 NAND or SPI flash.
928
929 @item @b{ARM Wait-For-Interrupt}...
930 Many ARM chips synchronize the JTAG clock using the core clock.
931 Low power states which stop that core clock thus prevent JTAG access.
932 Idle loops in tasking environments often enter those low power states
933 via the @code{WFI} instruction (or its coprocessor equivalent, before ARMv7).
934
935 You may want to @emph{disable that instruction} in source code,
936 or otherwise prevent using that state,
937 to ensure you can get JTAG access at any time.
938 For example, the OpenOCD @command{halt} command may not
939 work for an idle processor otherwise.
940
941 @item @b{Delay after reset}...
942 Not all chips have good support for debugger access
943 right after reset; many LPC2xxx chips have issues here.
944 Similarly, applications that reconfigure pins used for
945 JTAG access as they start will also block debugger access.
946
947 To work with boards like this, @emph{enable a short delay loop}
948 the first thing after reset, before "real" startup activities.
949 For example, one second's delay is usually more than enough
950 time for a JTAG debugger to attach, so that
951 early code execution can be debugged
952 or firmware can be replaced.
953
954 @item @b{Debug Communications Channel (DCC)}...
955 Some processors include mechanisms to send messages over JTAG.
956 Many ARM cores support these, as do some cores from other vendors.
957 (OpenOCD may be able to use this DCC internally, speeding up some
958 operations like writing to memory.)
959
960 Your application may want to deliver various debugging messages
961 over JTAG, by @emph{linking with a small library of code}
962 provided with OpenOCD and using the utilities there to send
963 various kinds of message.
964 @xref{Software Debug Messages and Tracing}.
965
966 @end itemize
967
968 @node Config File Guidelines
969 @chapter Config File Guidelines
970
971 This chapter is aimed at any user who needs to write a config file,
972 including developers and integrators of OpenOCD and any user who
973 needs to get a new board working smoothly.
974 It provides guidelines for creating those files.
975
976 You should find the following directories under @t{$(INSTALLDIR)/scripts},
977 with files including the ones listed here.
978 Use them as-is where you can; or as models for new files.
979 @itemize @bullet
980 @item @file{interface} ...
981 think JTAG Dongle. Files that configure JTAG adapters go here.
982 @example
983 $ ls interface
984 arm-jtag-ew.cfg hitex_str9-comstick.cfg oocdlink.cfg
985 arm-usb-ocd.cfg icebear.cfg openocd-usb.cfg
986 at91rm9200.cfg jlink.cfg parport.cfg
987 axm0432.cfg jtagkey2.cfg parport_dlc5.cfg
988 calao-usb-a9260-c01.cfg jtagkey.cfg rlink.cfg
989 calao-usb-a9260-c02.cfg jtagkey-tiny.cfg sheevaplug.cfg
990 calao-usb-a9260.cfg luminary.cfg signalyzer.cfg
991 chameleon.cfg luminary-icdi.cfg stm32-stick.cfg
992 cortino.cfg luminary-lm3s811.cfg turtelizer2.cfg
993 dummy.cfg olimex-arm-usb-ocd.cfg usbprog.cfg
994 flyswatter.cfg olimex-jtag-tiny.cfg vsllink.cfg
995 $
996 @end example
997 @item @file{board} ...
998 think Circuit Board, PWA, PCB, they go by many names. Board files
999 contain initialization items that are specific to a board.
1000 They reuse target configuration files, since the same
1001 microprocessor chips are used on many boards,
1002 but support for external parts varies widely. For
1003 example, the SDRAM initialization sequence for the board, or the type
1004 of external flash and what address it uses. Any initialization
1005 sequence to enable that external flash or SDRAM should be found in the
1006 board file. Boards may also contain multiple targets: two CPUs; or
1007 a CPU and an FPGA.
1008 @example
1009 $ ls board
1010 arm_evaluator7t.cfg keil_mcb1700.cfg
1011 at91rm9200-dk.cfg keil_mcb2140.cfg
1012 at91sam9g20-ek.cfg linksys_nslu2.cfg
1013 atmel_at91sam7s-ek.cfg logicpd_imx27.cfg
1014 atmel_at91sam9260-ek.cfg mini2440.cfg
1015 atmel_sam3u_ek.cfg olimex_LPC2378STK.cfg
1016 crossbow_tech_imote2.cfg olimex_lpc_h2148.cfg
1017 csb337.cfg olimex_sam7_ex256.cfg
1018 csb732.cfg olimex_sam9_l9260.cfg
1019 digi_connectcore_wi-9c.cfg olimex_stm32_h103.cfg
1020 dm355evm.cfg omap2420_h4.cfg
1021 dm365evm.cfg osk5912.cfg
1022 dm6446evm.cfg pic-p32mx.cfg
1023 eir.cfg propox_mmnet1001.cfg
1024 ek-lm3s1968.cfg pxa255_sst.cfg
1025 ek-lm3s3748.cfg sheevaplug.cfg
1026 ek-lm3s811.cfg stm3210e_eval.cfg
1027 ek-lm3s9b9x.cfg stm32f10x_128k_eval.cfg
1028 hammer.cfg str910-eval.cfg
1029 hitex_lpc2929.cfg telo.cfg
1030 hitex_stm32-performancestick.cfg ti_beagleboard.cfg
1031 hitex_str9-comstick.cfg topas910.cfg
1032 iar_str912_sk.cfg topasa900.cfg
1033 imx27ads.cfg unknown_at91sam9260.cfg
1034 imx27lnst.cfg x300t.cfg
1035 imx31pdk.cfg zy1000.cfg
1036 $
1037 @end example
1038 @item @file{target} ...
1039 think chip. The ``target'' directory represents the JTAG TAPs
1040 on a chip
1041 which OpenOCD should control, not a board. Two common types of targets
1042 are ARM chips and FPGA or CPLD chips.
1043 When a chip has multiple TAPs (maybe it has both ARM and DSP cores),
1044 the target config file defines all of them.
1045 @example
1046 $ ls target
1047 aduc702x.cfg imx27.cfg pxa255.cfg
1048 ar71xx.cfg imx31.cfg pxa270.cfg
1049 at91eb40a.cfg imx35.cfg readme.txt
1050 at91r40008.cfg is5114.cfg sam7se512.cfg
1051 at91rm9200.cfg ixp42x.cfg sam7x256.cfg
1052 at91sam3u1c.cfg lm3s1968.cfg samsung_s3c2410.cfg
1053 at91sam3u1e.cfg lm3s3748.cfg samsung_s3c2440.cfg
1054 at91sam3u2c.cfg lm3s6965.cfg samsung_s3c2450.cfg
1055 at91sam3u2e.cfg lm3s811.cfg samsung_s3c4510.cfg
1056 at91sam3u4c.cfg lm3s9b9x.cfg samsung_s3c6410.cfg
1057 at91sam3u4e.cfg lpc1768.cfg sharp_lh79532.cfg
1058 at91sam3uXX.cfg lpc2103.cfg smdk6410.cfg
1059 at91sam7sx.cfg lpc2124.cfg smp8634.cfg
1060 at91sam9260.cfg lpc2129.cfg stm32.cfg
1061 c100.cfg lpc2148.cfg str710.cfg
1062 c100config.tcl lpc2294.cfg str730.cfg
1063 c100helper.tcl lpc2378.cfg str750.cfg
1064 c100regs.tcl lpc2478.cfg str912.cfg
1065 cs351x.cfg lpc2900.cfg telo.cfg
1066 davinci.cfg mega128.cfg ti_dm355.cfg
1067 dragonite.cfg netx500.cfg ti_dm365.cfg
1068 epc9301.cfg omap2420.cfg ti_dm6446.cfg
1069 feroceon.cfg omap3530.cfg tmpa900.cfg
1070 icepick.cfg omap5912.cfg tmpa910.cfg
1071 imx21.cfg pic32mx.cfg xba_revA3.cfg
1072 $
1073 @end example
1074 @item @emph{more} ... browse for other library files which may be useful.
1075 For example, there are various generic and CPU-specific utilities.
1076 @end itemize
1077
1078 The @file{openocd.cfg} user config
1079 file may override features in any of the above files by
1080 setting variables before sourcing the target file, or by adding
1081 commands specific to their situation.
1082
1083 @section Interface Config Files
1084
1085 The user config file
1086 should be able to source one of these files with a command like this:
1087
1088 @example
1089 source [find interface/FOOBAR.cfg]
1090 @end example
1091
1092 A preconfigured interface file should exist for every interface in use
1093 today, that said, perhaps some interfaces have only been used by the
1094 sole developer who created it.
1095
1096 A separate chapter gives information about how to set these up.
1097 @xref{Interface - Dongle Configuration}.
1098 Read the OpenOCD source code if you have a new kind of hardware interface
1099 and need to provide a driver for it.
1100
1101 @section Board Config Files
1102 @cindex config file, board
1103 @cindex board config file
1104
1105 The user config file
1106 should be able to source one of these files with a command like this:
1107
1108 @example
1109 source [find board/FOOBAR.cfg]
1110 @end example
1111
1112 The point of a board config file is to package everything
1113 about a given board that user config files need to know.
1114 In summary the board files should contain (if present)
1115
1116 @enumerate
1117 @item One or more @command{source [target/...cfg]} statements
1118 @item NOR flash configuration (@pxref{NOR Configuration})
1119 @item NAND flash configuration (@pxref{NAND Configuration})
1120 @item Target @code{reset} handlers for SDRAM and I/O configuration
1121 @item JTAG adapter reset configuration (@pxref{Reset Configuration})
1122 @item All things that are not ``inside a chip''
1123 @end enumerate
1124
1125 Generic things inside target chips belong in target config files,
1126 not board config files. So for example a @code{reset-init} event
1127 handler should know board-specific oscillator and PLL parameters,
1128 which it passes to target-specific utility code.
1129
1130 The most complex task of a board config file is creating such a
1131 @code{reset-init} event handler.
1132 Define those handlers last, after you verify the rest of the board
1133 configuration works.
1134
1135 @subsection Communication Between Config files
1136
1137 In addition to target-specific utility code, another way that
1138 board and target config files communicate is by following a
1139 convention on how to use certain variables.
1140
1141 The full Tcl/Tk language supports ``namespaces'', but JIM-Tcl does not.
1142 Thus the rule we follow in OpenOCD is this: Variables that begin with
1143 a leading underscore are temporary in nature, and can be modified and
1144 used at will within a target configuration file.
1145
1146 Complex board config files can do the things like this,
1147 for a board with three chips:
1148
1149 @example
1150 # Chip #1: PXA270 for network side, big endian
1151 set CHIPNAME network
1152 set ENDIAN big
1153 source [find target/pxa270.cfg]
1154 # on return: _TARGETNAME = network.cpu
1155 # other commands can refer to the "network.cpu" target.
1156 $_TARGETNAME configure .... events for this CPU..
1157
1158 # Chip #2: PXA270 for video side, little endian
1159 set CHIPNAME video
1160 set ENDIAN little
1161 source [find target/pxa270.cfg]
1162 # on return: _TARGETNAME = video.cpu
1163 # other commands can refer to the "video.cpu" target.
1164 $_TARGETNAME configure .... events for this CPU..
1165
1166 # Chip #3: Xilinx FPGA for glue logic
1167 set CHIPNAME xilinx
1168 unset ENDIAN
1169 source [find target/spartan3.cfg]
1170 @end example
1171
1172 That example is oversimplified because it doesn't show any flash memory,
1173 or the @code{reset-init} event handlers to initialize external DRAM
1174 or (assuming it needs it) load a configuration into the FPGA.
1175 Such features are usually needed for low-level work with many boards,
1176 where ``low level'' implies that the board initialization software may
1177 not be working. (That's a common reason to need JTAG tools. Another
1178 is to enable working with microcontroller-based systems, which often
1179 have no debugging support except a JTAG connector.)
1180
1181 Target config files may also export utility functions to board and user
1182 config files. Such functions should use name prefixes, to help avoid
1183 naming collisions.
1184
1185 Board files could also accept input variables from user config files.
1186 For example, there might be a @code{J4_JUMPER} setting used to identify
1187 what kind of flash memory a development board is using, or how to set
1188 up other clocks and peripherals.
1189
1190 @subsection Variable Naming Convention
1191 @cindex variable names
1192
1193 Most boards have only one instance of a chip.
1194 However, it should be easy to create a board with more than
1195 one such chip (as shown above).
1196 Accordingly, we encourage these conventions for naming
1197 variables associated with different @file{target.cfg} files,
1198 to promote consistency and
1199 so that board files can override target defaults.
1200
1201 Inputs to target config files include:
1202
1203 @itemize @bullet
1204 @item @code{CHIPNAME} ...
1205 This gives a name to the overall chip, and is used as part of
1206 tap identifier dotted names.
1207 While the default is normally provided by the chip manufacturer,
1208 board files may need to distinguish between instances of a chip.
1209 @item @code{ENDIAN} ...
1210 By default @option{little} - although chips may hard-wire @option{big}.
1211 Chips that can't change endianness don't need to use this variable.
1212 @item @code{CPUTAPID} ...
1213 When OpenOCD examines the JTAG chain, it can be told verify the
1214 chips against the JTAG IDCODE register.
1215 The target file will hold one or more defaults, but sometimes the
1216 chip in a board will use a different ID (perhaps a newer revision).
1217 @end itemize
1218
1219 Outputs from target config files include:
1220
1221 @itemize @bullet
1222 @item @code{_TARGETNAME} ...
1223 By convention, this variable is created by the target configuration
1224 script. The board configuration file may make use of this variable to
1225 configure things like a ``reset init'' script, or other things
1226 specific to that board and that target.
1227 If the chip has 2 targets, the names are @code{_TARGETNAME0},
1228 @code{_TARGETNAME1}, ... etc.
1229 @end itemize
1230
1231 @subsection The reset-init Event Handler
1232 @cindex event, reset-init
1233 @cindex reset-init handler
1234
1235 Board config files run in the OpenOCD configuration stage;
1236 they can't use TAPs or targets, since they haven't been
1237 fully set up yet.
1238 This means you can't write memory or access chip registers;
1239 you can't even verify that a flash chip is present.
1240 That's done later in event handlers, of which the target @code{reset-init}
1241 handler is one of the most important.
1242
1243 Except on microcontrollers, the basic job of @code{reset-init} event
1244 handlers is setting up flash and DRAM, as normally handled by boot loaders.
1245 Microcontrollers rarely use boot loaders; they run right out of their
1246 on-chip flash and SRAM memory. But they may want to use one of these
1247 handlers too, if just for developer convenience.
1248
1249 @quotation Note
1250 Because this is so very board-specific, and chip-specific, no examples
1251 are included here.
1252 Instead, look at the board config files distributed with OpenOCD.
1253 If you have a boot loader, its source code will help; so will
1254 configuration files for other JTAG tools
1255 (@pxref{Translating Configuration Files}).
1256 @end quotation
1257
1258 Some of this code could probably be shared between different boards.
1259 For example, setting up a DRAM controller often doesn't differ by
1260 much except the bus width (16 bits or 32?) and memory timings, so a
1261 reusable TCL procedure loaded by the @file{target.cfg} file might take
1262 those as parameters.
1263 Similarly with oscillator, PLL, and clock setup;
1264 and disabling the watchdog.
1265 Structure the code cleanly, and provide comments to help
1266 the next developer doing such work.
1267 (@emph{You might be that next person} trying to reuse init code!)
1268
1269 The last thing normally done in a @code{reset-init} handler is probing
1270 whatever flash memory was configured. For most chips that needs to be
1271 done while the associated target is halted, either because JTAG memory
1272 access uses the CPU or to prevent conflicting CPU access.
1273
1274 @subsection JTAG Clock Rate
1275
1276 Before your @code{reset-init} handler has set up
1277 the PLLs and clocking, you may need to run with
1278 a low JTAG clock rate.
1279 @xref{JTAG Speed}.
1280 Then you'd increase that rate after your handler has
1281 made it possible to use the faster JTAG clock.
1282 When the initial low speed is board-specific, for example
1283 because it depends on a board-specific oscillator speed, then
1284 you should probably set it up in the board config file;
1285 if it's target-specific, it belongs in the target config file.
1286
1287 For most ARM-based processors the fastest JTAG clock@footnote{A FAQ
1288 @uref{http://www.arm.com/support/faqdev/4170.html} gives details.}
1289 is one sixth of the CPU clock; or one eighth for ARM11 cores.
1290 Consult chip documentation to determine the peak JTAG clock rate,
1291 which might be less than that.
1292
1293 @quotation Warning
1294 On most ARMs, JTAG clock detection is coupled to the core clock, so
1295 software using a @option{wait for interrupt} operation blocks JTAG access.
1296 Adaptive clocking provides a partial workaround, but a more complete
1297 solution just avoids using that instruction with JTAG debuggers.
1298 @end quotation
1299
1300 If the board supports adaptive clocking, use the @command{jtag_rclk}
1301 command, in case your board is used with JTAG adapter which
1302 also supports it. Otherwise use @command{jtag_khz}.
1303 Set the slow rate at the beginning of the reset sequence,
1304 and the faster rate as soon as the clocks are at full speed.
1305
1306 @section Target Config Files
1307 @cindex config file, target
1308 @cindex target config file
1309
1310 Board config files communicate with target config files using
1311 naming conventions as described above, and may source one or
1312 more target config files like this:
1313
1314 @example
1315 source [find target/FOOBAR.cfg]
1316 @end example
1317
1318 The point of a target config file is to package everything
1319 about a given chip that board config files need to know.
1320 In summary the target files should contain
1321
1322 @enumerate
1323 @item Set defaults
1324 @item Add TAPs to the scan chain
1325 @item Add CPU targets (includes GDB support)
1326 @item CPU/Chip/CPU-Core specific features
1327 @item On-Chip flash
1328 @end enumerate
1329
1330 As a rule of thumb, a target file sets up only one chip.
1331 For a microcontroller, that will often include a single TAP,
1332 which is a CPU needing a GDB target, and its on-chip flash.
1333
1334 More complex chips may include multiple TAPs, and the target
1335 config file may need to define them all before OpenOCD
1336 can talk to the chip.
1337 For example, some phone chips have JTAG scan chains that include
1338 an ARM core for operating system use, a DSP,
1339 another ARM core embedded in an image processing engine,
1340 and other processing engines.
1341
1342 @subsection Default Value Boiler Plate Code
1343
1344 All target configuration files should start with code like this,
1345 letting board config files express environment-specific
1346 differences in how things should be set up.
1347
1348 @example
1349 # Boards may override chip names, perhaps based on role,
1350 # but the default should match what the vendor uses
1351 if @{ [info exists CHIPNAME] @} @{
1352 set _CHIPNAME $CHIPNAME
1353 @} else @{
1354 set _CHIPNAME sam7x256
1355 @}
1356
1357 # ONLY use ENDIAN with targets that can change it.
1358 if @{ [info exists ENDIAN] @} @{
1359 set _ENDIAN $ENDIAN
1360 @} else @{
1361 set _ENDIAN little
1362 @}
1363
1364 # TAP identifiers may change as chips mature, for example with
1365 # new revision fields (the "3" here). Pick a good default; you
1366 # can pass several such identifiers to the "jtag newtap" command.
1367 if @{ [info exists CPUTAPID ] @} @{
1368 set _CPUTAPID $CPUTAPID
1369 @} else @{
1370 set _CPUTAPID 0x3f0f0f0f
1371 @}
1372 @end example
1373 @c but 0x3f0f0f0f is for an str73x part ...
1374
1375 @emph{Remember:} Board config files may include multiple target
1376 config files, or the same target file multiple times
1377 (changing at least @code{CHIPNAME}).
1378
1379 Likewise, the target configuration file should define
1380 @code{_TARGETNAME} (or @code{_TARGETNAME0} etc) and
1381 use it later on when defining debug targets:
1382
1383 @example
1384 set _TARGETNAME $_CHIPNAME.cpu
1385 target create $_TARGETNAME arm7tdmi -chain-position $_TARGETNAME
1386 @end example
1387
1388 @subsection Adding TAPs to the Scan Chain
1389 After the ``defaults'' are set up,
1390 add the TAPs on each chip to the JTAG scan chain.
1391 @xref{TAP Declaration}, and the naming convention
1392 for taps.
1393
1394 In the simplest case the chip has only one TAP,
1395 probably for a CPU or FPGA.
1396 The config file for the Atmel AT91SAM7X256
1397 looks (in part) like this:
1398
1399 @example
1400 jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
1401 @end example
1402
1403 A board with two such at91sam7 chips would be able
1404 to source such a config file twice, with different
1405 values for @code{CHIPNAME}, so
1406 it adds a different TAP each time.
1407
1408 If there are nonzero @option{-expected-id} values,
1409 OpenOCD attempts to verify the actual tap id against those values.
1410 It will issue error messages if there is mismatch, which
1411 can help to pinpoint problems in OpenOCD configurations.
1412
1413 @example
1414 JTAG tap: sam7x256.cpu tap/device found: 0x3f0f0f0f
1415 (Manufacturer: 0x787, Part: 0xf0f0, Version: 0x3)
1416 ERROR: Tap: sam7x256.cpu - Expected id: 0x12345678, Got: 0x3f0f0f0f
1417 ERROR: expected: mfg: 0x33c, part: 0x2345, ver: 0x1
1418 ERROR: got: mfg: 0x787, part: 0xf0f0, ver: 0x3
1419 @end example
1420
1421 There are more complex examples too, with chips that have
1422 multiple TAPs. Ones worth looking at include:
1423
1424 @itemize
1425 @item @file{target/omap3530.cfg} -- with disabled ARM and DSP,
1426 plus a JRC to enable them
1427 @item @file{target/str912.cfg} -- with flash, CPU, and boundary scan
1428 @item @file{target/ti_dm355.cfg} -- with ETM, ARM, and JRC (this JRC
1429 is not currently used)
1430 @end itemize
1431
1432 @subsection Add CPU targets
1433
1434 After adding a TAP for a CPU, you should set it up so that
1435 GDB and other commands can use it.
1436 @xref{CPU Configuration}.
1437 For the at91sam7 example above, the command can look like this;
1438 note that @code{$_ENDIAN} is not needed, since OpenOCD defaults
1439 to little endian, and this chip doesn't support changing that.
1440
1441 @example
1442 set _TARGETNAME $_CHIPNAME.cpu
1443 target create $_TARGETNAME arm7tdmi -chain-position $_TARGETNAME
1444 @end example
1445
1446 Work areas are small RAM areas associated with CPU targets.
1447 They are used by OpenOCD to speed up downloads,
1448 and to download small snippets of code to program flash chips.
1449 If the chip includes a form of ``on-chip-ram'' - and many do - define
1450 a work area if you can.
1451 Again using the at91sam7 as an example, this can look like:
1452
1453 @example
1454 $_TARGETNAME configure -work-area-phys 0x00200000 \
1455 -work-area-size 0x4000 -work-area-backup 0
1456 @end example
1457
1458 @subsection Chip Reset Setup
1459
1460 As a rule, you should put the @command{reset_config} command
1461 into the board file. Most things you think you know about a
1462 chip can be tweaked by the board.
1463
1464 Some chips have specific ways the TRST and SRST signals are
1465 managed. In the unusual case that these are @emph{chip specific}
1466 and can never be changed by board wiring, they could go here.
1467 For example, some chips can't support JTAG debugging without
1468 both signals.
1469
1470 Provide a @code{reset-assert} event handler if you can.
1471 Such a handler uses JTAG operations to reset the target,
1472 letting this target config be used in systems which don't
1473 provide the optional SRST signal, or on systems where you
1474 don't want to reset all targets at once.
1475 Such a handler might write to chip registers to force a reset,
1476 use a JRC to do that (preferable -- the target may be wedged!),
1477 or force a watchdog timer to trigger.
1478 (For Cortex-M3 targets, this is not necessary. The target
1479 driver knows how to use trigger an NVIC reset when SRST is
1480 not available.)
1481
1482 Some chips need special attention during reset handling if
1483 they're going to be used with JTAG.
1484 An example might be needing to send some commands right
1485 after the target's TAP has been reset, providing a
1486 @code{reset-deassert-post} event handler that writes a chip
1487 register to report that JTAG debugging is being done.
1488 Another would be reconfiguring the watchdog so that it stops
1489 counting while the core is halted in the debugger.
1490
1491 JTAG clocking constraints often change during reset, and in
1492 some cases target config files (rather than board config files)
1493 are the right places to handle some of those issues.
1494 For example, immediately after reset most chips run using a
1495 slower clock than they will use later.
1496 That means that after reset (and potentially, as OpenOCD
1497 first starts up) they must use a slower JTAG clock rate
1498 than they will use later.
1499 @xref{JTAG Speed}.
1500
1501 @quotation Important
1502 When you are debugging code that runs right after chip
1503 reset, getting these issues right is critical.
1504 In particular, if you see intermittent failures when
1505 OpenOCD verifies the scan chain after reset,
1506 look at how you are setting up JTAG clocking.
1507 @end quotation
1508
1509 @subsection ARM Core Specific Hacks
1510
1511 If the chip has a DCC, enable it. If the chip is an ARM9 with some
1512 special high speed download features - enable it.
1513
1514 If present, the MMU, the MPU and the CACHE should be disabled.
1515
1516 Some ARM cores are equipped with trace support, which permits
1517 examination of the instruction and data bus activity. Trace
1518 activity is controlled through an ``Embedded Trace Module'' (ETM)
1519 on one of the core's scan chains. The ETM emits voluminous data
1520 through a ``trace port''. (@xref{ARM Hardware Tracing}.)
1521 If you are using an external trace port,
1522 configure it in your board config file.
1523 If you are using an on-chip ``Embedded Trace Buffer'' (ETB),
1524 configure it in your target config file.
1525
1526 @example
1527 etm config $_TARGETNAME 16 normal full etb
1528 etb config $_TARGETNAME $_CHIPNAME.etb
1529 @end example
1530
1531 @subsection Internal Flash Configuration
1532
1533 This applies @b{ONLY TO MICROCONTROLLERS} that have flash built in.
1534
1535 @b{Never ever} in the ``target configuration file'' define any type of
1536 flash that is external to the chip. (For example a BOOT flash on
1537 Chip Select 0.) Such flash information goes in a board file - not
1538 the TARGET (chip) file.
1539
1540 Examples:
1541 @itemize @bullet
1542 @item at91sam7x256 - has 256K flash YES enable it.
1543 @item str912 - has flash internal YES enable it.
1544 @item imx27 - uses boot flash on CS0 - it goes in the board file.
1545 @item pxa270 - again - CS0 flash - it goes in the board file.
1546 @end itemize
1547
1548 @anchor{Translating Configuration Files}
1549 @section Translating Configuration Files
1550 @cindex translation
1551 If you have a configuration file for another hardware debugger
1552 or toolset (Abatron, BDI2000, BDI3000, CCS,
1553 Lauterbach, Segger, Macraigor, etc.), translating
1554 it into OpenOCD syntax is often quite straightforward. The most tricky
1555 part of creating a configuration script is oftentimes the reset init
1556 sequence where e.g. PLLs, DRAM and the like is set up.
1557
1558 One trick that you can use when translating is to write small
1559 Tcl procedures to translate the syntax into OpenOCD syntax. This
1560 can avoid manual translation errors and make it easier to
1561 convert other scripts later on.
1562
1563 Example of transforming quirky arguments to a simple search and
1564 replace job:
1565
1566 @example
1567 # Lauterbach syntax(?)
1568 #
1569 # Data.Set c15:0x042f %long 0x40000015
1570 #
1571 # OpenOCD syntax when using procedure below.
1572 #
1573 # setc15 0x01 0x00050078
1574
1575 proc setc15 @{regs value@} @{
1576 global TARGETNAME
1577
1578 echo [format "set p15 0x%04x, 0x%08x" $regs $value]
1579
1580 arm mcr 15 [expr ($regs>>12)&0x7] \
1581 [expr ($regs>>0)&0xf] [expr ($regs>>4)&0xf] \
1582 [expr ($regs>>8)&0x7] $value
1583 @}
1584 @end example
1585
1586
1587
1588 @node Daemon Configuration
1589 @chapter Daemon Configuration
1590 @cindex initialization
1591 The commands here are commonly found in the openocd.cfg file and are
1592 used to specify what TCP/IP ports are used, and how GDB should be
1593 supported.
1594
1595 @anchor{Configuration Stage}
1596 @section Configuration Stage
1597 @cindex configuration stage
1598 @cindex config command
1599
1600 When the OpenOCD server process starts up, it enters a
1601 @emph{configuration stage} which is the only time that
1602 certain commands, @emph{configuration commands}, may be issued.
1603 In this manual, the definition of a configuration command is
1604 presented as a @emph{Config Command}, not as a @emph{Command}
1605 which may be issued interactively.
1606
1607 Those configuration commands include declaration of TAPs,
1608 flash banks,
1609 the interface used for JTAG communication,
1610 and other basic setup.
1611 The server must leave the configuration stage before it
1612 may access or activate TAPs.
1613 After it leaves this stage, configuration commands may no
1614 longer be issued.
1615
1616 @section Entering the Run Stage
1617
1618 The first thing OpenOCD does after leaving the configuration
1619 stage is to verify that it can talk to the scan chain
1620 (list of TAPs) which has been configured.
1621 It will warn if it doesn't find TAPs it expects to find,
1622 or finds TAPs that aren't supposed to be there.
1623 You should see no errors at this point.
1624 If you see errors, resolve them by correcting the
1625 commands you used to configure the server.
1626 Common errors include using an initial JTAG speed that's too
1627 fast, and not providing the right IDCODE values for the TAPs
1628 on the scan chain.
1629
1630 Once OpenOCD has entered the run stage, a number of commands
1631 become available.
1632 A number of these relate to the debug targets you may have declared.
1633 For example, the @command{mww} command will not be available until
1634 a target has been successfuly instantiated.
1635 If you want to use those commands, you may need to force
1636 entry to the run stage.
1637
1638 @deffn {Config Command} init
1639 This command terminates the configuration stage and
1640 enters the run stage. This helps when you need to have
1641 the startup scripts manage tasks such as resetting the target,
1642 programming flash, etc. To reset the CPU upon startup, add "init" and
1643 "reset" at the end of the config script or at the end of the OpenOCD
1644 command line using the @option{-c} command line switch.
1645
1646 If this command does not appear in any startup/configuration file
1647 OpenOCD executes the command for you after processing all
1648 configuration files and/or command line options.
1649
1650 @b{NOTE:} This command normally occurs at or near the end of your
1651 openocd.cfg file to force OpenOCD to ``initialize'' and make the
1652 targets ready. For example: If your openocd.cfg file needs to
1653 read/write memory on your target, @command{init} must occur before
1654 the memory read/write commands. This includes @command{nand probe}.
1655 @end deffn
1656
1657 @deffn {Overridable Procedure} jtag_init
1658 This is invoked at server startup to verify that it can talk
1659 to the scan chain (list of TAPs) which has been configured.
1660
1661 The default implementation first tries @command{jtag arp_init},
1662 which uses only a lightweight JTAG reset before examining the
1663 scan chain.
1664 If that fails, it tries again, using a harder reset
1665 from the overridable procedure @command{init_reset}.
1666
1667 Implementations must have verified the JTAG scan chain before
1668 they return.
1669 This is done by calling @command{jtag arp_init}
1670 (or @command{jtag arp_init-reset}).
1671 @end deffn
1672
1673 @anchor{TCP/IP Ports}
1674 @section TCP/IP Ports
1675 @cindex TCP port
1676 @cindex server
1677 @cindex port
1678 @cindex security
1679 The OpenOCD server accepts remote commands in several syntaxes.
1680 Each syntax uses a different TCP/IP port, which you may specify
1681 only during configuration (before those ports are opened).
1682
1683 For reasons including security, you may wish to prevent remote
1684 access using one or more of these ports.
1685 In such cases, just specify the relevant port number as zero.
1686 If you disable all access through TCP/IP, you will need to
1687 use the command line @option{-pipe} option.
1688
1689 @deffn {Command} gdb_port (number)
1690 @cindex GDB server
1691 Specify or query the first port used for incoming GDB connections.
1692 The GDB port for the
1693 first target will be gdb_port, the second target will listen on gdb_port + 1, and so on.
1694 When not specified during the configuration stage,
1695 the port @var{number} defaults to 3333.
1696 When specified as zero, this port is not activated.
1697 @end deffn
1698
1699 @deffn {Command} tcl_port (number)
1700 Specify or query the port used for a simplified RPC
1701 connection that can be used by clients to issue TCL commands and get the
1702 output from the Tcl engine.
1703 Intended as a machine interface.
1704 When not specified during the configuration stage,
1705 the port @var{number} defaults to 6666.
1706 When specified as zero, this port is not activated.
1707 @end deffn
1708
1709 @deffn {Command} telnet_port (number)
1710 Specify or query the
1711 port on which to listen for incoming telnet connections.
1712 This port is intended for interaction with one human through TCL commands.
1713 When not specified during the configuration stage,
1714 the port @var{number} defaults to 4444.
1715 When specified as zero, this port is not activated.
1716 @end deffn
1717
1718 @anchor{GDB Configuration}
1719 @section GDB Configuration
1720 @cindex GDB
1721 @cindex GDB configuration
1722 You can reconfigure some GDB behaviors if needed.
1723 The ones listed here are static and global.
1724 @xref{Target Configuration}, about configuring individual targets.
1725 @xref{Target Events}, about configuring target-specific event handling.
1726
1727 @anchor{gdb_breakpoint_override}
1728 @deffn {Command} gdb_breakpoint_override [@option{hard}|@option{soft}|@option{disable}]
1729 Force breakpoint type for gdb @command{break} commands.
1730 This option supports GDB GUIs which don't
1731 distinguish hard versus soft breakpoints, if the default OpenOCD and
1732 GDB behaviour is not sufficient. GDB normally uses hardware
1733 breakpoints if the memory map has been set up for flash regions.
1734 @end deffn
1735
1736 @anchor{gdb_flash_program}
1737 @deffn {Config Command} gdb_flash_program (@option{enable}|@option{disable})
1738 Set to @option{enable} to cause OpenOCD to program the flash memory when a
1739 vFlash packet is received.
1740 The default behaviour is @option{enable}.
1741 @end deffn
1742
1743 @deffn {Config Command} gdb_memory_map (@option{enable}|@option{disable})
1744 Set to @option{enable} to cause OpenOCD to send the memory configuration to GDB when
1745 requested. GDB will then know when to set hardware breakpoints, and program flash
1746 using the GDB load command. @command{gdb_flash_program enable} must also be enabled
1747 for flash programming to work.
1748 Default behaviour is @option{enable}.
1749 @xref{gdb_flash_program}.
1750 @end deffn
1751
1752 @deffn {Config Command} gdb_report_data_abort (@option{enable}|@option{disable})
1753 Specifies whether data aborts cause an error to be reported
1754 by GDB memory read packets.
1755 The default behaviour is @option{disable};
1756 use @option{enable} see these errors reported.
1757 @end deffn
1758
1759 @anchor{Event Polling}
1760 @section Event Polling
1761
1762 Hardware debuggers are parts of asynchronous systems,
1763 where significant events can happen at any time.
1764 The OpenOCD server needs to detect some of these events,
1765 so it can report them to through TCL command line
1766 or to GDB.
1767
1768 Examples of such events include:
1769
1770 @itemize
1771 @item One of the targets can stop running ... maybe it triggers
1772 a code breakpoint or data watchpoint, or halts itself.
1773 @item Messages may be sent over ``debug message'' channels ... many
1774 targets support such messages sent over JTAG,
1775 for receipt by the person debugging or tools.
1776 @item Loss of power ... some adapters can detect these events.
1777 @item Resets not issued through JTAG ... such reset sources
1778 can include button presses or other system hardware, sometimes
1779 including the target itself (perhaps through a watchdog).
1780 @item Debug instrumentation sometimes supports event triggering
1781 such as ``trace buffer full'' (so it can quickly be emptied)
1782 or other signals (to correlate with code behavior).
1783 @end itemize
1784
1785 None of those events are signaled through standard JTAG signals.
1786 However, most conventions for JTAG connectors include voltage
1787 level and system reset (SRST) signal detection.
1788 Some connectors also include instrumentation signals, which
1789 can imply events when those signals are inputs.
1790
1791 In general, OpenOCD needs to periodically check for those events,
1792 either by looking at the status of signals on the JTAG connector
1793 or by sending synchronous ``tell me your status'' JTAG requests
1794 to the various active targets.
1795 There is a command to manage and monitor that polling,
1796 which is normally done in the background.
1797
1798 @deffn Command poll [@option{on}|@option{off}]
1799 Poll the current target for its current state.
1800 (Also, @pxref{target curstate}.)
1801 If that target is in debug mode, architecture
1802 specific information about the current state is printed.
1803 An optional parameter
1804 allows background polling to be enabled and disabled.
1805
1806 You could use this from the TCL command shell, or
1807 from GDB using @command{monitor poll} command.
1808 Leave background polling enabled while you're using GDB.
1809 @example
1810 > poll
1811 background polling: on
1812 target state: halted
1813 target halted in ARM state due to debug-request, \
1814 current mode: Supervisor
1815 cpsr: 0x800000d3 pc: 0x11081bfc
1816 MMU: disabled, D-Cache: disabled, I-Cache: enabled
1817 >
1818 @end example
1819 @end deffn
1820
1821 @node Interface - Dongle Configuration
1822 @chapter Interface - Dongle Configuration
1823 @cindex config file, interface
1824 @cindex interface config file
1825
1826 JTAG Adapters/Interfaces/Dongles are normally configured
1827 through commands in an interface configuration
1828 file which is sourced by your @file{openocd.cfg} file, or
1829 through a command line @option{-f interface/....cfg} option.
1830
1831 @example
1832 source [find interface/olimex-jtag-tiny.cfg]
1833 @end example
1834
1835 These commands tell
1836 OpenOCD what type of JTAG adapter you have, and how to talk to it.
1837 A few cases are so simple that you only need to say what driver to use:
1838
1839 @example
1840 # jlink interface
1841 interface jlink
1842 @end example
1843
1844 Most adapters need a bit more configuration than that.
1845
1846
1847 @section Interface Configuration
1848
1849 The interface command tells OpenOCD what type of JTAG dongle you are
1850 using. Depending on the type of dongle, you may need to have one or
1851 more additional commands.
1852
1853 @deffn {Config Command} {interface} name
1854 Use the interface driver @var{name} to connect to the
1855 target.
1856 @end deffn
1857
1858 @deffn Command {interface_list}
1859 List the interface drivers that have been built into
1860 the running copy of OpenOCD.
1861 @end deffn
1862
1863 @deffn Command {jtag interface}
1864 Returns the name of the interface driver being used.
1865 @end deffn
1866
1867 @section Interface Drivers
1868
1869 Each of the interface drivers listed here must be explicitly
1870 enabled when OpenOCD is configured, in order to be made
1871 available at run time.
1872
1873 @deffn {Interface Driver} {amt_jtagaccel}
1874 Amontec Chameleon in its JTAG Accelerator configuration,
1875 connected to a PC's EPP mode parallel port.
1876 This defines some driver-specific commands:
1877
1878 @deffn {Config Command} {parport_port} number
1879 Specifies either the address of the I/O port (default: 0x378 for LPT1) or
1880 the number of the @file{/dev/parport} device.
1881 @end deffn
1882
1883 @deffn {Config Command} rtck [@option{enable}|@option{disable}]
1884 Displays status of RTCK option.
1885 Optionally sets that option first.
1886 @end deffn
1887 @end deffn
1888
1889 @deffn {Interface Driver} {arm-jtag-ew}
1890 Olimex ARM-JTAG-EW USB adapter
1891 This has one driver-specific command:
1892
1893 @deffn Command {armjtagew_info}
1894 Logs some status
1895 @end deffn
1896 @end deffn
1897
1898 @deffn {Interface Driver} {at91rm9200}
1899 Supports bitbanged JTAG from the local system,
1900 presuming that system is an Atmel AT91rm9200
1901 and a specific set of GPIOs is used.
1902 @c command: at91rm9200_device NAME
1903 @c chooses among list of bit configs ... only one option
1904 @end deffn
1905
1906 @deffn {Interface Driver} {dummy}
1907 A dummy software-only driver for debugging.
1908 @end deffn
1909
1910 @deffn {Interface Driver} {ep93xx}
1911 Cirrus Logic EP93xx based single-board computer bit-banging (in development)
1912 @end deffn
1913
1914 @deffn {Interface Driver} {ft2232}
1915 FTDI FT2232 (USB) based devices over one of the userspace libraries.
1916 These interfaces have several commands, used to configure the driver
1917 before initializing the JTAG scan chain:
1918
1919 @deffn {Config Command} {ft2232_device_desc} description
1920 Provides the USB device description (the @emph{iProduct string})
1921 of the FTDI FT2232 device. If not
1922 specified, the FTDI default value is used. This setting is only valid
1923 if compiled with FTD2XX support.
1924 @end deffn
1925
1926 @deffn {Config Command} {ft2232_serial} serial-number
1927 Specifies the @var{serial-number} of the FTDI FT2232 device to use,
1928 in case the vendor provides unique IDs and more than one FT2232 device
1929 is connected to the host.
1930 If not specified, serial numbers are not considered.
1931 (Note that USB serial numbers can be arbitrary Unicode strings,
1932 and are not restricted to containing only decimal digits.)
1933 @end deffn
1934
1935 @deffn {Config Command} {ft2232_layout} name
1936 Each vendor's FT2232 device can use different GPIO signals
1937 to control output-enables, reset signals, and LEDs.
1938 Currently valid layout @var{name} values include:
1939 @itemize @minus
1940 @item @b{axm0432_jtag} Axiom AXM-0432
1941 @item @b{comstick} Hitex STR9 comstick
1942 @item @b{cortino} Hitex Cortino JTAG interface
1943 @item @b{evb_lm3s811} Luminary Micro EVB_LM3S811 as a JTAG interface,
1944 either for the local Cortex-M3 (SRST only)
1945 or in a passthrough mode (neither SRST nor TRST)
1946 @item @b{luminary_icdi} Luminary In-Circuit Debug Interface (ICDI) Board
1947 @item @b{flyswatter} Tin Can Tools Flyswatter
1948 @item @b{icebear} ICEbear JTAG adapter from Section 5
1949 @item @b{jtagkey} Amontec JTAGkey and JTAGkey-Tiny (and compatibles)
1950 @item @b{jtagkey2} Amontec JTAGkey2 (and compatibles)
1951 @item @b{m5960} American Microsystems M5960
1952 @item @b{olimex-jtag} Olimex ARM-USB-OCD and ARM-USB-Tiny
1953 @item @b{oocdlink} OOCDLink
1954 @c oocdlink ~= jtagkey_prototype_v1
1955 @item @b{sheevaplug} Marvell Sheevaplug development kit
1956 @item @b{signalyzer} Xverve Signalyzer
1957 @item @b{stm32stick} Hitex STM32 Performance Stick
1958 @item @b{turtelizer2} egnite Software turtelizer2
1959 @item @b{usbjtag} "USBJTAG-1" layout described in the OpenOCD diploma thesis
1960 @end itemize
1961 @end deffn
1962
1963 @deffn {Config Command} {ft2232_vid_pid} [vid pid]+
1964 The vendor ID and product ID of the FTDI FT2232 device. If not specified, the FTDI
1965 default values are used.
1966 Currently, up to eight [@var{vid}, @var{pid}] pairs may be given, e.g.
1967 @example
1968 ft2232_vid_pid 0x0403 0xcff8 0x15ba 0x0003
1969 @end example
1970 @end deffn
1971
1972 @deffn {Config Command} {ft2232_latency} ms
1973 On some systems using FT2232 based JTAG interfaces the FT_Read function call in
1974 ft2232_read() fails to return the expected number of bytes. This can be caused by
1975 USB communication delays and has proved hard to reproduce and debug. Setting the
1976 FT2232 latency timer to a larger value increases delays for short USB packets but it
1977 also reduces the risk of timeouts before receiving the expected number of bytes.
1978 The OpenOCD default value is 2 and for some systems a value of 10 has proved useful.
1979 @end deffn
1980
1981 For example, the interface config file for a
1982 Turtelizer JTAG Adapter looks something like this:
1983
1984 @example
1985 interface ft2232
1986 ft2232_device_desc "Turtelizer JTAG/RS232 Adapter"
1987 ft2232_layout turtelizer2
1988 ft2232_vid_pid 0x0403 0xbdc8
1989 @end example
1990 @end deffn
1991
1992 @deffn {Interface Driver} {gw16012}
1993 Gateworks GW16012 JTAG programmer.
1994 This has one driver-specific command:
1995
1996 @deffn {Config Command} {parport_port} number
1997 Specifies either the address of the I/O port (default: 0x378 for LPT1) or
1998 the number of the @file{/dev/parport} device.
1999 @end deffn
2000 @end deffn
2001
2002 @deffn {Interface Driver} {jlink}
2003 Segger jlink USB adapter
2004 @c command: jlink_info
2005 @c dumps status
2006 @c command: jlink_hw_jtag (2|3)
2007 @c sets version 2 or 3
2008 @end deffn
2009
2010 @deffn {Interface Driver} {parport}
2011 Supports PC parallel port bit-banging cables:
2012 Wigglers, PLD download cable, and more.
2013 These interfaces have several commands, used to configure the driver
2014 before initializing the JTAG scan chain:
2015
2016 @deffn {Config Command} {parport_cable} name
2017 The layout of the parallel port cable used to connect to the target.
2018 Currently valid cable @var{name} values include:
2019
2020 @itemize @minus
2021 @item @b{altium} Altium Universal JTAG cable.
2022 @item @b{arm-jtag} Same as original wiggler except SRST and
2023 TRST connections reversed and TRST is also inverted.
2024 @item @b{chameleon} The Amontec Chameleon's CPLD when operated
2025 in configuration mode. This is only used to
2026 program the Chameleon itself, not a connected target.
2027 @item @b{dlc5} The Xilinx Parallel cable III.
2028 @item @b{flashlink} The ST Parallel cable.
2029 @item @b{lattice} Lattice ispDOWNLOAD Cable
2030 @item @b{old_amt_wiggler} The Wiggler configuration that comes with
2031 some versions of
2032 Amontec's Chameleon Programmer. The new version available from
2033 the website uses the original Wiggler layout ('@var{wiggler}')
2034 @item @b{triton} The parallel port adapter found on the
2035 ``Karo Triton 1 Development Board''.
2036 This is also the layout used by the HollyGates design
2037 (see @uref{http://www.lartmaker.nl/projects/jtag/}).
2038 @item @b{wiggler} The original Wiggler layout, also supported by
2039 several clones, such as the Olimex ARM-JTAG
2040 @item @b{wiggler2} Same as original wiggler except an led is fitted on D5.
2041 @item @b{wiggler_ntrst_inverted} Same as original wiggler except TRST is inverted.
2042 @end itemize
2043 @end deffn
2044
2045 @deffn {Config Command} {parport_port} number
2046 Either the address of the I/O port (default: 0x378 for LPT1) or the number of
2047 the @file{/dev/parport} device
2048
2049 When using PPDEV to access the parallel port, use the number of the parallel port:
2050 @option{parport_port 0} (the default). If @option{parport_port 0x378} is specified
2051 you may encounter a problem.
2052 @end deffn
2053
2054 @deffn Command {parport_toggling_time} [nanoseconds]
2055 Displays how many nanoseconds the hardware needs to toggle TCK;
2056 the parport driver uses this value to obey the
2057 @command{jtag_khz} configuration.
2058 When the optional @var{nanoseconds} parameter is given,
2059 that setting is changed before displaying the current value.
2060
2061 The default setting should work reasonably well on commodity PC hardware.
2062 However, you may want to calibrate for your specific hardware.
2063 @quotation Tip
2064 To measure the toggling time with a logic analyzer or a digital storage
2065 oscilloscope, follow the procedure below:
2066 @example
2067 > parport_toggling_time 1000
2068 > jtag_khz 500
2069 @end example
2070 This sets the maximum JTAG clock speed of the hardware, but
2071 the actual speed probably deviates from the requested 500 kHz.
2072 Now, measure the time between the two closest spaced TCK transitions.
2073 You can use @command{runtest 1000} or something similar to generate a
2074 large set of samples.
2075 Update the setting to match your measurement:
2076 @example
2077 > parport_toggling_time <measured nanoseconds>
2078 @end example
2079 Now the clock speed will be a better match for @command{jtag_khz rate}
2080 commands given in OpenOCD scripts and event handlers.
2081
2082 You can do something similar with many digital multimeters, but note
2083 that you'll probably need to run the clock continuously for several
2084 seconds before it decides what clock rate to show. Adjust the
2085 toggling time up or down until the measured clock rate is a good
2086 match for the jtag_khz rate you specified; be conservative.
2087 @end quotation
2088 @end deffn
2089
2090 @deffn {Config Command} {parport_write_on_exit} (on|off)
2091 This will configure the parallel driver to write a known
2092 cable-specific value to the parallel interface on exiting OpenOCD
2093 @end deffn
2094
2095 For example, the interface configuration file for a
2096 classic ``Wiggler'' cable might look something like this:
2097
2098 @example
2099 interface parport
2100 parport_port 0xc8b8
2101 parport_cable wiggler
2102 @end example
2103 @end deffn
2104
2105 @deffn {Interface Driver} {presto}
2106 ASIX PRESTO USB JTAG programmer.
2107 @c command: presto_serial str
2108 @c sets serial number
2109 @end deffn
2110
2111 @deffn {Interface Driver} {rlink}
2112 Raisonance RLink USB adapter
2113 @end deffn
2114
2115 @deffn {Interface Driver} {usbprog}
2116 usbprog is a freely programmable USB adapter.
2117 @end deffn
2118
2119 @deffn {Interface Driver} {vsllink}
2120 vsllink is part of Versaloon which is a versatile USB programmer.
2121
2122 @quotation Note
2123 This defines quite a few driver-specific commands,
2124 which are not currently documented here.
2125 @end quotation
2126 @end deffn
2127
2128 @deffn {Interface Driver} {ZY1000}
2129 This is the Zylin ZY1000 JTAG debugger.
2130
2131 @quotation Note
2132 This defines some driver-specific commands,
2133 which are not currently documented here.
2134 @end quotation
2135
2136 @deffn Command power [@option{on}|@option{off}]
2137 Turn power switch to target on/off.
2138 No arguments: print status.
2139 @end deffn
2140
2141 @end deffn
2142
2143 @anchor{JTAG Speed}
2144 @section JTAG Speed
2145 JTAG clock setup is part of system setup.
2146 It @emph{does not belong with interface setup} since any interface
2147 only knows a few of the constraints for the JTAG clock speed.
2148 Sometimes the JTAG speed is
2149 changed during the target initialization process: (1) slow at
2150 reset, (2) program the CPU clocks, (3) run fast.
2151 Both the "slow" and "fast" clock rates are functions of the
2152 oscillators used, the chip, the board design, and sometimes
2153 power management software that may be active.
2154
2155 The speed used during reset, and the scan chain verification which
2156 follows reset, can be adjusted using a @code{reset-start}
2157 target event handler.
2158 It can then be reconfigured to a faster speed by a
2159 @code{reset-init} target event handler after it reprograms those
2160 CPU clocks, or manually (if something else, such as a boot loader,
2161 sets up those clocks).
2162 @xref{Target Events}.
2163 When the initial low JTAG speed is a chip characteristic, perhaps
2164 because of a required oscillator speed, provide such a handler
2165 in the target config file.
2166 When that speed is a function of a board-specific characteristic
2167 such as which speed oscillator is used, it belongs in the board
2168 config file instead.
2169 In both cases it's safest to also set the initial JTAG clock rate
2170 to that same slow speed, so that OpenOCD never starts up using a
2171 clock speed that's faster than the scan chain can support.
2172
2173 @example
2174 jtag_rclk 3000
2175 $_TARGET.cpu configure -event reset-start @{ jtag_rclk 3000 @}
2176 @end example
2177
2178 If your system supports adaptive clocking (RTCK), configuring
2179 JTAG to use that is probably the most robust approach.
2180 However, it introduces delays to synchronize clocks; so it
2181 may not be the fastest solution.
2182
2183 @b{NOTE:} Script writers should consider using @command{jtag_rclk}
2184 instead of @command{jtag_khz}.
2185
2186 @deffn {Command} jtag_khz max_speed_kHz
2187 A non-zero speed is in KHZ. Hence: 3000 is 3mhz.
2188 JTAG interfaces usually support a limited number of
2189 speeds. The speed actually used won't be faster
2190 than the speed specified.
2191
2192 Chip data sheets generally include a top JTAG clock rate.
2193 The actual rate is often a function of a CPU core clock,
2194 and is normally less than that peak rate.
2195 For example, most ARM cores accept at most one sixth of the CPU clock.
2196
2197 Speed 0 (khz) selects RTCK method.
2198 @xref{FAQ RTCK}.
2199 If your system uses RTCK, you won't need to change the
2200 JTAG clocking after setup.
2201 Not all interfaces, boards, or targets support ``rtck''.
2202 If the interface device can not
2203 support it, an error is returned when you try to use RTCK.
2204 @end deffn
2205
2206 @defun jtag_rclk fallback_speed_kHz
2207 @cindex adaptive clocking
2208 @cindex RTCK
2209 This Tcl proc (defined in @file{startup.tcl}) attempts to enable RTCK/RCLK.
2210 If that fails (maybe the interface, board, or target doesn't
2211 support it), falls back to the specified frequency.
2212 @example
2213 # Fall back to 3mhz if RTCK is not supported
2214 jtag_rclk 3000
2215 @end example
2216 @end defun
2217
2218 @node Reset Configuration
2219 @chapter Reset Configuration
2220 @cindex Reset Configuration
2221
2222 Every system configuration may require a different reset
2223 configuration. This can also be quite confusing.
2224 Resets also interact with @var{reset-init} event handlers,
2225 which do things like setting up clocks and DRAM, and
2226 JTAG clock rates. (@xref{JTAG Speed}.)
2227 They can also interact with JTAG routers.
2228 Please see the various board files for examples.
2229
2230 @quotation Note
2231 To maintainers and integrators:
2232 Reset configuration touches several things at once.
2233 Normally the board configuration file
2234 should define it and assume that the JTAG adapter supports
2235 everything that's wired up to the board's JTAG connector.
2236
2237 However, the target configuration file could also make note
2238 of something the silicon vendor has done inside the chip,
2239 which will be true for most (or all) boards using that chip.
2240 And when the JTAG adapter doesn't support everything, the
2241 user configuration file will need to override parts of
2242 the reset configuration provided by other files.
2243 @end quotation
2244
2245 @section Types of Reset
2246
2247 There are many kinds of reset possible through JTAG, but
2248 they may not all work with a given board and adapter.
2249 That's part of why reset configuration can be error prone.
2250
2251 @itemize @bullet
2252 @item
2253 @emph{System Reset} ... the @emph{SRST} hardware signal
2254 resets all chips connected to the JTAG adapter, such as processors,
2255 power management chips, and I/O controllers. Normally resets triggered
2256 with this signal behave exactly like pressing a RESET button.
2257 @item
2258 @emph{JTAG TAP Reset} ... the @emph{TRST} hardware signal resets
2259 just the TAP controllers connected to the JTAG adapter.
2260 Such resets should not be visible to the rest of the system; resetting a
2261 device's the TAP controller just puts that controller into a known state.
2262 @item
2263 @emph{Emulation Reset} ... many devices can be reset through JTAG
2264 commands. These resets are often distinguishable from system
2265 resets, either explicitly (a "reset reason" register says so)
2266 or implicitly (not all parts of the chip get reset).
2267 @item
2268 @emph{Other Resets} ... system-on-chip devices often support
2269 several other types of reset.
2270 You may need to arrange that a watchdog timer stops
2271 while debugging, preventing a watchdog reset.
2272 There may be individual module resets.
2273 @end itemize
2274
2275 In the best case, OpenOCD can hold SRST, then reset
2276 the TAPs via TRST and send commands through JTAG to halt the
2277 CPU at the reset vector before the 1st instruction is executed.
2278 Then when it finally releases the SRST signal, the system is
2279 halted under debugger control before any code has executed.
2280 This is the behavior required to support the @command{reset halt}
2281 and @command{reset init} commands; after @command{reset init} a
2282 board-specific script might do things like setting up DRAM.
2283 (@xref{Reset Command}.)
2284
2285 @anchor{SRST and TRST Issues}
2286 @section SRST and TRST Issues
2287
2288 Because SRST and TRST are hardware signals, they can have a
2289 variety of system-specific constraints. Some of the most
2290 common issues are:
2291
2292 @itemize @bullet
2293
2294 @item @emph{Signal not available} ... Some boards don't wire
2295 SRST or TRST to the JTAG connector. Some JTAG adapters don't
2296 support such signals even if they are wired up.
2297 Use the @command{reset_config} @var{signals} options to say
2298 when either of those signals is not connected.
2299 When SRST is not available, your code might not be able to rely
2300 on controllers having been fully reset during code startup.
2301 Missing TRST is not a problem, since JTAG level resets can
2302 be triggered using with TMS signaling.
2303
2304 @item @emph{Signals shorted} ... Sometimes a chip, board, or
2305 adapter will connect SRST to TRST, instead of keeping them separate.
2306 Use the @command{reset_config} @var{combination} options to say
2307 when those signals aren't properly independent.
2308
2309 @item @emph{Timing} ... Reset circuitry like a resistor/capacitor
2310 delay circuit, reset supervisor, or on-chip features can extend
2311 the effect of a JTAG adapter's reset for some time after the adapter
2312 stops issuing the reset. For example, there may be chip or board
2313 requirements that all reset pulses last for at least a
2314 certain amount of time; and reset buttons commonly have
2315 hardware debouncing.
2316 Use the @command{jtag_nsrst_delay} and @command{jtag_ntrst_delay}
2317 commands to say when extra delays are needed.
2318
2319 @item @emph{Drive type} ... Reset lines often have a pullup
2320 resistor, letting the JTAG interface treat them as open-drain
2321 signals. But that's not a requirement, so the adapter may need
2322 to use push/pull output drivers.
2323 Also, with weak pullups it may be advisable to drive
2324 signals to both levels (push/pull) to minimize rise times.
2325 Use the @command{reset_config} @var{trst_type} and
2326 @var{srst_type} parameters to say how to drive reset signals.
2327
2328 @item @emph{Special initialization} ... Targets sometimes need
2329 special JTAG initialization sequences to handle chip-specific
2330 issues (not limited to errata).
2331 For example, certain JTAG commands might need to be issued while
2332 the system as a whole is in a reset state (SRST active)
2333 but the JTAG scan chain is usable (TRST inactive).
2334 Many systems treat combined assertion of SRST and TRST as a
2335 trigger for a harder reset than SRST alone.
2336 Such custom reset handling is discussed later in this chapter.
2337 @end itemize
2338
2339 There can also be other issues.
2340 Some devices don't fully conform to the JTAG specifications.
2341 Trivial system-specific differences are common, such as
2342 SRST and TRST using slightly different names.
2343 There are also vendors who distribute key JTAG documentation for
2344 their chips only to developers who have signed a Non-Disclosure
2345 Agreement (NDA).
2346
2347 Sometimes there are chip-specific extensions like a requirement to use
2348 the normally-optional TRST signal (precluding use of JTAG adapters which
2349 don't pass TRST through), or needing extra steps to complete a TAP reset.
2350
2351 In short, SRST and especially TRST handling may be very finicky,
2352 needing to cope with both architecture and board specific constraints.
2353
2354 @section Commands for Handling Resets
2355
2356 @deffn {Command} jtag_nsrst_assert_width milliseconds
2357 Minimum amount of time (in milliseconds) OpenOCD should wait
2358 after asserting nSRST (active-low system reset) before
2359 allowing it to be deasserted.
2360 @end deffn
2361
2362 @deffn {Command} jtag_nsrst_delay milliseconds
2363 How long (in milliseconds) OpenOCD should wait after deasserting
2364 nSRST (active-low system reset) before starting new JTAG operations.
2365 When a board has a reset button connected to SRST line it will
2366 probably have hardware debouncing, implying you should use this.
2367 @end deffn
2368
2369 @deffn {Command} jtag_ntrst_assert_width milliseconds
2370 Minimum amount of time (in milliseconds) OpenOCD should wait
2371 after asserting nTRST (active-low JTAG TAP reset) before
2372 allowing it to be deasserted.
2373 @end deffn
2374
2375 @deffn {Command} jtag_ntrst_delay milliseconds
2376 How long (in milliseconds) OpenOCD should wait after deasserting
2377 nTRST (active-low JTAG TAP reset) before starting new JTAG operations.
2378 @end deffn
2379
2380 @deffn {Command} reset_config mode_flag ...
2381 This command displays or modifies the reset configuration
2382 of your combination of JTAG board and target in target
2383 configuration scripts.
2384
2385 Information earlier in this section describes the kind of problems
2386 the command is intended to address (@pxref{SRST and TRST Issues}).
2387 As a rule this command belongs only in board config files,
2388 describing issues like @emph{board doesn't connect TRST};
2389 or in user config files, addressing limitations derived
2390 from a particular combination of interface and board.
2391 (An unlikely example would be using a TRST-only adapter
2392 with a board that only wires up SRST.)
2393
2394 The @var{mode_flag} options can be specified in any order, but only one
2395 of each type -- @var{signals}, @var{combination},
2396 @var{gates},
2397 @var{trst_type},
2398 and @var{srst_type} -- may be specified at a time.
2399 If you don't provide a new value for a given type, its previous
2400 value (perhaps the default) is unchanged.
2401 For example, this means that you don't need to say anything at all about
2402 TRST just to declare that if the JTAG adapter should want to drive SRST,
2403 it must explicitly be driven high (@option{srst_push_pull}).
2404
2405 @itemize
2406 @item
2407 @var{signals} can specify which of the reset signals are connected.
2408 For example, If the JTAG interface provides SRST, but the board doesn't
2409 connect that signal properly, then OpenOCD can't use it.
2410 Possible values are @option{none} (the default), @option{trst_only},
2411 @option{srst_only} and @option{trst_and_srst}.
2412
2413 @quotation Tip
2414 If your board provides SRST and/or TRST through the JTAG connector,
2415 you must declare that so those signals can be used.
2416 @end quotation
2417
2418 @item
2419 The @var{combination} is an optional value specifying broken reset
2420 signal implementations.
2421 The default behaviour if no option given is @option{separate},
2422 indicating everything behaves normally.
2423 @option{srst_pulls_trst} states that the
2424 test logic is reset together with the reset of the system (e.g. Philips
2425 LPC2000, "broken" board layout), @option{trst_pulls_srst} says that
2426 the system is reset together with the test logic (only hypothetical, I
2427 haven't seen hardware with such a bug, and can be worked around).
2428 @option{combined} implies both @option{srst_pulls_trst} and
2429 @option{trst_pulls_srst}.
2430
2431 @item
2432 The @var{gates} tokens control flags that describe some cases where
2433 JTAG may be unvailable during reset.
2434 @option{srst_gates_jtag} (default)
2435 indicates that asserting SRST gates the
2436 JTAG clock. This means that no communication can happen on JTAG
2437 while SRST is asserted.
2438 Its converse is @option{srst_nogate}, indicating that JTAG commands
2439 can safely be issued while SRST is active.
2440 @end itemize
2441
2442 The optional @var{trst_type} and @var{srst_type} parameters allow the
2443 driver mode of each reset line to be specified. These values only affect
2444 JTAG interfaces with support for different driver modes, like the Amontec
2445 JTAGkey and JTAG Accelerator. Also, they are necessarily ignored if the
2446 relevant signal (TRST or SRST) is not connected.
2447
2448 @itemize
2449 @item
2450 Possible @var{trst_type} driver modes for the test reset signal (TRST)
2451 are the default @option{trst_push_pull}, and @option{trst_open_drain}.
2452 Most boards connect this signal to a pulldown, so the JTAG TAPs
2453 never leave reset unless they are hooked up to a JTAG adapter.
2454
2455 @item
2456 Possible @var{srst_type} driver modes for the system reset signal (SRST)
2457 are the default @option{srst_open_drain}, and @option{srst_push_pull}.
2458 Most boards connect this signal to a pullup, and allow the
2459 signal to be pulled low by various events including system
2460 powerup and pressing a reset button.
2461 @end itemize
2462 @end deffn
2463
2464 @section Custom Reset Handling
2465 @cindex events
2466
2467 OpenOCD has several ways to help support the various reset
2468 mechanisms provided by chip and board vendors.
2469 The commands shown in the previous section give standard parameters.
2470 There are also @emph{event handlers} associated with TAPs or Targets.
2471 Those handlers are Tcl procedures you can provide, which are invoked
2472 at particular points in the reset sequence.
2473
2474 @emph{When SRST is not an option} you must set
2475 up a @code{reset-assert} event handler for your target.
2476 For example, some JTAG adapters don't include the SRST signal;
2477 and some boards have multiple targets, and you won't always
2478 want to reset everything at once.
2479
2480 After configuring those mechanisms, you might still
2481 find your board doesn't start up or reset correctly.
2482 For example, maybe it needs a slightly different sequence
2483 of SRST and/or TRST manipulations, because of quirks that
2484 the @command{reset_config} mechanism doesn't address;
2485 or asserting both might trigger a stronger reset, which
2486 needs special attention.
2487
2488 Experiment with lower level operations, such as @command{jtag_reset}
2489 and the @command{jtag arp_*} operations shown here,
2490 to find a sequence of operations that works.
2491 @xref{JTAG Commands}.
2492 When you find a working sequence, it can be used to override
2493 @command{jtag_init}, which fires during OpenOCD startup
2494 (@pxref{Configuration Stage});
2495 or @command{init_reset}, which fires during reset processing.
2496
2497 You might also want to provide some project-specific reset
2498 schemes. For example, on a multi-target board the standard
2499 @command{reset} command would reset all targets, but you
2500 may need the ability to reset only one target at time and
2501 thus want to avoid using the board-wide SRST signal.
2502
2503 @deffn {Overridable Procedure} init_reset mode
2504 This is invoked near the beginning of the @command{reset} command,
2505 usually to provide as much of a cold (power-up) reset as practical.
2506 By default it is also invoked from @command{jtag_init} if
2507 the scan chain does not respond to pure JTAG operations.
2508 The @var{mode} parameter is the parameter given to the
2509 low level reset command (@option{halt},
2510 @option{init}, or @option{run}), @option{setup},
2511 or potentially some other value.
2512
2513 The default implementation just invokes @command{jtag arp_init-reset}.
2514 Replacements will normally build on low level JTAG
2515 operations such as @command{jtag_reset}.
2516 Operations here must not address individual TAPs
2517 (or their associated targets)
2518 until the JTAG scan chain has first been verified to work.
2519
2520 Implementations must have verified the JTAG scan chain before
2521 they return.
2522 This is done by calling @command{jtag arp_init}
2523 (or @command{jtag arp_init-reset}).
2524 @end deffn
2525
2526 @deffn Command {jtag arp_init}
2527 This validates the scan chain using just the four
2528 standard JTAG signals (TMS, TCK, TDI, TDO).
2529 It starts by issuing a JTAG-only reset.
2530 Then it performs checks to verify that the scan chain configuration
2531 matches the TAPs it can observe.
2532 Those checks include checking IDCODE values for each active TAP,
2533 and verifying the length of their instruction registers using
2534 TAP @code{-ircapture} and @code{-irmask} values.
2535 If these tests all pass, TAP @code{setup} events are
2536 issued to all TAPs with handlers for that event.
2537 @end deffn
2538
2539 @deffn Command {jtag arp_init-reset}
2540 This uses TRST and SRST to try resetting
2541 everything on the JTAG scan chain
2542 (and anything else connected to SRST).
2543 It then invokes the logic of @command{jtag arp_init}.
2544 @end deffn
2545
2546
2547 @node TAP Declaration
2548 @chapter TAP Declaration
2549 @cindex TAP declaration
2550 @cindex TAP configuration
2551
2552 @emph{Test Access Ports} (TAPs) are the core of JTAG.
2553 TAPs serve many roles, including:
2554
2555 @itemize @bullet
2556 @item @b{Debug Target} A CPU TAP can be used as a GDB debug target
2557 @item @b{Flash Programing} Some chips program the flash directly via JTAG.
2558 Others do it indirectly, making a CPU do it.
2559 @item @b{Program Download} Using the same CPU support GDB uses,
2560 you can initialize a DRAM controller, download code to DRAM, and then
2561 start running that code.
2562 @item @b{Boundary Scan} Most chips support boundary scan, which
2563 helps test for board assembly problems like solder bridges
2564 and missing connections
2565 @end itemize
2566
2567 OpenOCD must know about the active TAPs on your board(s).
2568 Setting up the TAPs is the core task of your configuration files.
2569 Once those TAPs are set up, you can pass their names to code
2570 which sets up CPUs and exports them as GDB targets,
2571 probes flash memory, performs low-level JTAG operations, and more.
2572
2573 @section Scan Chains
2574 @cindex scan chain
2575
2576 TAPs are part of a hardware @dfn{scan chain},
2577 which is daisy chain of TAPs.
2578 They also need to be added to
2579 OpenOCD's software mirror of that hardware list,
2580 giving each member a name and associating other data with it.
2581 Simple scan chains, with a single TAP, are common in
2582 systems with a single microcontroller or microprocessor.
2583 More complex chips may have several TAPs internally.
2584 Very complex scan chains might have a dozen or more TAPs:
2585 several in one chip, more in the next, and connecting
2586 to other boards with their own chips and TAPs.
2587
2588 You can display the list with the @command{scan_chain} command.
2589 (Don't confuse this with the list displayed by the @command{targets}
2590 command, presented in the next chapter.
2591 That only displays TAPs for CPUs which are configured as
2592 debugging targets.)
2593 Here's what the scan chain might look like for a chip more than one TAP:
2594
2595 @verbatim
2596 TapName Enabled IdCode Expected IrLen IrCap IrMask
2597 -- ------------------ ------- ---------- ---------- ----- ----- ------
2598 0 omap5912.dsp Y 0x03df1d81 0x03df1d81 38 0x01 0x03
2599 1 omap5912.arm Y 0x0692602f 0x0692602f 4 0x01 0x0f
2600 2 omap5912.unknown Y 0x00000000 0x00000000 8 0x01 0x03
2601 @end verbatim
2602
2603 OpenOCD can detect some of that information, but not all
2604 of it. @xref{Autoprobing}.
2605 Unfortunately those TAPs can't always be autoconfigured,
2606 because not all devices provide good support for that.
2607 JTAG doesn't require supporting IDCODE instructions, and
2608 chips with JTAG routers may not link TAPs into the chain
2609 until they are told to do so.
2610
2611 The configuration mechanism currently supported by OpenOCD
2612 requires explicit configuration of all TAP devices using
2613 @command{jtag newtap} commands, as detailed later in this chapter.
2614 A command like this would declare one tap and name it @code{chip1.cpu}:
2615
2616 @example
2617 jtag newtap chip1 cpu -irlen 4 -expected-id 0x3ba00477
2618 @end example
2619
2620 Each target configuration file lists the TAPs provided
2621 by a given chip.
2622 Board configuration files combine all the targets on a board,
2623 and so forth.
2624 Note that @emph{the order in which TAPs are declared is very important.}
2625 It must match the order in the JTAG scan chain, both inside
2626 a single chip and between them.
2627 @xref{FAQ TAP Order}.
2628
2629 For example, the ST Microsystems STR912 chip has
2630 three separate TAPs@footnote{See the ST
2631 document titled: @emph{STR91xFAxxx, Section 3.15 Jtag Interface, Page:
2632 28/102, Figure 3: JTAG chaining inside the STR91xFA}.
2633 @url{http://eu.st.com/stonline/products/literature/ds/13495.pdf}}.
2634 To configure those taps, @file{target/str912.cfg}
2635 includes commands something like this:
2636
2637 @example
2638 jtag newtap str912 flash ... params ...
2639 jtag newtap str912 cpu ... params ...
2640 jtag newtap str912 bs ... params ...
2641 @end example
2642
2643 Actual config files use a variable instead of literals like
2644 @option{str912}, to support more than one chip of each type.
2645 @xref{Config File Guidelines}.
2646
2647 @deffn Command {jtag names}
2648 Returns the names of all current TAPs in the scan chain.
2649 Use @command{jtag cget} or @command{jtag tapisenabled}
2650 to examine attributes and state of each TAP.
2651 @example
2652 foreach t [jtag names] @{
2653 puts [format "TAP: %s\n" $t]
2654 @}
2655 @end example
2656 @end deffn
2657
2658 @deffn Command {scan_chain}
2659 Displays the TAPs in the scan chain configuration,
2660 and their status.
2661 The set of TAPs listed by this command is fixed by
2662 exiting the OpenOCD configuration stage,
2663 but systems with a JTAG router can
2664 enable or disable TAPs dynamically.
2665 @end deffn
2666
2667 @c FIXME! "jtag cget" should be able to return all TAP
2668 @c attributes, like "$target_name cget" does for targets.
2669
2670 @c Probably want "jtag eventlist", and a "tap-reset" event
2671 @c (on entry to RESET state).
2672
2673 @section TAP Names
2674 @cindex dotted name
2675
2676 When TAP objects are declared with @command{jtag newtap},
2677 a @dfn{dotted.name} is created for the TAP, combining the
2678 name of a module (usually a chip) and a label for the TAP.
2679 For example: @code{xilinx.tap}, @code{str912.flash},
2680 @code{omap3530.jrc}, @code{dm6446.dsp}, or @code{stm32.cpu}.
2681 Many other commands use that dotted.name to manipulate or
2682 refer to the TAP. For example, CPU configuration uses the
2683 name, as does declaration of NAND or NOR flash banks.
2684
2685 The components of a dotted name should follow ``C'' symbol
2686 name rules: start with an alphabetic character, then numbers
2687 and underscores are OK; while others (including dots!) are not.
2688
2689 @quotation Tip
2690 In older code, JTAG TAPs were numbered from 0..N.
2691 This feature is still present.
2692 However its use is highly discouraged, and
2693 should not be relied on; it will be removed by mid-2010.
2694 Update all of your scripts to use TAP names rather than numbers,
2695 by paying attention to the runtime warnings they trigger.
2696 Using TAP numbers in target configuration scripts prevents
2697 reusing those scripts on boards with multiple targets.
2698 @end quotation
2699
2700 @section TAP Declaration Commands
2701
2702 @c shouldn't this be(come) a {Config Command}?
2703 @anchor{jtag newtap}
2704 @deffn Command {jtag newtap} chipname tapname configparams...
2705 Declares a new TAP with the dotted name @var{chipname}.@var{tapname},
2706 and configured according to the various @var{configparams}.
2707
2708 The @var{chipname} is a symbolic name for the chip.
2709 Conventionally target config files use @code{$_CHIPNAME},
2710 defaulting to the model name given by the chip vendor but
2711 overridable.
2712
2713 @cindex TAP naming convention
2714 The @var{tapname} reflects the role of that TAP,
2715 and should follow this convention:
2716
2717 @itemize @bullet
2718 @item @code{bs} -- For boundary scan if this is a seperate TAP;
2719 @item @code{cpu} -- The main CPU of the chip, alternatively
2720 @code{arm} and @code{dsp} on chips with both ARM and DSP CPUs,
2721 @code{arm1} and @code{arm2} on chips two ARMs, and so forth;
2722 @item @code{etb} -- For an embedded trace buffer (example: an ARM ETB11);
2723 @item @code{flash} -- If the chip has a flash TAP, like the str912;
2724 @item @code{jrc} -- For JTAG route controller (example: the ICEpick modules
2725 on many Texas Instruments chips, like the OMAP3530 on Beagleboards);
2726 @item @code{tap} -- Should be used only FPGA or CPLD like devices
2727 with a single TAP;
2728 @item @code{unknownN} -- If you have no idea what the TAP is for (N is a number);
2729 @item @emph{when in doubt} -- Use the chip maker's name in their data sheet.
2730 For example, the Freescale IMX31 has a SDMA (Smart DMA) with
2731 a JTAG TAP; that TAP should be named @code{sdma}.
2732 @end itemize
2733
2734 Every TAP requires at least the following @var{configparams}:
2735
2736 @itemize @bullet
2737 @item @code{-irlen} @var{NUMBER}
2738 @*The length in bits of the
2739 instruction register, such as 4 or 5 bits.
2740 @end itemize
2741
2742 A TAP may also provide optional @var{configparams}:
2743
2744 @itemize @bullet
2745 @item @code{-disable} (or @code{-enable})
2746 @*Use the @code{-disable} parameter to flag a TAP which is not
2747 linked in to the scan chain after a reset using either TRST
2748 or the JTAG state machine's @sc{reset} state.
2749 You may use @code{-enable} to highlight the default state
2750 (the TAP is linked in).
2751 @xref{Enabling and Disabling TAPs}.
2752 @item @code{-expected-id} @var{number}
2753 @*A non-zero @var{number} represents a 32-bit IDCODE
2754 which you expect to find when the scan chain is examined.
2755 These codes are not required by all JTAG devices.
2756 @emph{Repeat the option} as many times as required if more than one
2757 ID code could appear (for example, multiple versions).
2758 Specify @var{number} as zero to suppress warnings about IDCODE
2759 values that were found but not included in the list.
2760
2761 Provide this value if at all possible, since it lets OpenOCD
2762 tell when the scan chain it sees isn't right. These values
2763 are provided in vendors' chip documentation, usually a technical
2764 reference manual. Sometimes you may need to probe the JTAG
2765 hardware to find these values.
2766 @xref{Autoprobing}.
2767 @item @code{-ignore-version}
2768 @*Specify this to ignore the JTAG version field in the @code{-expected-id}
2769 option. When vendors put out multiple versions of a chip, or use the same
2770 JTAG-level ID for several largely-compatible chips, it may be more practical
2771 to ignore the version field than to update config files to handle all of
2772 the various chip IDs.
2773 @item @code{-ircapture} @var{NUMBER}
2774 @*The bit pattern loaded by the TAP into the JTAG shift register
2775 on entry to the @sc{ircapture} state, such as 0x01.
2776 JTAG requires the two LSBs of this value to be 01.
2777 By default, @code{-ircapture} and @code{-irmask} are set
2778 up to verify that two-bit value. You may provide
2779 additional bits, if you know them, or indicate that
2780 a TAP doesn't conform to the JTAG specification.
2781 @item @code{-irmask} @var{NUMBER}
2782 @*A mask used with @code{-ircapture}
2783 to verify that instruction scans work correctly.
2784 Such scans are not used by OpenOCD except to verify that
2785 there seems to be no problems with JTAG scan chain operations.
2786 @end itemize
2787 @end deffn
2788
2789 @section Other TAP commands
2790
2791 @deffn Command {jtag cget} dotted.name @option{-event} name
2792 @deffnx Command {jtag configure} dotted.name @option{-event} name string
2793 At this writing this TAP attribute
2794 mechanism is used only for event handling.
2795 (It is not a direct analogue of the @code{cget}/@code{configure}
2796 mechanism for debugger targets.)
2797 See the next section for information about the available events.
2798
2799 The @code{configure} subcommand assigns an event handler,
2800 a TCL string which is evaluated when the event is triggered.
2801 The @code{cget} subcommand returns that handler.
2802 @end deffn
2803
2804 @anchor{TAP Events}
2805 @section TAP Events
2806 @cindex events
2807 @cindex TAP events
2808
2809 OpenOCD includes two event mechanisms.
2810 The one presented here applies to all JTAG TAPs.
2811 The other applies to debugger targets,
2812 which are associated with certain TAPs.
2813
2814 The TAP events currently defined are:
2815
2816 @itemize @bullet
2817 @item @b{post-reset}
2818 @* The TAP has just completed a JTAG reset.
2819 The tap may still be in the JTAG @sc{reset} state.
2820 Handlers for these events might perform initialization sequences
2821 such as issuing TCK cycles, TMS sequences to ensure
2822 exit from the ARM SWD mode, and more.
2823
2824 Because the scan chain has not yet been verified, handlers for these events
2825 @emph{should not issue commands which scan the JTAG IR or DR registers}
2826 of any particular target.
2827 @b{NOTE:} As this is written (September 2009), nothing prevents such access.
2828 @item @b{setup}
2829 @* The scan chain has been reset and verified.
2830 This handler may enable TAPs as needed.
2831 @item @b{tap-disable}
2832 @* The TAP needs to be disabled. This handler should
2833 implement @command{jtag tapdisable}
2834 by issuing the relevant JTAG commands.
2835 @item @b{tap-enable}
2836 @* The TAP needs to be enabled. This handler should
2837 implement @command{jtag tapenable}
2838 by issuing the relevant JTAG commands.
2839 @end itemize
2840
2841 If you need some action after each JTAG reset, which isn't actually
2842 specific to any TAP (since you can't yet trust the scan chain's
2843 contents to be accurate), you might:
2844
2845 @example
2846 jtag configure CHIP.jrc -event post-reset @{
2847 echo "JTAG Reset done"
2848 ... non-scan jtag operations to be done after reset
2849 @}
2850 @end example
2851
2852
2853 @anchor{Enabling and Disabling TAPs}
2854 @section Enabling and Disabling TAPs
2855 @cindex JTAG Route Controller
2856 @cindex jrc
2857
2858 In some systems, a @dfn{JTAG Route Controller} (JRC)
2859 is used to enable and/or disable specific JTAG TAPs.
2860 Many ARM based chips from Texas Instruments include
2861 an ``ICEpick'' module, which is a JRC.
2862 Such chips include DaVinci and OMAP3 processors.
2863
2864 A given TAP may not be visible until the JRC has been
2865 told to link it into the scan chain; and if the JRC
2866 has been told to unlink that TAP, it will no longer
2867 be visible.
2868 Such routers address problems that JTAG ``bypass mode''
2869 ignores, such as:
2870
2871 @itemize
2872 @item The scan chain can only go as fast as its slowest TAP.
2873 @item Having many TAPs slows instruction scans, since all
2874 TAPs receive new instructions.
2875 @item TAPs in the scan chain must be powered up, which wastes
2876 power and prevents debugging some power management mechanisms.
2877 @end itemize
2878
2879 The IEEE 1149.1 JTAG standard has no concept of a ``disabled'' tap,
2880 as implied by the existence of JTAG routers.
2881 However, the upcoming IEEE 1149.7 framework (layered on top of JTAG)
2882 does include a kind of JTAG router functionality.
2883
2884 @c (a) currently the event handlers don't seem to be able to
2885 @c fail in a way that could lead to no-change-of-state.
2886
2887 In OpenOCD, tap enabling/disabling is invoked by the Tcl commands
2888 shown below, and is implemented using TAP event handlers.
2889 So for example, when defining a TAP for a CPU connected to
2890 a JTAG router, your @file{target.cfg} file
2891 should define TAP event handlers using
2892 code that looks something like this:
2893
2894 @example
2895 jtag configure CHIP.cpu -event tap-enable @{
2896 ... jtag operations using CHIP.jrc
2897 @}
2898 jtag configure CHIP.cpu -event tap-disable @{
2899 ... jtag operations using CHIP.jrc
2900 @}
2901 @end example
2902
2903 Then you might want that CPU's TAP enabled almost all the time:
2904
2905 @example
2906 jtag configure $CHIP.jrc -event setup "jtag tapenable $CHIP.cpu"
2907 @end example
2908
2909 Note how that particular setup event handler declaration
2910 uses quotes to evaluate @code{$CHIP} when the event is configured.
2911 Using brackets @{ @} would cause it to be evaluated later,
2912 at runtime, when it might have a different value.
2913
2914 @deffn Command {jtag tapdisable} dotted.name
2915 If necessary, disables the tap
2916 by sending it a @option{tap-disable} event.
2917 Returns the string "1" if the tap
2918 specified by @var{dotted.name} is enabled,
2919 and "0" if it is disabled.
2920 @end deffn
2921
2922 @deffn Command {jtag tapenable} dotted.name
2923 If necessary, enables the tap
2924 by sending it a @option{tap-enable} event.
2925 Returns the string "1" if the tap
2926 specified by @var{dotted.name} is enabled,
2927 and "0" if it is disabled.
2928 @end deffn
2929
2930 @deffn Command {jtag tapisenabled} dotted.name
2931 Returns the string "1" if the tap
2932 specified by @var{dotted.name} is enabled,
2933 and "0" if it is disabled.
2934
2935 @quotation Note
2936 Humans will find the @command{scan_chain} command more helpful
2937 for querying the state of the JTAG taps.
2938 @end quotation
2939 @end deffn
2940
2941 @anchor{Autoprobing}
2942 @section Autoprobing
2943 @cindex autoprobe
2944 @cindex JTAG autoprobe
2945
2946 TAP configuration is the first thing that needs to be done
2947 after interface and reset configuration. Sometimes it's
2948 hard finding out what TAPs exist, or how they are identified.
2949 Vendor documentation is not always easy to find and use.
2950
2951 To help you get past such problems, OpenOCD has a limited
2952 @emph{autoprobing} ability to look at the scan chain, doing
2953 a @dfn{blind interrogation} and then reporting the TAPs it finds.
2954 To use this mechanism, start the OpenOCD server with only data
2955 that configures your JTAG interface, and arranges to come up
2956 with a slow clock (many devices don't support fast JTAG clocks
2957 right when they come out of reset).
2958
2959 For example, your @file{openocd.cfg} file might have:
2960
2961 @example
2962 source [find interface/olimex-arm-usb-tiny-h.cfg]
2963 reset_config trst_and_srst
2964 jtag_rclk 8
2965 @end example
2966
2967 When you start the server without any TAPs configured, it will
2968 attempt to autoconfigure the TAPs. There are two parts to this:
2969
2970 @enumerate
2971 @item @emph{TAP discovery} ...
2972 After a JTAG reset (sometimes a system reset may be needed too),
2973 each TAP's data registers will hold the contents of either the
2974 IDCODE or BYPASS register.
2975 If JTAG communication is working, OpenOCD will see each TAP,
2976 and report what @option{-expected-id} to use with it.
2977 @item @emph{IR Length discovery} ...
2978 Unfortunately JTAG does not provide a reliable way to find out
2979 the value of the @option{-irlen} parameter to use with a TAP
2980 that is discovered.
2981 If OpenOCD can discover the length of a TAP's instruction
2982 register, it will report it.
2983 Otherwise you may need to consult vendor documentation, such
2984 as chip data sheets or BSDL files.
2985 @end enumerate
2986
2987 In many cases your board will have a simple scan chain with just
2988 a single device. Here's what OpenOCD reported with one board
2989 that's a bit more complex:
2990
2991 @example
2992 clock speed 8 kHz
2993 There are no enabled taps. AUTO PROBING MIGHT NOT WORK!!
2994 AUTO auto0.tap - use "jtag newtap auto0 tap -expected-id 0x2b900f0f ..."
2995 AUTO auto1.tap - use "jtag newtap auto1 tap -expected-id 0x07926001 ..."
2996 AUTO auto2.tap - use "jtag newtap auto2 tap -expected-id 0x0b73b02f ..."
2997 AUTO auto0.tap - use "... -irlen 4"
2998 AUTO auto1.tap - use "... -irlen 4"
2999 AUTO auto2.tap - use "... -irlen 6"
3000 no gdb ports allocated as no target has been specified
3001 @end example
3002
3003 Given that information, you should be able to either find some existing
3004 config files to use, or create your own. If you create your own, you
3005 would configure from the bottom up: first a @file{target.cfg} file
3006 with these TAPs, any targets associated with them, and any on-chip
3007 resources; then a @file{board.cfg} with off-chip resources, clocking,
3008 and so forth.
3009
3010 @node CPU Configuration
3011 @chapter CPU Configuration
3012 @cindex GDB target
3013
3014 This chapter discusses how to set up GDB debug targets for CPUs.
3015 You can also access these targets without GDB
3016 (@pxref{Architecture and Core Commands},
3017 and @ref{Target State handling}) and
3018 through various kinds of NAND and NOR flash commands.
3019 If you have multiple CPUs you can have multiple such targets.
3020
3021 We'll start by looking at how to examine the targets you have,
3022 then look at how to add one more target and how to configure it.
3023
3024 @section Target List
3025 @cindex target, current
3026 @cindex target, list
3027
3028 All targets that have been set up are part of a list,
3029 where each member has a name.
3030 That name should normally be the same as the TAP name.
3031 You can display the list with the @command{targets}
3032 (plural!) command.
3033 This display often has only one CPU; here's what it might
3034 look like with more than one:
3035 @verbatim
3036 TargetName Type Endian TapName State
3037 -- ------------------ ---------- ------ ------------------ ------------
3038 0* at91rm9200.cpu arm920t little at91rm9200.cpu running
3039 1 MyTarget cortex_m3 little mychip.foo tap-disabled
3040 @end verbatim
3041
3042 One member of that list is the @dfn{current target}, which
3043 is implicitly referenced by many commands.
3044 It's the one marked with a @code{*} near the target name.
3045 In particular, memory addresses often refer to the address
3046 space seen by that current target.
3047 Commands like @command{mdw} (memory display words)
3048 and @command{flash erase_address} (erase NOR flash blocks)
3049 are examples; and there are many more.
3050
3051 Several commands let you examine the list of targets:
3052
3053 @deffn Command {target count}
3054 @emph{Note: target numbers are deprecated; don't use them.
3055 They will be removed shortly after August 2010, including this command.
3056 Iterate target using @command{target names}, not by counting.}
3057
3058 Returns the number of targets, @math{N}.
3059 The highest numbered target is @math{N - 1}.
3060 @example
3061 set c [target count]
3062 for @{ set x 0 @} @{ $x < $c @} @{ incr x @} @{
3063 # Assuming you have created this function
3064 print_target_details $x
3065 @}
3066 @end example
3067 @end deffn
3068
3069 @deffn Command {target current}
3070 Returns the name of the current target.
3071 @end deffn
3072
3073 @deffn Command {target names}
3074 Lists the names of all current targets in the list.
3075 @example
3076 foreach t [target names] @{
3077 puts [format "Target: %s\n" $t]
3078 @}
3079 @end example
3080 @end deffn
3081
3082 @deffn Command {target number} number
3083 @emph{Note: target numbers are deprecated; don't use them.
3084 They will be removed shortly after August 2010, including this command.}
3085
3086 The list of targets is numbered starting at zero.
3087 This command returns the name of the target at index @var{number}.
3088 @example
3089 set thename [target number $x]
3090 puts [format "Target %d is: %s\n" $x $thename]
3091 @end example
3092 @end deffn
3093
3094 @c yep, "target list" would have been better.
3095 @c plus maybe "target setdefault".
3096
3097 @deffn Command targets [name]
3098 @emph{Note: the name of this command is plural. Other target
3099 command names are singular.}
3100
3101 With no parameter, this command displays a table of all known
3102 targets in a user friendly form.
3103
3104 With a parameter, this command sets the current target to
3105 the given target with the given @var{name}; this is
3106 only relevant on boards which have more than one target.
3107 @end deffn
3108
3109 @section Target CPU Types and Variants
3110 @cindex target type
3111 @cindex CPU type
3112 @cindex CPU variant
3113
3114 Each target has a @dfn{CPU type}, as shown in the output of
3115 the @command{targets} command. You need to specify that type
3116 when calling @command{target create}.
3117 The CPU type indicates more than just the instruction set.
3118 It also indicates how that instruction set is implemented,
3119 what kind of debug support it integrates,
3120 whether it has an MMU (and if so, what kind),
3121 what core-specific commands may be available
3122 (@pxref{Architecture and Core Commands}),
3123 and more.
3124
3125 For some CPU types, OpenOCD also defines @dfn{variants} which
3126 indicate differences that affect their handling.
3127 For example, a particular implementation bug might need to be
3128 worked around in some chip versions.
3129
3130 It's easy to see what target types are supported,
3131 since there's a command to list them.
3132 However, there is currently no way to list what target variants
3133 are supported (other than by reading the OpenOCD source code).
3134
3135 @anchor{target types}
3136 @deffn Command {target types}
3137 Lists all supported target types.
3138 At this writing, the supported CPU types and variants are:
3139
3140 @itemize @bullet
3141 @item @code{arm11} -- this is a generation of ARMv6 cores
3142 @item @code{arm720t} -- this is an ARMv4 core with an MMU
3143 @item @code{arm7tdmi} -- this is an ARMv4 core
3144 @item @code{arm920t} -- this is an ARMv5 core with an MMU
3145 @item @code{arm926ejs} -- this is an ARMv5 core with an MMU
3146 @item @code{arm966e} -- this is an ARMv5 core
3147 @item @code{arm9tdmi} -- this is an ARMv4 core
3148 @item @code{avr} -- implements Atmel's 8-bit AVR instruction set.
3149 (Support for this is preliminary and incomplete.)
3150 @item @code{cortex_a8} -- this is an ARMv7 core with an MMU
3151 @item @code{cortex_m3} -- this is an ARMv7 core, supporting only the
3152 compact Thumb2 instruction set. It supports one variant:
3153 @itemize @minus
3154 @item @code{lm3s} ... Use this when debugging older Stellaris LM3S targets.
3155 This will cause OpenOCD to use a software reset rather than asserting
3156 SRST, to avoid a issue with clearing the debug registers.
3157 This is fixed in Fury Rev B, DustDevil Rev B, Tempest; these revisions will
3158 be detected and the normal reset behaviour used.
3159 @end itemize
3160 @item @code{dragonite} -- resembles arm966e
3161 @item @code{dsp563xx} -- implements Freescale's 24-bit DSP.
3162 (Support for this is still incomplete.)
3163 @item @code{fa526} -- resembles arm920 (w/o Thumb)
3164 @item @code{feroceon} -- resembles arm926
3165 @item @code{mips_m4k} -- a MIPS core. This supports one variant:
3166 @itemize @minus
3167 @item @code{ejtag_srst} ... Use this when debugging targets that do not
3168 provide a functional SRST line on the EJTAG connector. This causes
3169 OpenOCD to instead use an EJTAG software reset command to reset the
3170 processor.
3171 You still need to enable @option{srst} on the @command{reset_config}
3172 command to enable OpenOCD hardware reset functionality.
3173 @end itemize
3174 @item @code{xscale} -- this is actually an architecture,
3175 not a CPU type. It is based on the ARMv5 architecture.
3176 There are several variants defined:
3177 @itemize @minus
3178 @item @code{ixp42x}, @code{ixp45x}, @code{ixp46x},
3179 @code{pxa27x} ... instruction register length is 7 bits
3180 @item @code{pxa250}, @code{pxa255},
3181 @code{pxa26x} ... instruction register length is 5 bits
3182 @item @code{pxa3xx} ... instruction register length is 11 bits
3183 @end itemize
3184 @end itemize
3185 @end deffn
3186
3187 To avoid being confused by the variety of ARM based cores, remember
3188 this key point: @emph{ARM is a technology licencing company}.
3189 (See: @url{http://www.arm.com}.)
3190 The CPU name used by OpenOCD will reflect the CPU design that was
3191 licenced, not a vendor brand which incorporates that design.
3192 Name prefixes like arm7, arm9, arm11, and cortex
3193 reflect design generations;
3194 while names like ARMv4, ARMv5, ARMv6, and ARMv7
3195 reflect an architecture version implemented by a CPU design.
3196
3197 @anchor{Target Configuration}
3198 @section Target Configuration
3199
3200 Before creating a ``target'', you must have added its TAP to the scan chain.
3201 When you've added that TAP, you will have a @code{dotted.name}
3202 which is used to set up the CPU support.
3203 The chip-specific configuration file will normally configure its CPU(s)
3204 right after it adds all of the chip's TAPs to the scan chain.
3205
3206 Although you can set up a target in one step, it's often clearer if you
3207 use shorter commands and do it in two steps: create it, then configure
3208 optional parts.
3209 All operations on the target after it's created will use a new
3210 command, created as part of target creation.
3211
3212 The two main things to configure after target creation are
3213 a work area, which usually has target-specific defaults even
3214 if the board setup code overrides them later;
3215 and event handlers (@pxref{Target Events}), which tend
3216 to be much more board-specific.
3217 The key steps you use might look something like this
3218
3219 @example
3220 target create MyTarget cortex_m3 -chain-position mychip.cpu
3221 $MyTarget configure -work-area-phys 0x08000 -work-area-size 8096
3222 $MyTarget configure -event reset-deassert-pre @{ jtag_rclk 5 @}
3223 $MyTarget configure -event reset-init @{ myboard_reinit @}
3224 @end example
3225
3226 You should specify a working area if you can; typically it uses some
3227 on-chip SRAM.
3228 Such a working area can speed up many things, including bulk
3229 writes to target memory;
3230 flash operations like checking to see if memory needs to be erased;
3231 GDB memory checksumming;
3232 and more.
3233
3234 @quotation Warning
3235 On more complex chips, the work area can become
3236 inaccessible when application code
3237 (such as an operating system)
3238 enables or disables the MMU.
3239 For example, the particular MMU context used to acess the virtual
3240 address will probably matter ... and that context might not have
3241 easy access to other addresses needed.
3242 At this writing, OpenOCD doesn't have much MMU intelligence.
3243 @end quotation
3244
3245 It's often very useful to define a @code{reset-init} event handler.
3246 For systems that are normally used with a boot loader,
3247 common tasks include updating clocks and initializing memory
3248 controllers.
3249 That may be needed to let you write the boot loader into flash,
3250 in order to ``de-brick'' your board; or to load programs into
3251 external DDR memory without having run the boot loader.
3252
3253 @deffn Command {target create} target_name type configparams...
3254 This command creates a GDB debug target that refers to a specific JTAG tap.
3255 It enters that target into a list, and creates a new
3256 command (@command{@var{target_name}}) which is used for various
3257 purposes including additional configuration.
3258
3259 @itemize @bullet
3260 @item @var{target_name} ... is the name of the debug target.
3261 By convention this should be the same as the @emph{dotted.name}
3262 of the TAP associated with this target, which must be specified here
3263 using the @code{-chain-position @var{dotted.name}} configparam.
3264
3265 This name is also used to create the target object command,
3266 referred to here as @command{$target_name},
3267 and in other places the target needs to be identified.
3268 @item @var{type} ... specifies the target type. @xref{target types}.
3269 @item @var{configparams} ... all parameters accepted by
3270 @command{$target_name configure} are permitted.
3271 If the target is big-endian, set it here with @code{-endian big}.
3272 If the variant matters, set it here with @code{-variant}.
3273
3274 You @emph{must} set the @code{-chain-position @var{dotted.name}} here.
3275 @end itemize
3276 @end deffn
3277
3278 @deffn Command {$target_name configure} configparams...
3279 The options accepted by this command may also be
3280 specified as parameters to @command{target create}.
3281 Their values can later be queried one at a time by
3282 using the @command{$target_name cget} command.
3283
3284 @emph{Warning:} changing some of these after setup is dangerous.
3285 For example, moving a target from one TAP to another;
3286 and changing its endianness or variant.
3287
3288 @itemize @bullet
3289
3290 @item @code{-chain-position} @var{dotted.name} -- names the TAP
3291 used to access this target.
3292
3293 @item @code{-endian} (@option{big}|@option{little}) -- specifies
3294 whether the CPU uses big or little endian conventions
3295
3296 @item @code{-event} @var{event_name} @var{event_body} --
3297 @xref{Target Events}.
3298 Note that this updates a list of named event handlers.
3299 Calling this twice with two different event names assigns
3300 two different handlers, but calling it twice with the
3301 same event name assigns only one handler.
3302
3303 @item @code{-variant} @var{name} -- specifies a variant of the target,
3304 which OpenOCD needs to know about.
3305
3306 @item @code{-work-area-backup} (@option{0}|@option{1}) -- says
3307 whether the work area gets backed up; by default,
3308 @emph{it is not backed up.}
3309 When possible, use a working_area that doesn't need to be backed up,
3310 since performing a backup slows down operations.
3311 For example, the beginning of an SRAM block is likely to
3312 be used by most build systems, but the end is often unused.
3313
3314 @item @code{-work-area-size} @var{size} -- specify work are size,
3315 in bytes. The same size applies regardless of whether its physical
3316 or virtual address is being used.
3317
3318 @item @code{-work-area-phys} @var{address} -- set the work area
3319 base @var{address} to be used when no MMU is active.
3320
3321 @item @code{-work-area-virt} @var{address} -- set the work area
3322 base @var{address} to be used when an MMU is active.
3323 @emph{Do not specify a value for this except on targets with an MMU.}
3324 The value should normally correspond to a static mapping for the
3325 @code{-work-area-phys} address, set up by the current operating system.
3326
3327 @end itemize
3328 @end deffn
3329
3330 @section Other $target_name Commands
3331 @cindex object command
3332
3333 The Tcl/Tk language has the concept of object commands,
3334 and OpenOCD adopts that same model for targets.
3335
3336 A good Tk example is a on screen button.
3337 Once a button is created a button
3338 has a name (a path in Tk terms) and that name is useable as a first
3339 class command. For example in Tk, one can create a button and later
3340 configure it like this:
3341
3342 @example
3343 # Create
3344 button .foobar -background red -command @{ foo @}
3345 # Modify
3346 .foobar configure -foreground blue
3347 # Query
3348 set x [.foobar cget -background]
3349 # Report
3350 puts [format "The button is %s" $x]
3351 @end example
3352
3353 In OpenOCD's terms, the ``target'' is an object just like a Tcl/Tk
3354 button, and its object commands are invoked the same way.
3355
3356 @example
3357 str912.cpu mww 0x1234 0x42
3358 omap3530.cpu mww 0x5555 123
3359 @end example
3360
3361 The commands supported by OpenOCD target objects are:
3362
3363 @deffn Command {$target_name arp_examine}
3364 @deffnx Command {$target_name arp_halt}
3365 @deffnx Command {$target_name arp_poll}
3366 @deffnx Command {$target_name arp_reset}
3367 @deffnx Command {$target_name arp_waitstate}
3368 Internal OpenOCD scripts (most notably @file{startup.tcl})
3369 use these to deal with specific reset cases.
3370 They are not otherwise documented here.
3371 @end deffn
3372
3373 @deffn Command {$target_name array2mem} arrayname width address count
3374 @deffnx Command {$target_name mem2array} arrayname width address count
3375 These provide an efficient script-oriented interface to memory.
3376 The @code{array2mem} primitive writes bytes, halfwords, or words;
3377 while @code{mem2array} reads them.
3378 In both cases, the TCL side uses an array, and
3379 the target side uses raw memory.
3380
3381 The efficiency comes from enabling the use of
3382 bulk JTAG data transfer operations.
3383 The script orientation comes from working with data
3384 values that are packaged for use by TCL scripts;
3385 @command{mdw} type primitives only print data they retrieve,
3386 and neither store nor return those values.
3387
3388 @itemize
3389 @item @var{arrayname} ... is the name of an array variable
3390 @item @var{width} ... is 8/16/32 - indicating the memory access size
3391 @item @var{address} ... is the target memory address
3392 @item @var{count} ... is the number of elements to process
3393 @end itemize
3394 @end deffn
3395
3396 @deffn Command {$target_name cget} queryparm
3397 Each configuration parameter accepted by
3398 @command{$target_name configure}
3399 can be individually queried, to return its current value.
3400 The @var{queryparm} is a parameter name
3401 accepted by that command, such as @code{-work-area-phys}.
3402 There are a few special cases:
3403
3404 @itemize @bullet
3405 @item @code{-event} @var{event_name} -- returns the handler for the
3406 event named @var{event_name}.
3407 This is a special case because setting a handler requires
3408 two parameters.
3409 @item @code{-type} -- returns the target type.
3410 This is a special case because this is set using
3411 @command{target create} and can't be changed
3412 using @command{$target_name configure}.
3413 @end itemize
3414
3415 For example, if you wanted to summarize information about
3416 all the targets you might use something like this:
3417
3418 @example
3419 foreach name [target names] @{
3420 set y [$name cget -endian]
3421 set z [$name cget -type]
3422 puts [format "Chip %d is %s, Endian: %s, type: %s" \
3423 $x $name $y $z]
3424 @}
3425 @end example
3426 @end deffn
3427
3428 @anchor{target curstate}
3429 @deffn Command {$target_name curstate}
3430 Displays the current target state:
3431 @code{debug-running},
3432 @code{halted},
3433 @code{reset},
3434 @code{running}, or @code{unknown}.
3435 (Also, @pxref{Event Polling}.)
3436 @end deffn
3437
3438 @deffn Command {$target_name eventlist}
3439 Displays a table listing all event handlers
3440 currently associated with this target.
3441 @xref{Target Events}.
3442 @end deffn
3443
3444 @deffn Command {$target_name invoke-event} event_name
3445 Invokes the handler for the event named @var{event_name}.
3446 (This is primarily intended for use by OpenOCD framework
3447 code, for example by the reset code in @file{startup.tcl}.)
3448 @end deffn
3449
3450 @deffn Command {$target_name mdw} addr [count]
3451 @deffnx Command {$target_name mdh} addr [count]
3452 @deffnx Command {$target_name mdb} addr [count]
3453 Display contents of address @var{addr}, as
3454 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
3455 or 8-bit bytes (@command{mdb}).
3456 If @var{count} is specified, displays that many units.
3457 (If you want to manipulate the data instead of displaying it,
3458 see the @code{mem2array} primitives.)
3459 @end deffn
3460
3461 @deffn Command {$target_name mww} addr word
3462 @deffnx Command {$target_name mwh} addr halfword
3463 @deffnx Command {$target_name mwb} addr byte
3464 Writes the specified @var{word} (32 bits),
3465 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
3466 at the specified address @var{addr}.
3467 @end deffn
3468
3469 @anchor{Target Events}
3470 @section Target Events
3471 @cindex target events
3472 @cindex events
3473 At various times, certain things can happen, or you want them to happen.
3474 For example:
3475 @itemize @bullet
3476 @item What should happen when GDB connects? Should your target reset?
3477 @item When GDB tries to flash the target, do you need to enable the flash via a special command?
3478 @item Is using SRST appropriate (and possible) on your system?
3479 Or instead of that, do you need to issue JTAG commands to trigger reset?
3480 SRST usually resets everything on the scan chain, which can be inappropriate.
3481 @item During reset, do you need to write to certain memory locations
3482 to set up system clocks or
3483 to reconfigure the SDRAM?
3484 How about configuring the watchdog timer, or other peripherals,
3485 to stop running while you hold the core stopped for debugging?
3486 @end itemize
3487
3488 All of the above items can be addressed by target event handlers.
3489 These are set up by @command{$target_name configure -event} or
3490 @command{target create ... -event}.
3491
3492 The programmer's model matches the @code{-command} option used in Tcl/Tk
3493 buttons and events. The two examples below act the same, but one creates
3494 and invokes a small procedure while the other inlines it.
3495
3496 @example
3497 proc my_attach_proc @{ @} @{
3498 echo "Reset..."
3499 reset halt
3500 @}
3501 mychip.cpu configure -event gdb-attach my_attach_proc
3502 mychip.cpu configure -event gdb-attach @{
3503 echo "Reset..."
3504 reset halt
3505 @}
3506 @end example
3507
3508 The following target events are defined:
3509
3510 @itemize @bullet
3511 @item @b{debug-halted}
3512 @* The target has halted for debug reasons (i.e.: breakpoint)
3513 @item @b{debug-resumed}
3514 @* The target has resumed (i.e.: gdb said run)
3515 @item @b{early-halted}
3516 @* Occurs early in the halt process
3517 @ignore
3518 @item @b{examine-end}
3519 @* Currently not used (goal: when JTAG examine completes)
3520 @item @b{examine-start}
3521 @* Currently not used (goal: when JTAG examine starts)
3522 @end ignore
3523 @item @b{gdb-attach}
3524 @* When GDB connects
3525 @item @b{gdb-detach}
3526 @* When GDB disconnects
3527 @item @b{gdb-end}
3528 @* When the target has halted and GDB is not doing anything (see early halt)
3529 @item @b{gdb-flash-erase-start}
3530 @* Before the GDB flash process tries to erase the flash
3531 @item @b{gdb-flash-erase-end}
3532 @* After the GDB flash process has finished erasing the flash
3533 @item @b{gdb-flash-write-start}
3534 @* Before GDB writes to the flash
3535 @item @b{gdb-flash-write-end}
3536 @* After GDB writes to the flash
3537 @item @b{gdb-start}
3538 @* Before the target steps, gdb is trying to start/resume the target
3539 @item @b{halted}
3540 @* The target has halted
3541 @ignore
3542 @item @b{old-gdb_program_config}
3543 @* DO NOT USE THIS: Used internally
3544 @item @b{old-pre_resume}
3545 @* DO NOT USE THIS: Used internally
3546 @end ignore
3547 @item @b{reset-assert-pre}
3548 @* Issued as part of @command{reset} processing
3549 after @command{reset_init} was triggered
3550 but before either SRST alone is re-asserted on the scan chain,
3551 or @code{reset-assert} is triggered.
3552 @item @b{reset-assert}
3553 @* Issued as part of @command{reset} processing
3554 after @command{reset-assert-pre} was triggered.
3555 When such a handler is present, cores which support this event will use
3556 it instead of asserting SRST.
3557 This support is essential for debugging with JTAG interfaces which
3558 don't include an SRST line (JTAG doesn't require SRST), and for
3559 selective reset on scan chains that have multiple targets.
3560 @item @b{reset-assert-post}
3561 @* Issued as part of @command{reset} processing
3562 after @code{reset-assert} has been triggered.
3563 or the target asserted SRST on the entire scan chain.
3564 @item @b{reset-deassert-pre}
3565 @* Issued as part of @command{reset} processing
3566 after @code{reset-assert-post} has been triggered.
3567 @item @b{reset-deassert-post}
3568 @* Issued as part of @command{reset} processing
3569 after @code{reset-deassert-pre} has been triggered
3570 and (if the target is using it) after SRST has been
3571 released on the scan chain.
3572 @item @b{reset-end}
3573 @* Issued as the final step in @command{reset} processing.
3574 @ignore
3575 @item @b{reset-halt-post}
3576 @* Currently not used
3577 @item @b{reset-halt-pre}
3578 @* Currently not used
3579 @end ignore
3580 @item @b{reset-init}
3581 @* Used by @b{reset init} command for board-specific initialization.
3582 This event fires after @emph{reset-deassert-post}.
3583
3584 This is where you would configure PLLs and clocking, set up DRAM so
3585 you can download programs that don't fit in on-chip SRAM, set up pin
3586 multiplexing, and so on.
3587 (You may be able to switch to a fast JTAG clock rate here, after
3588 the target clocks are fully set up.)
3589 @item @b{reset-start}
3590 @* Issued as part of @command{reset} processing
3591 before @command{reset_init} is called.
3592
3593 This is the most robust place to use @command{jtag_rclk}
3594 or @command{jtag_khz} to switch to a low JTAG clock rate,
3595 when reset disables PLLs needed to use a fast clock.
3596 @ignore
3597 @item @b{reset-wait-pos}
3598 @* Currently not used
3599 @item @b{reset-wait-pre}
3600 @* Currently not used
3601 @end ignore
3602 @item @b{resume-start}
3603 @* Before any target is resumed
3604 @item @b{resume-end}
3605 @* After all targets have resumed
3606 @item @b{resume-ok}
3607 @* Success
3608 @item @b{resumed}
3609 @* Target has resumed
3610 @end itemize
3611
3612
3613 @node Flash Commands
3614 @chapter Flash Commands
3615
3616 OpenOCD has different commands for NOR and NAND flash;
3617 the ``flash'' command works with NOR flash, while
3618 the ``nand'' command works with NAND flash.
3619 This partially reflects different hardware technologies:
3620 NOR flash usually supports direct CPU instruction and data bus access,
3621 while data from a NAND flash must be copied to memory before it can be
3622 used. (SPI flash must also be copied to memory before use.)
3623 However, the documentation also uses ``flash'' as a generic term;
3624 for example, ``Put flash configuration in board-specific files''.
3625
3626 Flash Steps:
3627 @enumerate
3628 @item Configure via the command @command{flash bank}
3629 @* Do this in a board-specific configuration file,
3630 passing parameters as needed by the driver.
3631 @item Operate on the flash via @command{flash subcommand}
3632 @* Often commands to manipulate the flash are typed by a human, or run
3633 via a script in some automated way. Common tasks include writing a
3634 boot loader, operating system, or other data.
3635 @item GDB Flashing
3636 @* Flashing via GDB requires the flash be configured via ``flash
3637 bank'', and the GDB flash features be enabled.
3638 @xref{GDB Configuration}.
3639 @end enumerate
3640
3641 Many CPUs have the ablity to ``boot'' from the first flash bank.
3642 This means that misprogramming that bank can ``brick'' a system,
3643 so that it can't boot.
3644 JTAG tools, like OpenOCD, are often then used to ``de-brick'' the
3645 board by (re)installing working boot firmware.
3646
3647 @anchor{NOR Configuration}
3648 @section Flash Configuration Commands
3649 @cindex flash configuration
3650
3651 @deffn {Config Command} {flash bank} name driver base size chip_width bus_width target [driver_options]
3652 Configures a flash bank which provides persistent storage
3653 for addresses from @math{base} to @math{base + size - 1}.
3654 These banks will often be visible to GDB through the target's memory map.
3655 In some cases, configuring a flash bank will activate extra commands;
3656 see the driver-specific documentation.
3657
3658 @itemize @bullet
3659 @item @var{name} ... may be used to reference the flash bank
3660 in other flash commands.
3661 @item @var{driver} ... identifies the controller driver
3662 associated with the flash bank being declared.
3663 This is usually @code{cfi} for external flash, or else
3664 the name of a microcontroller with embedded flash memory.
3665 @xref{Flash Driver List}.
3666 @item @var{base} ... Base address of the flash chip.
3667 @item @var{size} ... Size of the chip, in bytes.
3668 For some drivers, this value is detected from the hardware.
3669 @item @var{chip_width} ... Width of the flash chip, in bytes;
3670 ignored for most microcontroller drivers.
3671 @item @var{bus_width} ... Width of the data bus used to access the
3672 chip, in bytes; ignored for most microcontroller drivers.
3673 @item @var{target} ... Names the target used to issue
3674 commands to the flash controller.
3675 @comment Actually, it's currently a controller-specific parameter...
3676 @item @var{driver_options} ... drivers may support, or require,
3677 additional parameters. See the driver-specific documentation
3678 for more information.
3679 @end itemize
3680 @quotation Note
3681 This command is not available after OpenOCD initialization has completed.
3682 Use it in board specific configuration files, not interactively.
3683 @end quotation
3684 @end deffn
3685
3686 @comment the REAL name for this command is "ocd_flash_banks"
3687 @comment less confusing would be: "flash list" (like "nand list")
3688 @deffn Command {flash banks}
3689 Prints a one-line summary of each device that was
3690 declared using @command{flash bank}, numbered from zero.
3691 Note that this is the @emph{plural} form;
3692 the @emph{singular} form is a very different command.
3693 @end deffn
3694
3695 @deffn Command {flash list}
3696 Retrieves a list of associative arrays for each device that was
3697 declared using @command{flash bank}, numbered from zero.
3698 This returned list can be manipulated easily from within scripts.
3699 @end deffn
3700
3701 @deffn Command {flash probe} num
3702 Identify the flash, or validate the parameters of the configured flash. Operation
3703 depends on the flash type.
3704 The @var{num} parameter is a value shown by @command{flash banks}.
3705 Most flash commands will implicitly @emph{autoprobe} the bank;
3706 flash drivers can distinguish between probing and autoprobing,
3707 but most don't bother.
3708 @end deffn
3709
3710 @section Erasing, Reading, Writing to Flash
3711 @cindex flash erasing
3712 @cindex flash reading
3713 @cindex flash writing
3714 @cindex flash programming
3715
3716 One feature distinguishing NOR flash from NAND or serial flash technologies
3717 is that for read access, it acts exactly like any other addressible memory.
3718 This means you can use normal memory read commands like @command{mdw} or
3719 @command{dump_image} with it, with no special @command{flash} subcommands.
3720 @xref{Memory access}, and @ref{Image access}.
3721
3722 Write access works differently. Flash memory normally needs to be erased
3723 before it's written. Erasing a sector turns all of its bits to ones, and
3724 writing can turn ones into zeroes. This is why there are special commands
3725 for interactive erasing and writing, and why GDB needs to know which parts
3726 of the address space hold NOR flash memory.
3727
3728 @quotation Note
3729 Most of these erase and write commands leverage the fact that NOR flash
3730 chips consume target address space. They implicitly refer to the current
3731 JTAG target, and map from an address in that target's address space
3732 back to a flash bank.
3733 @comment In May 2009, those mappings may fail if any bank associated
3734 @comment with that target doesn't succesfuly autoprobe ... bug worth fixing?
3735 A few commands use abstract addressing based on bank and sector numbers,
3736 and don't depend on searching the current target and its address space.
3737 Avoid confusing the two command models.
3738 @end quotation
3739
3740 Some flash chips implement software protection against accidental writes,
3741 since such buggy writes could in some cases ``brick'' a system.
3742 For such systems, erasing and writing may require sector protection to be
3743 disabled first.
3744 Examples include CFI flash such as ``Intel Advanced Bootblock flash'',
3745 and AT91SAM7 on-chip flash.
3746 @xref{flash protect}.
3747
3748 @anchor{flash erase_sector}
3749 @deffn Command {flash erase_sector} num first last
3750 Erase sectors in bank @var{num}, starting at sector @var{first}
3751 up to and including @var{last}.
3752 Sector numbering starts at 0.
3753 Providing a @var{last} sector of @option{last}
3754 specifies "to the end of the flash bank".
3755 The @var{num} parameter is a value shown by @command{flash banks}.
3756 @end deffn
3757
3758 @deffn Command {flash erase_address} address length
3759 Erase sectors starting at @var{address} for @var{length} bytes.
3760 The flash bank to use is inferred from the @var{address}, and
3761 the specified length must stay within that bank.
3762 As a special case, when @var{length} is zero and @var{address} is
3763 the start of the bank, the whole flash is erased.
3764 @end deffn
3765
3766 @deffn Command {flash fillw} address word length
3767 @deffnx Command {flash fillh} address halfword length
3768 @deffnx Command {flash fillb} address byte length
3769 Fills flash memory with the specified @var{word} (32 bits),
3770 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
3771 starting at @var{address} and continuing
3772 for @var{length} units (word/halfword/byte).
3773 No erasure is done before writing; when needed, that must be done
3774 before issuing this command.
3775 Writes are done in blocks of up to 1024 bytes, and each write is
3776 verified by reading back the data and comparing it to what was written.
3777 The flash bank to use is inferred from the @var{address} of
3778 each block, and the specified length must stay within that bank.
3779 @end deffn
3780 @comment no current checks for errors if fill blocks touch multiple banks!
3781
3782 @anchor{flash write_bank}
3783 @deffn Command {flash write_bank} num filename offset
3784 Write the binary @file{filename} to flash bank @var{num},
3785 starting at @var{offset} bytes from the beginning of the bank.
3786 The @var{num} parameter is a value shown by @command{flash banks}.
3787 @end deffn
3788
3789 @anchor{flash write_image}
3790 @deffn Command {flash write_image} [erase] [unlock] filename [offset] [type]
3791 Write the image @file{filename} to the current target's flash bank(s).
3792 A relocation @var{offset} may be specified, in which case it is added
3793 to the base address for each section in the image.
3794 The file [@var{type}] can be specified
3795 explicitly as @option{bin} (binary), @option{ihex} (Intel hex),
3796 @option{elf} (ELF file), @option{s19} (Motorola s19).
3797 @option{mem}, or @option{builder}.
3798 The relevant flash sectors will be erased prior to programming
3799 if the @option{erase} parameter is given. If @option{unlock} is
3800 provided, then the flash banks are unlocked before erase and
3801 program. The flash bank to use is inferred from the @var{address} of
3802 each image segment.
3803 @end deffn
3804
3805 @section Other Flash commands
3806 @cindex flash protection
3807
3808 @deffn Command {flash erase_check} num
3809 Check erase state of sectors in flash bank @var{num},
3810 and display that status.
3811 The @var{num} parameter is a value shown by @command{flash banks}.
3812 This is the only operation that
3813 updates the erase state information displayed by @option{flash info}. That means you have
3814 to issue a @command{flash erase_check} command after erasing or programming the device
3815 to get updated information.
3816 (Code execution may have invalidated any state records kept by OpenOCD.)
3817 @end deffn
3818
3819 @deffn Command {flash info} num
3820 Print info about flash bank @var{num}
3821 The @var{num} parameter is a value shown by @command{flash banks}.
3822 The information includes per-sector protect status.
3823 @end deffn
3824
3825 @anchor{flash protect}
3826 @deffn Command {flash protect} num first last (@option{on}|@option{off})
3827 Enable (@option{on}) or disable (@option{off}) protection of flash sectors
3828 in flash bank @var{num}, starting at sector @var{first}
3829 and continuing up to and including @var{last}.
3830 Providing a @var{last} sector of @option{last}
3831 specifies "to the end of the flash bank".
3832 The @var{num} parameter is a value shown by @command{flash banks}.
3833 @end deffn
3834
3835 @deffn Command {flash protect_check} num
3836 Check protection state of sectors in flash bank @var{num}.
3837 The @var{num} parameter is a value shown by @command{flash banks}.
3838 @comment @option{flash erase_sector} using the same syntax.
3839 @end deffn
3840
3841 @anchor{Flash Driver List}
3842 @section Flash Driver List
3843 As noted above, the @command{flash bank} command requires a driver name,
3844 and allows driver-specific options and behaviors.
3845 Some drivers also activate driver-specific commands.
3846
3847 @subsection External Flash
3848
3849 @deffn {Flash Driver} cfi
3850 @cindex Common Flash Interface
3851 @cindex CFI
3852 The ``Common Flash Interface'' (CFI) is the main standard for
3853 external NOR flash chips, each of which connects to a
3854 specific external chip select on the CPU.
3855 Frequently the first such chip is used to boot the system.
3856 Your board's @code{reset-init} handler might need to
3857 configure additional chip selects using other commands (like: @command{mww} to
3858 configure a bus and its timings), or
3859 perhaps configure a GPIO pin that controls the ``write protect'' pin
3860 on the flash chip.
3861 The CFI driver can use a target-specific working area to significantly
3862 speed up operation.
3863
3864 The CFI driver can accept the following optional parameters, in any order:
3865
3866 @itemize
3867 @item @var{jedec_probe} ... is used to detect certain non-CFI flash ROMs,
3868 like AM29LV010 and similar types.
3869 @item @var{x16_as_x8} ... when a 16-bit flash is hooked up to an 8-bit bus.
3870 @end itemize
3871
3872 To configure two adjacent banks of 16 MBytes each, both sixteen bits (two bytes)
3873 wide on a sixteen bit bus:
3874
3875 @example
3876 flash bank cfi 0x00000000 0x01000000 2 2 $_TARGETNAME
3877 flash bank cfi 0x01000000 0x01000000 2 2 $_TARGETNAME
3878 @end example
3879
3880 To configure one bank of 32 MBytes
3881 built from two sixteen bit (two byte) wide parts wired in parallel
3882 to create a thirty-two bit (four byte) bus with doubled throughput:
3883
3884 @example
3885 flash bank cfi 0x00000000 0x02000000 2 4 $_TARGETNAME
3886 @end example
3887
3888 @c "cfi part_id" disabled
3889 @end deffn
3890
3891 @subsection Internal Flash (Microcontrollers)
3892
3893 @deffn {Flash Driver} aduc702x
3894 The ADUC702x analog microcontrollers from Analog Devices
3895 include internal flash and use ARM7TDMI cores.
3896 The aduc702x flash driver works with models ADUC7019 through ADUC7028.
3897 The setup command only requires the @var{target} argument
3898 since all devices in this family have the same memory layout.
3899
3900 @example
3901 flash bank aduc702x 0 0 0 0 $_TARGETNAME
3902 @end example
3903 @end deffn
3904
3905 @deffn {Flash Driver} at91sam3
3906 @cindex at91sam3
3907 All members of the AT91SAM3 microcontroller family from
3908 Atmel include internal flash and use ARM's Cortex-M3 core. The driver
3909 currently (6/22/09) recognizes the AT91SAM3U[1/2/4][C/E] chips. Note
3910 that the driver was orginaly developed and tested using the
3911 AT91SAM3U4E, using a SAM3U-EK eval board. Support for other chips in
3912 the family was cribbed from the data sheet. @emph{Note to future
3913 readers/updaters: Please remove this worrysome comment after other
3914 chips are confirmed.}
3915
3916 The AT91SAM3U4[E/C] (256K) chips have two flash banks; most other chips
3917 have one flash bank. In all cases the flash banks are at
3918 the following fixed locations:
3919
3920 @example
3921 # Flash bank 0 - all chips
3922 flash bank at91sam3 0x00080000 0 1 1 $_TARGETNAME
3923 # Flash bank 1 - only 256K chips
3924 flash bank at91sam3 0x00100000 0 1 1 $_TARGETNAME
3925 @end example
3926
3927 Internally, the AT91SAM3 flash memory is organized as follows.
3928 Unlike the AT91SAM7 chips, these are not used as parameters
3929 to the @command{flash bank} command:
3930
3931 @itemize
3932 @item @emph{N-Banks:} 256K chips have 2 banks, others have 1 bank.
3933 @item @emph{Bank Size:} 128K/64K Per flash bank
3934 @item @emph{Sectors:} 16 or 8 per bank
3935 @item @emph{SectorSize:} 8K Per Sector
3936 @item @emph{PageSize:} 256 bytes per page. Note that OpenOCD operates on 'sector' sizes, not page sizes.
3937 @end itemize
3938
3939 The AT91SAM3 driver adds some additional commands:
3940
3941 @deffn Command {at91sam3 gpnvm}
3942 @deffnx Command {at91sam3 gpnvm clear} number
3943 @deffnx Command {at91sam3 gpnvm set} number
3944 @deffnx Command {at91sam3 gpnvm show} [@option{all}|number]
3945 With no parameters, @command{show} or @command{show all},
3946 shows the status of all GPNVM bits.
3947 With @command{show} @var{number}, displays that bit.
3948
3949 With @command{set} @var{number} or @command{clear} @var{number},
3950 modifies that GPNVM bit.
3951 @end deffn
3952
3953 @deffn Command {at91sam3 info}
3954 This command attempts to display information about the AT91SAM3
3955 chip. @emph{First} it read the @code{CHIPID_CIDR} [address 0x400e0740, see
3956 Section 28.2.1, page 505 of the AT91SAM3U 29/may/2009 datasheet,
3957 document id: doc6430A] and decodes the values. @emph{Second} it reads the
3958 various clock configuration registers and attempts to display how it
3959 believes the chip is configured. By default, the SLOWCLK is assumed to
3960 be 32768 Hz, see the command @command{at91sam3 slowclk}.
3961 @end deffn
3962
3963 @deffn Command {at91sam3 slowclk} [value]
3964 This command shows/sets the slow clock frequency used in the
3965 @command{at91sam3 info} command calculations above.
3966 @end deffn
3967 @end deffn
3968
3969 @deffn {Flash Driver} at91sam7
3970 All members of the AT91SAM7 microcontroller family from Atmel include
3971 internal flash and use ARM7TDMI cores. The driver automatically
3972 recognizes a number of these chips using the chip identification
3973 register, and autoconfigures itself.
3974
3975 @example
3976 flash bank at91sam7 0 0 0 0 $_TARGETNAME
3977 @end example
3978
3979 For chips which are not recognized by the controller driver, you must
3980 provide additional parameters in the following order:
3981
3982 @itemize
3983 @item @var{chip_model} ... label used with @command{flash info}
3984 @item @var{banks}
3985 @item @var{sectors_per_bank}
3986 @item @var{pages_per_sector}
3987 @item @var{pages_size}
3988 @item @var{num_nvm_bits}
3989 @item @var{freq_khz} ... required if an external clock is provided,
3990 optional (but recommended) when the oscillator frequency is known
3991 @end itemize
3992
3993 It is recommended that you provide zeroes for all of those values
3994 except the clock frequency, so that everything except that frequency
3995 will be autoconfigured.
3996 Knowing the frequency helps ensure correct timings for flash access.
3997
3998 The flash controller handles erases automatically on a page (128/256 byte)
3999 basis, so explicit erase commands are not necessary for flash programming.
4000 However, there is an ``EraseAll`` command that can erase an entire flash
4001 plane (of up to 256KB), and it will be used automatically when you issue
4002 @command{flash erase_sector} or @command{flash erase_address} commands.
4003
4004 @deffn Command {at91sam7 gpnvm} bitnum (@option{set}|@option{clear})
4005 Set or clear a ``General Purpose Non-Volatle Memory'' (GPNVM)
4006 bit for the processor. Each processor has a number of such bits,
4007 used for controlling features such as brownout detection (so they
4008 are not truly general purpose).
4009 @quotation Note
4010 This assumes that the first flash bank (number 0) is associated with
4011 the appropriate at91sam7 target.
4012 @end quotation
4013 @end deffn
4014 @end deffn
4015
4016 @deffn {Flash Driver} avr
4017 The AVR 8-bit microcontrollers from Atmel integrate flash memory.
4018 @emph{The current implementation is incomplete.}
4019 @comment - defines mass_erase ... pointless given flash_erase_address
4020 @end deffn
4021
4022 @deffn {Flash Driver} ecosflash
4023 @emph{No idea what this is...}
4024 The @var{ecosflash} driver defines one mandatory parameter,
4025 the name of a modules of target code which is downloaded
4026 and executed.
4027 @end deffn
4028
4029 @deffn {Flash Driver} lpc2000
4030 Most members of the LPC1700 and LPC2000 microcontroller families from NXP
4031 include internal flash and use Cortex-M3 (LPC1700) or ARM7TDMI (LPC2000) cores.
4032
4033 @quotation Note
4034 There are LPC2000 devices which are not supported by the @var{lpc2000}
4035 driver:
4036 The LPC2888 is supported by the @var{lpc288x} driver.
4037 The LPC29xx family is supported by the @var{lpc2900} driver.
4038 @end quotation
4039
4040 The @var{lpc2000} driver defines two mandatory and one optional parameters,
4041 which must appear in the following order:
4042
4043 @itemize
4044 @item @var{variant} ... required, may be
4045 @var{lpc2000_v1} (older LPC21xx and LPC22xx)
4046 @var{lpc2000_v2} (LPC213x, LPC214x, LPC210[123], LPC23xx and LPC24xx)
4047 or @var{lpc1700} (LPC175x and LPC176x)
4048 @item @var{clock_kHz} ... the frequency, in kiloHertz,
4049 at which the core is running
4050 @item @var{calc_checksum} ... optional (but you probably want to provide this!),
4051 telling the driver to calculate a valid checksum for the exception vector table.
4052 @end itemize
4053
4054 LPC flashes don't require the chip and bus width to be specified.
4055
4056 @example
4057 flash bank lpc2000 0x0 0x7d000 0 0 $_TARGETNAME \
4058 lpc2000_v2 14765 calc_checksum
4059 @end example
4060
4061 @deffn {Command} {lpc2000 part_id} bank
4062 Displays the four byte part identifier associated with
4063 the specified flash @var{bank}.
4064 @end deffn
4065 @end deffn
4066
4067 @deffn {Flash Driver} lpc288x
4068 The LPC2888 microcontroller from NXP needs slightly different flash
4069 support from its lpc2000 siblings.
4070 The @var{lpc288x} driver defines one mandatory parameter,
4071 the programming clock rate in Hz.
4072 LPC flashes don't require the chip and bus width to be specified.
4073
4074 @example
4075 flash bank lpc288x 0 0 0 0 $_TARGETNAME 12000000
4076 @end example
4077 @end deffn
4078
4079 @deffn {Flash Driver} lpc2900
4080 This driver supports the LPC29xx ARM968E based microcontroller family
4081 from NXP.
4082
4083 The predefined parameters @var{base}, @var{size}, @var{chip_width} and
4084 @var{bus_width} of the @code{flash bank} command are ignored. Flash size and
4085 sector layout are auto-configured by the driver.
4086 The driver has one additional mandatory parameter: The CPU clock rate
4087 (in kHz) at the time the flash operations will take place. Most of the time this
4088 will not be the crystal frequency, but a higher PLL frequency. The
4089 @code{reset-init} event handler in the board script is usually the place where
4090 you start the PLL.
4091
4092 The driver rejects flashless devices (currently the LPC2930).
4093
4094 The EEPROM in LPC2900 devices is not mapped directly into the address space.
4095 It must be handled much more like NAND flash memory, and will therefore be
4096 handled by a separate @code{lpc2900_eeprom} driver (not yet available).
4097
4098 Sector protection in terms of the LPC2900 is handled transparently. Every time a
4099 sector needs to be erased or programmed, it is automatically unprotected.
4100 What is shown as protection status in the @code{flash info} command, is
4101 actually the LPC2900 @emph{sector security}. This is a mechanism to prevent a
4102 sector from ever being erased or programmed again. As this is an irreversible
4103 mechanism, it is handled by a special command (@code{lpc2900 secure_sector}),
4104 and not by the standard @code{flash protect} command.
4105
4106 Example for a 125 MHz clock frequency:
4107 @example
4108 flash bank lpc2900 0 0 0 0 $_TARGETNAME 125000
4109 @end example
4110
4111 Some @code{lpc2900}-specific commands are defined. In the following command list,
4112 the @var{bank} parameter is the bank number as obtained by the
4113 @code{flash banks} command.
4114
4115 @deffn Command {lpc2900 signature} bank
4116 Calculates a 128-bit hash value, the @emph{signature}, from the whole flash
4117 content. This is a hardware feature of the flash block, hence the calculation is
4118 very fast. You may use this to verify the content of a programmed device against
4119 a known signature.
4120 Example:
4121 @example
4122 lpc2900 signature 0
4123 signature: 0x5f40cdc8:0xc64e592e:0x10490f89:0x32a0f317
4124 @end example
4125 @end deffn
4126
4127 @deffn Command {lpc2900 read_custom} bank filename
4128 Reads the 912 bytes of customer information from the flash index sector, and
4129 saves it to a file in binary format.
4130 Example:
4131 @example
4132 lpc2900 read_custom 0 /path_to/customer_info.bin
4133 @end example
4134 @end deffn
4135
4136 The index sector of the flash is a @emph{write-only} sector. It cannot be
4137 erased! In order to guard against unintentional write access, all following
4138 commands need to be preceeded by a successful call to the @code{password}
4139 command:
4140
4141 @deffn Command {lpc2900 password} bank password
4142 You need to use this command right before each of the following commands:
4143 @code{lpc2900 write_custom}, @code{lpc2900 secure_sector},
4144 @code{lpc2900 secure_jtag}.
4145
4146 The password string is fixed to "I_know_what_I_am_doing".
4147 Example:
4148 @example
4149 lpc2900 password 0 I_know_what_I_am_doing
4150 Potentially dangerous operation allowed in next command!
4151 @end example
4152 @end deffn
4153
4154 @deffn Command {lpc2900 write_custom} bank filename type
4155 Writes the content of the file into the customer info space of the flash index
4156 sector. The filetype can be specified with the @var{type} field. Possible values
4157 for @var{type} are: @var{bin} (binary), @var{ihex} (Intel hex format),
4158 @var{elf} (ELF binary) or @var{s19} (Motorola S-records). The file must
4159 contain a single section, and the contained data length must be exactly
4160 912 bytes.
4161 @quotation Attention
4162 This cannot be reverted! Be careful!
4163 @end quotation
4164 Example:
4165 @example
4166 lpc2900 write_custom 0 /path_to/customer_info.bin bin
4167 @end example
4168 @end deffn
4169
4170 @deffn Command {lpc2900 secure_sector} bank first last
4171 Secures the sector range from @var{first} to @var{last} (including) against
4172 further program and erase operations. The sector security will be effective
4173 after the next power cycle.
4174 @quotation Attention
4175 This cannot be reverted! Be careful!
4176 @end quotation
4177 Secured sectors appear as @emph{protected} in the @code{flash info} command.
4178 Example:
4179 @example
4180 lpc2900 secure_sector 0 1 1
4181 flash info 0
4182 #0 : lpc2900 at 0x20000000, size 0x000c0000, (...)
4183 # 0: 0x00000000 (0x2000 8kB) not protected
4184 # 1: 0x00002000 (0x2000 8kB) protected
4185 # 2: 0x00004000 (0x2000 8kB) not protected
4186 @end example
4187 @end deffn
4188
4189 @deffn Command {lpc2900 secure_jtag} bank
4190 Irreversibly disable the JTAG port. The new JTAG security setting will be
4191 effective after the next power cycle.
4192 @quotation Attention
4193 This cannot be reverted! Be careful!
4194 @end quotation
4195 Examples:
4196 @example
4197 lpc2900 secure_jtag 0
4198 @end example
4199 @end deffn
4200 @end deffn
4201
4202 @deffn {Flash Driver} ocl
4203 @emph{No idea what this is, other than using some arm7/arm9 core.}
4204
4205 @example
4206 flash bank ocl 0 0 0 0 $_TARGETNAME
4207 @end example
4208 @end deffn
4209
4210 @deffn {Flash Driver} pic32mx
4211 The PIC32MX microcontrollers are based on the MIPS 4K cores,
4212 and integrate flash memory.
4213 @emph{The current implementation is incomplete.}
4214
4215 @example
4216 flash bank pix32mx 0 0 0 0 $_TARGETNAME
4217 @end example
4218
4219 @comment numerous *disabled* commands are defined:
4220 @comment - chip_erase ... pointless given flash_erase_address
4221 @comment - lock, unlock ... pointless given protect on/off (yes?)
4222 @comment - pgm_word ... shouldn't bank be deduced from address??
4223 Some pic32mx-specific commands are defined:
4224 @deffn Command {pic32mx pgm_word} address value bank
4225 Programs the specified 32-bit @var{value} at the given @var{address}
4226 in the specified chip @var{bank}.
4227 @end deffn
4228 @end deffn
4229
4230 @deffn {Flash Driver} stellaris
4231 All members of the Stellaris LM3Sxxx microcontroller family from
4232 Texas Instruments
4233 include internal flash and use ARM Cortex M3 cores.
4234 The driver automatically recognizes a number of these chips using
4235 the chip identification register, and autoconfigures itself.
4236 @footnote{Currently there is a @command{stellaris mass_erase} command.
4237 That seems pointless since the same effect can be had using the
4238 standard @command{flash erase_address} command.}
4239
4240 @example
4241 flash bank stellaris 0 0 0 0 $_TARGETNAME
4242 @end example
4243 @end deffn
4244
4245 @deffn {Flash Driver} stm32x
4246 All members of the STM32 microcontroller family from ST Microelectronics
4247 include internal flash and use ARM Cortex M3 cores.
4248 The driver automatically recognizes a number of these chips using
4249 the chip identification register, and autoconfigures itself.
4250
4251 @example
4252 flash bank stm32x 0 0 0 0 $_TARGETNAME
4253 @end example
4254
4255 Some stm32x-specific commands
4256 @footnote{Currently there is a @command{stm32x mass_erase} command.
4257 That seems pointless since the same effect can be had using the
4258 standard @command{flash erase_address} command.}
4259 are defined:
4260
4261 @deffn Command {stm32x lock} num
4262 Locks the entire stm32 device.
4263 The @var{num} parameter is a value shown by @command{flash banks}.
4264 @end deffn
4265
4266 @deffn Command {stm32x unlock} num
4267 Unlocks the entire stm32 device.
4268 The @var{num} parameter is a value shown by @command{flash banks}.
4269 @end deffn
4270
4271 @deffn Command {stm32x options_read} num
4272 Read and display the stm32 option bytes written by
4273 the @command{stm32x options_write} command.
4274 The @var{num} parameter is a value shown by @command{flash banks}.
4275 @end deffn
4276
4277 @deffn Command {stm32x options_write} num (@option{SWWDG}|@option{HWWDG}) (@option{RSTSTNDBY}|@option{NORSTSTNDBY}) (@option{RSTSTOP}|@option{NORSTSTOP})
4278 Writes the stm32 option byte with the specified values.
4279 The @var{num} parameter is a value shown by @command{flash banks}.
4280 @end deffn
4281 @end deffn
4282
4283 @deffn {Flash Driver} str7x
4284 All members of the STR7 microcontroller family from ST Microelectronics
4285 include internal flash and use ARM7TDMI cores.
4286 The @var{str7x} driver defines one mandatory parameter, @var{variant},
4287 which is either @code{STR71x}, @code{STR73x} or @code{STR75x}.
4288
4289 @example
4290 flash bank str7x 0x40000000 0x00040000 0 0 $_TARGETNAME STR71x
4291 @end example
4292
4293 @deffn Command {str7x disable_jtag} bank
4294 Activate the Debug/Readout protection mechanism
4295 for the specified flash bank.
4296 @end deffn
4297 @end deffn
4298
4299 @deffn {Flash Driver} str9x
4300 Most members of the STR9 microcontroller family from ST Microelectronics
4301 include internal flash and use ARM966E cores.
4302 The str9 needs the flash controller to be configured using
4303 the @command{str9x flash_config} command prior to Flash programming.
4304
4305 @example
4306 flash bank str9x 0x40000000 0x00040000 0 0 $_TARGETNAME
4307 str9x flash_config 0 4 2 0 0x80000
4308 @end example
4309
4310 @deffn Command {str9x flash_config} num bbsr nbbsr bbadr nbbadr
4311 Configures the str9 flash controller.
4312 The @var{num} parameter is a value shown by @command{flash banks}.
4313
4314 @itemize @bullet
4315 @item @var{bbsr} - Boot Bank Size register
4316 @item @var{nbbsr} - Non Boot Bank Size register
4317 @item @var{bbadr} - Boot Bank Start Address register
4318 @item @var{nbbadr} - Boot Bank Start Address register
4319 @end itemize
4320 @end deffn
4321
4322 @end deffn
4323
4324 @deffn {Flash Driver} tms470
4325 Most members of the TMS470 microcontroller family from Texas Instruments
4326 include internal flash and use ARM7TDMI cores.
4327 This driver doesn't require the chip and bus width to be specified.
4328
4329 Some tms470-specific commands are defined:
4330
4331 @deffn Command {tms470 flash_keyset} key0 key1 key2 key3
4332 Saves programming keys in a register, to enable flash erase and write commands.
4333 @end deffn
4334
4335 @deffn Command {tms470 osc_mhz} clock_mhz
4336 Reports the clock speed, which is used to calculate timings.
4337 @end deffn
4338
4339 @deffn Command {tms470 plldis} (0|1)
4340 Disables (@var{1}) or enables (@var{0}) use of the PLL to speed up
4341 the flash clock.
4342 @end deffn
4343 @end deffn
4344
4345 @subsection str9xpec driver
4346 @cindex str9xpec
4347
4348 Here is some background info to help
4349 you better understand how this driver works. OpenOCD has two flash drivers for
4350 the str9:
4351 @enumerate
4352 @item
4353 Standard driver @option{str9x} programmed via the str9 core. Normally used for
4354 flash programming as it is faster than the @option{str9xpec} driver.
4355 @item
4356 Direct programming @option{str9xpec} using the flash controller. This is an
4357 ISC compilant (IEEE 1532) tap connected in series with the str9 core. The str9
4358 core does not need to be running to program using this flash driver. Typical use
4359 for this driver is locking/unlocking the target and programming the option bytes.
4360 @end enumerate
4361
4362 Before we run any commands using the @option{str9xpec} driver we must first disable
4363 the str9 core. This example assumes the @option{str9xpec} driver has been
4364 configured for flash bank 0.
4365 @example
4366 # assert srst, we do not want core running
4367 # while accessing str9xpec flash driver
4368 jtag_reset 0 1
4369 # turn off target polling
4370 poll off
4371 # disable str9 core
4372 str9xpec enable_turbo 0
4373 # read option bytes
4374 str9xpec options_read 0
4375 # re-enable str9 core
4376 str9xpec disable_turbo 0
4377 poll on
4378 reset halt
4379 @end example
4380 The above example will read the str9 option bytes.
4381 When performing a unlock remember that you will not be able to halt the str9 - it
4382 has been locked. Halting the core is not required for the @option{str9xpec} driver
4383 as mentioned above, just issue the commands above manually or from a telnet prompt.
4384
4385 @deffn {Flash Driver} str9xpec
4386 Only use this driver for locking/unlocking the device or configuring the option bytes.
4387 Use the standard str9 driver for programming.
4388 Before using the flash commands the turbo mode must be enabled using the
4389 @command{str9xpec enable_turbo} command.
4390
4391 Several str9xpec-specific commands are defined:
4392
4393 @deffn Command {str9xpec disable_turbo} num
4394 Restore the str9 into JTAG chain.
4395 @end deffn
4396
4397 @deffn Command {str9xpec enable_turbo} num
4398 Enable turbo mode, will simply remove the str9 from the chain and talk
4399 directly to the embedded flash controller.
4400 @end deffn
4401
4402 @deffn Command {str9xpec lock} num
4403 Lock str9 device. The str9 will only respond to an unlock command that will
4404 erase the device.
4405 @end deffn
4406
4407 @deffn Command {str9xpec part_id} num
4408 Prints the part identifier for bank @var{num}.
4409 @end deffn
4410
4411 @deffn Command {str9xpec options_cmap} num (@option{bank0}|@option{bank1})
4412 Configure str9 boot bank.
4413 @end deffn
4414
4415 @deffn Command {str9xpec options_lvdsel} num (@option{vdd}|@option{vdd_vddq})
4416 Configure str9 lvd source.
4417 @end deffn
4418
4419 @deffn Command {str9xpec options_lvdthd} num (@option{2.4v}|@option{2.7v})
4420 Configure str9 lvd threshold.
4421 @end deffn
4422
4423 @deffn Command {str9xpec options_lvdwarn} bank (@option{vdd}|@option{vdd_vddq})
4424 Configure str9 lvd reset warning source.
4425 @end deffn
4426
4427 @deffn Command {str9xpec options_read} num
4428 Read str9 option bytes.
4429 @end deffn
4430
4431 @deffn Command {str9xpec options_write} num
4432 Write str9 option bytes.
4433 @end deffn
4434
4435 @deffn Command {str9xpec unlock} num
4436 unlock str9 device.
4437 @end deffn
4438
4439 @end deffn
4440
4441
4442 @section mFlash
4443
4444 @subsection mFlash Configuration
4445 @cindex mFlash Configuration
4446
4447 @deffn {Config Command} {mflash bank} soc base RST_pin target
4448 Configures a mflash for @var{soc} host bank at
4449 address @var{base}.
4450 The pin number format depends on the host GPIO naming convention.
4451 Currently, the mflash driver supports s3c2440 and pxa270.
4452
4453 Example for s3c2440 mflash where @var{RST pin} is GPIO B1:
4454
4455 @example
4456 mflash bank s3c2440 0x10000000 1b 0
4457 @end example
4458
4459 Example for pxa270 mflash where @var{RST pin} is GPIO 43:
4460
4461 @example
4462 mflash bank pxa270 0x08000000 43 0
4463 @end example
4464 @end deffn
4465
4466 @subsection mFlash commands
4467 @cindex mFlash commands
4468
4469 @deffn Command {mflash config pll} frequency
4470 Configure mflash PLL.
4471 The @var{frequency} is the mflash input frequency, in Hz.
4472 Issuing this command will erase mflash's whole internal nand and write new pll.
4473 After this command, mflash needs power-on-reset for normal operation.
4474 If pll was newly configured, storage and boot(optional) info also need to be update.
4475 @end deffn
4476
4477 @deffn Command {mflash config boot}
4478 Configure bootable option.
4479 If bootable option is set, mflash offer the first 8 sectors
4480 (4kB) for boot.
4481 @end deffn
4482
4483 @deffn Command {mflash config storage}
4484 Configure storage information.
4485 For the normal storage operation, this information must be
4486 written.
4487 @end deffn
4488
4489 @deffn Command {mflash dump} num filename offset size
4490 Dump @var{size} bytes, starting at @var{offset} bytes from the
4491 beginning of the bank @var{num}, to the file named @var{filename}.
4492 @end deffn
4493
4494 @deffn Command {mflash probe}
4495 Probe mflash.
4496 @end deffn
4497
4498 @deffn Command {mflash write} num filename offset
4499 Write the binary file @var{filename} to mflash bank @var{num}, starting at
4500 @var{offset} bytes from the beginning of the bank.
4501 @end deffn
4502
4503 @node NAND Flash Commands
4504 @chapter NAND Flash Commands
4505 @cindex NAND
4506
4507 Compared to NOR or SPI flash, NAND devices are inexpensive
4508 and high density. Today's NAND chips, and multi-chip modules,
4509 commonly hold multiple GigaBytes of data.
4510
4511 NAND chips consist of a number of ``erase blocks'' of a given
4512 size (such as 128 KBytes), each of which is divided into a
4513 number of pages (of perhaps 512 or 2048 bytes each). Each
4514 page of a NAND flash has an ``out of band'' (OOB) area to hold
4515 Error Correcting Code (ECC) and other metadata, usually 16 bytes
4516 of OOB for every 512 bytes of page data.
4517
4518 One key characteristic of NAND flash is that its error rate
4519 is higher than that of NOR flash. In normal operation, that
4520 ECC is used to correct and detect errors. However, NAND
4521 blocks can also wear out and become unusable; those blocks
4522 are then marked "bad". NAND chips are even shipped from the
4523 manufacturer with a few bad blocks. The highest density chips
4524 use a technology (MLC) that wears out more quickly, so ECC
4525 support is increasingly important as a way to detect blocks
4526 that have begun to fail, and help to preserve data integrity
4527 with techniques such as wear leveling.
4528
4529 Software is used to manage the ECC. Some controllers don't
4530 support ECC directly; in those cases, software ECC is used.
4531 Other controllers speed up the ECC calculations with hardware.
4532 Single-bit error correction hardware is routine. Controllers
4533 geared for newer MLC chips may correct 4 or more errors for
4534 every 512 bytes of data.
4535
4536 You will need to make sure that any data you write using
4537 OpenOCD includes the apppropriate kind of ECC. For example,
4538 that may mean passing the @code{oob_softecc} flag when
4539 writing NAND data, or ensuring that the correct hardware
4540 ECC mode is used.
4541
4542 The basic steps for using NAND devices include:
4543 @enumerate
4544 @item Declare via the command @command{nand device}
4545 @* Do this in a board-specific configuration file,
4546 passing parameters as needed by the controller.
4547 @item Configure each device using @command{nand probe}.
4548 @* Do this only after the associated target is set up,
4549 such as in its reset-init script or in procures defined
4550 to access that device.
4551 @item Operate on the flash via @command{nand subcommand}
4552 @* Often commands to manipulate the flash are typed by a human, or run
4553 via a script in some automated way. Common task include writing a
4554 boot loader, operating system, or other data needed to initialize or
4555 de-brick a board.
4556 @end enumerate
4557
4558 @b{NOTE:} At the time this text was written, the largest NAND
4559 flash fully supported by OpenOCD is 2 GiBytes (16 GiBits).
4560 This is because the variables used to hold offsets and lengths
4561 are only 32 bits wide.
4562 (Larger chips may work in some cases, unless an offset or length
4563 is larger than 0xffffffff, the largest 32-bit unsigned integer.)
4564 Some larger devices will work, since they are actually multi-chip
4565 modules with two smaller chips and individual chipselect lines.
4566
4567 @anchor{NAND Configuration}
4568 @section NAND Configuration Commands
4569 @cindex NAND configuration
4570
4571 NAND chips must be declared in configuration scripts,
4572 plus some additional configuration that's done after
4573 OpenOCD has initialized.
4574
4575 @deffn {Config Command} {nand device} name controller target [configparams...]
4576 Declares a NAND device, which can be read and written to
4577 after it has been configured through @command{nand probe}.
4578 In OpenOCD, devices are single chips; this is unlike some
4579 operating systems, which may manage multiple chips as if
4580 they were a single (larger) device.
4581 In some cases, configuring a device will activate extra
4582 commands; see the controller-specific documentation.
4583
4584 @b{NOTE:} This command is not available after OpenOCD
4585 initialization has completed. Use it in board specific
4586 configuration files, not interactively.
4587
4588 @itemize @bullet
4589 @item @var{name} ... may be used to reference the NAND bank
4590 in other commands.
4591 @item @var{controller} ... identifies the controller driver
4592 associated with the NAND device being declared.
4593 @xref{NAND Driver List}.
4594 @item @var{target} ... names the target used when issuing
4595 commands to the NAND controller.
4596 @comment Actually, it's currently a controller-specific parameter...
4597 @item @var{configparams} ... controllers may support, or require,
4598 additional parameters. See the controller-specific documentation
4599 for more information.
4600 @end itemize
4601 @end deffn
4602
4603 @deffn Command {nand list}
4604 Prints a summary of each device declared
4605 using @command{nand device}, numbered from zero.
4606 Note that un-probed devices show no details.
4607 @example
4608 > nand list
4609 #0: NAND 1GiB 3,3V 8-bit (Micron) pagesize: 2048, buswidth: 8,
4610 blocksize: 131072, blocks: 8192
4611 #1: NAND 1GiB 3,3V 8-bit (Micron) pagesize: 2048, buswidth: 8,
4612 blocksize: 131072, blocks: 8192
4613 >
4614 @end example
4615 @end deffn
4616
4617 @deffn Command {nand probe} num
4618 Probes the specified device to determine key characteristics
4619 like its page and block sizes, and how many blocks it has.
4620 The @var{num} parameter is the value shown by @command{nand list}.
4621 You must (successfully) probe a device before you can use
4622 it with most other NAND commands.
4623 @end deffn
4624
4625 @section Erasing, Reading, Writing to NAND Flash
4626
4627 @deffn Command {nand dump} num filename offset length [oob_option]
4628 @cindex NAND reading
4629 Reads binary data from the NAND device and writes it to the file,
4630 starting at the specified offset.
4631 The @var{num} parameter is the value shown by @command{nand list}.
4632
4633 Use a complete path name for @var{filename}, so you don't depend
4634 on the directory used to start the OpenOCD server.
4635
4636 The @var{offset} and @var{length} must be exact multiples of the
4637 device's page size. They describe a data region; the OOB data
4638 associated with each such page may also be accessed.
4639
4640 @b{NOTE:} At the time this text was written, no error correction
4641 was done on the data that's read, unless raw access was disabled
4642 and the underlying NAND controller driver had a @code{read_page}
4643 method which handled that error correction.
4644
4645 By default, only page data is saved to the specified file.
4646 Use an @var{oob_option} parameter to save OOB data:
4647 @itemize @bullet
4648 @item no oob_* parameter
4649 @*Output file holds only page data; OOB is discarded.
4650 @item @code{oob_raw}
4651 @*Output file interleaves page data and OOB data;
4652 the file will be longer than "length" by the size of the
4653 spare areas associated with each data page.
4654 Note that this kind of "raw" access is different from
4655 what's implied by @command{nand raw_access}, which just
4656 controls whether a hardware-aware access method is used.
4657 @item @code{oob_only}
4658 @*Output file has only raw OOB data, and will
4659 be smaller than "length" since it will contain only the
4660 spare areas associated with each data page.
4661 @end itemize
4662 @end deffn
4663
4664 @deffn Command {nand erase} num [offset length]
4665 @cindex NAND erasing
4666 @cindex NAND programming
4667 Erases blocks on the specified NAND device, starting at the
4668 specified @var{offset} and continuing for @var{length} bytes.
4669 Both of those values must be exact multiples of the device's
4670 block size, and the region they specify must fit entirely in the chip.
4671 If those parameters are not specified,
4672 the whole NAND chip will be erased.
4673 The @var{num} parameter is the value shown by @command{nand list}.
4674
4675 @b{NOTE:} This command will try to erase bad blocks, when told
4676 to do so, which will probably invalidate the manufacturer's bad
4677 block marker.
4678 For the remainder of the current server session, @command{nand info}
4679 will still report that the block ``is'' bad.
4680 @end deffn
4681
4682 @deffn Command {nand write} num filename offset [option...]
4683 @cindex NAND writing
4684 @cindex NAND programming
4685 Writes binary data from the file into the specified NAND device,
4686 starting at the specified offset. Those pages should already
4687 have been erased; you can't change zero bits to one bits.
4688 The @var{num} parameter is the value shown by @command{nand list}.
4689
4690 Use a complete path name for @var{filename}, so you don't depend
4691 on the directory used to start the OpenOCD server.
4692
4693 The @var{offset} must be an exact multiple of the device's page size.
4694 All data in the file will be written, assuming it doesn't run
4695 past the end of the device.
4696 Only full pages are written, and any extra space in the last
4697 page will be filled with 0xff bytes. (That includes OOB data,
4698 if that's being written.)
4699
4700 @b{NOTE:} At the time this text was written, bad blocks are
4701 ignored. That is, this routine will not skip bad blocks,
4702 but will instead try to write them. This can cause problems.
4703
4704 Provide at most one @var{option} parameter. With some
4705 NAND drivers, the meanings of these parameters may change
4706 if @command{nand raw_access} was used to disable hardware ECC.
4707 @itemize @bullet
4708 @item no oob_* parameter
4709 @*File has only page data, which is written.
4710 If raw acccess is in use, the OOB area will not be written.
4711 Otherwise, if the underlying NAND controller driver has
4712 a @code{write_page} routine, that routine may write the OOB
4713 with hardware-computed ECC data.
4714 @item @code{oob_only}
4715 @*File has only raw OOB data, which is written to the OOB area.
4716 Each page's data area stays untouched. @i{This can be a dangerous
4717 option}, since it can invalidate the ECC data.
4718 You may need to force raw access to use this mode.
4719 @item @code{oob_raw}
4720 @*File interleaves data and OOB data, both of which are written
4721 If raw access is enabled, the data is written first, then the
4722 un-altered OOB.
4723 Otherwise, if the underlying NAND controller driver has
4724 a @code{write_page} routine, that routine may modify the OOB
4725 before it's written, to include hardware-computed ECC data.
4726 @item @code{oob_softecc}
4727 @*File has only page data, which is written.
4728 The OOB area is filled with 0xff, except for a standard 1-bit
4729 software ECC code stored in conventional locations.
4730 You might need to force raw access to use this mode, to prevent
4731 the underlying driver from applying hardware ECC.
4732 @item @code{oob_softecc_kw}
4733 @*File has only page data, which is written.
4734 The OOB area is filled with 0xff, except for a 4-bit software ECC
4735 specific to the boot ROM in Marvell Kirkwood SoCs.
4736 You might need to force raw access to use this mode, to prevent
4737 the underlying driver from applying hardware ECC.
4738 @end itemize
4739 @end deffn
4740
4741 @deffn Command {nand verify} num filename offset [option...]
4742 @cindex NAND verification
4743 @cindex NAND programming
4744 Verify the binary data in the file has been programmed to the
4745 specified NAND device, starting at the specified offset.
4746 The @var{num} parameter is the value shown by @command{nand list}.
4747
4748 Use a complete path name for @var{filename}, so you don't depend
4749 on the directory used to start the OpenOCD server.
4750
4751 The @var{offset} must be an exact multiple of the device's page size.
4752 All data in the file will be read and compared to the contents of the
4753 flash, assuming it doesn't run past the end of the device.
4754 As with @command{nand write}, only full pages are verified, so any extra
4755 space in the last page will be filled with 0xff bytes.
4756
4757 The same @var{options} accepted by @command{nand write},
4758 and the file will be processed similarly to produce the buffers that
4759 can be compared against the contents produced from @command{nand dump}.
4760
4761 @b{NOTE:} This will not work when the underlying NAND controller
4762 driver's @code{write_page} routine must update the OOB with a
4763 hardward-computed ECC before the data is written. This limitation may
4764 be removed in a future release.
4765 @end deffn
4766
4767 @section Other NAND commands
4768 @cindex NAND other commands
4769
4770 @deffn Command {nand check_bad_blocks} [offset length]
4771 Checks for manufacturer bad block markers on the specified NAND
4772 device. If no parameters are provided, checks the whole
4773 device; otherwise, starts at the specified @var{offset} and
4774 continues for @var{length} bytes.
4775 Both of those values must be exact multiples of the device's
4776 block size, and the region they specify must fit entirely in the chip.
4777 The @var{num} parameter is the value shown by @command{nand list}.
4778
4779 @b{NOTE:} Before using this command you should force raw access
4780 with @command{nand raw_access enable} to ensure that the underlying
4781 driver will not try to apply hardware ECC.
4782 @end deffn
4783
4784 @deffn Command {nand info} num
4785 The @var{num} parameter is the value shown by @command{nand list}.
4786 This prints the one-line summary from "nand list", plus for
4787 devices which have been probed this also prints any known
4788 status for each block.
4789 @end deffn
4790
4791 @deffn Command {nand raw_access} num (@option{enable}|@option{disable})
4792 Sets or clears an flag affecting how page I/O is done.
4793 The @var{num} parameter is the value shown by @command{nand list}.
4794
4795 This flag is cleared (disabled) by default, but changing that
4796 value won't affect all NAND devices. The key factor is whether
4797 the underlying driver provides @code{read_page} or @code{write_page}
4798 methods. If it doesn't provide those methods, the setting of
4799 this flag is irrelevant; all access is effectively ``raw''.
4800
4801 When those methods exist, they are normally used when reading
4802 data (@command{nand dump} or reading bad block markers) or
4803 writing it (@command{nand write}). However, enabling
4804 raw access (setting the flag) prevents use of those methods,
4805 bypassing hardware ECC logic.
4806 @i{This can be a dangerous option}, since writing blocks
4807 with the wrong ECC data can cause them to be marked as bad.
4808 @end deffn
4809
4810 @anchor{NAND Driver List}
4811 @section NAND Driver List
4812 As noted above, the @command{nand device} command allows
4813 driver-specific options and behaviors.
4814 Some controllers also activate controller-specific commands.
4815
4816 @deffn {NAND Driver} at91sam9
4817 This driver handles the NAND controllers found on AT91SAM9 family chips from
4818 Atmel. It takes two extra parameters: address of the NAND chip;
4819 address of the ECC controller.
4820 @example
4821 nand device $NANDFLASH at91sam9 $CHIPNAME 0x40000000 0xfffffe800
4822 @end example
4823 AT91SAM9 chips support single-bit ECC hardware. The @code{write_page} and
4824 @code{read_page} methods are used to utilize the ECC hardware unless they are
4825 disabled by using the @command{nand raw_access} command. There are four
4826 additional commands that are needed to fully configure the AT91SAM9 NAND
4827 controller. Two are optional; most boards use the same wiring for ALE/CLE:
4828 @deffn Command {at91sam9 cle} num addr_line
4829 Configure the address line used for latching commands. The @var{num}
4830 parameter is the value shown by @command{nand list}.
4831 @end deffn
4832 @deffn Command {at91sam9 ale} num addr_line
4833 Configure the address line used for latching addresses. The @var{num}
4834 parameter is the value shown by @command{nand list}.
4835 @end deffn
4836
4837 For the next two commands, it is assumed that the pins have already been
4838 properly configured for input or output.
4839 @deffn Command {at91sam9 rdy_busy} num pio_base_addr pin
4840 Configure the RDY/nBUSY input from the NAND device. The @var{num}
4841 parameter is the value shown by @command{nand list}. @var{pio_base_addr}
4842 is the base address of the PIO controller and @var{pin} is the pin number.
4843 @end deffn
4844 @deffn Command {at91sam9 ce} num pio_base_addr pin
4845 Configure the chip enable input to the NAND device. The @var{num}
4846 parameter is the value shown by @command{nand list}. @var{pio_base_addr}
4847 is the base address of the PIO controller and @var{pin} is the pin number.
4848 @end deffn
4849 @end deffn
4850
4851 @deffn {NAND Driver} davinci
4852 This driver handles the NAND controllers found on DaVinci family
4853 chips from Texas Instruments.
4854 It takes three extra parameters:
4855 address of the NAND chip;
4856 hardware ECC mode to use (@option{hwecc1},
4857 @option{hwecc4}, @option{hwecc4_infix});
4858 address of the AEMIF controller on this processor.
4859 @example
4860 nand device davinci dm355.arm 0x02000000 hwecc4 0x01e10000
4861 @end example
4862 All DaVinci processors support the single-bit ECC hardware,
4863 and newer ones also support the four-bit ECC hardware.
4864 The @code{write_page} and @code{read_page} methods are used
4865 to implement those ECC modes, unless they are disabled using
4866 the @command{nand raw_access} command.
4867 @end deffn
4868
4869 @deffn {NAND Driver} lpc3180
4870 These controllers require an extra @command{nand device}
4871 parameter: the clock rate used by the controller.
4872 @deffn Command {lpc3180 select} num [mlc|slc]
4873 Configures use of the MLC or SLC controller mode.
4874 MLC implies use of hardware ECC.
4875 The @var{num} parameter is the value shown by @command{nand list}.
4876 @end deffn
4877
4878 At this writing, this driver includes @code{write_page}
4879 and @code{read_page} methods. Using @command{nand raw_access}
4880 to disable those methods will prevent use of hardware ECC
4881 in the MLC controller mode, but won't change SLC behavior.
4882 @end deffn
4883 @comment current lpc3180 code won't issue 5-byte address cycles
4884
4885 @deffn {NAND Driver} orion
4886 These controllers require an extra @command{nand device}
4887 parameter: the address of the controller.
4888 @example
4889 nand device orion 0xd8000000
4890 @end example
4891 These controllers don't define any specialized commands.
4892 At this writing, their drivers don't include @code{write_page}
4893 or @code{read_page} methods, so @command{nand raw_access} won't
4894 change any behavior.
4895 @end deffn
4896
4897 @deffn {NAND Driver} s3c2410
4898 @deffnx {NAND Driver} s3c2412
4899 @deffnx {NAND Driver} s3c2440
4900 @deffnx {NAND Driver} s3c2443
4901 These S3C24xx family controllers don't have any special
4902 @command{nand device} options, and don't define any
4903 specialized commands.
4904 At this writing, their drivers don't include @code{write_page}
4905 or @code{read_page} methods, so @command{nand raw_access} won't
4906 change any behavior.
4907 @end deffn
4908
4909 @node PLD/FPGA Commands
4910 @chapter PLD/FPGA Commands
4911 @cindex PLD
4912 @cindex FPGA
4913
4914 Programmable Logic Devices (PLDs) and the more flexible
4915 Field Programmable Gate Arrays (FPGAs) are both types of programmable hardware.
4916 OpenOCD can support programming them.
4917 Although PLDs are generally restrictive (cells are less functional, and
4918 there are no special purpose cells for memory or computational tasks),
4919 they share the same OpenOCD infrastructure.
4920 Accordingly, both are called PLDs here.
4921
4922 @section PLD/FPGA Configuration and Commands
4923
4924 As it does for JTAG TAPs, debug targets, and flash chips (both NOR and NAND),
4925 OpenOCD maintains a list of PLDs available for use in various commands.
4926 Also, each such PLD requires a driver.
4927
4928 They are referenced by the number shown by the @command{pld devices} command,
4929 and new PLDs are defined by @command{pld device driver_name}.
4930
4931 @deffn {Config Command} {pld device} driver_name tap_name [driver_options]
4932 Defines a new PLD device, supported by driver @var{driver_name},
4933 using the TAP named @var{tap_name}.
4934 The driver may make use of any @var{driver_options} to configure its
4935 behavior.
4936 @end deffn
4937
4938 @deffn {Command} {pld devices}
4939 Lists the PLDs and their numbers.
4940 @end deffn
4941
4942 @deffn {Command} {pld load} num filename
4943 Loads the file @file{filename} into the PLD identified by @var{num}.
4944 The file format must be inferred by the driver.
4945 @end deffn
4946
4947 @section PLD/FPGA Drivers, Options, and Commands
4948
4949 Drivers may support PLD-specific options to the @command{pld device}
4950 definition command, and may also define commands usable only with
4951 that particular type of PLD.
4952
4953 @deffn {FPGA Driver} virtex2
4954 Virtex-II is a family of FPGAs sold by Xilinx.
4955 It supports the IEEE 1532 standard for In-System Configuration (ISC).
4956 No driver-specific PLD definition options are used,
4957 and one driver-specific command is defined.
4958
4959 @deffn {Command} {virtex2 read_stat} num
4960 Reads and displays the Virtex-II status register (STAT)
4961 for FPGA @var{num}.
4962 @end deffn
4963 @end deffn
4964
4965 @node General Commands
4966 @chapter General Commands
4967 @cindex commands
4968
4969 The commands documented in this chapter here are common commands that
4970 you, as a human, may want to type and see the output of. Configuration type
4971 commands are documented elsewhere.
4972
4973 Intent:
4974 @itemize @bullet
4975 @item @b{Source Of Commands}
4976 @* OpenOCD commands can occur in a configuration script (discussed
4977 elsewhere) or typed manually by a human or supplied programatically,
4978 or via one of several TCP/IP Ports.
4979
4980 @item @b{From the human}
4981 @* A human should interact with the telnet interface (default port: 4444)
4982 or via GDB (default port 3333).
4983
4984 To issue commands from within a GDB session, use the @option{monitor}
4985 command, e.g. use @option{monitor poll} to issue the @option{poll}
4986 command. All output is relayed through the GDB session.
4987
4988 @item @b{Machine Interface}
4989 The Tcl interface's intent is to be a machine interface. The default Tcl
4990 port is 5555.
4991 @end itemize
4992
4993
4994 @section Daemon Commands
4995
4996 @deffn {Command} exit
4997 Exits the current telnet session.
4998 @end deffn
4999
5000 @c note EXTREMELY ANNOYING word wrap at column 75
5001 @c even when lines are e.g. 100+ columns ...
5002 @c coded in startup.tcl
5003 @deffn {Command} help [string]
5004 With no parameters, prints help text for all commands.
5005 Otherwise, prints each helptext containing @var{string}.
5006 Not every command provides helptext.
5007 @end deffn
5008
5009 @deffn Command sleep msec [@option{busy}]
5010 Wait for at least @var{msec} milliseconds before resuming.
5011 If @option{busy} is passed, busy-wait instead of sleeping.
5012 (This option is strongly discouraged.)
5013 Useful in connection with script files
5014 (@command{script} command and @command{target_name} configuration).
5015 @end deffn
5016
5017 @deffn Command shutdown
5018 Close the OpenOCD daemon, disconnecting all clients (GDB, telnet, other).
5019 @end deffn
5020
5021 @anchor{debug_level}
5022 @deffn Command debug_level [n]
5023 @cindex message level
5024 Display debug level.
5025 If @var{n} (from 0..3) is provided, then set it to that level.
5026 This affects the kind of messages sent to the server log.
5027 Level 0 is error messages only;
5028 level 1 adds warnings;
5029 level 2 adds informational messages;
5030 and level 3 adds debugging messages.
5031 The default is level 2, but that can be overridden on
5032 the command line along with the location of that log
5033 file (which is normally the server's standard output).
5034 @xref{Running}.
5035 @end deffn
5036
5037 @deffn Command fast (@option{enable}|@option{disable})
5038 Default disabled.
5039 Set default behaviour of OpenOCD to be "fast and dangerous".
5040
5041 At this writing, this only affects the defaults for two ARM7/ARM9 parameters:
5042 fast memory access, and DCC downloads. Those parameters may still be
5043 individually overridden.
5044
5045 The target specific "dangerous" optimisation tweaking options may come and go
5046 as more robust and user friendly ways are found to ensure maximum throughput
5047 and robustness with a minimum of configuration.
5048
5049 Typically the "fast enable" is specified first on the command line:
5050
5051 @example
5052 openocd -c "fast enable" -c "interface dummy" -f target/str710.cfg
5053 @end example
5054 @end deffn
5055
5056 @deffn Command echo message
5057 Logs a message at "user" priority.
5058 Output @var{message} to stdout.
5059 @example
5060 echo "Downloading kernel -- please wait"
5061 @end example
5062 @end deffn
5063
5064 @deffn Command log_output [filename]
5065 Redirect logging to @var{filename};
5066 the initial log output channel is stderr.
5067 @end deffn
5068
5069 @anchor{Target State handling}
5070 @section Target State handling
5071 @cindex reset
5072 @cindex halt
5073 @cindex target initialization
5074
5075 In this section ``target'' refers to a CPU configured as
5076 shown earlier (@pxref{CPU Configuration}).
5077 These commands, like many, implicitly refer to
5078 a current target which is used to perform the
5079 various operations. The current target may be changed
5080 by using @command{targets} command with the name of the
5081 target which should become current.
5082
5083 @deffn Command reg [(number|name) [value]]
5084 Access a single register by @var{number} or by its @var{name}.
5085 The target must generally be halted before access to CPU core
5086 registers is allowed. Depending on the hardware, some other
5087 registers may be accessible while the target is running.
5088
5089 @emph{With no arguments}:
5090 list all available registers for the current target,
5091 showing number, name, size, value, and cache status.
5092 For valid entries, a value is shown; valid entries
5093 which are also dirty (and will be written back later)
5094 are flagged as such.
5095
5096 @emph{With number/name}: display that register's value.
5097
5098 @emph{With both number/name and value}: set register's value.
5099 Writes may be held in a writeback cache internal to OpenOCD,
5100 so that setting the value marks the register as dirty instead
5101 of immediately flushing that value. Resuming CPU execution
5102 (including by single stepping) or otherwise activating the
5103 relevant module will flush such values.
5104
5105 Cores may have surprisingly many registers in their
5106 Debug and trace infrastructure:
5107
5108 @example
5109 > reg
5110 ===== ARM registers
5111 (0) r0 (/32): 0x0000D3C2 (dirty)
5112 (1) r1 (/32): 0xFD61F31C
5113 (2) r2 (/32)
5114 ...
5115 (164) ETM_contextid_comparator_mask (/32)
5116 >
5117 @end example
5118 @end deffn
5119
5120 @deffn Command halt [ms]
5121 @deffnx Command wait_halt [ms]
5122 The @command{halt} command first sends a halt request to the target,
5123 which @command{wait_halt} doesn't.
5124 Otherwise these behave the same: wait up to @var{ms} milliseconds,
5125 or 5 seconds if there is no parameter, for the target to halt
5126 (and enter debug mode).
5127 Using 0 as the @var{ms} parameter prevents OpenOCD from waiting.
5128
5129 @quotation Warning
5130 On ARM cores, software using the @emph{wait for interrupt} operation
5131 often blocks the JTAG access needed by a @command{halt} command.
5132 This is because that operation also puts the core into a low
5133 power mode by gating the core clock;
5134 but the core clock is needed to detect JTAG clock transitions.
5135
5136 One partial workaround uses adaptive clocking: when the core is
5137 interrupted the operation completes, then JTAG clocks are accepted
5138 at least until the interrupt handler completes.
5139 However, this workaround is often unusable since the processor, board,
5140 and JTAG adapter must all support adaptive JTAG clocking.
5141 Also, it can't work until an interrupt is issued.
5142
5143 A more complete workaround is to not use that operation while you
5144 work with a JTAG debugger.
5145 Tasking environments generaly have idle loops where the body is the
5146 @emph{wait for interrupt} operation.
5147 (On older cores, it is a coprocessor action;
5148 newer cores have a @option{wfi} instruction.)
5149 Such loops can just remove that operation, at the cost of higher
5150 power consumption (because the CPU is needlessly clocked).
5151 @end quotation
5152
5153 @end deffn
5154
5155 @deffn Command resume [address]
5156 Resume the target at its current code position,
5157 or the optional @var{address} if it is provided.
5158 OpenOCD will wait 5 seconds for the target to resume.
5159 @end deffn
5160
5161 @deffn Command step [address]
5162 Single-step the target at its current code position,
5163 or the optional @var{address} if it is provided.
5164 @end deffn
5165
5166 @anchor{Reset Command}
5167 @deffn Command reset
5168 @deffnx Command {reset run}
5169 @deffnx Command {reset halt}
5170 @deffnx Command {reset init}
5171 Perform as hard a reset as possible, using SRST if possible.
5172 @emph{All defined targets will be reset, and target
5173 events will fire during the reset sequence.}
5174
5175 The optional parameter specifies what should
5176 happen after the reset.
5177 If there is no parameter, a @command{reset run} is executed.
5178 The other options will not work on all systems.
5179 @xref{Reset Configuration}.
5180
5181 @itemize @minus
5182 @item @b{run} Let the target run
5183 @item @b{halt} Immediately halt the target
5184 @item @b{init} Immediately halt the target, and execute the reset-init script
5185 @end itemize
5186 @end deffn
5187
5188 @deffn Command soft_reset_halt
5189 Requesting target halt and executing a soft reset. This is often used
5190 when a target cannot be reset and halted. The target, after reset is
5191 released begins to execute code. OpenOCD attempts to stop the CPU and
5192 then sets the program counter back to the reset vector. Unfortunately
5193 the code that was executed may have left the hardware in an unknown
5194 state.
5195 @end deffn
5196
5197 @section I/O Utilities
5198
5199 These commands are available when
5200 OpenOCD is built with @option{--enable-ioutil}.
5201 They are mainly useful on embedded targets,
5202 notably the ZY1000.
5203 Hosts with operating systems have complementary tools.
5204
5205 @emph{Note:} there are several more such commands.
5206
5207 @deffn Command append_file filename [string]*
5208 Appends the @var{string} parameters to
5209 the text file @file{filename}.
5210 Each string except the last one is followed by one space.
5211 The last string is followed by a newline.
5212 @end deffn
5213
5214 @deffn Command cat filename
5215 Reads and displays the text file @file{filename}.
5216 @end deffn
5217
5218 @deffn Command cp src_filename dest_filename
5219 Copies contents from the file @file{src_filename}
5220 into @file{dest_filename}.
5221 @end deffn
5222
5223 @deffn Command ip
5224 @emph{No description provided.}
5225 @end deffn
5226
5227 @deffn Command ls
5228 @emph{No description provided.}
5229 @end deffn
5230
5231 @deffn Command mac
5232 @emph{No description provided.}
5233 @end deffn
5234
5235 @deffn Command meminfo
5236 Display available RAM memory on OpenOCD host.
5237 Used in OpenOCD regression testing scripts.
5238 @end deffn
5239
5240 @deffn Command peek
5241 @emph{No description provided.}
5242 @end deffn
5243
5244 @deffn Command poke
5245 @emph{No description provided.}
5246 @end deffn
5247
5248 @deffn Command rm filename
5249 @c "rm" has both normal and Jim-level versions??
5250 Unlinks the file @file{filename}.
5251 @end deffn
5252
5253 @deffn Command trunc filename
5254 Removes all data in the file @file{filename}.
5255 @end deffn
5256
5257 @anchor{Memory access}
5258 @section Memory access commands
5259 @cindex memory access
5260
5261 These commands allow accesses of a specific size to the memory
5262 system. Often these are used to configure the current target in some
5263 special way. For example - one may need to write certain values to the
5264 SDRAM controller to enable SDRAM.
5265
5266 @enumerate
5267 @item Use the @command{targets} (plural) command
5268 to change the current target.
5269 @item In system level scripts these commands are deprecated.
5270 Please use their TARGET object siblings to avoid making assumptions
5271 about what TAP is the current target, or about MMU configuration.
5272 @end enumerate
5273
5274 @deffn Command mdw [phys] addr [count]
5275 @deffnx Command mdh [phys] addr [count]
5276 @deffnx Command mdb [phys] addr [count]
5277 Display contents of address @var{addr}, as
5278 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
5279 or 8-bit bytes (@command{mdb}).
5280 When the current target has an MMU which is present and active,
5281 @var{addr} is interpreted as a virtual address.
5282 Otherwise, or if the optional @var{phys} flag is specified,
5283 @var{addr} is interpreted as a physical address.
5284 If @var{count} is specified, displays that many units.
5285 (If you want to manipulate the data instead of displaying it,
5286 see the @code{mem2array} primitives.)
5287 @end deffn
5288
5289 @deffn Command mww [phys] addr word
5290 @deffnx Command mwh [phys] addr halfword
5291 @deffnx Command mwb [phys] addr byte
5292 Writes the specified @var{word} (32 bits),
5293 @var{halfword} (16 bits), or @var{byte} (8-bit) value,
5294 at the specified address @var{addr}.
5295 When the current target has an MMU which is present and active,
5296 @var{addr} is interpreted as a virtual address.
5297 Otherwise, or if the optional @var{phys} flag is specified,
5298 @var{addr} is interpreted as a physical address.
5299 @end deffn
5300
5301
5302 @anchor{Image access}
5303 @section Image loading commands
5304 @cindex image loading
5305 @cindex image dumping
5306
5307 @anchor{dump_image}
5308 @deffn Command {dump_image} filename address size
5309 Dump @var{size} bytes of target memory starting at @var{address} to the
5310 binary file named @var{filename}.
5311 @end deffn
5312
5313 @deffn Command {fast_load}
5314 Loads an image stored in memory by @command{fast_load_image} to the
5315 current target. Must be preceeded by fast_load_image.
5316 @end deffn
5317
5318 @deffn Command {fast_load_image} filename address [@option{bin}|@option{ihex}|@option{elf}]
5319 Normally you should be using @command{load_image} or GDB load. However, for
5320 testing purposes or when I/O overhead is significant(OpenOCD running on an embedded
5321 host), storing the image in memory and uploading the image to the target
5322 can be a way to upload e.g. multiple debug sessions when the binary does not change.
5323 Arguments are the same as @command{load_image}, but the image is stored in OpenOCD host
5324 memory, i.e. does not affect target. This approach is also useful when profiling
5325 target programming performance as I/O and target programming can easily be profiled
5326 separately.
5327 @end deffn
5328
5329 @anchor{load_image}
5330 @deffn Command {load_image} filename address [@option{bin}|@option{ihex}|@option{elf}]
5331 Load image from file @var{filename} to target memory at @var{address}.
5332 The file format may optionally be specified
5333 (@option{bin}, @option{ihex}, or @option{elf})
5334 @end deffn
5335
5336 @deffn Command {test_image} filename [address [@option{bin}|@option{ihex}|@option{elf}]]
5337 Displays image section sizes and addresses
5338 as if @var{filename} were loaded into target memory
5339 starting at @var{address} (defaults to zero).
5340 The file format may optionally be specified
5341 (@option{bin}, @option{ihex}, or @option{elf})
5342 @end deffn
5343
5344 @deffn Command {verify_image} filename address [@option{bin}|@option{ihex}|@option{elf}]
5345 Verify @var{filename} against target memory starting at @var{address}.
5346 The file format may optionally be specified
5347 (@option{bin}, @option{ihex}, or @option{elf})
5348 This will first attempt a comparison using a CRC checksum, if this fails it will try a binary compare.
5349 @end deffn
5350
5351
5352 @section Breakpoint and Watchpoint commands
5353 @cindex breakpoint
5354 @cindex watchpoint
5355
5356 CPUs often make debug modules accessible through JTAG, with
5357 hardware support for a handful of code breakpoints and data
5358 watchpoints.
5359 In addition, CPUs almost always support software breakpoints.
5360
5361 @deffn Command {bp} [address len [@option{hw}]]
5362 With no parameters, lists all active breakpoints.
5363 Else sets a breakpoint on code execution starting
5364 at @var{address} for @var{length} bytes.
5365 This is a software breakpoint, unless @option{hw} is specified
5366 in which case it will be a hardware breakpoint.
5367
5368 (@xref{arm9 vector_catch}, or @pxref{xscale vector_catch},
5369 for similar mechanisms that do not consume hardware breakpoints.)
5370 @end deffn
5371
5372 @deffn Command {rbp} address
5373 Remove the breakpoint at @var{address}.
5374 @end deffn
5375
5376 @deffn Command {rwp} address
5377 Remove data watchpoint on @var{address}
5378 @end deffn
5379
5380 @deffn Command {wp} [address len [(@option{r}|@option{w}|@option{a}) [value [mask]]]]
5381 With no parameters, lists all active watchpoints.
5382 Else sets a data watchpoint on data from @var{address} for @var{length} bytes.
5383 The watch point is an "access" watchpoint unless
5384 the @option{r} or @option{w} parameter is provided,
5385 defining it as respectively a read or write watchpoint.
5386 If a @var{value} is provided, that value is used when determining if
5387 the watchpoint should trigger. The value may be first be masked
5388 using @var{mask} to mark ``don't care'' fields.
5389 @end deffn
5390
5391 @section Misc Commands
5392
5393 @cindex profiling
5394 @deffn Command {profile} seconds filename
5395 Profiling samples the CPU's program counter as quickly as possible,
5396 which is useful for non-intrusive stochastic profiling.
5397 Saves up to 10000 sampines in @file{filename} using ``gmon.out'' format.
5398 @end deffn
5399
5400 @deffn Command {version}
5401 Displays a string identifying the version of this OpenOCD server.
5402 @end deffn
5403
5404 @deffn Command {virt2phys} virtual_address
5405 Requests the current target to map the specified @var{virtual_address}
5406 to its corresponding physical address, and displays the result.
5407 @end deffn
5408
5409 @node Architecture and Core Commands
5410 @chapter Architecture and Core Commands
5411 @cindex Architecture Specific Commands
5412 @cindex Core Specific Commands
5413
5414 Most CPUs have specialized JTAG operations to support debugging.
5415 OpenOCD packages most such operations in its standard command framework.
5416 Some of those operations don't fit well in that framework, so they are
5417 exposed here as architecture or implementation (core) specific commands.
5418
5419 @anchor{ARM Hardware Tracing}
5420 @section ARM Hardware Tracing
5421 @cindex tracing
5422 @cindex ETM
5423 @cindex ETB
5424
5425 CPUs based on ARM cores may include standard tracing interfaces,
5426 based on an ``Embedded Trace Module'' (ETM) which sends voluminous
5427 address and data bus trace records to a ``Trace Port''.
5428
5429 @itemize
5430 @item
5431 Development-oriented boards will sometimes provide a high speed
5432 trace connector for collecting that data, when the particular CPU
5433 supports such an interface.
5434 (The standard connector is a 38-pin Mictor, with both JTAG
5435 and trace port support.)
5436 Those trace connectors are supported by higher end JTAG adapters
5437 and some logic analyzer modules; frequently those modules can
5438 buffer several megabytes of trace data.
5439 Configuring an ETM coupled to such an external trace port belongs
5440 in the board-specific configuration file.
5441 @item
5442 If the CPU doesn't provide an external interface, it probably
5443 has an ``Embedded Trace Buffer'' (ETB) on the chip, which is a
5444 dedicated SRAM. 4KBytes is one common ETB size.
5445 Configuring an ETM coupled only to an ETB belongs in the CPU-specific
5446 (target) configuration file, since it works the same on all boards.
5447 @end itemize
5448
5449 ETM support in OpenOCD doesn't seem to be widely used yet.
5450
5451 @quotation Issues
5452 ETM support may be buggy, and at least some @command{etm config}
5453 parameters should be detected by asking the ETM for them.
5454
5455 ETM trigger events could also implement a kind of complex
5456 hardware breakpoint, much more powerful than the simple
5457 watchpoint hardware exported by EmbeddedICE modules.
5458 @emph{Such breakpoints can be triggered even when using the
5459 dummy trace port driver}.
5460
5461 It seems like a GDB hookup should be possible,
5462 as well as tracing only during specific states
5463 (perhaps @emph{handling IRQ 23} or @emph{calls foo()}).
5464
5465 There should be GUI tools to manipulate saved trace data and help
5466 analyse it in conjunction with the source code.
5467 It's unclear how much of a common interface is shared
5468 with the current XScale trace support, or should be
5469 shared with eventual Nexus-style trace module support.
5470
5471 At this writing (November 2009) only ARM7, ARM9, and ARM11 support
5472 for ETM modules is available. The code should be able to
5473 work with some newer cores; but not all of them support
5474 this original style of JTAG access.
5475 @end quotation
5476
5477 @subsection ETM Configuration
5478 ETM setup is coupled with the trace port driver configuration.
5479
5480 @deffn {Config Command} {etm config} target width mode clocking driver
5481 Declares the ETM associated with @var{target}, and associates it
5482 with a given trace port @var{driver}. @xref{Trace Port Drivers}.
5483
5484 Several of the parameters must reflect the trace port capabilities,
5485 which are a function of silicon capabilties (exposed later
5486 using @command{etm info}) and of what hardware is connected to
5487 that port (such as an external pod, or ETB).
5488 The @var{width} must be either 4, 8, or 16,
5489 except with ETMv3.0 and newer modules which may also
5490 support 1, 2, 24, 32, 48, and 64 bit widths.
5491 (With those versions, @command{etm info} also shows whether
5492 the selected port width and mode are supported.)
5493
5494 The @var{mode} must be @option{normal}, @option{multiplexed},
5495 or @option{demultiplexed}.
5496 The @var{clocking} must be @option{half} or @option{full}.
5497
5498 @quotation Warning
5499 With ETMv3.0 and newer, the bits set with the @var{mode} and
5500 @var{clocking} parameters both control the mode.
5501 This modified mode does not map to the values supported by
5502 previous ETM modules, so this syntax is subject to change.
5503 @end quotation
5504
5505 @quotation Note
5506 You can see the ETM registers using the @command{reg} command.
5507 Not all possible registers are present in every ETM.
5508 Most of the registers are write-only, and are used to configure
5509 what CPU activities are traced.
5510 @end quotation
5511 @end deffn
5512
5513 @deffn Command {etm info}
5514 Displays information about the current target's ETM.
5515 This includes resource counts from the @code{ETM_CONFIG} register,
5516 as well as silicon capabilities (except on rather old modules).
5517 from the @code{ETM_SYS_CONFIG} register.
5518 @end deffn
5519
5520 @deffn Command {etm status}
5521 Displays status of the current target's ETM and trace port driver:
5522 is the ETM idle, or is it collecting data?
5523 Did trace data overflow?
5524 Was it triggered?
5525 @end deffn
5526
5527 @deffn Command {etm tracemode} [type context_id_bits cycle_accurate branch_output]
5528 Displays what data that ETM will collect.
5529 If arguments are provided, first configures that data.
5530 When the configuration changes, tracing is stopped
5531 and any buffered trace data is invalidated.
5532
5533 @itemize
5534 @item @var{type} ... describing how data accesses are traced,
5535 when they pass any ViewData filtering that that was set up.
5536 The value is one of
5537 @option{none} (save nothing),
5538 @option{data} (save data),
5539 @option{address} (save addresses),
5540 @option{all} (save data and addresses)
5541 @item @var{context_id_bits} ... 0, 8, 16, or 32
5542 @item @var{cycle_accurate} ... @option{enable} or @option{disable}
5543 cycle-accurate instruction tracing.
5544 Before ETMv3, enabling this causes much extra data to be recorded.
5545 @item @var{branch_output} ... @option{enable} or @option{disable}.
5546 Disable this unless you need to try reconstructing the instruction
5547 trace stream without an image of the code.
5548 @end itemize
5549 @end deffn
5550
5551 @deffn Command {etm trigger_debug} (@option{enable}|@option{disable})
5552 Displays whether ETM triggering debug entry (like a breakpoint) is
5553 enabled or disabled, after optionally modifying that configuration.
5554 The default behaviour is @option{disable}.
5555 Any change takes effect after the next @command{etm start}.
5556
5557 By using script commands to configure ETM registers, you can make the
5558 processor enter debug state automatically when certain conditions,
5559 more complex than supported by the breakpoint hardware, happen.
5560 @end deffn
5561
5562 @subsection ETM Trace Operation
5563
5564 After setting up the ETM, you can use it to collect data.
5565 That data can be exported to files for later analysis.
5566 It can also be parsed with OpenOCD, for basic sanity checking.
5567
5568 To configure what is being traced, you will need to write
5569 various trace registers using @command{reg ETM_*} commands.
5570 For the definitions of these registers, read ARM publication
5571 @emph{IHI 0014, ``Embedded Trace Macrocell, Architecture Specification''}.
5572 Be aware that most of the relevant registers are write-only,
5573 and that ETM resources are limited. There are only a handful
5574 of address comparators, data comparators, counters, and so on.
5575
5576 Examples of scenarios you might arrange to trace include:
5577
5578 @itemize
5579 @item Code flow within a function, @emph{excluding} subroutines
5580 it calls. Use address range comparators to enable tracing
5581 for instruction access within that function's body.
5582 @item Code flow within a function, @emph{including} subroutines
5583 it calls. Use the sequencer and address comparators to activate
5584 tracing on an ``entered function'' state, then deactivate it by
5585 exiting that state when the function's exit code is invoked.
5586 @item Code flow starting at the fifth invocation of a function,
5587 combining one of the above models with a counter.
5588 @item CPU data accesses to the registers for a particular device,
5589 using address range comparators and the ViewData logic.
5590 @item Such data accesses only during IRQ handling, combining the above
5591 model with sequencer triggers which on entry and exit to the IRQ handler.
5592 @item @emph{... more}
5593 @end itemize
5594
5595 At this writing, September 2009, there are no Tcl utility
5596 procedures to help set up any common tracing scenarios.
5597
5598 @deffn Command {etm analyze}
5599 Reads trace data into memory, if it wasn't already present.
5600 Decodes and prints the data that was collected.
5601 @end deffn
5602
5603 @deffn Command {etm dump} filename
5604 Stores the captured trace data in @file{filename}.
5605 @end deffn
5606
5607 @deffn Command {etm image} filename [base_address] [type]
5608 Opens an image file.
5609 @end deffn
5610
5611 @deffn Command {etm load} filename
5612 Loads captured trace data from @file{filename}.
5613 @end deffn
5614
5615 @deffn Command {etm start}
5616 Starts trace data collection.
5617 @end deffn
5618
5619 @deffn Command {etm stop}
5620 Stops trace data collection.
5621 @end deffn
5622
5623 @anchor{Trace Port Drivers}
5624 @subsection Trace Port Drivers
5625
5626 To use an ETM trace port it must be associated with a driver.
5627
5628 @deffn {Trace Port Driver} dummy
5629 Use the @option{dummy} driver if you are configuring an ETM that's
5630 not connected to anything (on-chip ETB or off-chip trace connector).
5631 @emph{This driver lets OpenOCD talk to the ETM, but it does not expose
5632 any trace data collection.}
5633 @deffn {Config Command} {etm_dummy config} target
5634 Associates the ETM for @var{target} with a dummy driver.
5635 @end deffn
5636 @end deffn
5637
5638 @deffn {Trace Port Driver} etb
5639 Use the @option{etb} driver if you are configuring an ETM
5640 to use on-chip ETB memory.
5641 @deffn {Config Command} {etb config} target etb_tap
5642 Associates the ETM for @var{target} with the ETB at @var{etb_tap}.
5643 You can see the ETB registers using the @command{reg} command.
5644 @end deffn
5645 @deffn Command {etb trigger_percent} [percent]
5646 This displays, or optionally changes, ETB behavior after the
5647 ETM's configured @emph{trigger} event fires.
5648 It controls how much more trace data is saved after the (single)
5649 trace trigger becomes active.
5650
5651 @itemize
5652 @item The default corresponds to @emph{trace around} usage,
5653 recording 50 percent data before the event and the rest
5654 afterwards.
5655 @item The minimum value of @var{percent} is 2 percent,
5656 recording almost exclusively data before the trigger.
5657 Such extreme @emph{trace before} usage can help figure out
5658 what caused that event to happen.
5659 @item The maximum value of @var{percent} is 100 percent,
5660 recording data almost exclusively after the event.
5661 This extreme @emph{trace after} usage might help sort out
5662 how the event caused trouble.
5663 @end itemize
5664 @c REVISIT allow "break" too -- enter debug mode.
5665 @end deffn
5666
5667 @end deffn
5668
5669 @deffn {Trace Port Driver} oocd_trace
5670 This driver isn't available unless OpenOCD was explicitly configured
5671 with the @option{--enable-oocd_trace} option. You probably don't want
5672 to configure it unless you've built the appropriate prototype hardware;
5673 it's @emph{proof-of-concept} software.
5674
5675 Use the @option{oocd_trace} driver if you are configuring an ETM that's
5676 connected to an off-chip trace connector.
5677
5678 @deffn {Config Command} {oocd_trace config} target tty
5679 Associates the ETM for @var{target} with a trace driver which
5680 collects data through the serial port @var{tty}.
5681 @end deffn
5682
5683 @deffn Command {oocd_trace resync}
5684 Re-synchronizes with the capture clock.
5685 @end deffn
5686
5687 @deffn Command {oocd_trace status}
5688 Reports whether the capture clock is locked or not.
5689 @end deffn
5690 @end deffn
5691
5692
5693 @section Generic ARM
5694 @cindex ARM
5695
5696 These commands should be available on all ARM processors.
5697 They are available in addition to other core-specific
5698 commands that may be available.
5699
5700 @deffn Command {arm core_state} [@option{arm}|@option{thumb}]
5701 Displays the core_state, optionally changing it to process
5702 either @option{arm} or @option{thumb} instructions.
5703 The target may later be resumed in the currently set core_state.
5704 (Processors may also support the Jazelle state, but
5705 that is not currently supported in OpenOCD.)
5706 @end deffn
5707
5708 @deffn Command {arm disassemble} address [count [@option{thumb}]]
5709 @cindex disassemble
5710 Disassembles @var{count} instructions starting at @var{address}.
5711 If @var{count} is not specified, a single instruction is disassembled.
5712 If @option{thumb} is specified, or the low bit of the address is set,
5713 Thumb2 (mixed 16/32-bit) instructions are used;
5714 else ARM (32-bit) instructions are used.
5715 (Processors may also support the Jazelle state, but
5716 those instructions are not currently understood by OpenOCD.)
5717
5718 Note that all Thumb instructions are Thumb2 instructions,
5719 so older processors (without Thumb2 support) will still
5720 see correct disassembly of Thumb code.
5721 Also, ThumbEE opcodes are the same as Thumb2,
5722 with a handful of exceptions.
5723 ThumbEE disassembly currently has no explicit support.
5724 @end deffn
5725
5726 @deffn Command {arm mcr} pX op1 CRn CRm op2 value
5727 Write @var{value} to a coprocessor @var{pX} register
5728 passing parameters @var{CRn},
5729 @var{CRm}, opcodes @var{opc1} and @var{opc2},
5730 and using the MCR instruction.
5731 (Parameter sequence matches the ARM instruction, but omits
5732 an ARM register.)
5733 @end deffn
5734
5735 @deffn Command {arm mrc} pX coproc op1 CRn CRm op2
5736 Read a coprocessor @var{pX} register passing parameters @var{CRn},
5737 @var{CRm}, opcodes @var{opc1} and @var{opc2},
5738 and the MRC instruction.
5739 Returns the result so it can be manipulated by Jim scripts.
5740 (Parameter sequence matches the ARM instruction, but omits
5741 an ARM register.)
5742 @end deffn
5743
5744 @deffn Command {arm reg}
5745 Display a table of all banked core registers, fetching the current value from every
5746 core mode if necessary.
5747 @end deffn
5748
5749 @section ARMv4 and ARMv5 Architecture
5750 @cindex ARMv4
5751 @cindex ARMv5
5752
5753 The ARMv4 and ARMv5 architectures are widely used in embedded systems,
5754 and introduced core parts of the instruction set in use today.
5755 That includes the Thumb instruction set, introduced in the ARMv4T
5756 variant.
5757
5758 @subsection ARM7 and ARM9 specific commands
5759 @cindex ARM7
5760 @cindex ARM9
5761
5762 These commands are specific to ARM7 and ARM9 cores, like ARM7TDMI, ARM720T,
5763 ARM9TDMI, ARM920T or ARM926EJ-S.
5764 They are available in addition to the ARM commands,
5765 and any other core-specific commands that may be available.
5766
5767 @deffn Command {arm7_9 dbgrq} (@option{enable}|@option{disable})
5768 Control use of the EmbeddedIce DBGRQ signal to force entry into debug mode,
5769 instead of breakpoints. This should be
5770 safe for all but ARM7TDMI--S cores (like Philips LPC).
5771 This feature is enabled by default on most ARM9 cores,
5772 including ARM9TDMI, ARM920T, and ARM926EJ-S.
5773 @end deffn
5774
5775 @deffn Command {arm7_9 dcc_downloads} (@option{enable}|@option{disable})
5776 @cindex DCC
5777 Control the use of the debug communications channel (DCC) to write larger (>128 byte)
5778 amounts of memory. DCC downloads offer a huge speed increase, but might be
5779 unsafe, especially with targets running at very low speeds. This command was introduced
5780 with OpenOCD rev. 60, and requires a few bytes of working area.
5781 @end deffn
5782
5783 @anchor{arm7_9 fast_memory_access}
5784 @deffn Command {arm7_9 fast_memory_access} (@option{enable}|@option{disable})
5785 Enable or disable memory writes and reads that don't check completion of
5786 the operation. This provides a huge speed increase, especially with USB JTAG
5787 cables (FT2232), but might be unsafe if used with targets running at very low
5788 speeds, like the 32kHz startup clock of an AT91RM9200.
5789 @end deffn
5790
5791 @deffn Command {arm7_9 semihosting} [@option{enable}|@option{disable}]
5792 @cindex ARM semihosting
5793 Display status of semihosting, after optionally changing that status.
5794
5795 Semihosting allows for code executing on an ARM target to use the
5796 I/O facilities on the host computer i.e. the system where OpenOCD
5797 is running. The target application must be linked against a library
5798 implementing the ARM semihosting convention that forwards operation
5799 requests by using a special SVC instruction that is trapped at the
5800 Supervisor Call vector by OpenOCD.
5801 @end deffn
5802
5803 @subsection ARM720T specific commands
5804 @cindex ARM720T
5805
5806 These commands are available to ARM720T based CPUs,
5807 which are implementations of the ARMv4T architecture
5808 based on the ARM7TDMI-S integer core.
5809 They are available in addition to the ARM and ARM7/ARM9 commands.
5810
5811 @deffn Command {arm720t cp15} regnum [value]
5812 Display cp15 register @var{regnum};
5813 else if a @var{value} is provided, that value is written to that register.
5814 @end deffn
5815
5816 @subsection ARM9 specific commands
5817 @cindex ARM9
5818
5819 ARM9-family cores are built around ARM9TDMI or ARM9E (including ARM9EJS)
5820 integer processors.
5821 Such cores include the ARM920T, ARM926EJ-S, and ARM966.
5822
5823 @c 9-june-2009: tried this on arm920t, it didn't work.
5824 @c no-params always lists nothing caught, and that's how it acts.
5825 @c 23-oct-2009: doesn't work _consistently_ ... as if the ICE
5826 @c versions have different rules about when they commit writes.
5827
5828 @anchor{arm9 vector_catch}
5829 @deffn Command {arm9 vector_catch} [@option{all}|@option{none}|list]
5830 @cindex vector_catch
5831 Vector Catch hardware provides a sort of dedicated breakpoint
5832 for hardware events such as reset, interrupt, and abort.
5833 You can use this to conserve normal breakpoint resources,
5834 so long as you're not concerned with code that branches directly
5835 to those hardware vectors.
5836
5837 This always finishes by listing the current configuration.
5838 If parameters are provided, it first reconfigures the
5839 vector catch hardware to intercept
5840 @option{all} of the hardware vectors,
5841 @option{none} of them,
5842 or a list with one or more of the following:
5843 @option{reset} @option{undef} @option{swi} @option{pabt} @option{dabt}
5844 @option{irq} @option{fiq}.
5845 @end deffn
5846
5847 @subsection ARM920T specific commands
5848 @cindex ARM920T
5849
5850 These commands are available to ARM920T based CPUs,
5851 which are implementations of the ARMv4T architecture
5852 built using the ARM9TDMI integer core.
5853 They are available in addition to the ARM, ARM7/ARM9,
5854 and ARM9 commands.
5855
5856 @deffn Command {arm920t cache_info}
5857 Print information about the caches found. This allows to see whether your target
5858 is an ARM920T (2x16kByte cache) or ARM922T (2x8kByte cache).
5859 @end deffn
5860
5861 @deffn Command {arm920t cp15} regnum [value]
5862 Display cp15 register @var{regnum};
5863 else if a @var{value} is provided, that value is written to that register.
5864 @end deffn
5865
5866 @deffn Command {arm920t cp15i} opcode [value [address]]
5867 Interpreted access using cp15 @var{opcode}.
5868 If no @var{value} is provided, the result is displayed.
5869 Else if that value is written using the specified @var{address},
5870 or using zero if no other address is not provided.
5871 @end deffn
5872
5873 @deffn Command {arm920t read_cache} filename
5874 Dump the content of ICache and DCache to a file named @file{filename}.
5875 @end deffn
5876
5877 @deffn Command {arm920t read_mmu} filename
5878 Dump the content of the ITLB and DTLB to a file named @file{filename}.
5879 @end deffn
5880
5881 @subsection ARM926ej-s specific commands
5882 @cindex ARM926ej-s
5883
5884 These commands are available to ARM926ej-s based CPUs,
5885 which are implementations of the ARMv5TEJ architecture
5886 based on the ARM9EJ-S integer core.
5887 They are available in addition to the ARM, ARM7/ARM9,
5888 and ARM9 commands.
5889
5890 The Feroceon cores also support these commands, although
5891 they are not built from ARM926ej-s designs.
5892
5893 @deffn Command {arm926ejs cache_info}
5894 Print information about the caches found.
5895 @end deffn
5896
5897 @subsection ARM966E specific commands
5898 @cindex ARM966E
5899
5900 These commands are available to ARM966 based CPUs,
5901 which are implementations of the ARMv5TE architecture.
5902 They are available in addition to the ARM, ARM7/ARM9,
5903 and ARM9 commands.
5904
5905 @deffn Command {arm966e cp15} regnum [value]
5906 Display cp15 register @var{regnum};
5907 else if a @var{value} is provided, that value is written to that register.
5908 @end deffn
5909
5910 @subsection XScale specific commands
5911 @cindex XScale
5912
5913 Some notes about the debug implementation on the XScale CPUs:
5914
5915 The XScale CPU provides a special debug-only mini-instruction cache
5916 (mini-IC) in which exception vectors and target-resident debug handler
5917 code are placed by OpenOCD. In order to get access to the CPU, OpenOCD
5918 must point vector 0 (the reset vector) to the entry of the debug
5919 handler. However, this means that the complete first cacheline in the
5920 mini-IC is marked valid, which makes the CPU fetch all exception
5921 handlers from the mini-IC, ignoring the code in RAM.
5922
5923 OpenOCD currently does not sync the mini-IC entries with the RAM
5924 contents (which would fail anyway while the target is running), so
5925 the user must provide appropriate values using the @code{xscale
5926 vector_table} command.
5927
5928 It is recommended to place a pc-relative indirect branch in the vector
5929 table, and put the branch destination somewhere in memory. Doing so
5930 makes sure the code in the vector table stays constant regardless of
5931 code layout in memory:
5932 @example
5933 _vectors:
5934 ldr pc,[pc,#0x100-8]
5935 ldr pc,[pc,#0x100-8]
5936 ldr pc,[pc,#0x100-8]
5937 ldr pc,[pc,#0x100-8]
5938 ldr pc,[pc,#0x100-8]
5939 ldr pc,[pc,#0x100-8]
5940 ldr pc,[pc,#0x100-8]
5941 ldr pc,[pc,#0x100-8]
5942 .org 0x100
5943 .long real_reset_vector
5944 .long real_ui_handler
5945 .long real_swi_handler
5946 .long real_pf_abort
5947 .long real_data_abort
5948 .long 0 /* unused */
5949 .long real_irq_handler
5950 .long real_fiq_handler
5951 @end example
5952
5953 The debug handler must be placed somewhere in the address space using
5954 the @code{xscale debug_handler} command. The allowed locations for the
5955 debug handler are either (0x800 - 0x1fef800) or (0xfe000800 -
5956 0xfffff800). The default value is 0xfe000800.
5957
5958
5959 These commands are available to XScale based CPUs,
5960 which are implementations of the ARMv5TE architecture.
5961
5962 @deffn Command {xscale analyze_trace}
5963 Displays the contents of the trace buffer.
5964 @end deffn
5965
5966 @deffn Command {xscale cache_clean_address} address
5967 Changes the address used when cleaning the data cache.
5968 @end deffn
5969
5970 @deffn Command {xscale cache_info}
5971 Displays information about the CPU caches.
5972 @end deffn
5973
5974 @deffn Command {xscale cp15} regnum [value]
5975 Display cp15 register @var{regnum};
5976 else if a @var{value} is provided, that value is written to that register.
5977 @end deffn
5978
5979 @deffn Command {xscale debug_handler} target address
5980 Changes the address used for the specified target's debug handler.
5981 @end deffn
5982
5983 @deffn Command {xscale dcache} (@option{enable}|@option{disable})
5984 Enables or disable the CPU's data cache.
5985 @end deffn
5986
5987 @deffn Command {xscale dump_trace} filename
5988 Dumps the raw contents of the trace buffer to @file{filename}.
5989 @end deffn
5990
5991 @deffn Command {xscale icache} (@option{enable}|@option{disable})
5992 Enables or disable the CPU's instruction cache.
5993 @end deffn
5994
5995 @deffn Command {xscale mmu} (@option{enable}|@option{disable})
5996 Enables or disable the CPU's memory management unit.
5997 @end deffn
5998
5999 @deffn Command {xscale trace_buffer} (@option{enable}|@option{disable}) [@option{fill} [n] | @option{wrap}]
6000 Enables or disables the trace buffer,
6001 and controls how it is emptied.
6002 @end deffn
6003
6004 @deffn Command {xscale trace_image} filename [offset [type]]
6005 Opens a trace image from @file{filename}, optionally rebasing
6006 its segment addresses by @var{offset}.
6007 The image @var{type} may be one of
6008 @option{bin} (binary), @option{ihex} (Intel hex),
6009 @option{elf} (ELF file), @option{s19} (Motorola s19),
6010 @option{mem}, or @option{builder}.
6011 @end deffn
6012
6013 @anchor{xscale vector_catch}
6014 @deffn Command {xscale vector_catch} [mask]
6015 @cindex vector_catch
6016 Display a bitmask showing the hardware vectors to catch.
6017 If the optional parameter is provided, first set the bitmask to that value.
6018
6019 The mask bits correspond with bit 16..23 in the DCSR:
6020 @example
6021 0x01 Trap Reset
6022 0x02 Trap Undefined Instructions
6023 0x04 Trap Software Interrupt
6024 0x08 Trap Prefetch Abort
6025 0x10 Trap Data Abort
6026 0x20 reserved
6027 0x40 Trap IRQ
6028 0x80 Trap FIQ
6029 @end example
6030 @end deffn
6031
6032 @anchor{xscale vector_table}
6033 @deffn Command {xscale vector_table} [<low|high> <index> <value>]
6034 @cindex vector_table
6035
6036 Set an entry in the mini-IC vector table. There are two tables: one for
6037 low vectors (at 0x00000000), and one for high vectors (0xFFFF0000), each
6038 holding the 8 exception vectors. @var{index} can be 1-7, because vector 0
6039 points to the debug handler entry and can not be overwritten.
6040 @var{value} holds the 32-bit opcode that is placed in the mini-IC.
6041
6042 Without arguments, the current settings are displayed.
6043
6044 @end deffn
6045
6046 @section ARMv6 Architecture
6047 @cindex ARMv6
6048
6049 @subsection ARM11 specific commands
6050 @cindex ARM11
6051
6052 @deffn Command {arm11 memwrite burst} [value]
6053 Displays the value of the memwrite burst-enable flag,
6054 which is enabled by default. Burst writes are only used
6055 for memory writes larger than 1 word. Single word writes
6056 are likely to be from reset init scripts and those writes
6057 are often to non-memory locations which could easily have
6058 many wait states, which could easily break burst writes.
6059 If @var{value} is defined, first assigns that.
6060 @end deffn
6061
6062 @deffn Command {arm11 memwrite error_fatal} [value]
6063 Displays the value of the memwrite error_fatal flag,
6064 which is enabled by default.
6065 If @var{value} is defined, first assigns that.
6066 @end deffn
6067
6068 @deffn Command {arm11 step_irq_enable} [value]
6069 Displays the value of the flag controlling whether
6070 IRQs are enabled during single stepping;
6071 they are disabled by default.
6072 If @var{value} is defined, first assigns that.
6073 @end deffn
6074
6075 @deffn Command {arm11 vcr} [value]
6076 @cindex vector_catch
6077 Displays the value of the @emph{Vector Catch Register (VCR)},
6078 coprocessor 14 register 7.
6079 If @var{value} is defined, first assigns that.
6080
6081 Vector Catch hardware provides dedicated breakpoints
6082 for certain hardware events.
6083 The specific bit values are core-specific (as in fact is using
6084 coprocessor 14 register 7 itself) but all current ARM11
6085 cores @emph{except the ARM1176} use the same six bits.
6086 @end deffn
6087
6088 @section ARMv7 Architecture
6089 @cindex ARMv7
6090
6091 @subsection ARMv7 Debug Access Port (DAP) specific commands
6092 @cindex Debug Access Port
6093 @cindex DAP
6094 These commands are specific to ARM architecture v7 Debug Access Port (DAP),
6095 included on Cortex-M3 and Cortex-A8 systems.
6096 They are available in addition to other core-specific commands that may be available.
6097
6098 @deffn Command {dap info} [num]
6099 Displays dap info for ap @var{num}, defaulting to the currently selected AP.
6100 @end deffn
6101
6102 @deffn Command {dap apsel} [num]
6103 Select AP @var{num}, defaulting to 0.
6104 @end deffn
6105
6106 @deffn Command {dap apid} [num]
6107 Displays id register from AP @var{num},
6108 defaulting to the currently selected AP.
6109 @end deffn
6110
6111 @deffn Command {dap baseaddr} [num]
6112 Displays debug base address from AP @var{num},
6113 defaulting to the currently selected AP.
6114 @end deffn
6115
6116 @deffn Command {dap memaccess} [value]
6117 Displays the number of extra tck for mem-ap memory bus access [0-255].
6118 If @var{value} is defined, first assigns that.
6119 @end deffn
6120
6121 @subsection Cortex-M3 specific commands
6122 @cindex Cortex-M3
6123
6124 @deffn Command {cortex_m3 disassemble} address [count]
6125 @cindex disassemble
6126 Disassembles @var{count} Thumb2 instructions starting at @var{address}.
6127 If @var{count} is not specified, a single instruction is disassembled.
6128 @end deffn
6129
6130 @deffn Command {cortex_m3 maskisr} (@option{on}|@option{off})
6131 Control masking (disabling) interrupts during target step/resume.
6132 @end deffn
6133
6134 @deffn Command {cortex_m3 vector_catch} [@option{all}|@option{none}|list]
6135 @cindex vector_catch
6136 Vector Catch hardware provides dedicated breakpoints
6137 for certain hardware events.
6138
6139 Parameters request interception of
6140 @option{all} of these hardware event vectors,
6141 @option{none} of them,
6142 or one or more of the following:
6143 @option{hard_err} for a HardFault exception;
6144 @option{mm_err} for a MemManage exception;
6145 @option{bus_err} for a BusFault exception;
6146 @option{irq_err},
6147 @option{state_err},
6148 @option{chk_err}, or
6149 @option{nocp_err} for various UsageFault exceptions; or
6150 @option{reset}.
6151 If NVIC setup code does not enable them,
6152 MemManage, BusFault, and UsageFault exceptions
6153 are mapped to HardFault.
6154 UsageFault checks for
6155 divide-by-zero and unaligned access
6156 must also be explicitly enabled.
6157
6158 This finishes by listing the current vector catch configuration.
6159 @end deffn
6160
6161 @anchor{Software Debug Messages and Tracing}
6162 @section Software Debug Messages and Tracing
6163 @cindex Linux-ARM DCC support
6164 @cindex tracing
6165 @cindex libdcc
6166 @cindex DCC
6167 OpenOCD can process certain requests from target software, when
6168 the target uses appropriate libraries.
6169 The most powerful mechanism is semihosting, but there is also
6170 a lighter weight mechanism using only the DCC channel.
6171
6172 Currently @command{target_request debugmsgs}
6173 is supported only for @option{arm7_9} and @option{cortex_m3} cores.
6174 These messages are received as part of target polling, so
6175 you need to have @command{poll on} active to receive them.
6176 They are intrusive in that they will affect program execution
6177 times. If that is a problem, @pxref{ARM Hardware Tracing}.
6178
6179 See @file{libdcc} in the contrib dir for more details.
6180 In addition to sending strings, characters, and
6181 arrays of various size integers from the target,
6182 @file{libdcc} also exports a software trace point mechanism.
6183 The target being debugged may
6184 issue trace messages which include a 24-bit @dfn{trace point} number.
6185 Trace point support includes two distinct mechanisms,
6186 each supported by a command:
6187
6188 @itemize
6189 @item @emph{History} ... A circular buffer of trace points
6190 can be set up, and then displayed at any time.
6191 This tracks where code has been, which can be invaluable in
6192 finding out how some fault was triggered.
6193
6194 The buffer may overflow, since it collects records continuously.
6195 It may be useful to use some of the 24 bits to represent a
6196 particular event, and other bits to hold data.
6197
6198 @item @emph{Counting} ... An array of counters can be set up,
6199 and then displayed at any time.
6200 This can help establish code coverage and identify hot spots.
6201
6202 The array of counters is directly indexed by the trace point
6203 number, so trace points with higher numbers are not counted.
6204 @end itemize
6205
6206 Linux-ARM kernels have a ``Kernel low-level debugging
6207 via EmbeddedICE DCC channel'' option (CONFIG_DEBUG_ICEDCC,
6208 depends on CONFIG_DEBUG_LL) which uses this mechanism to
6209 deliver messages before a serial console can be activated.
6210 This is not the same format used by @file{libdcc}.
6211 Other software, such as the U-Boot boot loader, sometimes
6212 does the same thing.
6213
6214 @deffn Command {target_request debugmsgs} [@option{enable}|@option{disable}|@option{charmsg}]
6215 Displays current handling of target DCC message requests.
6216 These messages may be sent to the debugger while the target is running.
6217 The optional @option{enable} and @option{charmsg} parameters
6218 both enable the messages, while @option{disable} disables them.
6219
6220 With @option{charmsg} the DCC words each contain one character,
6221 as used by Linux with CONFIG_DEBUG_ICEDCC;
6222 otherwise the libdcc format is used.
6223 @end deffn
6224
6225 @deffn Command {trace history} [@option{clear}|count]
6226 With no parameter, displays all the trace points that have triggered
6227 in the order they triggered.
6228 With the parameter @option{clear}, erases all current trace history records.
6229 With a @var{count} parameter, allocates space for that many
6230 history records.
6231 @end deffn
6232
6233 @deffn Command {trace point} [@option{clear}|identifier]
6234 With no parameter, displays all trace point identifiers and how many times
6235 they have been triggered.
6236 With the parameter @option{clear}, erases all current trace point counters.
6237 With a numeric @var{identifier} parameter, creates a new a trace point counter
6238 and associates it with that identifier.
6239
6240 @emph{Important:} The identifier and the trace point number
6241 are not related except by this command.
6242 These trace point numbers always start at zero (from server startup,
6243 or after @command{trace point clear}) and count up from there.
6244 @end deffn
6245
6246
6247 @node JTAG Commands
6248 @chapter JTAG Commands
6249 @cindex JTAG Commands
6250 Most general purpose JTAG commands have been presented earlier.
6251 (@xref{JTAG Speed}, @ref{Reset Configuration}, and @ref{TAP Declaration}.)
6252 Lower level JTAG commands, as presented here,
6253 may be needed to work with targets which require special
6254 attention during operations such as reset or initialization.
6255
6256 To use these commands you will need to understand some
6257 of the basics of JTAG, including:
6258
6259 @itemize @bullet
6260 @item A JTAG scan chain consists of a sequence of individual TAP
6261 devices such as a CPUs.
6262 @item Control operations involve moving each TAP through the same
6263 standard state machine (in parallel)
6264 using their shared TMS and clock signals.
6265 @item Data transfer involves shifting data through the chain of
6266 instruction or data registers of each TAP, writing new register values
6267 while the reading previous ones.
6268 @item Data register sizes are a function of the instruction active in
6269 a given TAP, while instruction register sizes are fixed for each TAP.
6270 All TAPs support a BYPASS instruction with a single bit data register.
6271 @item The way OpenOCD differentiates between TAP devices is by
6272 shifting different instructions into (and out of) their instruction
6273 registers.
6274 @end itemize
6275
6276 @section Low Level JTAG Commands
6277
6278 These commands are used by developers who need to access
6279 JTAG instruction or data registers, possibly controlling
6280 the order of TAP state transitions.
6281 If you're not debugging OpenOCD internals, or bringing up a
6282 new JTAG adapter or a new type of TAP device (like a CPU or
6283 JTAG router), you probably won't need to use these commands.
6284
6285 @deffn Command {drscan} tap [numbits value]+ [@option{-endstate} tap_state]
6286 Loads the data register of @var{tap} with a series of bit fields
6287 that specify the entire register.
6288 Each field is @var{numbits} bits long with
6289 a numeric @var{value} (hexadecimal encouraged).
6290 The return value holds the original value of each
6291 of those fields.
6292
6293 For example, a 38 bit number might be specified as one
6294 field of 32 bits then one of 6 bits.
6295 @emph{For portability, never pass fields which are more
6296 than 32 bits long. Many OpenOCD implementations do not
6297 support 64-bit (or larger) integer values.}
6298
6299 All TAPs other than @var{tap} must be in BYPASS mode.
6300 The single bit in their data registers does not matter.
6301
6302 When @var{tap_state} is specified, the JTAG state machine is left
6303 in that state.
6304 For example @sc{drpause} might be specified, so that more
6305 instructions can be issued before re-entering the @sc{run/idle} state.
6306 If the end state is not specified, the @sc{run/idle} state is entered.
6307
6308 @quotation Warning
6309 OpenOCD does not record information about data register lengths,
6310 so @emph{it is important that you get the bit field lengths right}.
6311 Remember that different JTAG instructions refer to different
6312 data registers, which may have different lengths.
6313 Moreover, those lengths may not be fixed;
6314 the SCAN_N instruction can change the length of
6315 the register accessed by the INTEST instruction
6316 (by connecting a different scan chain).
6317 @end quotation
6318 @end deffn
6319
6320 @deffn Command {flush_count}
6321 Returns the number of times the JTAG queue has been flushed.
6322 This may be used for performance tuning.
6323
6324 For example, flushing a queue over USB involves a
6325 minimum latency, often several milliseconds, which does
6326 not change with the amount of data which is written.
6327 You may be able to identify performance problems by finding
6328 tasks which waste bandwidth by flushing small transfers too often,
6329 instead of batching them into larger operations.
6330 @end deffn
6331
6332 @deffn Command {irscan} [tap instruction]+ [@option{-endstate} tap_state]
6333 For each @var{tap} listed, loads the instruction register
6334 with its associated numeric @var{instruction}.
6335 (The number of bits in that instruction may be displayed
6336 using the @command{scan_chain} command.)
6337 For other TAPs, a BYPASS instruction is loaded.
6338
6339 When @var{tap_state} is specified, the JTAG state machine is left
6340 in that state.
6341 For example @sc{irpause} might be specified, so the data register
6342 can be loaded before re-entering the @sc{run/idle} state.
6343 If the end state is not specified, the @sc{run/idle} state is entered.
6344
6345 @quotation Note
6346 OpenOCD currently supports only a single field for instruction
6347 register values, unlike data register values.
6348 For TAPs where the instruction register length is more than 32 bits,
6349 portable scripts currently must issue only BYPASS instructions.
6350 @end quotation
6351 @end deffn
6352
6353 @deffn Command {jtag_reset} trst srst
6354 Set values of reset signals.
6355 The @var{trst} and @var{srst} parameter values may be
6356 @option{0}, indicating that reset is inactive (pulled or driven high),
6357 or @option{1}, indicating it is active (pulled or driven low).
6358 The @command{reset_config} command should already have been used
6359 to configure how the board and JTAG adapter treat these two
6360 signals, and to say if either signal is even present.
6361 @xref{Reset Configuration}.
6362
6363 Note that TRST is specially handled.
6364 It actually signifies JTAG's @sc{reset} state.
6365 So if the board doesn't support the optional TRST signal,
6366 or it doesn't support it along with the specified SRST value,
6367 JTAG reset is triggered with TMS and TCK signals
6368 instead of the TRST signal.
6369 And no matter how that JTAG reset is triggered, once
6370 the scan chain enters @sc{reset} with TRST inactive,
6371 TAP @code{post-reset} events are delivered to all TAPs
6372 with handlers for that event.
6373 @end deffn
6374
6375 @deffn Command {pathmove} start_state [next_state ...]
6376 Start by moving to @var{start_state}, which
6377 must be one of the @emph{stable} states.
6378 Unless it is the only state given, this will often be the
6379 current state, so that no TCK transitions are needed.
6380 Then, in a series of single state transitions
6381 (conforming to the JTAG state machine) shift to
6382 each @var{next_state} in sequence, one per TCK cycle.
6383 The final state must also be stable.
6384 @end deffn
6385
6386 @deffn Command {runtest} @var{num_cycles}
6387 Move to the @sc{run/idle} state, and execute at least
6388 @var{num_cycles} of the JTAG clock (TCK).
6389 Instructions often need some time
6390 to execute before they take effect.
6391 @end deffn
6392
6393 @c tms_sequence (short|long)
6394 @c ... temporary, debug-only, other than USBprog bug workaround...
6395
6396 @deffn Command {verify_ircapture} (@option{enable}|@option{disable})
6397 Verify values captured during @sc{ircapture} and returned
6398 during IR scans. Default is enabled, but this can be
6399 overridden by @command{verify_jtag}.
6400 This flag is ignored when validating JTAG chain configuration.
6401 @end deffn
6402
6403 @deffn Command {verify_jtag} (@option{enable}|@option{disable})
6404 Enables verification of DR and IR scans, to help detect
6405 programming errors. For IR scans, @command{verify_ircapture}
6406 must also be enabled.
6407 Default is enabled.
6408 @end deffn
6409
6410 @section TAP state names
6411 @cindex TAP state names
6412
6413 The @var{tap_state} names used by OpenOCD in the @command{drscan},
6414 @command{irscan}, and @command{pathmove} commands are the same
6415 as those used in SVF boundary scan documents, except that
6416 SVF uses @sc{idle} instead of @sc{run/idle}.
6417
6418 @itemize @bullet
6419 @item @b{RESET} ... @emph{stable} (with TMS high);
6420 acts as if TRST were pulsed
6421 @item @b{RUN/IDLE} ... @emph{stable}; don't assume this always means IDLE
6422 @item @b{DRSELECT}
6423 @item @b{DRCAPTURE}
6424 @item @b{DRSHIFT} ... @emph{stable}; TDI/TDO shifting
6425 through the data register
6426 @item @b{DREXIT1}
6427 @item @b{DRPAUSE} ... @emph{stable}; data register ready
6428 for update or more shifting
6429 @item @b{DREXIT2}
6430 @item @b{DRUPDATE}
6431 @item @b{IRSELECT}
6432 @item @b{IRCAPTURE}
6433 @item @b{IRSHIFT} ... @emph{stable}; TDI/TDO shifting
6434 through the instruction register
6435 @item @b{IREXIT1}
6436 @item @b{IRPAUSE} ... @emph{stable}; instruction register ready
6437 for update or more shifting
6438 @item @b{IREXIT2}
6439 @item @b{IRUPDATE}
6440 @end itemize
6441
6442 Note that only six of those states are fully ``stable'' in the
6443 face of TMS fixed (low except for @sc{reset})
6444 and a free-running JTAG clock. For all the
6445 others, the next TCK transition changes to a new state.
6446
6447 @itemize @bullet
6448 @item From @sc{drshift} and @sc{irshift}, clock transitions will
6449 produce side effects by changing register contents. The values
6450 to be latched in upcoming @sc{drupdate} or @sc{irupdate} states
6451 may not be as expected.
6452 @item @sc{run/idle}, @sc{drpause}, and @sc{irpause} are reasonable
6453 choices after @command{drscan} or @command{irscan} commands,
6454 since they are free of JTAG side effects.
6455 @item @sc{run/idle} may have side effects that appear at non-JTAG
6456 levels, such as advancing the ARM9E-S instruction pipeline.
6457 Consult the documentation for the TAP(s) you are working with.
6458 @end itemize
6459
6460 @node Boundary Scan Commands
6461 @chapter Boundary Scan Commands
6462
6463 One of the original purposes of JTAG was to support
6464 boundary scan based hardware testing.
6465 Although its primary focus is to support On-Chip Debugging,
6466 OpenOCD also includes some boundary scan commands.
6467
6468 @section SVF: Serial Vector Format
6469 @cindex Serial Vector Format
6470 @cindex SVF
6471
6472 The Serial Vector Format, better known as @dfn{SVF}, is a
6473 way to represent JTAG test patterns in text files.
6474 OpenOCD supports running such test files.
6475
6476 @deffn Command {svf} filename [@option{quiet}]
6477 This issues a JTAG reset (Test-Logic-Reset) and then
6478 runs the SVF script from @file{filename}.
6479 Unless the @option{quiet} option is specified,
6480 each command is logged before it is executed.
6481 @end deffn
6482
6483 @section XSVF: Xilinx Serial Vector Format
6484 @cindex Xilinx Serial Vector Format
6485 @cindex XSVF
6486
6487 The Xilinx Serial Vector Format, better known as @dfn{XSVF}, is a
6488 binary representation of SVF which is optimized for use with
6489 Xilinx devices.
6490 OpenOCD supports running such test files.
6491
6492 @quotation Important
6493 Not all XSVF commands are supported.
6494 @end quotation
6495
6496 @deffn Command {xsvf} (tapname|@option{plain}) filename [@option{virt2}] [@option{quiet}]
6497 This issues a JTAG reset (Test-Logic-Reset) and then
6498 runs the XSVF script from @file{filename}.
6499 When a @var{tapname} is specified, the commands are directed at
6500 that TAP.
6501 When @option{virt2} is specified, the @sc{xruntest} command counts
6502 are interpreted as TCK cycles instead of microseconds.
6503 Unless the @option{quiet} option is specified,
6504 messages are logged for comments and some retries.
6505 @end deffn
6506
6507 The OpenOCD sources also include two utility scripts
6508 for working with XSVF; they are not currently installed
6509 after building the software.
6510 You may find them useful:
6511
6512 @itemize
6513 @item @emph{svf2xsvf} ... converts SVF files into the extended XSVF
6514 syntax understood by the @command{xsvf} command; see notes below.
6515 @item @emph{xsvfdump} ... converts XSVF files into a text output format;
6516 understands the OpenOCD extensions.
6517 @end itemize
6518
6519 The input format accepts a handful of non-standard extensions.
6520 These include three opcodes corresponding to SVF extensions
6521 from Lattice Semiconductor (LCOUNT, LDELAY, LDSR), and
6522 two opcodes supporting a more accurate translation of SVF
6523 (XTRST, XWAITSTATE).
6524 If @emph{xsvfdump} shows a file is using those opcodes, it
6525 probably will not be usable with other XSVF tools.
6526
6527
6528 @node TFTP
6529 @chapter TFTP
6530 @cindex TFTP
6531 If OpenOCD runs on an embedded host(as ZY1000 does), then TFTP can
6532 be used to access files on PCs (either the developer's PC or some other PC).
6533
6534 The way this works on the ZY1000 is to prefix a filename by
6535 "/tftp/ip/" and append the TFTP path on the TFTP
6536 server (tftpd). For example,
6537
6538 @example
6539 load_image /tftp/10.0.0.96/c:\temp\abc.elf
6540 @end example
6541
6542 will load c:\temp\abc.elf from the developer pc (10.0.0.96) into memory as
6543 if the file was hosted on the embedded host.
6544
6545 In order to achieve decent performance, you must choose a TFTP server
6546 that supports a packet size bigger than the default packet size (512 bytes). There
6547 are numerous TFTP servers out there (free and commercial) and you will have to do
6548 a bit of googling to find something that fits your requirements.
6549
6550 @node GDB and OpenOCD
6551 @chapter GDB and OpenOCD
6552 @cindex GDB
6553 OpenOCD complies with the remote gdbserver protocol, and as such can be used
6554 to debug remote targets.
6555 Setting up GDB to work with OpenOCD can involve several components:
6556
6557 @itemize
6558 @item OpenOCD itself may need to be configured. @xref{GDB Configuration}.
6559 @item GDB itself may need configuration, as shown in this chapter.
6560 @item If you have a GUI environment like Eclipse,
6561 that also will probably need to be configured.
6562 @end itemize
6563
6564 Of course, the version of GDB you use will need to be one which has
6565 been built to know about the target CPU you're using. It's probably
6566 part of the tool chain you're using. For example, if you are doing
6567 cross-development for ARM on an x86 PC, instead of using the native
6568 x86 @command{gdb} command you might use @command{arm-none-eabi-gdb}
6569 if that's the tool chain used to compile your code.
6570
6571 @anchor{Connecting to GDB}
6572 @section Connecting to GDB
6573 @cindex Connecting to GDB
6574 Use GDB 6.7 or newer with OpenOCD if you run into trouble. For
6575 instance GDB 6.3 has a known bug that produces bogus memory access
6576 errors, which has since been fixed; see
6577 @url{http://osdir.com/ml/gdb.bugs.discuss/2004-12/msg00018.html}
6578
6579 OpenOCD can communicate with GDB in two ways:
6580
6581 @enumerate
6582 @item
6583 A socket (TCP/IP) connection is typically started as follows:
6584 @example
6585 target remote localhost:3333
6586 @end example
6587 This would cause GDB to connect to the gdbserver on the local pc using port 3333.
6588 @item
6589 A pipe connection is typically started as follows:
6590 @example
6591 target remote | openocd --pipe
6592 @end example
6593 This would cause GDB to run OpenOCD and communicate using pipes (stdin/stdout).
6594 Using this method has the advantage of GDB starting/stopping OpenOCD for the debug
6595 session.
6596 @end enumerate
6597
6598 To list the available OpenOCD commands type @command{monitor help} on the
6599 GDB command line.
6600
6601 @section Sample GDB session startup
6602
6603 With the remote protocol, GDB sessions start a little differently
6604 than they do when you're debugging locally.
6605 Here's an examples showing how to start a debug session with a
6606 small ARM program.
6607 In this case the program was linked to be loaded into SRAM on a Cortex-M3.
6608 Most programs would be written into flash (address 0) and run from there.
6609
6610 @example
6611 $ arm-none-eabi-gdb example.elf
6612 (gdb) target remote localhost:3333
6613 Remote debugging using localhost:3333
6614 ...
6615 (gdb) monitor reset halt
6616 ...
6617 (gdb) load
6618 Loading section .vectors, size 0x100 lma 0x20000000
6619 Loading section .text, size 0x5a0 lma 0x20000100
6620 Loading section .data, size 0x18 lma 0x200006a0
6621 Start address 0x2000061c, load size 1720
6622 Transfer rate: 22 KB/sec, 573 bytes/write.
6623 (gdb) continue
6624 Continuing.
6625 ...
6626 @end example
6627
6628 You could then interrupt the GDB session to make the program break,
6629 type @command{where} to show the stack, @command{list} to show the
6630 code around the program counter, @command{step} through code,
6631 set breakpoints or watchpoints, and so on.
6632
6633 @section Configuring GDB for OpenOCD
6634
6635 OpenOCD supports the gdb @option{qSupported} packet, this enables information
6636 to be sent by the GDB remote server (i.e. OpenOCD) to GDB. Typical information includes
6637 packet size and the device's memory map.
6638 You do not need to configure the packet size by hand,
6639 and the relevant parts of the memory map should be automatically
6640 set up when you declare (NOR) flash banks.
6641
6642 However, there are other things which GDB can't currently query.
6643 You may need to set those up by hand.
6644 As OpenOCD starts up, you will often see a line reporting
6645 something like:
6646
6647 @example
6648 Info : lm3s.cpu: hardware has 6 breakpoints, 4 watchpoints
6649 @end example
6650
6651 You can pass that information to GDB with these commands:
6652
6653 @example
6654 set remote hardware-breakpoint-limit 6
6655 set remote hardware-watchpoint-limit 4
6656 @end example
6657
6658 With that particular hardware (Cortex-M3) the hardware breakpoints
6659 only work for code running from flash memory. Most other ARM systems
6660 do not have such restrictions.
6661
6662 @section Programming using GDB
6663 @cindex Programming using GDB
6664
6665 By default the target memory map is sent to GDB. This can be disabled by
6666 the following OpenOCD configuration option:
6667 @example
6668 gdb_memory_map disable
6669 @end example
6670 For this to function correctly a valid flash configuration must also be set
6671 in OpenOCD. For faster performance you should also configure a valid
6672 working area.
6673
6674 Informing GDB of the memory map of the target will enable GDB to protect any
6675 flash areas of the target and use hardware breakpoints by default. This means
6676 that the OpenOCD option @command{gdb_breakpoint_override} is not required when
6677 using a memory map. @xref{gdb_breakpoint_override}.
6678
6679 To view the configured memory map in GDB, use the GDB command @option{info mem}
6680 All other unassigned addresses within GDB are treated as RAM.
6681
6682 GDB 6.8 and higher set any memory area not in the memory map as inaccessible.
6683 This can be changed to the old behaviour by using the following GDB command
6684 @example
6685 set mem inaccessible-by-default off
6686 @end example
6687
6688 If @command{gdb_flash_program enable} is also used, GDB will be able to
6689 program any flash memory using the vFlash interface.
6690
6691 GDB will look at the target memory map when a load command is given, if any
6692 areas to be programmed lie within the target flash area the vFlash packets
6693 will be used.
6694
6695 If the target needs configuring before GDB programming, an event
6696 script can be executed:
6697 @example
6698 $_TARGETNAME configure -event EVENTNAME BODY
6699 @end example
6700
6701 To verify any flash programming the GDB command @option{compare-sections}
6702 can be used.
6703
6704 @node Tcl Scripting API
6705 @chapter Tcl Scripting API
6706 @cindex Tcl Scripting API
6707 @cindex Tcl scripts
6708 @section API rules
6709
6710 The commands are stateless. E.g. the telnet command line has a concept
6711 of currently active target, the Tcl API proc's take this sort of state
6712 information as an argument to each proc.
6713
6714 There are three main types of return values: single value, name value
6715 pair list and lists.
6716
6717 Name value pair. The proc 'foo' below returns a name/value pair
6718 list.
6719
6720 @verbatim
6721
6722 > set foo(me) Duane
6723 > set foo(you) Oyvind
6724 > set foo(mouse) Micky
6725 > set foo(duck) Donald
6726
6727 If one does this:
6728
6729 > set foo
6730
6731 The result is:
6732
6733 me Duane you Oyvind mouse Micky duck Donald
6734
6735 Thus, to get the names of the associative array is easy:
6736
6737 foreach { name value } [set foo] {
6738 puts "Name: $name, Value: $value"
6739 }
6740 @end verbatim
6741
6742 Lists returned must be relatively small. Otherwise a range
6743 should be passed in to the proc in question.
6744
6745 @section Internal low-level Commands
6746
6747 By low-level, the intent is a human would not directly use these commands.
6748
6749 Low-level commands are (should be) prefixed with "ocd_", e.g.
6750 @command{ocd_flash_banks}
6751 is the low level API upon which @command{flash banks} is implemented.
6752
6753 @itemize @bullet
6754 @item @b{ocd_mem2array} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}>
6755
6756 Read memory and return as a Tcl array for script processing
6757 @item @b{ocd_array2mem} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}>
6758
6759 Convert a Tcl array to memory locations and write the values
6760 @item @b{ocd_flash_banks} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}> <@var{target}> [@option{driver options} ...]
6761
6762 Return information about the flash banks
6763 @end itemize
6764
6765 OpenOCD commands can consist of two words, e.g. "flash banks". The
6766 @file{startup.tcl} "unknown" proc will translate this into a Tcl proc
6767 called "flash_banks".
6768
6769 @section OpenOCD specific Global Variables
6770
6771 Real Tcl has ::tcl_platform(), and platform::identify, and many other
6772 variables. JimTCL, as implemented in OpenOCD creates $ocd_HOSTOS which
6773 holds one of the following values:
6774
6775 @itemize @bullet
6776 @item @b{winxx} Built using Microsoft Visual Studio
6777 @item @b{linux} Linux is the underlying operating sytem
6778 @item @b{darwin} Darwin (mac-os) is the underlying operating sytem.
6779 @item @b{cygwin} Running under Cygwin
6780 @item @b{mingw32} Running under MingW32
6781 @item @b{other} Unknown, none of the above.
6782 @end itemize
6783
6784 Note: 'winxx' was choosen because today (March-2009) no distinction is made between Win32 and Win64.
6785
6786 @quotation Note
6787 We should add support for a variable like Tcl variable
6788 @code{tcl_platform(platform)}, it should be called
6789 @code{jim_platform} (because it
6790 is jim, not real tcl).
6791 @end quotation
6792
6793 @node FAQ
6794 @chapter FAQ
6795 @cindex faq
6796 @enumerate
6797 @anchor{FAQ RTCK}
6798 @item @b{RTCK, also known as: Adaptive Clocking - What is it?}
6799 @cindex RTCK
6800 @cindex adaptive clocking
6801 @*
6802
6803 In digital circuit design it is often refered to as ``clock
6804 synchronisation'' the JTAG interface uses one clock (TCK or TCLK)
6805 operating at some speed, your target is operating at another. The two
6806 clocks are not synchronised, they are ``asynchronous''
6807
6808 In order for the two to work together they must be synchronised. Otherwise
6809 the two systems will get out of sync with each other and nothing will
6810 work. There are 2 basic options:
6811 @enumerate
6812 @item
6813 Use a special circuit.
6814 @item
6815 One clock must be some multiple slower than the other.
6816 @end enumerate
6817
6818 @b{Does this really matter?} For some chips and some situations, this
6819 is a non-issue (i.e.: A 500MHz ARM926) but for others - for example some
6820 Atmel SAM7 and SAM9 chips start operation from reset at 32kHz -
6821 program/enable the oscillators and eventually the main clock. It is in
6822 those critical times you must slow the JTAG clock to sometimes 1 to
6823 4kHz.
6824
6825 Imagine debugging a 500MHz ARM926 hand held battery powered device
6826 that ``deep sleeps'' at 32kHz between every keystroke. It can be
6827 painful.
6828
6829 @b{Solution #1 - A special circuit}
6830
6831 In order to make use of this, your JTAG dongle must support the RTCK
6832 feature. Not all dongles support this - keep reading!
6833
6834 The RTCK signal often found in some ARM chips is used to help with
6835 this problem. ARM has a good description of the problem described at
6836 this link: @url{http://www.arm.com/support/faqdev/4170.html} [checked
6837 28/nov/2008]. Link title: ``How does the JTAG synchronisation logic
6838 work? / how does adaptive clocking work?''.
6839
6840 The nice thing about adaptive clocking is that ``battery powered hand
6841 held device example'' - the adaptiveness works perfectly all the
6842 time. One can set a break point or halt the system in the deep power
6843 down code, slow step out until the system speeds up.
6844
6845 Note that adaptive clocking may also need to work at the board level,
6846 when a board-level scan chain has multiple chips.
6847 Parallel clock voting schemes are good way to implement this,
6848 both within and between chips, and can easily be implemented
6849 with a CPLD.
6850 It's not difficult to have logic fan a module's input TCK signal out
6851 to each TAP in the scan chain, and then wait until each TAP's RTCK comes
6852 back with the right polarity before changing the output RTCK signal.
6853 Texas Instruments makes some clock voting logic available
6854 for free (with no support) in VHDL form; see
6855 @url{http://tiexpressdsp.com/index.php/Adaptive_Clocking}
6856
6857 @b{Solution #2 - Always works - but may be slower}
6858
6859 Often this is a perfectly acceptable solution.
6860
6861 In most simple terms: Often the JTAG clock must be 1/10 to 1/12 of
6862 the target clock speed. But what that ``magic division'' is varies
6863 depending on the chips on your board.
6864 @b{ARM rule of thumb} Most ARM based systems require an 6:1 division;
6865 ARM11 cores use an 8:1 division.
6866 @b{Xilinx rule of thumb} is 1/12 the clock speed.
6867
6868 Note: Many FTDI2232C based JTAG dongles are limited to 6MHz.
6869
6870 You can still debug the 'low power' situations - you just need to
6871 manually adjust the clock speed at every step. While painful and
6872 tedious, it is not always practical.
6873
6874 It is however easy to ``code your way around it'' - i.e.: Cheat a little,
6875 have a special debug mode in your application that does a ``high power
6876 sleep''. If you are careful - 98% of your problems can be debugged
6877 this way.
6878
6879 Note that on ARM you may need to avoid using the @emph{wait for interrupt}
6880 operation in your idle loops even if you don't otherwise change the CPU
6881 clock rate.
6882 That operation gates the CPU clock, and thus the JTAG clock; which
6883 prevents JTAG access. One consequence is not being able to @command{halt}
6884 cores which are executing that @emph{wait for interrupt} operation.
6885
6886 To set the JTAG frequency use the command:
6887
6888 @example
6889 # Example: 1.234MHz
6890 jtag_khz 1234
6891 @end example
6892
6893
6894 @item @b{Win32 Pathnames} Why don't backslashes work in Windows paths?
6895
6896 OpenOCD uses Tcl and a backslash is an escape char. Use @{ and @}
6897 around Windows filenames.
6898
6899 @example
6900 > echo \a
6901
6902 > echo @{\a@}
6903 \a
6904 > echo "\a"
6905
6906 >
6907 @end example
6908
6909
6910 @item @b{Missing: cygwin1.dll} OpenOCD complains about a missing cygwin1.dll.
6911
6912 Make sure you have Cygwin installed, or at least a version of OpenOCD that
6913 claims to come with all the necessary DLLs. When using Cygwin, try launching
6914 OpenOCD from the Cygwin shell.
6915
6916 @item @b{Breakpoint Issue} I'm trying to set a breakpoint using GDB (or a frontend like Insight or
6917 Eclipse), but OpenOCD complains that "Info: arm7_9_common.c:213
6918 arm7_9_add_breakpoint(): sw breakpoint requested, but software breakpoints not enabled".
6919
6920 GDB issues software breakpoints when a normal breakpoint is requested, or to implement
6921 source-line single-stepping. On ARMv4T systems, like ARM7TDMI, ARM720T or ARM920T,
6922 software breakpoints consume one of the two available hardware breakpoints.
6923
6924 @item @b{LPC2000 Flash} When erasing or writing LPC2000 on-chip flash, the operation fails at random.
6925
6926 Make sure the core frequency specified in the @option{flash lpc2000} line matches the
6927 clock at the time you're programming the flash. If you've specified the crystal's
6928 frequency, make sure the PLL is disabled. If you've specified the full core speed
6929 (e.g. 60MHz), make sure the PLL is enabled.
6930
6931 @item @b{Amontec Chameleon} When debugging using an Amontec Chameleon in its JTAG Accelerator configuration,
6932 I keep getting "Error: amt_jtagaccel.c:184 amt_wait_scan_busy(): amt_jtagaccel timed
6933 out while waiting for end of scan, rtck was disabled".
6934
6935 Make sure your PC's parallel port operates in EPP mode. You might have to try several
6936 settings in your PC BIOS (ECP, EPP, and different versions of those).
6937
6938 @item @b{Data Aborts} When debugging with OpenOCD and GDB (plain GDB, Insight, or Eclipse),
6939 I get lots of "Error: arm7_9_common.c:1771 arm7_9_read_memory():
6940 memory read caused data abort".
6941
6942 The errors are non-fatal, and are the result of GDB trying to trace stack frames
6943 beyond the last valid frame. It might be possible to prevent this by setting up
6944 a proper "initial" stack frame, if you happen to know what exactly has to
6945 be done, feel free to add this here.
6946
6947 @b{Simple:} In your startup code - push 8 registers of zeros onto the
6948 stack before calling main(). What GDB is doing is ``climbing'' the run
6949 time stack by reading various values on the stack using the standard
6950 call frame for the target. GDB keeps going - until one of 2 things
6951 happen @b{#1} an invalid frame is found, or @b{#2} some huge number of
6952 stackframes have been processed. By pushing zeros on the stack, GDB
6953 gracefully stops.
6954
6955 @b{Debugging Interrupt Service Routines} - In your ISR before you call
6956 your C code, do the same - artifically push some zeros onto the stack,
6957 remember to pop them off when the ISR is done.
6958
6959 @b{Also note:} If you have a multi-threaded operating system, they
6960 often do not @b{in the intrest of saving memory} waste these few
6961 bytes. Painful...
6962
6963
6964 @item @b{JTAG Reset Config} I get the following message in the OpenOCD console (or log file):
6965 "Warning: arm7_9_common.c:679 arm7_9_assert_reset(): srst resets test logic, too".
6966
6967 This warning doesn't indicate any serious problem, as long as you don't want to
6968 debug your core right out of reset. Your .cfg file specified @option{jtag_reset
6969 trst_and_srst srst_pulls_trst} to tell OpenOCD that either your board,
6970 your debugger or your target uC (e.g. LPC2000) can't assert the two reset signals
6971 independently. With this setup, it's not possible to halt the core right out of
6972 reset, everything else should work fine.
6973
6974 @item @b{USB Power} When using OpenOCD in conjunction with Amontec JTAGkey and the Yagarto
6975 toolchain (Eclipse, arm-elf-gcc, arm-elf-gdb), the debugging seems to be
6976 unstable. When single-stepping over large blocks of code, GDB and OpenOCD
6977 quit with an error message. Is there a stability issue with OpenOCD?
6978
6979 No, this is not a stability issue concerning OpenOCD. Most users have solved
6980 this issue by simply using a self-powered USB hub, which they connect their
6981 Amontec JTAGkey to. Apparently, some computers do not provide a USB power
6982 supply stable enough for the Amontec JTAGkey to be operated.
6983
6984 @b{Laptops running on battery have this problem too...}
6985
6986 @item @b{USB Power} When using the Amontec JTAGkey, sometimes OpenOCD crashes with the
6987 following error messages: "Error: ft2232.c:201 ft2232_read(): FT_Read returned:
6988 4" and "Error: ft2232.c:365 ft2232_send_and_recv(): couldn't read from FT2232".
6989 What does that mean and what might be the reason for this?
6990
6991 First of all, the reason might be the USB power supply. Try using a self-powered
6992 hub instead of a direct connection to your computer. Secondly, the error code 4
6993 corresponds to an FT_IO_ERROR, which means that the driver for the FTDI USB
6994 chip ran into some sort of error - this points us to a USB problem.
6995
6996 @item @b{GDB Disconnects} When using the Amontec JTAGkey, sometimes OpenOCD crashes with the following
6997 error message: "Error: gdb_server.c:101 gdb_get_char(): read: 10054".
6998 What does that mean and what might be the reason for this?
6999
7000 Error code 10054 corresponds to WSAECONNRESET, which means that the debugger (GDB)
7001 has closed the connection to OpenOCD. This might be a GDB issue.
7002
7003 @item @b{LPC2000 Flash} In the configuration file in the section where flash device configurations
7004 are described, there is a parameter for specifying the clock frequency
7005 for LPC2000 internal flash devices (e.g. @option{flash bank lpc2000
7006 0x0 0x40000 0 0 0 lpc2000_v1 14746 calc_checksum}), which must be
7007 specified in kilohertz. However, I do have a quartz crystal of a
7008 frequency that contains fractions of kilohertz (e.g. 14,745,600 Hz,
7009 i.e. 14,745.600 kHz). Is it possible to specify real numbers for the
7010 clock frequency?
7011
7012 No. The clock frequency specified here must be given as an integral number.
7013 However, this clock frequency is used by the In-Application-Programming (IAP)
7014 routines of the LPC2000 family only, which seems to be very tolerant concerning
7015 the given clock frequency, so a slight difference between the specified clock
7016 frequency and the actual clock frequency will not cause any trouble.
7017
7018 @item @b{Command Order} Do I have to keep a specific order for the commands in the configuration file?
7019
7020 Well, yes and no. Commands can be given in arbitrary order, yet the
7021 devices listed for the JTAG scan chain must be given in the right
7022 order (jtag newdevice), with the device closest to the TDO-Pin being
7023 listed first. In general, whenever objects of the same type exist
7024 which require an index number, then these objects must be given in the
7025 right order (jtag newtap, targets and flash banks - a target
7026 references a jtag newtap and a flash bank references a target).
7027
7028 You can use the ``scan_chain'' command to verify and display the tap order.
7029
7030 Also, some commands can't execute until after @command{init} has been
7031 processed. Such commands include @command{nand probe} and everything
7032 else that needs to write to controller registers, perhaps for setting
7033 up DRAM and loading it with code.
7034
7035 @anchor{FAQ TAP Order}
7036 @item @b{JTAG TAP Order} Do I have to declare the TAPS in some
7037 particular order?
7038
7039 Yes; whenever you have more than one, you must declare them in
7040 the same order used by the hardware.
7041
7042 Many newer devices have multiple JTAG TAPs. For example: ST
7043 Microsystems STM32 chips have two TAPs, a ``boundary scan TAP'' and
7044 ``Cortex-M3'' TAP. Example: The STM32 reference manual, Document ID:
7045 RM0008, Section 26.5, Figure 259, page 651/681, the ``TDI'' pin is
7046 connected to the boundary scan TAP, which then connects to the
7047 Cortex-M3 TAP, which then connects to the TDO pin.
7048
7049 Thus, the proper order for the STM32 chip is: (1) The Cortex-M3, then
7050 (2) The boundary scan TAP. If your board includes an additional JTAG
7051 chip in the scan chain (for example a Xilinx CPLD or FPGA) you could
7052 place it before or after the STM32 chip in the chain. For example:
7053
7054 @itemize @bullet
7055 @item OpenOCD_TDI(output) -> STM32 TDI Pin (BS Input)
7056 @item STM32 BS TDO (output) -> STM32 Cortex-M3 TDI (input)
7057 @item STM32 Cortex-M3 TDO (output) -> SM32 TDO Pin
7058 @item STM32 TDO Pin (output) -> Xilinx TDI Pin (input)
7059 @item Xilinx TDO Pin -> OpenOCD TDO (input)
7060 @end itemize
7061
7062 The ``jtag device'' commands would thus be in the order shown below. Note:
7063
7064 @itemize @bullet
7065 @item jtag newtap Xilinx tap -irlen ...
7066 @item jtag newtap stm32 cpu -irlen ...
7067 @item jtag newtap stm32 bs -irlen ...
7068 @item # Create the debug target and say where it is
7069 @item target create stm32.cpu -chain-position stm32.cpu ...
7070 @end itemize
7071
7072
7073 @item @b{SYSCOMP} Sometimes my debugging session terminates with an error. When I look into the
7074 log file, I can see these error messages: Error: arm7_9_common.c:561
7075 arm7_9_execute_sys_speed(): timeout waiting for SYSCOMP
7076
7077 TODO.
7078
7079 @end enumerate
7080
7081 @node Tcl Crash Course
7082 @chapter Tcl Crash Course
7083 @cindex Tcl
7084
7085 Not everyone knows Tcl - this is not intended to be a replacement for
7086 learning Tcl, the intent of this chapter is to give you some idea of
7087 how the Tcl scripts work.
7088
7089 This chapter is written with two audiences in mind. (1) OpenOCD users
7090 who need to understand a bit more of how JIM-Tcl works so they can do
7091 something useful, and (2) those that want to add a new command to
7092 OpenOCD.
7093
7094 @section Tcl Rule #1
7095 There is a famous joke, it goes like this:
7096 @enumerate
7097 @item Rule #1: The wife is always correct
7098 @item Rule #2: If you think otherwise, See Rule #1
7099 @end enumerate
7100
7101 The Tcl equal is this:
7102
7103 @enumerate
7104 @item Rule #1: Everything is a string
7105 @item Rule #2: If you think otherwise, See Rule #1
7106 @end enumerate
7107
7108 As in the famous joke, the consequences of Rule #1 are profound. Once
7109 you understand Rule #1, you will understand Tcl.
7110
7111 @section Tcl Rule #1b
7112 There is a second pair of rules.
7113 @enumerate
7114 @item Rule #1: Control flow does not exist. Only commands
7115 @* For example: the classic FOR loop or IF statement is not a control
7116 flow item, they are commands, there is no such thing as control flow
7117 in Tcl.
7118 @item Rule #2: If you think otherwise, See Rule #1
7119 @* Actually what happens is this: There are commands that by
7120 convention, act like control flow key words in other languages. One of
7121 those commands is the word ``for'', another command is ``if''.
7122 @end enumerate
7123
7124 @section Per Rule #1 - All Results are strings
7125 Every Tcl command results in a string. The word ``result'' is used
7126 deliberatly. No result is just an empty string. Remember: @i{Rule #1 -
7127 Everything is a string}
7128
7129 @section Tcl Quoting Operators
7130 In life of a Tcl script, there are two important periods of time, the
7131 difference is subtle.
7132 @enumerate
7133 @item Parse Time
7134 @item Evaluation Time
7135 @end enumerate
7136
7137 The two key items here are how ``quoted things'' work in Tcl. Tcl has
7138 three primary quoting constructs, the [square-brackets] the
7139 @{curly-braces@} and ``double-quotes''
7140
7141 By now you should know $VARIABLES always start with a $DOLLAR
7142 sign. BTW: To set a variable, you actually use the command ``set'', as
7143 in ``set VARNAME VALUE'' much like the ancient BASIC langauge ``let x
7144 = 1'' statement, but without the equal sign.
7145
7146 @itemize @bullet
7147 @item @b{[square-brackets]}
7148 @* @b{[square-brackets]} are command substitutions. It operates much
7149 like Unix Shell `back-ticks`. The result of a [square-bracket]
7150 operation is exactly 1 string. @i{Remember Rule #1 - Everything is a
7151 string}. These two statements are roughly identical:
7152 @example
7153 # bash example
7154 X=`date`
7155 echo "The Date is: $X"
7156 # Tcl example
7157 set X [date]
7158 puts "The Date is: $X"
7159 @end example
7160 @item @b{``double-quoted-things''}
7161 @* @b{``double-quoted-things''} are just simply quoted
7162 text. $VARIABLES and [square-brackets] are expanded in place - the
7163 result however is exactly 1 string. @i{Remember Rule #1 - Everything
7164 is a string}
7165 @example
7166 set x "Dinner"
7167 puts "It is now \"[date]\", $x is in 1 hour"
7168 @end example
7169 @item @b{@{Curly-Braces@}}
7170 @*@b{@{Curly-Braces@}} are magic: $VARIABLES and [square-brackets] are
7171 parsed, but are NOT expanded or executed. @{Curly-Braces@} are like
7172 'single-quote' operators in BASH shell scripts, with the added
7173 feature: @{curly-braces@} can be nested, single quotes can not. @{@{@{this is
7174 nested 3 times@}@}@} NOTE: [date] is a bad example;
7175 at this writing, Jim/OpenOCD does not have a date command.
7176 @end itemize
7177
7178 @section Consequences of Rule 1/2/3/4
7179
7180 The consequences of Rule 1 are profound.
7181
7182 @subsection Tokenisation & Execution.
7183
7184 Of course, whitespace, blank lines and #comment lines are handled in
7185 the normal way.
7186
7187 As a script is parsed, each (multi) line in the script file is
7188 tokenised and according to the quoting rules. After tokenisation, that
7189 line is immedatly executed.
7190
7191 Multi line statements end with one or more ``still-open''
7192 @{curly-braces@} which - eventually - closes a few lines later.
7193
7194 @subsection Command Execution
7195
7196 Remember earlier: There are no ``control flow''
7197 statements in Tcl. Instead there are COMMANDS that simply act like
7198 control flow operators.
7199
7200 Commands are executed like this:
7201
7202 @enumerate
7203 @item Parse the next line into (argc) and (argv[]).
7204 @item Look up (argv[0]) in a table and call its function.
7205 @item Repeat until End Of File.
7206 @end enumerate
7207
7208 It sort of works like this:
7209 @example
7210 for(;;)@{
7211 ReadAndParse( &argc, &argv );
7212
7213 cmdPtr = LookupCommand( argv[0] );
7214
7215 (*cmdPtr->Execute)( argc, argv );
7216 @}
7217 @end example
7218
7219 When the command ``proc'' is parsed (which creates a procedure
7220 function) it gets 3 parameters on the command line. @b{1} the name of
7221 the proc (function), @b{2} the list of parameters, and @b{3} the body
7222 of the function. Not the choice of words: LIST and BODY. The PROC
7223 command stores these items in a table somewhere so it can be found by
7224 ``LookupCommand()''
7225
7226 @subsection The FOR command
7227
7228 The most interesting command to look at is the FOR command. In Tcl,
7229 the FOR command is normally implemented in C. Remember, FOR is a
7230 command just like any other command.
7231
7232 When the ascii text containing the FOR command is parsed, the parser
7233 produces 5 parameter strings, @i{(If in doubt: Refer to Rule #1)} they
7234 are:
7235
7236 @enumerate 0
7237 @item The ascii text 'for'
7238 @item The start text
7239 @item The test expression
7240 @item The next text
7241 @item The body text
7242 @end enumerate
7243
7244 Sort of reminds you of ``main( int argc, char **argv )'' does it not?
7245 Remember @i{Rule #1 - Everything is a string.} The key point is this:
7246 Often many of those parameters are in @{curly-braces@} - thus the
7247 variables inside are not expanded or replaced until later.
7248
7249 Remember that every Tcl command looks like the classic ``main( argc,
7250 argv )'' function in C. In JimTCL - they actually look like this:
7251
7252 @example
7253 int
7254 MyCommand( Jim_Interp *interp,
7255 int *argc,
7256 Jim_Obj * const *argvs );
7257 @end example
7258
7259 Real Tcl is nearly identical. Although the newer versions have
7260 introduced a byte-code parser and intepreter, but at the core, it
7261 still operates in the same basic way.
7262
7263 @subsection FOR command implementation
7264
7265 To understand Tcl it is perhaps most helpful to see the FOR
7266 command. Remember, it is a COMMAND not a control flow structure.
7267
7268 In Tcl there are two underlying C helper functions.
7269
7270 Remember Rule #1 - You are a string.
7271
7272 The @b{first} helper parses and executes commands found in an ascii
7273 string. Commands can be seperated by semicolons, or newlines. While
7274 parsing, variables are expanded via the quoting rules.
7275
7276 The @b{second} helper evaluates an ascii string as a numerical
7277 expression and returns a value.
7278
7279 Here is an example of how the @b{FOR} command could be
7280 implemented. The pseudo code below does not show error handling.
7281 @example
7282 void Execute_AsciiString( void *interp, const char *string );
7283
7284 int Evaluate_AsciiExpression( void *interp, const char *string );
7285
7286 int
7287 MyForCommand( void *interp,
7288 int argc,
7289 char **argv )
7290 @{
7291 if( argc != 5 )@{
7292 SetResult( interp, "WRONG number of parameters");
7293 return ERROR;
7294 @}
7295
7296 // argv[0] = the ascii string just like C
7297
7298 // Execute the start statement.
7299 Execute_AsciiString( interp, argv[1] );
7300
7301 // Top of loop test
7302 for(;;)@{
7303 i = Evaluate_AsciiExpression(interp, argv[2]);
7304 if( i == 0 )
7305 break;
7306
7307 // Execute the body
7308 Execute_AsciiString( interp, argv[3] );
7309
7310 // Execute the LOOP part
7311 Execute_AsciiString( interp, argv[4] );
7312 @}
7313
7314 // Return no error
7315 SetResult( interp, "" );
7316 return SUCCESS;
7317 @}
7318 @end example
7319
7320 Every other command IF, WHILE, FORMAT, PUTS, EXPR, everything works
7321 in the same basic way.
7322
7323 @section OpenOCD Tcl Usage
7324
7325 @subsection source and find commands
7326 @b{Where:} In many configuration files
7327 @* Example: @b{ source [find FILENAME] }
7328 @*Remember the parsing rules
7329 @enumerate
7330 @item The FIND command is in square brackets.
7331 @* The FIND command is executed with the parameter FILENAME. It should
7332 find the full path to the named file. The RESULT is a string, which is
7333 substituted on the orginal command line.
7334 @item The command source is executed with the resulting filename.
7335 @* SOURCE reads a file and executes as a script.
7336 @end enumerate
7337 @subsection format command
7338 @b{Where:} Generally occurs in numerous places.
7339 @* Tcl has no command like @b{printf()}, instead it has @b{format}, which is really more like
7340 @b{sprintf()}.
7341 @b{Example}
7342 @example
7343 set x 6
7344 set y 7
7345 puts [format "The answer: %d" [expr $x * $y]]
7346 @end example
7347 @enumerate
7348 @item The SET command creates 2 variables, X and Y.
7349 @item The double [nested] EXPR command performs math
7350 @* The EXPR command produces numerical result as a string.
7351 @* Refer to Rule #1
7352 @item The format command is executed, producing a single string
7353 @* Refer to Rule #1.
7354 @item The PUTS command outputs the text.
7355 @end enumerate
7356 @subsection Body or Inlined Text
7357 @b{Where:} Various TARGET scripts.
7358 @example
7359 #1 Good
7360 proc someproc @{@} @{
7361 ... multiple lines of stuff ...
7362 @}
7363 $_TARGETNAME configure -event FOO someproc
7364 #2 Good - no variables
7365 $_TARGETNAME confgure -event foo "this ; that;"
7366 #3 Good Curly Braces
7367 $_TARGETNAME configure -event FOO @{
7368 puts "Time: [date]"
7369 @}
7370 #4 DANGER DANGER DANGER
7371 $_TARGETNAME configure -event foo "puts \"Time: [date]\""
7372 @end example
7373 @enumerate
7374 @item The $_TARGETNAME is an OpenOCD variable convention.
7375 @*@b{$_TARGETNAME} represents the last target created, the value changes
7376 each time a new target is created. Remember the parsing rules. When
7377 the ascii text is parsed, the @b{$_TARGETNAME} becomes a simple string,
7378 the name of the target which happens to be a TARGET (object)
7379 command.
7380 @item The 2nd parameter to the @option{-event} parameter is a TCBODY
7381 @*There are 4 examples:
7382 @enumerate
7383 @item The TCLBODY is a simple string that happens to be a proc name
7384 @item The TCLBODY is several simple commands seperated by semicolons
7385 @item The TCLBODY is a multi-line @{curly-brace@} quoted string
7386 @item The TCLBODY is a string with variables that get expanded.
7387 @end enumerate
7388
7389 In the end, when the target event FOO occurs the TCLBODY is
7390 evaluated. Method @b{#1} and @b{#2} are functionally identical. For
7391 Method @b{#3} and @b{#4} it is more interesting. What is the TCLBODY?
7392
7393 Remember the parsing rules. In case #3, @{curly-braces@} mean the
7394 $VARS and [square-brackets] are expanded later, when the EVENT occurs,
7395 and the text is evaluated. In case #4, they are replaced before the
7396 ``Target Object Command'' is executed. This occurs at the same time
7397 $_TARGETNAME is replaced. In case #4 the date will never
7398 change. @{BTW: [date] is a bad example; at this writing,
7399 Jim/OpenOCD does not have a date command@}
7400 @end enumerate
7401 @subsection Global Variables
7402 @b{Where:} You might discover this when writing your own procs @* In
7403 simple terms: Inside a PROC, if you need to access a global variable
7404 you must say so. See also ``upvar''. Example:
7405 @example
7406 proc myproc @{ @} @{
7407 set y 0 #Local variable Y
7408 global x #Global variable X
7409 puts [format "X=%d, Y=%d" $x $y]
7410 @}
7411 @end example
7412 @section Other Tcl Hacks
7413 @b{Dynamic variable creation}
7414 @example
7415 # Dynamically create a bunch of variables.
7416 for @{ set x 0 @} @{ $x < 32 @} @{ set x [expr $x + 1]@} @{
7417 # Create var name
7418 set vn [format "BIT%d" $x]
7419 # Make it a global
7420 global $vn
7421 # Set it.
7422 set $vn [expr (1 << $x)]
7423 @}
7424 @end example
7425 @b{Dynamic proc/command creation}
7426 @example
7427 # One "X" function - 5 uart functions.
7428 foreach who @{A B C D E@}
7429 proc [format "show_uart%c" $who] @{ @} "show_UARTx $who"
7430 @}
7431 @end example
7432
7433 @include fdl.texi
7434
7435 @node OpenOCD Concept Index
7436 @comment DO NOT use the plain word ``Index'', reason: CYGWIN filename
7437 @comment case issue with ``Index.html'' and ``index.html''
7438 @comment Occurs when creating ``--html --no-split'' output
7439 @comment This fix is based on: http://sourceware.org/ml/binutils/2006-05/msg00215.html
7440 @unnumbered OpenOCD Concept Index
7441
7442 @printindex cp
7443
7444 @node Command and Driver Index
7445 @unnumbered Command and Driver Index
7446 @printindex fn
7447
7448 @bye

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)