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.

7583 lines
278 KiB

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