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.
 
 
 
 
 
 

9813 lines
365 KiB

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