David Brownell <david-b@pacbell.net>:
[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 @end itemize
27
28 @quotation
29 Permission is granted to copy, distribute and/or modify this document
30 under the terms of the GNU Free Documentation License, Version 1.2 or
31 any later version published by the Free Software Foundation; with no
32 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
33 Texts. A copy of the license is included in the section entitled ``GNU
34 Free Documentation License''.
35 @end quotation
36 @end copying
37
38 @titlepage
39 @titlefont{@emph{Open On-Chip Debugger:}}
40 @sp 1
41 @title OpenOCD User's Guide
42 @subtitle for release @value{VERSION}
43 @subtitle @value{UPDATED}
44
45 @page
46 @vskip 0pt plus 1filll
47 @insertcopying
48 @end titlepage
49
50 @summarycontents
51 @contents
52
53 @ifnottex
54 @node Top
55 @top OpenOCD User's Guide
56
57 @insertcopying
58 @end ifnottex
59
60 @menu
61 * About:: About OpenOCD
62 * Developers:: OpenOCD Developers
63 * Building OpenOCD:: Building OpenOCD From SVN
64 * JTAG Hardware Dongles:: JTAG Hardware Dongles
65 * Running:: Running OpenOCD
66 * Simple Configuration Files:: Simple Configuration Files
67 * Config File Guidelines:: Config File Guidelines
68 * About JIM-Tcl:: About JIM-Tcl
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 * General Commands:: General Commands
77 * Architecture and Core Commands:: Architecture and Core Commands
78 * JTAG Commands:: JTAG Commands
79 * Sample Scripts:: Sample Target Scripts
80 * TFTP:: TFTP
81 * GDB and OpenOCD:: Using GDB and OpenOCD
82 * Tcl Scripting API:: Tcl Scripting API
83 * Upgrading:: Deprecated/Removed Commands
84 * Target Library:: Target Library
85 * FAQ:: Frequently Asked Questions
86 * Tcl Crash Course:: Tcl Crash Course
87 * License:: GNU Free Documentation License
88
89 @comment DO NOT use the plain word ``Index'', reason: CYGWIN filename
90 @comment case issue with ``Index.html'' and ``index.html''
91 @comment Occurs when creating ``--html --no-split'' output
92 @comment This fix is based on: http://sourceware.org/ml/binutils/2006-05/msg00215.html
93 * OpenOCD Concept Index:: Concept Index
94 * Command and Driver Index:: Command and Driver Index
95 @end menu
96
97 @node About
98 @unnumbered About
99 @cindex about
100
101 OpenOCD was created by Dominic Rath as part of a diploma thesis written at the
102 University of Applied Sciences Augsburg (@uref{http://www.fh-augsburg.de}).
103 Since that time, the project has grown into an active open-source project,
104 supported by a diverse community of software and hardware developers from
105 around the world.
106
107 @section What is OpenOCD?
108
109 The Open On-Chip Debugger (OpenOCD) aims to provide debugging,
110 in-system programming and boundary-scan testing for embedded target
111 devices.
112
113 @b{JTAG:} OpenOCD uses a ``hardware interface dongle'' to communicate
114 with the JTAG (IEEE 1149.1) compliant TAPs on your target board.
115 A @dfn{TAP} is a ``Test Access Port'', a module which processes
116 special instructions and data. TAPs are daisy-chained within and
117 between chips and boards.
118
119 @b{Dongles:} OpenOCD currently supports many types of hardware dongles: USB
120 based, parallel port based, and other standalone boxes that run
121 OpenOCD internally. @xref{JTAG Hardware Dongles}.
122
123 @b{GDB Debug:} It allows ARM7 (ARM7TDMI and ARM720t), ARM9 (ARM920T,
124 ARM922T, ARM926EJ--S, ARM966E--S), XScale (PXA25x, IXP42x) and
125 Cortex-M3 (Stellaris LM3 and ST STM32) based cores to be
126 debugged via the GDB protocol.
127
128 @b{Flash Programing:} Flash writing is supported for external CFI
129 compatible NOR flashes (Intel and AMD/Spansion command set) and several
130 internal flashes (LPC2000, AT91SAM7, STR7x, STR9x, LM3, and
131 STM32x). Preliminary support for various NAND flash controllers
132 (LPC3180, Orion, S3C24xx, more) controller is included.
133
134 @section OpenOCD Web Site
135
136 The OpenOCD web site provides the latest public news from the community:
137
138 @uref{http://openocd.berlios.de/web/}
139
140 @section Latest User's Guide:
141
142 The user's guide you are now reading may not be the latest one
143 available. A version for more recent code may be available.
144 Its HTML form is published irregularly at:
145
146 @uref{http://openocd.berlios.de/doc/}
147
148 PDF form is likewise published at:
149
150 @uref{http://openocd.berlios.de/doc/pdf/}
151
152 @section OpenOCD User's Forum
153
154 There is an OpenOCD forum (phpBB) hosted by SparkFun:
155
156 @uref{http://forum.sparkfun.com/viewforum.php?f=18}
157
158
159 @node Developers
160 @chapter OpenOCD Developer Resources
161 @cindex developers
162
163 If you are interested in improving the state of OpenOCD's debugging and
164 testing support, new contributions will be welcome. Motivated developers
165 can produce new target, flash or interface drivers, improve the
166 documentation, as well as more conventional bug fixes and enhancements.
167
168 The resources in this chapter are available for developers wishing to explore
169 or expand the OpenOCD source code.
170
171 @section OpenOCD Subversion Repository
172
173 The ``Building From Source'' section provides instructions to retrieve
174 and and build the latest version of the OpenOCD source code.
175 @xref{Building OpenOCD}.
176
177 Developers that want to contribute patches to the OpenOCD system are
178 @b{strongly} encouraged to base their work off of the most recent trunk
179 revision. Patches created against older versions may require additional
180 work from their submitter in order to be updated for newer releases.
181
182 @section Doxygen Developer Manual
183
184 During the development of the 0.2.0 release, the OpenOCD project began
185 providing a Doxygen reference manual. This document contains more
186 technical information about the software internals, development
187 processes, and similar documentation:
188
189 @uref{http://openocd.berlios.de/doc/doxygen/index.html}
190
191 This document is a work-in-progress, but contributions would be welcome
192 to fill in the gaps. All of the source files are provided in-tree,
193 listed in the Doxyfile configuration in the top of the repository trunk.
194
195 @section OpenOCD Developer Mailing List
196
197 The OpenOCD Developer Mailing List provides the primary means of
198 communication between developers:
199
200 @uref{https://lists.berlios.de/mailman/listinfo/openocd-development}
201
202 All drivers developers are enouraged to also subscribe to the list of
203 SVN commits to keep pace with the ongoing changes:
204
205 @uref{https://lists.berlios.de/mailman/listinfo/openocd-svn}
206
207
208 @node Building OpenOCD
209 @chapter Building OpenOCD
210 @cindex building
211
212 @section Pre-Built Tools
213 If you are interested in getting actual work done rather than building
214 OpenOCD, then check if your interface supplier provides binaries for
215 you. Chances are that that binary is from some SVN version that is more
216 stable than SVN trunk where bleeding edge development takes place.
217
218 @section Packagers Please Read!
219
220 You are a @b{PACKAGER} of OpenOCD if you
221
222 @enumerate
223 @item @b{Sell dongles} and include pre-built binaries
224 @item @b{Supply tools} i.e.: A complete development solution
225 @item @b{Supply IDEs} like Eclipse, or RHIDE, etc.
226 @item @b{Build packages} i.e.: RPM files, or DEB files for a Linux Distro
227 @end enumerate
228
229 As a @b{PACKAGER}, you will experience first reports of most issues.
230 When you fix those problems for your users, your solution may help
231 prevent hundreds (if not thousands) of other questions from other users.
232
233 If something does not work for you, please work to inform the OpenOCD
234 developers know how to improve the system or documentation to avoid
235 future problems, and follow-up to help us ensure the issue will be fully
236 resolved in our future releases.
237
238 That said, the OpenOCD developers would also like you to follow a few
239 suggestions:
240
241 @enumerate
242 @item @b{Always build with printer ports enabled.}
243 @item @b{Try to use LIBFTDI + LIBUSB where possible. You cover more bases.}
244 @end enumerate
245
246 @itemize @bullet
247 @item @b{Why YES to LIBFTDI + LIBUSB?}
248 @itemize @bullet
249 @item @b{LESS} work - libusb perhaps already there
250 @item @b{LESS} work - identical code, multiple platforms
251 @item @b{MORE} dongles are supported
252 @item @b{MORE} platforms are supported
253 @item @b{MORE} complete solution
254 @end itemize
255 @item @b{Why not LIBFTDI + LIBUSB} (i.e.: ftd2xx instead)?
256 @itemize @bullet
257 @item @b{LESS} speed - some say it is slower
258 @item @b{LESS} complex to distribute (external dependencies)
259 @end itemize
260 @end itemize
261
262 @section Building From Source
263
264 You can download the current SVN version with an SVN client of your choice from the
265 following repositories:
266
267 @uref{svn://svn.berlios.de/openocd/trunk}
268
269 or
270
271 @uref{http://svn.berlios.de/svnroot/repos/openocd/trunk}
272
273 Using the SVN command line client, you can use the following command to fetch the
274 latest version (make sure there is no (non-svn) directory called "openocd" in the
275 current directory):
276
277 @example
278 svn checkout svn://svn.berlios.de/openocd/trunk openocd
279 @end example
280
281 If you prefer GIT based tools, the @command{git-svn} package works too:
282
283 @example
284 git svn clone -s svn://svn.berlios.de/openocd
285 @end example
286
287 Building OpenOCD from a repository requires a recent version of the
288 GNU autotools (autoconf >= 2.59 and automake >= 1.9).
289 For building on Windows,
290 you have to use Cygwin. Make sure that your @env{PATH} environment variable contains no
291 other locations with Unix utils (like UnxUtils) - these can't handle the Cygwin
292 paths, resulting in obscure dependency errors (This is an observation I've gathered
293 from the logs of one user - correct me if I'm wrong).
294
295 You further need the appropriate driver files, if you want to build support for
296 a FTDI FT2232 based interface:
297
298 @itemize @bullet
299 @item @b{ftdi2232} libftdi (@uref{http://www.intra2net.com/opensource/ftdi/})
300 @item @b{ftd2xx} libftd2xx (@uref{http://www.ftdichip.com/Drivers/D2XX.htm})
301 @item When using the Amontec JTAGkey, you have to get the drivers from the Amontec
302 homepage (@uref{http://www.amontec.com}). The JTAGkey uses a non-standard VID/PID.
303 @end itemize
304
305 libftdi is supported under Windows. Do not use versions earlier than 0.14.
306
307 In general, the D2XX driver provides superior performance (several times as fast),
308 but has the draw-back of being binary-only - though that isn't that bad, as it isn't
309 a kernel module, only a user space library.
310
311 To build OpenOCD (on both Linux and Cygwin), use the following commands:
312
313 @example
314 ./bootstrap
315 @end example
316
317 Bootstrap generates the configure script, and prepares building on your system.
318
319 @example
320 ./configure [options, see below]
321 @end example
322
323 Configure generates the Makefiles used to build OpenOCD.
324
325 @example
326 make
327 make install
328 @end example
329
330 Make builds OpenOCD, and places the final executable in ./src/, the last step, ``make install'' is optional.
331
332 The configure script takes several options, specifying which JTAG interfaces
333 should be included (among other things):
334
335 @itemize @bullet
336 @item
337 @option{--enable-parport} - Enable building the PC parallel port driver.
338 @item
339 @option{--enable-parport_ppdev} - Enable use of ppdev (/dev/parportN) for parport.
340 @item
341 @option{--enable-parport_giveio} - Enable use of giveio for parport instead of ioperm.
342 @item
343 @option{--enable-amtjtagaccel} - Enable building the Amontec JTAG-Accelerator driver.
344 @item
345 @option{--enable-ecosboard} - Enable building support for eCosBoard based JTAG debugger.
346 @item
347 @option{--enable-ioutil} - Enable ioutil functions - useful for standalone OpenOCD implementations.
348 @item
349 @option{--enable-httpd} - Enable builtin httpd server - useful for standalone OpenOCD implementations.
350 @item
351 @option{--enable-ep93xx} - Enable building support for EP93xx based SBCs.
352 @item
353 @option{--enable-at91rm9200} - Enable building support for AT91RM9200 based SBCs.
354 @item
355 @option{--enable-gw16012} - Enable building support for the Gateworks GW16012 JTAG programmer.
356 @item
357 @option{--enable-ft2232_ftd2xx} - Numerous USB type ARM JTAG dongles use the FT2232C chip from this FTDICHIP.COM chip (closed source).
358 @item
359 @option{--enable-ft2232_libftdi} - An open source (free) alternative to FTDICHIP.COM ftd2xx solution (Linux, MacOS, Cygwin).
360 @item
361 @option{--with-ftd2xx-win32-zipdir=PATH} - If using FTDICHIP.COM ft2232c driver,
362 give the directory where the Win32 FTDICHIP.COM 'CDM' driver zip file was unpacked.
363 @item
364 @option{--with-ftd2xx-linux-tardir=PATH} - If using FTDICHIP.COM ft2232c driver
365 on Linux, give the directory where the Linux driver's TAR.GZ file was unpacked.
366 @item
367 @option{--with-ftd2xx-lib=shared|static} - Linux only. Default: static. Specifies how the FTDICHIP.COM libftd2xx driver should be linked. Note: 'static' only works in conjunction with @option{--with-ftd2xx-linux-tardir}. The 'shared' value is supported (12/26/2008), however you must manually install the required header files and shared libraries in an appropriate place. This uses ``libusb'' internally.
368 @item
369 @option{--enable-presto_libftdi} - Enable building support for ASIX Presto programmer using the libftdi driver.
370 @item
371 @option{--enable-presto_ftd2xx} - Enable building support for ASIX Presto programmer using the FTD2XX driver.
372 @item
373 @option{--enable-usbprog} - Enable building support for the USBprog JTAG programmer.
374 @item
375 @option{--enable-oocd_trace} - Enable building support for the OpenOCD+trace ETM capture device.
376 @item
377 @option{--enable-jlink} - Enable building support for the Segger J-Link JTAG programmer.
378 @item
379 @option{--enable-vsllink} - Enable building support for the Versaloon-Link JTAG programmer.
380 @item
381 @option{--enable-rlink} - Enable building support for the Raisonance RLink JTAG programmer.
382 @item
383 @option{--enable-arm-jtag-ew} - Enable building support for the Olimex ARM-JTAG-EW programmer.
384 @item
385 @option{--enable-dummy} - Enable building the dummy port driver.
386 @end itemize
387
388 @section Parallel Port Dongles
389
390 If you want to access the parallel port using the PPDEV interface you have to specify
391 both the @option{--enable-parport} AND the @option{--enable-parport_ppdev} option since
392 the @option{--enable-parport_ppdev} option actually is an option to the parport driver
393 (see @uref{http://forum.sparkfun.com/viewtopic.php?t=3795} for more info).
394
395 The same is true for the @option{--enable-parport_giveio} option, you have to
396 use both the @option{--enable-parport} AND the @option{--enable-parport_giveio} option if you want to use giveio instead of ioperm parallel port access method.
397
398 @section FT2232C Based USB Dongles
399
400 There are 2 methods of using the FTD2232, either (1) using the
401 FTDICHIP.COM closed source driver, or (2) the open (and free) driver
402 libftdi. Some claim the (closed) FTDICHIP.COM solution is faster.
403
404 The FTDICHIP drivers come as either a (win32) ZIP file, or a (Linux)
405 TAR.GZ file. You must unpack them ``some where'' convient. As of this
406 writing (12/26/2008) FTDICHIP does not supply means to install these
407 files ``in an appropriate place'' As a result, there are two
408 ``./configure'' options that help.
409
410 Below is an example build process:
411
412 @enumerate
413 @item Check out the latest version of ``openocd'' from SVN.
414
415 @item If you are using the FTDICHIP.COM driver, download
416 and unpack the Windows or Linux FTD2xx drivers
417 (@uref{http://www.ftdichip.com/Drivers/D2XX.htm}).
418 If you are using the libftdi driver, install that package
419 (e.g. @command{apt-get install libftdi} on systems with APT).
420
421 @example
422 /home/duane/ftd2xx.win32 => the Cygwin/Win32 ZIP file contents
423 /home/duane/libftd2xx0.4.16 => the Linux TAR.GZ file contents
424 @end example
425
426 @item Configure with options resembling the following.
427
428 @enumerate a
429 @item Cygwin FTDICHIP solution:
430 @example
431 ./configure --prefix=/home/duane/mytools \
432 --enable-ft2232_ftd2xx \
433 --with-ftd2xx-win32-zipdir=/home/duane/ftd2xx.win32
434 @end example
435
436 @item Linux FTDICHIP solution:
437 @example
438 ./configure --prefix=/home/duane/mytools \
439 --enable-ft2232_ftd2xx \
440 --with-ft2xx-linux-tardir=/home/duane/libftd2xx0.4.16
441 @end example
442
443 @item Cygwin/Linux LIBFTDI solution ... assuming that
444 @itemize
445 @item For Windows -- that the Windows port of LIBUSB is in place.
446 @item For Linux -- that libusb has been built/installed and is in place.
447 @item That libftdi has been built and installed (relies on libusb).
448 @end itemize
449
450 Then configure the libftdi solution like this:
451
452 @example
453 ./configure --prefix=/home/duane/mytools \
454 --enable-ft2232_libftdi
455 @end example
456 @end enumerate
457
458 @item Then just type ``make'', and perhaps ``make install''.
459 @end enumerate
460
461
462 @section Miscellaneous Configure Options
463
464 @itemize @bullet
465 @item
466 @option{--disable-option-checking} - Ignore unrecognized @option{--enable} and @option{--with} options.
467 @item
468 @option{--enable-gccwarnings} - Enable extra gcc warnings during build.
469 Default is enabled.
470 @item
471 @option{--enable-release} - Enable building of an OpenOCD release, generally
472 this is for developers. It simply omits the svn version string when the
473 openocd @option{-v} is executed.
474 @end itemize
475
476 @node JTAG Hardware Dongles
477 @chapter JTAG Hardware Dongles
478 @cindex dongles
479 @cindex FTDI
480 @cindex wiggler
481 @cindex zy1000
482 @cindex printer port
483 @cindex USB Adapter
484 @cindex rtck
485
486 Defined: @b{dongle}: A small device that plugins into a computer and serves as
487 an adapter .... [snip]
488
489 In the OpenOCD case, this generally refers to @b{a small adapater} one
490 attaches to your computer via USB or the Parallel Printer Port. The
491 execption being the Zylin ZY1000 which is a small box you attach via
492 an ethernet cable. The Zylin ZY1000 has the advantage that it does not
493 require any drivers to be installed on the developer PC. It also has
494 a built in web interface. It supports RTCK/RCLK or adaptive clocking
495 and has a built in relay to power cycle targets remotely.
496
497
498 @section Choosing a Dongle
499
500 There are three things you should keep in mind when choosing a dongle.
501
502 @enumerate
503 @item @b{Voltage} What voltage is your target? 1.8, 2.8, 3.3, or 5V? Does your dongle support it?
504 @item @b{Connection} Printer Ports - Does your computer have one?
505 @item @b{Connection} Is that long printer bit-bang cable practical?
506 @item @b{RTCK} Do you require RTCK? Also known as ``adaptive clocking''
507 @end enumerate
508
509 @section Stand alone Systems
510
511 @b{ZY1000} See: @url{http://www.zylin.com/zy1000.html} Technically, not a
512 dongle, but a standalone box. The ZY1000 has the advantage that it does
513 not require any drivers installed on the developer PC. It also has
514 a built in web interface. It supports RTCK/RCLK or adaptive clocking
515 and has a built in relay to power cycle targets remotely.
516
517 @section USB FT2232 Based
518
519 There are many USB JTAG dongles on the market, many of them are based
520 on a chip from ``Future Technology Devices International'' (FTDI)
521 known as the FTDI FT2232; this is a USB full speed (12 Mbps) chip.
522 See: @url{http://www.ftdichip.com} for more information.
523 In summer 2009, USB high speed (480 Mbps) versions of these FTDI
524 chips are starting to become available in JTAG adapters.
525
526 As of 28/Nov/2008, the following are supported:
527
528 @itemize @bullet
529 @item @b{usbjtag}
530 @* Link @url{http://www.hs-augsburg.de/~hhoegl/proj/usbjtag/usbjtag.html}
531 @item @b{jtagkey}
532 @* See: @url{http://www.amontec.com/jtagkey.shtml}
533 @item @b{oocdlink}
534 @* See: @url{http://www.oocdlink.com} By Joern Kaipf
535 @item @b{signalyzer}
536 @* See: @url{http://www.signalyzer.com}
537 @item @b{evb_lm3s811}
538 @* See: @url{http://www.luminarymicro.com} - The Stellaris LM3S811 eval board has an FTD2232C chip built in.
539 @item @b{olimex-jtag}
540 @* See: @url{http://www.olimex.com}
541 @item @b{flyswatter}
542 @* See: @url{http://www.tincantools.com}
543 @item @b{turtelizer2}
544 @* See:
545 @uref{http://www.ethernut.de/en/hardware/turtelizer/index.html, Turtelizer 2}, or
546 @url{http://www.ethernut.de}
547 @item @b{comstick}
548 @* Link: @url{http://www.hitex.com/index.php?id=383}
549 @item @b{stm32stick}
550 @* Link @url{http://www.hitex.com/stm32-stick}
551 @item @b{axm0432_jtag}
552 @* Axiom AXM-0432 Link @url{http://www.axman.com}
553 @item @b{cortino}
554 @* Link @url{http://www.hitex.com/index.php?id=cortino}
555 @end itemize
556
557 @section USB JLINK based
558 There are several OEM versions of the Segger @b{JLINK} adapter. It is
559 an example of a micro controller based JTAG adapter, it uses an
560 AT91SAM764 internally.
561
562 @itemize @bullet
563 @item @b{ATMEL SAMICE} Only works with ATMEL chips!
564 @* Link: @url{http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3892}
565 @item @b{SEGGER JLINK}
566 @* Link: @url{http://www.segger.com/jlink.html}
567 @item @b{IAR J-Link}
568 @* Link: @url{http://www.iar.com/website1/1.0.1.0/369/1/index.php}
569 @end itemize
570
571 @section USB RLINK based
572 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.
573
574 @itemize @bullet
575 @item @b{Raisonance RLink}
576 @* Link: @url{http://www.raisonance.com/products/RLink.php}
577 @item @b{STM32 Primer}
578 @* Link: @url{http://www.stm32circle.com/resources/stm32primer.php}
579 @item @b{STM32 Primer2}
580 @* Link: @url{http://www.stm32circle.com/resources/stm32primer2.php}
581 @end itemize
582
583 @section USB Other
584 @itemize @bullet
585 @item @b{USBprog}
586 @* Link: @url{http://www.embedded-projects.net/usbprog} - which uses an Atmel MEGA32 and a UBN9604
587
588 @item @b{USB - Presto}
589 @* Link: @url{http://tools.asix.net/prg_presto.htm}
590
591 @item @b{Versaloon-Link}
592 @* Link: @url{http://www.simonqian.com/en/Versaloon}
593
594 @item @b{ARM-JTAG-EW}
595 @* Link: @url{http://www.olimex.com/dev/arm-jtag-ew.html}
596 @end itemize
597
598 @section IBM PC Parallel Printer Port Based
599
600 The two well known ``JTAG Parallel Ports'' cables are the Xilnx DLC5
601 and the MacGraigor Wiggler. There are many clones and variations of
602 these on the market.
603
604 @itemize @bullet
605
606 @item @b{Wiggler} - There are many clones of this.
607 @* Link: @url{http://www.macraigor.com/wiggler.htm}
608
609 @item @b{DLC5} - From XILINX - There are many clones of this
610 @* Link: Search the web for: ``XILINX DLC5'' - it is no longer
611 produced, PDF schematics are easily found and it is easy to make.
612
613 @item @b{Amontec - JTAG Accelerator}
614 @* Link: @url{http://www.amontec.com/jtag_accelerator.shtml}
615
616 @item @b{GW16402}
617 @* Link: @url{http://www.gateworks.com/products/avila_accessories/gw16042.php}
618
619 @item @b{Wiggler2}
620 @*@uref{http://www.ccac.rwth-aachen.de/@/~michaels/@/index.php/hardware/@/armjtag,
621 Improved parallel-port wiggler-style JTAG adapter}
622
623 @item @b{Wiggler_ntrst_inverted}
624 @* Yet another variation - See the source code, src/jtag/parport.c
625
626 @item @b{old_amt_wiggler}
627 @* Unknown - probably not on the market today
628
629 @item @b{arm-jtag}
630 @* Link: Most likely @url{http://www.olimex.com/dev/arm-jtag.html} [another wiggler clone]
631
632 @item @b{chameleon}
633 @* Link: @url{http://www.amontec.com/chameleon.shtml}
634
635 @item @b{Triton}
636 @* Unknown.
637
638 @item @b{Lattice}
639 @* ispDownload from Lattice Semiconductor
640 @url{http://www.latticesemi.com/lit/docs/@/devtools/dlcable.pdf}
641
642 @item @b{flashlink}
643 @* From ST Microsystems;
644 @uref{http://www.st.com/stonline/@/products/literature/um/7889.pdf,
645 FlashLINK JTAG programing cable for PSD and uPSD}
646
647 @end itemize
648
649 @section Other...
650 @itemize @bullet
651
652 @item @b{ep93xx}
653 @* An EP93xx based Linux machine using the GPIO pins directly.
654
655 @item @b{at91rm9200}
656 @* Like the EP93xx - but an ATMEL AT91RM9200 based solution using the GPIO pins on the chip.
657
658 @end itemize
659
660 @node Running
661 @chapter Running
662 @cindex running OpenOCD
663 @cindex --configfile
664 @cindex --debug_level
665 @cindex --logfile
666 @cindex --search
667
668 The @option{--help} option shows:
669 @verbatim
670 bash$ openocd --help
671
672 --help | -h display this help
673 --version | -v display OpenOCD version
674 --file | -f use configuration file <name>
675 --search | -s dir to search for config files and scripts
676 --debug | -d set debug level <0-3>
677 --log_output | -l redirect log output to file <name>
678 --command | -c run <command>
679 --pipe | -p use pipes when talking to gdb
680 @end verbatim
681
682 By default OpenOCD reads the file configuration file ``openocd.cfg''
683 in the current directory. To specify a different (or multiple)
684 configuration file, you can use the ``-f'' option. For example:
685
686 @example
687 openocd -f config1.cfg -f config2.cfg -f config3.cfg
688 @end example
689
690 Once started, OpenOCD runs as a daemon, waiting for connections from
691 clients (Telnet, GDB, Other).
692
693 If you are having problems, you can enable internal debug messages via
694 the ``-d'' option.
695
696 Also it is possible to interleave commands w/config scripts using the
697 @option{-c} command line switch.
698
699 To enable debug output (when reporting problems or working on OpenOCD
700 itself), use the @option{-d} command line switch. This sets the
701 @option{debug_level} to "3", outputting the most information,
702 including debug messages. The default setting is "2", outputting only
703 informational messages, warnings and errors. You can also change this
704 setting from within a telnet or gdb session using @option{debug_level
705 <n>} @xref{debug_level}.
706
707 You can redirect all output from the daemon to a file using the
708 @option{-l <logfile>} switch.
709
710 Search paths for config/script files can be added to OpenOCD by using
711 the @option{-s <search>} switch. The current directory and the OpenOCD
712 target library is in the search path by default.
713
714 For details on the @option{-p} option. @xref{Connecting to GDB}.
715
716 Note! OpenOCD will launch the GDB & telnet server even if it can not
717 establish a connection with the target. In general, it is possible for
718 the JTAG controller to be unresponsive until the target is set up
719 correctly via e.g. GDB monitor commands in a GDB init script.
720
721 @node Simple Configuration Files
722 @chapter Simple Configuration Files
723 @cindex configuration
724
725 @section Outline
726 There are 4 basic ways of ``configurating'' OpenOCD to run, they are:
727
728 @enumerate
729 @item A small openocd.cfg file which ``sources'' other configuration files
730 @item A monolithic openocd.cfg file
731 @item Many -f filename options on the command line
732 @item Your Mixed Solution
733 @end enumerate
734
735 @section Small configuration file method
736
737 This is the preferred method. It is simple and works well for many
738 people. The developers of OpenOCD would encourage you to use this
739 method. If you create a new configuration please email new
740 configurations to the development list.
741
742 Here is an example of an openocd.cfg file for an ATMEL at91sam7x256
743
744 @example
745 source [find interface/signalyzer.cfg]
746
747 # GDB can also flash my flash!
748 gdb_memory_map enable
749 gdb_flash_program enable
750
751 source [find target/sam7x256.cfg]
752 @end example
753
754 There are many example configuration scripts you can work with. You
755 should look in the directory: @t{$(INSTALLDIR)/lib/openocd}. You
756 should find:
757
758 @enumerate
759 @item @b{board} - eval board level configurations
760 @item @b{interface} - specific dongle configurations
761 @item @b{target} - the target chips
762 @item @b{tcl} - helper scripts
763 @item @b{xscale} - things specific to the xscale.
764 @end enumerate
765
766 Look first in the ``boards'' area, then the ``targets'' area. Often a board
767 configuration is a good example to work from.
768
769 @section Many -f filename options
770 Some believe this is a wonderful solution, others find it painful.
771
772 You can use a series of ``-f filename'' options on the command line,
773 OpenOCD will read each filename in sequence, for example:
774
775 @example
776 openocd -f file1.cfg -f file2.cfg -f file2.cfg
777 @end example
778
779 You can also intermix various commands with the ``-c'' command line
780 option.
781
782 @section Monolithic file
783 The ``Monolithic File'' dispenses with all ``source'' statements and
784 puts everything in one self contained (monolithic) file. This is not
785 encouraged.
786
787 Please try to ``source'' various files or use the multiple -f
788 technique.
789
790 @section Advice for you
791 Often, one uses a ``mixed approach''. Where possible, please try to
792 ``source'' common things, and if needed cut/paste parts of the
793 standard distribution configuration files as needed.
794
795 @b{REMEMBER:} The ``important parts'' of your configuration file are:
796
797 @enumerate
798 @item @b{Interface} - Defines the dongle
799 @item @b{Taps} - Defines the JTAG Taps
800 @item @b{GDB Targets} - What GDB talks to
801 @item @b{Flash Programing} - Very Helpful
802 @end enumerate
803
804 Some key things you should look at and understand are:
805
806 @enumerate
807 @item The reset configuration of your debug environment as a whole
808 @item Is there a ``work area'' that OpenOCD can use?
809 @* For ARM - work areas mean up to 10x faster downloads.
810 @item For MMU/MPU based ARM chips (i.e.: ARM9 and later) will that work area still be available?
811 @item For complex targets (multiple chips) the JTAG SPEED becomes an issue.
812 @end enumerate
813
814
815
816 @node Config File Guidelines
817 @chapter Config File Guidelines
818
819 This section/chapter is aimed at developers and integrators of
820 OpenOCD. These are guidelines for creating new boards and new target
821 configurations as of 28/Nov/2008.
822
823 However, you, the user of OpenOCD, should be somewhat familiar with
824 this section as it should help explain some of the internals of what
825 you might be looking at.
826
827 The user should find the following directories under @t{$(INSTALLDIR)/lib/openocd} :
828
829 @itemize @bullet
830 @item @b{interface}
831 @*Think JTAG Dongle. Files that configure the JTAG dongle go here.
832 @item @b{board}
833 @* Think Circuit Board, PWA, PCB, they go by many names. Board files
834 contain initialization items that are specific to a board - for
835 example: The SDRAM initialization sequence for the board, or the type
836 of external flash and what address it is found at. Any initialization
837 sequence to enable that external flash or SDRAM should be found in the
838 board file. Boards may also contain multiple targets, i.e.: Two CPUs, or
839 a CPU and an FPGA or CPLD.
840 @item @b{target}
841 @* Think chip. The ``target'' directory represents the JTAG TAPs
842 on a chip
843 which OpenOCD should control, not a board. Two common types of targets
844 are ARM chips and FPGA or CPLD chips.
845 When a chip has multiple TAPs (maybe it has both ARM and DSP cores),
846 the target config file defines all of them.
847 @end itemize
848
849 @b{If needed...} The user in their ``openocd.cfg'' file or the board
850 file might override a specific feature in any of the above files by
851 setting a variable or two before sourcing the target file. Or adding
852 various commands specific to their situation.
853
854 @section Interface Config Files
855
856 The user should be able to source one of these files via a command like this:
857
858 @example
859 source [find interface/FOOBAR.cfg]
860 Or:
861 openocd -f interface/FOOBAR.cfg
862 @end example
863
864 A preconfigured interface file should exist for every interface in use
865 today, that said, perhaps some interfaces have only been used by the
866 sole developer who created it.
867
868 Interface files should be found in @t{$(INSTALLDIR)/lib/openocd/interface}
869
870 @section Board Config Files
871
872 @b{Note: BOARD directory NEW as of 28/nov/2008}
873
874 The user should be able to source one of these files via a command like this:
875
876 @example
877 source [find board/FOOBAR.cfg]
878 Or:
879 openocd -f board/FOOBAR.cfg
880 @end example
881
882
883 The board file should contain one or more @t{source [find
884 target/FOO.cfg]} statements along with any board specific things.
885
886 In summary the board files should contain (if present)
887
888 @enumerate
889 @item External flash configuration (i.e.: NOR flash on CS0, two NANDs on CS2)
890 @item SDRAM configuration (size, speed, etc.
891 @item Board specific IO configuration (i.e.: GPIO pins might disable a 2nd flash)
892 @item Multiple TARGET source statements
893 @item Reset configuration
894 @item All things that are not ``inside a chip''
895 @item Things inside a chip go in a 'target' file
896 @end enumerate
897
898 @section Target Config Files
899
900 The user should be able to source one of these files via a command like this:
901
902 @example
903 source [find target/FOOBAR.cfg]
904 Or:
905 openocd -f target/FOOBAR.cfg
906 @end example
907
908 In summary the target files should contain
909
910 @enumerate
911 @item Set defaults
912 @item Add TAPs to the scan chain
913 @item Add CPU targets
914 @item CPU/Chip/CPU-Core specific features
915 @item On-Chip flash
916 @end enumerate
917
918 @subsection Important variable names
919
920 By default, the end user should never need to set these
921 variables. However, if the user needs to override a setting they only
922 need to set the variable in a simple way.
923
924 @itemize @bullet
925 @item @b{CHIPNAME}
926 @* This gives a name to the overall chip, and is used as part of the
927 tap identifier dotted name.
928 @item @b{ENDIAN}
929 @* By default little - unless the chip or board is not normally used that way.
930 @item @b{CPUTAPID}
931 @* When OpenOCD examines the JTAG chain, it will attempt to identify
932 every chip. If the @t{-expected-id} is nonzero, OpenOCD attempts
933 to verify the tap id number verses configuration file and may issue an
934 error or warning like this. The hope is that this will help to pinpoint
935 problems in OpenOCD configurations.
936
937 @example
938 Info: JTAG tap: sam7x256.cpu tap/device found: 0x3f0f0f0f
939 (Manufacturer: 0x787, Part: 0xf0f0, Version: 0x3)
940 Error: ERROR: Tap: sam7x256.cpu - Expected id: 0x12345678,
941 Got: 0x3f0f0f0f
942 Error: ERROR: expected: mfg: 0x33c, part: 0x2345, ver: 0x1
943 Error: ERROR: got: mfg: 0x787, part: 0xf0f0, ver: 0x3
944 @end example
945
946 @item @b{_TARGETNAME}
947 @* By convention, this variable is created by the target configuration
948 script. The board configuration file may make use of this variable to
949 configure things like a ``reset init'' script, or other things
950 specific to that board and that target.
951
952 If the chip has 2 targets, use the names @b{_TARGETNAME0},
953 @b{_TARGETNAME1}, ... etc.
954
955 @b{Remember:} The ``board file'' may include multiple targets.
956
957 At no time should the name ``target0'' (the default target name if
958 none was specified) be used. The name ``target0'' is a hard coded name
959 - the next target on the board will be some other number.
960 In the same way, avoid using target numbers even when they are
961 permitted; use the right target name(s) for your board.
962
963 The user (or board file) should reasonably be able to:
964
965 @example
966 source [find target/FOO.cfg]
967 $_TARGETNAME configure ... FOO specific parameters
968
969 source [find target/BAR.cfg]
970 $_TARGETNAME configure ... BAR specific parameters
971 @end example
972
973 @end itemize
974
975 @subsection Tcl Variables Guide Line
976 The Full Tcl/Tk language supports ``namespaces'' - JIM-Tcl does not.
977
978 Thus the rule we follow in OpenOCD is this: Variables that begin with
979 a leading underscore are temporary in nature, and can be modified and
980 used at will within a ?TARGET? configuration file.
981
982 @b{EXAMPLE:} The user should be able to do this:
983
984 @example
985 # Board has 3 chips,
986 # PXA270 #1 network side, big endian
987 # PXA270 #2 video side, little endian
988 # Xilinx Glue logic
989 set CHIPNAME network
990 set ENDIAN big
991 source [find target/pxa270.cfg]
992 # variable: _TARGETNAME = network.cpu
993 # other commands can refer to the "network.cpu" tap.
994 $_TARGETNAME configure .... params for this CPU..
995
996 set ENDIAN little
997 set CHIPNAME video
998 source [find target/pxa270.cfg]
999 # variable: _TARGETNAME = video.cpu
1000 # other commands can refer to the "video.cpu" tap.
1001 $_TARGETNAME configure .... params for this CPU..
1002
1003 unset ENDIAN
1004 set CHIPNAME xilinx
1005 source [find target/spartan3.cfg]
1006
1007 # Since $_TARGETNAME is temporal..
1008 # these names still work!
1009 network.cpu configure ... params
1010 video.cpu configure ... params
1011 @end example
1012
1013 @subsection Default Value Boiler Plate Code
1014
1015 All target configuration files should start with this (or a modified form)
1016
1017 @example
1018 # SIMPLE example
1019 if @{ [info exists CHIPNAME] @} @{
1020 set _CHIPNAME $CHIPNAME
1021 @} else @{
1022 set _CHIPNAME sam7x256
1023 @}
1024
1025 if @{ [info exists ENDIAN] @} @{
1026 set _ENDIAN $ENDIAN
1027 @} else @{
1028 set _ENDIAN little
1029 @}
1030
1031 if @{ [info exists CPUTAPID ] @} @{
1032 set _CPUTAPID $CPUTAPID
1033 @} else @{
1034 set _CPUTAPID 0x3f0f0f0f
1035 @}
1036 @end example
1037
1038 @subsection Adding TAPs to the Scan Chain
1039 After the ``defaults'' are set up,
1040 add the TAPs on each chip to the JTAG scan chain.
1041 @xref{TAP Declaration}, and the naming convention
1042 for taps.
1043
1044 In the simplest case the chip has only one TAP,
1045 probably for a CPU or FPGA.
1046 The config file for the Atmel AT91SAM7X256
1047 looks (in part) like this:
1048
1049 @example
1050 jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf \
1051 -expected-id $_CPUTAPID
1052 @end example
1053
1054 A board with two such at91sam7 chips would be able
1055 to source such a config file twice, with different
1056 values for @code{CHIPNAME}, so
1057 it adds a different TAP each time.
1058
1059 There are more complex examples too, with chips that have
1060 multiple TAPs. Ones worth looking at include:
1061
1062 @itemize
1063 @item @file{target/omap3530.cfg} -- with a disabled ARM, and a JRC
1064 (there's a DSP too, which is not listed)
1065 @item @file{target/str912.cfg} -- with flash, CPU, and boundary scan
1066 @item @file{target/ti_dm355.cfg} -- with ETM, ARM, and JRC (this JRC
1067 is not currently used)
1068 @end itemize
1069
1070 @subsection Add CPU targets
1071
1072 After adding a TAP for a CPU, you should set it up so that
1073 GDB and other commands can use it.
1074 @xref{CPU Configuration}.
1075 For the at91sam7 example above, the command can look like this:
1076
1077 @example
1078 set _TARGETNAME $_CHIPNAME.cpu
1079 target create $_TARGETNAME arm7tdmi -chain-position $_TARGETNAME
1080 @end example
1081
1082 Work areas are small RAM areas associated with CPU targets.
1083 They are used by OpenOCD to speed up downloads,
1084 and to download small snippets of code to program flash chips.
1085 If the chip includes a form of ``on-chip-ram'' - and many do - define
1086 a work area if you can.
1087 Again using the at91sam7 as an example, this can look like:
1088
1089 @example
1090 $_TARGETNAME configure -work-area-phys 0x00200000 \
1091 -work-area-size 0x4000 -work-area-backup 0
1092 @end example
1093
1094 @subsection Reset Configuration
1095
1096 As a rule, you should put the @command{reset_config} command
1097 into the board file. Most things you think you know about a
1098 chip can be tweaked by the board.
1099
1100 Some chips have specific ways the TRST and SRST signals are
1101 managed. In the unusual case that these are @emph{chip specific}
1102 and can never be changed by board wiring, they could go here.
1103
1104 @subsection ARM Core Specific Hacks
1105
1106 If the chip has a DCC, enable it. If the chip is an ARM9 with some
1107 special high speed download features - enable it.
1108
1109 If the chip has an ARM ``vector catch'' feature - by default enable
1110 it for Undefined Instructions, Data Abort, and Prefetch Abort, if the
1111 user is really writing a handler for those situations - they can
1112 easily disable it. Experiance has shown the ``vector catch'' is
1113 helpful - for common programing errors.
1114
1115 If present, the MMU, the MPU and the CACHE should be disabled.
1116
1117 Some ARM cores are equipped with trace support, which permits
1118 examination of the instruction and data bus activity. Trace
1119 activity is controlled through an ``Embedded Trace Module'' (ETM)
1120 on one of the core's scan chains. The ETM emits voluminous data
1121 through a ``trace port''. (@xref{ARM Tracing}.)
1122 If you are using an external trace port,
1123 configure it in your board config file.
1124 If you are using an on-chip ``Embedded Trace Buffer'' (ETB),
1125 configure it in your target config file.
1126
1127 @example
1128 etm config $_TARGETNAME 16 normal full etb
1129 etb config $_TARGETNAME $_CHIPNAME.etb
1130 @end example
1131
1132 @subsection Internal Flash Configuration
1133
1134 This applies @b{ONLY TO MICROCONTROLLERS} that have flash built in.
1135
1136 @b{Never ever} in the ``target configuration file'' define any type of
1137 flash that is external to the chip. (For example a BOOT flash on
1138 Chip Select 0.) Such flash information goes in a board file - not
1139 the TARGET (chip) file.
1140
1141 Examples:
1142 @itemize @bullet
1143 @item at91sam7x256 - has 256K flash YES enable it.
1144 @item str912 - has flash internal YES enable it.
1145 @item imx27 - uses boot flash on CS0 - it goes in the board file.
1146 @item pxa270 - again - CS0 flash - it goes in the board file.
1147 @end itemize
1148
1149 @node About JIM-Tcl
1150 @chapter About JIM-Tcl
1151 @cindex JIM Tcl
1152 @cindex tcl
1153
1154 OpenOCD includes a small ``TCL Interpreter'' known as JIM-TCL. You can
1155 learn more about JIM here: @url{http://jim.berlios.de}
1156
1157 @itemize @bullet
1158 @item @b{JIM vs. Tcl}
1159 @* JIM-TCL is a stripped down version of the well known Tcl language,
1160 which can be found here: @url{http://www.tcl.tk}. JIM-Tcl has far
1161 fewer features. JIM-Tcl is a single .C file and a single .H file and
1162 impliments the basic Tcl command set along. In contrast: Tcl 8.6 is a
1163 4.2 MB .zip file containing 1540 files.
1164
1165 @item @b{Missing Features}
1166 @* Our practice has been: Add/clone the real Tcl feature if/when
1167 needed. We welcome JIM Tcl improvements, not bloat.
1168
1169 @item @b{Scripts}
1170 @* OpenOCD configuration scripts are JIM Tcl Scripts. OpenOCD's
1171 command interpreter today (28/nov/2008) is a mixture of (newer)
1172 JIM-Tcl commands, and (older) the orginal command interpreter.
1173
1174 @item @b{Commands}
1175 @* At the OpenOCD telnet command line (or via the GDB mon command) one
1176 can type a Tcl for() loop, set variables, etc.
1177
1178 @item @b{Historical Note}
1179 @* JIM-Tcl was introduced to OpenOCD in spring 2008.
1180
1181 @item @b{Need a crash course in Tcl?}
1182 @*@xref{Tcl Crash Course}.
1183 @end itemize
1184
1185 @node Daemon Configuration
1186 @chapter Daemon Configuration
1187 @cindex initialization
1188 The commands here are commonly found in the openocd.cfg file and are
1189 used to specify what TCP/IP ports are used, and how GDB should be
1190 supported.
1191
1192 @section Configuration Stage
1193 @cindex configuration stage
1194 @cindex configuration command
1195
1196 When the OpenOCD server process starts up, it enters a
1197 @emph{configuration stage} which is the only time that
1198 certain commands, @emph{configuration commands}, may be issued.
1199 Those configuration commands include declaration of TAPs
1200 and other basic setup.
1201 The server must leave the configuration stage before it
1202 may access or activate TAPs.
1203 After it leaves this stage, configuration commands may no
1204 longer be issued.
1205
1206 @deffn {Config Command} init
1207 This command terminates the configuration stage and
1208 enters the normal command mode. This can be useful to add commands to
1209 the startup scripts and commands such as resetting the target,
1210 programming flash, etc. To reset the CPU upon startup, add "init" and
1211 "reset" at the end of the config script or at the end of the OpenOCD
1212 command line using the @option{-c} command line switch.
1213
1214 If this command does not appear in any startup/configuration file
1215 OpenOCD executes the command for you after processing all
1216 configuration files and/or command line options.
1217
1218 @b{NOTE:} This command normally occurs at or near the end of your
1219 openocd.cfg file to force OpenOCD to ``initialize'' and make the
1220 targets ready. For example: If your openocd.cfg file needs to
1221 read/write memory on your target, @command{init} must occur before
1222 the memory read/write commands. This includes @command{nand probe}.
1223 @end deffn
1224
1225 @section TCP/IP Ports
1226 @cindex TCP port
1227 @cindex server
1228 @cindex port
1229 The OpenOCD server accepts remote commands in several syntaxes.
1230 Each syntax uses a different TCP/IP port, which you may specify
1231 only during configuration (before those ports are opened).
1232
1233 @deffn {Command} gdb_port (number)
1234 @cindex GDB server
1235 Specify or query the first port used for incoming GDB connections.
1236 The GDB port for the
1237 first target will be gdb_port, the second target will listen on gdb_port + 1, and so on.
1238 When not specified during the configuration stage,
1239 the port @var{number} defaults to 3333.
1240 @end deffn
1241
1242 @deffn {Command} tcl_port (number)
1243 Specify or query the port used for a simplified RPC
1244 connection that can be used by clients to issue TCL commands and get the
1245 output from the Tcl engine.
1246 Intended as a machine interface.
1247 When not specified during the configuration stage,
1248 the port @var{number} defaults to 6666.
1249 @end deffn
1250
1251 @deffn {Command} telnet_port (number)
1252 Specify or query the
1253 port on which to listen for incoming telnet connections.
1254 This port is intended for interaction with one human through TCL commands.
1255 When not specified during the configuration stage,
1256 the port @var{number} defaults to 4444.
1257 @end deffn
1258
1259 @anchor{GDB Configuration}
1260 @section GDB Configuration
1261 @cindex GDB
1262 @cindex GDB configuration
1263 You can reconfigure some GDB behaviors if needed.
1264 The ones listed here are static and global.
1265 @xref{Target Configuration}, about configuring individual targets.
1266 @xref{Target Events}, about configuring target-specific event handling.
1267
1268 @anchor{gdb_breakpoint_override}
1269 @deffn {Command} gdb_breakpoint_override [@option{hard}|@option{soft}|@option{disable}]
1270 Force breakpoint type for gdb @command{break} commands.
1271 This option supports GDB GUIs which don't
1272 distinguish hard versus soft breakpoints, if the default OpenOCD and
1273 GDB behaviour is not sufficient. GDB normally uses hardware
1274 breakpoints if the memory map has been set up for flash regions.
1275 @end deffn
1276
1277 @deffn {Config command} gdb_detach (@option{resume}|@option{reset}|@option{halt}|@option{nothing})
1278 Configures what OpenOCD will do when GDB detaches from the daemon.
1279 Default behaviour is @option{resume}.
1280 @end deffn
1281
1282 @anchor{gdb_flash_program}
1283 @deffn {Config command} gdb_flash_program (@option{enable}|@option{disable})
1284 Set to @option{enable} to cause OpenOCD to program the flash memory when a
1285 vFlash packet is received.
1286 The default behaviour is @option{enable}.
1287 @end deffn
1288
1289 @deffn {Config command} gdb_memory_map (@option{enable}|@option{disable})
1290 Set to @option{enable} to cause OpenOCD to send the memory configuration to GDB when
1291 requested. GDB will then know when to set hardware breakpoints, and program flash
1292 using the GDB load command. @command{gdb_flash_program enable} must also be enabled
1293 for flash programming to work.
1294 Default behaviour is @option{enable}.
1295 @xref{gdb_flash_program}.
1296 @end deffn
1297
1298 @deffn {Config command} gdb_report_data_abort (@option{enable}|@option{disable})
1299 Specifies whether data aborts cause an error to be reported
1300 by GDB memory read packets.
1301 The default behaviour is @option{disable};
1302 use @option{enable} see these errors reported.
1303 @end deffn
1304
1305 @node Interface - Dongle Configuration
1306 @chapter Interface - Dongle Configuration
1307 JTAG Adapters/Interfaces/Dongles are normally configured
1308 through commands in an interface configuration
1309 file which is sourced by your @file{openocd.cfg} file, or
1310 through a command line @option{-f interface/....cfg} option.
1311
1312 @example
1313 source [find interface/olimex-jtag-tiny.cfg]
1314 @end example
1315
1316 These commands tell
1317 OpenOCD what type of JTAG adapter you have, and how to talk to it.
1318 A few cases are so simple that you only need to say what driver to use:
1319
1320 @example
1321 # jlink interface
1322 interface jlink
1323 @end example
1324
1325 Most adapters need a bit more configuration than that.
1326
1327
1328 @section Interface Configuration
1329
1330 The interface command tells OpenOCD what type of JTAG dongle you are
1331 using. Depending on the type of dongle, you may need to have one or
1332 more additional commands.
1333
1334 @deffn {Config Command} {interface} name
1335 Use the interface driver @var{name} to connect to the
1336 target.
1337 @end deffn
1338
1339 @deffn Command {jtag interface}
1340 Returns the name of the interface driver being used.
1341 @end deffn
1342
1343 @section Interface Drivers
1344
1345 Each of the interface drivers listed here must be explicitly
1346 enabled when OpenOCD is configured, in order to be made
1347 available at run time.
1348
1349 @deffn {Interface Driver} {amt_jtagaccel}
1350 Amontec Chameleon in its JTAG Accelerator configuration,
1351 connected to a PC's EPP mode parallel port.
1352 This defines some driver-specific commands:
1353
1354 @deffn {Config Command} {parport_port} number
1355 Specifies either the address of the I/O port (default: 0x378 for LPT1) or
1356 the number of the @file{/dev/parport} device.
1357 @end deffn
1358
1359 @deffn {Config Command} rtck [@option{enable}|@option{disable}]
1360 Displays status of RTCK option.
1361 Optionally sets that option first.
1362 @end deffn
1363 @end deffn
1364
1365 @deffn {Interface Driver} {arm-jtag-ew}
1366 Olimex ARM-JTAG-EW USB adapter
1367 This has one driver-specific command:
1368
1369 @deffn Command {armjtagew_info}
1370 Logs some status
1371 @end deffn
1372 @end deffn
1373
1374 @deffn {Interface Driver} {at91rm9200}
1375 Supports bitbanged JTAG from the local system,
1376 presuming that system is an Atmel AT91rm9200
1377 and a specific set of GPIOs is used.
1378 @c command: at91rm9200_device NAME
1379 @c chooses among list of bit configs ... only one option
1380 @end deffn
1381
1382 @deffn {Interface Driver} {dummy}
1383 A dummy software-only driver for debugging.
1384 @end deffn
1385
1386 @deffn {Interface Driver} {ep93xx}
1387 Cirrus Logic EP93xx based single-board computer bit-banging (in development)
1388 @end deffn
1389
1390 @deffn {Interface Driver} {ft2232}
1391 FTDI FT2232 (USB) based devices over one of the userspace libraries.
1392 These interfaces have several commands, used to configure the driver
1393 before initializing the JTAG scan chain:
1394
1395 @deffn {Config Command} {ft2232_device_desc} description
1396 Provides the USB device description (the @emph{iProduct string})
1397 of the FTDI FT2232 device. If not
1398 specified, the FTDI default value is used. This setting is only valid
1399 if compiled with FTD2XX support.
1400 @end deffn
1401
1402 @deffn {Config Command} {ft2232_serial} serial-number
1403 Specifies the @var{serial-number} of the FTDI FT2232 device to use,
1404 in case the vendor provides unique IDs and more than one FT2232 device
1405 is connected to the host.
1406 If not specified, serial numbers are not considered.
1407 @end deffn
1408
1409 @deffn {Config Command} {ft2232_layout} name
1410 Each vendor's FT2232 device can use different GPIO signals
1411 to control output-enables, reset signals, and LEDs.
1412 Currently valid layout @var{name} values include:
1413 @itemize @minus
1414 @item @b{axm0432_jtag} Axiom AXM-0432
1415 @item @b{comstick} Hitex STR9 comstick
1416 @item @b{cortino} Hitex Cortino JTAG interface
1417 @item @b{evb_lm3s811} Luminary Micro EVB_LM3S811 as a JTAG interface
1418 (bypassing onboard processor), no TRST or SRST signals on external connector
1419 @item @b{flyswatter} Tin Can Tools Flyswatter
1420 @item @b{icebear} ICEbear JTAG adapter from Section 5
1421 @item @b{jtagkey} Amontec JTAGkey and JTAGkey-Tiny (and compatibles)
1422 @item @b{m5960} American Microsystems M5960
1423 @item @b{olimex-jtag} Olimex ARM-USB-OCD and ARM-USB-Tiny
1424 @item @b{oocdlink} OOCDLink
1425 @c oocdlink ~= jtagkey_prototype_v1
1426 @item @b{sheevaplug} Marvell Sheevaplug development kit
1427 @item @b{signalyzer} Xverve Signalyzer
1428 @item @b{stm32stick} Hitex STM32 Performance Stick
1429 @item @b{turtelizer2} egnite Software turtelizer2
1430 @item @b{usbjtag} "USBJTAG-1" layout described in the OpenOCD diploma thesis
1431 @end itemize
1432 @end deffn
1433
1434 @deffn {Config Command} {ft2232_vid_pid} [vid pid]+
1435 The vendor ID and product ID of the FTDI FT2232 device. If not specified, the FTDI
1436 default values are used.
1437 Currently, up to eight [@var{vid}, @var{pid}] pairs may be given, e.g.
1438 @example
1439 ft2232_vid_pid 0x0403 0xcff8 0x15ba 0x0003
1440 @end example
1441 @end deffn
1442
1443 @deffn {Config Command} {ft2232_latency} ms
1444 On some systems using FT2232 based JTAG interfaces the FT_Read function call in
1445 ft2232_read() fails to return the expected number of bytes. This can be caused by
1446 USB communication delays and has proved hard to reproduce and debug. Setting the
1447 FT2232 latency timer to a larger value increases delays for short USB packets but it
1448 also reduces the risk of timeouts before receiving the expected number of bytes.
1449 The OpenOCD default value is 2 and for some systems a value of 10 has proved useful.
1450 @end deffn
1451
1452 For example, the interface config file for a
1453 Turtelizer JTAG Adapter looks something like this:
1454
1455 @example
1456 interface ft2232
1457 ft2232_device_desc "Turtelizer JTAG/RS232 Adapter"
1458 ft2232_layout turtelizer2
1459 ft2232_vid_pid 0x0403 0xbdc8
1460 @end example
1461 @end deffn
1462
1463 @deffn {Interface Driver} {gw16012}
1464 Gateworks GW16012 JTAG programmer.
1465 This has one driver-specific command:
1466
1467 @deffn {Config Command} {parport_port} number
1468 Specifies either the address of the I/O port (default: 0x378 for LPT1) or
1469 the number of the @file{/dev/parport} device.
1470 @end deffn
1471 @end deffn
1472
1473 @deffn {Interface Driver} {jlink}
1474 Segger jlink USB adapter
1475 @c command: jlink_info
1476 @c dumps status
1477 @c command: jlink_hw_jtag (2|3)
1478 @c sets version 2 or 3
1479 @end deffn
1480
1481 @deffn {Interface Driver} {parport}
1482 Supports PC parallel port bit-banging cables:
1483 Wigglers, PLD download cable, and more.
1484 These interfaces have several commands, used to configure the driver
1485 before initializing the JTAG scan chain:
1486
1487 @deffn {Config Command} {parport_cable} name
1488 The layout of the parallel port cable used to connect to the target.
1489 Currently valid cable @var{name} values include:
1490
1491 @itemize @minus
1492 @item @b{altium} Altium Universal JTAG cable.
1493 @item @b{arm-jtag} Same as original wiggler except SRST and
1494 TRST connections reversed and TRST is also inverted.
1495 @item @b{chameleon} The Amontec Chameleon's CPLD when operated
1496 in configuration mode. This is only used to
1497 program the Chameleon itself, not a connected target.
1498 @item @b{dlc5} The Xilinx Parallel cable III.
1499 @item @b{flashlink} The ST Parallel cable.
1500 @item @b{lattice} Lattice ispDOWNLOAD Cable
1501 @item @b{old_amt_wiggler} The Wiggler configuration that comes with
1502 some versions of
1503 Amontec's Chameleon Programmer. The new version available from
1504 the website uses the original Wiggler layout ('@var{wiggler}')
1505 @item @b{triton} The parallel port adapter found on the
1506 ``Karo Triton 1 Development Board''.
1507 This is also the layout used by the HollyGates design
1508 (see @uref{http://www.lartmaker.nl/projects/jtag/}).
1509 @item @b{wiggler} The original Wiggler layout, also supported by
1510 several clones, such as the Olimex ARM-JTAG
1511 @item @b{wiggler2} Same as original wiggler except an led is fitted on D5.
1512 @item @b{wiggler_ntrst_inverted} Same as original wiggler except TRST is inverted.
1513 @end itemize
1514 @end deffn
1515
1516 @deffn {Config Command} {parport_port} number
1517 Either the address of the I/O port (default: 0x378 for LPT1) or the number of
1518 the @file{/dev/parport} device
1519
1520 When using PPDEV to access the parallel port, use the number of the parallel port:
1521 @option{parport_port 0} (the default). If @option{parport_port 0x378} is specified
1522 you may encounter a problem.
1523 @end deffn
1524
1525 @deffn {Config Command} {parport_write_on_exit} (on|off)
1526 This will configure the parallel driver to write a known
1527 cable-specific value to the parallel interface on exiting OpenOCD
1528 @end deffn
1529
1530 For example, the interface configuration file for a
1531 classic ``Wiggler'' cable might look something like this:
1532
1533 @example
1534 interface parport
1535 parport_port 0xc8b8
1536 parport_cable wiggler
1537 @end example
1538 @end deffn
1539
1540 @deffn {Interface Driver} {presto}
1541 ASIX PRESTO USB JTAG programmer.
1542 @c command: presto_serial str
1543 @c sets serial number
1544 @end deffn
1545
1546 @deffn {Interface Driver} {rlink}
1547 Raisonance RLink USB adapter
1548 @end deffn
1549
1550 @deffn {Interface Driver} {usbprog}
1551 usbprog is a freely programmable USB adapter.
1552 @end deffn
1553
1554 @deffn {Interface Driver} {vsllink}
1555 vsllink is part of Versaloon which is a versatile USB programmer.
1556
1557 @quotation Note
1558 This defines quite a few driver-specific commands,
1559 which are not currently documented here.
1560 @end quotation
1561 @end deffn
1562
1563 @deffn {Interface Driver} {ZY1000}
1564 This is the Zylin ZY1000 JTAG debugger.
1565
1566 @quotation Note
1567 This defines some driver-specific commands,
1568 which are not currently documented here.
1569 @end quotation
1570
1571 @deffn Command power [@option{on}|@option{off}]
1572 Turn power switch to target on/off.
1573 No arguments: print status.
1574 @end deffn
1575
1576 @end deffn
1577
1578 @anchor{JTAG Speed}
1579 @section JTAG Speed
1580 JTAG clock setup is part of system setup.
1581 It @emph{does not belong with interface setup} since any interface
1582 only knows a few of the constraints for the JTAG clock speed.
1583 Sometimes the JTAG speed is
1584 changed during the target initialization process: (1) slow at
1585 reset, (2) program the CPU clocks, (3) run fast.
1586 Both the "slow" and "fast" clock rates are functions of the
1587 oscillators used, the chip, the board design, and sometimes
1588 power management software that may be active.
1589
1590 The speed used during reset can be adjusted using pre_reset
1591 and post_reset event handlers.
1592 @xref{Target Events}.
1593
1594 If your system supports adaptive clocking (RTCK), configuring
1595 JTAG to use that is probably the most robust approach.
1596 However, it introduces delays to synchronize clocks; so it
1597 may not be the fastest solution.
1598
1599 @b{NOTE:} Script writers should consider using @command{jtag_rclk}
1600 instead of @command{jtag_khz}.
1601
1602 @deffn {Command} jtag_khz max_speed_kHz
1603 A non-zero speed is in KHZ. Hence: 3000 is 3mhz.
1604 JTAG interfaces usually support a limited number of
1605 speeds. The speed actually used won't be faster
1606 than the speed specified.
1607
1608 As a rule of thumb, if you specify a clock rate make
1609 sure the JTAG clock is no more than @math{1/6th CPU-Clock}.
1610 This is especially true for synthesized cores (ARMxxx-S).
1611
1612 Speed 0 (khz) selects RTCK method.
1613 @xref{FAQ RTCK}.
1614 If your system uses RTCK, you won't need to change the
1615 JTAG clocking after setup.
1616 Not all interfaces, boards, or targets support ``rtck''.
1617 If the interface device can not
1618 support it, an error is returned when you try to use RTCK.
1619 @end deffn
1620
1621 @defun jtag_rclk fallback_speed_kHz
1622 @cindex RTCK
1623 This Tcl proc (defined in startup.tcl) attempts to enable RTCK/RCLK.
1624 If that fails (maybe the interface, board, or target doesn't
1625 support it), falls back to the specified frequency.
1626 @example
1627 # Fall back to 3mhz if RTCK is not supported
1628 jtag_rclk 3000
1629 @end example
1630 @end defun
1631
1632 @node Reset Configuration
1633 @chapter Reset Configuration
1634 @cindex Reset Configuration
1635
1636 Every system configuration may require a different reset
1637 configuration. This can also be quite confusing.
1638 Resets also interact with @var{reset-init} event handlers,
1639 which do things like setting up clocks and DRAM, and
1640 JTAG clock rates. (@xref{JTAG Speed}.)
1641 Please see the various board files for examples.
1642
1643 @quotation Note
1644 To maintainers and integrators:
1645 Reset configuration touches several things at once.
1646 Normally the board configuration file
1647 should define it and assume that the JTAG adapter supports
1648 everything that's wired up to the board's JTAG connector.
1649 However, the target configuration file could also make note
1650 of something the silicon vendor has done inside the chip,
1651 which will be true for most (or all) boards using that chip.
1652 And when the JTAG adapter doesn't support everything, the
1653 system configuration file will need to override parts of
1654 the reset configuration provided by other files.
1655 @end quotation
1656
1657 @section Types of Reset
1658
1659 There are many kinds of reset possible through JTAG, but
1660 they may not all work with a given board and adapter.
1661 That's part of why reset configuration can be error prone.
1662
1663 @itemize @bullet
1664 @item
1665 @emph{System Reset} ... the @emph{SRST} hardware signal
1666 resets all chips connected to the JTAG adapter, such as processors,
1667 power management chips, and I/O controllers. Normally resets triggered
1668 with this signal behave exactly like pressing a RESET button.
1669 @item
1670 @emph{JTAG TAP Reset} ... the @emph{TRST} hardware signal resets
1671 just the TAP controllers connected to the JTAG adapter.
1672 Such resets should not be visible to the rest of the system; resetting a
1673 device's the TAP controller just puts that controller into a known state.
1674 @item
1675 @emph{Emulation Reset} ... many devices can be reset through JTAG
1676 commands. These resets are often distinguishable from system
1677 resets, either explicitly (a "reset reason" register says so)
1678 or implicitly (not all parts of the chip get reset).
1679 @item
1680 @emph{Other Resets} ... system-on-chip devices often support
1681 several other types of reset.
1682 You may need to arrange that a watchdog timer stops
1683 while debugging, preventing a watchdog reset.
1684 There may be individual module resets.
1685 @end itemize
1686
1687 In the best case, OpenOCD can hold SRST, then reset
1688 the TAPs via TRST and send commands through JTAG to halt the
1689 CPU at the reset vector before the 1st instruction is executed.
1690 Then when it finally releases the SRST signal, the system is
1691 halted under debugger control before any code has executed.
1692 This is the behavior required to support the @command{reset halt}
1693 and @command{reset init} commands; after @command{reset init} a
1694 board-specific script might do things like setting up DRAM.
1695 (@xref{Reset Command}.)
1696
1697 @section SRST and TRST Issues
1698
1699 Because SRST and TRST are hardware signals, they can have a
1700 variety of system-specific constraints. Some of the most
1701 common issues are:
1702
1703 @itemize @bullet
1704
1705 @item @emph{Signal not available} ... Some boards don't wire
1706 SRST or TRST to the JTAG connector. Some JTAG adapters don't
1707 support such signals even if they are wired up.
1708 Use the @command{reset_config} @var{signals} options to say
1709 when one of those signals is not connected.
1710 When SRST is not available, your code might not be able to rely
1711 on controllers having been fully reset during code startup.
1712
1713 @item @emph{Signals shorted} ... Sometimes a chip, board, or
1714 adapter will connect SRST to TRST, instead of keeping them separate.
1715 Use the @command{reset_config} @var{combination} options to say
1716 when those signals aren't properly independent.
1717
1718 @item @emph{Timing} ... Reset circuitry like a resistor/capacitor
1719 delay circuit, reset supervisor, or on-chip features can extend
1720 the effect of a JTAG adapter's reset for some time after the adapter
1721 stops issuing the reset. For example, there may be chip or board
1722 requirements that all reset pulses last for at least a
1723 certain amount of time; and reset buttons commonly have
1724 hardware debouncing.
1725 Use the @command{jtag_nsrst_delay} and @command{jtag_ntrst_delay}
1726 commands to say when extra delays are needed.
1727
1728 @item @emph{Drive type} ... Reset lines often have a pullup
1729 resistor, letting the JTAG interface treat them as open-drain
1730 signals. But that's not a requirement, so the adapter may need
1731 to use push/pull output drivers.
1732 Also, with weak pullups it may be advisable to drive
1733 signals to both levels (push/pull) to minimize rise times.
1734 Use the @command{reset_config} @var{trst_type} and
1735 @var{srst_type} parameters to say how to drive reset signals.
1736
1737 @item @emph{Special initialization} ... Targets sometimes need
1738 special JTAG initialization sequences to handle chip-specific
1739 issues (not limited to errata).
1740 For example, certain JTAG commands might need to be issued while
1741 the system as a whole is in a reset state (SRST active)
1742 but the JTAG scan chain is usable (TRST inactive).
1743 (@xref{JTAG Commands}, where the @command{jtag_reset}
1744 command is presented.)
1745 @end itemize
1746
1747 There can also be other issues.
1748 Some devices don't fully conform to the JTAG specifications.
1749 Trivial system-specific differences are common, such as
1750 SRST and TRST using slightly different names.
1751 There are also vendors who distribute key JTAG documentation for
1752 their chips only to developers who have signed a Non-Disclosure
1753 Agreement (NDA).
1754
1755 Sometimes there are chip-specific extensions like a requirement to use
1756 the normally-optional TRST signal (precluding use of JTAG adapters which
1757 don't pass TRST through), or needing extra steps to complete a TAP reset.
1758
1759 In short, SRST and especially TRST handling may be very finicky,
1760 needing to cope with both architecture and board specific constraints.
1761
1762 @section Commands for Handling Resets
1763
1764 @deffn {Command} jtag_nsrst_delay milliseconds
1765 How long (in milliseconds) OpenOCD should wait after deasserting
1766 nSRST (active-low system reset) before starting new JTAG operations.
1767 When a board has a reset button connected to SRST line it will
1768 probably have hardware debouncing, implying you should use this.
1769 @end deffn
1770
1771 @deffn {Command} jtag_ntrst_delay milliseconds
1772 How long (in milliseconds) OpenOCD should wait after deasserting
1773 nTRST (active-low JTAG TAP reset) before starting new JTAG operations.
1774 @end deffn
1775
1776 @deffn {Command} reset_config mode_flag ...
1777 This command tells OpenOCD the reset configuration
1778 of your combination of JTAG board and target in target
1779 configuration scripts.
1780
1781 If you have an interface that does not support SRST and
1782 TRST(unlikely), then you may be able to work around that
1783 problem by using a reset_config command to override any
1784 settings in the target configuration script.
1785
1786 SRST and TRST has a fairly well understood definition and
1787 behaviour in the JTAG specification, but vendors take
1788 liberties to achieve various more or less clearly understood
1789 goals. Sometimes documentation is available, other times it
1790 is not. OpenOCD has the reset_config command to allow OpenOCD
1791 to deal with the various common cases.
1792
1793 The @var{mode_flag} options can be specified in any order, but only one
1794 of each type -- @var{signals}, @var{combination}, @var{trst_type},
1795 and @var{srst_type} -- may be specified at a time.
1796 If you don't provide a new value for a given type, its previous
1797 value (perhaps the default) is unchanged.
1798 For example, this means that you don't need to say anything at all about
1799 TRST just to declare that if the JTAG adapter should want to drive SRST,
1800 it must explicitly be driven high (@option{srst_push_pull}).
1801
1802 @var{signals} can specify which of the reset signals are connected.
1803 For example, If the JTAG interface provides SRST, but the board doesn't
1804 connect that signal properly, then OpenOCD can't use it.
1805 Possible values are @option{none} (the default), @option{trst_only},
1806 @option{srst_only} and @option{trst_and_srst}.
1807
1808 @quotation Tip
1809 If your board provides SRST or TRST through the JTAG connector,
1810 you must declare that or else those signals will not be used.
1811 @end quotation
1812
1813 The @var{combination} is an optional value specifying broken reset
1814 signal implementations.
1815 The default behaviour if no option given is @option{separate},
1816 indicating everything behaves normally.
1817 @option{srst_pulls_trst} states that the
1818 test logic is reset together with the reset of the system (e.g. Philips
1819 LPC2000, "broken" board layout), @option{trst_pulls_srst} says that
1820 the system is reset together with the test logic (only hypothetical, I
1821 haven't seen hardware with such a bug, and can be worked around).
1822 @option{combined} implies both @option{srst_pulls_trst} and
1823 @option{trst_pulls_srst}.
1824
1825 The optional @var{trst_type} and @var{srst_type} parameters allow the
1826 driver mode of each reset line to be specified. These values only affect
1827 JTAG interfaces with support for different driver modes, like the Amontec
1828 JTAGkey and JTAGAccelerator. Also, they are necessarily ignored if the
1829 relevant signal (TRST or SRST) is not connected.
1830
1831 Possible @var{trst_type} driver modes for the test reset signal (TRST)
1832 are @option{trst_push_pull} (default) and @option{trst_open_drain}.
1833 Most boards connect this signal to a pulldown, so the JTAG TAPs
1834 never leave reset unless they are hooked up to a JTAG adapter.
1835
1836 Possible @var{srst_type} driver modes for the system reset signal (SRST)
1837 are the default @option{srst_open_drain}, and @option{srst_push_pull}.
1838 Most boards connect this signal to a pullup, and allow the
1839 signal to be pulled low by various events including system
1840 powerup and pressing a reset button.
1841 @end deffn
1842
1843
1844 @node TAP Declaration
1845 @chapter TAP Declaration
1846 @cindex TAP declaration
1847 @cindex TAP configuration
1848
1849 @emph{Test Access Ports} (TAPs) are the core of JTAG.
1850 TAPs serve many roles, including:
1851
1852 @itemize @bullet
1853 @item @b{Debug Target} A CPU TAP can be used as a GDB debug target
1854 @item @b{Flash Programing} Some chips program the flash directly via JTAG.
1855 Others do it indirectly, making a CPU do it.
1856 @item @b{Program Download} Using the same CPU support GDB uses,
1857 you can initialize a DRAM controller, download code to DRAM, and then
1858 start running that code.
1859 @item @b{Boundary Scan} Most chips support boundary scan, which
1860 helps test for board assembly problems like solder bridges
1861 and missing connections
1862 @end itemize
1863
1864 OpenOCD must know about the active TAPs on your board(s).
1865 Setting up the TAPs is the core task of your configuration files.
1866 Once those TAPs are set up, you can pass their names to code
1867 which sets up CPUs and exports them as GDB targets,
1868 probes flash memory, performs low-level JTAG operations, and more.
1869
1870 @section Scan Chains
1871
1872 OpenOCD uses a JTAG adapter (interface) to talk to your board,
1873 which has a daisy chain of TAPs.
1874 That daisy chain is called a @dfn{scan chain}.
1875 Simple configurations may have a single TAP in the scan chain,
1876 perhaps for a microcontroller.
1877 Complex configurations might have a dozen or more TAPs:
1878 several in one chip, more in the next, and connecting
1879 to other boards with their own chips and TAPs.
1880
1881 Unfortunately those TAPs can't always be autoconfigured,
1882 because not all devices provide good support for that.
1883 (JTAG doesn't require supporting IDCODE instructions.)
1884 The configuration mechanism currently supported by OpenOCD
1885 requires explicit configuration of all TAP devices using
1886 @command{jtag newtap} commands.
1887 One like this would declare a tap and name it @code{chip1.cpu}:
1888
1889 @example
1890 jtag newtap chip1 cpu -irlen 7 -ircapture 0x01 -irmask 0x55
1891 @end example
1892
1893 Each target configuration file lists the TAPs provided
1894 by a given chip.
1895 Board configuration files combine all the targets on a board,
1896 and so forth.
1897 Note that @emph{the order in which TAPs are declared is very important.}
1898 It must match the order in the JTAG scan chain, both inside
1899 a single chip and between them.
1900 @xref{FAQ TAP Order}.
1901
1902 For example, the ST Microsystems STR912 chip has
1903 three separate TAPs@footnote{See the ST
1904 document titled: @emph{STR91xFAxxx, Section 3.15 Jtag Interface, Page:
1905 28/102, Figure 3: JTAG chaining inside the STR91xFA}.
1906 @url{http://eu.st.com/stonline/products/literature/ds/13495.pdf}}.
1907 To configure those taps, @file{target/str912.cfg}
1908 includes commands something like this:
1909
1910 @example
1911 jtag newtap str912 flash ... params ...
1912 jtag newtap str912 cpu ... params ...
1913 jtag newtap str912 bs ... params ...
1914 @end example
1915
1916 Actual config files use a variable instead of literals like
1917 @option{str912}, to support more than one chip of each type.
1918 @xref{Config File Guidelines}.
1919
1920 @section TAP Names
1921
1922 When TAP objects are declared with @command{jtag newtap},
1923 a @dfn{dotted.name} is created for the TAP, combining the
1924 name of a module (usually a chip) and a label for the TAP.
1925 For example: @code{xilinx.tap}, @code{str912.flash},
1926 @code{omap3530.jrc}, @code{dm6446.dsp}, or @code{stm32.cpu}.
1927 Many other commands use that dotted.name to manipulate or
1928 refer to the TAP. For example, CPU configuration uses the
1929 name, as does declaration of NAND or NOR flash banks.
1930
1931 The components of a dotted name should follow ``C'' symbol
1932 name rules: start with an alphabetic character, then numbers
1933 and underscores are OK; while others (including dots!) are not.
1934
1935 @quotation Tip
1936 In older code, JTAG TAPs were numbered from 0..N.
1937 This feature is still present.
1938 However its use is highly discouraged, and
1939 should not be counted upon.
1940 Update all of your scripts to use TAP names rather than numbers.
1941 Using TAP numbers in target configuration scripts prevents
1942 reusing on boards with multiple targets.
1943 @end quotation
1944
1945 @section TAP Declaration Commands
1946
1947 @c shouldn't this be(come) a {Config Command}?
1948 @anchor{jtag newtap}
1949 @deffn Command {jtag newtap} chipname tapname configparams...
1950 Declares a new TAP with the dotted name @var{chipname}.@var{tapname},
1951 and configured according to the various @var{configparams}.
1952
1953 The @var{chipname} is a symbolic name for the chip.
1954 Conventionally target config files use @code{$_CHIPNAME},
1955 defaulting to the model name given by the chip vendor but
1956 overridable.
1957
1958 @cindex TAP naming convention
1959 The @var{tapname} reflects the role of that TAP,
1960 and should follow this convention:
1961
1962 @itemize @bullet
1963 @item @code{bs} -- For boundary scan if this is a seperate TAP;
1964 @item @code{cpu} -- The main CPU of the chip, alternatively
1965 @code{arm} and @code{dsp} on chips with both ARM and DSP CPUs,
1966 @code{arm1} and @code{arm2} on chips two ARMs, and so forth;
1967 @item @code{etb} -- For an embedded trace buffer (example: an ARM ETB11);
1968 @item @code{flash} -- If the chip has a flash TAP, like the str912;
1969 @item @code{jrc} -- For JTAG route controller (example: the ICEpick modules
1970 on many Texas Instruments chips, like the OMAP3530 on Beagleboards);
1971 @item @code{tap} -- Should be used only FPGA or CPLD like devices
1972 with a single TAP;
1973 @item @code{unknownN} -- If you have no idea what the TAP is for (N is a number);
1974 @item @emph{when in doubt} -- Use the chip maker's name in their data sheet.
1975 For example, the Freescale IMX31 has a SDMA (Smart DMA) with
1976 a JTAG TAP; that TAP should be named @code{sdma}.
1977 @end itemize
1978
1979 Every TAP requires at least the following @var{configparams}:
1980
1981 @itemize @bullet
1982 @item @code{-ircapture} @var{NUMBER}
1983 @*The IDCODE capture command, such as 0x01.
1984 @item @code{-irlen} @var{NUMBER}
1985 @*The length in bits of the
1986 instruction register, such as 4 or 5 bits.
1987 @item @code{-irmask} @var{NUMBER}
1988 @*A mask for the IR register.
1989 For some devices, there are bits in the IR that aren't used.
1990 This lets OpenOCD mask them off when doing IDCODE comparisons.
1991 In general, this should just be all ones for the size of the IR.
1992 @end itemize
1993
1994 A TAP may also provide optional @var{configparams}:
1995
1996 @itemize @bullet
1997 @item @code{-disable} (or @code{-enable})
1998 @*Use the @code{-disable} paramater to flag a TAP which is not
1999 linked in to the scan chain when it is declared.
2000 You may use @code{-enable} to highlight the default state
2001 (the TAP is linked in).
2002 @xref{Enabling and Disabling TAPs}.
2003 @item @code{-expected-id} @var{number}
2004 @*A non-zero value represents the expected 32-bit IDCODE
2005 found when the JTAG chain is examined.
2006 These codes are not required by all JTAG devices.
2007 @emph{Repeat the option} as many times as required if more than one
2008 ID code could appear (for example, multiple versions).
2009 @end itemize
2010 @end deffn
2011
2012 @c @deffn Command {jtag arp_init-reset}
2013 @c ... more or less "init" ?
2014
2015 @anchor{Enabling and Disabling TAPs}
2016 @section Enabling and Disabling TAPs
2017 @cindex TAP events
2018
2019 In some systems, a @dfn{JTAG Route Controller} (JRC)
2020 is used to enable and/or disable specific JTAG TAPs.
2021 Many ARM based chips from Texas Instruments include
2022 an ``ICEpick'' module, which is a JRC.
2023 Such chips include DaVinci and OMAP3 processors.
2024
2025 A given TAP may not be visible until the JRC has been
2026 told to link it into the scan chain; and if the JRC
2027 has been told to unlink that TAP, it will no longer
2028 be visible.
2029 Such routers address problems that JTAG ``bypass mode''
2030 ignores, such as:
2031
2032 @itemize
2033 @item The scan chain can only go as fast as its slowest TAP.
2034 @item Having many TAPs slows instruction scans, since all
2035 TAPs receive new instructions.
2036 @item TAPs in the scan chain must be powered up, which wastes
2037 power and prevents debugging some power management mechanisms.
2038 @end itemize
2039
2040 The IEEE 1149.1 JTAG standard has no concept of a ``disabled'' tap,
2041 as implied by the existence of JTAG routers.
2042 However, the upcoming IEEE 1149.7 framework (layered on top of JTAG)
2043 does include a kind of JTAG router functionality.
2044
2045 @c (a) currently the event handlers don't seem to be able to
2046 @c fail in a way that could lead to no-change-of-state.
2047 @c (b) eventually non-event configuration should be possible,
2048 @c in which case some this documentation must move.
2049
2050 @deffn Command {jtag cget} dotted.name @option{-event} name
2051 @deffnx Command {jtag configure} dotted.name @option{-event} name string
2052 At this writing this mechanism is used only for event handling,
2053 and the only two events relate to TAP enabling and disabling.
2054
2055 The @code{configure} subcommand assigns an event handler,
2056 a TCL string which is evaluated when the event is triggered.
2057 The @code{cget} subcommand returns that handler.
2058 The two possible values for an event @var{name}
2059 are @option{tap-disable} and @option{tap-enable}.
2060
2061 So for example, when defining a TAP for a CPU connected to
2062 a JTAG router, you should define TAP event handlers using
2063 code that looks something like this:
2064
2065 @example
2066 jtag configure CHIP.cpu -event tap-enable @{
2067 echo "Enabling CPU TAP"
2068 ... jtag operations using CHIP.jrc
2069 @}
2070 jtag configure CHIP.cpu -event tap-disable @{
2071 echo "Disabling CPU TAP"
2072 ... jtag operations using CHIP.jrc
2073 @}
2074 @end example
2075 @end deffn
2076
2077 @deffn Command {jtag tapdisable} dotted.name
2078 @deffnx Command {jtag tapenable} dotted.name
2079 @deffnx Command {jtag tapisenabled} dotted.name
2080 These three commands all return the string "1" if the tap
2081 specified by @var{dotted.name} is enabled,
2082 and "0" if it is disbabled.
2083 The @command{tapenable} variant first enables the tap
2084 by sending it a @option{tap-enable} event.
2085 The @command{tapdisable} variant first disables the tap
2086 by sending it a @option{tap-disable} event.
2087
2088 @quotation Note
2089 Humans will find the @command{scan_chain} command more helpful
2090 than the script-oriented @command{tapisenabled}
2091 for querying the state of the JTAG taps.
2092 @end quotation
2093 @end deffn
2094
2095 @node CPU Configuration
2096 @chapter CPU Configuration
2097 @cindex GDB target
2098
2099 This chapter discusses how to set up GDB debug targets for CPUs.
2100 You can also access these targets without GDB
2101 (@pxref{Architecture and Core Commands},
2102 and @ref{Target State handling}) and
2103 through various kinds of NAND and NOR flash commands.
2104 If you have multiple CPUs you can have multiple such targets.
2105
2106 We'll start by looking at how to examine the targets you have,
2107 then look at how to add one more target and how to configure it.
2108
2109 @section Target List
2110
2111 All targets that have been set up are part of a list,
2112 where each member has a name.
2113 That name should normally be the same as the TAP name.
2114 You can display the list with the @command{targets}
2115 (plural!) command.
2116 This display often has only one CPU; here's what it might
2117 look like with more than one:
2118 @verbatim
2119 CmdName Type Endian AbsChainPos Name State
2120 -- ---------- ---------- ---------- ----------- ------------- ----------
2121 0: rm9200.cpu arm920t little 2 rm9200.cpu running
2122 1: MyTarget cortex_m3 little 0 mychip.cpu halted
2123 @end verbatim
2124
2125 One member of that list is the @dfn{current target}, which
2126 is implicitly referenced by many commands.
2127 In particular, memory addresses often refer to the address
2128 space seen by that current target.
2129 Commands like @command{mdw} (memory display words)
2130 and @command{flash erase_address} (erase NOR flash blocks)
2131 are examples; and there are many more.
2132
2133 Several commands let you examine the list of targets:
2134
2135 @deffn Command {target count}
2136 Returns the number of targets, @math{N}.
2137 The highest numbered target is @math{N - 1}.
2138 @example
2139 set c [target count]
2140 for @{ set x 0 @} @{ $x < $c @} @{ incr x @} @{
2141 # Assuming you have created this function
2142 print_target_details $x
2143 @}
2144 @end example
2145 @end deffn
2146
2147 @deffn Command {target current}
2148 Returns the name of the current target.
2149 @end deffn
2150
2151 @deffn Command {target names}
2152 Lists the names of all current targets in the list.
2153 @example
2154 foreach t [target names] @{
2155 puts [format "Target: %s\n" $t]
2156 @}
2157 @end example
2158 @end deffn
2159
2160 @deffn Command {target number} number
2161 The list of targets is numbered starting at zero.
2162 This command returns the name of the target at index @var{number}.
2163 @example
2164 set thename [target number $x]
2165 puts [format "Target %d is: %s\n" $x $thename]
2166 @end example
2167 @end deffn
2168
2169 @c yep, "target list" would have been better.
2170 @c plus maybe "target setdefault".
2171
2172 @deffn Command targets [name]
2173 @emph{Note: the name of this command is plural. Other target
2174 command names are singular.}
2175
2176 With no parameter, this command displays a table of all known
2177 targets in a user friendly form.
2178
2179 With a parameter, this command sets the current target to
2180 the given target with the given @var{name}; this is
2181 only relevant on boards which have more than one target.
2182 @end deffn
2183
2184 @section Target CPU Types and Variants
2185
2186 Each target has a @dfn{CPU type}, as shown in the output of
2187 the @command{targets} command. You need to specify that type
2188 when calling @command{target create}.
2189 The CPU type indicates more than just the instruction set.
2190 It also indicates how that instruction set is implemented,
2191 what kind of debug support it integrates,
2192 whether it has an MMU (and if so, what kind),
2193 what core-specific commands may be available
2194 (@pxref{Architecture and Core Commands}),
2195 and more.
2196
2197 For some CPU types, OpenOCD also defines @dfn{variants} which
2198 indicate differences that affect their handling.
2199 For example, a particular implementation bug might need to be
2200 worked around in some chip versions.
2201
2202 It's easy to see what target types are supported,
2203 since there's a command to list them.
2204 However, there is currently no way to list what target variants
2205 are supported (other than by reading the OpenOCD source code).
2206
2207 @anchor{target types}
2208 @deffn Command {target types}
2209 Lists all supported target types.
2210 At this writing, the supported CPU types and variants are:
2211
2212 @itemize @bullet
2213 @item @code{arm11} -- this is a generation of ARMv6 cores
2214 @item @code{arm720t} -- this is an ARMv4 core
2215 @item @code{arm7tdmi} -- this is an ARMv4 core
2216 @item @code{arm920t} -- this is an ARMv5 core
2217 @item @code{arm926ejs} -- this is an ARMv5 core
2218 @item @code{arm966e} -- this is an ARMv5 core
2219 @item @code{arm9tdmi} -- this is an ARMv4 core
2220 @item @code{avr} -- implements Atmel's 8-bit AVR instruction set.
2221 (Support for this is preliminary and incomplete.)
2222 @item @code{cortex_a8} -- this is an ARMv7 core
2223 @item @code{cortex_m3} -- this is an ARMv7 core, supporting only the
2224 compact Thumb2 instruction set. It supports one variant:
2225 @itemize @minus
2226 @item @code{lm3s} ... Use this when debugging older Stellaris LM3S targets.
2227 This will cause OpenOCD to use a software reset rather than asserting
2228 SRST, to avoid a issue with clearing the debug registers.
2229 This is fixed in Fury Rev B, DustDevil Rev B, Tempest; these revisions will
2230 be detected and the normal reset behaviour used.
2231 @end itemize
2232 @item @code{feroceon} -- resembles arm926
2233 @item @code{mips_m4k} -- a MIPS core. This supports one variant:
2234 @itemize @minus
2235 @item @code{ejtag_srst} ... Use this when debugging targets that do not
2236 provide a functional SRST line on the EJTAG connector. This causes
2237 OpenOCD to instead use an EJTAG software reset command to reset the
2238 processor.
2239 You still need to enable @option{srst} on the @command{reset_config}
2240 command to enable OpenOCD hardware reset functionality.
2241 @end itemize
2242 @item @code{xscale} -- this is actually an architecture,
2243 not a CPU type. It is based on the ARMv5 architecture.
2244 There are several variants defined:
2245 @itemize @minus
2246 @item @code{ixp42x}, @code{ixp45x}, @code{ixp46x},
2247 @code{pxa27x} ... instruction register length is 7 bits
2248 @item @code{pxa250}, @code{pxa255},
2249 @code{pxa26x} ... instruction register length is 5 bits
2250 @end itemize
2251 @end itemize
2252 @end deffn
2253
2254 To avoid being confused by the variety of ARM based cores, remember
2255 this key point: @emph{ARM is a technology licencing company}.
2256 (See: @url{http://www.arm.com}.)
2257 The CPU name used by OpenOCD will reflect the CPU design that was
2258 licenced, not a vendor brand which incorporates that design.
2259 Name prefixes like arm7, arm9, arm11, and cortex
2260 reflect design generations;
2261 while names like ARMv4, ARMv5, ARMv6, and ARMv7
2262 reflect an architecture version implemented by a CPU design.
2263
2264 @anchor{Target Configuration}
2265 @section Target Configuration
2266
2267 Before creating a ``target'', you must have added its TAP to the scan chain.
2268 When you've added that TAP, you will have a @code{dotted.name}
2269 which is used to set up the CPU support.
2270 The chip-specific configuration file will normally configure its CPU(s)
2271 right after it adds all of the chip's TAPs to the scan chain.
2272
2273 Although you can set up a target in one step, it's often clearer if you
2274 use shorter commands and do it in two steps: create it, then configure
2275 optional parts.
2276 All operations on the target after it's created will use a new
2277 command, created as part of target creation.
2278
2279 The two main things to configure after target creation are
2280 a work area, which usually has target-specific defaults even
2281 if the board setup code overrides them later;
2282 and event handlers (@pxref{Target Events}), which tend
2283 to be much more board-specific.
2284 The key steps you use might look something like this
2285
2286 @example
2287 target create MyTarget cortex_m3 -chain-position mychip.cpu
2288 $MyTarget configure -work-area-phys 0x08000 -work-area-size 8096
2289 $MyTarget configure -event reset-deassert-pre @{ jtag_rclk 5 @}
2290 $MyTarget configure -event reset-init @{ myboard_reinit @}
2291 @end example
2292
2293 You should specify a working area if you can; typically it uses some
2294 on-chip SRAM.
2295 Such a working area can speed up many things, including bulk
2296 writes to target memory;
2297 flash operations like checking to see if memory needs to be erased;
2298 GDB memory checksumming;
2299 and more.
2300
2301 @quotation Warning
2302 On more complex chips, the work area can become
2303 inaccessible when application code
2304 (such as an operating system)
2305 enables or disables the MMU.
2306 For example, the particular MMU context used to acess the virtual
2307 address will probably matter ... and that context might not have
2308 easy access to other addresses needed.
2309 At this writing, OpenOCD doesn't have much MMU intelligence.
2310 @end quotation
2311
2312 It's often very useful to define a @code{reset-init} event handler.
2313 For systems that are normally used with a boot loader,
2314 common tasks include updating clocks and initializing memory
2315 controllers.
2316 That may be needed to let you write the boot loader into flash,
2317 in order to ``de-brick'' your board; or to load programs into
2318 external DDR memory without having run the boot loader.
2319
2320 @deffn Command {target create} target_name type configparams...
2321 This command creates a GDB debug target that refers to a specific JTAG tap.
2322 It enters that target into a list, and creates a new
2323 command (@command{@var{target_name}}) which is used for various
2324 purposes including additional configuration.
2325
2326 @itemize @bullet
2327 @item @var{target_name} ... is the name of the debug target.
2328 By convention this should be the same as the @emph{dotted.name}
2329 of the TAP associated with this target, which must be specified here
2330 using the @code{-chain-position @var{dotted.name}} configparam.
2331
2332 This name is also used to create the target object command,
2333 referred to here as @command{$target_name},
2334 and in other places the target needs to be identified.
2335 @item @var{type} ... specifies the target type. @xref{target types}.
2336 @item @var{configparams} ... all parameters accepted by
2337 @command{$target_name configure} are permitted.
2338 If the target is big-endian, set it here with @code{-endian big}.
2339 If the variant matters, set it here with @code{-variant}.
2340
2341 You @emph{must} set the @code{-chain-position @var{dotted.name}} here.
2342 @end itemize
2343 @end deffn
2344
2345 @deffn Command {$target_name configure} configparams...
2346 The options accepted by this command may also be
2347 specified as parameters to @command{target create}.
2348 Their values can later be queried one at a time by
2349 using the @command{$target_name cget} command.
2350
2351 @emph{Warning:} changing some of these after setup is dangerous.
2352 For example, moving a target from one TAP to another;
2353 and changing its endianness or variant.
2354
2355 @itemize @bullet
2356
2357 @item @code{-chain-position} @var{dotted.name} -- names the TAP
2358 used to access this target.
2359
2360 @item @code{-endian} (@option{big}|@option{little}) -- specifies
2361 whether the CPU uses big or little endian conventions
2362
2363 @item @code{-event} @var{event_name} @var{event_body} --
2364 @xref{Target Events}.
2365 Note that this updates a list of named event handlers.
2366 Calling this twice with two different event names assigns
2367 two different handlers, but calling it twice with the
2368 same event name assigns only one handler.
2369
2370 @item @code{-variant} @var{name} -- specifies a variant of the target,
2371 which OpenOCD needs to know about.
2372
2373 @item @code{-work-area-backup} (@option{0}|@option{1}) -- says
2374 whether the work area gets backed up; by default, it doesn't.
2375 When possible, use a working_area that doesn't need to be backed up,
2376 since performing a backup slows down operations.
2377
2378 @item @code{-work-area-size} @var{size} -- specify/set the work area
2379
2380 @item @code{-work-area-phys} @var{address} -- set the work area
2381 base @var{address} to be used when no MMU is active.
2382
2383 @item @code{-work-area-virt} @var{address} -- set the work area
2384 base @var{address} to be used when an MMU is active.
2385
2386 @end itemize
2387 @end deffn
2388
2389 @section Other $target_name Commands
2390 @cindex object command
2391
2392 The Tcl/Tk language has the concept of object commands,
2393 and OpenOCD adopts that same model for targets.
2394
2395 A good Tk example is a on screen button.
2396 Once a button is created a button
2397 has a name (a path in Tk terms) and that name is useable as a first
2398 class command. For example in Tk, one can create a button and later
2399 configure it like this:
2400
2401 @example
2402 # Create
2403 button .foobar -background red -command @{ foo @}
2404 # Modify
2405 .foobar configure -foreground blue
2406 # Query
2407 set x [.foobar cget -background]
2408 # Report
2409 puts [format "The button is %s" $x]
2410 @end example
2411
2412 In OpenOCD's terms, the ``target'' is an object just like a Tcl/Tk
2413 button, and its object commands are invoked the same way.
2414
2415 @example
2416 str912.cpu mww 0x1234 0x42
2417 omap3530.cpu mww 0x5555 123
2418 @end example
2419
2420 The commands supported by OpenOCD target objects are:
2421
2422 @deffn Command {$target_name arp_examine}
2423 @deffnx Command {$target_name arp_halt}
2424 @deffnx Command {$target_name arp_poll}
2425 @deffnx Command {$target_name arp_reset}
2426 @deffnx Command {$target_name arp_waitstate}
2427 Internal OpenOCD scripts (most notably @file{startup.tcl})
2428 use these to deal with specific reset cases.
2429 They are not otherwise documented here.
2430 @end deffn
2431
2432 @deffn Command {$target_name array2mem} arrayname width address count
2433 @deffnx Command {$target_name mem2array} arrayname width address count
2434 These provide an efficient script-oriented interface to memory.
2435 The @code{array2mem} primitive writes bytes, halfwords, or words;
2436 while @code{mem2array} reads them.
2437 In both cases, the TCL side uses an array, and
2438 the target side uses raw memory.
2439
2440 The efficiency comes from enabling the use of
2441 bulk JTAG data transfer operations.
2442 The script orientation comes from working with data
2443 values that are packaged for use by TCL scripts;
2444 @command{mdw} type primitives only print data they retrieve,
2445 and neither store nor return those values.
2446
2447 @itemize
2448 @item @var{arrayname} ... is the name of an array variable
2449 @item @var{width} ... is 8/16/32 - indicating the memory access size
2450 @item @var{address} ... is the target memory address
2451 @item @var{count} ... is the number of elements to process
2452 @end itemize
2453 @end deffn
2454
2455 @deffn Command {$target_name cget} queryparm
2456 Each configuration parameter accepted by
2457 @command{$target_name configure}
2458 can be individually queried, to return its current value.
2459 The @var{queryparm} is a parameter name
2460 accepted by that command, such as @code{-work-area-phys}.
2461 There are a few special cases:
2462
2463 @itemize @bullet
2464 @item @code{-event} @var{event_name} -- returns the handler for the
2465 event named @var{event_name}.
2466 This is a special case because setting a handler requires
2467 two parameters.
2468 @item @code{-type} -- returns the target type.
2469 This is a special case because this is set using
2470 @command{target create} and can't be changed
2471 using @command{$target_name configure}.
2472 @end itemize
2473
2474 For example, if you wanted to summarize information about
2475 all the targets you might use something like this:
2476
2477 @example
2478 for @{ set x 0 @} @{ $x < [target count] @} @{ incr x @} @{
2479 set name [target number $x]
2480 set y [$name cget -endian]
2481 set z [$name cget -type]
2482 puts [format "Chip %d is %s, Endian: %s, type: %s" \
2483 $x $name $y $z]
2484 @}
2485 @end example
2486 @end deffn
2487
2488 @deffn Command {$target_name curstate}
2489 Displays the current target state:
2490 @code{debug-running},
2491 @code{halted},
2492 @code{reset},
2493 @code{running}, or @code{unknown}.
2494 @end deffn
2495
2496 @deffn Command {$target_name eventlist}
2497 Displays a table listing all event handlers
2498 currently associated with this target.
2499 @xref{Target Events}.
2500 @end deffn
2501
2502 @deffn Command {$target_name invoke-event} event_name
2503 Invokes the handler for the event named @var{event_name}.
2504 (This is primarily intended for use by OpenOCD framework
2505 code, for example by the reset code in @file{startup.tcl}.)
2506 @end deffn
2507
2508 @deffn Command {$target_name mdw} addr [count]
2509 @deffnx Command {$target_name mdh} addr [count]
2510 @deffnx Command {$target_name mdb} addr [count]
2511 Display contents of address @var{addr}, as
2512 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
2513 or 8-bit bytes (@command{mdb}).
2514 If @var{count} is specified, displays that many units.
2515 (If you want to manipulate the data instead of displaying it,
2516 see the @code{mem2array} primitives.)
2517 @end deffn
2518
2519 @deffn Command {$target_name mww} addr word
2520 @deffnx Command {$target_name mwh} addr halfword
2521 @deffnx Command {$target_name mwb} addr byte
2522 Writes the specified @var{word} (32 bits),
2523 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
2524 at the specified address @var{addr}.
2525 @end deffn
2526
2527 @anchor{Target Events}
2528 @section Target Events
2529 @cindex events
2530 At various times, certain things can happen, or you want them to happen.
2531 For example:
2532 @itemize @bullet
2533 @item What should happen when GDB connects? Should your target reset?
2534 @item When GDB tries to flash the target, do you need to enable the flash via a special command?
2535 @item During reset, do you need to write to certain memory locations
2536 to set up system clocks or
2537 to reconfigure the SDRAM?
2538 @end itemize
2539
2540 All of the above items can be addressed by target event handlers.
2541 These are set up by @command{$target_name configure -event} or
2542 @command{target create ... -event}.
2543
2544 The programmer's model matches the @code{-command} option used in Tcl/Tk
2545 buttons and events. The two examples below act the same, but one creates
2546 and invokes a small procedure while the other inlines it.
2547
2548 @example
2549 proc my_attach_proc @{ @} @{
2550 echo "Reset..."
2551 reset halt
2552 @}
2553 mychip.cpu configure -event gdb-attach my_attach_proc
2554 mychip.cpu configure -event gdb-attach @{
2555 echo "Reset..."
2556 reset halt
2557 @}
2558 @end example
2559
2560 The following target events are defined:
2561
2562 @itemize @bullet
2563 @item @b{debug-halted}
2564 @* The target has halted for debug reasons (i.e.: breakpoint)
2565 @item @b{debug-resumed}
2566 @* The target has resumed (i.e.: gdb said run)
2567 @item @b{early-halted}
2568 @* Occurs early in the halt process
2569 @item @b{examine-end}
2570 @* Currently not used (goal: when JTAG examine completes)
2571 @item @b{examine-start}
2572 @* Currently not used (goal: when JTAG examine starts)
2573 @item @b{gdb-attach}
2574 @* When GDB connects
2575 @item @b{gdb-detach}
2576 @* When GDB disconnects
2577 @item @b{gdb-end}
2578 @* When the taret has halted and GDB is not doing anything (see early halt)
2579 @item @b{gdb-flash-erase-start}
2580 @* Before the GDB flash process tries to erase the flash
2581 @item @b{gdb-flash-erase-end}
2582 @* After the GDB flash process has finished erasing the flash
2583 @item @b{gdb-flash-write-start}
2584 @* Before GDB writes to the flash
2585 @item @b{gdb-flash-write-end}
2586 @* After GDB writes to the flash
2587 @item @b{gdb-start}
2588 @* Before the taret steps, gdb is trying to start/resume the target
2589 @item @b{halted}
2590 @* The target has halted
2591 @item @b{old-gdb_program_config}
2592 @* DO NOT USE THIS: Used internally
2593 @item @b{old-pre_resume}
2594 @* DO NOT USE THIS: Used internally
2595 @item @b{reset-assert-pre}
2596 @* Issued as part of @command{reset} processing
2597 after SRST and/or TRST were activated and deactivated,
2598 but before reset is asserted on the tap.
2599 @item @b{reset-assert-post}
2600 @* Issued as part of @command{reset} processing
2601 when reset is asserted on the tap.
2602 @item @b{reset-deassert-pre}
2603 @* Issued as part of @command{reset} processing
2604 when reset is about to be released on the tap.
2605
2606 For some chips, this may be a good place to make sure
2607 the JTAG clock is slow enough to work before the PLL
2608 has been set up to allow faster JTAG speeds.
2609 @item @b{reset-deassert-post}
2610 @* Issued as part of @command{reset} processing
2611 when reset has been released on the tap.
2612 @item @b{reset-end}
2613 @* Issued as the final step in @command{reset} processing.
2614 @item @b{reset-halt-post}
2615 @* Currently not usd
2616 @item @b{reset-halt-pre}
2617 @* Currently not used
2618 @item @b{reset-init}
2619 @* Used by @b{reset init} command for board-specific initialization.
2620 This event fires after @emph{reset-deassert-post}.
2621
2622 This is where you would configure PLLs and clocking, set up DRAM so
2623 you can download programs that don't fit in on-chip SRAM, set up pin
2624 multiplexing, and so on.
2625 @item @b{reset-start}
2626 @* Issued as part of @command{reset} processing
2627 before either SRST or TRST are activated.
2628 @item @b{reset-wait-pos}
2629 @* Currently not used
2630 @item @b{reset-wait-pre}
2631 @* Currently not used
2632 @item @b{resume-start}
2633 @* Before any target is resumed
2634 @item @b{resume-end}
2635 @* After all targets have resumed
2636 @item @b{resume-ok}
2637 @* Success
2638 @item @b{resumed}
2639 @* Target has resumed
2640 @end itemize
2641
2642
2643 @node Flash Commands
2644 @chapter Flash Commands
2645
2646 OpenOCD has different commands for NOR and NAND flash;
2647 the ``flash'' command works with NOR flash, while
2648 the ``nand'' command works with NAND flash.
2649 This partially reflects different hardware technologies:
2650 NOR flash usually supports direct CPU instruction and data bus access,
2651 while data from a NAND flash must be copied to memory before it can be
2652 used. (SPI flash must also be copied to memory before use.)
2653 However, the documentation also uses ``flash'' as a generic term;
2654 for example, ``Put flash configuration in board-specific files''.
2655
2656 @quotation Note
2657 As of 28-nov-2008 OpenOCD does not know how to program a SPI
2658 flash that a micro may boot from. Perhaps you, the reader, would like to
2659 contribute support for this.
2660 @end quotation
2661
2662 Flash Steps:
2663 @enumerate
2664 @item Configure via the command @command{flash bank}
2665 @* Do this in a board-specific configuration file,
2666 passing parameters as needed by the driver.
2667 @item Operate on the flash via @command{flash subcommand}
2668 @* Often commands to manipulate the flash are typed by a human, or run
2669 via a script in some automated way. Common tasks include writing a
2670 boot loader, operating system, or other data.
2671 @item GDB Flashing
2672 @* Flashing via GDB requires the flash be configured via ``flash
2673 bank'', and the GDB flash features be enabled.
2674 @xref{GDB Configuration}.
2675 @end enumerate
2676
2677 Many CPUs have the ablity to ``boot'' from the first flash bank.
2678 This means that misprograming that bank can ``brick'' a system,
2679 so that it can't boot.
2680 JTAG tools, like OpenOCD, are often then used to ``de-brick'' the
2681 board by (re)installing working boot firmware.
2682
2683 @section Flash Configuration Commands
2684 @cindex flash configuration
2685
2686 @deffn {Config Command} {flash bank} driver base size chip_width bus_width target [driver_options]
2687 Configures a flash bank which provides persistent storage
2688 for addresses from @math{base} to @math{base + size - 1}.
2689 These banks will often be visible to GDB through the target's memory map.
2690 In some cases, configuring a flash bank will activate extra commands;
2691 see the driver-specific documentation.
2692
2693 @itemize @bullet
2694 @item @var{driver} ... identifies the controller driver
2695 associated with the flash bank being declared.
2696 This is usually @code{cfi} for external flash, or else
2697 the name of a microcontroller with embedded flash memory.
2698 @xref{Flash Driver List}.
2699 @item @var{base} ... Base address of the flash chip.
2700 @item @var{size} ... Size of the chip, in bytes.
2701 For some drivers, this value is detected from the hardware.
2702 @item @var{chip_width} ... Width of the flash chip, in bytes;
2703 ignored for most microcontroller drivers.
2704 @item @var{bus_width} ... Width of the data bus used to access the
2705 chip, in bytes; ignored for most microcontroller drivers.
2706 @item @var{target} ... Names the target used to issue
2707 commands to the flash controller.
2708 @comment Actually, it's currently a controller-specific parameter...
2709 @item @var{driver_options} ... drivers may support, or require,
2710 additional parameters. See the driver-specific documentation
2711 for more information.
2712 @end itemize
2713 @quotation Note
2714 This command is not available after OpenOCD initialization has completed.
2715 Use it in board specific configuration files, not interactively.
2716 @end quotation
2717 @end deffn
2718
2719 @comment the REAL name for this command is "ocd_flash_banks"
2720 @comment less confusing would be: "flash list" (like "nand list")
2721 @deffn Command {flash banks}
2722 Prints a one-line summary of each device declared
2723 using @command{flash bank}, numbered from zero.
2724 Note that this is the @emph{plural} form;
2725 the @emph{singular} form is a very different command.
2726 @end deffn
2727
2728 @deffn Command {flash probe} num
2729 Identify the flash, or validate the parameters of the configured flash. Operation
2730 depends on the flash type.
2731 The @var{num} parameter is a value shown by @command{flash banks}.
2732 Most flash commands will implicitly @emph{autoprobe} the bank;
2733 flash drivers can distinguish between probing and autoprobing,
2734 but most don't bother.
2735 @end deffn
2736
2737 @section Erasing, Reading, Writing to Flash
2738 @cindex flash erasing
2739 @cindex flash reading
2740 @cindex flash writing
2741 @cindex flash programming
2742
2743 One feature distinguishing NOR flash from NAND or serial flash technologies
2744 is that for read access, it acts exactly like any other addressible memory.
2745 This means you can use normal memory read commands like @command{mdw} or
2746 @command{dump_image} with it, with no special @command{flash} subcommands.
2747 @xref{Memory access}, and @ref{Image access}.
2748
2749 Write access works differently. Flash memory normally needs to be erased
2750 before it's written. Erasing a sector turns all of its bits to ones, and
2751 writing can turn ones into zeroes. This is why there are special commands
2752 for interactive erasing and writing, and why GDB needs to know which parts
2753 of the address space hold NOR flash memory.
2754
2755 @quotation Note
2756 Most of these erase and write commands leverage the fact that NOR flash
2757 chips consume target address space. They implicitly refer to the current
2758 JTAG target, and map from an address in that target's address space
2759 back to a flash bank.
2760 @comment In May 2009, those mappings may fail if any bank associated
2761 @comment with that target doesn't succesfuly autoprobe ... bug worth fixing?
2762 A few commands use abstract addressing based on bank and sector numbers,
2763 and don't depend on searching the current target and its address space.
2764 Avoid confusing the two command models.
2765 @end quotation
2766
2767 Some flash chips implement software protection against accidental writes,
2768 since such buggy writes could in some cases ``brick'' a system.
2769 For such systems, erasing and writing may require sector protection to be
2770 disabled first.
2771 Examples include CFI flash such as ``Intel Advanced Bootblock flash'',
2772 and AT91SAM7 on-chip flash.
2773 @xref{flash protect}.
2774
2775 @anchor{flash erase_sector}
2776 @deffn Command {flash erase_sector} num first last
2777 Erase sectors in bank @var{num}, starting at sector @var{first} up to and including
2778 @var{last}. Sector numbering starts at 0.
2779 The @var{num} parameter is a value shown by @command{flash banks}.
2780 @end deffn
2781
2782 @deffn Command {flash erase_address} address length
2783 Erase sectors starting at @var{address} for @var{length} bytes.
2784 The flash bank to use is inferred from the @var{address}, and
2785 the specified length must stay within that bank.
2786 As a special case, when @var{length} is zero and @var{address} is
2787 the start of the bank, the whole flash is erased.
2788 @end deffn
2789
2790 @deffn Command {flash fillw} address word length
2791 @deffnx Command {flash fillh} address halfword length
2792 @deffnx Command {flash fillb} address byte length
2793 Fills flash memory with the specified @var{word} (32 bits),
2794 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
2795 starting at @var{address} and continuing
2796 for @var{length} units (word/halfword/byte).
2797 No erasure is done before writing; when needed, that must be done
2798 before issuing this command.
2799 Writes are done in blocks of up to 1024 bytes, and each write is
2800 verified by reading back the data and comparing it to what was written.
2801 The flash bank to use is inferred from the @var{address} of
2802 each block, and the specified length must stay within that bank.
2803 @end deffn
2804 @comment no current checks for errors if fill blocks touch multiple banks!
2805
2806 @anchor{flash write_bank}
2807 @deffn Command {flash write_bank} num filename offset
2808 Write the binary @file{filename} to flash bank @var{num},
2809 starting at @var{offset} bytes from the beginning of the bank.
2810 The @var{num} parameter is a value shown by @command{flash banks}.
2811 @end deffn
2812
2813 @anchor{flash write_image}
2814 @deffn Command {flash write_image} [erase] filename [offset] [type]
2815 Write the image @file{filename} to the current target's flash bank(s).
2816 A relocation @var{offset} may be specified, in which case it is added
2817 to the base address for each section in the image.
2818 The file [@var{type}] can be specified
2819 explicitly as @option{bin} (binary), @option{ihex} (Intel hex),
2820 @option{elf} (ELF file), @option{s19} (Motorola s19).
2821 @option{mem}, or @option{builder}.
2822 The relevant flash sectors will be erased prior to programming
2823 if the @option{erase} parameter is given.
2824 The flash bank to use is inferred from the @var{address} of
2825 each image segment.
2826 @end deffn
2827
2828 @section Other Flash commands
2829 @cindex flash protection
2830
2831 @deffn Command {flash erase_check} num
2832 Check erase state of sectors in flash bank @var{num},
2833 and display that status.
2834 The @var{num} parameter is a value shown by @command{flash banks}.
2835 This is the only operation that
2836 updates the erase state information displayed by @option{flash info}. That means you have
2837 to issue an @command{flash erase_check} command after erasing or programming the device
2838 to get updated information.
2839 (Code execution may have invalidated any state records kept by OpenOCD.)
2840 @end deffn
2841
2842 @deffn Command {flash info} num
2843 Print info about flash bank @var{num}
2844 The @var{num} parameter is a value shown by @command{flash banks}.
2845 The information includes per-sector protect status.
2846 @end deffn
2847
2848 @anchor{flash protect}
2849 @deffn Command {flash protect} num first last (on|off)
2850 Enable (@var{on}) or disable (@var{off}) protection of flash sectors
2851 @var{first} to @var{last} of flash bank @var{num}.
2852 The @var{num} parameter is a value shown by @command{flash banks}.
2853 @end deffn
2854
2855 @deffn Command {flash protect_check} num
2856 Check protection state of sectors in flash bank @var{num}.
2857 The @var{num} parameter is a value shown by @command{flash banks}.
2858 @comment @option{flash erase_sector} using the same syntax.
2859 @end deffn
2860
2861 @anchor{Flash Driver List}
2862 @section Flash Drivers, Options, and Commands
2863 As noted above, the @command{flash bank} command requires a driver name,
2864 and allows driver-specific options and behaviors.
2865 Some drivers also activate driver-specific commands.
2866
2867 @subsection External Flash
2868
2869 @deffn {Flash Driver} cfi
2870 @cindex Common Flash Interface
2871 @cindex CFI
2872 The ``Common Flash Interface'' (CFI) is the main standard for
2873 external NOR flash chips, each of which connects to a
2874 specific external chip select on the CPU.
2875 Frequently the first such chip is used to boot the system.
2876 Your board's @code{reset-init} handler might need to
2877 configure additional chip selects using other commands (like: @command{mww} to
2878 configure a bus and its timings) , or
2879 perhaps configure a GPIO pin that controls the ``write protect'' pin
2880 on the flash chip.
2881 The CFI driver can use a target-specific working area to significantly
2882 speed up operation.
2883
2884 The CFI driver can accept the following optional parameters, in any order:
2885
2886 @itemize
2887 @item @var{jedec_probe} ... is used to detect certain non-CFI flash ROMs,
2888 like AM29LV010 and similar types.
2889 @item @var{x16_as_x8} ... when a 16-bit flash is hooked up to an 8-bit bus.
2890 @end itemize
2891
2892 To configure two adjacent banks of 16 MBytes each, both sixteen bits (two bytes)
2893 wide on a sixteen bit bus:
2894
2895 @example
2896 flash bank cfi 0x00000000 0x01000000 2 2 $_TARGETNAME
2897 flash bank cfi 0x01000000 0x01000000 2 2 $_TARGETNAME
2898 @end example
2899 @end deffn
2900
2901 @subsection Internal Flash (Microcontrollers)
2902
2903 @deffn {Flash Driver} aduc702x
2904 The ADUC702x analog microcontrollers from ST Micro
2905 include internal flash and use ARM7TDMI cores.
2906 The aduc702x flash driver works with models ADUC7019 through ADUC7028.
2907 The setup command only requires the @var{target} argument
2908 since all devices in this family have the same memory layout.
2909
2910 @example
2911 flash bank aduc702x 0 0 0 0 $_TARGETNAME
2912 @end example
2913 @end deffn
2914
2915 @deffn {Flash Driver} at91sam7
2916 All members of the AT91SAM7 microcontroller family from Atmel
2917 include internal flash and use ARM7TDMI cores.
2918 The driver automatically recognizes a number of these chips using
2919 the chip identification register, and autoconfigures itself.
2920
2921 @example
2922 flash bank at91sam7 0 0 0 0 $_TARGETNAME
2923 @end example
2924
2925 For chips which are not recognized by the controller driver, you must
2926 provide additional parameters in the following order:
2927
2928 @itemize
2929 @item @var{chip_model} ... label used with @command{flash info}
2930 @item @var{banks}
2931 @item @var{sectors_per_bank}
2932 @item @var{pages_per_sector}
2933 @item @var{pages_size}
2934 @item @var{num_nvm_bits}
2935 @item @var{freq_khz} ... required if an external clock is provided,
2936 optional (but recommended) when the oscillator frequency is known
2937 @end itemize
2938
2939 It is recommended that you provide zeroes for all of those values
2940 except the clock frequency, so that everything except that frequency
2941 will be autoconfigured.
2942 Knowing the frequency helps ensure correct timings for flash access.
2943
2944 The flash controller handles erases automatically on a page (128/256 byte)
2945 basis, so explicit erase commands are not necessary for flash programming.
2946 However, there is an ``EraseAll`` command that can erase an entire flash
2947 plane (of up to 256KB), and it will be used automatically when you issue
2948 @command{flash erase_sector} or @command{flash erase_address} commands.
2949
2950 @deffn Command {at91sam7 gpnvm} bitnum (set|clear)
2951 Set or clear a ``General Purpose Non-Volatle Memory'' (GPNVM)
2952 bit for the processor. Each processor has a number of such bits,
2953 used for controlling features such as brownout detection (so they
2954 are not truly general purpose).
2955 @quotation Note
2956 This assumes that the first flash bank (number 0) is associated with
2957 the appropriate at91sam7 target.
2958 @end quotation
2959 @end deffn
2960 @end deffn
2961
2962 @deffn {Flash Driver} avr
2963 The AVR 8-bit microcontrollers from Atmel integrate flash memory.
2964 @emph{The current implementation is incomplete.}
2965 @comment - defines mass_erase ... pointless given flash_erase_address
2966 @end deffn
2967
2968 @deffn {Flash Driver} ecosflash
2969 @emph{No idea what this is...}
2970 The @var{ecosflash} driver defines one mandatory parameter,
2971 the name of a modules of target code which is downloaded
2972 and executed.
2973 @end deffn
2974
2975 @deffn {Flash Driver} lpc2000
2976 Most members of the LPC2000 microcontroller family from NXP
2977 include internal flash and use ARM7TDMI cores.
2978 The @var{lpc2000} driver defines two mandatory and one optional parameters,
2979 which must appear in the following order:
2980
2981 @itemize
2982 @item @var{variant} ... required, may be
2983 @var{lpc2000_v1} (older LPC21xx and LPC22xx)
2984 or @var{lpc2000_v2} (LPC213x, LPC214x, LPC210[123], LPC23xx and LPC24xx)
2985 @item @var{clock_kHz} ... the frequency, in kiloHertz,
2986 at which the core is running
2987 @item @var{calc_checksum} ... optional (but you probably want to provide this!),
2988 telling the driver to calculate a valid checksum for the exception vector table.
2989 @end itemize
2990
2991 LPC flashes don't require the chip and bus width to be specified.
2992
2993 @example
2994 flash bank lpc2000 0x0 0x7d000 0 0 $_TARGETNAME \
2995 lpc2000_v2 14765 calc_checksum
2996 @end example
2997 @end deffn
2998
2999 @deffn {Flash Driver} lpc288x
3000 The LPC2888 microcontroller from NXP needs slightly different flash
3001 support from its lpc2000 siblings.
3002 The @var{lpc288x} driver defines one mandatory parameter,
3003 the programming clock rate in Hz.
3004 LPC flashes don't require the chip and bus width to be specified.
3005
3006 @example
3007 flash bank lpc288x 0 0 0 0 $_TARGETNAME 12000000
3008 @end example
3009 @end deffn
3010
3011 @deffn {Flash Driver} ocl
3012 @emph{No idea what this is, other than using some arm7/arm9 core.}
3013
3014 @example
3015 flash bank ocl 0 0 0 0 $_TARGETNAME
3016 @end example
3017 @end deffn
3018
3019 @deffn {Flash Driver} pic32mx
3020 The PIC32MX microcontrollers are based on the MIPS 4K cores,
3021 and integrate flash memory.
3022 @emph{The current implementation is incomplete.}
3023
3024 @example
3025 flash bank pix32mx 0 0 0 0 $_TARGETNAME
3026 @end example
3027
3028 @comment numerous *disabled* commands are defined:
3029 @comment - chip_erase ... pointless given flash_erase_address
3030 @comment - lock, unlock ... pointless given protect on/off (yes?)
3031 @comment - pgm_word ... shouldn't bank be deduced from address??
3032 Some pic32mx-specific commands are defined:
3033 @deffn Command {pic32mx pgm_word} address value bank
3034 Programs the specified 32-bit @var{value} at the given @var{address}
3035 in the specified chip @var{bank}.
3036 @end deffn
3037 @end deffn
3038
3039 @deffn {Flash Driver} stellaris
3040 All members of the Stellaris LM3Sxxx microcontroller family from
3041 Texas Instruments
3042 include internal flash and use ARM Cortex M3 cores.
3043 The driver automatically recognizes a number of these chips using
3044 the chip identification register, and autoconfigures itself.
3045 @footnote{Currently there is a @command{stellaris mass_erase} command.
3046 That seems pointless since the same effect can be had using the
3047 standard @command{flash erase_address} command.}
3048
3049 @example
3050 flash bank stellaris 0 0 0 0 $_TARGETNAME
3051 @end example
3052 @end deffn
3053
3054 @deffn {Flash Driver} stm32x
3055 All members of the STM32 microcontroller family from ST Microelectronics
3056 include internal flash and use ARM Cortex M3 cores.
3057 The driver automatically recognizes a number of these chips using
3058 the chip identification register, and autoconfigures itself.
3059
3060 @example
3061 flash bank stm32x 0 0 0 0 $_TARGETNAME
3062 @end example
3063
3064 Some stm32x-specific commands
3065 @footnote{Currently there is a @command{stm32x mass_erase} command.
3066 That seems pointless since the same effect can be had using the
3067 standard @command{flash erase_address} command.}
3068 are defined:
3069
3070 @deffn Command {stm32x lock} num
3071 Locks the entire stm32 device.
3072 The @var{num} parameter is a value shown by @command{flash banks}.
3073 @end deffn
3074
3075 @deffn Command {stm32x unlock} num
3076 Unlocks the entire stm32 device.
3077 The @var{num} parameter is a value shown by @command{flash banks}.
3078 @end deffn
3079
3080 @deffn Command {stm32x options_read} num
3081 Read and display the stm32 option bytes written by
3082 the @command{stm32x options_write} command.
3083 The @var{num} parameter is a value shown by @command{flash banks}.
3084 @end deffn
3085
3086 @deffn Command {stm32x options_write} num (SWWDG|HWWDG) (RSTSTNDBY|NORSTSTNDBY) (RSTSTOP|NORSTSTOP)
3087 Writes the stm32 option byte with the specified values.
3088 The @var{num} parameter is a value shown by @command{flash banks}.
3089 @end deffn
3090 @end deffn
3091
3092 @deffn {Flash Driver} str7x
3093 All members of the STR7 microcontroller family from ST Microelectronics
3094 include internal flash and use ARM7TDMI cores.
3095 The @var{str7x} driver defines one mandatory parameter, @var{variant},
3096 which is either @code{STR71x}, @code{STR73x} or @code{STR75x}.
3097
3098 @example
3099 flash bank str7x 0x40000000 0x00040000 0 0 $_TARGETNAME STR71x
3100 @end example
3101 @end deffn
3102
3103 @deffn {Flash Driver} str9x
3104 Most members of the STR9 microcontroller family from ST Microelectronics
3105 include internal flash and use ARM966E cores.
3106 The str9 needs the flash controller to be configured using
3107 the @command{str9x flash_config} command prior to Flash programming.
3108
3109 @example
3110 flash bank str9x 0x40000000 0x00040000 0 0 $_TARGETNAME
3111 str9x flash_config 0 4 2 0 0x80000
3112 @end example
3113
3114 @deffn Command {str9x flash_config} num bbsr nbbsr bbadr nbbadr
3115 Configures the str9 flash controller.
3116 The @var{num} parameter is a value shown by @command{flash banks}.
3117
3118 @itemize @bullet
3119 @item @var{bbsr} - Boot Bank Size register
3120 @item @var{nbbsr} - Non Boot Bank Size register
3121 @item @var{bbadr} - Boot Bank Start Address register
3122 @item @var{nbbadr} - Boot Bank Start Address register
3123 @end itemize
3124 @end deffn
3125
3126 @end deffn
3127
3128 @deffn {Flash Driver} tms470
3129 Most members of the TMS470 microcontroller family from Texas Instruments
3130 include internal flash and use ARM7TDMI cores.
3131 This driver doesn't require the chip and bus width to be specified.
3132
3133 Some tms470-specific commands are defined:
3134
3135 @deffn Command {tms470 flash_keyset} key0 key1 key2 key3
3136 Saves programming keys in a register, to enable flash erase and write commands.
3137 @end deffn
3138
3139 @deffn Command {tms470 osc_mhz} clock_mhz
3140 Reports the clock speed, which is used to calculate timings.
3141 @end deffn
3142
3143 @deffn Command {tms470 plldis} (0|1)
3144 Disables (@var{1}) or enables (@var{0}) use of the PLL to speed up
3145 the flash clock.
3146 @end deffn
3147 @end deffn
3148
3149 @subsection str9xpec driver
3150 @cindex str9xpec
3151
3152 Here is some background info to help
3153 you better understand how this driver works. OpenOCD has two flash drivers for
3154 the str9:
3155 @enumerate
3156 @item
3157 Standard driver @option{str9x} programmed via the str9 core. Normally used for
3158 flash programming as it is faster than the @option{str9xpec} driver.
3159 @item
3160 Direct programming @option{str9xpec} using the flash controller. This is an
3161 ISC compilant (IEEE 1532) tap connected in series with the str9 core. The str9
3162 core does not need to be running to program using this flash driver. Typical use
3163 for this driver is locking/unlocking the target and programming the option bytes.
3164 @end enumerate
3165
3166 Before we run any commands using the @option{str9xpec} driver we must first disable
3167 the str9 core. This example assumes the @option{str9xpec} driver has been
3168 configured for flash bank 0.
3169 @example
3170 # assert srst, we do not want core running
3171 # while accessing str9xpec flash driver
3172 jtag_reset 0 1
3173 # turn off target polling
3174 poll off
3175 # disable str9 core
3176 str9xpec enable_turbo 0
3177 # read option bytes
3178 str9xpec options_read 0
3179 # re-enable str9 core
3180 str9xpec disable_turbo 0
3181 poll on
3182 reset halt
3183 @end example
3184 The above example will read the str9 option bytes.
3185 When performing a unlock remember that you will not be able to halt the str9 - it
3186 has been locked. Halting the core is not required for the @option{str9xpec} driver
3187 as mentioned above, just issue the commands above manually or from a telnet prompt.
3188
3189 @deffn {Flash Driver} str9xpec
3190 Only use this driver for locking/unlocking the device or configuring the option bytes.
3191 Use the standard str9 driver for programming.
3192 Before using the flash commands the turbo mode must be enabled using the
3193 @command{str9xpec enable_turbo} command.
3194
3195 Several str9xpec-specific commands are defined:
3196
3197 @deffn Command {str9xpec disable_turbo} num
3198 Restore the str9 into JTAG chain.
3199 @end deffn
3200
3201 @deffn Command {str9xpec enable_turbo} num
3202 Enable turbo mode, will simply remove the str9 from the chain and talk
3203 directly to the embedded flash controller.
3204 @end deffn
3205
3206 @deffn Command {str9xpec lock} num
3207 Lock str9 device. The str9 will only respond to an unlock command that will
3208 erase the device.
3209 @end deffn
3210
3211 @deffn Command {str9xpec part_id} num
3212 Prints the part identifier for bank @var{num}.
3213 @end deffn
3214
3215 @deffn Command {str9xpec options_cmap} num (@option{bank0}|@option{bank1})
3216 Configure str9 boot bank.
3217 @end deffn
3218
3219 @deffn Command {str9xpec options_lvdsel} num (@option{vdd}|@option{vdd_vddq})
3220 Configure str9 lvd source.
3221 @end deffn
3222
3223 @deffn Command {str9xpec options_lvdthd} num (@option{2.4v}|@option{2.7v})
3224 Configure str9 lvd threshold.
3225 @end deffn
3226
3227 @deffn Command {str9xpec options_lvdwarn} bank (@option{vdd}|@option{vdd_vddq})
3228 Configure str9 lvd reset warning source.
3229 @end deffn
3230
3231 @deffn Command {str9xpec options_read} num
3232 Read str9 option bytes.
3233 @end deffn
3234
3235 @deffn Command {str9xpec options_write} num
3236 Write str9 option bytes.
3237 @end deffn
3238
3239 @deffn Command {str9xpec unlock} num
3240 unlock str9 device.
3241 @end deffn
3242
3243 @end deffn
3244
3245
3246 @section mFlash
3247
3248 @subsection mFlash Configuration
3249 @cindex mFlash Configuration
3250
3251 @deffn {Config Command} {mflash bank} soc base RST_pin target
3252 Configures a mflash for @var{soc} host bank at
3253 address @var{base}.
3254 The pin number format depends on the host GPIO naming convention.
3255 Currently, the mflash driver supports s3c2440 and pxa270.
3256
3257 Example for s3c2440 mflash where @var{RST pin} is GPIO B1:
3258
3259 @example
3260 mflash bank s3c2440 0x10000000 1b 0
3261 @end example
3262
3263 Example for pxa270 mflash where @var{RST pin} is GPIO 43:
3264
3265 @example
3266 mflash bank pxa270 0x08000000 43 0
3267 @end example
3268 @end deffn
3269
3270 @subsection mFlash commands
3271 @cindex mFlash commands
3272
3273 @deffn Command {mflash config pll} frequency
3274 Configure mflash PLL.
3275 The @var{frequency} is the mflash input frequency, in Hz.
3276 Issuing this command will erase mflash's whole internal nand and write new pll.
3277 After this command, mflash needs power-on-reset for normal operation.
3278 If pll was newly configured, storage and boot(optional) info also need to be update.
3279 @end deffn
3280
3281 @deffn Command {mflash config boot}
3282 Configure bootable option.
3283 If bootable option is set, mflash offer the first 8 sectors
3284 (4kB) for boot.
3285 @end deffn
3286
3287 @deffn Command {mflash config storage}
3288 Configure storage information.
3289 For the normal storage operation, this information must be
3290 written.
3291 @end deffn
3292
3293 @deffn Command {mflash dump} num filename offset size
3294 Dump @var{size} bytes, starting at @var{offset} bytes from the
3295 beginning of the bank @var{num}, to the file named @var{filename}.
3296 @end deffn
3297
3298 @deffn Command {mflash probe}
3299 Probe mflash.
3300 @end deffn
3301
3302 @deffn Command {mflash write} num filename offset
3303 Write the binary file @var{filename} to mflash bank @var{num}, starting at
3304 @var{offset} bytes from the beginning of the bank.
3305 @end deffn
3306
3307 @node NAND Flash Commands
3308 @chapter NAND Flash Commands
3309 @cindex NAND
3310
3311 Compared to NOR or SPI flash, NAND devices are inexpensive
3312 and high density. Today's NAND chips, and multi-chip modules,
3313 commonly hold multiple GigaBytes of data.
3314
3315 NAND chips consist of a number of ``erase blocks'' of a given
3316 size (such as 128 KBytes), each of which is divided into a
3317 number of pages (of perhaps 512 or 2048 bytes each). Each
3318 page of a NAND flash has an ``out of band'' (OOB) area to hold
3319 Error Correcting Code (ECC) and other metadata, usually 16 bytes
3320 of OOB for every 512 bytes of page data.
3321
3322 One key characteristic of NAND flash is that its error rate
3323 is higher than that of NOR flash. In normal operation, that
3324 ECC is used to correct and detect errors. However, NAND
3325 blocks can also wear out and become unusable; those blocks
3326 are then marked "bad". NAND chips are even shipped from the
3327 manufacturer with a few bad blocks. The highest density chips
3328 use a technology (MLC) that wears out more quickly, so ECC
3329 support is increasingly important as a way to detect blocks
3330 that have begun to fail, and help to preserve data integrity
3331 with techniques such as wear leveling.
3332
3333 Software is used to manage the ECC. Some controllers don't
3334 support ECC directly; in those cases, software ECC is used.
3335 Other controllers speed up the ECC calculations with hardware.
3336 Single-bit error correction hardware is routine. Controllers
3337 geared for newer MLC chips may correct 4 or more errors for
3338 every 512 bytes of data.
3339
3340 You will need to make sure that any data you write using
3341 OpenOCD includes the apppropriate kind of ECC. For example,
3342 that may mean passing the @code{oob_softecc} flag when
3343 writing NAND data, or ensuring that the correct hardware
3344 ECC mode is used.
3345
3346 The basic steps for using NAND devices include:
3347 @enumerate
3348 @item Declare via the command @command{nand device}
3349 @* Do this in a board-specific configuration file,
3350 passing parameters as needed by the controller.
3351 @item Configure each device using @command{nand probe}.
3352 @* Do this only after the associated target is set up,
3353 such as in its reset-init script or in procures defined
3354 to access that device.
3355 @item Operate on the flash via @command{nand subcommand}
3356 @* Often commands to manipulate the flash are typed by a human, or run
3357 via a script in some automated way. Common task include writing a
3358 boot loader, operating system, or other data needed to initialize or
3359 de-brick a board.
3360 @end enumerate
3361
3362 @b{NOTE:} At the time this text was written, the largest NAND
3363 flash fully supported by OpenOCD is 2 GiBytes (16 GiBits).
3364 This is because the variables used to hold offsets and lengths
3365 are only 32 bits wide.
3366 (Larger chips may work in some cases, unless an offset or length
3367 is larger than 0xffffffff, the largest 32-bit unsigned integer.)
3368 Some larger devices will work, since they are actually multi-chip
3369 modules with two smaller chips and individual chipselect lines.
3370
3371 @section NAND Configuration Commands
3372 @cindex NAND configuration
3373
3374 NAND chips must be declared in configuration scripts,
3375 plus some additional configuration that's done after
3376 OpenOCD has initialized.
3377
3378 @deffn {Config Command} {nand device} controller target [configparams...]
3379 Declares a NAND device, which can be read and written to
3380 after it has been configured through @command{nand probe}.
3381 In OpenOCD, devices are single chips; this is unlike some
3382 operating systems, which may manage multiple chips as if
3383 they were a single (larger) device.
3384 In some cases, configuring a device will activate extra
3385 commands; see the controller-specific documentation.
3386
3387 @b{NOTE:} This command is not available after OpenOCD
3388 initialization has completed. Use it in board specific
3389 configuration files, not interactively.
3390
3391 @itemize @bullet
3392 @item @var{controller} ... identifies the controller driver
3393 associated with the NAND device being declared.
3394 @xref{NAND Driver List}.
3395 @item @var{target} ... names the target used when issuing
3396 commands to the NAND controller.
3397 @comment Actually, it's currently a controller-specific parameter...
3398 @item @var{configparams} ... controllers may support, or require,
3399 additional parameters. See the controller-specific documentation
3400 for more information.
3401 @end itemize
3402 @end deffn
3403
3404 @deffn Command {nand list}
3405 Prints a one-line summary of each device declared
3406 using @command{nand device}, numbered from zero.
3407 Note that un-probed devices show no details.
3408 @end deffn
3409
3410 @deffn Command {nand probe} num
3411 Probes the specified device to determine key characteristics
3412 like its page and block sizes, and how many blocks it has.
3413 The @var{num} parameter is the value shown by @command{nand list}.
3414 You must (successfully) probe a device before you can use
3415 it with most other NAND commands.
3416 @end deffn
3417
3418 @section Erasing, Reading, Writing to NAND Flash
3419
3420 @deffn Command {nand dump} num filename offset length [oob_option]
3421 @cindex NAND reading
3422 Reads binary data from the NAND device and writes it to the file,
3423 starting at the specified offset.
3424 The @var{num} parameter is the value shown by @command{nand list}.
3425
3426 Use a complete path name for @var{filename}, so you don't depend
3427 on the directory used to start the OpenOCD server.
3428
3429 The @var{offset} and @var{length} must be exact multiples of the
3430 device's page size. They describe a data region; the OOB data
3431 associated with each such page may also be accessed.
3432
3433 @b{NOTE:} At the time this text was written, no error correction
3434 was done on the data that's read, unless raw access was disabled
3435 and the underlying NAND controller driver had a @code{read_page}
3436 method which handled that error correction.
3437
3438 By default, only page data is saved to the specified file.
3439 Use an @var{oob_option} parameter to save OOB data:
3440 @itemize @bullet
3441 @item no oob_* parameter
3442 @*Output file holds only page data; OOB is discarded.
3443 @item @code{oob_raw}
3444 @*Output file interleaves page data and OOB data;
3445 the file will be longer than "length" by the size of the
3446 spare areas associated with each data page.
3447 Note that this kind of "raw" access is different from
3448 what's implied by @command{nand raw_access}, which just
3449 controls whether a hardware-aware access method is used.
3450 @item @code{oob_only}
3451 @*Output file has only raw OOB data, and will
3452 be smaller than "length" since it will contain only the
3453 spare areas associated with each data page.
3454 @end itemize
3455 @end deffn
3456
3457 @deffn Command {nand erase} num offset length
3458 @cindex NAND erasing
3459 @cindex NAND programming
3460 Erases blocks on the specified NAND device, starting at the
3461 specified @var{offset} and continuing for @var{length} bytes.
3462 Both of those values must be exact multiples of the device's
3463 block size, and the region they specify must fit entirely in the chip.
3464 The @var{num} parameter is the value shown by @command{nand list}.
3465
3466 @b{NOTE:} This command will try to erase bad blocks, when told
3467 to do so, which will probably invalidate the manufacturer's bad
3468 block marker.
3469 For the remainder of the current server session, @command{nand info}
3470 will still report that the block ``is'' bad.
3471 @end deffn
3472
3473 @deffn Command {nand write} num filename offset [option...]
3474 @cindex NAND writing
3475 @cindex NAND programming
3476 Writes binary data from the file into the specified NAND device,
3477 starting at the specified offset. Those pages should already
3478 have been erased; you can't change zero bits to one bits.
3479 The @var{num} parameter is the value shown by @command{nand list}.
3480
3481 Use a complete path name for @var{filename}, so you don't depend
3482 on the directory used to start the OpenOCD server.
3483
3484 The @var{offset} must be an exact multiple of the device's page size.
3485 All data in the file will be written, assuming it doesn't run
3486 past the end of the device.
3487 Only full pages are written, and any extra space in the last
3488 page will be filled with 0xff bytes. (That includes OOB data,
3489 if that's being written.)
3490
3491 @b{NOTE:} At the time this text was written, bad blocks are
3492 ignored. That is, this routine will not skip bad blocks,
3493 but will instead try to write them. This can cause problems.
3494
3495 Provide at most one @var{option} parameter. With some
3496 NAND drivers, the meanings of these parameters may change
3497 if @command{nand raw_access} was used to disable hardware ECC.
3498 @itemize @bullet
3499 @item no oob_* parameter
3500 @*File has only page data, which is written.
3501 If raw acccess is in use, the OOB area will not be written.
3502 Otherwise, if the underlying NAND controller driver has
3503 a @code{write_page} routine, that routine may write the OOB
3504 with hardware-computed ECC data.
3505 @item @code{oob_only}
3506 @*File has only raw OOB data, which is written to the OOB area.
3507 Each page's data area stays untouched. @i{This can be a dangerous
3508 option}, since it can invalidate the ECC data.
3509 You may need to force raw access to use this mode.
3510 @item @code{oob_raw}
3511 @*File interleaves data and OOB data, both of which are written
3512 If raw access is enabled, the data is written first, then the
3513 un-altered OOB.
3514 Otherwise, if the underlying NAND controller driver has
3515 a @code{write_page} routine, that routine may modify the OOB
3516 before it's written, to include hardware-computed ECC data.
3517 @item @code{oob_softecc}
3518 @*File has only page data, which is written.
3519 The OOB area is filled with 0xff, except for a standard 1-bit
3520 software ECC code stored in conventional locations.
3521 You might need to force raw access to use this mode, to prevent
3522 the underlying driver from applying hardware ECC.
3523 @item @code{oob_softecc_kw}
3524 @*File has only page data, which is written.
3525 The OOB area is filled with 0xff, except for a 4-bit software ECC
3526 specific to the boot ROM in Marvell Kirkwood SoCs.
3527 You might need to force raw access to use this mode, to prevent
3528 the underlying driver from applying hardware ECC.
3529 @end itemize
3530 @end deffn
3531
3532 @section Other NAND commands
3533 @cindex NAND other commands
3534
3535 @deffn Command {nand check_bad_blocks} [offset length]
3536 Checks for manufacturer bad block markers on the specified NAND
3537 device. If no parameters are provided, checks the whole
3538 device; otherwise, starts at the specified @var{offset} and
3539 continues for @var{length} bytes.
3540 Both of those values must be exact multiples of the device's
3541 block size, and the region they specify must fit entirely in the chip.
3542 The @var{num} parameter is the value shown by @command{nand list}.
3543
3544 @b{NOTE:} Before using this command you should force raw access
3545 with @command{nand raw_access enable} to ensure that the underlying
3546 driver will not try to apply hardware ECC.
3547 @end deffn
3548
3549 @deffn Command {nand info} num
3550 The @var{num} parameter is the value shown by @command{nand list}.
3551 This prints the one-line summary from "nand list", plus for
3552 devices which have been probed this also prints any known
3553 status for each block.
3554 @end deffn
3555
3556 @deffn Command {nand raw_access} num (@option{enable}|@option{disable})
3557 Sets or clears an flag affecting how page I/O is done.
3558 The @var{num} parameter is the value shown by @command{nand list}.
3559
3560 This flag is cleared (disabled) by default, but changing that
3561 value won't affect all NAND devices. The key factor is whether
3562 the underlying driver provides @code{read_page} or @code{write_page}
3563 methods. If it doesn't provide those methods, the setting of
3564 this flag is irrelevant; all access is effectively ``raw''.
3565
3566 When those methods exist, they are normally used when reading
3567 data (@command{nand dump} or reading bad block markers) or
3568 writing it (@command{nand write}). However, enabling
3569 raw access (setting the flag) prevents use of those methods,
3570 bypassing hardware ECC logic.
3571 @i{This can be a dangerous option}, since writing blocks
3572 with the wrong ECC data can cause them to be marked as bad.
3573 @end deffn
3574
3575 @anchor{NAND Driver List}
3576 @section NAND Drivers, Options, and Commands
3577 As noted above, the @command{nand device} command allows
3578 driver-specific options and behaviors.
3579 Some controllers also activate controller-specific commands.
3580
3581 @deffn {NAND Driver} davinci
3582 This driver handles the NAND controllers found on DaVinci family
3583 chips from Texas Instruments.
3584 It takes three extra parameters:
3585 address of the NAND chip;
3586 hardware ECC mode to use (hwecc1, hwecc4, hwecc4_infix);
3587 address of the AEMIF controller on this processor.
3588 @example
3589 nand device davinci dm355.arm 0x02000000 hwecc4 0x01e10000
3590 @end example
3591 All DaVinci processors support the single-bit ECC hardware,
3592 and newer ones also support the four-bit ECC hardware.
3593 The @code{write_page} and @code{read_page} methods are used
3594 to implement those ECC modes, unless they are disabled using
3595 the @command{nand raw_access} command.
3596 @end deffn
3597
3598 @deffn {NAND Driver} lpc3180
3599 These controllers require an extra @command{nand device}
3600 parameter: the clock rate used by the controller.
3601 @deffn Command {lpc3180 select} num [mlc|slc]
3602 Configures use of the MLC or SLC controller mode.
3603 MLC implies use of hardware ECC.
3604 The @var{num} parameter is the value shown by @command{nand list}.
3605 @end deffn
3606
3607 At this writing, this driver includes @code{write_page}
3608 and @code{read_page} methods. Using @command{nand raw_access}
3609 to disable those methods will prevent use of hardware ECC
3610 in the MLC controller mode, but won't change SLC behavior.
3611 @end deffn
3612 @comment current lpc3180 code won't issue 5-byte address cycles
3613
3614 @deffn {NAND Driver} orion
3615 These controllers require an extra @command{nand device}
3616 parameter: the address of the controller.
3617 @example
3618 nand device orion 0xd8000000
3619 @end example
3620 These controllers don't define any specialized commands.
3621 At this writing, their drivers don't include @code{write_page}
3622 or @code{read_page} methods, so @command{nand raw_access} won't
3623 change any behavior.
3624 @end deffn
3625
3626 @deffn {NAND Driver} s3c2410
3627 @deffnx {NAND Driver} s3c2412
3628 @deffnx {NAND Driver} s3c2440
3629 @deffnx {NAND Driver} s3c2443
3630 These S3C24xx family controllers don't have any special
3631 @command{nand device} options, and don't define any
3632 specialized commands.
3633 At this writing, their drivers don't include @code{write_page}
3634 or @code{read_page} methods, so @command{nand raw_access} won't
3635 change any behavior.
3636 @end deffn
3637
3638 @node General Commands
3639 @chapter General Commands
3640 @cindex commands
3641
3642 The commands documented in this chapter here are common commands that
3643 you, as a human, may want to type and see the output of. Configuration type
3644 commands are documented elsewhere.
3645
3646 Intent:
3647 @itemize @bullet
3648 @item @b{Source Of Commands}
3649 @* OpenOCD commands can occur in a configuration script (discussed
3650 elsewhere) or typed manually by a human or supplied programatically,
3651 or via one of several TCP/IP Ports.
3652
3653 @item @b{From the human}
3654 @* A human should interact with the telnet interface (default port: 4444)
3655 or via GDB (default port 3333).
3656
3657 To issue commands from within a GDB session, use the @option{monitor}
3658 command, e.g. use @option{monitor poll} to issue the @option{poll}
3659 command. All output is relayed through the GDB session.
3660
3661 @item @b{Machine Interface}
3662 The Tcl interface's intent is to be a machine interface. The default Tcl
3663 port is 5555.
3664 @end itemize
3665
3666
3667 @section Daemon Commands
3668
3669 @deffn Command sleep msec [@option{busy}]
3670 Wait for at least @var{msec} milliseconds before resuming.
3671 If @option{busy} is passed, busy-wait instead of sleeping.
3672 (This option is strongly discouraged.)
3673 Useful in connection with script files
3674 (@command{script} command and @command{target_name} configuration).
3675 @end deffn
3676
3677 @deffn Command shutdown
3678 Close the OpenOCD daemon, disconnecting all clients (GDB, telnet, other).
3679 @end deffn
3680
3681 @anchor{debug_level}
3682 @deffn Command debug_level [n]
3683 @cindex message level
3684 Display debug level.
3685 If @var{n} (from 0..3) is provided, then set it to that level.
3686 This affects the kind of messages sent to the server log.
3687 Level 0 is error messages only;
3688 level 1 adds warnings;
3689 level 2 (the default) adds informational messages;
3690 and level 3 adds debugging messages.
3691 @end deffn
3692
3693 @deffn Command fast (@option{enable}|@option{disable})
3694 Default disabled.
3695 Set default behaviour of OpenOCD to be "fast and dangerous".
3696
3697 At this writing, this only affects the defaults for two ARM7/ARM9 parameters:
3698 fast memory access, and DCC downloads. Those parameters may still be
3699 individually overridden.
3700
3701 The target specific "dangerous" optimisation tweaking options may come and go
3702 as more robust and user friendly ways are found to ensure maximum throughput
3703 and robustness with a minimum of configuration.
3704
3705 Typically the "fast enable" is specified first on the command line:
3706
3707 @example
3708 openocd -c "fast enable" -c "interface dummy" -f target/str710.cfg
3709 @end example
3710 @end deffn
3711
3712 @deffn Command echo message
3713 Logs a message at "user" priority.
3714 Output @var{message} to stdout.
3715 @example
3716 echo "Downloading kernel -- please wait"
3717 @end example
3718 @end deffn
3719
3720 @deffn Command log_output [filename]
3721 Redirect logging to @var{filename};
3722 the initial log output channel is stderr.
3723 @end deffn
3724
3725 @anchor{Target State handling}
3726 @section Target State handling
3727 @cindex reset
3728 @cindex halt
3729 @cindex target initialization
3730
3731 In this section ``target'' refers to a CPU configured as
3732 shown earlier (@pxref{CPU Configuration}).
3733 These commands, like many, implicitly refer to
3734 a @dfn{current target} which is used to perform the
3735 various operations. The current target may be changed
3736 by using @command{targets} command with the name of the
3737 target which should become current.
3738
3739 @deffn Command reg [(number|name) [value]]
3740 Access a single register by @var{number} or by its @var{name}.
3741
3742 @emph{With no arguments}:
3743 list all available registers for the current target,
3744 showing number, name, size, value, and cache status.
3745
3746 @emph{With number/name}: display that register's value.
3747
3748 @emph{With both number/name and value}: set register's value.
3749
3750 Cores may have surprisingly many registers in their
3751 Debug and trace infrastructure:
3752
3753 @example
3754 > reg
3755 (0) r0 (/32): 0x0000D3C2 (dirty: 1, valid: 1)
3756 (1) r1 (/32): 0xFD61F31C (dirty: 0, valid: 1)
3757 (2) r2 (/32): 0x00022551 (dirty: 0, valid: 1)
3758 ...
3759 (164) ETM_CONTEXTID_COMPARATOR_MASK (/32): \
3760 0x00000000 (dirty: 0, valid: 0)
3761 >
3762 @end example
3763 @end deffn
3764
3765 @deffn Command poll [@option{on}|@option{off}]
3766 Poll the current target for its current state.
3767 If that target is in debug mode, architecture
3768 specific information about the current state is printed. An optional parameter
3769 allows continuous polling to be enabled and disabled.
3770
3771 @example
3772 > poll
3773 target state: halted
3774 target halted in ARM state due to debug-request, \
3775 current mode: Supervisor
3776 cpsr: 0x800000d3 pc: 0x11081bfc
3777 MMU: disabled, D-Cache: disabled, I-Cache: enabled
3778 >
3779 @end example
3780 @end deffn
3781
3782 @deffn Command halt [ms]
3783 @deffnx Command wait_halt [ms]
3784 The @command{halt} command first sends a halt request to the target,
3785 which @command{wait_halt} doesn't.
3786 Otherwise these behave the same: wait up to @var{ms} milliseconds,
3787 or 5 seconds if there is no parameter, for the target to halt
3788 (and enter debug mode).
3789 Using 0 as the @var{ms} parameter prevents OpenOCD from waiting.
3790 @end deffn
3791
3792 @deffn Command resume [address]
3793 Resume the target at its current code position,
3794 or the optional @var{address} if it is provided.
3795 OpenOCD will wait 5 seconds for the target to resume.
3796 @end deffn
3797
3798 @deffn Command step [address]
3799 Single-step the target at its current code position,
3800 or the optional @var{address} if it is provided.
3801 @end deffn
3802
3803 @anchor{Reset Command}
3804 @deffn Command reset
3805 @deffnx Command {reset run}
3806 @deffnx Command {reset halt}
3807 @deffnx Command {reset init}
3808 Perform as hard a reset as possible, using SRST if possible.
3809 @emph{All defined targets will be reset, and target
3810 events will fire during the reset sequence.}
3811
3812 The optional parameter specifies what should
3813 happen after the reset.
3814 If there is no parameter, a @command{reset run} is executed.
3815 The other options will not work on all systems.
3816 @xref{Reset Configuration}.
3817
3818 @itemize @minus
3819 @item @b{run} Let the target run
3820 @item @b{halt} Immediately halt the target
3821 @item @b{init} Immediately halt the target, and execute the reset-init script
3822 @end itemize
3823 @end deffn
3824
3825 @deffn Command soft_reset_halt
3826 Requesting target halt and executing a soft reset. This is often used
3827 when a target cannot be reset and halted. The target, after reset is
3828 released begins to execute code. OpenOCD attempts to stop the CPU and
3829 then sets the program counter back to the reset vector. Unfortunately
3830 the code that was executed may have left the hardware in an unknown
3831 state.
3832 @end deffn
3833
3834 @section I/O Utilities
3835
3836 These commands are available when
3837 OpenOCD is built with @option{--enable-ioutil}.
3838 They are mainly useful on embedded targets;
3839 PC type hosts have complimentary tools.
3840
3841 @emph{Note:} there are several more such commands.
3842
3843 @deffn Command meminfo
3844 Display available RAM memory on OpenOCD host.
3845 Used in OpenOCD regression testing scripts.
3846 @end deffn
3847
3848 @anchor{Memory access}
3849 @section Memory access commands
3850 @cindex memory access
3851
3852 These commands allow accesses of a specific size to the memory
3853 system. Often these are used to configure the current target in some
3854 special way. For example - one may need to write certain values to the
3855 SDRAM controller to enable SDRAM.
3856
3857 @enumerate
3858 @item Use the @command{targets} (plural) command
3859 to change the current target.
3860 @item In system level scripts these commands are deprecated.
3861 Please use their TARGET object siblings to avoid making assumptions
3862 about what TAP is the current target, or about MMU configuration.
3863 @end enumerate
3864
3865 @deffn Command mdw addr [count]
3866 @deffnx Command mdh addr [count]
3867 @deffnx Command mdb addr [count]
3868 Display contents of address @var{addr}, as
3869 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
3870 or 8-bit bytes (@command{mdb}).
3871 If @var{count} is specified, displays that many units.
3872 (If you want to manipulate the data instead of displaying it,
3873 see the @code{mem2array} primitives.)
3874 @end deffn
3875
3876 @deffn Command mww addr word
3877 @deffnx Command mwh addr halfword
3878 @deffnx Command mwb addr byte
3879 Writes the specified @var{word} (32 bits),
3880 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
3881 at the specified address @var{addr}.
3882 @end deffn
3883
3884
3885 @anchor{Image access}
3886 @section Image loading commands
3887 @cindex image loading
3888 @cindex image dumping
3889
3890 @anchor{dump_image}
3891 @deffn Command {dump_image} filename address size
3892 Dump @var{size} bytes of target memory starting at @var{address} to the
3893 binary file named @var{filename}.
3894 @end deffn
3895
3896 @deffn Command {fast_load}
3897 Loads an image stored in memory by @command{fast_load_image} to the
3898 current target. Must be preceeded by fast_load_image.
3899 @end deffn
3900
3901 @deffn Command {fast_load_image} filename address [@option{bin}|@option{ihex}|@option{elf}]
3902 Normally you should be using @command{load_image} or GDB load. However, for
3903 testing purposes or when I/O overhead is significant(OpenOCD running on an embedded
3904 host), storing the image in memory and uploading the image to the target
3905 can be a way to upload e.g. multiple debug sessions when the binary does not change.
3906 Arguments are the same as @command{load_image}, but the image is stored in OpenOCD host
3907 memory, i.e. does not affect target. This approach is also useful when profiling
3908 target programming performance as I/O and target programming can easily be profiled
3909 separately.
3910 @end deffn
3911
3912 @anchor{load_image}
3913 @deffn Command {load_image} filename address [@option{bin}|@option{ihex}|@option{elf}]
3914 Load image from file @var{filename} to target memory at @var{address}.
3915 The file format may optionally be specified
3916 (@option{bin}, @option{ihex}, or @option{elf})
3917 @end deffn
3918
3919 @deffn Command {verify_image} filename address [@option{bin}|@option{ihex}|@option{elf}]
3920 Verify @var{filename} against target memory starting at @var{address}.
3921 The file format may optionally be specified
3922 (@option{bin}, @option{ihex}, or @option{elf})
3923 This will first attempt a comparison using a CRC checksum, if this fails it will try a binary compare.
3924 @end deffn
3925
3926
3927 @section Breakpoint and Watchpoint commands
3928 @cindex breakpoint
3929 @cindex watchpoint
3930
3931 CPUs often make debug modules accessible through JTAG, with
3932 hardware support for a handful of code breakpoints and data
3933 watchpoints.
3934 In addition, CPUs almost always support software breakpoints.
3935
3936 @deffn Command {bp} [address len [@option{hw}]]
3937 With no parameters, lists all active breakpoints.
3938 Else sets a breakpoint on code execution starting
3939 at @var{address} for @var{length} bytes.
3940 This is a software breakpoint, unless @option{hw} is specified
3941 in which case it will be a hardware breakpoint.
3942 @end deffn
3943
3944 @deffn Command {rbp} address
3945 Remove the breakpoint at @var{address}.
3946 @end deffn
3947
3948 @deffn Command {rwp} address
3949 Remove data watchpoint on @var{address}
3950 @end deffn
3951
3952 @deffn Command {wp} [address len [(@option{r}|@option{w}|@option{a}) [value [mask]]]
3953 With no parameters, lists all active watchpoints.
3954 Else sets a data watchpoint on data from @var{address} for @var{length} bytes.
3955 The watch point is an "access" watchpoint unless
3956 the @option{r} or @option{w} parameter is provided,
3957 defining it as respectively a read or write watchpoint.
3958 If a @var{value} is provided, that value is used when determining if
3959 the watchpoint should trigger. The value may be first be masked
3960 using @var{mask} to mark ``don't care'' fields.
3961 @end deffn
3962
3963 @section Misc Commands
3964 @cindex profiling
3965
3966 @deffn Command {profile} seconds filename
3967 Profiling samples the CPU's program counter as quickly as possible,
3968 which is useful for non-intrusive stochastic profiling.
3969 Saves up to 10000 sampines in @file{filename} using ``gmon.out'' format.
3970 @end deffn
3971
3972 @node Architecture and Core Commands
3973 @chapter Architecture and Core Commands
3974 @cindex Architecture Specific Commands
3975 @cindex Core Specific Commands
3976
3977 Most CPUs have specialized JTAG operations to support debugging.
3978 OpenOCD packages most such operations in its standard command framework.
3979 Some of those operations don't fit well in that framework, so they are
3980 exposed here as architecture or implementation (core) specific commands.
3981
3982 @anchor{ARM Tracing}
3983 @section ARM Tracing
3984 @cindex ETM
3985 @cindex ETB
3986
3987 CPUs based on ARM cores may include standard tracing interfaces,
3988 based on an ``Embedded Trace Module'' (ETM) which sends voluminous
3989 address and data bus trace records to a ``Trace Port''.
3990
3991 @itemize
3992 @item
3993 Development-oriented boards will sometimes provide a high speed
3994 trace connector for collecting that data, when the particular CPU
3995 supports such an interface.
3996 (The standard connector is a 38-pin Mictor, with both JTAG
3997 and trace port support.)
3998 Those trace connectors are supported by higher end JTAG adapters
3999 and some logic analyzer modules; frequently those modules can
4000 buffer several megabytes of trace data.
4001 Configuring an ETM coupled to such an external trace port belongs
4002 in the board-specific configuration file.
4003 @item
4004 If the CPU doesn't provide an external interface, it probably
4005 has an ``Embedded Trace Buffer'' (ETB) on the chip, which is a
4006 dedicated SRAM. 4KBytes is one common ETB size.
4007 Configuring an ETM coupled only to an ETB belongs in the CPU-specific
4008 (target) configuration file, since it works the same on all boards.
4009 @end itemize
4010
4011 ETM support in OpenOCD doesn't seem to be widely used yet.
4012
4013 @quotation Issues
4014 ETM support may be buggy, and at least some @command{etm config}
4015 parameters should be detected by asking the ETM for them.
4016 It seems like a GDB hookup should be possible,
4017 as well as triggering trace on specific events
4018 (perhaps @emph{handling IRQ 23} or @emph{calls foo()}).
4019 There should be GUI tools to manipulate saved trace data and help
4020 analyse it in conjunction with the source code.
4021 It's unclear how much of a common interface is shared
4022 with the current XScale trace support, or should be
4023 shared with eventual Nexus-style trace module support.
4024 @end quotation
4025
4026 @subsection ETM Configuration
4027 ETM setup is coupled with the trace port driver configuration.
4028
4029 @deffn {Config Command} {etm config} target width mode clocking driver
4030 Declares the ETM associated with @var{target}, and associates it
4031 with a given trace port @var{driver}. @xref{Trace Port Drivers}.
4032
4033 Several of the parameters must reflect the trace port configuration.
4034 The @var{width} must be either 4, 8, or 16.
4035 The @var{mode} must be @option{normal}, @option{multiplexted},
4036 or @option{demultiplexted}.
4037 The @var{clocking} must be @option{half} or @option{full}.
4038
4039 @quotation Note
4040 You can see the ETM registers using the @command{reg} command, although
4041 not all of those possible registers are present in every ETM.
4042 @end quotation
4043 @end deffn
4044
4045 @deffn Command {etm info}
4046 Displays information about the current target's ETM.
4047 @end deffn
4048
4049 @deffn Command {etm status}
4050 Displays status of the current target's ETM:
4051 is the ETM idle, or is it collecting data?
4052 Did trace data overflow?
4053 Was it triggered?
4054 @end deffn
4055
4056 @deffn Command {etm tracemode} [type context_id_bits cycle_accurate branch_output]
4057 Displays what data that ETM will collect.
4058 If arguments are provided, first configures that data.
4059 When the configuration changes, tracing is stopped
4060 and any buffered trace data is invalidated.
4061
4062 @itemize
4063 @item @var{type} ... one of
4064 @option{none} (save nothing),
4065 @option{data} (save data),
4066 @option{address} (save addresses),
4067 @option{all} (save data and addresses)
4068 @item @var{context_id_bits} ... 0, 8, 16, or 32
4069 @item @var{cycle_accurate} ... @option{enable} or @option{disable}
4070 @item @var{branch_output} ... @option{enable} or @option{disable}
4071 @end itemize
4072 @end deffn
4073
4074 @deffn Command {etm trigger_percent} percent
4075 @emph{Buggy and effectively a NOP ... @var{percent} from 2..100}
4076 @end deffn
4077
4078 @subsection ETM Trace Operation
4079
4080 After setting up the ETM, you can use it to collect data.
4081 That data can be exported to files for later analysis.
4082 It can also be parsed with OpenOCD, for basic sanity checking.
4083
4084 @deffn Command {etm analyze}
4085 Reads trace data into memory, if it wasn't already present.
4086 Decodes and prints the data that was collected.
4087 @end deffn
4088
4089 @deffn Command {etm dump} filename
4090 Stores the captured trace data in @file{filename}.
4091 @end deffn
4092
4093 @deffn Command {etm image} filename [base_address] [type]
4094 Opens an image file.
4095 @end deffn
4096
4097 @deffn Command {etm load} filename
4098 Loads captured trace data from @file{filename}.
4099 @end deffn
4100
4101 @deffn Command {etm start}
4102 Starts trace data collection.
4103 @end deffn
4104
4105 @deffn Command {etm stop}
4106 Stops trace data collection.
4107 @end deffn
4108
4109 @anchor{Trace Port Drivers}
4110 @subsection Trace Port Drivers
4111
4112 To use an ETM trace port it must be associated with a driver.
4113
4114 @deffn {Trace Port Driver} dummy
4115 Use the @option{dummy} driver if you are configuring an ETM that's
4116 not connected to anything (on-chip ETB or off-chip trace connector).
4117 @emph{This driver lets OpenOCD talk to the ETM, but it does not expose
4118 any trace data collection.}
4119 @deffn {Config Command} {etm_dummy config} target
4120 Associates the ETM for @var{target} with a dummy driver.
4121 @end deffn
4122 @end deffn
4123
4124 @deffn {Trace Port Driver} etb
4125 Use the @option{etb} driver if you are configuring an ETM
4126 to use on-chip ETB memory.
4127 @deffn {Config Command} {etb config} target etb_tap
4128 Associates the ETM for @var{target} with the ETB at @var{etb_tap}.
4129 You can see the ETB registers using the @command{reg} command.
4130 @end deffn
4131 @end deffn
4132
4133 @deffn {Trace Port Driver} oocd_trace
4134 This driver isn't available unless OpenOCD was explicitly configured
4135 with the @option{--enable-oocd_trace} option. You probably don't want
4136 to configure it unless you've built the appropriate prototype hardware;
4137 it's @emph{proof-of-concept} software.
4138
4139 Use the @option{oocd_trace} driver if you are configuring an ETM that's
4140 connected to an off-chip trace connector.
4141
4142 @deffn {Config Command} {oocd_trace config} target tty
4143 Associates the ETM for @var{target} with a trace driver which
4144 collects data through the serial port @var{tty}.
4145 @end deffn
4146
4147 @deffn Command {oocd_trace resync}
4148 Re-synchronizes with the capture clock.
4149 @end deffn
4150
4151 @deffn Command {oocd_trace status}
4152 Reports whether the capture clock is locked or not.
4153 @end deffn
4154 @end deffn
4155
4156
4157 @section ARMv4 and ARMv5 Architecture
4158 @cindex ARMv4
4159 @cindex ARMv5
4160
4161 These commands are specific to ARM architecture v4 and v5,
4162 including all ARM7 or ARM9 systems and Intel XScale.
4163 They are available in addition to other core-specific
4164 commands that may be available.
4165
4166 @deffn Command {armv4_5 core_state} [@option{arm}|@option{thumb}]
4167 Displays the core_state, optionally changing it to process
4168 either @option{arm} or @option{thumb} instructions.
4169 The target may later be resumed in the currently set core_state.
4170 (Processors may also support the Jazelle state, but
4171 that is not currently supported in OpenOCD.)
4172 @end deffn
4173
4174 @deffn Command {armv4_5 disassemble} address count [thumb]
4175 @cindex disassemble
4176 Disassembles @var{count} instructions starting at @var{address}.
4177 If @option{thumb} is specified, Thumb (16-bit) instructions are used;
4178 else ARM (32-bit) instructions are used.
4179 (Processors may also support the Jazelle state, but
4180 those instructions are not currently understood by OpenOCD.)
4181 @end deffn
4182
4183 @deffn Command {armv4_5 reg}
4184 Display a table of all banked core registers, fetching the current value from every
4185 core mode if necessary. OpenOCD versions before rev. 60 didn't fetch the current
4186 register value.
4187 @end deffn
4188
4189 @subsection ARM7 and ARM9 specific commands
4190 @cindex ARM7
4191 @cindex ARM9
4192
4193 These commands are specific to ARM7 and ARM9 cores, like ARM7TDMI, ARM720T,
4194 ARM9TDMI, ARM920T or ARM926EJ-S.
4195 They are available in addition to the ARMv4/5 commands,
4196 and any other core-specific commands that may be available.
4197
4198 @deffn Command {arm7_9 dbgrq} (@option{enable}|@option{disable})
4199 Control use of the EmbeddedIce DBGRQ signal to force entry into debug mode,
4200 instead of breakpoints. This should be
4201 safe for all but ARM7TDMI--S cores (like Philips LPC).
4202 @end deffn
4203
4204 @deffn Command {arm7_9 dcc_downloads} (@option{enable}|@option{disable})
4205 @cindex DCC
4206 Control the use of the debug communications channel (DCC) to write larger (>128 byte)
4207 amounts of memory. DCC downloads offer a huge speed increase, but might be
4208 unsafe, especially with targets running at very low speeds. This command was introduced
4209 with OpenOCD rev. 60, and requires a few bytes of working area.
4210 @end deffn
4211
4212 @anchor{arm7_9 fast_memory_access}
4213 @deffn Command {arm7_9 fast_memory_access} (@option{enable}|@option{disable})
4214 Enable or disable memory writes and reads that don't check completion of
4215 the operation. This provides a huge speed increase, especially with USB JTAG
4216 cables (FT2232), but might be unsafe if used with targets running at very low
4217 speeds, like the 32kHz startup clock of an AT91RM9200.
4218 @end deffn
4219
4220 @deffn {Debug Command} {arm7_9 write_core_reg} num mode word
4221 @emph{This is intended for use while debugging OpenOCD; you probably
4222 shouldn't use it.}
4223
4224 Writes a 32-bit @var{word} to register @var{num} (from 0 to 16)
4225 as used in the specified @var{mode}
4226 (where e.g. mode 16 is "user" and mode 19 is "supervisor";
4227 the M4..M0 bits of the PSR).
4228 Registers 0..15 are the normal CPU registers such as r0(0), r1(1) ... pc(15).
4229 Register 16 is the mode-specific SPSR,
4230 unless the specified mode is 0xffffffff (32-bit all-ones)
4231 in which case register 16 is the CPSR.
4232 The write goes directly to the CPU, bypassing the register cache.
4233 @end deffn
4234
4235 @deffn {Debug Command} {arm7_9 write_xpsr} word (@option{0}|@option{1})
4236 @emph{This is intended for use while debugging OpenOCD; you probably
4237 shouldn't use it.}
4238
4239 If the second parameter is zero, writes @var{word} to the
4240 Current Program Status register (CPSR).
4241 Else writes @var{word} to the current mode's Saved PSR (SPSR).
4242 In both cases, this bypasses the register cache.
4243 @end deffn
4244
4245 @deffn {Debug Command} {arm7_9 write_xpsr_im8} byte rotate (@option{0}|@option{1})
4246 @emph{This is intended for use while debugging OpenOCD; you probably
4247 shouldn't use it.}
4248
4249 Writes eight bits to the CPSR or SPSR,
4250 first rotating them by @math{2*rotate} bits,
4251 and bypassing the register cache.
4252 This has lower JTAG overhead than writing the entire CPSR or SPSR
4253 with @command{arm7_9 write_xpsr}.
4254 @end deffn
4255
4256 @subsection ARM720T specific commands
4257 @cindex ARM720T
4258
4259 These commands are available to ARM720T based CPUs,
4260 which are implementations of the ARMv4T architecture
4261 based on the ARM7TDMI-S integer core.
4262 They are available in addition to the ARMv4/5 and ARM7/ARM9 commands.
4263
4264 @deffn Command {arm720t cp15} regnum [value]
4265 Display cp15 register @var{regnum};
4266 else if a @var{value} is provided, that value is written to that register.
4267 @end deffn
4268
4269 @deffn Command {arm720t mdw_phys} addr [count]
4270 @deffnx Command {arm720t mdh_phys} addr [count]
4271 @deffnx Command {arm720t mdb_phys} addr [count]
4272 Display contents of physical address @var{addr}, as
4273 32-bit words (@command{mdw_phys}), 16-bit halfwords (@command{mdh_phys}),
4274 or 8-bit bytes (@command{mdb_phys}).
4275 If @var{count} is specified, displays that many units.
4276 @end deffn
4277
4278 @deffn Command {arm720t mww_phys} addr word
4279 @deffnx Command {arm720t mwh_phys} addr halfword
4280 @deffnx Command {arm720t mwb_phys} addr byte
4281 Writes the specified @var{word} (32 bits),
4282 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
4283 at the specified physical address @var{addr}.
4284 @end deffn
4285
4286 @deffn Command {arm720t virt2phys} va
4287 Translate a virtual address @var{va} to a physical address
4288 and display the result.
4289 @end deffn
4290
4291 @subsection ARM9TDMI specific commands
4292 @cindex ARM9TDMI
4293
4294 Many ARM9-family CPUs are built around ARM9TDMI integer cores,
4295 or processors resembling ARM9TDMI, and can use these commands.
4296 Such cores include the ARM920T, ARM926EJ-S, and ARM966.
4297
4298 @deffn Command {arm9tdmi vector_catch} (@option{all}|@option{none}|list)
4299 Catch arm9 interrupt vectors, can be @option{all}, @option{none},
4300 or a list with one or more of the following:
4301 @option{reset} @option{undef} @option{swi} @option{pabt} @option{dabt} @option{reserved}
4302 @option{irq} @option{fiq}.
4303 @end deffn
4304
4305 @subsection ARM920T specific commands
4306 @cindex ARM920T
4307
4308 These commands are available to ARM920T based CPUs,
4309 which are implementations of the ARMv4T architecture
4310 built using the ARM9TDMI integer core.
4311 They are available in addition to the ARMv4/5, ARM7/ARM9,
4312 and ARM9TDMI commands.
4313
4314 @deffn Command {arm920t cache_info}
4315 Print information about the caches found. This allows to see whether your target
4316 is an ARM920T (2x16kByte cache) or ARM922T (2x8kByte cache).
4317 @end deffn
4318
4319 @deffn Command {arm920t cp15} regnum [value]
4320 Display cp15 register @var{regnum};
4321 else if a @var{value} is provided, that value is written to that register.
4322 @end deffn
4323
4324 @deffn Command {arm920t cp15i} opcode [value [address]]
4325 Interpreted access using cp15 @var{opcode}.
4326 If no @var{value} is provided, the result is displayed.
4327 Else if that value is written using the specified @var{address},
4328 or using zero if no other address is not provided.
4329 @end deffn
4330
4331 @deffn Command {arm920t mdw_phys} addr [count]
4332 @deffnx Command {arm920t mdh_phys} addr [count]
4333 @deffnx Command {arm920t mdb_phys} addr [count]
4334 Display contents of physical address @var{addr}, as
4335 32-bit words (@command{mdw_phys}), 16-bit halfwords (@command{mdh_phys}),
4336 or 8-bit bytes (@command{mdb_phys}).
4337 If @var{count} is specified, displays that many units.
4338 @end deffn
4339
4340 @deffn Command {arm920t mww_phys} addr word
4341 @deffnx Command {arm920t mwh_phys} addr halfword
4342 @deffnx Command {arm920t mwb_phys} addr byte
4343 Writes the specified @var{word} (32 bits),
4344 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
4345 at the specified physical address @var{addr}.
4346 @end deffn
4347
4348 @deffn Command {arm920t read_cache} filename
4349 Dump the content of ICache and DCache to a file named @file{filename}.
4350 @end deffn
4351
4352 @deffn Command {arm920t read_mmu} filename
4353 Dump the content of the ITLB and DTLB to a file named @file{filename}.
4354 @end deffn
4355
4356 @deffn Command {arm920t virt2phys} va
4357 Translate a virtual address @var{va} to a physical address
4358 and display the result.
4359 @end deffn
4360
4361 @subsection ARM926ej-s specific commands
4362 @cindex ARM926ej-s
4363
4364 These commands are available to ARM926ej-s based CPUs,
4365 which are implementations of the ARMv5TEJ architecture
4366 based on the ARM9EJ-S integer core.
4367 They are available in addition to the ARMv4/5, ARM7/ARM9,
4368 and ARM9TDMI commands.
4369
4370 The Feroceon cores also support these commands, although
4371 they are not built from ARM926ej-s designs.
4372
4373 @deffn Command {arm926ejs cache_info}
4374 Print information about the caches found.
4375 @end deffn
4376
4377 @deffn Command {arm926ejs cp15} opcode1 opcode2 CRn CRm regnum [value]
4378 Accesses cp15 register @var{regnum} using
4379 @var{opcode1}, @var{opcode2}, @var{CRn}, and @var{CRm}.
4380 If a @var{value} is provided, that value is written to that register.
4381 Else that register is read and displayed.
4382 @end deffn
4383
4384 @deffn Command {arm926ejs mdw_phys} addr [count]
4385 @deffnx Command {arm926ejs mdh_phys} addr [count]
4386 @deffnx Command {arm926ejs mdb_phys} addr [count]
4387 Display contents of physical address @var{addr}, as
4388 32-bit words (@command{mdw_phys}), 16-bit halfwords (@command{mdh_phys}),
4389 or 8-bit bytes (@command{mdb_phys}).
4390 If @var{count} is specified, displays that many units.
4391 @end deffn
4392
4393 @deffn Command {arm926ejs mww_phys} addr word
4394 @deffnx Command {arm926ejs mwh_phys} addr halfword
4395 @deffnx Command {arm926ejs mwb_phys} addr byte
4396 Writes the specified @var{word} (32 bits),
4397 @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
4398 at the specified physical address @var{addr}.
4399 @end deffn
4400
4401 @deffn Command {arm926ejs virt2phys} va
4402 Translate a virtual address @var{va} to a physical address
4403 and display the result.
4404 @end deffn
4405
4406 @subsection ARM966E specific commands
4407 @cindex ARM966E
4408
4409 These commands are available to ARM966 based CPUs,
4410 which are implementations of the ARMv5TE architecture.
4411 They are available in addition to the ARMv4/5, ARM7/ARM9,
4412 and ARM9TDMI commands.
4413
4414 @deffn Command {arm966e cp15} regnum [value]
4415 Display cp15 register @var{regnum};
4416 else if a @var{value} is provided, that value is written to that register.
4417 @end deffn
4418
4419 @subsection XScale specific commands
4420 @cindex XScale
4421
4422 These commands are available to XScale based CPUs,
4423 which are implementations of the ARMv5TE architecture.
4424
4425 @deffn Command {xscale analyze_trace}
4426 Displays the contents of the trace buffer.
4427 @end deffn
4428
4429 @deffn Command {xscale cache_clean_address} address
4430 Changes the address used when cleaning the data cache.
4431 @end deffn
4432
4433 @deffn Command {xscale cache_info}
4434 Displays information about the CPU caches.
4435 @end deffn
4436
4437 @deffn Command {xscale cp15} regnum [value]
4438 Display cp15 register @var{regnum};
4439 else if a @var{value} is provided, that value is written to that register.
4440 @end deffn
4441
4442 @deffn Command {xscale debug_handler} target address
4443 Changes the address used for the specified target's debug handler.
4444 @end deffn
4445
4446 @deffn Command {xscale dcache} (@option{enable}|@option{disable})
4447 Enables or disable the CPU's data cache.
4448 @end deffn
4449
4450 @deffn Command {xscale dump_trace} filename
4451 Dumps the raw contents of the trace buffer to @file{filename}.
4452 @end deffn
4453
4454 @deffn Command {xscale icache} (@option{enable}|@option{disable})
4455 Enables or disable the CPU's instruction cache.
4456 @end deffn
4457
4458 @deffn Command {xscale mmu} (@option{enable}|@option{disable})
4459 Enables or disable the CPU's memory management unit.
4460 @end deffn
4461
4462 @deffn Command {xscale trace_buffer} (@option{enable}|@option{disable}) [@option{fill} [n] | @option{wrap}]
4463 Enables or disables the trace buffer,
4464 and controls how it is emptied.
4465 @end deffn
4466
4467 @deffn Command {xscale trace_image} filename [offset [type]]
4468 Opens a trace image from @file{filename}, optionally rebasing
4469 its segment addresses by @var{offset}.
4470 The image @var{type} may be one of
4471 @option{bin} (binary), @option{ihex} (Intel hex),
4472 @option{elf} (ELF file), @option{s19} (Motorola s19),
4473 @option{mem}, or @option{builder}.
4474 @end deffn
4475
4476 @deffn Command {xscale vector_catch} mask
4477 Provide a bitmask showing the vectors to catch.
4478 @end deffn
4479
4480 @section ARMv6 Architecture
4481 @cindex ARMv6
4482
4483 @subsection ARM11 specific commands
4484 @cindex ARM11
4485
4486 @deffn Command {arm11 mcr} p1 p2 p3 p4 p5
4487 Read coprocessor register
4488 @end deffn
4489
4490 @deffn Command {arm11 memwrite burst} [value]
4491 Displays the value of the memwrite burst-enable flag,
4492 which is enabled by default.
4493 If @var{value} is defined, first assigns that.
4494 @end deffn
4495
4496 @deffn Command {arm11 memwrite error_fatal} [value]
4497 Displays the value of the memwrite error_fatal flag,
4498 which is enabled by default.
4499 If @var{value} is defined, first assigns that.
4500 @end deffn
4501
4502 @deffn Command {arm11 mrc} p1 p2 p3 p4 p5 value
4503 Write coprocessor register
4504 @end deffn
4505
4506 @deffn Command {arm11 no_increment} [value]
4507 Displays the value of the flag controlling whether
4508 some read or write operations increment the pointer
4509 (the default behavior) or not (acting like a FIFO).
4510 If @var{value} is defined, first assigns that.
4511 @end deffn
4512
4513 @deffn Command {arm11 step_irq_enable} [value]
4514 Displays the value of the flag controlling whether
4515 IRQs are enabled during single stepping;
4516 they is disabled by default.
4517 If @var{value} is defined, first assigns that.
4518 @end deffn
4519
4520 @section ARMv7 Architecture
4521 @cindex ARMv7
4522
4523 @subsection ARMv7 Debug Access Port (DAP) specific commands
4524 @cindex Debug Access Port
4525 @cindex DAP
4526 These commands are specific to ARM architecture v7 Debug Access Port (DAP),
4527 included on cortex-m3 and cortex-a8 systems.
4528 They are available in addition to other core-specific commands that may be available.
4529
4530 @deffn Command {dap info} [num]
4531 Displays dap info for ap @var{num}, defaulting to the currently selected AP.
4532 @end deffn
4533
4534 @deffn Command {dap apsel} [num]
4535 Select AP @var{num}, defaulting to 0.
4536 @end deffn
4537
4538 @deffn Command {dap apid} [num]
4539 Displays id register from AP @var{num},
4540 defaulting to the currently selected AP.
4541 @end deffn
4542
4543 @deffn Command {dap baseaddr} [num]
4544 Displays debug base address from AP @var{num},
4545 defaulting to the currently selected AP.
4546 @end deffn
4547
4548 @deffn Command {dap memaccess} [value]
4549 Displays the number of extra tck for mem-ap memory bus access [0-255].
4550 If @var{value} is defined, first assigns that.
4551 @end deffn
4552
4553 @subsection Cortex-M3 specific commands
4554 @cindex Cortex-M3
4555
4556 @deffn Command {cortex_m3 maskisr} (@option{on}|@option{off})
4557 Control masking (disabling) interrupts during target step/resume.
4558 @end deffn
4559
4560 @section Target DCC Requests
4561 @cindex Linux-ARM DCC support
4562 @cindex libdcc
4563 @cindex DCC
4564 OpenOCD can handle certain target requests; currently debugmsgs
4565 @command{target_request debugmsgs}
4566 are only supported for arm7_9 and cortex_m3.
4567
4568 See libdcc in the contrib dir for more details.
4569 Linux-ARM kernels have a ``Kernel low-level debugging
4570 via EmbeddedICE DCC channel'' option (CONFIG_DEBUG_ICEDCC,
4571 depends on CONFIG_DEBUG_LL) which uses this mechanism to
4572 deliver messages before a serial console can be activated.
4573
4574 @deffn Command {target_request debugmsgs} [@option{enable}|@option{disable}|@option{charmsg}]
4575 Displays current handling of target DCC message requests.
4576 These messages may be sent to the debugger while the target is running.
4577 The optional @option{enable} and @option{charmsg} parameters
4578 both enable the messages, while @option{disable} disables them.
4579 With @option{charmsg} the DCC words each contain one character,
4580 as used by Linux with CONFIG_DEBUG_ICEDCC;
4581 otherwise the libdcc format is used.
4582 @end deffn
4583
4584 @node JTAG Commands
4585 @chapter JTAG Commands
4586 @cindex JTAG Commands
4587 Most general purpose JTAG commands have been presented earlier.
4588 (@xref{JTAG Speed}, @ref{Reset Configuration}, and @ref{TAP Declaration}.)
4589 Lower level JTAG commands, as presented here,
4590 may be needed to work with targets which require special
4591 attention during operations such as reset or initialization.
4592
4593 To use these commands you will need to understand some
4594 of the basics of JTAG, including:
4595
4596 @itemize @bullet
4597 @item A JTAG scan chain consists of a sequence of individual TAP
4598 devices such as a CPUs.
4599 @item Control operations involve moving each TAP through the same
4600 standard state machine (in parallel)
4601 using their shared TMS and clock signals.
4602 @item Data transfer involves shifting data through the chain of
4603 instruction or data registers of each TAP, writing new register values
4604 while the reading previous ones.
4605 @item Data register sizes are a function of the instruction active in
4606 a given TAP, while instruction register sizes are fixed for each TAP.
4607 All TAPs support a BYPASS instruction with a single bit data register.
4608 @item The way OpenOCD differentiates between TAP devices is by
4609 shifting different instructions into (and out of) their instruction
4610 registers.
4611 @end itemize
4612
4613 @section Low Level JTAG Commands
4614
4615 These commands are used by developers who need to access
4616 JTAG instruction or data registers, possibly controlling
4617 the order of TAP state transitions.
4618 If you're not debugging OpenOCD internals, or bringing up a
4619 new JTAG adapter or a new type of TAP device (like a CPU or
4620 JTAG router), you probably won't need to use these commands.
4621
4622 @deffn Command {drscan} tap [numbits value]+ [@option{-endstate} tap_state]
4623 Loads the data register of @var{tap} with a series of bit fields
4624 that specify the entire register.
4625 Each field is @var{numbits} bits long with
4626 a numeric @var{value} (hexadecimal encouraged).
4627 The return value holds the original value of each
4628 of those fields.
4629
4630 For example, a 38 bit number might be specified as one
4631 field of 32 bits then one of 6 bits.
4632 @emph{For portability, never pass fields which are more
4633 than 32 bits long. Many OpenOCD implementations do not
4634 support 64-bit (or larger) integer values.}
4635
4636 All TAPs other than @var{tap} must be in BYPASS mode.
4637 The single bit in their data registers does not matter.
4638
4639 When @var{tap_state} is specified, the JTAG state machine is left
4640 in that state.
4641 For example @sc{drpause} might be specified, so that more
4642 instructions can be issued before re-entering the @sc{run/idle} state.
4643 If the end state is not specified, the @sc{run/idle} state is entered.
4644
4645 @quotation Warning
4646 OpenOCD does not record information about data register lengths,
4647 so @emph{it is important that you get the bit field lengths right}.
4648 Remember that different JTAG instructions refer to different
4649 data registers, which may have different lengths.
4650 Moreover, those lengths may not be fixed;
4651 the SCAN_N instruction can change the length of
4652 the register accessed by the INTEST instruction
4653 (by connecting a different scan chain).
4654 @end quotation
4655 @end deffn
4656
4657 @deffn Command {flush_count}
4658 Returns the number of times the JTAG queue has been flushed.
4659 This may be used for performance tuning.
4660
4661 For example, flushing a queue over USB involves a
4662 minimum latency, often several milliseconds, which does
4663 not change with the amount of data which is written.
4664 You may be able to identify performance problems by finding
4665 tasks which waste bandwidth by flushing small transfers too often,
4666 instead of batching them into larger operations.
4667 @end deffn
4668
4669 @deffn Command {irscan} [tap instruction]+ [@option{-endstate} tap_state]
4670 For each @var{tap} listed, loads the instruction register
4671 with its associated numeric @var{instruction}.
4672 (The number of bits in that instruction may be displayed
4673 using the @command{scan_chain} command.)
4674 For other TAPs, a BYPASS instruction is loaded.
4675
4676 When @var{tap_state} is specified, the JTAG state machine is left
4677 in that state.
4678 For example @sc{irpause} might be specified, so the data register
4679 can be loaded before re-entering the @sc{run/idle} state.
4680 If the end state is not specified, the @sc{run/idle} state is entered.
4681
4682 @quotation Note
4683 OpenOCD currently supports only a single field for instruction
4684 register values, unlike data register values.
4685 For TAPs where the instruction register length is more than 32 bits,
4686 portable scripts currently must issue only BYPASS instructions.
4687 @end quotation
4688 @end deffn
4689
4690 @deffn Command {jtag_reset} trst srst
4691 Set values of reset signals.
4692 The @var{trst} and @var{srst} parameter values may be
4693 @option{0}, indicating that reset is inactive (pulled or driven high),
4694 or @option{1}, indicating it is active (pulled or driven low).
4695 The @command{reset_config} command should already have been used
4696 to configure how the board and JTAG adapter treat these two
4697 signals, and to say if either signal is even present.
4698 @xref{Reset Configuration}.
4699 @end deffn
4700
4701 @deffn Command {runtest} @var{num_cycles}
4702 Move to the @sc{run/idle} state, and execute at least
4703 @var{num_cycles} of the JTAG clock (TCK).
4704 Instructions often need some time
4705 to execute before they take effect.
4706 @end deffn
4707
4708 @deffn Command {scan_chain}
4709 Displays the TAPs in the scan chain configuration,
4710 and their status.
4711 The set of TAPs listed by this command is fixed by
4712 exiting the OpenOCD configuration stage,
4713 but systems with a JTAG router can
4714 enable or disable TAPs dynamically.
4715 In addition to the enable/disable status, the contents of
4716 each TAP's instruction register can also change.
4717 @end deffn
4718
4719 @c tms_sequence (short|long)
4720 @c ... temporary, debug-only, probably gone before 0.2 ships
4721
4722 @deffn Command {verify_ircapture} (@option{enable}|@option{disable})
4723 Verify values captured during @sc{ircapture} and returned
4724 during IR scans. Default is enabled, but this can be
4725 overridden by @command{verify_jtag}.
4726 @end deffn
4727
4728 @deffn Command {verify_jtag} (@option{enable}|@option{disable})
4729 Enables verification of DR and IR scans, to help detect
4730 programming errors. For IR scans, @command{verify_ircapture}
4731 must also be enabled.
4732 Default is enabled.
4733 @end deffn
4734
4735 @section TAP state names
4736 @cindex TAP state names
4737
4738 The @var{tap_state} names used by OpenOCD in the @command{drscan},
4739 and @command{irscan} commands are:
4740
4741 @itemize @bullet
4742 @item @b{RESET} ... should act as if TRST were active
4743 @item @b{RUN/IDLE} ... don't assume this always means IDLE
4744 @item @b{DRSELECT}
4745 @item @b{DRCAPTURE}
4746 @item @b{DRSHIFT} ... TDI/TDO shifting through the data register
4747 @item @b{DREXIT1}
4748 @item @b{DRPAUSE} ... data register ready for update or more shifting
4749 @item @b{DREXIT2}
4750 @item @b{DRUPDATE}
4751 @item @b{IRSELECT}
4752 @item @b{IRCAPTURE}
4753 @item @b{IRSHIFT} ... TDI/TDO shifting through the instruction register
4754 @item @b{IREXIT1}
4755 @item @b{IRPAUSE} ... instruction register ready for update or more shifting
4756 @item @b{IREXIT2}
4757 @item @b{IRUPDATE}
4758 @end itemize
4759
4760 Note that only six of those states are fully ``stable'' in the
4761 face of TMS fixed (usually low)
4762 and a free-running JTAG clock. For all the
4763 others, the next TCK transition changes to a new state.
4764
4765 @itemize @bullet
4766 @item From @sc{drshift} and @sc{irshift}, clock transitions will
4767 produce side effects by changing register contents. The values
4768 to be latched in upcoming @sc{drupdate} or @sc{irupdate} states
4769 may not be as expected.
4770 @item @sc{run/idle}, @sc{drpause}, and @sc{irpause} are reasonable
4771 choices after @command{drscan} or @command{irscan} commands,
4772 since they are free of JTAG side effects.
4773 However, @sc{run/idle} may have side effects that appear at other
4774 levels, such as advancing the ARM9E-S instruction pipeline.
4775 Consult the documentation for the TAP(s) you are working with.
4776 @end itemize
4777
4778 @node TFTP
4779 @chapter TFTP
4780 @cindex TFTP
4781 If OpenOCD runs on an embedded host(as ZY1000 does), then TFTP can
4782 be used to access files on PCs (either the developer's PC or some other PC).
4783
4784 The way this works on the ZY1000 is to prefix a filename by
4785 "/tftp/ip/" and append the TFTP path on the TFTP
4786 server (tftpd). For example,
4787
4788 @example
4789 load_image /tftp/10.0.0.96/c:\temp\abc.elf
4790 @end example
4791
4792 will load c:\temp\abc.elf from the developer pc (10.0.0.96) into memory as
4793 if the file was hosted on the embedded host.
4794
4795 In order to achieve decent performance, you must choose a TFTP server
4796 that supports a packet size bigger than the default packet size (512 bytes). There
4797 are numerous TFTP servers out there (free and commercial) and you will have to do
4798 a bit of googling to find something that fits your requirements.
4799
4800 @node Sample Scripts
4801 @chapter Sample Scripts
4802 @cindex scripts
4803
4804 This page shows how to use the Target Library.
4805
4806 The configuration script can be divided into the following sections:
4807 @itemize @bullet
4808 @item Daemon configuration
4809 @item Interface
4810 @item JTAG scan chain
4811 @item Target configuration
4812 @item Flash configuration
4813 @end itemize
4814
4815 Detailed information about each section can be found at OpenOCD configuration.
4816
4817 @section AT91R40008 example
4818 @cindex AT91R40008 example
4819 To start OpenOCD with a target script for the AT91R40008 CPU and reset
4820 the CPU upon startup of the OpenOCD daemon.
4821 @example
4822 openocd -f interface/parport.cfg -f target/at91r40008.cfg \
4823 -c "init" -c "reset"
4824 @end example
4825
4826
4827 @node GDB and OpenOCD
4828 @chapter GDB and OpenOCD
4829 @cindex GDB
4830 OpenOCD complies with the remote gdbserver protocol, and as such can be used
4831 to debug remote targets.
4832
4833 @anchor{Connecting to GDB}
4834 @section Connecting to GDB
4835 @cindex Connecting to GDB
4836 Use GDB 6.7 or newer with OpenOCD if you run into trouble. For
4837 instance GDB 6.3 has a known bug that produces bogus memory access
4838 errors, which has since been fixed: look up 1836 in
4839 @url{http://sourceware.org/cgi-bin/gnatsweb.pl?database=gdb}
4840
4841 OpenOCD can communicate with GDB in two ways:
4842
4843 @enumerate
4844 @item
4845 A socket (TCP/IP) connection is typically started as follows:
4846 @example
4847 target remote localhost:3333
4848 @end example
4849 This would cause GDB to connect to the gdbserver on the local pc using port 3333.
4850 @item
4851 A pipe connection is typically started as follows:
4852 @example
4853 target remote | openocd --pipe
4854 @end example
4855 This would cause GDB to run OpenOCD and communicate using pipes (stdin/stdout).
4856 Using this method has the advantage of GDB starting/stopping OpenOCD for the debug
4857 session.
4858 @end enumerate
4859
4860 To list the available OpenOCD commands type @command{monitor help} on the
4861 GDB command line.
4862
4863 OpenOCD supports the gdb @option{qSupported} packet, this enables information
4864 to be sent by the GDB remote server (i.e. OpenOCD) to GDB. Typical information includes
4865 packet size and the device's memory map.
4866
4867 Previous versions of OpenOCD required the following GDB options to increase
4868 the packet size and speed up GDB communication:
4869 @example
4870 set remote memory-write-packet-size 1024
4871 set remote memory-write-packet-size fixed
4872 set remote memory-read-packet-size 1024
4873 set remote memory-read-packet-size fixed
4874 @end example
4875 This is now handled in the @option{qSupported} PacketSize and should not be required.
4876
4877 @section Programming using GDB
4878 @cindex Programming using GDB
4879
4880 By default the target memory map is sent to GDB. This can be disabled by
4881 the following OpenOCD configuration option:
4882 @example
4883 gdb_memory_map disable
4884 @end example
4885 For this to function correctly a valid flash configuration must also be set
4886 in OpenOCD. For faster performance you should also configure a valid
4887 working area.
4888
4889 Informing GDB of the memory map of the target will enable GDB to protect any
4890 flash areas of the target and use hardware breakpoints by default. This means
4891 that the OpenOCD option @command{gdb_breakpoint_override} is not required when
4892 using a memory map. @xref{gdb_breakpoint_override}.
4893
4894 To view the configured memory map in GDB, use the GDB command @option{info mem}
4895 All other unassigned addresses within GDB are treated as RAM.
4896
4897 GDB 6.8 and higher set any memory area not in the memory map as inaccessible.
4898 This can be changed to the old behaviour by using the following GDB command
4899 @example
4900 set mem inaccessible-by-default off
4901 @end example
4902
4903 If @command{gdb_flash_program enable} is also used, GDB will be able to
4904 program any flash memory using the vFlash interface.
4905
4906 GDB will look at the target memory map when a load command is given, if any
4907 areas to be programmed lie within the target flash area the vFlash packets
4908 will be used.
4909
4910 If the target needs configuring before GDB programming, an event
4911 script can be executed:
4912 @example
4913 $_TARGETNAME configure -event EVENTNAME BODY
4914 @end example
4915
4916 To verify any flash programming the GDB command @option{compare-sections}
4917 can be used.
4918
4919 @node Tcl Scripting API
4920 @chapter Tcl Scripting API
4921 @cindex Tcl Scripting API
4922 @cindex Tcl scripts
4923 @section API rules
4924
4925 The commands are stateless. E.g. the telnet command line has a concept
4926 of currently active target, the Tcl API proc's take this sort of state
4927 information as an argument to each proc.
4928
4929 There are three main types of return values: single value, name value
4930 pair list and lists.
4931
4932 Name value pair. The proc 'foo' below returns a name/value pair
4933 list.
4934
4935 @verbatim
4936
4937 > set foo(me) Duane
4938 > set foo(you) Oyvind
4939 > set foo(mouse) Micky
4940 > set foo(duck) Donald
4941
4942 If one does this:
4943
4944 > set foo
4945
4946 The result is:
4947
4948 me Duane you Oyvind mouse Micky duck Donald
4949
4950 Thus, to get the names of the associative array is easy:
4951
4952 foreach { name value } [set foo] {
4953 puts "Name: $name, Value: $value"
4954 }
4955 @end verbatim
4956
4957 Lists returned must be relatively small. Otherwise a range
4958 should be passed in to the proc in question.
4959
4960 @section Internal low-level Commands
4961
4962 By low-level, the intent is a human would not directly use these commands.
4963
4964 Low-level commands are (should be) prefixed with "ocd_", e.g.
4965 @command{ocd_flash_banks}
4966 is the low level API upon which @command{flash banks} is implemented.
4967
4968 @itemize @bullet
4969 @item @b{ocd_mem2array} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}>
4970
4971 Read memory and return as a Tcl array for script processing
4972 @item @b{ocd_array2mem} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}>
4973
4974 Convert a Tcl array to memory locations and write the values
4975 @item @b{ocd_flash_banks} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}> <@var{target}> [@option{driver options} ...]
4976
4977 Return information about the flash banks
4978 @end itemize
4979
4980 OpenOCD commands can consist of two words, e.g. "flash banks". The
4981 startup.tcl "unknown" proc will translate this into a Tcl proc
4982 called "flash_banks".
4983
4984 @section OpenOCD specific Global Variables
4985
4986 @subsection HostOS
4987
4988 Real Tcl has ::tcl_platform(), and platform::identify, and many other
4989 variables. JimTCL, as implemented in OpenOCD creates $HostOS which
4990 holds one of the following values:
4991
4992 @itemize @bullet
4993 @item @b{winxx} Built using Microsoft Visual Studio
4994 @item @b{linux} Linux is the underlying operating sytem
4995 @item @b{darwin} Darwin (mac-os) is the underlying operating sytem.
4996 @item @b{cygwin} Running under Cygwin
4997 @item @b{mingw32} Running under MingW32
4998 @item @b{other} Unknown, none of the above.
4999 @end itemize
5000
5001 Note: 'winxx' was choosen because today (March-2009) no distinction is made between Win32 and Win64.
5002
5003 @quotation Note
5004 We should add support for a variable like Tcl variable
5005 @code{tcl_platform(platform)}, it should be called
5006 @code{jim_platform} (because it
5007 is jim, not real tcl).
5008 @end quotation
5009
5010 @node Upgrading
5011 @chapter Deprecated/Removed Commands
5012 @cindex Deprecated/Removed Commands
5013 Certain OpenOCD commands have been deprecated or
5014 removed during the various revisions.
5015
5016 Upgrade your scripts as soon as possible.
5017 These descriptions for old commands may be removed
5018 a year after the command itself was removed.
5019 This means that in January 2010 this chapter may
5020 become much shorter.
5021
5022 @itemize @bullet
5023 @item @b{arm7_9 fast_writes}
5024 @cindex arm7_9 fast_writes
5025 @*Use @command{arm7_9 fast_memory_access} instead.
5026 @item @b{endstate}
5027 @cindex endstate
5028 @*An buggy old command that would not really work since background polling would wipe out the global endstate
5029 @xref{arm7_9 fast_memory_access}.
5030 @item @b{arm7_9 force_hw_bkpts}
5031 @*Use @command{gdb_breakpoint_override} instead. Note that GDB will use hardware breakpoints
5032 for flash if the GDB memory map has been set up(default when flash is declared in
5033 target configuration). @xref{gdb_breakpoint_override}.
5034 @item @b{arm7_9 sw_bkpts}
5035 @*On by default. @xref{gdb_breakpoint_override}.
5036 @item @b{daemon_startup}
5037 @*this config option has been removed, simply adding @option{init} and @option{reset halt} to
5038 the end of your config script will give the same behaviour as using @option{daemon_startup reset}
5039 and @option{target cortex_m3 little reset_halt 0}.
5040 @item @b{dump_binary}
5041 @*use @option{dump_image} command with same args. @xref{dump_image}.
5042 @item @b{flash erase}
5043 @*use @option{flash erase_sector} command with same args. @xref{flash erase_sector}.
5044 @item @b{flash write}
5045 @*use @option{flash write_bank} command with same args. @xref{flash write_bank}.
5046 @item @b{flash write_binary}
5047 @*use @option{flash write_bank} command with same args. @xref{flash write_bank}.
5048 @item @b{flash auto_erase}
5049 @*use @option{flash write_image} command passing @option{erase} as the first parameter. @xref{flash write_image}.
5050
5051 @item @b{jtag_device}
5052 @*use the @command{jtag newtap} command, converting from positional syntax
5053 to named prefixes, and naming the TAP.
5054 @xref{jtag newtap}.
5055 Note that if you try to use the old command, a message will tell you the
5056 right new command to use; and that the fourth parameter in the old syntax
5057 was never actually used.
5058 @example
5059 OLD: jtag_device 8 0x01 0xe3 0xfe
5060 NEW: jtag newtap CHIPNAME TAPNAME \
5061 -irlen 8 -ircapture 0x01 -irmask 0xe3
5062 @end example
5063
5064 @item @b{jtag_speed} value
5065 @*@xref{JTAG Speed}.
5066 Usually, a value of zero means maximum
5067 speed. The actual effect of this option depends on the JTAG interface used.
5068 @itemize @minus
5069 @item wiggler: maximum speed / @var{number}
5070 @item ft2232: 6MHz / (@var{number}+1)
5071 @item amt jtagaccel: 8 / 2**@var{number}
5072 @item jlink: maximum speed in kHz (0-12000), 0 will use RTCK
5073 @item rlink: 24MHz / @var{number}, but only for certain values of @var{number}
5074 @comment end speed list.
5075 @end itemize
5076
5077 @item @b{load_binary}
5078 @*use @option{load_image} command with same args. @xref{load_image}.
5079 @item @b{run_and_halt_time}
5080 @*This command has been removed for simpler reset behaviour, it can be simulated with the
5081 following commands:
5082 @smallexample
5083 reset run
5084 sleep 100
5085 halt
5086 @end smallexample
5087 @item @b{target} <@var{type}> <@var{endian}> <@var{jtag-position}>
5088 @*use the create subcommand of @option{target}.
5089 @item @b{target_script} <@var{target#}> <@var{eventname}> <@var{scriptname}>
5090 @*use <@var{target_name}> configure -event <@var{eventname}> "script <@var{scriptname}>"
5091 @item @b{working_area}
5092 @*use the @option{configure} subcommand of @option{target} to set the work-area-virt, work-area-phy, work-area-size, and work-area-backup properties of the target.
5093 @end itemize
5094
5095 @node FAQ
5096 @chapter FAQ
5097 @cindex faq
5098 @enumerate
5099 @anchor{FAQ RTCK}
5100 @item @b{RTCK, also known as: Adaptive Clocking - What is it?}
5101 @cindex RTCK
5102 @cindex adaptive clocking
5103 @*
5104
5105 In digital circuit design it is often refered to as ``clock
5106 synchronisation'' the JTAG interface uses one clock (TCK or TCLK)
5107 operating at some speed, your target is operating at another. The two
5108 clocks are not synchronised, they are ``asynchronous''
5109
5110 In order for the two to work together they must be synchronised. Otherwise
5111 the two systems will get out of sync with each other and nothing will
5112 work. There are 2 basic options:
5113 @enumerate
5114 @item
5115 Use a special circuit.
5116 @item
5117 One clock must be some multiple slower than the other.
5118 @end enumerate
5119
5120 @b{Does this really matter?} For some chips and some situations, this
5121 is a non-issue (i.e.: A 500MHz ARM926) but for others - for example some
5122 Atmel SAM7 and SAM9 chips start operation from reset at 32kHz -
5123 program/enable the oscillators and eventually the main clock. It is in
5124 those critical times you must slow the JTAG clock to sometimes 1 to
5125 4kHz.
5126
5127 Imagine debugging a 500MHz ARM926 hand held battery powered device
5128 that ``deep sleeps'' at 32kHz between every keystroke. It can be
5129 painful.
5130
5131 @b{Solution #1 - A special circuit}
5132
5133 In order to make use of this, your JTAG dongle must support the RTCK
5134 feature. Not all dongles support this - keep reading!
5135
5136 The RTCK signal often found in some ARM chips is used to help with
5137 this problem. ARM has a good description of the problem described at
5138 this link: @url{http://www.arm.com/support/faqdev/4170.html} [checked
5139 28/nov/2008]. Link title: ``How does the JTAG synchronisation logic
5140 work? / how does adaptive clocking work?''.
5141
5142 The nice thing about adaptive clocking is that ``battery powered hand
5143 held device example'' - the adaptiveness works perfectly all the
5144 time. One can set a break point or halt the system in the deep power
5145 down code, slow step out until the system speeds up.
5146
5147 @b{Solution #2 - Always works - but may be slower}
5148
5149 Often this is a perfectly acceptable solution.
5150
5151 In most simple terms: Often the JTAG clock must be 1/10 to 1/12 of
5152 the target clock speed. But what that ``magic division'' is varies
5153 depending on the chips on your board. @b{ARM rule of thumb} Most ARM
5154 based systems require an 8:1 division. @b{Xilinx rule of thumb} is
5155 1/12 the clock speed.
5156
5157 Note: Many FTDI2232C based JTAG dongles are limited to 6MHz.
5158
5159 You can still debug the 'low power' situations - you just need to
5160 manually adjust the clock speed at every step. While painful and
5161 tedious, it is not always practical.
5162
5163 It is however easy to ``code your way around it'' - i.e.: Cheat a little,
5164 have a special debug mode in your application that does a ``high power
5165 sleep''. If you are careful - 98% of your problems can be debugged
5166 this way.
5167
5168 To set the JTAG frequency use the command:
5169
5170 @example
5171 # Example: 1.234MHz
5172 jtag_khz 1234
5173 @end example
5174
5175
5176 @item @b{Win32 Pathnames} Why don't backslashes work in Windows paths?
5177
5178 OpenOCD uses Tcl and a backslash is an escape char. Use @{ and @}
5179 around Windows filenames.
5180
5181 @example
5182 > echo \a
5183
5184 > echo @{\a@}
5185 \a
5186 > echo "\a"
5187
5188 >
5189 @end example
5190
5191
5192 @item @b{Missing: cygwin1.dll} OpenOCD complains about a missing cygwin1.dll.
5193
5194 Make sure you have Cygwin installed, or at least a version of OpenOCD that
5195 claims to come with all the necessary DLLs. When using Cygwin, try launching
5196 OpenOCD from the Cygwin shell.
5197
5198 @item @b{Breakpoint Issue} I'm trying to set a breakpoint using GDB (or a frontend like Insight or
5199 Eclipse), but OpenOCD complains that "Info: arm7_9_common.c:213
5200 arm7_9_add_breakpoint(): sw breakpoint requested, but software breakpoints not enabled".
5201
5202 GDB issues software breakpoints when a normal breakpoint is requested, or to implement
5203 source-line single-stepping. On ARMv4T systems, like ARM7TDMI, ARM720T or ARM920T,
5204 software breakpoints consume one of the two available hardware breakpoints.
5205
5206 @item @b{LPC2000 Flash} When erasing or writing LPC2000 on-chip flash, the operation fails at random.
5207
5208 Make sure the core frequency specified in the @option{flash lpc2000} line matches the
5209 clock at the time you're programming the flash. If you've specified the crystal's
5210 frequency, make sure the PLL is disabled. If you've specified the full core speed
5211 (e.g. 60MHz), make sure the PLL is enabled.
5212
5213 @item @b{Amontec Chameleon} When debugging using an Amontec Chameleon in its JTAG Accelerator configuration,
5214 I keep getting "Error: amt_jtagaccel.c:184 amt_wait_scan_busy(): amt_jtagaccel timed
5215 out while waiting for end of scan, rtck was disabled".
5216
5217 Make sure your PC's parallel port operates in EPP mode. You might have to try several
5218 settings in your PC BIOS (ECP, EPP, and different versions of those).
5219
5220 @item @b{Data Aborts} When debugging with OpenOCD and GDB (plain GDB, Insight, or Eclipse),
5221 I get lots of "Error: arm7_9_common.c:1771 arm7_9_read_memory():
5222 memory read caused data abort".
5223
5224 The errors are non-fatal, and are the result of GDB trying to trace stack frames
5225 beyond the last valid frame. It might be possible to prevent this by setting up
5226 a proper "initial" stack frame, if you happen to know what exactly has to
5227 be done, feel free to add this here.
5228
5229 @b{Simple:} In your startup code - push 8 registers of zeros onto the
5230 stack before calling main(). What GDB is doing is ``climbing'' the run
5231 time stack by reading various values on the stack using the standard
5232 call frame for the target. GDB keeps going - until one of 2 things
5233 happen @b{#1} an invalid frame is found, or @b{#2} some huge number of
5234 stackframes have been processed. By pushing zeros on the stack, GDB
5235 gracefully stops.
5236
5237 @b{Debugging Interrupt Service Routines} - In your ISR before you call
5238 your C code, do the same - artifically push some zeros onto the stack,
5239 remember to pop them off when the ISR is done.
5240
5241 @b{Also note:} If you have a multi-threaded operating system, they
5242 often do not @b{in the intrest of saving memory} waste these few
5243 bytes. Painful...
5244
5245
5246 @item @b{JTAG Reset Config} I get the following message in the OpenOCD console (or log file):
5247 "Warning: arm7_9_common.c:679 arm7_9_assert_reset(): srst resets test logic, too".
5248
5249 This warning doesn't indicate any serious problem, as long as you don't want to
5250 debug your core right out of reset. Your .cfg file specified @option{jtag_reset
5251 trst_and_srst srst_pulls_trst} to tell OpenOCD that either your board,
5252 your debugger or your target uC (e.g. LPC2000) can't assert the two reset signals
5253 independently. With this setup, it's not possible to halt the core right out of
5254 reset, everything else should work fine.
5255
5256 @item @b{USB Power} When using OpenOCD in conjunction with Amontec JTAGkey and the Yagarto
5257 toolchain (Eclipse, arm-elf-gcc, arm-elf-gdb), the debugging seems to be
5258 unstable. When single-stepping over large blocks of code, GDB and OpenOCD
5259 quit with an error message. Is there a stability issue with OpenOCD?
5260
5261 No, this is not a stability issue concerning OpenOCD. Most users have solved
5262 this issue by simply using a self-powered USB hub, which they connect their
5263 Amontec JTAGkey to. Apparently, some computers do not provide a USB power
5264 supply stable enough for the Amontec JTAGkey to be operated.
5265
5266 @b{Laptops running on battery have this problem too...}
5267
5268 @item @b{USB Power} When using the Amontec JTAGkey, sometimes OpenOCD crashes with the
5269 following error messages: "Error: ft2232.c:201 ft2232_read(): FT_Read returned:
5270 4" and "Error: ft2232.c:365 ft2232_send_and_recv(): couldn't read from FT2232".
5271 What does that mean and what might be the reason for this?
5272
5273 First of all, the reason might be the USB power supply. Try using a self-powered
5274 hub instead of a direct connection to your computer. Secondly, the error code 4
5275 corresponds to an FT_IO_ERROR, which means that the driver for the FTDI USB
5276 chip ran into some sort of error - this points us to a USB problem.
5277
5278 @item @b{GDB Disconnects} When using the Amontec JTAGkey, sometimes OpenOCD crashes with the following
5279 error message: "Error: gdb_server.c:101 gdb_get_char(): read: 10054".
5280 What does that mean and what might be the reason for this?
5281
5282 Error code 10054 corresponds to WSAECONNRESET, which means that the debugger (GDB)
5283 has closed the connection to OpenOCD. This might be a GDB issue.
5284
5285 @item @b{LPC2000 Flash} In the configuration file in the section where flash device configurations
5286 are described, there is a parameter for specifying the clock frequency
5287 for LPC2000 internal flash devices (e.g. @option{flash bank lpc2000
5288 0x0 0x40000 0 0 0 lpc2000_v1 14746 calc_checksum}), which must be
5289 specified in kilohertz. However, I do have a quartz crystal of a
5290 frequency that contains fractions of kilohertz (e.g. 14,745,600 Hz,
5291 i.e. 14,745.600 kHz). Is it possible to specify real numbers for the
5292 clock frequency?
5293
5294 No. The clock frequency specified here must be given as an integral number.
5295 However, this clock frequency is used by the In-Application-Programming (IAP)
5296 routines of the LPC2000 family only, which seems to be very tolerant concerning
5297 the given clock frequency, so a slight difference between the specified clock
5298 frequency and the actual clock frequency will not cause any trouble.
5299
5300 @item @b{Command Order} Do I have to keep a specific order for the commands in the configuration file?
5301
5302 Well, yes and no. Commands can be given in arbitrary order, yet the
5303 devices listed for the JTAG scan chain must be given in the right
5304 order (jtag newdevice), with the device closest to the TDO-Pin being
5305 listed first. In general, whenever objects of the same type exist
5306 which require an index number, then these objects must be given in the
5307 right order (jtag newtap, targets and flash banks - a target
5308 references a jtag newtap and a flash bank references a target).
5309
5310 You can use the ``scan_chain'' command to verify and display the tap order.
5311
5312 Also, some commands can't execute until after @command{init} has been
5313 processed. Such commands include @command{nand probe} and everything
5314 else that needs to write to controller registers, perhaps for setting
5315 up DRAM and loading it with code.
5316
5317 @anchor{FAQ TAP Order}
5318 @item @b{JTAG TAP Order} Do I have to declare the TAPS in some
5319 particular order?
5320
5321 Yes; whenever you have more than one, you must declare them in
5322 the same order used by the hardware.
5323
5324 Many newer devices have multiple JTAG TAPs. For example: ST
5325 Microsystems STM32 chips have two TAPs, a ``boundary scan TAP'' and
5326 ``Cortex-M3'' TAP. Example: The STM32 reference manual, Document ID:
5327 RM0008, Section 26.5, Figure 259, page 651/681, the ``TDI'' pin is
5328 connected to the boundary scan TAP, which then connects to the
5329 Cortex-M3 TAP, which then connects to the TDO pin.
5330
5331 Thus, the proper order for the STM32 chip is: (1) The Cortex-M3, then
5332 (2) The boundary scan TAP. If your board includes an additional JTAG
5333 chip in the scan chain (for example a Xilinx CPLD or FPGA) you could
5334 place it before or after the STM32 chip in the chain. For example:
5335
5336 @itemize @bullet
5337 @item OpenOCD_TDI(output) -> STM32 TDI Pin (BS Input)
5338 @item STM32 BS TDO (output) -> STM32 Cortex-M3 TDI (input)
5339 @item STM32 Cortex-M3 TDO (output) -> SM32 TDO Pin
5340 @item STM32 TDO Pin (output) -> Xilinx TDI Pin (input)
5341 @item Xilinx TDO Pin -> OpenOCD TDO (input)
5342 @end itemize
5343
5344 The ``jtag device'' commands would thus be in the order shown below. Note:
5345
5346 @itemize @bullet
5347 @item jtag newtap Xilinx tap -irlen ...
5348 @item jtag newtap stm32 cpu -irlen ...
5349 @item jtag newtap stm32 bs -irlen ...
5350 @item # Create the debug target and say where it is
5351 @item target create stm32.cpu -chain-position stm32.cpu ...
5352 @end itemize
5353
5354
5355 @item @b{SYSCOMP} Sometimes my debugging session terminates with an error. When I look into the
5356 log file, I can see these error messages: Error: arm7_9_common.c:561
5357 arm7_9_execute_sys_speed(): timeout waiting for SYSCOMP
5358
5359 TODO.
5360
5361 @end enumerate
5362
5363 @node Tcl Crash Course
5364 @chapter Tcl Crash Course
5365 @cindex Tcl
5366
5367 Not everyone knows Tcl - this is not intended to be a replacement for
5368 learning Tcl, the intent of this chapter is to give you some idea of
5369 how the Tcl scripts work.
5370
5371 This chapter is written with two audiences in mind. (1) OpenOCD users
5372 who need to understand a bit more of how JIM-Tcl works so they can do
5373 something useful, and (2) those that want to add a new command to
5374 OpenOCD.
5375
5376 @section Tcl Rule #1
5377 There is a famous joke, it goes like this:
5378 @enumerate
5379 @item Rule #1: The wife is always correct
5380 @item Rule #2: If you think otherwise, See Rule #1
5381 @end enumerate
5382
5383 The Tcl equal is this:
5384
5385 @enumerate
5386 @item Rule #1: Everything is a string
5387 @item Rule #2: If you think otherwise, See Rule #1
5388 @end enumerate
5389
5390 As in the famous joke, the consequences of Rule #1 are profound. Once
5391 you understand Rule #1, you will understand Tcl.
5392
5393 @section Tcl Rule #1b
5394 There is a second pair of rules.
5395 @enumerate
5396 @item Rule #1: Control flow does not exist. Only commands
5397 @* For example: the classic FOR loop or IF statement is not a control
5398 flow item, they are commands, there is no such thing as control flow
5399 in Tcl.
5400 @item Rule #2: If you think otherwise, See Rule #1
5401 @* Actually what happens is this: There are commands that by
5402 convention, act like control flow key words in other languages. One of
5403 those commands is the word ``for'', another command is ``if''.
5404 @end enumerate
5405
5406 @section Per Rule #1 - All Results are strings
5407 Every Tcl command results in a string. The word ``result'' is used
5408 deliberatly. No result is just an empty string. Remember: @i{Rule #1 -
5409 Everything is a string}
5410
5411 @section Tcl Quoting Operators
5412 In life of a Tcl script, there are two important periods of time, the
5413 difference is subtle.
5414 @enumerate
5415 @item Parse Time
5416 @item Evaluation Time
5417 @end enumerate
5418
5419 The two key items here are how ``quoted things'' work in Tcl. Tcl has
5420 three primary quoting constructs, the [square-brackets] the
5421 @{curly-braces@} and ``double-quotes''
5422
5423 By now you should know $VARIABLES always start with a $DOLLAR
5424 sign. BTW: To set a variable, you actually use the command ``set'', as
5425 in ``set VARNAME VALUE'' much like the ancient BASIC langauge ``let x
5426 = 1'' statement, but without the equal sign.
5427
5428 @itemize @bullet
5429 @item @b{[square-brackets]}
5430 @* @b{[square-brackets]} are command substitutions. It operates much
5431 like Unix Shell `back-ticks`. The result of a [square-bracket]
5432 operation is exactly 1 string. @i{Remember Rule #1 - Everything is a
5433 string}. These two statements are roughly identical:
5434 @example
5435 # bash example
5436 X=`date`
5437 echo "The Date is: $X"
5438 # Tcl example
5439 set X [date]
5440 puts "The Date is: $X"
5441 @end example
5442 @item @b{``double-quoted-things''}
5443 @* @b{``double-quoted-things''} are just simply quoted
5444 text. $VARIABLES and [square-brackets] are expanded in place - the
5445 result however is exactly 1 string. @i{Remember Rule #1 - Everything
5446 is a string}
5447 @example
5448 set x "Dinner"
5449 puts "It is now \"[date]\", $x is in 1 hour"
5450 @end example
5451 @item @b{@{Curly-Braces@}}
5452 @*@b{@{Curly-Braces@}} are magic: $VARIABLES and [square-brackets] are
5453 parsed, but are NOT expanded or executed. @{Curly-Braces@} are like
5454 'single-quote' operators in BASH shell scripts, with the added
5455 feature: @{curly-braces@} can be nested, single quotes can not. @{@{@{this is
5456 nested 3 times@}@}@} NOTE: [date] is perhaps a bad example, as of
5457 28/nov/2008, Jim/OpenOCD does not have a date command.
5458 @end itemize
5459
5460 @section Consequences of Rule 1/2/3/4
5461
5462 The consequences of Rule 1 are profound.
5463
5464 @subsection Tokenisation & Execution.
5465
5466 Of course, whitespace, blank lines and #comment lines are handled in
5467 the normal way.
5468
5469 As a script is parsed, each (multi) line in the script file is
5470 tokenised and according to the quoting rules. After tokenisation, that
5471 line is immedatly executed.
5472
5473 Multi line statements end with one or more ``still-open''
5474 @{curly-braces@} which - eventually - closes a few lines later.
5475
5476 @subsection Command Execution
5477
5478 Remember earlier: There are no ``control flow''
5479 statements in Tcl. Instead there are COMMANDS that simply act like
5480 control flow operators.
5481
5482 Commands are executed like this:
5483
5484 @enumerate
5485 @item Parse the next line into (argc) and (argv[]).
5486 @item Look up (argv[0]) in a table and call its function.
5487 @item Repeat until End Of File.
5488 @end enumerate
5489
5490 It sort of works like this:
5491 @example
5492 for(;;)@{
5493 ReadAndParse( &argc, &argv );
5494
5495 cmdPtr = LookupCommand( argv[0] );
5496
5497 (*cmdPtr->Execute)( argc, argv );
5498 @}
5499 @end example
5500
5501 When the command ``proc'' is parsed (which creates a procedure
5502 function) it gets 3 parameters on the command line. @b{1} the name of
5503 the proc (function), @b{2} the list of parameters, and @b{3} the body
5504 of the function. Not the choice of words: LIST and BODY. The PROC
5505 command stores these items in a table somewhere so it can be found by
5506 ``LookupCommand()''
5507
5508 @subsection The FOR command
5509
5510 The most interesting command to look at is the FOR command. In Tcl,
5511 the FOR command is normally implemented in C. Remember, FOR is a
5512 command just like any other command.
5513
5514 When the ascii text containing the FOR command is parsed, the parser
5515 produces 5 parameter strings, @i{(If in doubt: Refer to Rule #1)} they
5516 are:
5517
5518 @enumerate 0
5519 @item The ascii text 'for'
5520 @item The start text
5521 @item The test expression
5522 @item The next text
5523 @item The body text
5524 @end enumerate
5525
5526 Sort of reminds you of ``main( int argc, char **argv )'' does it not?
5527 Remember @i{Rule #1 - Everything is a string.} The key point is this:
5528 Often many of those parameters are in @{curly-braces@} - thus the
5529 variables inside are not expanded or replaced until later.
5530
5531 Remember that every Tcl command looks like the classic ``main( argc,
5532 argv )'' function in C. In JimTCL - they actually look like this:
5533
5534 @example
5535 int
5536 MyCommand( Jim_Interp *interp,
5537 int *argc,
5538 Jim_Obj * const *argvs );
5539 @end example
5540
5541 Real Tcl is nearly identical. Although the newer versions have
5542 introduced a byte-code parser and intepreter, but at the core, it
5543 still operates in the same basic way.
5544
5545 @subsection FOR command implementation
5546
5547 To understand Tcl it is perhaps most helpful to see the FOR
5548 command. Remember, it is a COMMAND not a control flow structure.
5549
5550 In Tcl there are two underlying C helper functions.
5551
5552 Remember Rule #1 - You are a string.
5553
5554 The @b{first} helper parses and executes commands found in an ascii
5555 string. Commands can be seperated by semicolons, or newlines. While
5556 parsing, variables are expanded via the quoting rules.
5557
5558 The @b{second} helper evaluates an ascii string as a numerical
5559 expression and returns a value.
5560
5561 Here is an example of how the @b{FOR} command could be
5562 implemented. The pseudo code below does not show error handling.
5563 @example
5564 void Execute_AsciiString( void *interp, const char *string );
5565
5566 int Evaluate_AsciiExpression( void *interp, const char *string );
5567
5568 int
5569 MyForCommand( void *interp,
5570 int argc,
5571 char **argv )
5572 @{
5573 if( argc != 5 )@{
5574 SetResult( interp, "WRONG number of parameters");
5575 return ERROR;
5576 @}
5577
5578 // argv[0] = the ascii string just like C
5579
5580 // Execute the start statement.
5581 Execute_AsciiString( interp, argv[1] );
5582
5583 // Top of loop test
5584 for(;;)@{
5585 i = Evaluate_AsciiExpression(interp, argv[2]);
5586 if( i == 0 )
5587 break;
5588
5589 // Execute the body
5590 Execute_AsciiString( interp, argv[3] );
5591
5592 // Execute the LOOP part
5593 Execute_AsciiString( interp, argv[4] );
5594 @}
5595
5596 // Return no error
5597 SetResult( interp, "" );
5598 return SUCCESS;
5599 @}
5600 @end example
5601
5602 Every other command IF, WHILE, FORMAT, PUTS, EXPR, everything works
5603 in the same basic way.
5604
5605 @section OpenOCD Tcl Usage
5606
5607 @subsection source and find commands
5608 @b{Where:} In many configuration files
5609 @* Example: @b{ source [find FILENAME] }
5610 @*Remember the parsing rules
5611 @enumerate
5612 @item The FIND command is in square brackets.
5613 @* The FIND command is executed with the parameter FILENAME. It should
5614 find the full path to the named file. The RESULT is a string, which is
5615 substituted on the orginal command line.
5616 @item The command source is executed with the resulting filename.
5617 @* SOURCE reads a file and executes as a script.
5618 @end enumerate
5619 @subsection format command
5620 @b{Where:} Generally occurs in numerous places.
5621 @* Tcl has no command like @b{printf()}, instead it has @b{format}, which is really more like
5622 @b{sprintf()}.
5623 @b{Example}
5624 @example
5625 set x 6
5626 set y 7
5627 puts [format "The answer: %d" [expr $x * $y]]
5628 @end example
5629 @enumerate
5630 @item The SET command creates 2 variables, X and Y.
5631 @item The double [nested] EXPR command performs math
5632 @* The EXPR command produces numerical result as a string.
5633 @* Refer to Rule #1
5634 @item The format command is executed, producing a single string
5635 @* Refer to Rule #1.
5636 @item The PUTS command outputs the text.
5637 @end enumerate
5638 @subsection Body or Inlined Text
5639 @b{Where:} Various TARGET scripts.
5640 @example
5641 #1 Good
5642 proc someproc @{@} @{
5643 ... multiple lines of stuff ...
5644 @}
5645 $_TARGETNAME configure -event FOO someproc
5646 #2 Good - no variables
5647 $_TARGETNAME confgure -event foo "this ; that;"
5648 #3 Good Curly Braces
5649 $_TARGETNAME configure -event FOO @{
5650 puts "Time: [date]"
5651 @}
5652 #4 DANGER DANGER DANGER
5653 $_TARGETNAME configure -event foo "puts \"Time: [date]\""
5654 @end example
5655 @enumerate
5656 @item The $_TARGETNAME is an OpenOCD variable convention.
5657 @*@b{$_TARGETNAME} represents the last target created, the value changes
5658 each time a new target is created. Remember the parsing rules. When
5659 the ascii text is parsed, the @b{$_TARGETNAME} becomes a simple string,
5660 the name of the target which happens to be a TARGET (object)
5661 command.
5662 @item The 2nd parameter to the @option{-event} parameter is a TCBODY
5663 @*There are 4 examples:
5664 @enumerate
5665 @item The TCLBODY is a simple string that happens to be a proc name
5666 @item The TCLBODY is several simple commands seperated by semicolons
5667 @item The TCLBODY is a multi-line @{curly-brace@} quoted string
5668 @item The TCLBODY is a string with variables that get expanded.
5669 @end enumerate
5670
5671 In the end, when the target event FOO occurs the TCLBODY is
5672 evaluated. Method @b{#1} and @b{#2} are functionally identical. For
5673 Method @b{#3} and @b{#4} it is more interesting. What is the TCLBODY?
5674
5675 Remember the parsing rules. In case #3, @{curly-braces@} mean the
5676 $VARS and [square-brackets] are expanded later, when the EVENT occurs,
5677 and the text is evaluated. In case #4, they are replaced before the
5678 ``Target Object Command'' is executed. This occurs at the same time
5679 $_TARGETNAME is replaced. In case #4 the date will never
5680 change. @{BTW: [date] is perhaps a bad example, as of 28/nov/2008,
5681 Jim/OpenOCD does not have a date command@}
5682 @end enumerate
5683 @subsection Global Variables
5684 @b{Where:} You might discover this when writing your own procs @* In
5685 simple terms: Inside a PROC, if you need to access a global variable
5686 you must say so. See also ``upvar''. Example:
5687 @example
5688 proc myproc @{ @} @{
5689 set y 0 #Local variable Y
5690 global x #Global variable X
5691 puts [format "X=%d, Y=%d" $x $y]
5692 @}
5693 @end example
5694 @section Other Tcl Hacks
5695 @b{Dynamic variable creation}
5696 @example
5697 # Dynamically create a bunch of variables.
5698 for @{ set x 0 @} @{ $x < 32 @} @{ set x [expr $x + 1]@} @{
5699 # Create var name
5700 set vn [format "BIT%d" $x]
5701 # Make it a global
5702 global $vn
5703 # Set it.
5704 set $vn [expr (1 << $x)]
5705 @}
5706 @end example
5707 @b{Dynamic proc/command creation}
5708 @example
5709 # One "X" function - 5 uart functions.
5710 foreach who @{A B C D E@}
5711 proc [format "show_uart%c" $who] @{ @} "show_UARTx $who"
5712 @}
5713 @end example
5714
5715 @node Target Library
5716 @chapter Target Library
5717 @cindex Target Library
5718
5719 OpenOCD comes with a target configuration script library. These scripts can be
5720 used as-is or serve as a starting point.
5721
5722 The target library is published together with the OpenOCD executable and
5723 the path to the target library is in the OpenOCD script search path.
5724 Similarly there are example scripts for configuring the JTAG interface.
5725
5726 The command line below uses the example parport configuration script
5727 that ship with OpenOCD, then configures the str710.cfg target and
5728 finally issues the init and reset commands. The communication speed
5729 is set to 10kHz for reset and 8MHz for post reset.
5730
5731 @example
5732 openocd -f interface/parport.cfg -f target/str710.cfg \
5733 -c "init" -c "reset"
5734 @end example
5735
5736 To list the target scripts available:
5737
5738 @example
5739 $ ls /usr/local/lib/openocd/target
5740
5741 arm7_fast.cfg lm3s6965.cfg pxa255.cfg stm32.cfg xba_revA3.cfg
5742 at91eb40a.cfg lpc2148.cfg pxa255_sst.cfg str710.cfg zy1000.cfg
5743 at91r40008.cfg lpc2294.cfg sam7s256.cfg str912.cfg
5744 at91sam9260.cfg nslu2.cfg sam7x256.cfg wi-9c.cfg
5745 @end example
5746
5747 @include fdl.texi
5748
5749 @node OpenOCD Concept Index
5750 @comment DO NOT use the plain word ``Index'', reason: CYGWIN filename
5751 @comment case issue with ``Index.html'' and ``index.html''
5752 @comment Occurs when creating ``--html --no-split'' output
5753 @comment This fix is based on: http://sourceware.org/ml/binutils/2006-05/msg00215.html
5754 @unnumbered OpenOCD Concept Index
5755
5756 @printindex cp
5757
5758 @node Command and Driver Index
5759 @unnumbered Command and Driver Index
5760 @printindex fn
5761
5762 @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)