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.
 
 
 
 
 
 

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