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.
 
 
 
 
 
 

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