You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

7763 lines
285 KiB

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