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.
 
 
 
 
 
 

6314 lines
228 KiB

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