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.
 
 
 
 
 
 

6896 lines
249 KiB

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