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.
 
 
 
 
 
 

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