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.
 
 
 
 
 
 

9784 lines
364 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, "disable"
  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
  3976. Print info about flash bank @var{num}
  3977. The @var{num} parameter is a value shown by @command{flash banks}.
  3978. This command will first query the hardware, it does not print cached
  3979. and possibly stale information.
  3980. @end deffn
  3981. @anchor{flashprotect}
  3982. @deffn Command {flash protect} num first last (@option{on}|@option{off})
  3983. Enable (@option{on}) or disable (@option{off}) protection of flash sectors
  3984. in flash bank @var{num}, starting at sector @var{first}
  3985. and continuing up to and including @var{last}.
  3986. Providing a @var{last} sector of @option{last}
  3987. specifies "to the end of the flash bank".
  3988. The @var{num} parameter is a value shown by @command{flash banks}.
  3989. @end deffn
  3990. @deffn Command {flash padded_value} num value
  3991. Sets the default value used for padding any image sections, This should
  3992. normally match the flash bank erased value. If not specified by this
  3993. comamnd or the flash driver then it defaults to 0xff.
  3994. @end deffn
  3995. @anchor{program}
  3996. @deffn Command {program} filename [verify] [reset] [exit] [offset]
  3997. This is a helper script that simplifies using OpenOCD as a standalone
  3998. programmer. The only required parameter is @option{filename}, the others are optional.
  3999. @xref{Flash Programming}.
  4000. @end deffn
  4001. @anchor{flashdriverlist}
  4002. @section Flash Driver List
  4003. As noted above, the @command{flash bank} command requires a driver name,
  4004. and allows driver-specific options and behaviors.
  4005. Some drivers also activate driver-specific commands.
  4006. @deffn {Flash Driver} virtual
  4007. This is a special driver that maps a previously defined bank to another
  4008. address. All bank settings will be copied from the master physical bank.
  4009. The @var{virtual} driver defines one mandatory parameters,
  4010. @itemize
  4011. @item @var{master_bank} The bank that this virtual address refers to.
  4012. @end itemize
  4013. So in the following example addresses 0xbfc00000 and 0x9fc00000 refer to
  4014. the flash bank defined at address 0x1fc00000. Any cmds executed on
  4015. the virtual banks are actually performed on the physical banks.
  4016. @example
  4017. flash bank $_FLASHNAME pic32mx 0x1fc00000 0 0 0 $_TARGETNAME
  4018. flash bank vbank0 virtual 0xbfc00000 0 0 0 $_TARGETNAME $_FLASHNAME
  4019. flash bank vbank1 virtual 0x9fc00000 0 0 0 $_TARGETNAME $_FLASHNAME
  4020. @end example
  4021. @end deffn
  4022. @subsection External Flash
  4023. @deffn {Flash Driver} cfi
  4024. @cindex Common Flash Interface
  4025. @cindex CFI
  4026. The ``Common Flash Interface'' (CFI) is the main standard for
  4027. external NOR flash chips, each of which connects to a
  4028. specific external chip select on the CPU.
  4029. Frequently the first such chip is used to boot the system.
  4030. Your board's @code{reset-init} handler might need to
  4031. configure additional chip selects using other commands (like: @command{mww} to
  4032. configure a bus and its timings), or
  4033. perhaps configure a GPIO pin that controls the ``write protect'' pin
  4034. on the flash chip.
  4035. The CFI driver can use a target-specific working area to significantly
  4036. speed up operation.
  4037. The CFI driver can accept the following optional parameters, in any order:
  4038. @itemize
  4039. @item @var{jedec_probe} ... is used to detect certain non-CFI flash ROMs,
  4040. like AM29LV010 and similar types.
  4041. @item @var{x16_as_x8} ... when a 16-bit flash is hooked up to an 8-bit bus.
  4042. @item @var{bus_swap} ... when data bytes in a 16-bit flash needs to be swapped.
  4043. @item @var{data_swap} ... when data bytes in a 16-bit flash needs to be
  4044. swapped when writing data values (ie. not CFI commands).
  4045. @end itemize
  4046. To configure two adjacent banks of 16 MBytes each, both sixteen bits (two bytes)
  4047. wide on a sixteen bit bus:
  4048. @example
  4049. flash bank $_FLASHNAME cfi 0x00000000 0x01000000 2 2 $_TARGETNAME
  4050. flash bank $_FLASHNAME cfi 0x01000000 0x01000000 2 2 $_TARGETNAME
  4051. @end example
  4052. To configure one bank of 32 MBytes
  4053. built from two sixteen bit (two byte) wide parts wired in parallel
  4054. to create a thirty-two bit (four byte) bus with doubled throughput:
  4055. @example
  4056. flash bank $_FLASHNAME cfi 0x00000000 0x02000000 2 4 $_TARGETNAME
  4057. @end example
  4058. @c "cfi part_id" disabled
  4059. @end deffn
  4060. @deffn {Flash Driver} jtagspi
  4061. @cindex Generic JTAG2SPI driver
  4062. @cindex SPI
  4063. @cindex jtagspi
  4064. @cindex bscan_spi
  4065. Several FPGAs and CPLDs can retrieve their configuration (bitstream) from a
  4066. SPI flash connected to them. To access this flash from the host, the device
  4067. is first programmed with a special proxy bitstream that
  4068. exposes the SPI flash on the device's JTAG interface. The flash can then be
  4069. accessed through JTAG.
  4070. Since signaling between JTAG and SPI is compatible, all that is required for
  4071. a proxy bitstream is to connect TDI-MOSI, TDO-MISO, TCK-CLK and activate
  4072. the flash chip select when the JTAG state machine is in SHIFT-DR. Such
  4073. a bitstream for several Xilinx FPGAs can be found in
  4074. @file{contrib/loaders/flash/fpga/xilinx_bscan_spi.py}. It requires migen
  4075. (@url{http://github.com/m-labs/migen}) and a Xilinx toolchain to build.
  4076. This flash bank driver requires a target on a JTAG tap and will access that
  4077. tap directly. Since no support from the target is needed, the target can be a
  4078. "testee" dummy. Since the target does not expose the flash memory
  4079. mapping, target commands that would otherwise be expected to access the flash
  4080. will not work. These include all @command{*_image} and
  4081. @command{$target_name m*} commands as well as @command{program}. Equivalent
  4082. functionality is available through the @command{flash write_bank},
  4083. @command{flash read_bank}, and @command{flash verify_bank} commands.
  4084. @itemize
  4085. @item @var{ir} ... is loaded into the JTAG IR to map the flash as the JTAG DR.
  4086. For the bitstreams generated from @file{xilinx_bscan_spi.py} this is the
  4087. @var{USER1} instruction.
  4088. @item @var{dr_length} ... is the length of the DR register. This will be 1 for
  4089. @file{xilinx_bscan_spi.py} bitstreams and most other cases.
  4090. @end itemize
  4091. @example
  4092. target create $_TARGETNAME testee -chain-position $_CHIPNAME.fpga
  4093. set _XILINX_USER1 0x02
  4094. set _DR_LENGTH 1
  4095. flash bank $_FLASHNAME spi 0x0 0 0 0 $_TARGETNAME $_XILINX_USER1 $_DR_LENGTH
  4096. @end example
  4097. @end deffn
  4098. @deffn {Flash Driver} lpcspifi
  4099. @cindex NXP SPI Flash Interface
  4100. @cindex SPIFI
  4101. @cindex lpcspifi
  4102. NXP's LPC43xx and LPC18xx families include a proprietary SPI
  4103. Flash Interface (SPIFI) peripheral that can drive and provide
  4104. memory mapped access to external SPI flash devices.
  4105. The lpcspifi driver initializes this interface and provides
  4106. program and erase functionality for these serial flash devices.
  4107. Use of this driver @b{requires} a working area of at least 1kB
  4108. to be configured on the target device; more than this will
  4109. significantly reduce flash programming times.
  4110. The setup command only requires the @var{base} parameter. All
  4111. other parameters are ignored, and the flash size and layout
  4112. are configured by the driver.
  4113. @example
  4114. flash bank $_FLASHNAME lpcspifi 0x14000000 0 0 0 $_TARGETNAME
  4115. @end example
  4116. @end deffn
  4117. @deffn {Flash Driver} stmsmi
  4118. @cindex STMicroelectronics Serial Memory Interface
  4119. @cindex SMI
  4120. @cindex stmsmi
  4121. Some devices form STMicroelectronics (e.g. STR75x MCU family,
  4122. SPEAr MPU family) include a proprietary
  4123. ``Serial Memory Interface'' (SMI) controller able to drive external
  4124. SPI flash devices.
  4125. Depending on specific device and board configuration, up to 4 external
  4126. flash devices can be connected.
  4127. SMI makes the flash content directly accessible in the CPU address
  4128. space; each external device is mapped in a memory bank.
  4129. CPU can directly read data, execute code and boot from SMI banks.
  4130. Normal OpenOCD commands like @command{mdw} can be used to display
  4131. the flash content.
  4132. The setup command only requires the @var{base} parameter in order
  4133. to identify the memory bank.
  4134. All other parameters are ignored. Additional information, like
  4135. flash size, are detected automatically.
  4136. @example
  4137. flash bank $_FLASHNAME stmsmi 0xf8000000 0 0 0 $_TARGETNAME
  4138. @end example
  4139. @end deffn
  4140. @deffn {Flash Driver} mrvlqspi
  4141. This driver supports QSPI flash controller of Marvell's Wireless
  4142. Microcontroller platform.
  4143. The flash size is autodetected based on the table of known JEDEC IDs
  4144. hardcoded in the OpenOCD sources.
  4145. @example
  4146. flash bank $_FLASHNAME mrvlqspi 0x0 0 0 0 $_TARGETNAME 0x46010000
  4147. @end example
  4148. @end deffn
  4149. @subsection Internal Flash (Microcontrollers)
  4150. @deffn {Flash Driver} aduc702x
  4151. The ADUC702x analog microcontrollers from Analog Devices
  4152. include internal flash and use ARM7TDMI cores.
  4153. The aduc702x flash driver works with models ADUC7019 through ADUC7028.
  4154. The setup command only requires the @var{target} argument
  4155. since all devices in this family have the same memory layout.
  4156. @example
  4157. flash bank $_FLASHNAME aduc702x 0 0 0 0 $_TARGETNAME
  4158. @end example
  4159. @end deffn
  4160. @deffn {Flash Driver} ambiqmicro
  4161. @cindex ambiqmicro
  4162. @cindex apollo
  4163. All members of the Apollo microcontroller family from
  4164. Ambiq Micro include internal flash and use ARM's Cortex-M4 core.
  4165. The host connects over USB to an FTDI interface that communicates
  4166. with the target using SWD.
  4167. The @var{ambiqmicro} driver reads the Chip Information Register detect
  4168. the device class of the MCU.
  4169. The Flash and Sram sizes directly follow device class, and are used
  4170. to set up the flash banks.
  4171. If this fails, the driver will use default values set to the minimum
  4172. sizes of an Apollo chip.
  4173. All Apollo chips have two flash banks of the same size.
  4174. In all cases the first flash bank starts at location 0,
  4175. and the second bank starts after the first.
  4176. @example
  4177. # Flash bank 0
  4178. flash bank $_FLASHNAME ambiqmicro 0 0x00040000 0 0 $_TARGETNAME
  4179. # Flash bank 1 - same size as bank0, starts after bank 0.
  4180. flash bank $_FLASHNAME ambiqmicro 0x00040000 0x00040000 0 0 $_TARGETNAME
  4181. @end example
  4182. Flash is programmed using custom entry points into the bootloader.
  4183. This is the only way to program the flash as no flash control registers
  4184. are available to the user.
  4185. The @var{ambiqmicro} driver adds some additional commands:
  4186. @deffn Command {ambiqmicro mass_erase} <bank>
  4187. Erase entire bank.
  4188. @end deffn
  4189. @deffn Command {ambiqmicro page_erase} <bank> <first> <last>
  4190. Erase device pages.
  4191. @end deffn
  4192. @deffn Command {ambiqmicro program_otp} <bank> <offset> <count>
  4193. Program OTP is a one time operation to create write protected flash.
  4194. The user writes sectors to sram starting at 0x10000010.
  4195. Program OTP will write these sectors from sram to flash, and write protect
  4196. the flash.
  4197. @end deffn
  4198. @end deffn
  4199. @anchor{at91samd}
  4200. @deffn {Flash Driver} at91samd
  4201. @cindex at91samd
  4202. All members of the ATSAMD, ATSAMR, ATSAML and ATSAMC microcontroller
  4203. families from Atmel include internal flash and use ARM's Cortex-M0+ core.
  4204. This driver uses the same cmd names/syntax as @xref{at91sam3}.
  4205. @deffn Command {at91samd chip-erase}
  4206. Issues a complete Flash erase via the Device Service Unit (DSU). This can be
  4207. used to erase a chip back to its factory state and does not require the
  4208. processor to be halted.
  4209. @end deffn
  4210. @deffn Command {at91samd set-security}
  4211. Secures the Flash via the Set Security Bit (SSB) command. This prevents access
  4212. to the Flash and can only be undone by using the chip-erase command which
  4213. erases the Flash contents and turns off the security bit. Warning: at this
  4214. time, openocd will not be able to communicate with a secured chip and it is
  4215. therefore not possible to chip-erase it without using another tool.
  4216. @example
  4217. at91samd set-security enable
  4218. @end example
  4219. @end deffn
  4220. @deffn Command {at91samd eeprom}
  4221. Shows or sets the EEPROM emulation size configuration, stored in the User Row
  4222. of the Flash. When setting, the EEPROM size must be specified in bytes and it
  4223. must be one of the permitted sizes according to the datasheet. Settings are
  4224. written immediately but only take effect on MCU reset. EEPROM emulation
  4225. requires additional firmware support and the minumum EEPROM size may not be
  4226. the same as the minimum that the hardware supports. Set the EEPROM size to 0
  4227. in order to disable this feature.
  4228. @example
  4229. at91samd eeprom
  4230. at91samd eeprom 1024
  4231. @end example
  4232. @end deffn
  4233. @deffn Command {at91samd bootloader}
  4234. Shows or sets the bootloader size configuration, stored in the User Row of the
  4235. Flash. This is called the BOOTPROT region. When setting, the bootloader size
  4236. must be specified in bytes and it must be one of the permitted sizes according
  4237. to the datasheet. Settings are written immediately but only take effect on
  4238. MCU reset. Setting the bootloader size to 0 disables bootloader protection.
  4239. @example
  4240. at91samd bootloader
  4241. at91samd bootloader 16384
  4242. @end example
  4243. @end deffn
  4244. @deffn Command {at91samd dsu_reset_deassert}
  4245. This command releases internal reset held by DSU
  4246. and prepares reset vector catch in case of reset halt.
  4247. Command is used internally in event event reset-deassert-post.
  4248. @end deffn
  4249. @end deffn
  4250. @anchor{at91sam3}
  4251. @deffn {Flash Driver} at91sam3
  4252. @cindex at91sam3
  4253. All members of the AT91SAM3 microcontroller family from
  4254. Atmel include internal flash and use ARM's Cortex-M3 core. The driver
  4255. currently (6/22/09) recognizes the AT91SAM3U[1/2/4][C/E] chips. Note
  4256. that the driver was orginaly developed and tested using the
  4257. AT91SAM3U4E, using a SAM3U-EK eval board. Support for other chips in
  4258. the family was cribbed from the data sheet. @emph{Note to future
  4259. readers/updaters: Please remove this worrysome comment after other
  4260. chips are confirmed.}
  4261. The AT91SAM3U4[E/C] (256K) chips have two flash banks; most other chips
  4262. have one flash bank. In all cases the flash banks are at
  4263. the following fixed locations:
  4264. @example
  4265. # Flash bank 0 - all chips
  4266. flash bank $_FLASHNAME at91sam3 0x00080000 0 1 1 $_TARGETNAME
  4267. # Flash bank 1 - only 256K chips
  4268. flash bank $_FLASHNAME at91sam3 0x00100000 0 1 1 $_TARGETNAME
  4269. @end example
  4270. Internally, the AT91SAM3 flash memory is organized as follows.
  4271. Unlike the AT91SAM7 chips, these are not used as parameters
  4272. to the @command{flash bank} command:
  4273. @itemize
  4274. @item @emph{N-Banks:} 256K chips have 2 banks, others have 1 bank.
  4275. @item @emph{Bank Size:} 128K/64K Per flash bank
  4276. @item @emph{Sectors:} 16 or 8 per bank
  4277. @item @emph{SectorSize:} 8K Per Sector
  4278. @item @emph{PageSize:} 256 bytes per page. Note that OpenOCD operates on 'sector' sizes, not page sizes.
  4279. @end itemize
  4280. The AT91SAM3 driver adds some additional commands:
  4281. @deffn Command {at91sam3 gpnvm}
  4282. @deffnx Command {at91sam3 gpnvm clear} number
  4283. @deffnx Command {at91sam3 gpnvm set} number
  4284. @deffnx Command {at91sam3 gpnvm show} [@option{all}|number]
  4285. With no parameters, @command{show} or @command{show all},
  4286. shows the status of all GPNVM bits.
  4287. With @command{show} @var{number}, displays that bit.
  4288. With @command{set} @var{number} or @command{clear} @var{number},
  4289. modifies that GPNVM bit.
  4290. @end deffn
  4291. @deffn Command {at91sam3 info}
  4292. This command attempts to display information about the AT91SAM3
  4293. chip. @emph{First} it read the @code{CHIPID_CIDR} [address 0x400e0740, see
  4294. Section 28.2.1, page 505 of the AT91SAM3U 29/may/2009 datasheet,
  4295. document id: doc6430A] and decodes the values. @emph{Second} it reads the
  4296. various clock configuration registers and attempts to display how it
  4297. believes the chip is configured. By default, the SLOWCLK is assumed to
  4298. be 32768 Hz, see the command @command{at91sam3 slowclk}.
  4299. @end deffn
  4300. @deffn Command {at91sam3 slowclk} [value]
  4301. This command shows/sets the slow clock frequency used in the
  4302. @command{at91sam3 info} command calculations above.
  4303. @end deffn
  4304. @end deffn
  4305. @deffn {Flash Driver} at91sam4
  4306. @cindex at91sam4
  4307. All members of the AT91SAM4 microcontroller family from
  4308. Atmel include internal flash and use ARM's Cortex-M4 core.
  4309. This driver uses the same cmd names/syntax as @xref{at91sam3}.
  4310. @end deffn
  4311. @deffn {Flash Driver} at91sam4l
  4312. @cindex at91sam4l
  4313. All members of the AT91SAM4L microcontroller family from
  4314. Atmel include internal flash and use ARM's Cortex-M4 core.
  4315. This driver uses the same cmd names/syntax as @xref{at91sam3}.
  4316. The AT91SAM4L driver adds some additional commands:
  4317. @deffn Command {at91sam4l smap_reset_deassert}
  4318. This command releases internal reset held by SMAP
  4319. and prepares reset vector catch in case of reset halt.
  4320. Command is used internally in event event reset-deassert-post.
  4321. @end deffn
  4322. @end deffn
  4323. @deffn {Flash Driver} atsamv
  4324. @cindex atsamv
  4325. All members of the ATSAMV, ATSAMS, and ATSAME families from
  4326. Atmel include internal flash and use ARM's Cortex-M7 core.
  4327. This driver uses the same cmd names/syntax as @xref{at91sam3}.
  4328. @end deffn
  4329. @deffn {Flash Driver} at91sam7
  4330. All members of the AT91SAM7 microcontroller family from Atmel include
  4331. internal flash and use ARM7TDMI cores. The driver automatically
  4332. recognizes a number of these chips using the chip identification
  4333. register, and autoconfigures itself.
  4334. @example
  4335. flash bank $_FLASHNAME at91sam7 0 0 0 0 $_TARGETNAME
  4336. @end example
  4337. For chips which are not recognized by the controller driver, you must
  4338. provide additional parameters in the following order:
  4339. @itemize
  4340. @item @var{chip_model} ... label used with @command{flash info}
  4341. @item @var{banks}
  4342. @item @var{sectors_per_bank}
  4343. @item @var{pages_per_sector}
  4344. @item @var{pages_size}
  4345. @item @var{num_nvm_bits}
  4346. @item @var{freq_khz} ... required if an external clock is provided,
  4347. optional (but recommended) when the oscillator frequency is known
  4348. @end itemize
  4349. It is recommended that you provide zeroes for all of those values
  4350. except the clock frequency, so that everything except that frequency
  4351. will be autoconfigured.
  4352. Knowing the frequency helps ensure correct timings for flash access.
  4353. The flash controller handles erases automatically on a page (128/256 byte)
  4354. basis, so explicit erase commands are not necessary for flash programming.
  4355. However, there is an ``EraseAll`` command that can erase an entire flash
  4356. plane (of up to 256KB), and it will be used automatically when you issue
  4357. @command{flash erase_sector} or @command{flash erase_address} commands.
  4358. @deffn Command {at91sam7 gpnvm} bitnum (@option{set}|@option{clear})
  4359. Set or clear a ``General Purpose Non-Volatile Memory'' (GPNVM)
  4360. bit for the processor. Each processor has a number of such bits,
  4361. used for controlling features such as brownout detection (so they
  4362. are not truly general purpose).
  4363. @quotation Note
  4364. This assumes that the first flash bank (number 0) is associated with
  4365. the appropriate at91sam7 target.
  4366. @end quotation
  4367. @end deffn
  4368. @end deffn
  4369. @deffn {Flash Driver} avr
  4370. The AVR 8-bit microcontrollers from Atmel integrate flash memory.
  4371. @emph{The current implementation is incomplete.}
  4372. @comment - defines mass_erase ... pointless given flash_erase_address
  4373. @end deffn
  4374. @deffn {Flash Driver} efm32
  4375. All members of the EFM32 microcontroller family from Energy Micro include
  4376. internal flash and use ARM Cortex-M3 cores. The driver automatically recognizes
  4377. a number of these chips using the chip identification register, and
  4378. autoconfigures itself.
  4379. @example
  4380. flash bank $_FLASHNAME efm32 0 0 0 0 $_TARGETNAME
  4381. @end example
  4382. A special feature of efm32 controllers is that it is possible to completely disable the
  4383. debug interface by writing the correct values to the 'Debug Lock Word'. OpenOCD supports
  4384. this via the following command:
  4385. @example
  4386. efm32 debuglock num
  4387. @end example
  4388. The @var{num} parameter is a value shown by @command{flash banks}.
  4389. Note that in order for this command to take effect, the target needs to be reset.
  4390. @emph{The current implementation is incomplete. Unprotecting flash pages is not
  4391. supported.}
  4392. @end deffn
  4393. @deffn {Flash Driver} fm3
  4394. All members of the FM3 microcontroller family from Fujitsu
  4395. include internal flash and use ARM Cortex-M3 cores.
  4396. The @var{fm3} driver uses the @var{target} parameter to select the
  4397. correct bank config, it can currently be one of the following:
  4398. @code{mb9bfxx1.cpu}, @code{mb9bfxx2.cpu}, @code{mb9bfxx3.cpu},
  4399. @code{mb9bfxx4.cpu}, @code{mb9bfxx5.cpu} or @code{mb9bfxx6.cpu}.
  4400. @example
  4401. flash bank $_FLASHNAME fm3 0 0 0 0 $_TARGETNAME
  4402. @end example
  4403. @end deffn
  4404. @deffn {Flash Driver} fm4
  4405. All members of the FM4 microcontroller family from Spansion (formerly Fujitsu)
  4406. include internal flash and use ARM Cortex-M4 cores.
  4407. The @var{fm4} driver uses a @var{family} parameter to select the
  4408. correct bank config, it can currently be one of the following:
  4409. @code{MB9BFx64}, @code{MB9BFx65}, @code{MB9BFx66}, @code{MB9BFx67}, @code{MB9BFx68},
  4410. @code{S6E2Cx8}, @code{S6E2Cx9}, @code{S6E2CxA} or @code{S6E2Dx},
  4411. with @code{x} treated as wildcard and otherwise case (and any trailing
  4412. characters) ignored.
  4413. @example
  4414. flash bank $@{_FLASHNAME@}0 fm4 0x00000000 0 0 0 $_TARGETNAME S6E2CCAJ0A
  4415. flash bank $@{_FLASHNAME@}1 fm4 0x00100000 0 0 0 $_TARGETNAME S6E2CCAJ0A
  4416. @end example
  4417. @emph{The current implementation is incomplete. Protection is not supported,
  4418. nor is Chip Erase (only Sector Erase is implemented).}
  4419. @end deffn
  4420. @deffn {Flash Driver} kinetis
  4421. @cindex kinetis
  4422. Kx and KLx members of the Kinetis microcontroller family from Freescale include
  4423. internal flash and use ARM Cortex-M0+ or M4 cores. The driver automatically
  4424. recognizes flash size and a number of flash banks (1-4) using the chip
  4425. identification register, and autoconfigures itself.
  4426. @example
  4427. flash bank $_FLASHNAME kinetis 0 0 0 0 $_TARGETNAME
  4428. @end example
  4429. @deffn Command {kinetis mdm check_security}
  4430. Checks status of device security lock. Used internally in examine-end event.
  4431. @end deffn
  4432. @deffn Command {kinetis mdm mass_erase}
  4433. Issues a complete Flash erase via the MDM-AP.
  4434. This can be used to erase a chip back to its factory state.
  4435. Command removes security lock from a device (use of SRST highly recommended).
  4436. It does not require the processor to be halted.
  4437. @end deffn
  4438. @deffn Command {kinetis nvm_partition}
  4439. For FlexNVM devices only (KxxDX and KxxFX).
  4440. Command shows or sets data flash or EEPROM backup size in kilobytes,
  4441. sets two EEPROM blocks sizes in bytes and enables/disables loading
  4442. of EEPROM contents to FlexRAM during reset.
  4443. For details see device reference manual, Flash Memory Module,
  4444. Program Partition command.
  4445. Setting is possible only once after mass_erase.
  4446. Reset the device after partition setting.
  4447. Show partition size:
  4448. @example
  4449. kinetis nvm_partition info
  4450. @end example
  4451. Set 32 KB data flash, rest of FlexNVM is EEPROM backup. EEPROM has two blocks
  4452. of 512 and 1536 bytes and its contents is loaded to FlexRAM during reset:
  4453. @example
  4454. kinetis nvm_partition dataflash 32 512 1536 on
  4455. @end example
  4456. Set 16 KB EEPROM backup, rest of FlexNVM is a data flash. EEPROM has two blocks
  4457. of 1024 bytes and its contents is not loaded to FlexRAM during reset:
  4458. @example
  4459. kinetis nvm_partition eebkp 16 1024 1024 off
  4460. @end example
  4461. @end deffn
  4462. @deffn Command {kinetis disable_wdog}
  4463. For Kx devices only (KLx has different COP watchdog, it is not supported).
  4464. Command disables watchdog timer.
  4465. @end deffn
  4466. @end deffn
  4467. @deffn {Flash Driver} kinetis_ke
  4468. @cindex kinetis_ke
  4469. KE members of the Kinetis microcontroller family from Freescale include
  4470. internal flash and use ARM Cortex-M0+. The driver automatically recognizes
  4471. the KE family and sub-family using the chip identification register, and
  4472. autoconfigures itself.
  4473. @example
  4474. flash bank $_FLASHNAME kinetis_ke 0 0 0 0 $_TARGETNAME
  4475. @end example
  4476. @deffn Command {kinetis_ke mdm check_security}
  4477. Checks status of device security lock. Used internally in examine-end event.
  4478. @end deffn
  4479. @deffn Command {kinetis_ke mdm mass_erase}
  4480. Issues a complete Flash erase via the MDM-AP.
  4481. This can be used to erase a chip back to its factory state.
  4482. Command removes security lock from a device (use of SRST highly recommended).
  4483. It does not require the processor to be halted.
  4484. @end deffn
  4485. @deffn Command {kinetis_ke disable_wdog}
  4486. Command disables watchdog timer.
  4487. @end deffn
  4488. @end deffn
  4489. @deffn {Flash Driver} lpc2000
  4490. This is the driver to support internal flash of all members of the
  4491. LPC11(x)00 and LPC1300 microcontroller families and most members of
  4492. the LPC800, LPC1500, LPC1700, LPC1800, LPC2000, LPC4000 and LPC54100
  4493. microcontroller families from NXP.
  4494. @quotation Note
  4495. There are LPC2000 devices which are not supported by the @var{lpc2000}
  4496. driver:
  4497. The LPC2888 is supported by the @var{lpc288x} driver.
  4498. The LPC29xx family is supported by the @var{lpc2900} driver.
  4499. @end quotation
  4500. The @var{lpc2000} driver defines two mandatory and one optional parameters,
  4501. which must appear in the following order:
  4502. @itemize
  4503. @item @var{variant} ... required, may be
  4504. @option{lpc2000_v1} (older LPC21xx and LPC22xx)
  4505. @option{lpc2000_v2} (LPC213x, LPC214x, LPC210[123], LPC23xx and LPC24xx)
  4506. @option{lpc1700} (LPC175x and LPC176x and LPC177x/8x)
  4507. @option{lpc4300} - available also as @option{lpc1800} alias (LPC18x[2357] and
  4508. LPC43x[2357])
  4509. @option{lpc800} (LPC8xx)
  4510. @option{lpc1100} (LPC11(x)xx and LPC13xx)
  4511. @option{lpc1500} (LPC15xx)
  4512. @option{lpc54100} (LPC541xx)
  4513. @option{lpc4000} (LPC40xx)
  4514. or @option{auto} - automatically detects flash variant and size for LPC11(x)00,
  4515. LPC8xx, LPC13xx, LPC17xx and LPC40xx
  4516. @item @var{clock_kHz} ... the frequency, in kiloHertz,
  4517. at which the core is running
  4518. @item @option{calc_checksum} ... optional (but you probably want to provide this!),
  4519. telling the driver to calculate a valid checksum for the exception vector table.
  4520. @quotation Note
  4521. If you don't provide @option{calc_checksum} when you're writing the vector
  4522. table, the boot ROM will almost certainly ignore your flash image.
  4523. However, if you do provide it,
  4524. with most tool chains @command{verify_image} will fail.
  4525. @end quotation
  4526. @end itemize
  4527. LPC flashes don't require the chip and bus width to be specified.
  4528. @example
  4529. flash bank $_FLASHNAME lpc2000 0x0 0x7d000 0 0 $_TARGETNAME \
  4530. lpc2000_v2 14765 calc_checksum
  4531. @end example
  4532. @deffn {Command} {lpc2000 part_id} bank
  4533. Displays the four byte part identifier associated with
  4534. the specified flash @var{bank}.
  4535. @end deffn
  4536. @end deffn
  4537. @deffn {Flash Driver} lpc288x
  4538. The LPC2888 microcontroller from NXP needs slightly different flash
  4539. support from its lpc2000 siblings.
  4540. The @var{lpc288x} driver defines one mandatory parameter,
  4541. the programming clock rate in Hz.
  4542. LPC flashes don't require the chip and bus width to be specified.
  4543. @example
  4544. flash bank $_FLASHNAME lpc288x 0 0 0 0 $_TARGETNAME 12000000
  4545. @end example
  4546. @end deffn
  4547. @deffn {Flash Driver} lpc2900
  4548. This driver supports the LPC29xx ARM968E based microcontroller family
  4549. from NXP.
  4550. The predefined parameters @var{base}, @var{size}, @var{chip_width} and
  4551. @var{bus_width} of the @code{flash bank} command are ignored. Flash size and
  4552. sector layout are auto-configured by the driver.
  4553. The driver has one additional mandatory parameter: The CPU clock rate
  4554. (in kHz) at the time the flash operations will take place. Most of the time this
  4555. will not be the crystal frequency, but a higher PLL frequency. The
  4556. @code{reset-init} event handler in the board script is usually the place where
  4557. you start the PLL.
  4558. The driver rejects flashless devices (currently the LPC2930).
  4559. The EEPROM in LPC2900 devices is not mapped directly into the address space.
  4560. It must be handled much more like NAND flash memory, and will therefore be
  4561. handled by a separate @code{lpc2900_eeprom} driver (not yet available).
  4562. Sector protection in terms of the LPC2900 is handled transparently. Every time a
  4563. sector needs to be erased or programmed, it is automatically unprotected.
  4564. What is shown as protection status in the @code{flash info} command, is
  4565. actually the LPC2900 @emph{sector security}. This is a mechanism to prevent a
  4566. sector from ever being erased or programmed again. As this is an irreversible
  4567. mechanism, it is handled by a special command (@code{lpc2900 secure_sector}),
  4568. and not by the standard @code{flash protect} command.
  4569. Example for a 125 MHz clock frequency:
  4570. @example
  4571. flash bank $_FLASHNAME lpc2900 0 0 0 0 $_TARGETNAME 125000
  4572. @end example
  4573. Some @code{lpc2900}-specific commands are defined. In the following command list,
  4574. the @var{bank} parameter is the bank number as obtained by the
  4575. @code{flash banks} command.
  4576. @deffn Command {lpc2900 signature} bank
  4577. Calculates a 128-bit hash value, the @emph{signature}, from the whole flash
  4578. content. This is a hardware feature of the flash block, hence the calculation is
  4579. very fast. You may use this to verify the content of a programmed device against
  4580. a known signature.
  4581. Example:
  4582. @example
  4583. lpc2900 signature 0
  4584. signature: 0x5f40cdc8:0xc64e592e:0x10490f89:0x32a0f317
  4585. @end example
  4586. @end deffn
  4587. @deffn Command {lpc2900 read_custom} bank filename
  4588. Reads the 912 bytes of customer information from the flash index sector, and
  4589. saves it to a file in binary format.
  4590. Example:
  4591. @example
  4592. lpc2900 read_custom 0 /path_to/customer_info.bin
  4593. @end example
  4594. @end deffn
  4595. The index sector of the flash is a @emph{write-only} sector. It cannot be
  4596. erased! In order to guard against unintentional write access, all following
  4597. commands need to be preceeded by a successful call to the @code{password}
  4598. command:
  4599. @deffn Command {lpc2900 password} bank password
  4600. You need to use this command right before each of the following commands:
  4601. @code{lpc2900 write_custom}, @code{lpc2900 secure_sector},
  4602. @code{lpc2900 secure_jtag}.
  4603. The password string is fixed to "I_know_what_I_am_doing".
  4604. Example:
  4605. @example
  4606. lpc2900 password 0 I_know_what_I_am_doing
  4607. Potentially dangerous operation allowed in next command!
  4608. @end example
  4609. @end deffn
  4610. @deffn Command {lpc2900 write_custom} bank filename type
  4611. Writes the content of the file into the customer info space of the flash index
  4612. sector. The filetype can be specified with the @var{type} field. Possible values
  4613. for @var{type} are: @var{bin} (binary), @var{ihex} (Intel hex format),
  4614. @var{elf} (ELF binary) or @var{s19} (Motorola S-records). The file must
  4615. contain a single section, and the contained data length must be exactly
  4616. 912 bytes.
  4617. @quotation Attention
  4618. This cannot be reverted! Be careful!
  4619. @end quotation
  4620. Example:
  4621. @example
  4622. lpc2900 write_custom 0 /path_to/customer_info.bin bin
  4623. @end example
  4624. @end deffn
  4625. @deffn Command {lpc2900 secure_sector} bank first last
  4626. Secures the sector range from @var{first} to @var{last} (including) against
  4627. further program and erase operations. The sector security will be effective
  4628. after the next power cycle.
  4629. @quotation Attention
  4630. This cannot be reverted! Be careful!
  4631. @end quotation
  4632. Secured sectors appear as @emph{protected} in the @code{flash info} command.
  4633. Example:
  4634. @example
  4635. lpc2900 secure_sector 0 1 1
  4636. flash info 0
  4637. #0 : lpc2900 at 0x20000000, size 0x000c0000, (...)
  4638. # 0: 0x00000000 (0x2000 8kB) not protected
  4639. # 1: 0x00002000 (0x2000 8kB) protected
  4640. # 2: 0x00004000 (0x2000 8kB) not protected
  4641. @end example
  4642. @end deffn
  4643. @deffn Command {lpc2900 secure_jtag} bank
  4644. Irreversibly disable the JTAG port. The new JTAG security setting will be
  4645. effective after the next power cycle.
  4646. @quotation Attention
  4647. This cannot be reverted! Be careful!
  4648. @end quotation
  4649. Examples:
  4650. @example
  4651. lpc2900 secure_jtag 0
  4652. @end example
  4653. @end deffn
  4654. @end deffn
  4655. @deffn {Flash Driver} mdr
  4656. This drivers handles the integrated NOR flash on Milandr Cortex-M
  4657. based controllers. A known limitation is that the Info memory can't be
  4658. read or verified as it's not memory mapped.
  4659. @example
  4660. flash bank <name> mdr <base> <size> \
  4661. 0 0 <target#> @var{type} @var{page_count} @var{sec_count}
  4662. @end example
  4663. @itemize @bullet
  4664. @item @var{type} - 0 for main memory, 1 for info memory
  4665. @item @var{page_count} - total number of pages
  4666. @item @var{sec_count} - number of sector per page count
  4667. @end itemize
  4668. Example usage:
  4669. @example
  4670. if @{ [info exists IMEMORY] && [string equal $IMEMORY true] @} @{
  4671. flash bank $@{_CHIPNAME@}_info.flash mdr 0x00000000 0x01000 \
  4672. 0 0 $_TARGETNAME 1 1 4
  4673. @} else @{
  4674. flash bank $_CHIPNAME.flash mdr 0x00000000 0x20000 \
  4675. 0 0 $_TARGETNAME 0 32 4
  4676. @}
  4677. @end example
  4678. @end deffn
  4679. @deffn {Flash Driver} niietcm4
  4680. This drivers handles the integrated NOR flash on NIIET Cortex-M4
  4681. based controllers. Flash size and sector layout are auto-configured by the driver.
  4682. Main flash memory is called "Bootflash" and has main region and info region.
  4683. Info region is NOT memory mapped by default,
  4684. but it can replace first part of main region if needed.
  4685. Full erase, single and block writes are supported for both main and info regions.
  4686. There is additional not memory mapped flash called "Userflash", which
  4687. also have division into regions: main and info.
  4688. Purpose of userflash - to store system and user settings.
  4689. Driver has special commands to perform operations with this memmory.
  4690. @example
  4691. flash bank $_FLASHNAME niietcm4 0 0 0 0 $_TARGETNAME
  4692. @end example
  4693. Some niietcm4-specific commands are defined:
  4694. @deffn Command {niietcm4 uflash_read_byte} bank ('main'|'info') address
  4695. Read byte from main or info userflash region.
  4696. @end deffn
  4697. @deffn Command {niietcm4 uflash_write_byte} bank ('main'|'info') address value
  4698. Write byte to main or info userflash region.
  4699. @end deffn
  4700. @deffn Command {niietcm4 uflash_full_erase} bank
  4701. Erase all userflash including info region.
  4702. @end deffn
  4703. @deffn Command {niietcm4 uflash_erase} bank ('main'|'info') first_sector last_sector
  4704. Erase sectors of main or info userflash region, starting at sector first up to and including last.
  4705. @end deffn
  4706. @deffn Command {niietcm4 uflash_protect_check} bank ('main'|'info')
  4707. Check sectors protect.
  4708. @end deffn
  4709. @deffn Command {niietcm4 uflash_protect} bank ('main'|'info') first_sector last_sector ('on'|'off')
  4710. Protect sectors of main or info userflash region, starting at sector first up to and including last.
  4711. @end deffn
  4712. @deffn Command {niietcm4 bflash_info_remap} bank ('on'|'off')
  4713. Enable remapping bootflash info region to 0x00000000 (or 0x40000000 if external memory boot used).
  4714. @end deffn
  4715. @deffn Command {niietcm4 extmem_cfg} bank ('gpioa'|'gpiob'|'gpioc'|'gpiod'|'gpioe'|'gpiof'|'gpiog'|'gpioh') pin_num ('func1'|'func3')
  4716. Configure external memory interface for boot.
  4717. @end deffn
  4718. @deffn Command {niietcm4 service_mode_erase} bank
  4719. Perform emergency erase of all flash (bootflash and userflash).
  4720. @end deffn
  4721. @deffn Command {niietcm4 driver_info} bank
  4722. Show information about flash driver.
  4723. @end deffn
  4724. @end deffn
  4725. @deffn {Flash Driver} nrf51
  4726. All members of the nRF51 microcontroller families from Nordic Semiconductor
  4727. include internal flash and use ARM Cortex-M0 core.
  4728. @example
  4729. flash bank $_FLASHNAME nrf51 0 0x00000000 0 0 $_TARGETNAME
  4730. @end example
  4731. Some nrf51-specific commands are defined:
  4732. @deffn Command {nrf51 mass_erase}
  4733. Erases the contents of the code memory and user information
  4734. configuration registers as well. It must be noted that this command
  4735. works only for chips that do not have factory pre-programmed region 0
  4736. code.
  4737. @end deffn
  4738. @end deffn
  4739. @deffn {Flash Driver} ocl
  4740. This driver is an implementation of the ``on chip flash loader''
  4741. protocol proposed by Pavel Chromy.
  4742. It is a minimalistic command-response protocol intended to be used
  4743. over a DCC when communicating with an internal or external flash
  4744. loader running from RAM. An example implementation for AT91SAM7x is
  4745. available in @file{contrib/loaders/flash/at91sam7x/}.
  4746. @example
  4747. flash bank $_FLASHNAME ocl 0 0 0 0 $_TARGETNAME
  4748. @end example
  4749. @end deffn
  4750. @deffn {Flash Driver} pic32mx
  4751. The PIC32MX microcontrollers are based on the MIPS 4K cores,
  4752. and integrate flash memory.
  4753. @example
  4754. flash bank $_FLASHNAME pix32mx 0x1fc00000 0 0 0 $_TARGETNAME
  4755. flash bank $_FLASHNAME pix32mx 0x1d000000 0 0 0 $_TARGETNAME
  4756. @end example
  4757. @comment numerous *disabled* commands are defined:
  4758. @comment - chip_erase ... pointless given flash_erase_address
  4759. @comment - lock, unlock ... pointless given protect on/off (yes?)
  4760. @comment - pgm_word ... shouldn't bank be deduced from address??
  4761. Some pic32mx-specific commands are defined:
  4762. @deffn Command {pic32mx pgm_word} address value bank
  4763. Programs the specified 32-bit @var{value} at the given @var{address}
  4764. in the specified chip @var{bank}.
  4765. @end deffn
  4766. @deffn Command {pic32mx unlock} bank
  4767. Unlock and erase specified chip @var{bank}.
  4768. This will remove any Code Protection.
  4769. @end deffn
  4770. @end deffn
  4771. @deffn {Flash Driver} psoc4
  4772. All members of the PSoC 41xx/42xx microcontroller family from Cypress
  4773. include internal flash and use ARM Cortex-M0 cores.
  4774. The driver automatically recognizes a number of these chips using
  4775. the chip identification register, and autoconfigures itself.
  4776. Note: Erased internal flash reads as 00.
  4777. System ROM of PSoC 4 does not implement erase of a flash sector.
  4778. @example
  4779. flash bank $_FLASHNAME psoc4 0 0 0 0 $_TARGETNAME
  4780. @end example
  4781. psoc4-specific commands
  4782. @deffn Command {psoc4 flash_autoerase} num (on|off)
  4783. Enables or disables autoerase mode for a flash bank.
  4784. If flash_autoerase is off, use mass_erase before flash programming.
  4785. Flash erase command fails if region to erase is not whole flash memory.
  4786. If flash_autoerase is on, a sector is both erased and programmed in one
  4787. system ROM call. Flash erase command is ignored.
  4788. This mode is suitable for gdb load.
  4789. The @var{num} parameter is a value shown by @command{flash banks}.
  4790. @end deffn
  4791. @deffn Command {psoc4 mass_erase} num
  4792. Erases the contents of the flash memory, protection and security lock.
  4793. The @var{num} parameter is a value shown by @command{flash banks}.
  4794. @end deffn
  4795. @end deffn
  4796. @deffn {Flash Driver} sim3x
  4797. All members of the SiM3 microcontroller family from Silicon Laboratories
  4798. include internal flash and use ARM Cortex-M3 cores. It supports both JTAG
  4799. and SWD interface.
  4800. The @var{sim3x} driver tries to probe the device to auto detect the MCU.
  4801. If this failes, it will use the @var{size} parameter as the size of flash bank.
  4802. @example
  4803. flash bank $_FLASHNAME sim3x 0 $_CPUROMSIZE 0 0 $_TARGETNAME
  4804. @end example
  4805. There are 2 commands defined in the @var{sim3x} driver:
  4806. @deffn Command {sim3x mass_erase}
  4807. Erases the complete flash. This is used to unlock the flash.
  4808. And this command is only possible when using the SWD interface.
  4809. @end deffn
  4810. @deffn Command {sim3x lock}
  4811. Lock the flash. To unlock use the @command{sim3x mass_erase} command.
  4812. @end deffn
  4813. @end deffn
  4814. @deffn {Flash Driver} stellaris
  4815. All members of the Stellaris LM3Sxxx, LM4x and Tiva C microcontroller
  4816. families from Texas Instruments include internal flash. The driver
  4817. automatically recognizes a number of these chips using the chip
  4818. identification register, and autoconfigures itself.
  4819. @footnote{Currently there is a @command{stellaris mass_erase} command.
  4820. That seems pointless since the same effect can be had using the
  4821. standard @command{flash erase_address} command.}
  4822. @example
  4823. flash bank $_FLASHNAME stellaris 0 0 0 0 $_TARGETNAME
  4824. @end example
  4825. @deffn Command {stellaris recover}
  4826. Performs the @emph{Recovering a "Locked" Device} procedure to restore
  4827. the flash and its associated nonvolatile registers to their factory
  4828. default values (erased). This is the only way to remove flash
  4829. protection or re-enable debugging if that capability has been
  4830. disabled.
  4831. Note that the final "power cycle the chip" step in this procedure
  4832. must be performed by hand, since OpenOCD can't do it.
  4833. @quotation Warning
  4834. if more than one Stellaris chip is connected, the procedure is
  4835. applied to all of them.
  4836. @end quotation
  4837. @end deffn
  4838. @end deffn
  4839. @deffn {Flash Driver} stm32f1x
  4840. All members of the STM32F0, STM32F1 and STM32F3 microcontroller families
  4841. from ST Microelectronics include internal flash and use ARM Cortex-M0/M3/M4 cores.
  4842. The driver automatically recognizes a number of these chips using
  4843. the chip identification register, and autoconfigures itself.
  4844. @example
  4845. flash bank $_FLASHNAME stm32f1x 0 0 0 0 $_TARGETNAME
  4846. @end example
  4847. Note that some devices have been found that have a flash size register that contains
  4848. an invalid value, to workaround this issue you can override the probed value used by
  4849. the flash driver.
  4850. @example
  4851. flash bank $_FLASHNAME stm32f1x 0 0x20000 0 0 $_TARGETNAME
  4852. @end example
  4853. If you have a target with dual flash banks then define the second bank
  4854. as per the following example.
  4855. @example
  4856. flash bank $_FLASHNAME stm32f1x 0x08080000 0 0 0 $_TARGETNAME
  4857. @end example
  4858. Some stm32f1x-specific commands
  4859. @footnote{Currently there is a @command{stm32f1x mass_erase} command.
  4860. That seems pointless since the same effect can be had using the
  4861. standard @command{flash erase_address} command.}
  4862. are defined:
  4863. @deffn Command {stm32f1x lock} num
  4864. Locks the entire stm32 device.
  4865. The @var{num} parameter is a value shown by @command{flash banks}.
  4866. @end deffn
  4867. @deffn Command {stm32f1x unlock} num
  4868. Unlocks the entire stm32 device.
  4869. The @var{num} parameter is a value shown by @command{flash banks}.
  4870. @end deffn
  4871. @deffn Command {stm32f1x options_read} num
  4872. Read and display the stm32 option bytes written by
  4873. the @command{stm32f1x options_write} command.
  4874. The @var{num} parameter is a value shown by @command{flash banks}.
  4875. @end deffn
  4876. @deffn Command {stm32f1x options_write} num (@option{SWWDG}|@option{HWWDG}) (@option{RSTSTNDBY}|@option{NORSTSTNDBY}) (@option{RSTSTOP}|@option{NORSTSTOP})
  4877. Writes the stm32 option byte with the specified values.
  4878. The @var{num} parameter is a value shown by @command{flash banks}.
  4879. @end deffn
  4880. @end deffn
  4881. @deffn {Flash Driver} stm32f2x
  4882. All members of the STM32F2, STM32F4 and STM32F7 microcontroller families from ST Microelectronics
  4883. include internal flash and use ARM Cortex-M3/M4/M7 cores.
  4884. The driver automatically recognizes a number of these chips using
  4885. the chip identification register, and autoconfigures itself.
  4886. Note that some devices have been found that have a flash size register that contains
  4887. an invalid value, to workaround this issue you can override the probed value used by
  4888. the flash driver.
  4889. @example
  4890. flash bank $_FLASHNAME stm32f2x 0 0x20000 0 0 $_TARGETNAME
  4891. @end example
  4892. Some stm32f2x-specific commands are defined:
  4893. @deffn Command {stm32f2x lock} num
  4894. Locks the entire stm32 device.
  4895. The @var{num} parameter is a value shown by @command{flash banks}.
  4896. @end deffn
  4897. @deffn Command {stm32f2x unlock} num
  4898. Unlocks the entire stm32 device.
  4899. The @var{num} parameter is a value shown by @command{flash banks}.
  4900. @end deffn
  4901. @deffn Command {stm32f2x options_read} num
  4902. Reads and displays user options and (where implemented) boot_addr0 and boot_addr1.
  4903. The @var{num} parameter is a value shown by @command{flash banks}.
  4904. @end deffn
  4905. @deffn Command {stm32f2x options_write} num user_options boot_addr0 boot_addr1
  4906. Writes user options and (where implemented) boot_addr0 and boot_addr1 in raw format.
  4907. Warning: The meaning of the various bits depends on the device, always check datasheet!
  4908. The @var{num} parameter is a value shown by @command{flash banks}, user_options a
  4909. 12 bit value, consisting of bits 31-28 and 7-0 of FLASH_OPTCR, boot_addr0 and boot_addr1
  4910. two halfwords (of FLASH_OPTCR1).
  4911. @end deffn
  4912. @end deffn
  4913. @deffn {Flash Driver} stm32lx
  4914. All members of the STM32L microcontroller families from ST Microelectronics
  4915. include internal flash and use ARM Cortex-M3 and Cortex-M0+ cores.
  4916. The driver automatically recognizes a number of these chips using
  4917. the chip identification register, and autoconfigures itself.
  4918. Note that some devices have been found that have a flash size register that contains
  4919. an invalid value, to workaround this issue you can override the probed value used by
  4920. the flash driver. If you use 0 as the bank base address, it tells the
  4921. driver to autodetect the bank location assuming you're configuring the
  4922. second bank.
  4923. @example
  4924. flash bank $_FLASHNAME stm32lx 0x08000000 0x20000 0 0 $_TARGETNAME
  4925. @end example
  4926. Some stm32lx-specific commands are defined:
  4927. @deffn Command {stm32lx mass_erase} num
  4928. Mass erases the entire stm32lx device (all flash banks and EEPROM
  4929. data). This is the only way to unlock a protected flash (unless RDP
  4930. Level is 2 which can't be unlocked at all).
  4931. The @var{num} parameter is a value shown by @command{flash banks}.
  4932. @end deffn
  4933. @end deffn
  4934. @deffn {Flash Driver} str7x
  4935. All members of the STR7 microcontroller family from ST Microelectronics
  4936. include internal flash and use ARM7TDMI cores.
  4937. The @var{str7x} driver defines one mandatory parameter, @var{variant},
  4938. which is either @code{STR71x}, @code{STR73x} or @code{STR75x}.
  4939. @example
  4940. flash bank $_FLASHNAME str7x \
  4941. 0x40000000 0x00040000 0 0 $_TARGETNAME STR71x
  4942. @end example
  4943. @deffn Command {str7x disable_jtag} bank
  4944. Activate the Debug/Readout protection mechanism
  4945. for the specified flash bank.
  4946. @end deffn
  4947. @end deffn
  4948. @deffn {Flash Driver} str9x
  4949. Most members of the STR9 microcontroller family from ST Microelectronics
  4950. include internal flash and use ARM966E cores.
  4951. The str9 needs the flash controller to be configured using
  4952. the @command{str9x flash_config} command prior to Flash programming.
  4953. @example
  4954. flash bank $_FLASHNAME str9x 0x40000000 0x00040000 0 0 $_TARGETNAME
  4955. str9x flash_config 0 4 2 0 0x80000
  4956. @end example
  4957. @deffn Command {str9x flash_config} num bbsr nbbsr bbadr nbbadr
  4958. Configures the str9 flash controller.
  4959. The @var{num} parameter is a value shown by @command{flash banks}.
  4960. @itemize @bullet
  4961. @item @var{bbsr} - Boot Bank Size register
  4962. @item @var{nbbsr} - Non Boot Bank Size register
  4963. @item @var{bbadr} - Boot Bank Start Address register
  4964. @item @var{nbbadr} - Boot Bank Start Address register
  4965. @end itemize
  4966. @end deffn
  4967. @end deffn
  4968. @deffn {Flash Driver} str9xpec
  4969. @cindex str9xpec
  4970. Only use this driver for locking/unlocking the device or configuring the option bytes.
  4971. Use the standard str9 driver for programming.
  4972. Before using the flash commands the turbo mode must be enabled using the
  4973. @command{str9xpec enable_turbo} command.
  4974. Here is some background info to help
  4975. you better understand how this driver works. OpenOCD has two flash drivers for
  4976. the str9:
  4977. @enumerate
  4978. @item
  4979. Standard driver @option{str9x} programmed via the str9 core. Normally used for
  4980. flash programming as it is faster than the @option{str9xpec} driver.
  4981. @item
  4982. Direct programming @option{str9xpec} using the flash controller. This is an
  4983. ISC compilant (IEEE 1532) tap connected in series with the str9 core. The str9
  4984. core does not need to be running to program using this flash driver. Typical use
  4985. for this driver is locking/unlocking the target and programming the option bytes.
  4986. @end enumerate
  4987. Before we run any commands using the @option{str9xpec} driver we must first disable
  4988. the str9 core. This example assumes the @option{str9xpec} driver has been
  4989. configured for flash bank 0.
  4990. @example
  4991. # assert srst, we do not want core running
  4992. # while accessing str9xpec flash driver
  4993. jtag_reset 0 1
  4994. # turn off target polling
  4995. poll off
  4996. # disable str9 core
  4997. str9xpec enable_turbo 0
  4998. # read option bytes
  4999. str9xpec options_read 0
  5000. # re-enable str9 core
  5001. str9xpec disable_turbo 0
  5002. poll on
  5003. reset halt
  5004. @end example
  5005. The above example will read the str9 option bytes.
  5006. When performing a unlock remember that you will not be able to halt the str9 - it
  5007. has been locked. Halting the core is not required for the @option{str9xpec} driver
  5008. as mentioned above, just issue the commands above manually or from a telnet prompt.
  5009. Several str9xpec-specific commands are defined:
  5010. @deffn Command {str9xpec disable_turbo} num
  5011. Restore the str9 into JTAG chain.
  5012. @end deffn
  5013. @deffn Command {str9xpec enable_turbo} num
  5014. Enable turbo mode, will simply remove the str9 from the chain and talk
  5015. directly to the embedded flash controller.
  5016. @end deffn
  5017. @deffn Command {str9xpec lock} num
  5018. Lock str9 device. The str9 will only respond to an unlock command that will
  5019. erase the device.
  5020. @end deffn
  5021. @deffn Command {str9xpec part_id} num
  5022. Prints the part identifier for bank @var{num}.
  5023. @end deffn
  5024. @deffn Command {str9xpec options_cmap} num (@option{bank0}|@option{bank1})
  5025. Configure str9 boot bank.
  5026. @end deffn
  5027. @deffn Command {str9xpec options_lvdsel} num (@option{vdd}|@option{vdd_vddq})
  5028. Configure str9 lvd source.
  5029. @end deffn
  5030. @deffn Command {str9xpec options_lvdthd} num (@option{2.4v}|@option{2.7v})
  5031. Configure str9 lvd threshold.
  5032. @end deffn
  5033. @deffn Command {str9xpec options_lvdwarn} bank (@option{vdd}|@option{vdd_vddq})
  5034. Configure str9 lvd reset warning source.
  5035. @end deffn
  5036. @deffn Command {str9xpec options_read} num
  5037. Read str9 option bytes.
  5038. @end deffn
  5039. @deffn Command {str9xpec options_write} num
  5040. Write str9 option bytes.
  5041. @end deffn
  5042. @deffn Command {str9xpec unlock} num
  5043. unlock str9 device.
  5044. @end deffn
  5045. @end deffn
  5046. @deffn {Flash Driver} tms470
  5047. Most members of the TMS470 microcontroller family from Texas Instruments
  5048. include internal flash and use ARM7TDMI cores.
  5049. This driver doesn't require the chip and bus width to be specified.
  5050. Some tms470-specific commands are defined:
  5051. @deffn Command {tms470 flash_keyset} key0 key1 key2 key3
  5052. Saves programming keys in a register, to enable flash erase and write commands.
  5053. @end deffn
  5054. @deffn Command {tms470 osc_mhz} clock_mhz
  5055. Reports the clock speed, which is used to calculate timings.
  5056. @end deffn
  5057. @deffn Command {tms470 plldis} (0|1)
  5058. Disables (@var{1}) or enables (@var{0}) use of the PLL to speed up
  5059. the flash clock.
  5060. @end deffn
  5061. @end deffn
  5062. @deffn {Flash Driver} xmc1xxx
  5063. All members of the XMC1xxx microcontroller family from Infineon.
  5064. This driver does not require the chip and bus width to be specified.
  5065. @end deffn
  5066. @deffn {Flash Driver} xmc4xxx
  5067. All members of the XMC4xxx microcontroller family from Infineon.
  5068. This driver does not require the chip and bus width to be specified.
  5069. Some xmc4xxx-specific commands are defined:
  5070. @deffn Command {xmc4xxx flash_password} bank_id passwd1 passwd2
  5071. Saves flash protection passwords which are used to lock the user flash
  5072. @end deffn
  5073. @deffn Command {xmc4xxx flash_unprotect} bank_id user_level[0-1]
  5074. Removes Flash write protection from the selected user bank
  5075. @end deffn
  5076. @end deffn
  5077. @section NAND Flash Commands
  5078. @cindex NAND
  5079. Compared to NOR or SPI flash, NAND devices are inexpensive
  5080. and high density. Today's NAND chips, and multi-chip modules,
  5081. commonly hold multiple GigaBytes of data.
  5082. NAND chips consist of a number of ``erase blocks'' of a given
  5083. size (such as 128 KBytes), each of which is divided into a
  5084. number of pages (of perhaps 512 or 2048 bytes each). Each
  5085. page of a NAND flash has an ``out of band'' (OOB) area to hold
  5086. Error Correcting Code (ECC) and other metadata, usually 16 bytes
  5087. of OOB for every 512 bytes of page data.
  5088. One key characteristic of NAND flash is that its error rate
  5089. is higher than that of NOR flash. In normal operation, that
  5090. ECC is used to correct and detect errors. However, NAND
  5091. blocks can also wear out and become unusable; those blocks
  5092. are then marked "bad". NAND chips are even shipped from the
  5093. manufacturer with a few bad blocks. The highest density chips
  5094. use a technology (MLC) that wears out more quickly, so ECC
  5095. support is increasingly important as a way to detect blocks
  5096. that have begun to fail, and help to preserve data integrity
  5097. with techniques such as wear leveling.
  5098. Software is used to manage the ECC. Some controllers don't
  5099. support ECC directly; in those cases, software ECC is used.
  5100. Other controllers speed up the ECC calculations with hardware.
  5101. Single-bit error correction hardware is routine. Controllers
  5102. geared for newer MLC chips may correct 4 or more errors for
  5103. every 512 bytes of data.
  5104. You will need to make sure that any data you write using
  5105. OpenOCD includes the apppropriate kind of ECC. For example,
  5106. that may mean passing the @code{oob_softecc} flag when
  5107. writing NAND data, or ensuring that the correct hardware
  5108. ECC mode is used.
  5109. The basic steps for using NAND devices include:
  5110. @enumerate
  5111. @item Declare via the command @command{nand device}
  5112. @* Do this in a board-specific configuration file,
  5113. passing parameters as needed by the controller.
  5114. @item Configure each device using @command{nand probe}.
  5115. @* Do this only after the associated target is set up,
  5116. such as in its reset-init script or in procures defined
  5117. to access that device.
  5118. @item Operate on the flash via @command{nand subcommand}
  5119. @* Often commands to manipulate the flash are typed by a human, or run
  5120. via a script in some automated way. Common task include writing a
  5121. boot loader, operating system, or other data needed to initialize or
  5122. de-brick a board.
  5123. @end enumerate
  5124. @b{NOTE:} At the time this text was written, the largest NAND
  5125. flash fully supported by OpenOCD is 2 GiBytes (16 GiBits).
  5126. This is because the variables used to hold offsets and lengths
  5127. are only 32 bits wide.
  5128. (Larger chips may work in some cases, unless an offset or length
  5129. is larger than 0xffffffff, the largest 32-bit unsigned integer.)
  5130. Some larger devices will work, since they are actually multi-chip
  5131. modules with two smaller chips and individual chipselect lines.
  5132. @anchor{nandconfiguration}
  5133. @subsection NAND Configuration Commands
  5134. @cindex NAND configuration
  5135. NAND chips must be declared in configuration scripts,
  5136. plus some additional configuration that's done after
  5137. OpenOCD has initialized.
  5138. @deffn {Config Command} {nand device} name driver target [configparams...]
  5139. Declares a NAND device, which can be read and written to
  5140. after it has been configured through @command{nand probe}.
  5141. In OpenOCD, devices are single chips; this is unlike some
  5142. operating systems, which may manage multiple chips as if
  5143. they were a single (larger) device.
  5144. In some cases, configuring a device will activate extra
  5145. commands; see the controller-specific documentation.
  5146. @b{NOTE:} This command is not available after OpenOCD
  5147. initialization has completed. Use it in board specific
  5148. configuration files, not interactively.
  5149. @itemize @bullet
  5150. @item @var{name} ... may be used to reference the NAND bank
  5151. in most other NAND commands. A number is also available.
  5152. @item @var{driver} ... identifies the NAND controller driver
  5153. associated with the NAND device being declared.
  5154. @xref{nanddriverlist,,NAND Driver List}.
  5155. @item @var{target} ... names the target used when issuing
  5156. commands to the NAND controller.
  5157. @comment Actually, it's currently a controller-specific parameter...
  5158. @item @var{configparams} ... controllers may support, or require,
  5159. additional parameters. See the controller-specific documentation
  5160. for more information.
  5161. @end itemize
  5162. @end deffn
  5163. @deffn Command {nand list}
  5164. Prints a summary of each device declared
  5165. using @command{nand device}, numbered from zero.
  5166. Note that un-probed devices show no details.
  5167. @example
  5168. > nand list
  5169. #0: NAND 1GiB 3,3V 8-bit (Micron) pagesize: 2048, buswidth: 8,
  5170. blocksize: 131072, blocks: 8192
  5171. #1: NAND 1GiB 3,3V 8-bit (Micron) pagesize: 2048, buswidth: 8,
  5172. blocksize: 131072, blocks: 8192
  5173. >
  5174. @end example
  5175. @end deffn
  5176. @deffn Command {nand probe} num
  5177. Probes the specified device to determine key characteristics
  5178. like its page and block sizes, and how many blocks it has.
  5179. The @var{num} parameter is the value shown by @command{nand list}.
  5180. You must (successfully) probe a device before you can use
  5181. it with most other NAND commands.
  5182. @end deffn
  5183. @subsection Erasing, Reading, Writing to NAND Flash
  5184. @deffn Command {nand dump} num filename offset length [oob_option]
  5185. @cindex NAND reading
  5186. Reads binary data from the NAND device and writes it to the file,
  5187. starting at the specified offset.
  5188. The @var{num} parameter is the value shown by @command{nand list}.
  5189. Use a complete path name for @var{filename}, so you don't depend
  5190. on the directory used to start the OpenOCD server.
  5191. The @var{offset} and @var{length} must be exact multiples of the
  5192. device's page size. They describe a data region; the OOB data
  5193. associated with each such page may also be accessed.
  5194. @b{NOTE:} At the time this text was written, no error correction
  5195. was done on the data that's read, unless raw access was disabled
  5196. and the underlying NAND controller driver had a @code{read_page}
  5197. method which handled that error correction.
  5198. By default, only page data is saved to the specified file.
  5199. Use an @var{oob_option} parameter to save OOB data:
  5200. @itemize @bullet
  5201. @item no oob_* parameter
  5202. @*Output file holds only page data; OOB is discarded.
  5203. @item @code{oob_raw}
  5204. @*Output file interleaves page data and OOB data;
  5205. the file will be longer than "length" by the size of the
  5206. spare areas associated with each data page.
  5207. Note that this kind of "raw" access is different from
  5208. what's implied by @command{nand raw_access}, which just
  5209. controls whether a hardware-aware access method is used.
  5210. @item @code{oob_only}
  5211. @*Output file has only raw OOB data, and will
  5212. be smaller than "length" since it will contain only the
  5213. spare areas associated with each data page.
  5214. @end itemize
  5215. @end deffn
  5216. @deffn Command {nand erase} num [offset length]
  5217. @cindex NAND erasing
  5218. @cindex NAND programming
  5219. Erases blocks on the specified NAND device, starting at the
  5220. specified @var{offset} and continuing for @var{length} bytes.
  5221. Both of those values must be exact multiples of the device's
  5222. block size, and the region they specify must fit entirely in the chip.
  5223. If those parameters are not specified,
  5224. the whole NAND chip will be erased.
  5225. The @var{num} parameter is the value shown by @command{nand list}.
  5226. @b{NOTE:} This command will try to erase bad blocks, when told
  5227. to do so, which will probably invalidate the manufacturer's bad
  5228. block marker.
  5229. For the remainder of the current server session, @command{nand info}
  5230. will still report that the block ``is'' bad.
  5231. @end deffn
  5232. @deffn Command {nand write} num filename offset [option...]
  5233. @cindex NAND writing
  5234. @cindex NAND programming
  5235. Writes binary data from the file into the specified NAND device,
  5236. starting at the specified offset. Those pages should already
  5237. have been erased; you can't change zero bits to one bits.
  5238. The @var{num} parameter is the value shown by @command{nand list}.
  5239. Use a complete path name for @var{filename}, so you don't depend
  5240. on the directory used to start the OpenOCD server.
  5241. The @var{offset} must be an exact multiple of the device's page size.
  5242. All data in the file will be written, assuming it doesn't run
  5243. past the end of the device.
  5244. Only full pages are written, and any extra space in the last
  5245. page will be filled with 0xff bytes. (That includes OOB data,
  5246. if that's being written.)
  5247. @b{NOTE:} At the time this text was written, bad blocks are
  5248. ignored. That is, this routine will not skip bad blocks,
  5249. but will instead try to write them. This can cause problems.
  5250. Provide at most one @var{option} parameter. With some
  5251. NAND drivers, the meanings of these parameters may change
  5252. if @command{nand raw_access} was used to disable hardware ECC.
  5253. @itemize @bullet
  5254. @item no oob_* parameter
  5255. @*File has only page data, which is written.
  5256. If raw acccess is in use, the OOB area will not be written.
  5257. Otherwise, if the underlying NAND controller driver has
  5258. a @code{write_page} routine, that routine may write the OOB
  5259. with hardware-computed ECC data.
  5260. @item @code{oob_only}
  5261. @*File has only raw OOB data, which is written to the OOB area.
  5262. Each page's data area stays untouched. @i{This can be a dangerous
  5263. option}, since it can invalidate the ECC data.
  5264. You may need to force raw access to use this mode.
  5265. @item @code{oob_raw}
  5266. @*File interleaves data and OOB data, both of which are written
  5267. If raw access is enabled, the data is written first, then the
  5268. un-altered OOB.
  5269. Otherwise, if the underlying NAND controller driver has
  5270. a @code{write_page} routine, that routine may modify the OOB
  5271. before it's written, to include hardware-computed ECC data.
  5272. @item @code{oob_softecc}
  5273. @*File has only page data, which is written.
  5274. The OOB area is filled with 0xff, except for a standard 1-bit
  5275. software ECC code stored in conventional locations.
  5276. You might need to force raw access to use this mode, to prevent
  5277. the underlying driver from applying hardware ECC.
  5278. @item @code{oob_softecc_kw}
  5279. @*File has only page data, which is written.
  5280. The OOB area is filled with 0xff, except for a 4-bit software ECC
  5281. specific to the boot ROM in Marvell Kirkwood SoCs.
  5282. You might need to force raw access to use this mode, to prevent
  5283. the underlying driver from applying hardware ECC.
  5284. @end itemize
  5285. @end deffn
  5286. @deffn Command {nand verify} num filename offset [option...]
  5287. @cindex NAND verification
  5288. @cindex NAND programming
  5289. Verify the binary data in the file has been programmed to the
  5290. specified NAND device, starting at the specified offset.
  5291. The @var{num} parameter is the value shown by @command{nand list}.
  5292. Use a complete path name for @var{filename}, so you don't depend
  5293. on the directory used to start the OpenOCD server.
  5294. The @var{offset} must be an exact multiple of the device's page size.
  5295. All data in the file will be read and compared to the contents of the
  5296. flash, assuming it doesn't run past the end of the device.
  5297. As with @command{nand write}, only full pages are verified, so any extra
  5298. space in the last page will be filled with 0xff bytes.
  5299. The same @var{options} accepted by @command{nand write},
  5300. and the file will be processed similarly to produce the buffers that
  5301. can be compared against the contents produced from @command{nand dump}.
  5302. @b{NOTE:} This will not work when the underlying NAND controller
  5303. driver's @code{write_page} routine must update the OOB with a
  5304. hardward-computed ECC before the data is written. This limitation may
  5305. be removed in a future release.
  5306. @end deffn
  5307. @subsection Other NAND commands
  5308. @cindex NAND other commands
  5309. @deffn Command {nand check_bad_blocks} num [offset length]
  5310. Checks for manufacturer bad block markers on the specified NAND
  5311. device. If no parameters are provided, checks the whole
  5312. device; otherwise, starts at the specified @var{offset} and
  5313. continues for @var{length} bytes.
  5314. Both of those values must be exact multiples of the device's
  5315. block size, and the region they specify must fit entirely in the chip.
  5316. The @var{num} parameter is the value shown by @command{nand list}.
  5317. @b{NOTE:} Before using this command you should force raw access
  5318. with @command{nand raw_access enable} to ensure that the underlying
  5319. driver will not try to apply hardware ECC.
  5320. @end deffn
  5321. @deffn Command {nand info} num
  5322. The @var{num} parameter is the value shown by @command{nand list}.
  5323. This prints the one-line summary from "nand list", plus for
  5324. devices which have been probed this also prints any known
  5325. status for each block.
  5326. @end deffn
  5327. @deffn Command {nand raw_access} num (@option{enable}|@option{disable})
  5328. Sets or clears an flag affecting how page I/O is done.
  5329. The @var{num} parameter is the value shown by @command{nand list}.
  5330. This flag is cleared (disabled) by default, but changing that
  5331. value won't affect all NAND devices. The key factor is whether
  5332. the underlying driver provides @code{read_page} or @code{write_page}
  5333. methods. If it doesn't provide those methods, the setting of
  5334. this flag is irrelevant; all access is effectively ``raw''.
  5335. When those methods exist, they are normally used when reading
  5336. data (@command{nand dump} or reading bad block markers) or
  5337. writing it (@command{nand write}). However, enabling
  5338. raw access (setting the flag) prevents use of those methods,
  5339. bypassing hardware ECC logic.
  5340. @i{This can be a dangerous option}, since writing blocks
  5341. with the wrong ECC data can cause them to be marked as bad.
  5342. @end deffn
  5343. @anchor{nanddriverlist}
  5344. @subsection NAND Driver List
  5345. As noted above, the @command{nand device} command allows
  5346. driver-specific options and behaviors.
  5347. Some controllers also activate controller-specific commands.
  5348. @deffn {NAND Driver} at91sam9
  5349. This driver handles the NAND controllers found on AT91SAM9 family chips from
  5350. Atmel. It takes two extra parameters: address of the NAND chip;
  5351. address of the ECC controller.
  5352. @example
  5353. nand device $NANDFLASH at91sam9 $CHIPNAME 0x40000000 0xfffffe800
  5354. @end example
  5355. AT91SAM9 chips support single-bit ECC hardware. The @code{write_page} and
  5356. @code{read_page} methods are used to utilize the ECC hardware unless they are
  5357. disabled by using the @command{nand raw_access} command. There are four
  5358. additional commands that are needed to fully configure the AT91SAM9 NAND
  5359. controller. Two are optional; most boards use the same wiring for ALE/CLE:
  5360. @deffn Command {at91sam9 cle} num addr_line
  5361. Configure the address line used for latching commands. The @var{num}
  5362. parameter is the value shown by @command{nand list}.
  5363. @end deffn
  5364. @deffn Command {at91sam9 ale} num addr_line
  5365. Configure the address line used for latching addresses. The @var{num}
  5366. parameter is the value shown by @command{nand list}.
  5367. @end deffn
  5368. For the next two commands, it is assumed that the pins have already been
  5369. properly configured for input or output.
  5370. @deffn Command {at91sam9 rdy_busy} num pio_base_addr pin
  5371. Configure the RDY/nBUSY input from the NAND device. The @var{num}
  5372. parameter is the value shown by @command{nand list}. @var{pio_base_addr}
  5373. is the base address of the PIO controller and @var{pin} is the pin number.
  5374. @end deffn
  5375. @deffn Command {at91sam9 ce} num pio_base_addr pin
  5376. Configure the chip enable input to the NAND device. The @var{num}
  5377. parameter is the value shown by @command{nand list}. @var{pio_base_addr}
  5378. is the base address of the PIO controller and @var{pin} is the pin number.
  5379. @end deffn
  5380. @end deffn
  5381. @deffn {NAND Driver} davinci
  5382. This driver handles the NAND controllers found on DaVinci family
  5383. chips from Texas Instruments.
  5384. It takes three extra parameters:
  5385. address of the NAND chip;
  5386. hardware ECC mode to use (@option{hwecc1},
  5387. @option{hwecc4}, @option{hwecc4_infix});
  5388. address of the AEMIF controller on this processor.
  5389. @example
  5390. nand device davinci dm355.arm 0x02000000 hwecc4 0x01e10000
  5391. @end example
  5392. All DaVinci processors support the single-bit ECC hardware,
  5393. and newer ones also support the four-bit ECC hardware.
  5394. The @code{write_page} and @code{read_page} methods are used
  5395. to implement those ECC modes, unless they are disabled using
  5396. the @command{nand raw_access} command.
  5397. @end deffn
  5398. @deffn {NAND Driver} lpc3180
  5399. These controllers require an extra @command{nand device}
  5400. parameter: the clock rate used by the controller.
  5401. @deffn Command {lpc3180 select} num [mlc|slc]
  5402. Configures use of the MLC or SLC controller mode.
  5403. MLC implies use of hardware ECC.
  5404. The @var{num} parameter is the value shown by @command{nand list}.
  5405. @end deffn
  5406. At this writing, this driver includes @code{write_page}
  5407. and @code{read_page} methods. Using @command{nand raw_access}
  5408. to disable those methods will prevent use of hardware ECC
  5409. in the MLC controller mode, but won't change SLC behavior.
  5410. @end deffn
  5411. @comment current lpc3180 code won't issue 5-byte address cycles
  5412. @deffn {NAND Driver} mx3
  5413. This driver handles the NAND controller in i.MX31. The mxc driver
  5414. should work for this chip aswell.
  5415. @end deffn
  5416. @deffn {NAND Driver} mxc
  5417. This driver handles the NAND controller found in Freescale i.MX
  5418. chips. It has support for v1 (i.MX27 and i.MX31) and v2 (i.MX35).
  5419. The driver takes 3 extra arguments, chip (@option{mx27},
  5420. @option{mx31}, @option{mx35}), ecc (@option{noecc}, @option{hwecc})
  5421. and optionally if bad block information should be swapped between
  5422. main area and spare area (@option{biswap}), defaults to off.
  5423. @example
  5424. nand device mx35.nand mxc imx35.cpu mx35 hwecc biswap
  5425. @end example
  5426. @deffn Command {mxc biswap} bank_num [enable|disable]
  5427. Turns on/off bad block information swaping from main area,
  5428. without parameter query status.
  5429. @end deffn
  5430. @end deffn
  5431. @deffn {NAND Driver} orion
  5432. These controllers require an extra @command{nand device}
  5433. parameter: the address of the controller.
  5434. @example
  5435. nand device orion 0xd8000000
  5436. @end example
  5437. These controllers don't define any specialized commands.
  5438. At this writing, their drivers don't include @code{write_page}
  5439. or @code{read_page} methods, so @command{nand raw_access} won't
  5440. change any behavior.
  5441. @end deffn
  5442. @deffn {NAND Driver} s3c2410
  5443. @deffnx {NAND Driver} s3c2412
  5444. @deffnx {NAND Driver} s3c2440
  5445. @deffnx {NAND Driver} s3c2443
  5446. @deffnx {NAND Driver} s3c6400
  5447. These S3C family controllers don't have any special
  5448. @command{nand device} options, and don't define any
  5449. specialized commands.
  5450. At this writing, their drivers don't include @code{write_page}
  5451. or @code{read_page} methods, so @command{nand raw_access} won't
  5452. change any behavior.
  5453. @end deffn
  5454. @section mFlash
  5455. @subsection mFlash Configuration
  5456. @cindex mFlash Configuration
  5457. @deffn {Config Command} {mflash bank} soc base RST_pin target
  5458. Configures a mflash for @var{soc} host bank at
  5459. address @var{base}.
  5460. The pin number format depends on the host GPIO naming convention.
  5461. Currently, the mflash driver supports s3c2440 and pxa270.
  5462. Example for s3c2440 mflash where @var{RST pin} is GPIO B1:
  5463. @example
  5464. mflash bank $_FLASHNAME s3c2440 0x10000000 1b 0
  5465. @end example
  5466. Example for pxa270 mflash where @var{RST pin} is GPIO 43:
  5467. @example
  5468. mflash bank $_FLASHNAME pxa270 0x08000000 43 0
  5469. @end example
  5470. @end deffn
  5471. @subsection mFlash commands
  5472. @cindex mFlash commands
  5473. @deffn Command {mflash config pll} frequency
  5474. Configure mflash PLL.
  5475. The @var{frequency} is the mflash input frequency, in Hz.
  5476. Issuing this command will erase mflash's whole internal nand and write new pll.
  5477. After this command, mflash needs power-on-reset for normal operation.
  5478. If pll was newly configured, storage and boot(optional) info also need to be update.
  5479. @end deffn
  5480. @deffn Command {mflash config boot}
  5481. Configure bootable option.
  5482. If bootable option is set, mflash offer the first 8 sectors
  5483. (4kB) for boot.
  5484. @end deffn
  5485. @deffn Command {mflash config storage}
  5486. Configure storage information.
  5487. For the normal storage operation, this information must be
  5488. written.
  5489. @end deffn
  5490. @deffn Command {mflash dump} num filename offset size
  5491. Dump @var{size} bytes, starting at @var{offset} bytes from the
  5492. beginning of the bank @var{num}, to the file named @var{filename}.
  5493. @end deffn
  5494. @deffn Command {mflash probe}
  5495. Probe mflash.
  5496. @end deffn
  5497. @deffn Command {mflash write} num filename offset
  5498. Write the binary file @var{filename} to mflash bank @var{num}, starting at
  5499. @var{offset} bytes from the beginning of the bank.
  5500. @end deffn
  5501. @node Flash Programming
  5502. @chapter Flash Programming
  5503. OpenOCD implements numerous ways to program the target flash, whether internal or external.
  5504. Programming can be acheived by either using GDB @ref{programmingusinggdb,,Programming using GDB},
  5505. or using the cmds given in @ref{flashprogrammingcommands,,Flash Programming Commands}.
  5506. @*To simplify using the flash cmds directly a jimtcl script is available that handles the programming and verify stage.
  5507. OpenOCD will program/verify/reset the target and optionally shutdown.
  5508. The script is executed as follows and by default the following actions will be peformed.
  5509. @enumerate
  5510. @item 'init' is executed.
  5511. @item 'reset init' is called to reset and halt the target, any 'reset init' scripts are executed.
  5512. @item @code{flash write_image} is called to erase and write any flash using the filename given.
  5513. @item @code{verify_image} is called if @option{verify} parameter is given.
  5514. @item @code{reset run} is called if @option{reset} parameter is given.
  5515. @item OpenOCD is shutdown if @option{exit} parameter is given.
  5516. @end enumerate
  5517. An example of usage is given below. @xref{program}.
  5518. @example
  5519. # program and verify using elf/hex/s19. verify and reset
  5520. # are optional parameters
  5521. openocd -f board/stm32f3discovery.cfg \
  5522. -c "program filename.elf verify reset exit"
  5523. # binary files need the flash address passing
  5524. openocd -f board/stm32f3discovery.cfg \
  5525. -c "program filename.bin exit 0x08000000"
  5526. @end example
  5527. @node PLD/FPGA Commands
  5528. @chapter PLD/FPGA Commands
  5529. @cindex PLD
  5530. @cindex FPGA
  5531. Programmable Logic Devices (PLDs) and the more flexible
  5532. Field Programmable Gate Arrays (FPGAs) are both types of programmable hardware.
  5533. OpenOCD can support programming them.
  5534. Although PLDs are generally restrictive (cells are less functional, and
  5535. there are no special purpose cells for memory or computational tasks),
  5536. they share the same OpenOCD infrastructure.
  5537. Accordingly, both are called PLDs here.
  5538. @section PLD/FPGA Configuration and Commands
  5539. As it does for JTAG TAPs, debug targets, and flash chips (both NOR and NAND),
  5540. OpenOCD maintains a list of PLDs available for use in various commands.
  5541. Also, each such PLD requires a driver.
  5542. They are referenced by the number shown by the @command{pld devices} command,
  5543. and new PLDs are defined by @command{pld device driver_name}.
  5544. @deffn {Config Command} {pld device} driver_name tap_name [driver_options]
  5545. Defines a new PLD device, supported by driver @var{driver_name},
  5546. using the TAP named @var{tap_name}.
  5547. The driver may make use of any @var{driver_options} to configure its
  5548. behavior.
  5549. @end deffn
  5550. @deffn {Command} {pld devices}
  5551. Lists the PLDs and their numbers.
  5552. @end deffn
  5553. @deffn {Command} {pld load} num filename
  5554. Loads the file @file{filename} into the PLD identified by @var{num}.
  5555. The file format must be inferred by the driver.
  5556. @end deffn
  5557. @section PLD/FPGA Drivers, Options, and Commands
  5558. Drivers may support PLD-specific options to the @command{pld device}
  5559. definition command, and may also define commands usable only with
  5560. that particular type of PLD.
  5561. @deffn {FPGA Driver} virtex2 [no_jstart]
  5562. Virtex-II is a family of FPGAs sold by Xilinx.
  5563. It supports the IEEE 1532 standard for In-System Configuration (ISC).
  5564. If @var{no_jstart} is non-zero, the JSTART instruction is not used after
  5565. loading the bitstream. While required for Series2, Series3, and Series6, it
  5566. breaks bitstream loading on Series7.
  5567. @deffn {Command} {virtex2 read_stat} num
  5568. Reads and displays the Virtex-II status register (STAT)
  5569. for FPGA @var{num}.
  5570. @end deffn
  5571. @end deffn
  5572. @node General Commands
  5573. @chapter General Commands
  5574. @cindex commands
  5575. The commands documented in this chapter here are common commands that
  5576. you, as a human, may want to type and see the output of. Configuration type
  5577. commands are documented elsewhere.
  5578. Intent:
  5579. @itemize @bullet
  5580. @item @b{Source Of Commands}
  5581. @* OpenOCD commands can occur in a configuration script (discussed
  5582. elsewhere) or typed manually by a human or supplied programatically,
  5583. or via one of several TCP/IP Ports.
  5584. @item @b{From the human}
  5585. @* A human should interact with the telnet interface (default port: 4444)
  5586. or via GDB (default port 3333).
  5587. To issue commands from within a GDB session, use the @option{monitor}
  5588. command, e.g. use @option{monitor poll} to issue the @option{poll}
  5589. command. All output is relayed through the GDB session.
  5590. @item @b{Machine Interface}
  5591. The Tcl interface's intent is to be a machine interface. The default Tcl
  5592. port is 5555.
  5593. @end itemize
  5594. @section Daemon Commands
  5595. @deffn {Command} exit
  5596. Exits the current telnet session.
  5597. @end deffn
  5598. @deffn {Command} help [string]
  5599. With no parameters, prints help text for all commands.
  5600. Otherwise, prints each helptext containing @var{string}.
  5601. Not every command provides helptext.
  5602. Configuration commands, and commands valid at any time, are
  5603. explicitly noted in parenthesis.
  5604. In most cases, no such restriction is listed; this indicates commands
  5605. which are only available after the configuration stage has completed.
  5606. @end deffn
  5607. @deffn Command sleep msec [@option{busy}]
  5608. Wait for at least @var{msec} milliseconds before resuming.
  5609. If @option{busy} is passed, busy-wait instead of sleeping.
  5610. (This option is strongly discouraged.)
  5611. Useful in connection with script files
  5612. (@command{script} command and @command{target_name} configuration).
  5613. @end deffn
  5614. @deffn Command shutdown [@option{error}]
  5615. Close the OpenOCD daemon, disconnecting all clients (GDB, telnet,
  5616. other). If option @option{error} is used, OpenOCD will return a
  5617. non-zero exit code to the parent process.
  5618. @end deffn
  5619. @anchor{debuglevel}
  5620. @deffn Command debug_level [n]
  5621. @cindex message level
  5622. Display debug level.
  5623. If @var{n} (from 0..3) is provided, then set it to that level.
  5624. This affects the kind of messages sent to the server log.
  5625. Level 0 is error messages only;
  5626. level 1 adds warnings;
  5627. level 2 adds informational messages;
  5628. and level 3 adds debugging messages.
  5629. The default is level 2, but that can be overridden on
  5630. the command line along with the location of that log
  5631. file (which is normally the server's standard output).
  5632. @xref{Running}.
  5633. @end deffn
  5634. @deffn Command echo [-n] message
  5635. Logs a message at "user" priority.
  5636. Output @var{message} to stdout.
  5637. Option "-n" suppresses trailing newline.
  5638. @example
  5639. echo "Downloading kernel -- please wait"
  5640. @end example
  5641. @end deffn
  5642. @deffn Command log_output [filename]
  5643. Redirect logging to @var{filename};
  5644. the initial log output channel is stderr.
  5645. @end deffn
  5646. @deffn Command add_script_search_dir [directory]
  5647. Add @var{directory} to the file/script search path.
  5648. @end deffn
  5649. @deffn Command bindto [name]
  5650. Specify address by name on which to listen for incoming TCP/IP connections.
  5651. By default, OpenOCD will listen on all available interfaces.
  5652. @end deffn
  5653. @anchor{targetstatehandling}
  5654. @section Target State handling
  5655. @cindex reset
  5656. @cindex halt
  5657. @cindex target initialization
  5658. In this section ``target'' refers to a CPU configured as
  5659. shown earlier (@pxref{CPU Configuration}).
  5660. These commands, like many, implicitly refer to
  5661. a current target which is used to perform the
  5662. various operations. The current target may be changed
  5663. by using @command{targets} command with the name of the
  5664. target which should become current.
  5665. @deffn Command reg [(number|name) [(value|'force')]]
  5666. Access a single register by @var{number} or by its @var{name}.
  5667. The target must generally be halted before access to CPU core
  5668. registers is allowed. Depending on the hardware, some other
  5669. registers may be accessible while the target is running.
  5670. @emph{With no arguments}:
  5671. list all available registers for the current target,
  5672. showing number, name, size, value, and cache status.
  5673. For valid entries, a value is shown; valid entries
  5674. which are also dirty (and will be written back later)
  5675. are flagged as such.
  5676. @emph{With number/name}: display that register's value.
  5677. Use @var{force} argument to read directly from the target,
  5678. bypassing any internal cache.
  5679. @emph{With both number/name and value}: set register's value.
  5680. Writes may be held in a writeback cache internal to OpenOCD,
  5681. so that setting the value marks the register as dirty instead
  5682. of immediately flushing that value. Resuming CPU execution
  5683. (including by single stepping) or otherwise activating the
  5684. relevant module will flush such values.
  5685. Cores may have surprisingly many registers in their
  5686. Debug and trace infrastructure:
  5687. @example
  5688. > reg
  5689. ===== ARM registers
  5690. (0) r0 (/32): 0x0000D3C2 (dirty)
  5691. (1) r1 (/32): 0xFD61F31C
  5692. (2) r2 (/32)
  5693. ...
  5694. (164) ETM_contextid_comparator_mask (/32)
  5695. >
  5696. @end example
  5697. @end deffn
  5698. @deffn Command halt [ms]
  5699. @deffnx Command wait_halt [ms]
  5700. The @command{halt} command first sends a halt request to the target,
  5701. which @command{wait_halt} doesn't.
  5702. Otherwise these behave the same: wait up to @var{ms} milliseconds,
  5703. or 5 seconds if there is no parameter, for the target to halt
  5704. (and enter debug mode).
  5705. Using 0 as the @var{ms} parameter prevents OpenOCD from waiting.
  5706. @quotation Warning
  5707. On ARM cores, software using the @emph{wait for interrupt} operation
  5708. often blocks the JTAG access needed by a @command{halt} command.
  5709. This is because that operation also puts the core into a low
  5710. power mode by gating the core clock;
  5711. but the core clock is needed to detect JTAG clock transitions.
  5712. One partial workaround uses adaptive clocking: when the core is
  5713. interrupted the operation completes, then JTAG clocks are accepted
  5714. at least until the interrupt handler completes.
  5715. However, this workaround is often unusable since the processor, board,
  5716. and JTAG adapter must all support adaptive JTAG clocking.
  5717. Also, it can't work until an interrupt is issued.
  5718. A more complete workaround is to not use that operation while you
  5719. work with a JTAG debugger.
  5720. Tasking environments generaly have idle loops where the body is the
  5721. @emph{wait for interrupt} operation.
  5722. (On older cores, it is a coprocessor action;
  5723. newer cores have a @option{wfi} instruction.)
  5724. Such loops can just remove that operation, at the cost of higher
  5725. power consumption (because the CPU is needlessly clocked).
  5726. @end quotation
  5727. @end deffn
  5728. @deffn Command resume [address]
  5729. Resume the target at its current code position,
  5730. or the optional @var{address} if it is provided.
  5731. OpenOCD will wait 5 seconds for the target to resume.
  5732. @end deffn
  5733. @deffn Command step [address]
  5734. Single-step the target at its current code position,
  5735. or the optional @var{address} if it is provided.
  5736. @end deffn
  5737. @anchor{resetcommand}
  5738. @deffn Command reset
  5739. @deffnx Command {reset run}
  5740. @deffnx Command {reset halt}
  5741. @deffnx Command {reset init}
  5742. Perform as hard a reset as possible, using SRST if possible.
  5743. @emph{All defined targets will be reset, and target
  5744. events will fire during the reset sequence.}
  5745. The optional parameter specifies what should
  5746. happen after the reset.
  5747. If there is no parameter, a @command{reset run} is executed.
  5748. The other options will not work on all systems.
  5749. @xref{Reset Configuration}.
  5750. @itemize @minus
  5751. @item @b{run} Let the target run
  5752. @item @b{halt} Immediately halt the target
  5753. @item @b{init} Immediately halt the target, and execute the reset-init script
  5754. @end itemize
  5755. @end deffn
  5756. @deffn Command soft_reset_halt
  5757. Requesting target halt and executing a soft reset. This is often used
  5758. when a target cannot be reset and halted. The target, after reset is
  5759. released begins to execute code. OpenOCD attempts to stop the CPU and
  5760. then sets the program counter back to the reset vector. Unfortunately
  5761. the code that was executed may have left the hardware in an unknown
  5762. state.
  5763. @end deffn
  5764. @section I/O Utilities
  5765. These commands are available when
  5766. OpenOCD is built with @option{--enable-ioutil}.
  5767. They are mainly useful on embedded targets,
  5768. notably the ZY1000.
  5769. Hosts with operating systems have complementary tools.
  5770. @emph{Note:} there are several more such commands.
  5771. @deffn Command append_file filename [string]*
  5772. Appends the @var{string} parameters to
  5773. the text file @file{filename}.
  5774. Each string except the last one is followed by one space.
  5775. The last string is followed by a newline.
  5776. @end deffn
  5777. @deffn Command cat filename
  5778. Reads and displays the text file @file{filename}.
  5779. @end deffn
  5780. @deffn Command cp src_filename dest_filename
  5781. Copies contents from the file @file{src_filename}
  5782. into @file{dest_filename}.
  5783. @end deffn
  5784. @deffn Command ip
  5785. @emph{No description provided.}
  5786. @end deffn
  5787. @deffn Command ls
  5788. @emph{No description provided.}
  5789. @end deffn
  5790. @deffn Command mac
  5791. @emph{No description provided.}
  5792. @end deffn
  5793. @deffn Command meminfo
  5794. Display available RAM memory on OpenOCD host.
  5795. Used in OpenOCD regression testing scripts.
  5796. @end deffn
  5797. @deffn Command peek
  5798. @emph{No description provided.}
  5799. @end deffn
  5800. @deffn Command poke
  5801. @emph{No description provided.}
  5802. @end deffn
  5803. @deffn Command rm filename
  5804. @c "rm" has both normal and Jim-level versions??
  5805. Unlinks the file @file{filename}.
  5806. @end deffn
  5807. @deffn Command trunc filename
  5808. Removes all data in the file @file{filename}.
  5809. @end deffn
  5810. @anchor{memoryaccess}
  5811. @section Memory access commands
  5812. @cindex memory access
  5813. These commands allow accesses of a specific size to the memory
  5814. system. Often these are used to configure the current target in some
  5815. special way. For example - one may need to write certain values to the
  5816. SDRAM controller to enable SDRAM.
  5817. @enumerate
  5818. @item Use the @command{targets} (plural) command
  5819. to change the current target.
  5820. @item In system level scripts these commands are deprecated.
  5821. Please use their TARGET object siblings to avoid making assumptions
  5822. about what TAP is the current target, or about MMU configuration.
  5823. @end enumerate
  5824. @deffn Command mdw [phys] addr [count]
  5825. @deffnx Command mdh [phys] addr [count]
  5826. @deffnx Command mdb [phys] addr [count]
  5827. Display contents of address @var{addr}, as
  5828. 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
  5829. or 8-bit bytes (@command{mdb}).
  5830. When the current target has an MMU which is present and active,
  5831. @var{addr} is interpreted as a virtual address.
  5832. Otherwise, or if the optional @var{phys} flag is specified,
  5833. @var{addr} is interpreted as a physical address.
  5834. If @var{count} is specified, displays that many units.
  5835. (If you want to manipulate the data instead of displaying it,
  5836. see the @code{mem2array} primitives.)
  5837. @end deffn
  5838. @deffn Command mww [phys] addr word
  5839. @deffnx Command mwh [phys] addr halfword
  5840. @deffnx Command mwb [phys] addr byte
  5841. Writes the specified @var{word} (32 bits),
  5842. @var{halfword} (16 bits), or @var{byte} (8-bit) value,
  5843. at the specified address @var{addr}.
  5844. When the current target has an MMU which is present and active,
  5845. @var{addr} is interpreted as a virtual address.
  5846. Otherwise, or if the optional @var{phys} flag is specified,
  5847. @var{addr} is interpreted as a physical address.
  5848. @end deffn
  5849. @anchor{imageaccess}
  5850. @section Image loading commands
  5851. @cindex image loading
  5852. @cindex image dumping
  5853. @deffn Command {dump_image} filename address size
  5854. Dump @var{size} bytes of target memory starting at @var{address} to the
  5855. binary file named @var{filename}.
  5856. @end deffn
  5857. @deffn Command {fast_load}
  5858. Loads an image stored in memory by @command{fast_load_image} to the
  5859. current target. Must be preceeded by fast_load_image.
  5860. @end deffn
  5861. @deffn Command {fast_load_image} filename address [@option{bin}|@option{ihex}|@option{elf}|@option{s19}]
  5862. Normally you should be using @command{load_image} or GDB load. However, for
  5863. testing purposes or when I/O overhead is significant(OpenOCD running on an embedded
  5864. host), storing the image in memory and uploading the image to the target
  5865. can be a way to upload e.g. multiple debug sessions when the binary does not change.
  5866. Arguments are the same as @command{load_image}, but the image is stored in OpenOCD host
  5867. memory, i.e. does not affect target. This approach is also useful when profiling
  5868. target programming performance as I/O and target programming can easily be profiled
  5869. separately.
  5870. @end deffn
  5871. @deffn Command {load_image} filename address [[@option{bin}|@option{ihex}|@option{elf}|@option{s19}] @option{min_addr} @option{max_length}]
  5872. Load image from file @var{filename} to target memory offset by @var{address} from its load address.
  5873. The file format may optionally be specified
  5874. (@option{bin}, @option{ihex}, @option{elf}, or @option{s19}).
  5875. In addition the following arguments may be specifed:
  5876. @var{min_addr} - ignore data below @var{min_addr} (this is w.r.t. to the target's load address + @var{address})
  5877. @var{max_length} - maximum number of bytes to load.
  5878. @example
  5879. proc load_image_bin @{fname foffset address length @} @{
  5880. # Load data from fname filename at foffset offset to
  5881. # target at address. Load at most length bytes.
  5882. load_image $fname [expr $address - $foffset] bin \
  5883. $address $length
  5884. @}
  5885. @end example
  5886. @end deffn
  5887. @deffn Command {test_image} filename [address [@option{bin}|@option{ihex}|@option{elf}]]
  5888. Displays image section sizes and addresses
  5889. as if @var{filename} were loaded into target memory
  5890. starting at @var{address} (defaults to zero).
  5891. The file format may optionally be specified
  5892. (@option{bin}, @option{ihex}, or @option{elf})
  5893. @end deffn
  5894. @deffn Command {verify_image} filename address [@option{bin}|@option{ihex}|@option{elf}]
  5895. Verify @var{filename} against target memory starting at @var{address}.
  5896. The file format may optionally be specified
  5897. (@option{bin}, @option{ihex}, or @option{elf})
  5898. This will first attempt a comparison using a CRC checksum, if this fails it will try a binary compare.
  5899. @end deffn
  5900. @section Breakpoint and Watchpoint commands
  5901. @cindex breakpoint
  5902. @cindex watchpoint
  5903. CPUs often make debug modules accessible through JTAG, with
  5904. hardware support for a handful of code breakpoints and data
  5905. watchpoints.
  5906. In addition, CPUs almost always support software breakpoints.
  5907. @deffn Command {bp} [address len [@option{hw}]]
  5908. With no parameters, lists all active breakpoints.
  5909. Else sets a breakpoint on code execution starting
  5910. at @var{address} for @var{length} bytes.
  5911. This is a software breakpoint, unless @option{hw} is specified
  5912. in which case it will be a hardware breakpoint.
  5913. (@xref{arm9vectorcatch,,arm9 vector_catch}, or @pxref{xscalevectorcatch,,xscale vector_catch},
  5914. for similar mechanisms that do not consume hardware breakpoints.)
  5915. @end deffn
  5916. @deffn Command {rbp} address
  5917. Remove the breakpoint at @var{address}.
  5918. @end deffn
  5919. @deffn Command {rwp} address
  5920. Remove data watchpoint on @var{address}
  5921. @end deffn
  5922. @deffn Command {wp} [address len [(@option{r}|@option{w}|@option{a}) [value [mask]]]]
  5923. With no parameters, lists all active watchpoints.
  5924. Else sets a data watchpoint on data from @var{address} for @var{length} bytes.
  5925. The watch point is an "access" watchpoint unless
  5926. the @option{r} or @option{w} parameter is provided,
  5927. defining it as respectively a read or write watchpoint.
  5928. If a @var{value} is provided, that value is used when determining if
  5929. the watchpoint should trigger. The value may be first be masked
  5930. using @var{mask} to mark ``don't care'' fields.
  5931. @end deffn
  5932. @section Misc Commands
  5933. @cindex profiling
  5934. @deffn Command {profile} seconds filename [start end]
  5935. Profiling samples the CPU's program counter as quickly as possible,
  5936. which is useful for non-intrusive stochastic profiling.
  5937. Saves up to 10000 samples in @file{filename} using ``gmon.out''
  5938. format. Optional @option{start} and @option{end} parameters allow to
  5939. limit the address range.
  5940. @end deffn
  5941. @deffn Command {version}
  5942. Displays a string identifying the version of this OpenOCD server.
  5943. @end deffn
  5944. @deffn Command {virt2phys} virtual_address
  5945. Requests the current target to map the specified @var{virtual_address}
  5946. to its corresponding physical address, and displays the result.
  5947. @end deffn
  5948. @node Architecture and Core Commands
  5949. @chapter Architecture and Core Commands
  5950. @cindex Architecture Specific Commands
  5951. @cindex Core Specific Commands
  5952. Most CPUs have specialized JTAG operations to support debugging.
  5953. OpenOCD packages most such operations in its standard command framework.
  5954. Some of those operations don't fit well in that framework, so they are
  5955. exposed here as architecture or implementation (core) specific commands.
  5956. @anchor{armhardwaretracing}
  5957. @section ARM Hardware Tracing
  5958. @cindex tracing
  5959. @cindex ETM
  5960. @cindex ETB
  5961. CPUs based on ARM cores may include standard tracing interfaces,
  5962. based on an ``Embedded Trace Module'' (ETM) which sends voluminous
  5963. address and data bus trace records to a ``Trace Port''.
  5964. @itemize
  5965. @item
  5966. Development-oriented boards will sometimes provide a high speed
  5967. trace connector for collecting that data, when the particular CPU
  5968. supports such an interface.
  5969. (The standard connector is a 38-pin Mictor, with both JTAG
  5970. and trace port support.)
  5971. Those trace connectors are supported by higher end JTAG adapters
  5972. and some logic analyzer modules; frequently those modules can
  5973. buffer several megabytes of trace data.
  5974. Configuring an ETM coupled to such an external trace port belongs
  5975. in the board-specific configuration file.
  5976. @item
  5977. If the CPU doesn't provide an external interface, it probably
  5978. has an ``Embedded Trace Buffer'' (ETB) on the chip, which is a
  5979. dedicated SRAM. 4KBytes is one common ETB size.
  5980. Configuring an ETM coupled only to an ETB belongs in the CPU-specific
  5981. (target) configuration file, since it works the same on all boards.
  5982. @end itemize
  5983. ETM support in OpenOCD doesn't seem to be widely used yet.
  5984. @quotation Issues
  5985. ETM support may be buggy, and at least some @command{etm config}
  5986. parameters should be detected by asking the ETM for them.
  5987. ETM trigger events could also implement a kind of complex
  5988. hardware breakpoint, much more powerful than the simple
  5989. watchpoint hardware exported by EmbeddedICE modules.
  5990. @emph{Such breakpoints can be triggered even when using the
  5991. dummy trace port driver}.
  5992. It seems like a GDB hookup should be possible,
  5993. as well as tracing only during specific states
  5994. (perhaps @emph{handling IRQ 23} or @emph{calls foo()}).
  5995. There should be GUI tools to manipulate saved trace data and help
  5996. analyse it in conjunction with the source code.
  5997. It's unclear how much of a common interface is shared
  5998. with the current XScale trace support, or should be
  5999. shared with eventual Nexus-style trace module support.
  6000. At this writing (November 2009) only ARM7, ARM9, and ARM11 support
  6001. for ETM modules is available. The code should be able to
  6002. work with some newer cores; but not all of them support
  6003. this original style of JTAG access.
  6004. @end quotation
  6005. @subsection ETM Configuration
  6006. ETM setup is coupled with the trace port driver configuration.
  6007. @deffn {Config Command} {etm config} target width mode clocking driver
  6008. Declares the ETM associated with @var{target}, and associates it
  6009. with a given trace port @var{driver}. @xref{traceportdrivers,,Trace Port Drivers}.
  6010. Several of the parameters must reflect the trace port capabilities,
  6011. which are a function of silicon capabilties (exposed later
  6012. using @command{etm info}) and of what hardware is connected to
  6013. that port (such as an external pod, or ETB).
  6014. The @var{width} must be either 4, 8, or 16,
  6015. except with ETMv3.0 and newer modules which may also
  6016. support 1, 2, 24, 32, 48, and 64 bit widths.
  6017. (With those versions, @command{etm info} also shows whether
  6018. the selected port width and mode are supported.)
  6019. The @var{mode} must be @option{normal}, @option{multiplexed},
  6020. or @option{demultiplexed}.
  6021. The @var{clocking} must be @option{half} or @option{full}.
  6022. @quotation Warning
  6023. With ETMv3.0 and newer, the bits set with the @var{mode} and
  6024. @var{clocking} parameters both control the mode.
  6025. This modified mode does not map to the values supported by
  6026. previous ETM modules, so this syntax is subject to change.
  6027. @end quotation
  6028. @quotation Note
  6029. You can see the ETM registers using the @command{reg} command.
  6030. Not all possible registers are present in every ETM.
  6031. Most of the registers are write-only, and are used to configure
  6032. what CPU activities are traced.
  6033. @end quotation
  6034. @end deffn
  6035. @deffn Command {etm info}
  6036. Displays information about the current target's ETM.
  6037. This includes resource counts from the @code{ETM_CONFIG} register,
  6038. as well as silicon capabilities (except on rather old modules).
  6039. from the @code{ETM_SYS_CONFIG} register.
  6040. @end deffn
  6041. @deffn Command {etm status}
  6042. Displays status of the current target's ETM and trace port driver:
  6043. is the ETM idle, or is it collecting data?
  6044. Did trace data overflow?
  6045. Was it triggered?
  6046. @end deffn
  6047. @deffn Command {etm tracemode} [type context_id_bits cycle_accurate branch_output]
  6048. Displays what data that ETM will collect.
  6049. If arguments are provided, first configures that data.
  6050. When the configuration changes, tracing is stopped
  6051. and any buffered trace data is invalidated.
  6052. @itemize
  6053. @item @var{type} ... describing how data accesses are traced,
  6054. when they pass any ViewData filtering that that was set up.
  6055. The value is one of
  6056. @option{none} (save nothing),
  6057. @option{data} (save data),
  6058. @option{address} (save addresses),
  6059. @option{all} (save data and addresses)
  6060. @item @var{context_id_bits} ... 0, 8, 16, or 32
  6061. @item @var{cycle_accurate} ... @option{enable} or @option{disable}
  6062. cycle-accurate instruction tracing.
  6063. Before ETMv3, enabling this causes much extra data to be recorded.
  6064. @item @var{branch_output} ... @option{enable} or @option{disable}.
  6065. Disable this unless you need to try reconstructing the instruction
  6066. trace stream without an image of the code.
  6067. @end itemize
  6068. @end deffn
  6069. @deffn Command {etm trigger_debug} (@option{enable}|@option{disable})
  6070. Displays whether ETM triggering debug entry (like a breakpoint) is
  6071. enabled or disabled, after optionally modifying that configuration.
  6072. The default behaviour is @option{disable}.
  6073. Any change takes effect after the next @command{etm start}.
  6074. By using script commands to configure ETM registers, you can make the
  6075. processor enter debug state automatically when certain conditions,
  6076. more complex than supported by the breakpoint hardware, happen.
  6077. @end deffn
  6078. @subsection ETM Trace Operation
  6079. After setting up the ETM, you can use it to collect data.
  6080. That data can be exported to files for later analysis.
  6081. It can also be parsed with OpenOCD, for basic sanity checking.
  6082. To configure what is being traced, you will need to write
  6083. various trace registers using @command{reg ETM_*} commands.
  6084. For the definitions of these registers, read ARM publication
  6085. @emph{IHI 0014, ``Embedded Trace Macrocell, Architecture Specification''}.
  6086. Be aware that most of the relevant registers are write-only,
  6087. and that ETM resources are limited. There are only a handful
  6088. of address comparators, data comparators, counters, and so on.
  6089. Examples of scenarios you might arrange to trace include:
  6090. @itemize
  6091. @item Code flow within a function, @emph{excluding} subroutines
  6092. it calls. Use address range comparators to enable tracing
  6093. for instruction access within that function's body.
  6094. @item Code flow within a function, @emph{including} subroutines
  6095. it calls. Use the sequencer and address comparators to activate
  6096. tracing on an ``entered function'' state, then deactivate it by
  6097. exiting that state when the function's exit code is invoked.
  6098. @item Code flow starting at the fifth invocation of a function,
  6099. combining one of the above models with a counter.
  6100. @item CPU data accesses to the registers for a particular device,
  6101. using address range comparators and the ViewData logic.
  6102. @item Such data accesses only during IRQ handling, combining the above
  6103. model with sequencer triggers which on entry and exit to the IRQ handler.
  6104. @item @emph{... more}
  6105. @end itemize
  6106. At this writing, September 2009, there are no Tcl utility
  6107. procedures to help set up any common tracing scenarios.
  6108. @deffn Command {etm analyze}
  6109. Reads trace data into memory, if it wasn't already present.
  6110. Decodes and prints the data that was collected.
  6111. @end deffn
  6112. @deffn Command {etm dump} filename
  6113. Stores the captured trace data in @file{filename}.
  6114. @end deffn
  6115. @deffn Command {etm image} filename [base_address] [type]
  6116. Opens an image file.
  6117. @end deffn
  6118. @deffn Command {etm load} filename
  6119. Loads captured trace data from @file{filename}.
  6120. @end deffn
  6121. @deffn Command {etm start}
  6122. Starts trace data collection.
  6123. @end deffn
  6124. @deffn Command {etm stop}
  6125. Stops trace data collection.
  6126. @end deffn
  6127. @anchor{traceportdrivers}
  6128. @subsection Trace Port Drivers
  6129. To use an ETM trace port it must be associated with a driver.
  6130. @deffn {Trace Port Driver} dummy
  6131. Use the @option{dummy} driver if you are configuring an ETM that's
  6132. not connected to anything (on-chip ETB or off-chip trace connector).
  6133. @emph{This driver lets OpenOCD talk to the ETM, but it does not expose
  6134. any trace data collection.}
  6135. @deffn {Config Command} {etm_dummy config} target
  6136. Associates the ETM for @var{target} with a dummy driver.
  6137. @end deffn
  6138. @end deffn
  6139. @deffn {Trace Port Driver} etb
  6140. Use the @option{etb} driver if you are configuring an ETM
  6141. to use on-chip ETB memory.
  6142. @deffn {Config Command} {etb config} target etb_tap
  6143. Associates the ETM for @var{target} with the ETB at @var{etb_tap}.
  6144. You can see the ETB registers using the @command{reg} command.
  6145. @end deffn
  6146. @deffn Command {etb trigger_percent} [percent]
  6147. This displays, or optionally changes, ETB behavior after the
  6148. ETM's configured @emph{trigger} event fires.
  6149. It controls how much more trace data is saved after the (single)
  6150. trace trigger becomes active.
  6151. @itemize
  6152. @item The default corresponds to @emph{trace around} usage,
  6153. recording 50 percent data before the event and the rest
  6154. afterwards.
  6155. @item The minimum value of @var{percent} is 2 percent,
  6156. recording almost exclusively data before the trigger.
  6157. Such extreme @emph{trace before} usage can help figure out
  6158. what caused that event to happen.
  6159. @item The maximum value of @var{percent} is 100 percent,
  6160. recording data almost exclusively after the event.
  6161. This extreme @emph{trace after} usage might help sort out
  6162. how the event caused trouble.
  6163. @end itemize
  6164. @c REVISIT allow "break" too -- enter debug mode.
  6165. @end deffn
  6166. @end deffn
  6167. @deffn {Trace Port Driver} oocd_trace
  6168. This driver isn't available unless OpenOCD was explicitly configured
  6169. with the @option{--enable-oocd_trace} option. You probably don't want
  6170. to configure it unless you've built the appropriate prototype hardware;
  6171. it's @emph{proof-of-concept} software.
  6172. Use the @option{oocd_trace} driver if you are configuring an ETM that's
  6173. connected to an off-chip trace connector.
  6174. @deffn {Config Command} {oocd_trace config} target tty
  6175. Associates the ETM for @var{target} with a trace driver which
  6176. collects data through the serial port @var{tty}.
  6177. @end deffn
  6178. @deffn Command {oocd_trace resync}
  6179. Re-synchronizes with the capture clock.
  6180. @end deffn
  6181. @deffn Command {oocd_trace status}
  6182. Reports whether the capture clock is locked or not.
  6183. @end deffn
  6184. @end deffn
  6185. @section Generic ARM
  6186. @cindex ARM
  6187. These commands should be available on all ARM processors.
  6188. They are available in addition to other core-specific
  6189. commands that may be available.
  6190. @deffn Command {arm core_state} [@option{arm}|@option{thumb}]
  6191. Displays the core_state, optionally changing it to process
  6192. either @option{arm} or @option{thumb} instructions.
  6193. The target may later be resumed in the currently set core_state.
  6194. (Processors may also support the Jazelle state, but
  6195. that is not currently supported in OpenOCD.)
  6196. @end deffn
  6197. @deffn Command {arm disassemble} address [count [@option{thumb}]]
  6198. @cindex disassemble
  6199. Disassembles @var{count} instructions starting at @var{address}.
  6200. If @var{count} is not specified, a single instruction is disassembled.
  6201. If @option{thumb} is specified, or the low bit of the address is set,
  6202. Thumb2 (mixed 16/32-bit) instructions are used;
  6203. else ARM (32-bit) instructions are used.
  6204. (Processors may also support the Jazelle state, but
  6205. those instructions are not currently understood by OpenOCD.)
  6206. Note that all Thumb instructions are Thumb2 instructions,
  6207. so older processors (without Thumb2 support) will still
  6208. see correct disassembly of Thumb code.
  6209. Also, ThumbEE opcodes are the same as Thumb2,
  6210. with a handful of exceptions.
  6211. ThumbEE disassembly currently has no explicit support.
  6212. @end deffn
  6213. @deffn Command {arm mcr} pX op1 CRn CRm op2 value
  6214. Write @var{value} to a coprocessor @var{pX} register
  6215. passing parameters @var{CRn},
  6216. @var{CRm}, opcodes @var{opc1} and @var{opc2},
  6217. and using the MCR instruction.
  6218. (Parameter sequence matches the ARM instruction, but omits
  6219. an ARM register.)
  6220. @end deffn
  6221. @deffn Command {arm mrc} pX coproc op1 CRn CRm op2
  6222. Read a coprocessor @var{pX} register passing parameters @var{CRn},
  6223. @var{CRm}, opcodes @var{opc1} and @var{opc2},
  6224. and the MRC instruction.
  6225. Returns the result so it can be manipulated by Jim scripts.
  6226. (Parameter sequence matches the ARM instruction, but omits
  6227. an ARM register.)
  6228. @end deffn
  6229. @deffn Command {arm reg}
  6230. Display a table of all banked core registers, fetching the current value from every
  6231. core mode if necessary.
  6232. @end deffn
  6233. @deffn Command {arm semihosting} [@option{enable}|@option{disable}]
  6234. @cindex ARM semihosting
  6235. Display status of semihosting, after optionally changing that status.
  6236. Semihosting allows for code executing on an ARM target to use the
  6237. I/O facilities on the host computer i.e. the system where OpenOCD
  6238. is running. The target application must be linked against a library
  6239. implementing the ARM semihosting convention that forwards operation
  6240. requests by using a special SVC instruction that is trapped at the
  6241. Supervisor Call vector by OpenOCD.
  6242. @end deffn
  6243. @section ARMv4 and ARMv5 Architecture
  6244. @cindex ARMv4
  6245. @cindex ARMv5
  6246. The ARMv4 and ARMv5 architectures are widely used in embedded systems,
  6247. and introduced core parts of the instruction set in use today.
  6248. That includes the Thumb instruction set, introduced in the ARMv4T
  6249. variant.
  6250. @subsection ARM7 and ARM9 specific commands
  6251. @cindex ARM7
  6252. @cindex ARM9
  6253. These commands are specific to ARM7 and ARM9 cores, like ARM7TDMI, ARM720T,
  6254. ARM9TDMI, ARM920T or ARM926EJ-S.
  6255. They are available in addition to the ARM commands,
  6256. and any other core-specific commands that may be available.
  6257. @deffn Command {arm7_9 dbgrq} [@option{enable}|@option{disable}]
  6258. Displays the value of the flag controlling use of the
  6259. the EmbeddedIce DBGRQ signal to force entry into debug mode,
  6260. instead of breakpoints.
  6261. If a boolean parameter is provided, first assigns that flag.
  6262. This should be
  6263. safe for all but ARM7TDMI-S cores (like NXP LPC).
  6264. This feature is enabled by default on most ARM9 cores,
  6265. including ARM9TDMI, ARM920T, and ARM926EJ-S.
  6266. @end deffn
  6267. @deffn Command {arm7_9 dcc_downloads} [@option{enable}|@option{disable}]
  6268. @cindex DCC
  6269. Displays the value of the flag controlling use of the debug communications
  6270. channel (DCC) to write larger (>128 byte) amounts of memory.
  6271. If a boolean parameter is provided, first assigns that flag.
  6272. DCC downloads offer a huge speed increase, but might be
  6273. unsafe, especially with targets running at very low speeds. This command was introduced
  6274. with OpenOCD rev. 60, and requires a few bytes of working area.
  6275. @end deffn
  6276. @deffn Command {arm7_9 fast_memory_access} [@option{enable}|@option{disable}]
  6277. Displays the value of the flag controlling use of memory writes and reads
  6278. that don't check completion of the operation.
  6279. If a boolean parameter is provided, first assigns that flag.
  6280. This provides a huge speed increase, especially with USB JTAG
  6281. cables (FT2232), but might be unsafe if used with targets running at very low
  6282. speeds, like the 32kHz startup clock of an AT91RM9200.
  6283. @end deffn
  6284. @subsection ARM720T specific commands
  6285. @cindex ARM720T
  6286. These commands are available to ARM720T based CPUs,
  6287. which are implementations of the ARMv4T architecture
  6288. based on the ARM7TDMI-S integer core.
  6289. They are available in addition to the ARM and ARM7/ARM9 commands.
  6290. @deffn Command {arm720t cp15} opcode [value]
  6291. @emph{DEPRECATED -- avoid using this.
  6292. Use the @command{arm mrc} or @command{arm mcr} commands instead.}
  6293. Display cp15 register returned by the ARM instruction @var{opcode};
  6294. else if a @var{value} is provided, that value is written to that register.
  6295. The @var{opcode} should be the value of either an MRC or MCR instruction.
  6296. @end deffn
  6297. @subsection ARM9 specific commands
  6298. @cindex ARM9
  6299. ARM9-family cores are built around ARM9TDMI or ARM9E (including ARM9EJS)
  6300. integer processors.
  6301. Such cores include the ARM920T, ARM926EJ-S, and ARM966.
  6302. @c 9-june-2009: tried this on arm920t, it didn't work.
  6303. @c no-params always lists nothing caught, and that's how it acts.
  6304. @c 23-oct-2009: doesn't work _consistently_ ... as if the ICE
  6305. @c versions have different rules about when they commit writes.
  6306. @anchor{arm9vectorcatch}
  6307. @deffn Command {arm9 vector_catch} [@option{all}|@option{none}|list]
  6308. @cindex vector_catch
  6309. Vector Catch hardware provides a sort of dedicated breakpoint
  6310. for hardware events such as reset, interrupt, and abort.
  6311. You can use this to conserve normal breakpoint resources,
  6312. so long as you're not concerned with code that branches directly
  6313. to those hardware vectors.
  6314. This always finishes by listing the current configuration.
  6315. If parameters are provided, it first reconfigures the
  6316. vector catch hardware to intercept
  6317. @option{all} of the hardware vectors,
  6318. @option{none} of them,
  6319. or a list with one or more of the following:
  6320. @option{reset} @option{undef} @option{swi} @option{pabt} @option{dabt}
  6321. @option{irq} @option{fiq}.
  6322. @end deffn
  6323. @subsection ARM920T specific commands
  6324. @cindex ARM920T
  6325. These commands are available to ARM920T based CPUs,
  6326. which are implementations of the ARMv4T architecture
  6327. built using the ARM9TDMI integer core.
  6328. They are available in addition to the ARM, ARM7/ARM9,
  6329. and ARM9 commands.
  6330. @deffn Command {arm920t cache_info}
  6331. Print information about the caches found. This allows to see whether your target
  6332. is an ARM920T (2x16kByte cache) or ARM922T (2x8kByte cache).
  6333. @end deffn
  6334. @deffn Command {arm920t cp15} regnum [value]
  6335. Display cp15 register @var{regnum};
  6336. else if a @var{value} is provided, that value is written to that register.
  6337. This uses "physical access" and the register number is as
  6338. shown in bits 38..33 of table 9-9 in the ARM920T TRM.
  6339. (Not all registers can be written.)
  6340. @end deffn
  6341. @deffn Command {arm920t cp15i} opcode [value [address]]
  6342. @emph{DEPRECATED -- avoid using this.
  6343. Use the @command{arm mrc} or @command{arm mcr} commands instead.}
  6344. Interpreted access using ARM instruction @var{opcode}, which should
  6345. be the value of either an MRC or MCR instruction
  6346. (as shown tables 9-11, 9-12, and 9-13 in the ARM920T TRM).
  6347. If no @var{value} is provided, the result is displayed.
  6348. Else if that value is written using the specified @var{address},
  6349. or using zero if no other address is provided.
  6350. @end deffn
  6351. @deffn Command {arm920t read_cache} filename
  6352. Dump the content of ICache and DCache to a file named @file{filename}.
  6353. @end deffn
  6354. @deffn Command {arm920t read_mmu} filename
  6355. Dump the content of the ITLB and DTLB to a file named @file{filename}.
  6356. @end deffn
  6357. @subsection ARM926ej-s specific commands
  6358. @cindex ARM926ej-s
  6359. These commands are available to ARM926ej-s based CPUs,
  6360. which are implementations of the ARMv5TEJ architecture
  6361. based on the ARM9EJ-S integer core.
  6362. They are available in addition to the ARM, ARM7/ARM9,
  6363. and ARM9 commands.
  6364. The Feroceon cores also support these commands, although
  6365. they are not built from ARM926ej-s designs.
  6366. @deffn Command {arm926ejs cache_info}
  6367. Print information about the caches found.
  6368. @end deffn
  6369. @subsection ARM966E specific commands
  6370. @cindex ARM966E
  6371. These commands are available to ARM966 based CPUs,
  6372. which are implementations of the ARMv5TE architecture.
  6373. They are available in addition to the ARM, ARM7/ARM9,
  6374. and ARM9 commands.
  6375. @deffn Command {arm966e cp15} regnum [value]
  6376. Display cp15 register @var{regnum};
  6377. else if a @var{value} is provided, that value is written to that register.
  6378. The six bit @var{regnum} values are bits 37..32 from table 7-2 of the
  6379. ARM966E-S TRM.
  6380. There is no current control over bits 31..30 from that table,
  6381. as required for BIST support.
  6382. @end deffn
  6383. @subsection XScale specific commands
  6384. @cindex XScale
  6385. Some notes about the debug implementation on the XScale CPUs:
  6386. The XScale CPU provides a special debug-only mini-instruction cache
  6387. (mini-IC) in which exception vectors and target-resident debug handler
  6388. code are placed by OpenOCD. In order to get access to the CPU, OpenOCD
  6389. must point vector 0 (the reset vector) to the entry of the debug
  6390. handler. However, this means that the complete first cacheline in the
  6391. mini-IC is marked valid, which makes the CPU fetch all exception
  6392. handlers from the mini-IC, ignoring the code in RAM.
  6393. To address this situation, OpenOCD provides the @code{xscale
  6394. vector_table} command, which allows the user to explicity write
  6395. individual entries to either the high or low vector table stored in
  6396. the mini-IC.
  6397. It is recommended to place a pc-relative indirect branch in the vector
  6398. table, and put the branch destination somewhere in memory. Doing so
  6399. makes sure the code in the vector table stays constant regardless of
  6400. code layout in memory:
  6401. @example
  6402. _vectors:
  6403. ldr pc,[pc,#0x100-8]
  6404. ldr pc,[pc,#0x100-8]
  6405. ldr pc,[pc,#0x100-8]
  6406. ldr pc,[pc,#0x100-8]
  6407. ldr pc,[pc,#0x100-8]
  6408. ldr pc,[pc,#0x100-8]
  6409. ldr pc,[pc,#0x100-8]
  6410. ldr pc,[pc,#0x100-8]
  6411. .org 0x100
  6412. .long real_reset_vector
  6413. .long real_ui_handler
  6414. .long real_swi_handler
  6415. .long real_pf_abort
  6416. .long real_data_abort
  6417. .long 0 /* unused */
  6418. .long real_irq_handler
  6419. .long real_fiq_handler
  6420. @end example
  6421. Alternatively, you may choose to keep some or all of the mini-IC
  6422. vector table entries synced with those written to memory by your
  6423. system software. The mini-IC can not be modified while the processor
  6424. is executing, but for each vector table entry not previously defined
  6425. using the @code{xscale vector_table} command, OpenOCD will copy the
  6426. value from memory to the mini-IC every time execution resumes from a
  6427. halt. This is done for both high and low vector tables (although the
  6428. table not in use may not be mapped to valid memory, and in this case
  6429. that copy operation will silently fail). This means that you will
  6430. need to briefly halt execution at some strategic point during system
  6431. start-up; e.g., after the software has initialized the vector table,
  6432. but before exceptions are enabled. A breakpoint can be used to
  6433. accomplish this once the appropriate location in the start-up code has
  6434. been identified. A watchpoint over the vector table region is helpful
  6435. in finding the location if you're not sure. Note that the same
  6436. situation exists any time the vector table is modified by the system
  6437. software.
  6438. The debug handler must be placed somewhere in the address space using
  6439. the @code{xscale debug_handler} command. The allowed locations for the
  6440. debug handler are either (0x800 - 0x1fef800) or (0xfe000800 -
  6441. 0xfffff800). The default value is 0xfe000800.
  6442. XScale has resources to support two hardware breakpoints and two
  6443. watchpoints. However, the following restrictions on watchpoint
  6444. functionality apply: (1) the value and mask arguments to the @code{wp}
  6445. command are not supported, (2) the watchpoint length must be a
  6446. power of two and not less than four, and can not be greater than the
  6447. watchpoint address, and (3) a watchpoint with a length greater than
  6448. four consumes all the watchpoint hardware resources. This means that
  6449. at any one time, you can have enabled either two watchpoints with a
  6450. length of four, or one watchpoint with a length greater than four.
  6451. These commands are available to XScale based CPUs,
  6452. which are implementations of the ARMv5TE architecture.
  6453. @deffn Command {xscale analyze_trace}
  6454. Displays the contents of the trace buffer.
  6455. @end deffn
  6456. @deffn Command {xscale cache_clean_address} address
  6457. Changes the address used when cleaning the data cache.
  6458. @end deffn
  6459. @deffn Command {xscale cache_info}
  6460. Displays information about the CPU caches.
  6461. @end deffn
  6462. @deffn Command {xscale cp15} regnum [value]
  6463. Display cp15 register @var{regnum};
  6464. else if a @var{value} is provided, that value is written to that register.
  6465. @end deffn
  6466. @deffn Command {xscale debug_handler} target address
  6467. Changes the address used for the specified target's debug handler.
  6468. @end deffn
  6469. @deffn Command {xscale dcache} [@option{enable}|@option{disable}]
  6470. Enables or disable the CPU's data cache.
  6471. @end deffn
  6472. @deffn Command {xscale dump_trace} filename
  6473. Dumps the raw contents of the trace buffer to @file{filename}.
  6474. @end deffn
  6475. @deffn Command {xscale icache} [@option{enable}|@option{disable}]
  6476. Enables or disable the CPU's instruction cache.
  6477. @end deffn
  6478. @deffn Command {xscale mmu} [@option{enable}|@option{disable}]
  6479. Enables or disable the CPU's memory management unit.
  6480. @end deffn
  6481. @deffn Command {xscale trace_buffer} [@option{enable}|@option{disable} [@option{fill} [n] | @option{wrap}]]
  6482. Displays the trace buffer status, after optionally
  6483. enabling or disabling the trace buffer
  6484. and modifying how it is emptied.
  6485. @end deffn
  6486. @deffn Command {xscale trace_image} filename [offset [type]]
  6487. Opens a trace image from @file{filename}, optionally rebasing
  6488. its segment addresses by @var{offset}.
  6489. The image @var{type} may be one of
  6490. @option{bin} (binary), @option{ihex} (Intel hex),
  6491. @option{elf} (ELF file), @option{s19} (Motorola s19),
  6492. @option{mem}, or @option{builder}.
  6493. @end deffn
  6494. @anchor{xscalevectorcatch}
  6495. @deffn Command {xscale vector_catch} [mask]
  6496. @cindex vector_catch
  6497. Display a bitmask showing the hardware vectors to catch.
  6498. If the optional parameter is provided, first set the bitmask to that value.
  6499. The mask bits correspond with bit 16..23 in the DCSR:
  6500. @example
  6501. 0x01 Trap Reset
  6502. 0x02 Trap Undefined Instructions
  6503. 0x04 Trap Software Interrupt
  6504. 0x08 Trap Prefetch Abort
  6505. 0x10 Trap Data Abort
  6506. 0x20 reserved
  6507. 0x40 Trap IRQ
  6508. 0x80 Trap FIQ
  6509. @end example
  6510. @end deffn
  6511. @deffn Command {xscale vector_table} [(@option{low}|@option{high}) index value]
  6512. @cindex vector_table
  6513. Set an entry in the mini-IC vector table. There are two tables: one for
  6514. low vectors (at 0x00000000), and one for high vectors (0xFFFF0000), each
  6515. holding the 8 exception vectors. @var{index} can be 1-7, because vector 0
  6516. points to the debug handler entry and can not be overwritten.
  6517. @var{value} holds the 32-bit opcode that is placed in the mini-IC.
  6518. Without arguments, the current settings are displayed.
  6519. @end deffn
  6520. @section ARMv6 Architecture
  6521. @cindex ARMv6
  6522. @subsection ARM11 specific commands
  6523. @cindex ARM11
  6524. @deffn Command {arm11 memwrite burst} [@option{enable}|@option{disable}]
  6525. Displays the value of the memwrite burst-enable flag,
  6526. which is enabled by default.
  6527. If a boolean parameter is provided, first assigns that flag.
  6528. Burst writes are only used for memory writes larger than 1 word.
  6529. They improve performance by assuming that the CPU has read each data
  6530. word over JTAG and completed its write before the next word arrives,
  6531. instead of polling for a status flag to verify that completion.
  6532. This is usually safe, because JTAG runs much slower than the CPU.
  6533. @end deffn
  6534. @deffn Command {arm11 memwrite error_fatal} [@option{enable}|@option{disable}]
  6535. Displays the value of the memwrite error_fatal flag,
  6536. which is enabled by default.
  6537. If a boolean parameter is provided, first assigns that flag.
  6538. When set, certain memory write errors cause earlier transfer termination.
  6539. @end deffn
  6540. @deffn Command {arm11 step_irq_enable} [@option{enable}|@option{disable}]
  6541. Displays the value of the flag controlling whether
  6542. IRQs are enabled during single stepping;
  6543. they are disabled by default.
  6544. If a boolean parameter is provided, first assigns that.
  6545. @end deffn
  6546. @deffn Command {arm11 vcr} [value]
  6547. @cindex vector_catch
  6548. Displays the value of the @emph{Vector Catch Register (VCR)},
  6549. coprocessor 14 register 7.
  6550. If @var{value} is defined, first assigns that.
  6551. Vector Catch hardware provides dedicated breakpoints
  6552. for certain hardware events.
  6553. The specific bit values are core-specific (as in fact is using
  6554. coprocessor 14 register 7 itself) but all current ARM11
  6555. cores @emph{except the ARM1176} use the same six bits.
  6556. @end deffn
  6557. @section ARMv7 Architecture
  6558. @cindex ARMv7
  6559. @subsection ARMv7 Debug Access Port (DAP) specific commands
  6560. @cindex Debug Access Port
  6561. @cindex DAP
  6562. These commands are specific to ARM architecture v7 Debug Access Port (DAP),
  6563. included on Cortex-M and Cortex-A systems.
  6564. They are available in addition to other core-specific commands that may be available.
  6565. @deffn Command {dap apid} [num]
  6566. Displays ID register from AP @var{num},
  6567. defaulting to the currently selected AP.
  6568. @end deffn
  6569. @deffn Command {dap apreg} ap_num reg [value]
  6570. Displays content of a register @var{reg} from AP @var{ap_num}
  6571. or set a new value @var{value}.
  6572. @var{reg} is byte address of a word register, 0, 4, 8 ... 0xfc.
  6573. @end deffn
  6574. @deffn Command {dap apsel} [num]
  6575. Select AP @var{num}, defaulting to 0.
  6576. @end deffn
  6577. @deffn Command {dap baseaddr} [num]
  6578. Displays debug base address from MEM-AP @var{num},
  6579. defaulting to the currently selected AP.
  6580. @end deffn
  6581. @deffn Command {dap info} [num]
  6582. Displays the ROM table for MEM-AP @var{num},
  6583. defaulting to the currently selected AP.
  6584. @end deffn
  6585. @deffn Command {dap memaccess} [value]
  6586. Displays the number of extra tck cycles in the JTAG idle to use for MEM-AP
  6587. memory bus access [0-255], giving additional time to respond to reads.
  6588. If @var{value} is defined, first assigns that.
  6589. @end deffn
  6590. @deffn Command {dap apcsw} [0 / 1]
  6591. fix CSW_SPROT from register AP_REG_CSW on selected dap.
  6592. Defaulting to 0.
  6593. @end deffn
  6594. @deffn Command {dap ti_be_32_quirks} [@option{enable}]
  6595. Set/get quirks mode for TI TMS450/TMS570 processors
  6596. Disabled by default
  6597. @end deffn
  6598. @subsection ARMv7-A specific commands
  6599. @cindex Cortex-A
  6600. @deffn Command {cortex_a cache_info}
  6601. display information about target caches
  6602. @end deffn
  6603. @deffn Command {cortex_a dacrfixup [@option{on}|@option{off}]}
  6604. Work around issues with software breakpoints when the program text is
  6605. mapped read-only by the operating system. This option sets the CP15 DACR
  6606. to "all-manager" to bypass MMU permission checks on memory access.
  6607. Defaults to 'off'.
  6608. @end deffn
  6609. @deffn Command {cortex_a dbginit}
  6610. Initialize core debug
  6611. Enables debug by unlocking the Software Lock and clearing sticky powerdown indications
  6612. @end deffn
  6613. @deffn Command {cortex_a smp_off}
  6614. Disable SMP mode
  6615. @end deffn
  6616. @deffn Command {cortex_a smp_on}
  6617. Enable SMP mode
  6618. @end deffn
  6619. @deffn Command {cortex_a smp_gdb} [core_id]
  6620. Display/set the current core displayed in GDB
  6621. @end deffn
  6622. @deffn Command {cortex_a maskisr} [@option{on}|@option{off}]
  6623. Selects whether interrupts will be processed when single stepping
  6624. @end deffn
  6625. @deffn Command {cache_config l2x} [base way]
  6626. configure l2x cache
  6627. @end deffn
  6628. @subsection ARMv7-R specific commands
  6629. @cindex Cortex-R
  6630. @deffn Command {cortex_r dbginit}
  6631. Initialize core debug
  6632. Enables debug by unlocking the Software Lock and clearing sticky powerdown indications
  6633. @end deffn
  6634. @deffn Command {cortex_r maskisr} [@option{on}|@option{off}]
  6635. Selects whether interrupts will be processed when single stepping
  6636. @end deffn
  6637. @subsection ARMv7-M specific commands
  6638. @cindex tracing
  6639. @cindex SWO
  6640. @cindex SWV
  6641. @cindex TPIU
  6642. @cindex ITM
  6643. @cindex ETM
  6644. @deffn Command {tpiu config} (@option{disable} | ((@option{external} | @option{internal (@var{filename} | -)}) @
  6645. (@option{sync @var{port_width}} | ((@option{manchester} | @option{uart}) @var{formatter_enable})) @
  6646. @var{TRACECLKIN_freq} [@var{trace_freq}]))
  6647. ARMv7-M architecture provides several modules to generate debugging
  6648. information internally (ITM, DWT and ETM). Their output is directed
  6649. through TPIU to be captured externally either on an SWO pin (this
  6650. configuration is called SWV) or on a synchronous parallel trace port.
  6651. This command configures the TPIU module of the target and, if internal
  6652. capture mode is selected, starts to capture trace output by using the
  6653. debugger adapter features.
  6654. Some targets require additional actions to be performed in the
  6655. @b{trace-config} handler for trace port to be activated.
  6656. Command options:
  6657. @itemize @minus
  6658. @item @option{disable} disable TPIU handling;
  6659. @item @option{external} configure TPIU to let user capture trace
  6660. output externally (with an additional UART or logic analyzer hardware);
  6661. @item @option{internal @var{filename}} configure TPIU and debug adapter to
  6662. gather trace data and append it to @var{filename} (which can be
  6663. either a regular file or a named pipe);
  6664. @item @option{internal -} configure TPIU and debug adapter to
  6665. gather trace data, but not write to any file. Useful in conjunction with the @command{tcl_trace} command;
  6666. @item @option{sync @var{port_width}} use synchronous parallel trace output
  6667. mode, and set port width to @var{port_width};
  6668. @item @option{manchester} use asynchronous SWO mode with Manchester
  6669. coding;
  6670. @item @option{uart} use asynchronous SWO mode with NRZ (same as
  6671. regular UART 8N1) coding;
  6672. @item @var{formatter_enable} is @option{on} or @option{off} to enable
  6673. or disable TPIU formatter which needs to be used when both ITM and ETM
  6674. data is to be output via SWO;
  6675. @item @var{TRACECLKIN_freq} this should be specified to match target's
  6676. current TRACECLKIN frequency (usually the same as HCLK);
  6677. @item @var{trace_freq} trace port frequency. Can be omitted in
  6678. internal mode to let the adapter driver select the maximum supported
  6679. rate automatically.
  6680. @end itemize
  6681. Example usage:
  6682. @enumerate
  6683. @item STM32L152 board is programmed with an application that configures
  6684. PLL to provide core clock with 24MHz frequency; to use ITM output it's
  6685. enough to:
  6686. @example
  6687. #include <libopencm3/cm3/itm.h>
  6688. ...
  6689. ITM_STIM8(0) = c;
  6690. ...
  6691. @end example
  6692. (the most obvious way is to use the first stimulus port for printf,
  6693. for that this ITM_STIM8 assignment can be used inside _write(); to make it
  6694. blocking to avoid data loss, add @code{while (!(ITM_STIM8(0) &
  6695. ITM_STIM_FIFOREADY));});
  6696. @item An FT2232H UART is connected to the SWO pin of the board;
  6697. @item Commands to configure UART for 12MHz baud rate:
  6698. @example
  6699. $ setserial /dev/ttyUSB1 spd_cust divisor 5
  6700. $ stty -F /dev/ttyUSB1 38400
  6701. @end example
  6702. (FT2232H's base frequency is 60MHz, spd_cust allows to alias 38400
  6703. baud with our custom divisor to get 12MHz)
  6704. @item @code{itmdump -f /dev/ttyUSB1 -d1}
  6705. @item OpenOCD invocation line:
  6706. @example
  6707. openocd -f interface/stlink-v2-1.cfg \
  6708. -c "transport select hla_swd" \
  6709. -f target/stm32l1.cfg \
  6710. -c "tpiu config external uart off 24000000 12000000"
  6711. @end example
  6712. @end enumerate
  6713. @end deffn
  6714. @deffn Command {itm port} @var{port} (@option{0}|@option{1}|@option{on}|@option{off})
  6715. Enable or disable trace output for ITM stimulus @var{port} (counting
  6716. from 0). Port 0 is enabled on target creation automatically.
  6717. @end deffn
  6718. @deffn Command {itm ports} (@option{0}|@option{1}|@option{on}|@option{off})
  6719. Enable or disable trace output for all ITM stimulus ports.
  6720. @end deffn
  6721. @subsection Cortex-M specific commands
  6722. @cindex Cortex-M
  6723. @deffn Command {cortex_m maskisr} (@option{auto}|@option{on}|@option{off})
  6724. Control masking (disabling) interrupts during target step/resume.
  6725. The @option{auto} option handles interrupts during stepping a way they get
  6726. served but don't disturb the program flow. The step command first allows
  6727. pending interrupt handlers to execute, then disables interrupts and steps over
  6728. the next instruction where the core was halted. After the step interrupts
  6729. are enabled again. If the interrupt handlers don't complete within 500ms,
  6730. the step command leaves with the core running.
  6731. Note that a free breakpoint is required for the @option{auto} option. If no
  6732. breakpoint is available at the time of the step, then the step is taken
  6733. with interrupts enabled, i.e. the same way the @option{off} option does.
  6734. Default is @option{auto}.
  6735. @end deffn
  6736. @deffn Command {cortex_m vector_catch} [@option{all}|@option{none}|list]
  6737. @cindex vector_catch
  6738. Vector Catch hardware provides dedicated breakpoints
  6739. for certain hardware events.
  6740. Parameters request interception of
  6741. @option{all} of these hardware event vectors,
  6742. @option{none} of them,
  6743. or one or more of the following:
  6744. @option{hard_err} for a HardFault exception;
  6745. @option{mm_err} for a MemManage exception;
  6746. @option{bus_err} for a BusFault exception;
  6747. @option{irq_err},
  6748. @option{state_err},
  6749. @option{chk_err}, or
  6750. @option{nocp_err} for various UsageFault exceptions; or
  6751. @option{reset}.
  6752. If NVIC setup code does not enable them,
  6753. MemManage, BusFault, and UsageFault exceptions
  6754. are mapped to HardFault.
  6755. UsageFault checks for
  6756. divide-by-zero and unaligned access
  6757. must also be explicitly enabled.
  6758. This finishes by listing the current vector catch configuration.
  6759. @end deffn
  6760. @deffn Command {cortex_m reset_config} (@option{srst}|@option{sysresetreq}|@option{vectreset})
  6761. Control reset handling. The default @option{srst} is to use srst if fitted,
  6762. otherwise fallback to @option{vectreset}.
  6763. @itemize @minus
  6764. @item @option{srst} use hardware srst if fitted otherwise fallback to @option{vectreset}.
  6765. @item @option{sysresetreq} use NVIC SYSRESETREQ to reset system.
  6766. @item @option{vectreset} use NVIC VECTRESET to reset system.
  6767. @end itemize
  6768. Using @option{vectreset} is a safe option for all current Cortex-M cores.
  6769. This however has the disadvantage of only resetting the core, all peripherals
  6770. are uneffected. A solution would be to use a @code{reset-init} event handler to manually reset
  6771. the peripherals.
  6772. @xref{targetevents,,Target Events}.
  6773. @end deffn
  6774. @section Intel Architecture
  6775. Intel Quark X10xx is the first product in the Quark family of SoCs. It is an IA-32
  6776. (Pentium x86 ISA) compatible SoC. The core CPU in the X10xx is codenamed Lakemont.
  6777. Lakemont version 1 (LMT1) is used in X10xx. The CPU TAP (Lakemont TAP) is used for
  6778. software debug and the CLTAP is used for SoC level operations.
  6779. Useful docs are here: https://communities.intel.com/community/makers/documentation
  6780. @itemize
  6781. @item Intel Quark SoC X1000 OpenOCD/GDB/Eclipse App Note (web search for doc num 330015)
  6782. @item Intel Quark SoC X1000 Debug Operations User Guide (web search for doc num 329866)
  6783. @item Intel Quark SoC X1000 Datasheet (web search for doc num 329676)
  6784. @end itemize
  6785. @subsection x86 32-bit specific commands
  6786. The three main address spaces for x86 are memory, I/O and configuration space.
  6787. These commands allow a user to read and write to the 64Kbyte I/O address space.
  6788. @deffn Command {x86_32 idw} address
  6789. Display the contents of a 32-bit I/O port from address range 0x0000 - 0xffff.
  6790. @end deffn
  6791. @deffn Command {x86_32 idh} address
  6792. Display the contents of a 16-bit I/O port from address range 0x0000 - 0xffff.
  6793. @end deffn
  6794. @deffn Command {x86_32 idb} address
  6795. Display the contents of a 8-bit I/O port from address range 0x0000 - 0xffff.
  6796. @end deffn
  6797. @deffn Command {x86_32 iww} address
  6798. Write the contents of a 32-bit I/O port to address range 0x0000 - 0xffff.
  6799. @end deffn
  6800. @deffn Command {x86_32 iwh} address
  6801. Write the contents of a 16-bit I/O port to address range 0x0000 - 0xffff.
  6802. @end deffn
  6803. @deffn Command {x86_32 iwb} address
  6804. Write the contents of a 8-bit I/O port to address range 0x0000 - 0xffff.
  6805. @end deffn
  6806. @section OpenRISC Architecture
  6807. The OpenRISC CPU is a soft core. It is used in a programmable SoC which can be
  6808. configured with any of the TAP / Debug Unit available.
  6809. @subsection TAP and Debug Unit selection commands
  6810. @deffn Command {tap_select} (@option{vjtag}|@option{mohor}|@option{xilinx_bscan})
  6811. Select between the Altera Virtual JTAG , Xilinx Virtual JTAG and Mohor TAP.
  6812. @end deffn
  6813. @deffn Command {du_select} (@option{adv}|@option{mohor}) [option]
  6814. Select between the Advanced Debug Interface and the classic one.
  6815. An option can be passed as a second argument to the debug unit.
  6816. When using the Advanced Debug Interface, option = 1 means the RTL core is
  6817. configured with ADBG_USE_HISPEED = 1. This configuration skips status checking
  6818. between bytes while doing read or write bursts.
  6819. @end deffn
  6820. @subsection Registers commands
  6821. @deffn Command {addreg} [name] [address] [feature] [reg_group]
  6822. Add a new register in the cpu register list. This register will be
  6823. included in the generated target descriptor file.
  6824. @strong{[feature]} must be "org.gnu.gdb.or1k.group[0..10]".
  6825. @strong{[reg_group]} can be anything. The default register list defines "system",
  6826. "dmmu", "immu", "dcache", "icache", "mac", "debug", "perf", "power", "pic"
  6827. and "timer" groups.
  6828. @emph{example:}
  6829. @example
  6830. addreg rtest 0x1234 org.gnu.gdb.or1k.group0 system
  6831. @end example
  6832. @end deffn
  6833. @deffn Command {readgroup} (@option{group})
  6834. Display all registers in @emph{group}.
  6835. @emph{group} can be "system",
  6836. "dmmu", "immu", "dcache", "icache", "mac", "debug", "perf", "power", "pic",
  6837. "timer" or any new group created with addreg command.
  6838. @end deffn
  6839. @anchor{softwaredebugmessagesandtracing}
  6840. @section Software Debug Messages and Tracing
  6841. @cindex Linux-ARM DCC support
  6842. @cindex tracing
  6843. @cindex libdcc
  6844. @cindex DCC
  6845. OpenOCD can process certain requests from target software, when
  6846. the target uses appropriate libraries.
  6847. The most powerful mechanism is semihosting, but there is also
  6848. a lighter weight mechanism using only the DCC channel.
  6849. Currently @command{target_request debugmsgs}
  6850. is supported only for @option{arm7_9} and @option{cortex_m} cores.
  6851. These messages are received as part of target polling, so
  6852. you need to have @command{poll on} active to receive them.
  6853. They are intrusive in that they will affect program execution
  6854. times. If that is a problem, @pxref{armhardwaretracing,,ARM Hardware Tracing}.
  6855. See @file{libdcc} in the contrib dir for more details.
  6856. In addition to sending strings, characters, and
  6857. arrays of various size integers from the target,
  6858. @file{libdcc} also exports a software trace point mechanism.
  6859. The target being debugged may
  6860. issue trace messages which include a 24-bit @dfn{trace point} number.
  6861. Trace point support includes two distinct mechanisms,
  6862. each supported by a command:
  6863. @itemize
  6864. @item @emph{History} ... A circular buffer of trace points
  6865. can be set up, and then displayed at any time.
  6866. This tracks where code has been, which can be invaluable in
  6867. finding out how some fault was triggered.
  6868. The buffer may overflow, since it collects records continuously.
  6869. It may be useful to use some of the 24 bits to represent a
  6870. particular event, and other bits to hold data.
  6871. @item @emph{Counting} ... An array of counters can be set up,
  6872. and then displayed at any time.
  6873. This can help establish code coverage and identify hot spots.
  6874. The array of counters is directly indexed by the trace point
  6875. number, so trace points with higher numbers are not counted.
  6876. @end itemize
  6877. Linux-ARM kernels have a ``Kernel low-level debugging
  6878. via EmbeddedICE DCC channel'' option (CONFIG_DEBUG_ICEDCC,
  6879. depends on CONFIG_DEBUG_LL) which uses this mechanism to
  6880. deliver messages before a serial console can be activated.
  6881. This is not the same format used by @file{libdcc}.
  6882. Other software, such as the U-Boot boot loader, sometimes
  6883. does the same thing.
  6884. @deffn Command {target_request debugmsgs} [@option{enable}|@option{disable}|@option{charmsg}]
  6885. Displays current handling of target DCC message requests.
  6886. These messages may be sent to the debugger while the target is running.
  6887. The optional @option{enable} and @option{charmsg} parameters
  6888. both enable the messages, while @option{disable} disables them.
  6889. With @option{charmsg} the DCC words each contain one character,
  6890. as used by Linux with CONFIG_DEBUG_ICEDCC;
  6891. otherwise the libdcc format is used.
  6892. @end deffn
  6893. @deffn Command {trace history} [@option{clear}|count]
  6894. With no parameter, displays all the trace points that have triggered
  6895. in the order they triggered.
  6896. With the parameter @option{clear}, erases all current trace history records.
  6897. With a @var{count} parameter, allocates space for that many
  6898. history records.
  6899. @end deffn
  6900. @deffn Command {trace point} [@option{clear}|identifier]
  6901. With no parameter, displays all trace point identifiers and how many times
  6902. they have been triggered.
  6903. With the parameter @option{clear}, erases all current trace point counters.
  6904. With a numeric @var{identifier} parameter, creates a new a trace point counter
  6905. and associates it with that identifier.
  6906. @emph{Important:} The identifier and the trace point number
  6907. are not related except by this command.
  6908. These trace point numbers always start at zero (from server startup,
  6909. or after @command{trace point clear}) and count up from there.
  6910. @end deffn
  6911. @node JTAG Commands
  6912. @chapter JTAG Commands
  6913. @cindex JTAG Commands
  6914. Most general purpose JTAG commands have been presented earlier.
  6915. (@xref{jtagspeed,,JTAG Speed}, @ref{Reset Configuration}, and @ref{TAP Declaration}.)
  6916. Lower level JTAG commands, as presented here,
  6917. may be needed to work with targets which require special
  6918. attention during operations such as reset or initialization.
  6919. To use these commands you will need to understand some
  6920. of the basics of JTAG, including:
  6921. @itemize @bullet
  6922. @item A JTAG scan chain consists of a sequence of individual TAP
  6923. devices such as a CPUs.
  6924. @item Control operations involve moving each TAP through the same
  6925. standard state machine (in parallel)
  6926. using their shared TMS and clock signals.
  6927. @item Data transfer involves shifting data through the chain of
  6928. instruction or data registers of each TAP, writing new register values
  6929. while the reading previous ones.
  6930. @item Data register sizes are a function of the instruction active in
  6931. a given TAP, while instruction register sizes are fixed for each TAP.
  6932. All TAPs support a BYPASS instruction with a single bit data register.
  6933. @item The way OpenOCD differentiates between TAP devices is by
  6934. shifting different instructions into (and out of) their instruction
  6935. registers.
  6936. @end itemize
  6937. @section Low Level JTAG Commands
  6938. These commands are used by developers who need to access
  6939. JTAG instruction or data registers, possibly controlling
  6940. the order of TAP state transitions.
  6941. If you're not debugging OpenOCD internals, or bringing up a
  6942. new JTAG adapter or a new type of TAP device (like a CPU or
  6943. JTAG router), you probably won't need to use these commands.
  6944. In a debug session that doesn't use JTAG for its transport protocol,
  6945. these commands are not available.
  6946. @deffn Command {drscan} tap [numbits value]+ [@option{-endstate} tap_state]
  6947. Loads the data register of @var{tap} with a series of bit fields
  6948. that specify the entire register.
  6949. Each field is @var{numbits} bits long with
  6950. a numeric @var{value} (hexadecimal encouraged).
  6951. The return value holds the original value of each
  6952. of those fields.
  6953. For example, a 38 bit number might be specified as one
  6954. field of 32 bits then one of 6 bits.
  6955. @emph{For portability, never pass fields which are more
  6956. than 32 bits long. Many OpenOCD implementations do not
  6957. support 64-bit (or larger) integer values.}
  6958. All TAPs other than @var{tap} must be in BYPASS mode.
  6959. The single bit in their data registers does not matter.
  6960. When @var{tap_state} is specified, the JTAG state machine is left
  6961. in that state.
  6962. For example @sc{drpause} might be specified, so that more
  6963. instructions can be issued before re-entering the @sc{run/idle} state.
  6964. If the end state is not specified, the @sc{run/idle} state is entered.
  6965. @quotation Warning
  6966. OpenOCD does not record information about data register lengths,
  6967. so @emph{it is important that you get the bit field lengths right}.
  6968. Remember that different JTAG instructions refer to different
  6969. data registers, which may have different lengths.
  6970. Moreover, those lengths may not be fixed;
  6971. the SCAN_N instruction can change the length of
  6972. the register accessed by the INTEST instruction
  6973. (by connecting a different scan chain).
  6974. @end quotation
  6975. @end deffn
  6976. @deffn Command {flush_count}
  6977. Returns the number of times the JTAG queue has been flushed.
  6978. This may be used for performance tuning.
  6979. For example, flushing a queue over USB involves a
  6980. minimum latency, often several milliseconds, which does
  6981. not change with the amount of data which is written.
  6982. You may be able to identify performance problems by finding
  6983. tasks which waste bandwidth by flushing small transfers too often,
  6984. instead of batching them into larger operations.
  6985. @end deffn
  6986. @deffn Command {irscan} [tap instruction]+ [@option{-endstate} tap_state]
  6987. For each @var{tap} listed, loads the instruction register
  6988. with its associated numeric @var{instruction}.
  6989. (The number of bits in that instruction may be displayed
  6990. using the @command{scan_chain} command.)
  6991. For other TAPs, a BYPASS instruction is loaded.
  6992. When @var{tap_state} is specified, the JTAG state machine is left
  6993. in that state.
  6994. For example @sc{irpause} might be specified, so the data register
  6995. can be loaded before re-entering the @sc{run/idle} state.
  6996. If the end state is not specified, the @sc{run/idle} state is entered.
  6997. @quotation Note
  6998. OpenOCD currently supports only a single field for instruction
  6999. register values, unlike data register values.
  7000. For TAPs where the instruction register length is more than 32 bits,
  7001. portable scripts currently must issue only BYPASS instructions.
  7002. @end quotation
  7003. @end deffn
  7004. @deffn Command {jtag_reset} trst srst
  7005. Set values of reset signals.
  7006. The @var{trst} and @var{srst} parameter values may be
  7007. @option{0}, indicating that reset is inactive (pulled or driven high),
  7008. or @option{1}, indicating it is active (pulled or driven low).
  7009. The @command{reset_config} command should already have been used
  7010. to configure how the board and JTAG adapter treat these two
  7011. signals, and to say if either signal is even present.
  7012. @xref{Reset Configuration}.
  7013. Note that TRST is specially handled.
  7014. It actually signifies JTAG's @sc{reset} state.
  7015. So if the board doesn't support the optional TRST signal,
  7016. or it doesn't support it along with the specified SRST value,
  7017. JTAG reset is triggered with TMS and TCK signals
  7018. instead of the TRST signal.
  7019. And no matter how that JTAG reset is triggered, once
  7020. the scan chain enters @sc{reset} with TRST inactive,
  7021. TAP @code{post-reset} events are delivered to all TAPs
  7022. with handlers for that event.
  7023. @end deffn
  7024. @deffn Command {pathmove} start_state [next_state ...]
  7025. Start by moving to @var{start_state}, which
  7026. must be one of the @emph{stable} states.
  7027. Unless it is the only state given, this will often be the
  7028. current state, so that no TCK transitions are needed.
  7029. Then, in a series of single state transitions
  7030. (conforming to the JTAG state machine) shift to
  7031. each @var{next_state} in sequence, one per TCK cycle.
  7032. The final state must also be stable.
  7033. @end deffn
  7034. @deffn Command {runtest} @var{num_cycles}
  7035. Move to the @sc{run/idle} state, and execute at least
  7036. @var{num_cycles} of the JTAG clock (TCK).
  7037. Instructions often need some time
  7038. to execute before they take effect.
  7039. @end deffn
  7040. @c tms_sequence (short|long)
  7041. @c ... temporary, debug-only, other than USBprog bug workaround...
  7042. @deffn Command {verify_ircapture} (@option{enable}|@option{disable})
  7043. Verify values captured during @sc{ircapture} and returned
  7044. during IR scans. Default is enabled, but this can be
  7045. overridden by @command{verify_jtag}.
  7046. This flag is ignored when validating JTAG chain configuration.
  7047. @end deffn
  7048. @deffn Command {verify_jtag} (@option{enable}|@option{disable})
  7049. Enables verification of DR and IR scans, to help detect
  7050. programming errors. For IR scans, @command{verify_ircapture}
  7051. must also be enabled.
  7052. Default is enabled.
  7053. @end deffn
  7054. @section TAP state names
  7055. @cindex TAP state names
  7056. The @var{tap_state} names used by OpenOCD in the @command{drscan},
  7057. @command{irscan}, and @command{pathmove} commands are the same
  7058. as those used in SVF boundary scan documents, except that
  7059. SVF uses @sc{idle} instead of @sc{run/idle}.
  7060. @itemize @bullet
  7061. @item @b{RESET} ... @emph{stable} (with TMS high);
  7062. acts as if TRST were pulsed
  7063. @item @b{RUN/IDLE} ... @emph{stable}; don't assume this always means IDLE
  7064. @item @b{DRSELECT}
  7065. @item @b{DRCAPTURE}
  7066. @item @b{DRSHIFT} ... @emph{stable}; TDI/TDO shifting
  7067. through the data register
  7068. @item @b{DREXIT1}
  7069. @item @b{DRPAUSE} ... @emph{stable}; data register ready
  7070. for update or more shifting
  7071. @item @b{DREXIT2}
  7072. @item @b{DRUPDATE}
  7073. @item @b{IRSELECT}
  7074. @item @b{IRCAPTURE}
  7075. @item @b{IRSHIFT} ... @emph{stable}; TDI/TDO shifting
  7076. through the instruction register
  7077. @item @b{IREXIT1}
  7078. @item @b{IRPAUSE} ... @emph{stable}; instruction register ready
  7079. for update or more shifting
  7080. @item @b{IREXIT2}
  7081. @item @b{IRUPDATE}
  7082. @end itemize
  7083. Note that only six of those states are fully ``stable'' in the
  7084. face of TMS fixed (low except for @sc{reset})
  7085. and a free-running JTAG clock. For all the
  7086. others, the next TCK transition changes to a new state.
  7087. @itemize @bullet
  7088. @item From @sc{drshift} and @sc{irshift}, clock transitions will
  7089. produce side effects by changing register contents. The values
  7090. to be latched in upcoming @sc{drupdate} or @sc{irupdate} states
  7091. may not be as expected.
  7092. @item @sc{run/idle}, @sc{drpause}, and @sc{irpause} are reasonable
  7093. choices after @command{drscan} or @command{irscan} commands,
  7094. since they are free of JTAG side effects.
  7095. @item @sc{run/idle} may have side effects that appear at non-JTAG
  7096. levels, such as advancing the ARM9E-S instruction pipeline.
  7097. Consult the documentation for the TAP(s) you are working with.
  7098. @end itemize
  7099. @node Boundary Scan Commands
  7100. @chapter Boundary Scan Commands
  7101. One of the original purposes of JTAG was to support
  7102. boundary scan based hardware testing.
  7103. Although its primary focus is to support On-Chip Debugging,
  7104. OpenOCD also includes some boundary scan commands.
  7105. @section SVF: Serial Vector Format
  7106. @cindex Serial Vector Format
  7107. @cindex SVF
  7108. The Serial Vector Format, better known as @dfn{SVF}, is a
  7109. way to represent JTAG test patterns in text files.
  7110. In a debug session using JTAG for its transport protocol,
  7111. OpenOCD supports running such test files.
  7112. @deffn Command {svf} filename [@option{quiet}]
  7113. This issues a JTAG reset (Test-Logic-Reset) and then
  7114. runs the SVF script from @file{filename}.
  7115. Unless the @option{quiet} option is specified,
  7116. each command is logged before it is executed.
  7117. @end deffn
  7118. @section XSVF: Xilinx Serial Vector Format
  7119. @cindex Xilinx Serial Vector Format
  7120. @cindex XSVF
  7121. The Xilinx Serial Vector Format, better known as @dfn{XSVF}, is a
  7122. binary representation of SVF which is optimized for use with
  7123. Xilinx devices.
  7124. In a debug session using JTAG for its transport protocol,
  7125. OpenOCD supports running such test files.
  7126. @quotation Important
  7127. Not all XSVF commands are supported.
  7128. @end quotation
  7129. @deffn Command {xsvf} (tapname|@option{plain}) filename [@option{virt2}] [@option{quiet}]
  7130. This issues a JTAG reset (Test-Logic-Reset) and then
  7131. runs the XSVF script from @file{filename}.
  7132. When a @var{tapname} is specified, the commands are directed at
  7133. that TAP.
  7134. When @option{virt2} is specified, the @sc{xruntest} command counts
  7135. are interpreted as TCK cycles instead of microseconds.
  7136. Unless the @option{quiet} option is specified,
  7137. messages are logged for comments and some retries.
  7138. @end deffn
  7139. The OpenOCD sources also include two utility scripts
  7140. for working with XSVF; they are not currently installed
  7141. after building the software.
  7142. You may find them useful:
  7143. @itemize
  7144. @item @emph{svf2xsvf} ... converts SVF files into the extended XSVF
  7145. syntax understood by the @command{xsvf} command; see notes below.
  7146. @item @emph{xsvfdump} ... converts XSVF files into a text output format;
  7147. understands the OpenOCD extensions.
  7148. @end itemize
  7149. The input format accepts a handful of non-standard extensions.
  7150. These include three opcodes corresponding to SVF extensions
  7151. from Lattice Semiconductor (LCOUNT, LDELAY, LDSR), and
  7152. two opcodes supporting a more accurate translation of SVF
  7153. (XTRST, XWAITSTATE).
  7154. If @emph{xsvfdump} shows a file is using those opcodes, it
  7155. probably will not be usable with other XSVF tools.
  7156. @node Utility Commands
  7157. @chapter Utility Commands
  7158. @cindex Utility Commands
  7159. @section RAM testing
  7160. @cindex RAM testing
  7161. There is often a need to stress-test random access memory (RAM) for
  7162. errors. OpenOCD comes with a Tcl implementation of well-known memory
  7163. testing procedures allowing the detection of all sorts of issues with
  7164. electrical wiring, defective chips, PCB layout and other common
  7165. hardware problems.
  7166. To use them, you usually need to initialise your RAM controller first;
  7167. consult your SoC's documentation to get the recommended list of
  7168. register operations and translate them to the corresponding
  7169. @command{mww}/@command{mwb} commands.
  7170. Load the memory testing functions with
  7171. @example
  7172. source [find tools/memtest.tcl]
  7173. @end example
  7174. to get access to the following facilities:
  7175. @deffn Command {memTestDataBus} address
  7176. Test the data bus wiring in a memory region by performing a walking
  7177. 1's test at a fixed address within that region.
  7178. @end deffn
  7179. @deffn Command {memTestAddressBus} baseaddress size
  7180. Perform a walking 1's test on the relevant bits of the address and
  7181. check for aliasing. This test will find single-bit address failures
  7182. such as stuck-high, stuck-low, and shorted pins.
  7183. @end deffn
  7184. @deffn Command {memTestDevice} baseaddress size
  7185. Test the integrity of a physical memory device by performing an
  7186. increment/decrement test over the entire region. In the process every
  7187. storage bit in the device is tested as zero and as one.
  7188. @end deffn
  7189. @deffn Command {runAllMemTests} baseaddress size
  7190. Run all of the above tests over a specified memory region.
  7191. @end deffn
  7192. @section Firmware recovery helpers
  7193. @cindex Firmware recovery
  7194. OpenOCD includes an easy-to-use script to facilitate mass-market
  7195. devices recovery with JTAG.
  7196. For quickstart instructions run:
  7197. @example
  7198. openocd -f tools/firmware-recovery.tcl -c firmware_help
  7199. @end example
  7200. @node TFTP
  7201. @chapter TFTP
  7202. @cindex TFTP
  7203. If OpenOCD runs on an embedded host (as ZY1000 does), then TFTP can
  7204. be used to access files on PCs (either the developer's PC or some other PC).
  7205. The way this works on the ZY1000 is to prefix a filename by
  7206. "/tftp/ip/" and append the TFTP path on the TFTP
  7207. server (tftpd). For example,
  7208. @example
  7209. load_image /tftp/10.0.0.96/c:\temp\abc.elf
  7210. @end example
  7211. will load c:\temp\abc.elf from the developer pc (10.0.0.96) into memory as
  7212. if the file was hosted on the embedded host.
  7213. In order to achieve decent performance, you must choose a TFTP server
  7214. that supports a packet size bigger than the default packet size (512 bytes). There
  7215. are numerous TFTP servers out there (free and commercial) and you will have to do
  7216. a bit of googling to find something that fits your requirements.
  7217. @node GDB and OpenOCD
  7218. @chapter GDB and OpenOCD
  7219. @cindex GDB
  7220. OpenOCD complies with the remote gdbserver protocol and, as such, can be used
  7221. to debug remote targets.
  7222. Setting up GDB to work with OpenOCD can involve several components:
  7223. @itemize
  7224. @item The OpenOCD server support for GDB may need to be configured.
  7225. @xref{gdbconfiguration,,GDB Configuration}.
  7226. @item GDB's support for OpenOCD may need configuration,
  7227. as shown in this chapter.
  7228. @item If you have a GUI environment like Eclipse,
  7229. that also will probably need to be configured.
  7230. @end itemize
  7231. Of course, the version of GDB you use will need to be one which has
  7232. been built to know about the target CPU you're using. It's probably
  7233. part of the tool chain you're using. For example, if you are doing
  7234. cross-development for ARM on an x86 PC, instead of using the native
  7235. x86 @command{gdb} command you might use @command{arm-none-eabi-gdb}
  7236. if that's the tool chain used to compile your code.
  7237. @section Connecting to GDB
  7238. @cindex Connecting to GDB
  7239. Use GDB 6.7 or newer with OpenOCD if you run into trouble. For
  7240. instance GDB 6.3 has a known bug that produces bogus memory access
  7241. errors, which has since been fixed; see
  7242. @url{http://osdir.com/ml/gdb.bugs.discuss/2004-12/msg00018.html}
  7243. OpenOCD can communicate with GDB in two ways:
  7244. @enumerate
  7245. @item
  7246. A socket (TCP/IP) connection is typically started as follows:
  7247. @example
  7248. target remote localhost:3333
  7249. @end example
  7250. This would cause GDB to connect to the gdbserver on the local pc using port 3333.
  7251. It is also possible to use the GDB extended remote protocol as follows:
  7252. @example
  7253. target extended-remote localhost:3333
  7254. @end example
  7255. @item
  7256. A pipe connection is typically started as follows:
  7257. @example
  7258. target remote | openocd -c "gdb_port pipe; log_output openocd.log"
  7259. @end example
  7260. This would cause GDB to run OpenOCD and communicate using pipes (stdin/stdout).
  7261. Using this method has the advantage of GDB starting/stopping OpenOCD for the debug
  7262. session. log_output sends the log output to a file to ensure that the pipe is
  7263. not saturated when using higher debug level outputs.
  7264. @end enumerate
  7265. To list the available OpenOCD commands type @command{monitor help} on the
  7266. GDB command line.
  7267. @section Sample GDB session startup
  7268. With the remote protocol, GDB sessions start a little differently
  7269. than they do when you're debugging locally.
  7270. Here's an example showing how to start a debug session with a
  7271. small ARM program.
  7272. In this case the program was linked to be loaded into SRAM on a Cortex-M3.
  7273. Most programs would be written into flash (address 0) and run from there.
  7274. @example
  7275. $ arm-none-eabi-gdb example.elf
  7276. (gdb) target remote localhost:3333
  7277. Remote debugging using localhost:3333
  7278. ...
  7279. (gdb) monitor reset halt
  7280. ...
  7281. (gdb) load
  7282. Loading section .vectors, size 0x100 lma 0x20000000
  7283. Loading section .text, size 0x5a0 lma 0x20000100
  7284. Loading section .data, size 0x18 lma 0x200006a0
  7285. Start address 0x2000061c, load size 1720
  7286. Transfer rate: 22 KB/sec, 573 bytes/write.
  7287. (gdb) continue
  7288. Continuing.
  7289. ...
  7290. @end example
  7291. You could then interrupt the GDB session to make the program break,
  7292. type @command{where} to show the stack, @command{list} to show the
  7293. code around the program counter, @command{step} through code,
  7294. set breakpoints or watchpoints, and so on.
  7295. @section Configuring GDB for OpenOCD
  7296. OpenOCD supports the gdb @option{qSupported} packet, this enables information
  7297. to be sent by the GDB remote server (i.e. OpenOCD) to GDB. Typical information includes
  7298. packet size and the device's memory map.
  7299. You do not need to configure the packet size by hand,
  7300. and the relevant parts of the memory map should be automatically
  7301. set up when you declare (NOR) flash banks.
  7302. However, there are other things which GDB can't currently query.
  7303. You may need to set those up by hand.
  7304. As OpenOCD starts up, you will often see a line reporting
  7305. something like:
  7306. @example
  7307. Info : lm3s.cpu: hardware has 6 breakpoints, 4 watchpoints
  7308. @end example
  7309. You can pass that information to GDB with these commands:
  7310. @example
  7311. set remote hardware-breakpoint-limit 6
  7312. set remote hardware-watchpoint-limit 4
  7313. @end example
  7314. With that particular hardware (Cortex-M3) the hardware breakpoints
  7315. only work for code running from flash memory. Most other ARM systems
  7316. do not have such restrictions.
  7317. Another example of useful GDB configuration came from a user who
  7318. found that single stepping his Cortex-M3 didn't work well with IRQs
  7319. and an RTOS until he told GDB to disable the IRQs while stepping:
  7320. @example
  7321. define hook-step
  7322. mon cortex_m maskisr on
  7323. end
  7324. define hookpost-step
  7325. mon cortex_m maskisr off
  7326. end
  7327. @end example
  7328. Rather than typing such commands interactively, you may prefer to
  7329. save them in a file and have GDB execute them as it starts, perhaps
  7330. using a @file{.gdbinit} in your project directory or starting GDB
  7331. using @command{gdb -x filename}.
  7332. @section Programming using GDB
  7333. @cindex Programming using GDB
  7334. @anchor{programmingusinggdb}
  7335. By default the target memory map is sent to GDB. This can be disabled by
  7336. the following OpenOCD configuration option:
  7337. @example
  7338. gdb_memory_map disable
  7339. @end example
  7340. For this to function correctly a valid flash configuration must also be set
  7341. in OpenOCD. For faster performance you should also configure a valid
  7342. working area.
  7343. Informing GDB of the memory map of the target will enable GDB to protect any
  7344. flash areas of the target and use hardware breakpoints by default. This means
  7345. that the OpenOCD option @command{gdb_breakpoint_override} is not required when
  7346. using a memory map. @xref{gdbbreakpointoverride,,gdb_breakpoint_override}.
  7347. To view the configured memory map in GDB, use the GDB command @option{info mem}.
  7348. All other unassigned addresses within GDB are treated as RAM.
  7349. GDB 6.8 and higher set any memory area not in the memory map as inaccessible.
  7350. This can be changed to the old behaviour by using the following GDB command
  7351. @example
  7352. set mem inaccessible-by-default off
  7353. @end example
  7354. If @command{gdb_flash_program enable} is also used, GDB will be able to
  7355. program any flash memory using the vFlash interface.
  7356. GDB will look at the target memory map when a load command is given, if any
  7357. areas to be programmed lie within the target flash area the vFlash packets
  7358. will be used.
  7359. If the target needs configuring before GDB programming, an event
  7360. script can be executed:
  7361. @example
  7362. $_TARGETNAME configure -event EVENTNAME BODY
  7363. @end example
  7364. To verify any flash programming the GDB command @option{compare-sections}
  7365. can be used.
  7366. @anchor{usingopenocdsmpwithgdb}
  7367. @section Using OpenOCD SMP with GDB
  7368. @cindex SMP
  7369. For SMP support following GDB serial protocol packet have been defined :
  7370. @itemize @bullet
  7371. @item j - smp status request
  7372. @item J - smp set request
  7373. @end itemize
  7374. OpenOCD implements :
  7375. @itemize @bullet
  7376. @item @option{jc} packet for reading core id displayed by
  7377. GDB connection. Reply is @option{XXXXXXXX} (8 hex digits giving core id) or
  7378. @option{E01} for target not smp.
  7379. @item @option{JcXXXXXXXX} (8 hex digits) packet for setting core id displayed at next GDB continue
  7380. (core id -1 is reserved for returning to normal resume mode). Reply @option{E01}
  7381. for target not smp or @option{OK} on success.
  7382. @end itemize
  7383. Handling of this packet within GDB can be done :
  7384. @itemize @bullet
  7385. @item by the creation of an internal variable (i.e @option{_core}) by mean
  7386. of function allocate_computed_value allowing following GDB command.
  7387. @example
  7388. set $_core 1
  7389. #Jc01 packet is sent
  7390. print $_core
  7391. #jc packet is sent and result is affected in $
  7392. @end example
  7393. @item by the usage of GDB maintenance command as described in following example (2 cpus in SMP with
  7394. core id 0 and 1 @pxref{definecputargetsworkinginsmp,,Define CPU targets working in SMP}).
  7395. @example
  7396. # toggle0 : force display of coreid 0
  7397. define toggle0
  7398. maint packet Jc0
  7399. continue
  7400. main packet Jc-1
  7401. end
  7402. # toggle1 : force display of coreid 1
  7403. define toggle1
  7404. maint packet Jc1
  7405. continue
  7406. main packet Jc-1
  7407. end
  7408. @end example
  7409. @end itemize
  7410. @section RTOS Support
  7411. @cindex RTOS Support
  7412. @anchor{gdbrtossupport}
  7413. OpenOCD includes RTOS support, this will however need enabling as it defaults to disabled.
  7414. It can be enabled by passing @option{-rtos} arg to the target @xref{rtostype,,RTOS Type}.
  7415. @* An example setup is below:
  7416. @example
  7417. $_TARGETNAME configure -rtos auto
  7418. @end example
  7419. This will attempt to auto detect the RTOS within your application.
  7420. Currently supported rtos's include:
  7421. @itemize @bullet
  7422. @item @option{eCos}
  7423. @item @option{ThreadX}
  7424. @item @option{FreeRTOS}
  7425. @item @option{linux}
  7426. @item @option{ChibiOS}
  7427. @item @option{embKernel}
  7428. @item @option{mqx}
  7429. @end itemize
  7430. @quotation Note
  7431. Before an RTOS can be detected, it must export certain symbols; otherwise, it cannot
  7432. be used by OpenOCD. Below is a list of the required symbols for each supported RTOS.
  7433. @end quotation
  7434. @table @code
  7435. @item eCos symbols
  7436. Cyg_Thread::thread_list, Cyg_Scheduler_Base::current_thread.
  7437. @item ThreadX symbols
  7438. _tx_thread_current_ptr, _tx_thread_created_ptr, _tx_thread_created_count.
  7439. @item FreeRTOS symbols
  7440. @c The following is taken from recent texinfo to provide compatibility
  7441. @c with ancient versions that do not support @raggedright
  7442. @tex
  7443. \begingroup
  7444. \rightskip0pt plus2em \spaceskip.3333em \xspaceskip.5em\relax
  7445. pxCurrentTCB, pxReadyTasksLists, xDelayedTaskList1, xDelayedTaskList2,
  7446. pxDelayedTaskList, pxOverflowDelayedTaskList, xPendingReadyList,
  7447. uxCurrentNumberOfTasks, uxTopUsedPriority.
  7448. \par
  7449. \endgroup
  7450. @end tex
  7451. @item linux symbols
  7452. init_task.
  7453. @item ChibiOS symbols
  7454. rlist, ch_debug, chSysInit.
  7455. @item embKernel symbols
  7456. Rtos::sCurrentTask, Rtos::sListReady, Rtos::sListSleep,
  7457. Rtos::sListSuspended, Rtos::sMaxPriorities, Rtos::sCurrentTaskCount.
  7458. @item mqx symbols
  7459. _mqx_kernel_data, MQX_init_struct.
  7460. @end table
  7461. For most RTOS supported the above symbols will be exported by default. However for
  7462. some, eg. FreeRTOS, extra steps must be taken.
  7463. These RTOSes may require additional OpenOCD-specific file to be linked
  7464. along with the project:
  7465. @table @code
  7466. @item FreeRTOS
  7467. contrib/rtos-helpers/FreeRTOS-openocd.c
  7468. @end table
  7469. @node Tcl Scripting API
  7470. @chapter Tcl Scripting API
  7471. @cindex Tcl Scripting API
  7472. @cindex Tcl scripts
  7473. @section API rules
  7474. Tcl commands are stateless; e.g. the @command{telnet} command has
  7475. a concept of currently active target, the Tcl API proc's take this sort
  7476. of state information as an argument to each proc.
  7477. There are three main types of return values: single value, name value
  7478. pair list and lists.
  7479. Name value pair. The proc 'foo' below returns a name/value pair
  7480. list.
  7481. @example
  7482. > set foo(me) Duane
  7483. > set foo(you) Oyvind
  7484. > set foo(mouse) Micky
  7485. > set foo(duck) Donald
  7486. @end example
  7487. If one does this:
  7488. @example
  7489. > set foo
  7490. @end example
  7491. The result is:
  7492. @example
  7493. me Duane you Oyvind mouse Micky duck Donald
  7494. @end example
  7495. Thus, to get the names of the associative array is easy:
  7496. @verbatim
  7497. foreach { name value } [set foo] {
  7498. puts "Name: $name, Value: $value"
  7499. }
  7500. @end verbatim
  7501. Lists returned should be relatively small. Otherwise, a range
  7502. should be passed in to the proc in question.
  7503. @section Internal low-level Commands
  7504. By "low-level," we mean commands that a human would typically not
  7505. invoke directly.
  7506. Some low-level commands need to be prefixed with "ocd_"; e.g.
  7507. @command{ocd_flash_banks}
  7508. is the low-level API upon which @command{flash banks} is implemented.
  7509. @itemize @bullet
  7510. @item @b{mem2array} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}>
  7511. Read memory and return as a Tcl array for script processing
  7512. @item @b{array2mem} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}>
  7513. Convert a Tcl array to memory locations and write the values
  7514. @item @b{ocd_flash_banks} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}> <@var{target}> [@option{driver options} ...]
  7515. Return information about the flash banks
  7516. @item @b{capture} <@var{command}>
  7517. Run <@var{command}> and return full log output that was produced during
  7518. its execution. Example:
  7519. @example
  7520. > capture "reset init"
  7521. @end example
  7522. @end itemize
  7523. OpenOCD commands can consist of two words, e.g. "flash banks". The
  7524. @file{startup.tcl} "unknown" proc will translate this into a Tcl proc
  7525. called "flash_banks".
  7526. @section OpenOCD specific Global Variables
  7527. Real Tcl has ::tcl_platform(), and platform::identify, and many other
  7528. variables. JimTCL, as implemented in OpenOCD creates $ocd_HOSTOS which
  7529. holds one of the following values:
  7530. @itemize @bullet
  7531. @item @b{cygwin} Running under Cygwin
  7532. @item @b{darwin} Darwin (Mac-OS) is the underlying operating sytem.
  7533. @item @b{freebsd} Running under FreeBSD
  7534. @item @b{openbsd} Running under OpenBSD
  7535. @item @b{netbsd} Running under NetBSD
  7536. @item @b{linux} Linux is the underlying operating sytem
  7537. @item @b{mingw32} Running under MingW32
  7538. @item @b{winxx} Built using Microsoft Visual Studio
  7539. @item @b{ecos} Running under eCos
  7540. @item @b{other} Unknown, none of the above.
  7541. @end itemize
  7542. Note: 'winxx' was choosen because today (March-2009) no distinction is made between Win32 and Win64.
  7543. @quotation Note
  7544. We should add support for a variable like Tcl variable
  7545. @code{tcl_platform(platform)}, it should be called
  7546. @code{jim_platform} (because it
  7547. is jim, not real tcl).
  7548. @end quotation
  7549. @section Tcl RPC server
  7550. @cindex RPC
  7551. OpenOCD provides a simple RPC server that allows to run arbitrary Tcl
  7552. commands and receive the results.
  7553. To access it, your application needs to connect to a configured TCP port
  7554. (see @command{tcl_port}). Then it can pass any string to the
  7555. interpreter terminating it with @code{0x1a} and wait for the return
  7556. value (it will be terminated with @code{0x1a} as well). This can be
  7557. repeated as many times as desired without reopening the connection.
  7558. Remember that most of the OpenOCD commands need to be prefixed with
  7559. @code{ocd_} to get the results back. Sometimes you might also need the
  7560. @command{capture} command.
  7561. See @file{contrib/rpc_examples/} for specific client implementations.
  7562. @section Tcl RPC server notifications
  7563. @cindex RPC Notifications
  7564. Notifications are sent asynchronously to other commands being executed over
  7565. the RPC server, so the port must be polled continuously.
  7566. Target event, state and reset notifications are emitted as Tcl associative arrays
  7567. in the following format.
  7568. @verbatim
  7569. type target_event event [event-name]
  7570. type target_state state [state-name]
  7571. type target_reset mode [reset-mode]
  7572. @end verbatim
  7573. @deffn {Command} tcl_notifications [on/off]
  7574. Toggle output of target notifications to the current Tcl RPC server.
  7575. Only available from the Tcl RPC server.
  7576. Defaults to off.
  7577. @end deffn
  7578. @section Tcl RPC server trace output
  7579. @cindex RPC trace output
  7580. Trace data is sent asynchronously to other commands being executed over
  7581. the RPC server, so the port must be polled continuously.
  7582. Target trace data is emitted as a Tcl associative array in the following format.
  7583. @verbatim
  7584. type target_trace data [trace-data-hex-encoded]
  7585. @end verbatim
  7586. @deffn {Command} tcl_trace [on/off]
  7587. Toggle output of target trace data to the current Tcl RPC server.
  7588. Only available from the Tcl RPC server.
  7589. Defaults to off.
  7590. See an example application here:
  7591. @url{https://github.com/apmorton/OpenOcdTraceUtil} [OpenOcdTraceUtil]
  7592. @end deffn
  7593. @node FAQ
  7594. @chapter FAQ
  7595. @cindex faq
  7596. @enumerate
  7597. @anchor{faqrtck}
  7598. @item @b{RTCK, also known as: Adaptive Clocking - What is it?}
  7599. @cindex RTCK
  7600. @cindex adaptive clocking
  7601. @*
  7602. In digital circuit design it is often refered to as ``clock
  7603. synchronisation'' the JTAG interface uses one clock (TCK or TCLK)
  7604. operating at some speed, your CPU target is operating at another.
  7605. The two clocks are not synchronised, they are ``asynchronous''
  7606. In order for the two to work together they must be synchronised
  7607. well enough to work; JTAG can't go ten times faster than the CPU,
  7608. for example. There are 2 basic options:
  7609. @enumerate
  7610. @item
  7611. Use a special "adaptive clocking" circuit to change the JTAG
  7612. clock rate to match what the CPU currently supports.
  7613. @item
  7614. The JTAG clock must be fixed at some speed that's enough slower than
  7615. the CPU clock that all TMS and TDI transitions can be detected.
  7616. @end enumerate
  7617. @b{Does this really matter?} For some chips and some situations, this
  7618. is a non-issue, like a 500MHz ARM926 with a 5 MHz JTAG link;
  7619. the CPU has no difficulty keeping up with JTAG.
  7620. Startup sequences are often problematic though, as are other
  7621. situations where the CPU clock rate changes (perhaps to save
  7622. power).
  7623. For example, Atmel AT91SAM chips start operation from reset with
  7624. a 32kHz system clock. Boot firmware may activate the main oscillator
  7625. and PLL before switching to a faster clock (perhaps that 500 MHz
  7626. ARM926 scenario).
  7627. If you're using JTAG to debug that startup sequence, you must slow
  7628. the JTAG clock to sometimes 1 to 4kHz. After startup completes,
  7629. JTAG can use a faster clock.
  7630. Consider also debugging a 500MHz ARM926 hand held battery powered
  7631. device that enters a low power ``deep sleep'' mode, at 32kHz CPU
  7632. clock, between keystrokes unless it has work to do. When would
  7633. that 5 MHz JTAG clock be usable?
  7634. @b{Solution #1 - A special circuit}
  7635. In order to make use of this,
  7636. your CPU, board, and JTAG adapter must all support the RTCK
  7637. feature. Not all of them support this; keep reading!
  7638. The RTCK ("Return TCK") signal in some ARM chips is used to help with
  7639. this problem. ARM has a good description of the problem described at
  7640. this link: @url{http://www.arm.com/support/faqdev/4170.html} [checked
  7641. 28/nov/2008]. Link title: ``How does the JTAG synchronisation logic
  7642. work? / how does adaptive clocking work?''.
  7643. The nice thing about adaptive clocking is that ``battery powered hand
  7644. held device example'' - the adaptiveness works perfectly all the
  7645. time. One can set a break point or halt the system in the deep power
  7646. down code, slow step out until the system speeds up.
  7647. Note that adaptive clocking may also need to work at the board level,
  7648. when a board-level scan chain has multiple chips.
  7649. Parallel clock voting schemes are good way to implement this,
  7650. both within and between chips, and can easily be implemented
  7651. with a CPLD.
  7652. It's not difficult to have logic fan a module's input TCK signal out
  7653. to each TAP in the scan chain, and then wait until each TAP's RTCK comes
  7654. back with the right polarity before changing the output RTCK signal.
  7655. Texas Instruments makes some clock voting logic available
  7656. for free (with no support) in VHDL form; see
  7657. @url{http://tiexpressdsp.com/index.php/Adaptive_Clocking}
  7658. @b{Solution #2 - Always works - but may be slower}
  7659. Often this is a perfectly acceptable solution.
  7660. In most simple terms: Often the JTAG clock must be 1/10 to 1/12 of
  7661. the target clock speed. But what that ``magic division'' is varies
  7662. depending on the chips on your board.
  7663. @b{ARM rule of thumb} Most ARM based systems require an 6:1 division;
  7664. ARM11 cores use an 8:1 division.
  7665. @b{Xilinx rule of thumb} is 1/12 the clock speed.
  7666. Note: most full speed FT2232 based JTAG adapters are limited to a
  7667. maximum of 6MHz. The ones using USB high speed chips (FT2232H)
  7668. often support faster clock rates (and adaptive clocking).
  7669. You can still debug the 'low power' situations - you just need to
  7670. either use a fixed and very slow JTAG clock rate ... or else
  7671. manually adjust the clock speed at every step. (Adjusting is painful
  7672. and tedious, and is not always practical.)
  7673. It is however easy to ``code your way around it'' - i.e.: Cheat a little,
  7674. have a special debug mode in your application that does a ``high power
  7675. sleep''. If you are careful - 98% of your problems can be debugged
  7676. this way.
  7677. Note that on ARM you may need to avoid using the @emph{wait for interrupt}
  7678. operation in your idle loops even if you don't otherwise change the CPU
  7679. clock rate.
  7680. That operation gates the CPU clock, and thus the JTAG clock; which
  7681. prevents JTAG access. One consequence is not being able to @command{halt}
  7682. cores which are executing that @emph{wait for interrupt} operation.
  7683. To set the JTAG frequency use the command:
  7684. @example
  7685. # Example: 1.234MHz
  7686. adapter_khz 1234
  7687. @end example
  7688. @item @b{Win32 Pathnames} Why don't backslashes work in Windows paths?
  7689. OpenOCD uses Tcl and a backslash is an escape char. Use @{ and @}
  7690. around Windows filenames.
  7691. @example
  7692. > echo \a
  7693. > echo @{\a@}
  7694. \a
  7695. > echo "\a"
  7696. >
  7697. @end example
  7698. @item @b{Missing: cygwin1.dll} OpenOCD complains about a missing cygwin1.dll.
  7699. Make sure you have Cygwin installed, or at least a version of OpenOCD that
  7700. claims to come with all the necessary DLLs. When using Cygwin, try launching
  7701. OpenOCD from the Cygwin shell.
  7702. @item @b{Breakpoint Issue} I'm trying to set a breakpoint using GDB (or a frontend like Insight or
  7703. Eclipse), but OpenOCD complains that "Info: arm7_9_common.c:213
  7704. arm7_9_add_breakpoint(): sw breakpoint requested, but software breakpoints not enabled".
  7705. GDB issues software breakpoints when a normal breakpoint is requested, or to implement
  7706. source-line single-stepping. On ARMv4T systems, like ARM7TDMI, ARM720T or ARM920T,
  7707. software breakpoints consume one of the two available hardware breakpoints.
  7708. @item @b{LPC2000 Flash} When erasing or writing LPC2000 on-chip flash, the operation fails at random.
  7709. Make sure the core frequency specified in the @option{flash lpc2000} line matches the
  7710. clock at the time you're programming the flash. If you've specified the crystal's
  7711. frequency, make sure the PLL is disabled. If you've specified the full core speed
  7712. (e.g. 60MHz), make sure the PLL is enabled.
  7713. @item @b{Amontec Chameleon} When debugging using an Amontec Chameleon in its JTAG Accelerator configuration,
  7714. I keep getting "Error: amt_jtagaccel.c:184 amt_wait_scan_busy(): amt_jtagaccel timed
  7715. out while waiting for end of scan, rtck was disabled".
  7716. Make sure your PC's parallel port operates in EPP mode. You might have to try several
  7717. settings in your PC BIOS (ECP, EPP, and different versions of those).
  7718. @item @b{Data Aborts} When debugging with OpenOCD and GDB (plain GDB, Insight, or Eclipse),
  7719. I get lots of "Error: arm7_9_common.c:1771 arm7_9_read_memory():
  7720. memory read caused data abort".
  7721. The errors are non-fatal, and are the result of GDB trying to trace stack frames
  7722. beyond the last valid frame. It might be possible to prevent this by setting up
  7723. a proper "initial" stack frame, if you happen to know what exactly has to
  7724. be done, feel free to add this here.
  7725. @b{Simple:} In your startup code - push 8 registers of zeros onto the
  7726. stack before calling main(). What GDB is doing is ``climbing'' the run
  7727. time stack by reading various values on the stack using the standard
  7728. call frame for the target. GDB keeps going - until one of 2 things
  7729. happen @b{#1} an invalid frame is found, or @b{#2} some huge number of
  7730. stackframes have been processed. By pushing zeros on the stack, GDB
  7731. gracefully stops.
  7732. @b{Debugging Interrupt Service Routines} - In your ISR before you call
  7733. your C code, do the same - artifically push some zeros onto the stack,
  7734. remember to pop them off when the ISR is done.
  7735. @b{Also note:} If you have a multi-threaded operating system, they
  7736. often do not @b{in the intrest of saving memory} waste these few
  7737. bytes. Painful...
  7738. @item @b{JTAG Reset Config} I get the following message in the OpenOCD console (or log file):
  7739. "Warning: arm7_9_common.c:679 arm7_9_assert_reset(): srst resets test logic, too".
  7740. This warning doesn't indicate any serious problem, as long as you don't want to
  7741. debug your core right out of reset. Your .cfg file specified @option{jtag_reset
  7742. trst_and_srst srst_pulls_trst} to tell OpenOCD that either your board,
  7743. your debugger or your target uC (e.g. LPC2000) can't assert the two reset signals
  7744. independently. With this setup, it's not possible to halt the core right out of
  7745. reset, everything else should work fine.
  7746. @item @b{USB Power} When using OpenOCD in conjunction with Amontec JTAGkey and the Yagarto
  7747. toolchain (Eclipse, arm-elf-gcc, arm-elf-gdb), the debugging seems to be
  7748. unstable. When single-stepping over large blocks of code, GDB and OpenOCD
  7749. quit with an error message. Is there a stability issue with OpenOCD?
  7750. No, this is not a stability issue concerning OpenOCD. Most users have solved
  7751. this issue by simply using a self-powered USB hub, which they connect their
  7752. Amontec JTAGkey to. Apparently, some computers do not provide a USB power
  7753. supply stable enough for the Amontec JTAGkey to be operated.
  7754. @b{Laptops running on battery have this problem too...}
  7755. @item @b{USB Power} When using the Amontec JTAGkey, sometimes OpenOCD crashes with the
  7756. following error messages: "Error: ft2232.c:201 ft2232_read(): FT_Read returned:
  7757. 4" and "Error: ft2232.c:365 ft2232_send_and_recv(): couldn't read from FT2232".
  7758. What does that mean and what might be the reason for this?
  7759. First of all, the reason might be the USB power supply. Try using a self-powered
  7760. hub instead of a direct connection to your computer. Secondly, the error code 4
  7761. corresponds to an FT_IO_ERROR, which means that the driver for the FTDI USB
  7762. chip ran into some sort of error - this points us to a USB problem.
  7763. @item @b{GDB Disconnects} When using the Amontec JTAGkey, sometimes OpenOCD crashes with the following
  7764. error message: "Error: gdb_server.c:101 gdb_get_char(): read: 10054".
  7765. What does that mean and what might be the reason for this?
  7766. Error code 10054 corresponds to WSAECONNRESET, which means that the debugger (GDB)
  7767. has closed the connection to OpenOCD. This might be a GDB issue.
  7768. @item @b{LPC2000 Flash} In the configuration file in the section where flash device configurations
  7769. are described, there is a parameter for specifying the clock frequency
  7770. for LPC2000 internal flash devices (e.g. @option{flash bank $_FLASHNAME lpc2000
  7771. 0x0 0x40000 0 0 $_TARGETNAME lpc2000_v1 14746 calc_checksum}), which must be
  7772. specified in kilohertz. However, I do have a quartz crystal of a
  7773. frequency that contains fractions of kilohertz (e.g. 14,745,600 Hz,
  7774. i.e. 14,745.600 kHz). Is it possible to specify real numbers for the
  7775. clock frequency?
  7776. No. The clock frequency specified here must be given as an integral number.
  7777. However, this clock frequency is used by the In-Application-Programming (IAP)
  7778. routines of the LPC2000 family only, which seems to be very tolerant concerning
  7779. the given clock frequency, so a slight difference between the specified clock
  7780. frequency and the actual clock frequency will not cause any trouble.
  7781. @item @b{Command Order} Do I have to keep a specific order for the commands in the configuration file?
  7782. Well, yes and no. Commands can be given in arbitrary order, yet the
  7783. devices listed for the JTAG scan chain must be given in the right
  7784. order (jtag newdevice), with the device closest to the TDO-Pin being
  7785. listed first. In general, whenever objects of the same type exist
  7786. which require an index number, then these objects must be given in the
  7787. right order (jtag newtap, targets and flash banks - a target
  7788. references a jtag newtap and a flash bank references a target).
  7789. You can use the ``scan_chain'' command to verify and display the tap order.
  7790. Also, some commands can't execute until after @command{init} has been
  7791. processed. Such commands include @command{nand probe} and everything
  7792. else that needs to write to controller registers, perhaps for setting
  7793. up DRAM and loading it with code.
  7794. @anchor{faqtaporder}
  7795. @item @b{JTAG TAP Order} Do I have to declare the TAPS in some
  7796. particular order?
  7797. Yes; whenever you have more than one, you must declare them in
  7798. the same order used by the hardware.
  7799. Many newer devices have multiple JTAG TAPs. For example: ST
  7800. Microsystems STM32 chips have two TAPs, a ``boundary scan TAP'' and
  7801. ``Cortex-M3'' TAP. Example: The STM32 reference manual, Document ID:
  7802. RM0008, Section 26.5, Figure 259, page 651/681, the ``TDI'' pin is
  7803. connected to the boundary scan TAP, which then connects to the
  7804. Cortex-M3 TAP, which then connects to the TDO pin.
  7805. Thus, the proper order for the STM32 chip is: (1) The Cortex-M3, then
  7806. (2) The boundary scan TAP. If your board includes an additional JTAG
  7807. chip in the scan chain (for example a Xilinx CPLD or FPGA) you could
  7808. place it before or after the STM32 chip in the chain. For example:
  7809. @itemize @bullet
  7810. @item OpenOCD_TDI(output) -> STM32 TDI Pin (BS Input)
  7811. @item STM32 BS TDO (output) -> STM32 Cortex-M3 TDI (input)
  7812. @item STM32 Cortex-M3 TDO (output) -> SM32 TDO Pin
  7813. @item STM32 TDO Pin (output) -> Xilinx TDI Pin (input)
  7814. @item Xilinx TDO Pin -> OpenOCD TDO (input)
  7815. @end itemize
  7816. The ``jtag device'' commands would thus be in the order shown below. Note:
  7817. @itemize @bullet
  7818. @item jtag newtap Xilinx tap -irlen ...
  7819. @item jtag newtap stm32 cpu -irlen ...
  7820. @item jtag newtap stm32 bs -irlen ...
  7821. @item # Create the debug target and say where it is
  7822. @item target create stm32.cpu -chain-position stm32.cpu ...
  7823. @end itemize
  7824. @item @b{SYSCOMP} Sometimes my debugging session terminates with an error. When I look into the
  7825. log file, I can see these error messages: Error: arm7_9_common.c:561
  7826. arm7_9_execute_sys_speed(): timeout waiting for SYSCOMP
  7827. TODO.
  7828. @end enumerate
  7829. @node Tcl Crash Course
  7830. @chapter Tcl Crash Course
  7831. @cindex Tcl
  7832. Not everyone knows Tcl - this is not intended to be a replacement for
  7833. learning Tcl, the intent of this chapter is to give you some idea of
  7834. how the Tcl scripts work.
  7835. This chapter is written with two audiences in mind. (1) OpenOCD users
  7836. who need to understand a bit more of how Jim-Tcl works so they can do
  7837. something useful, and (2) those that want to add a new command to
  7838. OpenOCD.
  7839. @section Tcl Rule #1
  7840. There is a famous joke, it goes like this:
  7841. @enumerate
  7842. @item Rule #1: The wife is always correct
  7843. @item Rule #2: If you think otherwise, See Rule #1
  7844. @end enumerate
  7845. The Tcl equal is this:
  7846. @enumerate
  7847. @item Rule #1: Everything is a string
  7848. @item Rule #2: If you think otherwise, See Rule #1
  7849. @end enumerate
  7850. As in the famous joke, the consequences of Rule #1 are profound. Once
  7851. you understand Rule #1, you will understand Tcl.
  7852. @section Tcl Rule #1b
  7853. There is a second pair of rules.
  7854. @enumerate
  7855. @item Rule #1: Control flow does not exist. Only commands
  7856. @* For example: the classic FOR loop or IF statement is not a control
  7857. flow item, they are commands, there is no such thing as control flow
  7858. in Tcl.
  7859. @item Rule #2: If you think otherwise, See Rule #1
  7860. @* Actually what happens is this: There are commands that by
  7861. convention, act like control flow key words in other languages. One of
  7862. those commands is the word ``for'', another command is ``if''.
  7863. @end enumerate
  7864. @section Per Rule #1 - All Results are strings
  7865. Every Tcl command results in a string. The word ``result'' is used
  7866. deliberatly. No result is just an empty string. Remember: @i{Rule #1 -
  7867. Everything is a string}
  7868. @section Tcl Quoting Operators
  7869. In life of a Tcl script, there are two important periods of time, the
  7870. difference is subtle.
  7871. @enumerate
  7872. @item Parse Time
  7873. @item Evaluation Time
  7874. @end enumerate
  7875. The two key items here are how ``quoted things'' work in Tcl. Tcl has
  7876. three primary quoting constructs, the [square-brackets] the
  7877. @{curly-braces@} and ``double-quotes''
  7878. By now you should know $VARIABLES always start with a $DOLLAR
  7879. sign. BTW: To set a variable, you actually use the command ``set'', as
  7880. in ``set VARNAME VALUE'' much like the ancient BASIC langauge ``let x
  7881. = 1'' statement, but without the equal sign.
  7882. @itemize @bullet
  7883. @item @b{[square-brackets]}
  7884. @* @b{[square-brackets]} are command substitutions. It operates much
  7885. like Unix Shell `back-ticks`. The result of a [square-bracket]
  7886. operation is exactly 1 string. @i{Remember Rule #1 - Everything is a
  7887. string}. These two statements are roughly identical:
  7888. @example
  7889. # bash example
  7890. X=`date`
  7891. echo "The Date is: $X"
  7892. # Tcl example
  7893. set X [date]
  7894. puts "The Date is: $X"
  7895. @end example
  7896. @item @b{``double-quoted-things''}
  7897. @* @b{``double-quoted-things''} are just simply quoted
  7898. text. $VARIABLES and [square-brackets] are expanded in place - the
  7899. result however is exactly 1 string. @i{Remember Rule #1 - Everything
  7900. is a string}
  7901. @example
  7902. set x "Dinner"
  7903. puts "It is now \"[date]\", $x is in 1 hour"
  7904. @end example
  7905. @item @b{@{Curly-Braces@}}
  7906. @*@b{@{Curly-Braces@}} are magic: $VARIABLES and [square-brackets] are
  7907. parsed, but are NOT expanded or executed. @{Curly-Braces@} are like
  7908. 'single-quote' operators in BASH shell scripts, with the added
  7909. feature: @{curly-braces@} can be nested, single quotes can not. @{@{@{this is
  7910. nested 3 times@}@}@} NOTE: [date] is a bad example;
  7911. at this writing, Jim/OpenOCD does not have a date command.
  7912. @end itemize
  7913. @section Consequences of Rule 1/2/3/4
  7914. The consequences of Rule 1 are profound.
  7915. @subsection Tokenisation & Execution.
  7916. Of course, whitespace, blank lines and #comment lines are handled in
  7917. the normal way.
  7918. As a script is parsed, each (multi) line in the script file is
  7919. tokenised and according to the quoting rules. After tokenisation, that
  7920. line is immedatly executed.
  7921. Multi line statements end with one or more ``still-open''
  7922. @{curly-braces@} which - eventually - closes a few lines later.
  7923. @subsection Command Execution
  7924. Remember earlier: There are no ``control flow''
  7925. statements in Tcl. Instead there are COMMANDS that simply act like
  7926. control flow operators.
  7927. Commands are executed like this:
  7928. @enumerate
  7929. @item Parse the next line into (argc) and (argv[]).
  7930. @item Look up (argv[0]) in a table and call its function.
  7931. @item Repeat until End Of File.
  7932. @end enumerate
  7933. It sort of works like this:
  7934. @example
  7935. for(;;)@{
  7936. ReadAndParse( &argc, &argv );
  7937. cmdPtr = LookupCommand( argv[0] );
  7938. (*cmdPtr->Execute)( argc, argv );
  7939. @}
  7940. @end example
  7941. When the command ``proc'' is parsed (which creates a procedure
  7942. function) it gets 3 parameters on the command line. @b{1} the name of
  7943. the proc (function), @b{2} the list of parameters, and @b{3} the body
  7944. of the function. Not the choice of words: LIST and BODY. The PROC
  7945. command stores these items in a table somewhere so it can be found by
  7946. ``LookupCommand()''
  7947. @subsection The FOR command
  7948. The most interesting command to look at is the FOR command. In Tcl,
  7949. the FOR command is normally implemented in C. Remember, FOR is a
  7950. command just like any other command.
  7951. When the ascii text containing the FOR command is parsed, the parser
  7952. produces 5 parameter strings, @i{(If in doubt: Refer to Rule #1)} they
  7953. are:
  7954. @enumerate 0
  7955. @item The ascii text 'for'
  7956. @item The start text
  7957. @item The test expression
  7958. @item The next text
  7959. @item The body text
  7960. @end enumerate
  7961. Sort of reminds you of ``main( int argc, char **argv )'' does it not?
  7962. Remember @i{Rule #1 - Everything is a string.} The key point is this:
  7963. Often many of those parameters are in @{curly-braces@} - thus the
  7964. variables inside are not expanded or replaced until later.
  7965. Remember that every Tcl command looks like the classic ``main( argc,
  7966. argv )'' function in C. In JimTCL - they actually look like this:
  7967. @example
  7968. int
  7969. MyCommand( Jim_Interp *interp,
  7970. int *argc,
  7971. Jim_Obj * const *argvs );
  7972. @end example
  7973. Real Tcl is nearly identical. Although the newer versions have
  7974. introduced a byte-code parser and intepreter, but at the core, it
  7975. still operates in the same basic way.
  7976. @subsection FOR command implementation
  7977. To understand Tcl it is perhaps most helpful to see the FOR
  7978. command. Remember, it is a COMMAND not a control flow structure.
  7979. In Tcl there are two underlying C helper functions.
  7980. Remember Rule #1 - You are a string.
  7981. The @b{first} helper parses and executes commands found in an ascii
  7982. string. Commands can be seperated by semicolons, or newlines. While
  7983. parsing, variables are expanded via the quoting rules.
  7984. The @b{second} helper evaluates an ascii string as a numerical
  7985. expression and returns a value.
  7986. Here is an example of how the @b{FOR} command could be
  7987. implemented. The pseudo code below does not show error handling.
  7988. @example
  7989. void Execute_AsciiString( void *interp, const char *string );
  7990. int Evaluate_AsciiExpression( void *interp, const char *string );
  7991. int
  7992. MyForCommand( void *interp,
  7993. int argc,
  7994. char **argv )
  7995. @{
  7996. if( argc != 5 )@{
  7997. SetResult( interp, "WRONG number of parameters");
  7998. return ERROR;
  7999. @}
  8000. // argv[0] = the ascii string just like C
  8001. // Execute the start statement.
  8002. Execute_AsciiString( interp, argv[1] );
  8003. // Top of loop test
  8004. for(;;)@{
  8005. i = Evaluate_AsciiExpression(interp, argv[2]);
  8006. if( i == 0 )
  8007. break;
  8008. // Execute the body
  8009. Execute_AsciiString( interp, argv[3] );
  8010. // Execute the LOOP part
  8011. Execute_AsciiString( interp, argv[4] );
  8012. @}
  8013. // Return no error
  8014. SetResult( interp, "" );
  8015. return SUCCESS;
  8016. @}
  8017. @end example
  8018. Every other command IF, WHILE, FORMAT, PUTS, EXPR, everything works
  8019. in the same basic way.
  8020. @section OpenOCD Tcl Usage
  8021. @subsection source and find commands
  8022. @b{Where:} In many configuration files
  8023. @* Example: @b{ source [find FILENAME] }
  8024. @*Remember the parsing rules
  8025. @enumerate
  8026. @item The @command{find} command is in square brackets,
  8027. and is executed with the parameter FILENAME. It should find and return
  8028. the full path to a file with that name; it uses an internal search path.
  8029. The RESULT is a string, which is substituted into the command line in
  8030. place of the bracketed @command{find} command.
  8031. (Don't try to use a FILENAME which includes the "#" character.
  8032. That character begins Tcl comments.)
  8033. @item The @command{source} command is executed with the resulting filename;
  8034. it reads a file and executes as a script.
  8035. @end enumerate
  8036. @subsection format command
  8037. @b{Where:} Generally occurs in numerous places.
  8038. @* Tcl has no command like @b{printf()}, instead it has @b{format}, which is really more like
  8039. @b{sprintf()}.
  8040. @b{Example}
  8041. @example
  8042. set x 6
  8043. set y 7
  8044. puts [format "The answer: %d" [expr $x * $y]]
  8045. @end example
  8046. @enumerate
  8047. @item The SET command creates 2 variables, X and Y.
  8048. @item The double [nested] EXPR command performs math
  8049. @* The EXPR command produces numerical result as a string.
  8050. @* Refer to Rule #1
  8051. @item The format command is executed, producing a single string
  8052. @* Refer to Rule #1.
  8053. @item The PUTS command outputs the text.
  8054. @end enumerate
  8055. @subsection Body or Inlined Text
  8056. @b{Where:} Various TARGET scripts.
  8057. @example
  8058. #1 Good
  8059. proc someproc @{@} @{
  8060. ... multiple lines of stuff ...
  8061. @}
  8062. $_TARGETNAME configure -event FOO someproc
  8063. #2 Good - no variables
  8064. $_TARGETNAME confgure -event foo "this ; that;"
  8065. #3 Good Curly Braces
  8066. $_TARGETNAME configure -event FOO @{
  8067. puts "Time: [date]"
  8068. @}
  8069. #4 DANGER DANGER DANGER
  8070. $_TARGETNAME configure -event foo "puts \"Time: [date]\""
  8071. @end example
  8072. @enumerate
  8073. @item The $_TARGETNAME is an OpenOCD variable convention.
  8074. @*@b{$_TARGETNAME} represents the last target created, the value changes
  8075. each time a new target is created. Remember the parsing rules. When
  8076. the ascii text is parsed, the @b{$_TARGETNAME} becomes a simple string,
  8077. the name of the target which happens to be a TARGET (object)
  8078. command.
  8079. @item The 2nd parameter to the @option{-event} parameter is a TCBODY
  8080. @*There are 4 examples:
  8081. @enumerate
  8082. @item The TCLBODY is a simple string that happens to be a proc name
  8083. @item The TCLBODY is several simple commands seperated by semicolons
  8084. @item The TCLBODY is a multi-line @{curly-brace@} quoted string
  8085. @item The TCLBODY is a string with variables that get expanded.
  8086. @end enumerate
  8087. In the end, when the target event FOO occurs the TCLBODY is
  8088. evaluated. Method @b{#1} and @b{#2} are functionally identical. For
  8089. Method @b{#3} and @b{#4} it is more interesting. What is the TCLBODY?
  8090. Remember the parsing rules. In case #3, @{curly-braces@} mean the
  8091. $VARS and [square-brackets] are expanded later, when the EVENT occurs,
  8092. and the text is evaluated. In case #4, they are replaced before the
  8093. ``Target Object Command'' is executed. This occurs at the same time
  8094. $_TARGETNAME is replaced. In case #4 the date will never
  8095. change. @{BTW: [date] is a bad example; at this writing,
  8096. Jim/OpenOCD does not have a date command@}
  8097. @end enumerate
  8098. @subsection Global Variables
  8099. @b{Where:} You might discover this when writing your own procs @* In
  8100. simple terms: Inside a PROC, if you need to access a global variable
  8101. you must say so. See also ``upvar''. Example:
  8102. @example
  8103. proc myproc @{ @} @{
  8104. set y 0 #Local variable Y
  8105. global x #Global variable X
  8106. puts [format "X=%d, Y=%d" $x $y]
  8107. @}
  8108. @end example
  8109. @section Other Tcl Hacks
  8110. @b{Dynamic variable creation}
  8111. @example
  8112. # Dynamically create a bunch of variables.
  8113. for @{ set x 0 @} @{ $x < 32 @} @{ set x [expr $x + 1]@} @{
  8114. # Create var name
  8115. set vn [format "BIT%d" $x]
  8116. # Make it a global
  8117. global $vn
  8118. # Set it.
  8119. set $vn [expr (1 << $x)]
  8120. @}
  8121. @end example
  8122. @b{Dynamic proc/command creation}
  8123. @example
  8124. # One "X" function - 5 uart functions.
  8125. foreach who @{A B C D E@}
  8126. proc [format "show_uart%c" $who] @{ @} "show_UARTx $who"
  8127. @}
  8128. @end example
  8129. @include fdl.texi
  8130. @node OpenOCD Concept Index
  8131. @comment DO NOT use the plain word ``Index'', reason: CYGWIN filename
  8132. @comment case issue with ``Index.html'' and ``index.html''
  8133. @comment Occurs when creating ``--html --no-split'' output
  8134. @comment This fix is based on: http://sourceware.org/ml/binutils/2006-05/msg00215.html
  8135. @unnumbered OpenOCD Concept Index
  8136. @printindex cp
  8137. @node Command and Driver Index
  8138. @unnumbered Command and Driver Index
  8139. @printindex fn
  8140. @bye