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.
 
 
 
 
 
 

11292 lines
424 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. * Server Configuration:: Server 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, STMicroelectronics STM32 and Energy Micro EFM32) and
  135. Intel Quark (x10xx) 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. STMicroelectronics has an adapter called @b{ST-LINK}.
  383. They only work with STMicroelectronics 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. @item @b{STLINK-V3}
  392. @* This is available standalone and as part of some kits.
  393. @* Link: @url{http://www.st.com/stlink-v3}
  394. @end itemize
  395. For info the original ST-LINK enumerates using the mass storage usb class; however,
  396. its implementation is completely broken. The result is this causes issues under Linux.
  397. The simplest solution is to get Linux to ignore the ST-LINK using one of the following methods:
  398. @itemize @bullet
  399. @item modprobe -r usb-storage && modprobe usb-storage quirks=483:3744:i
  400. @item add "options usb-storage quirks=483:3744:i" to /etc/modprobe.conf
  401. @end itemize
  402. @section USB TI/Stellaris ICDI based
  403. Texas Instruments has an adapter called @b{ICDI}.
  404. It is not to be confused with the FTDI based adapters that were originally fitted to their
  405. evaluation boards. This is the adapter fitted to the Stellaris LaunchPad.
  406. @section USB CMSIS-DAP based
  407. ARM has released a interface standard called CMSIS-DAP that simplifies connecting
  408. debuggers to ARM Cortex based targets @url{http://www.keil.com/support/man/docs/dapdebug/dapdebug_introduction.htm}.
  409. @section USB Other
  410. @itemize @bullet
  411. @item @b{USBprog}
  412. @* Link: @url{http://shop.embedded-projects.net/} - which uses an Atmel MEGA32 and a UBN9604
  413. @item @b{USB - Presto}
  414. @* Link: @url{http://tools.asix.net/prg_presto.htm}
  415. @item @b{Versaloon-Link}
  416. @* Link: @url{http://www.versaloon.com}
  417. @item @b{ARM-JTAG-EW}
  418. @* Link: @url{http://www.olimex.com/dev/arm-jtag-ew.html}
  419. @item @b{Buspirate}
  420. @* Link: @url{http://dangerousprototypes.com/bus-pirate-manual/}
  421. @item @b{opendous}
  422. @* Link: @url{http://code.google.com/p/opendous-jtag/} - which uses an AT90USB162
  423. @item @b{estick}
  424. @* Link: @url{http://code.google.com/p/estick-jtag/}
  425. @item @b{Keil ULINK v1}
  426. @* Link: @url{http://www.keil.com/ulink1/}
  427. @item @b{TI XDS110 Debug Probe}
  428. @* The XDS110 is included as the embedded debug probe on many Texas Instruments
  429. LaunchPad evaluation boards.
  430. @* The XDS110 is also available as a stand-alone USB debug probe. The XDS110
  431. stand-alone probe has the additional ability to supply voltage to the target
  432. board via its AUX FUNCTIONS port. Use the
  433. @command{xds110_supply_voltage <millivolts>} command to set the voltage. 0 turns
  434. off the supply. Otherwise, the supply can be set to any value in the range 1800
  435. to 3600 millivolts.
  436. @* Link: @url{http://processors.wiki.ti.com/index.php/XDS110}
  437. @* Link: @url{http://processors.wiki.ti.com/index.php/XDS_Emulation_Software_Package#XDS110_Support_Utilities}
  438. @end itemize
  439. @section IBM PC Parallel Printer Port Based
  440. The two well-known ``JTAG Parallel Ports'' cables are the Xilinx DLC5
  441. and the Macraigor Wiggler. There are many clones and variations of
  442. these on the market.
  443. Note that parallel ports are becoming much less common, so if you
  444. have the choice you should probably avoid these adapters in favor
  445. of USB-based ones.
  446. @itemize @bullet
  447. @item @b{Wiggler} - There are many clones of this.
  448. @* Link: @url{http://www.macraigor.com/wiggler.htm}
  449. @item @b{DLC5} - From XILINX - There are many clones of this
  450. @* Link: Search the web for: ``XILINX DLC5'' - it is no longer
  451. produced, PDF schematics are easily found and it is easy to make.
  452. @item @b{Amontec - JTAG Accelerator}
  453. @* Link: @url{http://www.amontec.com/jtag_accelerator.shtml}
  454. @item @b{Wiggler2}
  455. @* Link: @url{http://www.ccac.rwth-aachen.de/~michaels/index.php/hardware/armjtag}
  456. @item @b{Wiggler_ntrst_inverted}
  457. @* Yet another variation - See the source code, src/jtag/parport.c
  458. @item @b{old_amt_wiggler}
  459. @* Unknown - probably not on the market today
  460. @item @b{arm-jtag}
  461. @* Link: Most likely @url{http://www.olimex.com/dev/arm-jtag.html} [another wiggler clone]
  462. @item @b{chameleon}
  463. @* Link: @url{http://www.amontec.com/chameleon.shtml}
  464. @item @b{Triton}
  465. @* Unknown.
  466. @item @b{Lattice}
  467. @* ispDownload from Lattice Semiconductor
  468. @url{http://www.latticesemi.com/lit/docs/@/devtools/dlcable.pdf}
  469. @item @b{flashlink}
  470. @* From STMicroelectronics;
  471. @* Link: @url{http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/DM00039500.pdf}
  472. @end itemize
  473. @section Other...
  474. @itemize @bullet
  475. @item @b{ep93xx}
  476. @* An EP93xx based Linux machine using the GPIO pins directly.
  477. @item @b{at91rm9200}
  478. @* Like the EP93xx - but an ATMEL AT91RM9200 based solution using the GPIO pins on the chip.
  479. @item @b{bcm2835gpio}
  480. @* A BCM2835-based board (e.g. Raspberry Pi) using the GPIO pins of the expansion header.
  481. @item @b{imx_gpio}
  482. @* A NXP i.MX-based board (e.g. Wandboard) using the GPIO pins (should work on any i.MX processor).
  483. @item @b{jtag_vpi}
  484. @* A JTAG driver acting as a client for the JTAG VPI server interface.
  485. @* Link: @url{http://github.com/fjullien/jtag_vpi}
  486. @item @b{xlnx_pcie_xvc}
  487. @* A JTAG driver exposing Xilinx Virtual Cable over PCI Express to OpenOCD as JTAG interface.
  488. @end itemize
  489. @node About Jim-Tcl
  490. @chapter About Jim-Tcl
  491. @cindex Jim-Tcl
  492. @cindex tcl
  493. OpenOCD uses a small ``Tcl Interpreter'' known as Jim-Tcl.
  494. This programming language provides a simple and extensible
  495. command interpreter.
  496. All commands presented in this Guide are extensions to Jim-Tcl.
  497. You can use them as simple commands, without needing to learn
  498. much of anything about Tcl.
  499. Alternatively, you can write Tcl programs with them.
  500. You can learn more about Jim at its website, @url{http://jim.tcl.tk}.
  501. There is an active and responsive community, get on the mailing list
  502. if you have any questions. Jim-Tcl maintainers also lurk on the
  503. OpenOCD mailing list.
  504. @itemize @bullet
  505. @item @b{Jim vs. Tcl}
  506. @* Jim-Tcl is a stripped down version of the well known Tcl language,
  507. which can be found here: @url{http://www.tcl.tk}. Jim-Tcl has far
  508. fewer features. Jim-Tcl is several dozens of .C files and .H files and
  509. implements the basic Tcl command set. In contrast: Tcl 8.6 is a
  510. 4.2 MB .zip file containing 1540 files.
  511. @item @b{Missing Features}
  512. @* Our practice has been: Add/clone the real Tcl feature if/when
  513. needed. We welcome Jim-Tcl improvements, not bloat. Also there
  514. are a large number of optional Jim-Tcl features that are not
  515. enabled in OpenOCD.
  516. @item @b{Scripts}
  517. @* OpenOCD configuration scripts are Jim-Tcl Scripts. OpenOCD's
  518. command interpreter today is a mixture of (newer)
  519. Jim-Tcl commands, and the (older) original command interpreter.
  520. @item @b{Commands}
  521. @* At the OpenOCD telnet command line (or via the GDB monitor command) one
  522. can type a Tcl for() loop, set variables, etc.
  523. Some of the commands documented in this guide are implemented
  524. as Tcl scripts, from a @file{startup.tcl} file internal to the server.
  525. @item @b{Historical Note}
  526. @* Jim-Tcl was introduced to OpenOCD in spring 2008. Fall 2010,
  527. before OpenOCD 0.5 release, OpenOCD switched to using Jim-Tcl
  528. as a Git submodule, which greatly simplified upgrading Jim-Tcl
  529. to benefit from new features and bugfixes in Jim-Tcl.
  530. @item @b{Need a crash course in Tcl?}
  531. @*@xref{Tcl Crash Course}.
  532. @end itemize
  533. @node Running
  534. @chapter Running
  535. @cindex command line options
  536. @cindex logfile
  537. @cindex directory search
  538. Properly installing OpenOCD sets up your operating system to grant it access
  539. to the debug adapters. On Linux, this usually involves installing a file
  540. in @file{/etc/udev/rules.d,} so OpenOCD has permissions. An example rules file
  541. that works for many common adapters is shipped with OpenOCD in the
  542. @file{contrib} directory. MS-Windows needs
  543. complex and confusing driver configuration for every peripheral. Such issues
  544. are unique to each operating system, and are not detailed in this User's Guide.
  545. Then later you will invoke the OpenOCD server, with various options to
  546. tell it how each debug session should work.
  547. The @option{--help} option shows:
  548. @verbatim
  549. bash$ openocd --help
  550. --help | -h display this help
  551. --version | -v display OpenOCD version
  552. --file | -f use configuration file <name>
  553. --search | -s dir to search for config files and scripts
  554. --debug | -d set debug level to 3
  555. | -d<n> set debug level to <level>
  556. --log_output | -l redirect log output to file <name>
  557. --command | -c run <command>
  558. @end verbatim
  559. If you don't give any @option{-f} or @option{-c} options,
  560. OpenOCD tries to read the configuration file @file{openocd.cfg}.
  561. To specify one or more different
  562. configuration files, use @option{-f} options. For example:
  563. @example
  564. openocd -f config1.cfg -f config2.cfg -f config3.cfg
  565. @end example
  566. Configuration files and scripts are searched for in
  567. @enumerate
  568. @item the current directory,
  569. @item any search dir specified on the command line using the @option{-s} option,
  570. @item any search dir specified using the @command{add_script_search_dir} command,
  571. @item @file{$HOME/.openocd} (not on Windows),
  572. @item a directory in the @env{OPENOCD_SCRIPTS} environment variable (if set),
  573. @item the site wide script library @file{$pkgdatadir/site} and
  574. @item the OpenOCD-supplied script library @file{$pkgdatadir/scripts}.
  575. @end enumerate
  576. The first found file with a matching file name will be used.
  577. @quotation Note
  578. Don't try to use configuration script names or paths which
  579. include the "#" character. That character begins Tcl comments.
  580. @end quotation
  581. @section Simple setup, no customization
  582. In the best case, you can use two scripts from one of the script
  583. libraries, hook up your JTAG adapter, and start the server ... and
  584. your JTAG setup will just work "out of the box". Always try to
  585. start by reusing those scripts, but assume you'll need more
  586. customization even if this works. @xref{OpenOCD Project Setup}.
  587. If you find a script for your JTAG adapter, and for your board or
  588. target, you may be able to hook up your JTAG adapter then start
  589. the server with some variation of one of the following:
  590. @example
  591. openocd -f interface/ADAPTER.cfg -f board/MYBOARD.cfg
  592. openocd -f interface/ftdi/ADAPTER.cfg -f board/MYBOARD.cfg
  593. @end example
  594. You might also need to configure which reset signals are present,
  595. using @option{-c 'reset_config trst_and_srst'} or something similar.
  596. If all goes well you'll see output something like
  597. @example
  598. Open On-Chip Debugger 0.4.0 (2010-01-14-15:06)
  599. For bug reports, read
  600. http://openocd.org/doc/doxygen/bugs.html
  601. Info : JTAG tap: lm3s.cpu tap/device found: 0x3ba00477
  602. (mfg: 0x23b, part: 0xba00, ver: 0x3)
  603. @end example
  604. Seeing that "tap/device found" message, and no warnings, means
  605. the JTAG communication is working. That's a key milestone, but
  606. you'll probably need more project-specific setup.
  607. @section What OpenOCD does as it starts
  608. OpenOCD starts by processing the configuration commands provided
  609. on the command line or, if there were no @option{-c command} or
  610. @option{-f file.cfg} options given, in @file{openocd.cfg}.
  611. @xref{configurationstage,,Configuration Stage}.
  612. At the end of the configuration stage it verifies the JTAG scan
  613. chain defined using those commands; your configuration should
  614. ensure that this always succeeds.
  615. Normally, OpenOCD then starts running as a server.
  616. Alternatively, commands may be used to terminate the configuration
  617. stage early, perform work (such as updating some flash memory),
  618. and then shut down without acting as a server.
  619. Once OpenOCD starts running as a server, it waits for connections from
  620. clients (Telnet, GDB, RPC) and processes the commands issued through
  621. those channels.
  622. If you are having problems, you can enable internal debug messages via
  623. the @option{-d} option.
  624. Also it is possible to interleave Jim-Tcl commands w/config scripts using the
  625. @option{-c} command line switch.
  626. To enable debug output (when reporting problems or working on OpenOCD
  627. itself), use the @option{-d} command line switch. This sets the
  628. @option{debug_level} to "3", outputting the most information,
  629. including debug messages. The default setting is "2", outputting only
  630. informational messages, warnings and errors. You can also change this
  631. setting from within a telnet or gdb session using @command{debug_level<n>}
  632. (@pxref{debuglevel,,debug_level}).
  633. You can redirect all output from the server to a file using the
  634. @option{-l <logfile>} switch.
  635. Note! OpenOCD will launch the GDB & telnet server even if it can not
  636. establish a connection with the target. In general, it is possible for
  637. the JTAG controller to be unresponsive until the target is set up
  638. correctly via e.g. GDB monitor commands in a GDB init script.
  639. @node OpenOCD Project Setup
  640. @chapter OpenOCD Project Setup
  641. To use OpenOCD with your development projects, you need to do more than
  642. just connect the JTAG adapter hardware (dongle) to your development board
  643. and start the OpenOCD server.
  644. You also need to configure your OpenOCD server so that it knows
  645. about your adapter and board, and helps your work.
  646. You may also want to connect OpenOCD to GDB, possibly
  647. using Eclipse or some other GUI.
  648. @section Hooking up the JTAG Adapter
  649. Today's most common case is a dongle with a JTAG cable on one side
  650. (such as a ribbon cable with a 10-pin or 20-pin IDC connector)
  651. and a USB cable on the other.
  652. Instead of USB, some cables use Ethernet;
  653. older ones may use a PC parallel port, or even a serial port.
  654. @enumerate
  655. @item @emph{Start with power to your target board turned off},
  656. and nothing connected to your JTAG adapter.
  657. If you're particularly paranoid, unplug power to the board.
  658. It's important to have the ground signal properly set up,
  659. unless you are using a JTAG adapter which provides
  660. galvanic isolation between the target board and the
  661. debugging host.
  662. @item @emph{Be sure it's the right kind of JTAG connector.}
  663. If your dongle has a 20-pin ARM connector, you need some kind
  664. of adapter (or octopus, see below) to hook it up to
  665. boards using 14-pin or 10-pin connectors ... or to 20-pin
  666. connectors which don't use ARM's pinout.
  667. In the same vein, make sure the voltage levels are compatible.
  668. Not all JTAG adapters have the level shifters needed to work
  669. with 1.2 Volt boards.
  670. @item @emph{Be certain the cable is properly oriented} or you might
  671. damage your board. In most cases there are only two possible
  672. ways to connect the cable.
  673. Connect the JTAG cable from your adapter to the board.
  674. Be sure it's firmly connected.
  675. In the best case, the connector is keyed to physically
  676. prevent you from inserting it wrong.
  677. This is most often done using a slot on the board's male connector
  678. housing, which must match a key on the JTAG cable's female connector.
  679. If there's no housing, then you must look carefully and
  680. make sure pin 1 on the cable hooks up to pin 1 on the board.
  681. Ribbon cables are frequently all grey except for a wire on one
  682. edge, which is red. The red wire is pin 1.
  683. Sometimes dongles provide cables where one end is an ``octopus'' of
  684. color coded single-wire connectors, instead of a connector block.
  685. These are great when converting from one JTAG pinout to another,
  686. but are tedious to set up.
  687. Use these with connector pinout diagrams to help you match up the
  688. adapter signals to the right board pins.
  689. @item @emph{Connect the adapter's other end} once the JTAG cable is connected.
  690. A USB, parallel, or serial port connector will go to the host which
  691. you are using to run OpenOCD.
  692. For Ethernet, consult the documentation and your network administrator.
  693. For USB-based JTAG adapters you have an easy sanity check at this point:
  694. does the host operating system see the JTAG adapter? If you're running
  695. Linux, try the @command{lsusb} command. If that host is an
  696. MS-Windows host, you'll need to install a driver before OpenOCD works.
  697. @item @emph{Connect the adapter's power supply, if needed.}
  698. This step is primarily for non-USB adapters,
  699. but sometimes USB adapters need extra power.
  700. @item @emph{Power up the target board.}
  701. Unless you just let the magic smoke escape,
  702. you're now ready to set up the OpenOCD server
  703. so you can use JTAG to work with that board.
  704. @end enumerate
  705. Talk with the OpenOCD server using
  706. telnet (@code{telnet localhost 4444} on many systems) or GDB.
  707. @xref{GDB and OpenOCD}.
  708. @section Project Directory
  709. There are many ways you can configure OpenOCD and start it up.
  710. A simple way to organize them all involves keeping a
  711. single directory for your work with a given board.
  712. When you start OpenOCD from that directory,
  713. it searches there first for configuration files, scripts,
  714. files accessed through semihosting,
  715. and for code you upload to the target board.
  716. It is also the natural place to write files,
  717. such as log files and data you download from the board.
  718. @section Configuration Basics
  719. There are two basic ways of configuring OpenOCD, and
  720. a variety of ways you can mix them.
  721. Think of the difference as just being how you start the server:
  722. @itemize
  723. @item Many @option{-f file} or @option{-c command} options on the command line
  724. @item No options, but a @dfn{user config file}
  725. in the current directory named @file{openocd.cfg}
  726. @end itemize
  727. Here is an example @file{openocd.cfg} file for a setup
  728. using a Signalyzer FT2232-based JTAG adapter to talk to
  729. a board with an Atmel AT91SAM7X256 microcontroller:
  730. @example
  731. source [find interface/ftdi/signalyzer.cfg]
  732. # GDB can also flash my flash!
  733. gdb_memory_map enable
  734. gdb_flash_program enable
  735. source [find target/sam7x256.cfg]
  736. @end example
  737. Here is the command line equivalent of that configuration:
  738. @example
  739. openocd -f interface/ftdi/signalyzer.cfg \
  740. -c "gdb_memory_map enable" \
  741. -c "gdb_flash_program enable" \
  742. -f target/sam7x256.cfg
  743. @end example
  744. You could wrap such long command lines in shell scripts,
  745. each supporting a different development task.
  746. One might re-flash the board with a specific firmware version.
  747. Another might set up a particular debugging or run-time environment.
  748. @quotation Important
  749. At this writing (October 2009) the command line method has
  750. problems with how it treats variables.
  751. For example, after @option{-c "set VAR value"}, or doing the
  752. same in a script, the variable @var{VAR} will have no value
  753. that can be tested in a later script.
  754. @end quotation
  755. Here we will focus on the simpler solution: one user config
  756. file, including basic configuration plus any TCL procedures
  757. to simplify your work.
  758. @section User Config Files
  759. @cindex config file, user
  760. @cindex user config file
  761. @cindex config file, overview
  762. A user configuration file ties together all the parts of a project
  763. in one place.
  764. One of the following will match your situation best:
  765. @itemize
  766. @item Ideally almost everything comes from configuration files
  767. provided by someone else.
  768. For example, OpenOCD distributes a @file{scripts} directory
  769. (probably in @file{/usr/share/openocd/scripts} on Linux).
  770. Board and tool vendors can provide these too, as can individual
  771. user sites; the @option{-s} command line option lets you say
  772. where to find these files. (@xref{Running}.)
  773. The AT91SAM7X256 example above works this way.
  774. Three main types of non-user configuration file each have their
  775. own subdirectory in the @file{scripts} directory:
  776. @enumerate
  777. @item @b{interface} -- one for each different debug adapter;
  778. @item @b{board} -- one for each different board
  779. @item @b{target} -- the chips which integrate CPUs and other JTAG TAPs
  780. @end enumerate
  781. Best case: include just two files, and they handle everything else.
  782. The first is an interface config file.
  783. The second is board-specific, and it sets up the JTAG TAPs and
  784. their GDB targets (by deferring to some @file{target.cfg} file),
  785. declares all flash memory, and leaves you nothing to do except
  786. meet your deadline:
  787. @example
  788. source [find interface/olimex-jtag-tiny.cfg]
  789. source [find board/csb337.cfg]
  790. @end example
  791. Boards with a single microcontroller often won't need more
  792. than the target config file, as in the AT91SAM7X256 example.
  793. That's because there is no external memory (flash, DDR RAM), and
  794. the board differences are encapsulated by application code.
  795. @item Maybe you don't know yet what your board looks like to JTAG.
  796. Once you know the @file{interface.cfg} file to use, you may
  797. need help from OpenOCD to discover what's on the board.
  798. Once you find the JTAG TAPs, you can just search for appropriate
  799. target and board
  800. configuration files ... or write your own, from the bottom up.
  801. @xref{autoprobing,,Autoprobing}.
  802. @item You can often reuse some standard config files but
  803. need to write a few new ones, probably a @file{board.cfg} file.
  804. You will be using commands described later in this User's Guide,
  805. and working with the guidelines in the next chapter.
  806. For example, there may be configuration files for your JTAG adapter
  807. and target chip, but you need a new board-specific config file
  808. giving access to your particular flash chips.
  809. Or you might need to write another target chip configuration file
  810. for a new chip built around the Cortex-M3 core.
  811. @quotation Note
  812. When you write new configuration files, please submit
  813. them for inclusion in the next OpenOCD release.
  814. For example, a @file{board/newboard.cfg} file will help the
  815. next users of that board, and a @file{target/newcpu.cfg}
  816. will help support users of any board using that chip.
  817. @end quotation
  818. @item
  819. You may may need to write some C code.
  820. It may be as simple as supporting a new FT2232 or parport
  821. based adapter; a bit more involved, like a NAND or NOR flash
  822. controller driver; or a big piece of work like supporting
  823. a new chip architecture.
  824. @end itemize
  825. Reuse the existing config files when you can.
  826. Look first in the @file{scripts/boards} area, then @file{scripts/targets}.
  827. You may find a board configuration that's a good example to follow.
  828. When you write config files, separate the reusable parts
  829. (things every user of that interface, chip, or board needs)
  830. from ones specific to your environment and debugging approach.
  831. @itemize
  832. @item
  833. For example, a @code{gdb-attach} event handler that invokes
  834. the @command{reset init} command will interfere with debugging
  835. early boot code, which performs some of the same actions
  836. that the @code{reset-init} event handler does.
  837. @item
  838. Likewise, the @command{arm9 vector_catch} command (or
  839. @cindex vector_catch
  840. its siblings @command{xscale vector_catch}
  841. and @command{cortex_m vector_catch}) can be a time-saver
  842. during some debug sessions, but don't make everyone use that either.
  843. Keep those kinds of debugging aids in your user config file,
  844. along with messaging and tracing setup.
  845. (@xref{softwaredebugmessagesandtracing,,Software Debug Messages and Tracing}.)
  846. @item
  847. You might need to override some defaults.
  848. For example, you might need to move, shrink, or back up the target's
  849. work area if your application needs much SRAM.
  850. @item
  851. TCP/IP port configuration is another example of something which
  852. is environment-specific, and should only appear in
  853. a user config file. @xref{tcpipports,,TCP/IP Ports}.
  854. @end itemize
  855. @section Project-Specific Utilities
  856. A few project-specific utility
  857. routines may well speed up your work.
  858. Write them, and keep them in your project's user config file.
  859. For example, if you are making a boot loader work on a
  860. board, it's nice to be able to debug the ``after it's
  861. loaded to RAM'' parts separately from the finicky early
  862. code which sets up the DDR RAM controller and clocks.
  863. A script like this one, or a more GDB-aware sibling,
  864. may help:
  865. @example
  866. proc ramboot @{ @} @{
  867. # Reset, running the target's "reset-init" scripts
  868. # to initialize clocks and the DDR RAM controller.
  869. # Leave the CPU halted.
  870. reset init
  871. # Load CONFIG_SKIP_LOWLEVEL_INIT version into DDR RAM.
  872. load_image u-boot.bin 0x20000000
  873. # Start running.
  874. resume 0x20000000
  875. @}
  876. @end example
  877. Then once that code is working you will need to make it
  878. boot from NOR flash; a different utility would help.
  879. Alternatively, some developers write to flash using GDB.
  880. (You might use a similar script if you're working with a flash
  881. based microcontroller application instead of a boot loader.)
  882. @example
  883. proc newboot @{ @} @{
  884. # Reset, leaving the CPU halted. The "reset-init" event
  885. # proc gives faster access to the CPU and to NOR flash;
  886. # "reset halt" would be slower.
  887. reset init
  888. # Write standard version of U-Boot into the first two
  889. # sectors of NOR flash ... the standard version should
  890. # do the same lowlevel init as "reset-init".
  891. flash protect 0 0 1 off
  892. flash erase_sector 0 0 1
  893. flash write_bank 0 u-boot.bin 0x0
  894. flash protect 0 0 1 on
  895. # Reboot from scratch using that new boot loader.
  896. reset run
  897. @}
  898. @end example
  899. You may need more complicated utility procedures when booting
  900. from NAND.
  901. That often involves an extra bootloader stage,
  902. running from on-chip SRAM to perform DDR RAM setup so it can load
  903. the main bootloader code (which won't fit into that SRAM).
  904. Other helper scripts might be used to write production system images,
  905. involving considerably more than just a three stage bootloader.
  906. @section Target Software Changes
  907. Sometimes you may want to make some small changes to the software
  908. you're developing, to help make JTAG debugging work better.
  909. For example, in C or assembly language code you might
  910. use @code{#ifdef JTAG_DEBUG} (or its converse) around code
  911. handling issues like:
  912. @itemize @bullet
  913. @item @b{Watchdog Timers}...
  914. Watchdog timers are typically used to automatically reset systems if
  915. some application task doesn't periodically reset the timer. (The
  916. assumption is that the system has locked up if the task can't run.)
  917. When a JTAG debugger halts the system, that task won't be able to run
  918. and reset the timer ... potentially causing resets in the middle of
  919. your debug sessions.
  920. It's rarely a good idea to disable such watchdogs, since their usage
  921. needs to be debugged just like all other parts of your firmware.
  922. That might however be your only option.
  923. Look instead for chip-specific ways to stop the watchdog from counting
  924. while the system is in a debug halt state. It may be simplest to set
  925. that non-counting mode in your debugger startup scripts. You may however
  926. need a different approach when, for example, a motor could be physically
  927. damaged by firmware remaining inactive in a debug halt state. That might
  928. involve a type of firmware mode where that "non-counting" mode is disabled
  929. at the beginning then re-enabled at the end; a watchdog reset might fire
  930. and complicate the debug session, but hardware (or people) would be
  931. protected.@footnote{Note that many systems support a "monitor mode" debug
  932. that is a somewhat cleaner way to address such issues. You can think of
  933. it as only halting part of the system, maybe just one task,
  934. instead of the whole thing.
  935. At this writing, January 2010, OpenOCD based debugging does not support
  936. monitor mode debug, only "halt mode" debug.}
  937. @item @b{ARM Semihosting}...
  938. @cindex ARM semihosting
  939. When linked with a special runtime library provided with many
  940. toolchains@footnote{See chapter 8 "Semihosting" in
  941. @uref{http://infocenter.arm.com/help/topic/com.arm.doc.dui0203i/DUI0203I_rvct_developer_guide.pdf,
  942. ARM DUI 0203I}, the "RealView Compilation Tools Developer Guide".
  943. The CodeSourcery EABI toolchain also includes a semihosting library.},
  944. your target code can use I/O facilities on the debug host. That library
  945. provides a small set of system calls which are handled by OpenOCD.
  946. It can let the debugger provide your system console and a file system,
  947. helping with early debugging or providing a more capable environment
  948. for sometimes-complex tasks like installing system firmware onto
  949. NAND or SPI flash.
  950. @item @b{ARM Wait-For-Interrupt}...
  951. Many ARM chips synchronize the JTAG clock using the core clock.
  952. Low power states which stop that core clock thus prevent JTAG access.
  953. Idle loops in tasking environments often enter those low power states
  954. via the @code{WFI} instruction (or its coprocessor equivalent, before ARMv7).
  955. You may want to @emph{disable that instruction} in source code,
  956. or otherwise prevent using that state,
  957. to ensure you can get JTAG access at any time.@footnote{As a more
  958. polite alternative, some processors have special debug-oriented
  959. registers which can be used to change various features including
  960. how the low power states are clocked while debugging.
  961. The STM32 DBGMCU_CR register is an example; at the cost of extra
  962. power consumption, JTAG can be used during low power states.}
  963. For example, the OpenOCD @command{halt} command may not
  964. work for an idle processor otherwise.
  965. @item @b{Delay after reset}...
  966. Not all chips have good support for debugger access
  967. right after reset; many LPC2xxx chips have issues here.
  968. Similarly, applications that reconfigure pins used for
  969. JTAG access as they start will also block debugger access.
  970. To work with boards like this, @emph{enable a short delay loop}
  971. the first thing after reset, before "real" startup activities.
  972. For example, one second's delay is usually more than enough
  973. time for a JTAG debugger to attach, so that
  974. early code execution can be debugged
  975. or firmware can be replaced.
  976. @item @b{Debug Communications Channel (DCC)}...
  977. Some processors include mechanisms to send messages over JTAG.
  978. Many ARM cores support these, as do some cores from other vendors.
  979. (OpenOCD may be able to use this DCC internally, speeding up some
  980. operations like writing to memory.)
  981. Your application may want to deliver various debugging messages
  982. over JTAG, by @emph{linking with a small library of code}
  983. provided with OpenOCD and using the utilities there to send
  984. various kinds of message.
  985. @xref{softwaredebugmessagesandtracing,,Software Debug Messages and Tracing}.
  986. @end itemize
  987. @section Target Hardware Setup
  988. Chip vendors often provide software development boards which
  989. are highly configurable, so that they can support all options
  990. that product boards may require. @emph{Make sure that any
  991. jumpers or switches match the system configuration you are
  992. working with.}
  993. Common issues include:
  994. @itemize @bullet
  995. @item @b{JTAG setup} ...
  996. Boards may support more than one JTAG configuration.
  997. Examples include jumpers controlling pullups versus pulldowns
  998. on the nTRST and/or nSRST signals, and choice of connectors
  999. (e.g. which of two headers on the base board,
  1000. or one from a daughtercard).
  1001. For some Texas Instruments boards, you may need to jumper the
  1002. EMU0 and EMU1 signals (which OpenOCD won't currently control).
  1003. @item @b{Boot Modes} ...
  1004. Complex chips often support multiple boot modes, controlled
  1005. by external jumpers. Make sure this is set up correctly.
  1006. For example many i.MX boards from NXP need to be jumpered
  1007. to "ATX mode" to start booting using the on-chip ROM, when
  1008. using second stage bootloader code stored in a NAND flash chip.
  1009. Such explicit configuration is common, and not limited to
  1010. booting from NAND. You might also need to set jumpers to
  1011. start booting using code loaded from an MMC/SD card; external
  1012. SPI flash; Ethernet, UART, or USB links; NOR flash; OneNAND
  1013. flash; some external host; or various other sources.
  1014. @item @b{Memory Addressing} ...
  1015. Boards which support multiple boot modes may also have jumpers
  1016. to configure memory addressing. One board, for example, jumpers
  1017. external chipselect 0 (used for booting) to address either
  1018. a large SRAM (which must be pre-loaded via JTAG), NOR flash,
  1019. or NAND flash. When it's jumpered to address NAND flash, that
  1020. board must also be told to start booting from on-chip ROM.
  1021. Your @file{board.cfg} file may also need to be told this jumper
  1022. configuration, so that it can know whether to declare NOR flash
  1023. using @command{flash bank} or instead declare NAND flash with
  1024. @command{nand device}; and likewise which probe to perform in
  1025. its @code{reset-init} handler.
  1026. A closely related issue is bus width. Jumpers might need to
  1027. distinguish between 8 bit or 16 bit bus access for the flash
  1028. used to start booting.
  1029. @item @b{Peripheral Access} ...
  1030. Development boards generally provide access to every peripheral
  1031. on the chip, sometimes in multiple modes (such as by providing
  1032. multiple audio codec chips).
  1033. This interacts with software
  1034. configuration of pin multiplexing, where for example a
  1035. given pin may be routed either to the MMC/SD controller
  1036. or the GPIO controller. It also often interacts with
  1037. configuration jumpers. One jumper may be used to route
  1038. signals to an MMC/SD card slot or an expansion bus (which
  1039. might in turn affect booting); others might control which
  1040. audio or video codecs are used.
  1041. @end itemize
  1042. Plus you should of course have @code{reset-init} event handlers
  1043. which set up the hardware to match that jumper configuration.
  1044. That includes in particular any oscillator or PLL used to clock
  1045. the CPU, and any memory controllers needed to access external
  1046. memory and peripherals. Without such handlers, you won't be
  1047. able to access those resources without working target firmware
  1048. which can do that setup ... this can be awkward when you're
  1049. trying to debug that target firmware. Even if there's a ROM
  1050. bootloader which handles a few issues, it rarely provides full
  1051. access to all board-specific capabilities.
  1052. @node Config File Guidelines
  1053. @chapter Config File Guidelines
  1054. This chapter is aimed at any user who needs to write a config file,
  1055. including developers and integrators of OpenOCD and any user who
  1056. needs to get a new board working smoothly.
  1057. It provides guidelines for creating those files.
  1058. You should find the following directories under
  1059. @t{$(INSTALLDIR)/scripts}, with config files maintained upstream. Use
  1060. them as-is where you can; or as models for new files.
  1061. @itemize @bullet
  1062. @item @file{interface} ...
  1063. These are for debug adapters. Files that specify configuration to use
  1064. specific JTAG, SWD and other adapters go here.
  1065. @item @file{board} ...
  1066. Think Circuit Board, PWA, PCB, they go by many names. Board files
  1067. contain initialization items that are specific to a board.
  1068. They reuse target configuration files, since the same
  1069. microprocessor chips are used on many boards,
  1070. but support for external parts varies widely. For
  1071. example, the SDRAM initialization sequence for the board, or the type
  1072. of external flash and what address it uses. Any initialization
  1073. sequence to enable that external flash or SDRAM should be found in the
  1074. board file. Boards may also contain multiple targets: two CPUs; or
  1075. a CPU and an FPGA.
  1076. @item @file{target} ...
  1077. Think chip. The ``target'' directory represents the JTAG TAPs
  1078. on a chip
  1079. which OpenOCD should control, not a board. Two common types of targets
  1080. are ARM chips and FPGA or CPLD chips.
  1081. When a chip has multiple TAPs (maybe it has both ARM and DSP cores),
  1082. the target config file defines all of them.
  1083. @item @emph{more} ... browse for other library files which may be useful.
  1084. For example, there are various generic and CPU-specific utilities.
  1085. @end itemize
  1086. The @file{openocd.cfg} user config
  1087. file may override features in any of the above files by
  1088. setting variables before sourcing the target file, or by adding
  1089. commands specific to their situation.
  1090. @section Interface Config Files
  1091. The user config file
  1092. should be able to source one of these files with a command like this:
  1093. @example
  1094. source [find interface/FOOBAR.cfg]
  1095. @end example
  1096. A preconfigured interface file should exist for every debug adapter
  1097. in use today with OpenOCD.
  1098. That said, perhaps some of these config files
  1099. have only been used by the developer who created it.
  1100. A separate chapter gives information about how to set these up.
  1101. @xref{Debug Adapter Configuration}.
  1102. Read the OpenOCD source code (and Developer's Guide)
  1103. if you have a new kind of hardware interface
  1104. and need to provide a driver for it.
  1105. @section Board Config Files
  1106. @cindex config file, board
  1107. @cindex board config file
  1108. The user config file
  1109. should be able to source one of these files with a command like this:
  1110. @example
  1111. source [find board/FOOBAR.cfg]
  1112. @end example
  1113. The point of a board config file is to package everything
  1114. about a given board that user config files need to know.
  1115. In summary the board files should contain (if present)
  1116. @enumerate
  1117. @item One or more @command{source [find target/...cfg]} statements
  1118. @item NOR flash configuration (@pxref{norconfiguration,,NOR Configuration})
  1119. @item NAND flash configuration (@pxref{nandconfiguration,,NAND Configuration})
  1120. @item Target @code{reset} handlers for SDRAM and I/O configuration
  1121. @item JTAG adapter reset configuration (@pxref{Reset Configuration})
  1122. @item All things that are not ``inside a chip''
  1123. @end enumerate
  1124. Generic things inside target chips belong in target config files,
  1125. not board config files. So for example a @code{reset-init} event
  1126. handler should know board-specific oscillator and PLL parameters,
  1127. which it passes to target-specific utility code.
  1128. The most complex task of a board config file is creating such a
  1129. @code{reset-init} event handler.
  1130. Define those handlers last, after you verify the rest of the board
  1131. configuration works.
  1132. @subsection Communication Between Config files
  1133. In addition to target-specific utility code, another way that
  1134. board and target config files communicate is by following a
  1135. convention on how to use certain variables.
  1136. The full Tcl/Tk language supports ``namespaces'', but Jim-Tcl does not.
  1137. Thus the rule we follow in OpenOCD is this: Variables that begin with
  1138. a leading underscore are temporary in nature, and can be modified and
  1139. used at will within a target configuration file.
  1140. Complex board config files can do the things like this,
  1141. for a board with three chips:
  1142. @example
  1143. # Chip #1: PXA270 for network side, big endian
  1144. set CHIPNAME network
  1145. set ENDIAN big
  1146. source [find target/pxa270.cfg]
  1147. # on return: _TARGETNAME = network.cpu
  1148. # other commands can refer to the "network.cpu" target.
  1149. $_TARGETNAME configure .... events for this CPU..
  1150. # Chip #2: PXA270 for video side, little endian
  1151. set CHIPNAME video
  1152. set ENDIAN little
  1153. source [find target/pxa270.cfg]
  1154. # on return: _TARGETNAME = video.cpu
  1155. # other commands can refer to the "video.cpu" target.
  1156. $_TARGETNAME configure .... events for this CPU..
  1157. # Chip #3: Xilinx FPGA for glue logic
  1158. set CHIPNAME xilinx
  1159. unset ENDIAN
  1160. source [find target/spartan3.cfg]
  1161. @end example
  1162. That example is oversimplified because it doesn't show any flash memory,
  1163. or the @code{reset-init} event handlers to initialize external DRAM
  1164. or (assuming it needs it) load a configuration into the FPGA.
  1165. Such features are usually needed for low-level work with many boards,
  1166. where ``low level'' implies that the board initialization software may
  1167. not be working. (That's a common reason to need JTAG tools. Another
  1168. is to enable working with microcontroller-based systems, which often
  1169. have no debugging support except a JTAG connector.)
  1170. Target config files may also export utility functions to board and user
  1171. config files. Such functions should use name prefixes, to help avoid
  1172. naming collisions.
  1173. Board files could also accept input variables from user config files.
  1174. For example, there might be a @code{J4_JUMPER} setting used to identify
  1175. what kind of flash memory a development board is using, or how to set
  1176. up other clocks and peripherals.
  1177. @subsection Variable Naming Convention
  1178. @cindex variable names
  1179. Most boards have only one instance of a chip.
  1180. However, it should be easy to create a board with more than
  1181. one such chip (as shown above).
  1182. Accordingly, we encourage these conventions for naming
  1183. variables associated with different @file{target.cfg} files,
  1184. to promote consistency and
  1185. so that board files can override target defaults.
  1186. Inputs to target config files include:
  1187. @itemize @bullet
  1188. @item @code{CHIPNAME} ...
  1189. This gives a name to the overall chip, and is used as part of
  1190. tap identifier dotted names.
  1191. While the default is normally provided by the chip manufacturer,
  1192. board files may need to distinguish between instances of a chip.
  1193. @item @code{ENDIAN} ...
  1194. By default @option{little} - although chips may hard-wire @option{big}.
  1195. Chips that can't change endianess don't need to use this variable.
  1196. @item @code{CPUTAPID} ...
  1197. When OpenOCD examines the JTAG chain, it can be told verify the
  1198. chips against the JTAG IDCODE register.
  1199. The target file will hold one or more defaults, but sometimes the
  1200. chip in a board will use a different ID (perhaps a newer revision).
  1201. @end itemize
  1202. Outputs from target config files include:
  1203. @itemize @bullet
  1204. @item @code{_TARGETNAME} ...
  1205. By convention, this variable is created by the target configuration
  1206. script. The board configuration file may make use of this variable to
  1207. configure things like a ``reset init'' script, or other things
  1208. specific to that board and that target.
  1209. If the chip has 2 targets, the names are @code{_TARGETNAME0},
  1210. @code{_TARGETNAME1}, ... etc.
  1211. @end itemize
  1212. @subsection The reset-init Event Handler
  1213. @cindex event, reset-init
  1214. @cindex reset-init handler
  1215. Board config files run in the OpenOCD configuration stage;
  1216. they can't use TAPs or targets, since they haven't been
  1217. fully set up yet.
  1218. This means you can't write memory or access chip registers;
  1219. you can't even verify that a flash chip is present.
  1220. That's done later in event handlers, of which the target @code{reset-init}
  1221. handler is one of the most important.
  1222. Except on microcontrollers, the basic job of @code{reset-init} event
  1223. handlers is setting up flash and DRAM, as normally handled by boot loaders.
  1224. Microcontrollers rarely use boot loaders; they run right out of their
  1225. on-chip flash and SRAM memory. But they may want to use one of these
  1226. handlers too, if just for developer convenience.
  1227. @quotation Note
  1228. Because this is so very board-specific, and chip-specific, no examples
  1229. are included here.
  1230. Instead, look at the board config files distributed with OpenOCD.
  1231. If you have a boot loader, its source code will help; so will
  1232. configuration files for other JTAG tools
  1233. (@pxref{translatingconfigurationfiles,,Translating Configuration Files}).
  1234. @end quotation
  1235. Some of this code could probably be shared between different boards.
  1236. For example, setting up a DRAM controller often doesn't differ by
  1237. much except the bus width (16 bits or 32?) and memory timings, so a
  1238. reusable TCL procedure loaded by the @file{target.cfg} file might take
  1239. those as parameters.
  1240. Similarly with oscillator, PLL, and clock setup;
  1241. and disabling the watchdog.
  1242. Structure the code cleanly, and provide comments to help
  1243. the next developer doing such work.
  1244. (@emph{You might be that next person} trying to reuse init code!)
  1245. The last thing normally done in a @code{reset-init} handler is probing
  1246. whatever flash memory was configured. For most chips that needs to be
  1247. done while the associated target is halted, either because JTAG memory
  1248. access uses the CPU or to prevent conflicting CPU access.
  1249. @subsection JTAG Clock Rate
  1250. Before your @code{reset-init} handler has set up
  1251. the PLLs and clocking, you may need to run with
  1252. a low JTAG clock rate.
  1253. @xref{jtagspeed,,JTAG Speed}.
  1254. Then you'd increase that rate after your handler has
  1255. made it possible to use the faster JTAG clock.
  1256. When the initial low speed is board-specific, for example
  1257. because it depends on a board-specific oscillator speed, then
  1258. you should probably set it up in the board config file;
  1259. if it's target-specific, it belongs in the target config file.
  1260. For most ARM-based processors the fastest JTAG clock@footnote{A FAQ
  1261. @uref{http://www.arm.com/support/faqdev/4170.html} gives details.}
  1262. is one sixth of the CPU clock; or one eighth for ARM11 cores.
  1263. Consult chip documentation to determine the peak JTAG clock rate,
  1264. which might be less than that.
  1265. @quotation Warning
  1266. On most ARMs, JTAG clock detection is coupled to the core clock, so
  1267. software using a @option{wait for interrupt} operation blocks JTAG access.
  1268. Adaptive clocking provides a partial workaround, but a more complete
  1269. solution just avoids using that instruction with JTAG debuggers.
  1270. @end quotation
  1271. If both the chip and the board support adaptive clocking,
  1272. use the @command{jtag_rclk}
  1273. command, in case your board is used with JTAG adapter which
  1274. also supports it. Otherwise use @command{adapter speed}.
  1275. Set the slow rate at the beginning of the reset sequence,
  1276. and the faster rate as soon as the clocks are at full speed.
  1277. @anchor{theinitboardprocedure}
  1278. @subsection The init_board procedure
  1279. @cindex init_board procedure
  1280. The concept of @code{init_board} procedure is very similar to @code{init_targets}
  1281. (@xref{theinittargetsprocedure,,The init_targets procedure}.) - it's a replacement of ``linear''
  1282. configuration scripts. This procedure is meant to be executed when OpenOCD enters run stage
  1283. (@xref{enteringtherunstage,,Entering the Run Stage},) after @code{init_targets}. The idea to have
  1284. separate @code{init_targets} and @code{init_board} procedures is to allow the first one to configure
  1285. everything target specific (internal flash, internal RAM, etc.) and the second one to configure
  1286. everything board specific (reset signals, chip frequency, reset-init event handler, external memory, etc.).
  1287. Additionally ``linear'' board config file will most likely fail when target config file uses
  1288. @code{init_targets} scheme (``linear'' script is executed before @code{init} and @code{init_targets} - after),
  1289. so separating these two configuration stages is very convenient, as the easiest way to overcome this
  1290. problem is to convert board config file to use @code{init_board} procedure. Board config scripts don't
  1291. need to override @code{init_targets} defined in target config files when they only need to add some specifics.
  1292. Just as @code{init_targets}, the @code{init_board} procedure can be overridden by ``next level'' script (which sources
  1293. the original), allowing greater code reuse.
  1294. @example
  1295. ### board_file.cfg ###
  1296. # source target file that does most of the config in init_targets
  1297. source [find target/target.cfg]
  1298. proc enable_fast_clock @{@} @{
  1299. # enables fast on-board clock source
  1300. # configures the chip to use it
  1301. @}
  1302. # initialize only board specifics - reset, clock, adapter frequency
  1303. proc init_board @{@} @{
  1304. reset_config trst_and_srst trst_pulls_srst
  1305. $_TARGETNAME configure -event reset-start @{
  1306. adapter speed 100
  1307. @}
  1308. $_TARGETNAME configure -event reset-init @{
  1309. enable_fast_clock
  1310. adapter speed 10000
  1311. @}
  1312. @}
  1313. @end example
  1314. @section Target Config Files
  1315. @cindex config file, target
  1316. @cindex target config file
  1317. Board config files communicate with target config files using
  1318. naming conventions as described above, and may source one or
  1319. more target config files like this:
  1320. @example
  1321. source [find target/FOOBAR.cfg]
  1322. @end example
  1323. The point of a target config file is to package everything
  1324. about a given chip that board config files need to know.
  1325. In summary the target files should contain
  1326. @enumerate
  1327. @item Set defaults
  1328. @item Add TAPs to the scan chain
  1329. @item Add CPU targets (includes GDB support)
  1330. @item CPU/Chip/CPU-Core specific features
  1331. @item On-Chip flash
  1332. @end enumerate
  1333. As a rule of thumb, a target file sets up only one chip.
  1334. For a microcontroller, that will often include a single TAP,
  1335. which is a CPU needing a GDB target, and its on-chip flash.
  1336. More complex chips may include multiple TAPs, and the target
  1337. config file may need to define them all before OpenOCD
  1338. can talk to the chip.
  1339. For example, some phone chips have JTAG scan chains that include
  1340. an ARM core for operating system use, a DSP,
  1341. another ARM core embedded in an image processing engine,
  1342. and other processing engines.
  1343. @subsection Default Value Boiler Plate Code
  1344. All target configuration files should start with code like this,
  1345. letting board config files express environment-specific
  1346. differences in how things should be set up.
  1347. @example
  1348. # Boards may override chip names, perhaps based on role,
  1349. # but the default should match what the vendor uses
  1350. if @{ [info exists CHIPNAME] @} @{
  1351. set _CHIPNAME $CHIPNAME
  1352. @} else @{
  1353. set _CHIPNAME sam7x256
  1354. @}
  1355. # ONLY use ENDIAN with targets that can change it.
  1356. if @{ [info exists ENDIAN] @} @{
  1357. set _ENDIAN $ENDIAN
  1358. @} else @{
  1359. set _ENDIAN little
  1360. @}
  1361. # TAP identifiers may change as chips mature, for example with
  1362. # new revision fields (the "3" here). Pick a good default; you
  1363. # can pass several such identifiers to the "jtag newtap" command.
  1364. if @{ [info exists CPUTAPID ] @} @{
  1365. set _CPUTAPID $CPUTAPID
  1366. @} else @{
  1367. set _CPUTAPID 0x3f0f0f0f
  1368. @}
  1369. @end example
  1370. @c but 0x3f0f0f0f is for an str73x part ...
  1371. @emph{Remember:} Board config files may include multiple target
  1372. config files, or the same target file multiple times
  1373. (changing at least @code{CHIPNAME}).
  1374. Likewise, the target configuration file should define
  1375. @code{_TARGETNAME} (or @code{_TARGETNAME0} etc) and
  1376. use it later on when defining debug targets:
  1377. @example
  1378. set _TARGETNAME $_CHIPNAME.cpu
  1379. target create $_TARGETNAME arm7tdmi -chain-position $_TARGETNAME
  1380. @end example
  1381. @subsection Adding TAPs to the Scan Chain
  1382. After the ``defaults'' are set up,
  1383. add the TAPs on each chip to the JTAG scan chain.
  1384. @xref{TAP Declaration}, and the naming convention
  1385. for taps.
  1386. In the simplest case the chip has only one TAP,
  1387. probably for a CPU or FPGA.
  1388. The config file for the Atmel AT91SAM7X256
  1389. looks (in part) like this:
  1390. @example
  1391. jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
  1392. @end example
  1393. A board with two such at91sam7 chips would be able
  1394. to source such a config file twice, with different
  1395. values for @code{CHIPNAME}, so
  1396. it adds a different TAP each time.
  1397. If there are nonzero @option{-expected-id} values,
  1398. OpenOCD attempts to verify the actual tap id against those values.
  1399. It will issue error messages if there is mismatch, which
  1400. can help to pinpoint problems in OpenOCD configurations.
  1401. @example
  1402. JTAG tap: sam7x256.cpu tap/device found: 0x3f0f0f0f
  1403. (Manufacturer: 0x787, Part: 0xf0f0, Version: 0x3)
  1404. ERROR: Tap: sam7x256.cpu - Expected id: 0x12345678, Got: 0x3f0f0f0f
  1405. ERROR: expected: mfg: 0x33c, part: 0x2345, ver: 0x1
  1406. ERROR: got: mfg: 0x787, part: 0xf0f0, ver: 0x3
  1407. @end example
  1408. There are more complex examples too, with chips that have
  1409. multiple TAPs. Ones worth looking at include:
  1410. @itemize
  1411. @item @file{target/omap3530.cfg} -- with disabled ARM and DSP,
  1412. plus a JRC to enable them
  1413. @item @file{target/str912.cfg} -- with flash, CPU, and boundary scan
  1414. @item @file{target/ti_dm355.cfg} -- with ETM, ARM, and JRC (this JRC
  1415. is not currently used)
  1416. @end itemize
  1417. @subsection Add CPU targets
  1418. After adding a TAP for a CPU, you should set it up so that
  1419. GDB and other commands can use it.
  1420. @xref{CPU Configuration}.
  1421. For the at91sam7 example above, the command can look like this;
  1422. note that @code{$_ENDIAN} is not needed, since OpenOCD defaults
  1423. to little endian, and this chip doesn't support changing that.
  1424. @example
  1425. set _TARGETNAME $_CHIPNAME.cpu
  1426. target create $_TARGETNAME arm7tdmi -chain-position $_TARGETNAME
  1427. @end example
  1428. Work areas are small RAM areas associated with CPU targets.
  1429. They are used by OpenOCD to speed up downloads,
  1430. and to download small snippets of code to program flash chips.
  1431. If the chip includes a form of ``on-chip-ram'' - and many do - define
  1432. a work area if you can.
  1433. Again using the at91sam7 as an example, this can look like:
  1434. @example
  1435. $_TARGETNAME configure -work-area-phys 0x00200000 \
  1436. -work-area-size 0x4000 -work-area-backup 0
  1437. @end example
  1438. @anchor{definecputargetsworkinginsmp}
  1439. @subsection Define CPU targets working in SMP
  1440. @cindex SMP
  1441. After setting targets, you can define a list of targets working in SMP.
  1442. @example
  1443. set _TARGETNAME_1 $_CHIPNAME.cpu1
  1444. set _TARGETNAME_2 $_CHIPNAME.cpu2
  1445. target create $_TARGETNAME_1 cortex_a -chain-position $_CHIPNAME.dap \
  1446. -coreid 0 -dbgbase $_DAP_DBG1
  1447. target create $_TARGETNAME_2 cortex_a -chain-position $_CHIPNAME.dap \
  1448. -coreid 1 -dbgbase $_DAP_DBG2
  1449. #define 2 targets working in smp.
  1450. target smp $_CHIPNAME.cpu2 $_CHIPNAME.cpu1
  1451. @end example
  1452. In the above example on cortex_a, 2 cpus are working in SMP.
  1453. In SMP only one GDB instance is created and :
  1454. @itemize @bullet
  1455. @item a set of hardware breakpoint sets the same breakpoint on all targets in the list.
  1456. @item halt command triggers the halt of all targets in the list.
  1457. @item resume command triggers the write context and the restart of all targets in the list.
  1458. @item following a breakpoint: the target stopped by the breakpoint is displayed to the GDB session.
  1459. @item dedicated GDB serial protocol packets are implemented for switching/retrieving the target
  1460. displayed by the GDB session @pxref{usingopenocdsmpwithgdb,,Using OpenOCD SMP with GDB}.
  1461. @end itemize
  1462. The SMP behaviour can be disabled/enabled dynamically. On cortex_a following
  1463. command have been implemented.
  1464. @itemize @bullet
  1465. @item cortex_a smp on : enable SMP mode, behaviour is as described above.
  1466. @item cortex_a smp off : disable SMP mode, the current target is the one
  1467. displayed in the GDB session, only this target is now controlled by GDB
  1468. session. This behaviour is useful during system boot up.
  1469. @item cortex_a smp : display current SMP mode.
  1470. @item cortex_a smp_gdb : display/fix the core id displayed in GDB session see
  1471. following example.
  1472. @end itemize
  1473. @example
  1474. >cortex_a smp_gdb
  1475. gdb coreid 0 -> -1
  1476. #0 : coreid 0 is displayed to GDB ,
  1477. #-> -1 : next resume triggers a real resume
  1478. > cortex_a smp_gdb 1
  1479. gdb coreid 0 -> 1
  1480. #0 :coreid 0 is displayed to GDB ,
  1481. #->1 : next resume displays coreid 1 to GDB
  1482. > resume
  1483. > cortex_a smp_gdb
  1484. gdb coreid 1 -> 1
  1485. #1 :coreid 1 is displayed to GDB ,
  1486. #->1 : next resume displays coreid 1 to GDB
  1487. > cortex_a smp_gdb -1
  1488. gdb coreid 1 -> -1
  1489. #1 :coreid 1 is displayed to GDB,
  1490. #->-1 : next resume triggers a real resume
  1491. @end example
  1492. @subsection Chip Reset Setup
  1493. As a rule, you should put the @command{reset_config} command
  1494. into the board file. Most things you think you know about a
  1495. chip can be tweaked by the board.
  1496. Some chips have specific ways the TRST and SRST signals are
  1497. managed. In the unusual case that these are @emph{chip specific}
  1498. and can never be changed by board wiring, they could go here.
  1499. For example, some chips can't support JTAG debugging without
  1500. both signals.
  1501. Provide a @code{reset-assert} event handler if you can.
  1502. Such a handler uses JTAG operations to reset the target,
  1503. letting this target config be used in systems which don't
  1504. provide the optional SRST signal, or on systems where you
  1505. don't want to reset all targets at once.
  1506. Such a handler might write to chip registers to force a reset,
  1507. use a JRC to do that (preferable -- the target may be wedged!),
  1508. or force a watchdog timer to trigger.
  1509. (For Cortex-M targets, this is not necessary. The target
  1510. driver knows how to use trigger an NVIC reset when SRST is
  1511. not available.)
  1512. Some chips need special attention during reset handling if
  1513. they're going to be used with JTAG.
  1514. An example might be needing to send some commands right
  1515. after the target's TAP has been reset, providing a
  1516. @code{reset-deassert-post} event handler that writes a chip
  1517. register to report that JTAG debugging is being done.
  1518. Another would be reconfiguring the watchdog so that it stops
  1519. counting while the core is halted in the debugger.
  1520. JTAG clocking constraints often change during reset, and in
  1521. some cases target config files (rather than board config files)
  1522. are the right places to handle some of those issues.
  1523. For example, immediately after reset most chips run using a
  1524. slower clock than they will use later.
  1525. That means that after reset (and potentially, as OpenOCD
  1526. first starts up) they must use a slower JTAG clock rate
  1527. than they will use later.
  1528. @xref{jtagspeed,,JTAG Speed}.
  1529. @quotation Important
  1530. When you are debugging code that runs right after chip
  1531. reset, getting these issues right is critical.
  1532. In particular, if you see intermittent failures when
  1533. OpenOCD verifies the scan chain after reset,
  1534. look at how you are setting up JTAG clocking.
  1535. @end quotation
  1536. @anchor{theinittargetsprocedure}
  1537. @subsection The init_targets procedure
  1538. @cindex init_targets procedure
  1539. Target config files can either be ``linear'' (script executed line-by-line when parsed in
  1540. configuration stage, @xref{configurationstage,,Configuration Stage},) or they can contain a special
  1541. procedure called @code{init_targets}, which will be executed when entering run stage
  1542. (after parsing all config files or after @code{init} command, @xref{enteringtherunstage,,Entering the Run Stage}.)
  1543. Such procedure can be overridden by ``next level'' script (which sources the original).
  1544. This concept facilitates code reuse when basic target config files provide generic configuration
  1545. procedures and @code{init_targets} procedure, which can then be sourced and enhanced or changed in
  1546. a ``more specific'' target config file. This is not possible with ``linear'' config scripts,
  1547. because sourcing them executes every initialization commands they provide.
  1548. @example
  1549. ### generic_file.cfg ###
  1550. proc setup_my_chip @{chip_name flash_size ram_size@} @{
  1551. # basic initialization procedure ...
  1552. @}
  1553. proc init_targets @{@} @{
  1554. # initializes generic chip with 4kB of flash and 1kB of RAM
  1555. setup_my_chip MY_GENERIC_CHIP 4096 1024
  1556. @}
  1557. ### specific_file.cfg ###
  1558. source [find target/generic_file.cfg]
  1559. proc init_targets @{@} @{
  1560. # initializes specific chip with 128kB of flash and 64kB of RAM
  1561. setup_my_chip MY_CHIP_WITH_128K_FLASH_64KB_RAM 131072 65536
  1562. @}
  1563. @end example
  1564. The easiest way to convert ``linear'' config files to @code{init_targets} version is to
  1565. enclose every line of ``code'' (i.e. not @code{source} commands, procedures, etc.) in this procedure.
  1566. For an example of this scheme see LPC2000 target config files.
  1567. The @code{init_boards} procedure is a similar concept concerning board config files
  1568. (@xref{theinitboardprocedure,,The init_board procedure}.)
  1569. @anchor{theinittargeteventsprocedure}
  1570. @subsection The init_target_events procedure
  1571. @cindex init_target_events procedure
  1572. A special procedure called @code{init_target_events} is run just after
  1573. @code{init_targets} (@xref{theinittargetsprocedure,,The init_targets
  1574. procedure}.) and before @code{init_board}
  1575. (@xref{theinitboardprocedure,,The init_board procedure}.) It is used
  1576. to set up default target events for the targets that do not have those
  1577. events already assigned.
  1578. @subsection ARM Core Specific Hacks
  1579. If the chip has a DCC, enable it. If the chip is an ARM9 with some
  1580. special high speed download features - enable it.
  1581. If present, the MMU, the MPU and the CACHE should be disabled.
  1582. Some ARM cores are equipped with trace support, which permits
  1583. examination of the instruction and data bus activity. Trace
  1584. activity is controlled through an ``Embedded Trace Module'' (ETM)
  1585. on one of the core's scan chains. The ETM emits voluminous data
  1586. through a ``trace port''. (@xref{armhardwaretracing,,ARM Hardware Tracing}.)
  1587. If you are using an external trace port,
  1588. configure it in your board config file.
  1589. If you are using an on-chip ``Embedded Trace Buffer'' (ETB),
  1590. configure it in your target config file.
  1591. @example
  1592. etm config $_TARGETNAME 16 normal full etb
  1593. etb config $_TARGETNAME $_CHIPNAME.etb
  1594. @end example
  1595. @subsection Internal Flash Configuration
  1596. This applies @b{ONLY TO MICROCONTROLLERS} that have flash built in.
  1597. @b{Never ever} in the ``target configuration file'' define any type of
  1598. flash that is external to the chip. (For example a BOOT flash on
  1599. Chip Select 0.) Such flash information goes in a board file - not
  1600. the TARGET (chip) file.
  1601. Examples:
  1602. @itemize @bullet
  1603. @item at91sam7x256 - has 256K flash YES enable it.
  1604. @item str912 - has flash internal YES enable it.
  1605. @item imx27 - uses boot flash on CS0 - it goes in the board file.
  1606. @item pxa270 - again - CS0 flash - it goes in the board file.
  1607. @end itemize
  1608. @anchor{translatingconfigurationfiles}
  1609. @section Translating Configuration Files
  1610. @cindex translation
  1611. If you have a configuration file for another hardware debugger
  1612. or toolset (Abatron, BDI2000, BDI3000, CCS,
  1613. Lauterbach, SEGGER, Macraigor, etc.), translating
  1614. it into OpenOCD syntax is often quite straightforward. The most tricky
  1615. part of creating a configuration script is oftentimes the reset init
  1616. sequence where e.g. PLLs, DRAM and the like is set up.
  1617. One trick that you can use when translating is to write small
  1618. Tcl procedures to translate the syntax into OpenOCD syntax. This
  1619. can avoid manual translation errors and make it easier to
  1620. convert other scripts later on.
  1621. Example of transforming quirky arguments to a simple search and
  1622. replace job:
  1623. @example
  1624. # Lauterbach syntax(?)
  1625. #
  1626. # Data.Set c15:0x042f %long 0x40000015
  1627. #
  1628. # OpenOCD syntax when using procedure below.
  1629. #
  1630. # setc15 0x01 0x00050078
  1631. proc setc15 @{regs value@} @{
  1632. global TARGETNAME
  1633. echo [format "set p15 0x%04x, 0x%08x" $regs $value]
  1634. arm mcr 15 [expr ($regs>>12)&0x7] \
  1635. [expr ($regs>>0)&0xf] [expr ($regs>>4)&0xf] \
  1636. [expr ($regs>>8)&0x7] $value
  1637. @}
  1638. @end example
  1639. @node Server Configuration
  1640. @chapter Server Configuration
  1641. @cindex initialization
  1642. The commands here are commonly found in the openocd.cfg file and are
  1643. used to specify what TCP/IP ports are used, and how GDB should be
  1644. supported.
  1645. @anchor{configurationstage}
  1646. @section Configuration Stage
  1647. @cindex configuration stage
  1648. @cindex config command
  1649. When the OpenOCD server process starts up, it enters a
  1650. @emph{configuration stage} which is the only time that
  1651. certain commands, @emph{configuration commands}, may be issued.
  1652. Normally, configuration commands are only available
  1653. inside startup scripts.
  1654. In this manual, the definition of a configuration command is
  1655. presented as a @emph{Config Command}, not as a @emph{Command}
  1656. which may be issued interactively.
  1657. The runtime @command{help} command also highlights configuration
  1658. commands, and those which may be issued at any time.
  1659. Those configuration commands include declaration of TAPs,
  1660. flash banks,
  1661. the interface used for JTAG communication,
  1662. and other basic setup.
  1663. The server must leave the configuration stage before it
  1664. may access or activate TAPs.
  1665. After it leaves this stage, configuration commands may no
  1666. longer be issued.
  1667. @anchor{enteringtherunstage}
  1668. @section Entering the Run Stage
  1669. The first thing OpenOCD does after leaving the configuration
  1670. stage is to verify that it can talk to the scan chain
  1671. (list of TAPs) which has been configured.
  1672. It will warn if it doesn't find TAPs it expects to find,
  1673. or finds TAPs that aren't supposed to be there.
  1674. You should see no errors at this point.
  1675. If you see errors, resolve them by correcting the
  1676. commands you used to configure the server.
  1677. Common errors include using an initial JTAG speed that's too
  1678. fast, and not providing the right IDCODE values for the TAPs
  1679. on the scan chain.
  1680. Once OpenOCD has entered the run stage, a number of commands
  1681. become available.
  1682. A number of these relate to the debug targets you may have declared.
  1683. For example, the @command{mww} command will not be available until
  1684. a target has been successfully instantiated.
  1685. If you want to use those commands, you may need to force
  1686. entry to the run stage.
  1687. @deffn {Config Command} init
  1688. This command terminates the configuration stage and
  1689. enters the run stage. This helps when you need to have
  1690. the startup scripts manage tasks such as resetting the target,
  1691. programming flash, etc. To reset the CPU upon startup, add "init" and
  1692. "reset" at the end of the config script or at the end of the OpenOCD
  1693. command line using the @option{-c} command line switch.
  1694. If this command does not appear in any startup/configuration file
  1695. OpenOCD executes the command for you after processing all
  1696. configuration files and/or command line options.
  1697. @b{NOTE:} This command normally occurs at or near the end of your
  1698. openocd.cfg file to force OpenOCD to ``initialize'' and make the
  1699. targets ready. For example: If your openocd.cfg file needs to
  1700. read/write memory on your target, @command{init} must occur before
  1701. the memory read/write commands. This includes @command{nand probe}.
  1702. @end deffn
  1703. @deffn {Overridable Procedure} jtag_init
  1704. This is invoked at server startup to verify that it can talk
  1705. to the scan chain (list of TAPs) which has been configured.
  1706. The default implementation first tries @command{jtag arp_init},
  1707. which uses only a lightweight JTAG reset before examining the
  1708. scan chain.
  1709. If that fails, it tries again, using a harder reset
  1710. from the overridable procedure @command{init_reset}.
  1711. Implementations must have verified the JTAG scan chain before
  1712. they return.
  1713. This is done by calling @command{jtag arp_init}
  1714. (or @command{jtag arp_init-reset}).
  1715. @end deffn
  1716. @anchor{tcpipports}
  1717. @section TCP/IP Ports
  1718. @cindex TCP port
  1719. @cindex server
  1720. @cindex port
  1721. @cindex security
  1722. The OpenOCD server accepts remote commands in several syntaxes.
  1723. Each syntax uses a different TCP/IP port, which you may specify
  1724. only during configuration (before those ports are opened).
  1725. For reasons including security, you may wish to prevent remote
  1726. access using one or more of these ports.
  1727. In such cases, just specify the relevant port number as "disabled".
  1728. If you disable all access through TCP/IP, you will need to
  1729. use the command line @option{-pipe} option.
  1730. @anchor{gdb_port}
  1731. @deffn {Command} gdb_port [number]
  1732. @cindex GDB server
  1733. Normally gdb listens to a TCP/IP port, but GDB can also
  1734. communicate via pipes(stdin/out or named pipes). The name
  1735. "gdb_port" stuck because it covers probably more than 90% of
  1736. the normal use cases.
  1737. No arguments reports GDB port. "pipe" means listen to stdin
  1738. output to stdout, an integer is base port number, "disabled"
  1739. disables the gdb server.
  1740. When using "pipe", also use log_output to redirect the log
  1741. output to a file so as not to flood the stdin/out pipes.
  1742. The -p/--pipe option is deprecated and a warning is printed
  1743. as it is equivalent to passing in -c "gdb_port pipe; log_output openocd.log".
  1744. Any other string is interpreted as named pipe to listen to.
  1745. Output pipe is the same name as input pipe, but with 'o' appended,
  1746. e.g. /var/gdb, /var/gdbo.
  1747. The GDB port for the first target will be the base port, the
  1748. second target will listen on gdb_port + 1, and so on.
  1749. When not specified during the configuration stage,
  1750. the port @var{number} defaults to 3333.
  1751. When @var{number} is not a numeric value, incrementing it to compute
  1752. the next port number does not work. In this case, specify the proper
  1753. @var{number} for each target by using the option @code{-gdb-port} of the
  1754. commands @command{target create} or @command{$target_name configure}.
  1755. @xref{gdbportoverride,,option -gdb-port}.
  1756. Note: when using "gdb_port pipe", increasing the default remote timeout in
  1757. gdb (with 'set remotetimeout') is recommended. An insufficient timeout may
  1758. cause initialization to fail with "Unknown remote qXfer reply: OK".
  1759. @end deffn
  1760. @deffn {Command} tcl_port [number]
  1761. Specify or query the port used for a simplified RPC
  1762. connection that can be used by clients to issue TCL commands and get the
  1763. output from the Tcl engine.
  1764. Intended as a machine interface.
  1765. When not specified during the configuration stage,
  1766. the port @var{number} defaults to 6666.
  1767. When specified as "disabled", this service is not activated.
  1768. @end deffn
  1769. @deffn {Command} telnet_port [number]
  1770. Specify or query the
  1771. port on which to listen for incoming telnet connections.
  1772. This port is intended for interaction with one human through TCL commands.
  1773. When not specified during the configuration stage,
  1774. the port @var{number} defaults to 4444.
  1775. When specified as "disabled", this service is not activated.
  1776. @end deffn
  1777. @anchor{gdbconfiguration}
  1778. @section GDB Configuration
  1779. @cindex GDB
  1780. @cindex GDB configuration
  1781. You can reconfigure some GDB behaviors if needed.
  1782. The ones listed here are static and global.
  1783. @xref{targetconfiguration,,Target Configuration}, about configuring individual targets.
  1784. @xref{targetevents,,Target Events}, about configuring target-specific event handling.
  1785. @anchor{gdbbreakpointoverride}
  1786. @deffn {Command} gdb_breakpoint_override [@option{hard}|@option{soft}|@option{disable}]
  1787. Force breakpoint type for gdb @command{break} commands.
  1788. This option supports GDB GUIs which don't
  1789. distinguish hard versus soft breakpoints, if the default OpenOCD and
  1790. GDB behaviour is not sufficient. GDB normally uses hardware
  1791. breakpoints if the memory map has been set up for flash regions.
  1792. @end deffn
  1793. @anchor{gdbflashprogram}
  1794. @deffn {Config Command} gdb_flash_program (@option{enable}|@option{disable})
  1795. Set to @option{enable} to cause OpenOCD to program the flash memory when a
  1796. vFlash packet is received.
  1797. The default behaviour is @option{enable}.
  1798. @end deffn
  1799. @deffn {Config Command} gdb_memory_map (@option{enable}|@option{disable})
  1800. Set to @option{enable} to cause OpenOCD to send the memory configuration to GDB when
  1801. requested. GDB will then know when to set hardware breakpoints, and program flash
  1802. using the GDB load command. @command{gdb_flash_program enable} must also be enabled
  1803. for flash programming to work.
  1804. Default behaviour is @option{enable}.
  1805. @xref{gdbflashprogram,,gdb_flash_program}.
  1806. @end deffn
  1807. @deffn {Config Command} gdb_report_data_abort (@option{enable}|@option{disable})
  1808. Specifies whether data aborts cause an error to be reported
  1809. by GDB memory read packets.
  1810. The default behaviour is @option{disable};
  1811. use @option{enable} see these errors reported.
  1812. @end deffn
  1813. @deffn {Config Command} gdb_report_register_access_error (@option{enable}|@option{disable})
  1814. Specifies whether register accesses requested by GDB register read/write
  1815. packets report errors or not.
  1816. The default behaviour is @option{disable};
  1817. use @option{enable} see these errors reported.
  1818. @end deffn
  1819. @deffn {Config Command} gdb_target_description (@option{enable}|@option{disable})
  1820. Set to @option{enable} to cause OpenOCD to send the target descriptions to gdb via qXfer:features:read packet.
  1821. The default behaviour is @option{enable}.
  1822. @end deffn
  1823. @deffn {Command} gdb_save_tdesc
  1824. Saves the target description file to the local file system.
  1825. The file name is @i{target_name}.xml.
  1826. @end deffn
  1827. @anchor{eventpolling}
  1828. @section Event Polling
  1829. Hardware debuggers are parts of asynchronous systems,
  1830. where significant events can happen at any time.
  1831. The OpenOCD server needs to detect some of these events,
  1832. so it can report them to through TCL command line
  1833. or to GDB.
  1834. Examples of such events include:
  1835. @itemize
  1836. @item One of the targets can stop running ... maybe it triggers
  1837. a code breakpoint or data watchpoint, or halts itself.
  1838. @item Messages may be sent over ``debug message'' channels ... many
  1839. targets support such messages sent over JTAG,
  1840. for receipt by the person debugging or tools.
  1841. @item Loss of power ... some adapters can detect these events.
  1842. @item Resets not issued through JTAG ... such reset sources
  1843. can include button presses or other system hardware, sometimes
  1844. including the target itself (perhaps through a watchdog).
  1845. @item Debug instrumentation sometimes supports event triggering
  1846. such as ``trace buffer full'' (so it can quickly be emptied)
  1847. or other signals (to correlate with code behavior).
  1848. @end itemize
  1849. None of those events are signaled through standard JTAG signals.
  1850. However, most conventions for JTAG connectors include voltage
  1851. level and system reset (SRST) signal detection.
  1852. Some connectors also include instrumentation signals, which
  1853. can imply events when those signals are inputs.
  1854. In general, OpenOCD needs to periodically check for those events,
  1855. either by looking at the status of signals on the JTAG connector
  1856. or by sending synchronous ``tell me your status'' JTAG requests
  1857. to the various active targets.
  1858. There is a command to manage and monitor that polling,
  1859. which is normally done in the background.
  1860. @deffn Command poll [@option{on}|@option{off}]
  1861. Poll the current target for its current state.
  1862. (Also, @pxref{targetcurstate,,target curstate}.)
  1863. If that target is in debug mode, architecture
  1864. specific information about the current state is printed.
  1865. An optional parameter
  1866. allows background polling to be enabled and disabled.
  1867. You could use this from the TCL command shell, or
  1868. from GDB using @command{monitor poll} command.
  1869. Leave background polling enabled while you're using GDB.
  1870. @example
  1871. > poll
  1872. background polling: on
  1873. target state: halted
  1874. target halted in ARM state due to debug-request, \
  1875. current mode: Supervisor
  1876. cpsr: 0x800000d3 pc: 0x11081bfc
  1877. MMU: disabled, D-Cache: disabled, I-Cache: enabled
  1878. >
  1879. @end example
  1880. @end deffn
  1881. @node Debug Adapter Configuration
  1882. @chapter Debug Adapter Configuration
  1883. @cindex config file, interface
  1884. @cindex interface config file
  1885. Correctly installing OpenOCD includes making your operating system give
  1886. OpenOCD access to debug adapters. Once that has been done, Tcl commands
  1887. are used to select which one is used, and to configure how it is used.
  1888. @quotation Note
  1889. Because OpenOCD started out with a focus purely on JTAG, you may find
  1890. places where it wrongly presumes JTAG is the only transport protocol
  1891. in use. Be aware that recent versions of OpenOCD are removing that
  1892. limitation. JTAG remains more functional than most other transports.
  1893. Other transports do not support boundary scan operations, or may be
  1894. specific to a given chip vendor. Some might be usable only for
  1895. programming flash memory, instead of also for debugging.
  1896. @end quotation
  1897. Debug Adapters/Interfaces/Dongles are normally configured
  1898. through commands in an interface configuration
  1899. file which is sourced by your @file{openocd.cfg} file, or
  1900. through a command line @option{-f interface/....cfg} option.
  1901. @example
  1902. source [find interface/olimex-jtag-tiny.cfg]
  1903. @end example
  1904. These commands tell
  1905. OpenOCD what type of JTAG adapter you have, and how to talk to it.
  1906. A few cases are so simple that you only need to say what driver to use:
  1907. @example
  1908. # jlink interface
  1909. adapter driver jlink
  1910. @end example
  1911. Most adapters need a bit more configuration than that.
  1912. @section Adapter Configuration
  1913. The @command{adapter driver} command tells OpenOCD what type of debug adapter you are
  1914. using. Depending on the type of adapter, you may need to use one or
  1915. more additional commands to further identify or configure the adapter.
  1916. @deffn {Config Command} {adapter driver} name
  1917. Use the adapter driver @var{name} to connect to the
  1918. target.
  1919. @end deffn
  1920. @deffn Command {adapter list}
  1921. List the debug adapter drivers that have been built into
  1922. the running copy of OpenOCD.
  1923. @end deffn
  1924. @deffn Command {adapter transports} transport_name+
  1925. Specifies the transports supported by this debug adapter.
  1926. The adapter driver builds-in similar knowledge; use this only
  1927. when external configuration (such as jumpering) changes what
  1928. the hardware can support.
  1929. @end deffn
  1930. @deffn Command {adapter name}
  1931. Returns the name of the debug adapter driver being used.
  1932. @end deffn
  1933. @anchor{adapter_usb_location}
  1934. @deffn Command {adapter usb location} [<bus>-<port>[.<port>]...]
  1935. Displays or specifies the physical USB port of the adapter to use. The path
  1936. roots at @var{bus} and walks down the physical ports, with each
  1937. @var{port} option specifying a deeper level in the bus topology, the last
  1938. @var{port} denoting where the target adapter is actually plugged.
  1939. The USB bus topology can be queried with the command @emph{lsusb -t} or @emph{dmesg}.
  1940. This command is only available if your libusb1 is at least version 1.0.16.
  1941. @end deffn
  1942. @section Interface Drivers
  1943. Each of the interface drivers listed here must be explicitly
  1944. enabled when OpenOCD is configured, in order to be made
  1945. available at run time.
  1946. @deffn {Interface Driver} {amt_jtagaccel}
  1947. Amontec Chameleon in its JTAG Accelerator configuration,
  1948. connected to a PC's EPP mode parallel port.
  1949. This defines some driver-specific commands:
  1950. @deffn {Config Command} {parport_port} number
  1951. Specifies either the address of the I/O port (default: 0x378 for LPT1) or
  1952. the number of the @file{/dev/parport} device.
  1953. @end deffn
  1954. @deffn {Config Command} rtck [@option{enable}|@option{disable}]
  1955. Displays status of RTCK option.
  1956. Optionally sets that option first.
  1957. @end deffn
  1958. @end deffn
  1959. @deffn {Interface Driver} {arm-jtag-ew}
  1960. Olimex ARM-JTAG-EW USB adapter
  1961. This has one driver-specific command:
  1962. @deffn Command {armjtagew_info}
  1963. Logs some status
  1964. @end deffn
  1965. @end deffn
  1966. @deffn {Interface Driver} {at91rm9200}
  1967. Supports bitbanged JTAG from the local system,
  1968. presuming that system is an Atmel AT91rm9200
  1969. and a specific set of GPIOs is used.
  1970. @c command: at91rm9200_device NAME
  1971. @c chooses among list of bit configs ... only one option
  1972. @end deffn
  1973. @deffn {Interface Driver} {cmsis-dap}
  1974. ARM CMSIS-DAP compliant based adapter.
  1975. @deffn {Config Command} {cmsis_dap_vid_pid} [vid pid]+
  1976. The vendor ID and product ID of the CMSIS-DAP device. If not specified
  1977. the driver will attempt to auto detect the CMSIS-DAP device.
  1978. Currently, up to eight [@var{vid}, @var{pid}] pairs may be given, e.g.
  1979. @example
  1980. cmsis_dap_vid_pid 0xc251 0xf001 0x0d28 0x0204
  1981. @end example
  1982. @end deffn
  1983. @deffn {Config Command} {cmsis_dap_serial} [serial]
  1984. Specifies the @var{serial} of the CMSIS-DAP device to use.
  1985. If not specified, serial numbers are not considered.
  1986. @end deffn
  1987. @deffn {Command} {cmsis-dap info}
  1988. Display various device information, like hardware version, firmware version, current bus status.
  1989. @end deffn
  1990. @end deffn
  1991. @deffn {Interface Driver} {dummy}
  1992. A dummy software-only driver for debugging.
  1993. @end deffn
  1994. @deffn {Interface Driver} {ep93xx}
  1995. Cirrus Logic EP93xx based single-board computer bit-banging (in development)
  1996. @end deffn
  1997. @deffn {Interface Driver} {ftdi}
  1998. This driver is for adapters using the MPSSE (Multi-Protocol Synchronous Serial
  1999. Engine) mode built into many FTDI chips, such as the FT2232, FT4232 and FT232H.
  2000. The driver is using libusb-1.0 in asynchronous mode to talk to the FTDI device,
  2001. bypassing intermediate libraries like libftdi or D2XX.
  2002. Support for new FTDI based adapters can be added completely through
  2003. configuration files, without the need to patch and rebuild OpenOCD.
  2004. The driver uses a signal abstraction to enable Tcl configuration files to
  2005. define outputs for one or several FTDI GPIO. These outputs can then be
  2006. controlled using the @command{ftdi_set_signal} command. Special signal names
  2007. are reserved for nTRST, nSRST and LED (for blink) so that they, if defined,
  2008. will be used for their customary purpose. Inputs can be read using the
  2009. @command{ftdi_get_signal} command.
  2010. To support SWD, a signal named SWD_EN must be defined. It is set to 1 when the
  2011. SWD protocol is selected. When set, the adapter should route the SWDIO pin to
  2012. the data input. An SWDIO_OE signal, if defined, will be set to 1 or 0 as
  2013. required by the protocol, to tell the adapter to drive the data output onto
  2014. the SWDIO pin or keep the SWDIO pin Hi-Z, respectively.
  2015. Depending on the type of buffer attached to the FTDI GPIO, the outputs have to
  2016. be controlled differently. In order to support tristateable signals such as
  2017. nSRST, both a data GPIO and an output-enable GPIO can be specified for each
  2018. signal. The following output buffer configurations are supported:
  2019. @itemize @minus
  2020. @item Push-pull with one FTDI output as (non-)inverted data line
  2021. @item Open drain with one FTDI output as (non-)inverted output-enable
  2022. @item Tristate with one FTDI output as (non-)inverted data line and another
  2023. FTDI output as (non-)inverted output-enable
  2024. @item Unbuffered, using the FTDI GPIO as a tristate output directly by
  2025. switching data and direction as necessary
  2026. @end itemize
  2027. These interfaces have several commands, used to configure the driver
  2028. before initializing the JTAG scan chain:
  2029. @deffn {Config Command} {ftdi_vid_pid} [vid pid]+
  2030. The vendor ID and product ID of the adapter. Up to eight
  2031. [@var{vid}, @var{pid}] pairs may be given, e.g.
  2032. @example
  2033. ftdi_vid_pid 0x0403 0xcff8 0x15ba 0x0003
  2034. @end example
  2035. @end deffn
  2036. @deffn {Config Command} {ftdi_device_desc} description
  2037. Provides the USB device description (the @emph{iProduct string})
  2038. of the adapter. If not specified, the device description is ignored
  2039. during device selection.
  2040. @end deffn
  2041. @deffn {Config Command} {ftdi_serial} serial-number
  2042. Specifies the @var{serial-number} of the adapter to use,
  2043. in case the vendor provides unique IDs and more than one adapter
  2044. is connected to the host.
  2045. If not specified, serial numbers are not considered.
  2046. (Note that USB serial numbers can be arbitrary Unicode strings,
  2047. and are not restricted to containing only decimal digits.)
  2048. @end deffn
  2049. @deffn {Config Command} {ftdi_location} <bus>-<port>[.<port>]...
  2050. @emph{DEPRECATED -- avoid using this.
  2051. Use the command @ref{adapter_usb_location,,adapter usb location} instead.}
  2052. Specifies the physical USB port of the adapter to use. The path
  2053. roots at @var{bus} and walks down the physical ports, with each
  2054. @var{port} option specifying a deeper level in the bus topology, the last
  2055. @var{port} denoting where the target adapter is actually plugged.
  2056. The USB bus topology can be queried with the command @emph{lsusb -t}.
  2057. This command is only available if your libusb1 is at least version 1.0.16.
  2058. @end deffn
  2059. @deffn {Config Command} {ftdi_channel} channel
  2060. Selects the channel of the FTDI device to use for MPSSE operations. Most
  2061. adapters use the default, channel 0, but there are exceptions.
  2062. @end deffn
  2063. @deffn {Config Command} {ftdi_layout_init} data direction
  2064. Specifies the initial values of the FTDI GPIO data and direction registers.
  2065. Each value is a 16-bit number corresponding to the concatenation of the high
  2066. and low FTDI GPIO registers. The values should be selected based on the
  2067. schematics of the adapter, such that all signals are set to safe levels with
  2068. minimal impact on the target system. Avoid floating inputs, conflicting outputs
  2069. and initially asserted reset signals.
  2070. @end deffn
  2071. @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]
  2072. Creates a signal with the specified @var{name}, controlled by one or more FTDI
  2073. GPIO pins via a range of possible buffer connections. The masks are FTDI GPIO
  2074. register bitmasks to tell the driver the connection and type of the output
  2075. buffer driving the respective signal. @var{data_mask} is the bitmask for the
  2076. pin(s) connected to the data input of the output buffer. @option{-ndata} is
  2077. used with inverting data inputs and @option{-data} with non-inverting inputs.
  2078. The @option{-oe} (or @option{-noe}) option tells where the output-enable (or
  2079. not-output-enable) input to the output buffer is connected. The options
  2080. @option{-input} and @option{-ninput} specify the bitmask for pins to be read
  2081. with the method @command{ftdi_get_signal}.
  2082. Both @var{data_mask} and @var{oe_mask} need not be specified. For example, a
  2083. simple open-collector transistor driver would be specified with @option{-oe}
  2084. only. In that case the signal can only be set to drive low or to Hi-Z and the
  2085. driver will complain if the signal is set to drive high. Which means that if
  2086. it's a reset signal, @command{reset_config} must be specified as
  2087. @option{srst_open_drain}, not @option{srst_push_pull}.
  2088. A special case is provided when @option{-data} and @option{-oe} is set to the
  2089. same bitmask. Then the FTDI pin is considered being connected straight to the
  2090. target without any buffer. The FTDI pin is then switched between output and
  2091. input as necessary to provide the full set of low, high and Hi-Z
  2092. characteristics. In all other cases, the pins specified in a signal definition
  2093. are always driven by the FTDI.
  2094. If @option{-alias} or @option{-nalias} is used, the signal is created
  2095. identical (or with data inverted) to an already specified signal
  2096. @var{name}.
  2097. @end deffn
  2098. @deffn {Command} {ftdi_set_signal} name @option{0}|@option{1}|@option{z}
  2099. Set a previously defined signal to the specified level.
  2100. @itemize @minus
  2101. @item @option{0}, drive low
  2102. @item @option{1}, drive high
  2103. @item @option{z}, set to high-impedance
  2104. @end itemize
  2105. @end deffn
  2106. @deffn {Command} {ftdi_get_signal} name
  2107. Get the value of a previously defined signal.
  2108. @end deffn
  2109. @deffn {Command} {ftdi_tdo_sample_edge} @option{rising}|@option{falling}
  2110. Configure TCK edge at which the adapter samples the value of the TDO signal
  2111. Due to signal propagation delays, sampling TDO on rising TCK can become quite
  2112. peculiar at high JTAG clock speeds. However, FTDI chips offer a possibility to sample
  2113. TDO on falling edge of TCK. With some board/adapter configurations, this may increase
  2114. stability at higher JTAG clocks.
  2115. @itemize @minus
  2116. @item @option{rising}, sample TDO on rising edge of TCK - this is the default
  2117. @item @option{falling}, sample TDO on falling edge of TCK
  2118. @end itemize
  2119. @end deffn
  2120. For example adapter definitions, see the configuration files shipped in the
  2121. @file{interface/ftdi} directory.
  2122. @end deffn
  2123. @deffn {Interface Driver} {ft232r}
  2124. This driver is implementing synchronous bitbang mode of an FTDI FT232R,
  2125. FT230X, FT231X and similar USB UART bridge ICs by reusing RS232 signals as GPIO.
  2126. It currently doesn't support using CBUS pins as GPIO.
  2127. List of connections (default physical pin numbers for FT232R in 28-pin SSOP package):
  2128. @itemize @minus
  2129. @item RXD(5) - TDI
  2130. @item TXD(1) - TCK
  2131. @item RTS(3) - TDO
  2132. @item CTS(11) - TMS
  2133. @item DTR(2) - TRST
  2134. @item DCD(10) - SRST
  2135. @end itemize
  2136. User can change default pinout by supplying configuration
  2137. commands with GPIO numbers or RS232 signal names.
  2138. GPIO numbers correspond to bit numbers in FTDI GPIO register.
  2139. They differ from physical pin numbers.
  2140. For details see actual FTDI chip datasheets.
  2141. Every JTAG line must be configured to unique GPIO number
  2142. different than any other JTAG line, even those lines
  2143. that are sometimes not used like TRST or SRST.
  2144. FT232R
  2145. @itemize @minus
  2146. @item bit 7 - RI
  2147. @item bit 6 - DCD
  2148. @item bit 5 - DSR
  2149. @item bit 4 - DTR
  2150. @item bit 3 - CTS
  2151. @item bit 2 - RTS
  2152. @item bit 1 - RXD
  2153. @item bit 0 - TXD
  2154. @end itemize
  2155. These interfaces have several commands, used to configure the driver
  2156. before initializing the JTAG scan chain:
  2157. @deffn {Config Command} {ft232r_vid_pid} @var{vid} @var{pid}
  2158. The vendor ID and product ID of the adapter. If not specified, default
  2159. 0x0403:0x6001 is used.
  2160. @end deffn
  2161. @deffn {Config Command} {ft232r_serial_desc} @var{serial}
  2162. Specifies the @var{serial} of the adapter to use, in case the
  2163. vendor provides unique IDs and more than one adapter is connected to
  2164. the host. If not specified, serial numbers are not considered.
  2165. @end deffn
  2166. @deffn {Config Command} {ft232r_jtag_nums} @var{tck} @var{tms} @var{tdi} @var{tdo}
  2167. Set four JTAG GPIO numbers at once.
  2168. If not specified, default 0 3 1 2 or TXD CTS RXD RTS is used.
  2169. @end deffn
  2170. @deffn {Config Command} {ft232r_tck_num} @var{tck}
  2171. Set TCK GPIO number. If not specified, default 0 or TXD is used.
  2172. @end deffn
  2173. @deffn {Config Command} {ft232r_tms_num} @var{tms}
  2174. Set TMS GPIO number. If not specified, default 3 or CTS is used.
  2175. @end deffn
  2176. @deffn {Config Command} {ft232r_tdi_num} @var{tdi}
  2177. Set TDI GPIO number. If not specified, default 1 or RXD is used.
  2178. @end deffn
  2179. @deffn {Config Command} {ft232r_tdo_num} @var{tdo}
  2180. Set TDO GPIO number. If not specified, default 2 or RTS is used.
  2181. @end deffn
  2182. @deffn {Config Command} {ft232r_trst_num} @var{trst}
  2183. Set TRST GPIO number. If not specified, default 4 or DTR is used.
  2184. @end deffn
  2185. @deffn {Config Command} {ft232r_srst_num} @var{srst}
  2186. Set SRST GPIO number. If not specified, default 6 or DCD is used.
  2187. @end deffn
  2188. @deffn {Config Command} {ft232r_restore_serial} @var{word}
  2189. Restore serial port after JTAG. This USB bitmode control word
  2190. (16-bit) will be sent before quit. Lower byte should
  2191. set GPIO direction register to a "sane" state:
  2192. 0x15 for TXD RTS DTR as outputs (1), others as inputs (0). Higher
  2193. byte is usually 0 to disable bitbang mode.
  2194. When kernel driver reattaches, serial port should continue to work.
  2195. Value 0xFFFF disables sending control word and serial port,
  2196. then kernel driver will not reattach.
  2197. If not specified, default 0xFFFF is used.
  2198. @end deffn
  2199. @end deffn
  2200. @deffn {Interface Driver} {remote_bitbang}
  2201. Drive JTAG from a remote process. This sets up a UNIX or TCP socket connection
  2202. with a remote process and sends ASCII encoded bitbang requests to that process
  2203. instead of directly driving JTAG.
  2204. The remote_bitbang driver is useful for debugging software running on
  2205. processors which are being simulated.
  2206. @deffn {Config Command} {remote_bitbang_port} number
  2207. Specifies the TCP port of the remote process to connect to or 0 to use UNIX
  2208. sockets instead of TCP.
  2209. @end deffn
  2210. @deffn {Config Command} {remote_bitbang_host} hostname
  2211. Specifies the hostname of the remote process to connect to using TCP, or the
  2212. name of the UNIX socket to use if remote_bitbang_port is 0.
  2213. @end deffn
  2214. For example, to connect remotely via TCP to the host foobar you might have
  2215. something like:
  2216. @example
  2217. adapter driver remote_bitbang
  2218. remote_bitbang_port 3335
  2219. remote_bitbang_host foobar
  2220. @end example
  2221. To connect to another process running locally via UNIX sockets with socket
  2222. named mysocket:
  2223. @example
  2224. adapter driver remote_bitbang
  2225. remote_bitbang_port 0
  2226. remote_bitbang_host mysocket
  2227. @end example
  2228. @end deffn
  2229. @deffn {Interface Driver} {usb_blaster}
  2230. USB JTAG/USB-Blaster compatibles over one of the userspace libraries
  2231. for FTDI chips. These interfaces have several commands, used to
  2232. configure the driver before initializing the JTAG scan chain:
  2233. @deffn {Config Command} {usb_blaster_device_desc} description
  2234. Provides the USB device description (the @emph{iProduct string})
  2235. of the FTDI FT245 device. If not
  2236. specified, the FTDI default value is used. This setting is only valid
  2237. if compiled with FTD2XX support.
  2238. @end deffn
  2239. @deffn {Config Command} {usb_blaster_vid_pid} vid pid
  2240. The vendor ID and product ID of the FTDI FT245 device. If not specified,
  2241. default values are used.
  2242. Currently, only one @var{vid}, @var{pid} pair may be given, e.g. for
  2243. Altera USB-Blaster (default):
  2244. @example
  2245. usb_blaster_vid_pid 0x09FB 0x6001
  2246. @end example
  2247. The following VID/PID is for Kolja Waschk's USB JTAG:
  2248. @example
  2249. usb_blaster_vid_pid 0x16C0 0x06AD
  2250. @end example
  2251. @end deffn
  2252. @deffn {Command} {usb_blaster_pin} (@option{pin6}|@option{pin8}) (@option{0}|@option{1}|@option{s}|@option{t})
  2253. Sets the state or function of the unused GPIO pins on USB-Blasters
  2254. (pins 6 and 8 on the female JTAG header). These pins can be used as
  2255. SRST and/or TRST provided the appropriate connections are made on the
  2256. target board.
  2257. For example, to use pin 6 as SRST:
  2258. @example
  2259. usb_blaster_pin pin6 s
  2260. reset_config srst_only
  2261. @end example
  2262. @end deffn
  2263. @deffn {Command} {usb_blaster_lowlevel_driver} (@option{ftdi}|@option{ublast2})
  2264. Chooses the low level access method for the adapter. If not specified,
  2265. @option{ftdi} is selected unless it wasn't enabled during the
  2266. configure stage. USB-Blaster II needs @option{ublast2}.
  2267. @end deffn
  2268. @deffn {Command} {usb_blaster_firmware} @var{path}
  2269. This command specifies @var{path} to access USB-Blaster II firmware
  2270. image. To be used with USB-Blaster II only.
  2271. @end deffn
  2272. @end deffn
  2273. @deffn {Interface Driver} {gw16012}
  2274. Gateworks GW16012 JTAG programmer.
  2275. This has one driver-specific command:
  2276. @deffn {Config Command} {parport_port} [port_number]
  2277. Display either the address of the I/O port
  2278. (default: 0x378 for LPT1) or the number of the @file{/dev/parport} device.
  2279. If a parameter is provided, first switch to use that port.
  2280. This is a write-once setting.
  2281. @end deffn
  2282. @end deffn
  2283. @deffn {Interface Driver} {jlink}
  2284. SEGGER J-Link family of USB adapters. It currently supports JTAG and SWD
  2285. transports.
  2286. @quotation Compatibility Note
  2287. SEGGER released many firmware versions for the many hardware versions they
  2288. produced. OpenOCD was extensively tested and intended to run on all of them,
  2289. but some combinations were reported as incompatible. As a general
  2290. recommendation, it is advisable to use the latest firmware version
  2291. available for each hardware version. However the current V8 is a moving
  2292. target, and SEGGER firmware versions released after the OpenOCD was
  2293. released may not be compatible. In such cases it is recommended to
  2294. revert to the last known functional version. For 0.5.0, this is from
  2295. "Feb 8 2012 14:30:39", packed with 4.42c. For 0.6.0, the last known
  2296. version is from "May 3 2012 18:36:22", packed with 4.46f.
  2297. @end quotation
  2298. @deffn {Command} {jlink hwstatus}
  2299. Display various hardware related information, for example target voltage and pin
  2300. states.
  2301. @end deffn
  2302. @deffn {Command} {jlink freemem}
  2303. Display free device internal memory.
  2304. @end deffn
  2305. @deffn {Command} {jlink jtag} [@option{2}|@option{3}]
  2306. Set the JTAG command version to be used. Without argument, show the actual JTAG
  2307. command version.
  2308. @end deffn
  2309. @deffn {Command} {jlink config}
  2310. Display the device configuration.
  2311. @end deffn
  2312. @deffn {Command} {jlink config targetpower} [@option{on}|@option{off}]
  2313. Set the target power state on JTAG-pin 19. Without argument, show the target
  2314. power state.
  2315. @end deffn
  2316. @deffn {Command} {jlink config mac} [@option{ff:ff:ff:ff:ff:ff}]
  2317. Set the MAC address of the device. Without argument, show the MAC address.
  2318. @end deffn
  2319. @deffn {Command} {jlink config ip} [@option{A.B.C.D}(@option{/E}|@option{F.G.H.I})]
  2320. Set the IP configuration of the device, where A.B.C.D is the IP address, E the
  2321. bit of the subnet mask and F.G.H.I the subnet mask. Without arguments, show the
  2322. IP configuration.
  2323. @end deffn
  2324. @deffn {Command} {jlink config usb} [@option{0} to @option{3}]
  2325. Set the USB address of the device. This will also change the USB Product ID
  2326. (PID) of the device. Without argument, show the USB address.
  2327. @end deffn
  2328. @deffn {Command} {jlink config reset}
  2329. Reset the current configuration.
  2330. @end deffn
  2331. @deffn {Command} {jlink config write}
  2332. Write the current configuration to the internal persistent storage.
  2333. @end deffn
  2334. @deffn {Command} {jlink emucom write <channel> <data>}
  2335. Write data to an EMUCOM channel. The data needs to be encoded as hexadecimal
  2336. pairs.
  2337. The following example shows how to write the three bytes 0xaa, 0x0b and 0x23 to
  2338. the EMUCOM channel 0x10:
  2339. @example
  2340. > jlink emucom write 0x10 aa0b23
  2341. @end example
  2342. @end deffn
  2343. @deffn {Command} {jlink emucom read <channel> <length>}
  2344. Read data from an EMUCOM channel. The read data is encoded as hexadecimal
  2345. pairs.
  2346. The following example shows how to read 4 bytes from the EMUCOM channel 0x0:
  2347. @example
  2348. > jlink emucom read 0x0 4
  2349. 77a90000
  2350. @end example
  2351. @end deffn
  2352. @deffn {Config} {jlink usb} <@option{0} to @option{3}>
  2353. Set the USB address of the interface, in case more than one adapter is connected
  2354. to the host. If not specified, USB addresses are not considered. Device
  2355. selection via USB address is deprecated and the serial number should be used
  2356. instead.
  2357. As a configuration command, it can be used only before 'init'.
  2358. @end deffn
  2359. @deffn {Config} {jlink serial} <serial number>
  2360. Set the serial number of the interface, in case more than one adapter is
  2361. connected to the host. If not specified, serial numbers are not considered.
  2362. As a configuration command, it can be used only before 'init'.
  2363. @end deffn
  2364. @end deffn
  2365. @deffn {Interface Driver} {kitprog}
  2366. This driver is for Cypress Semiconductor's KitProg adapters. The KitProg is an
  2367. SWD-only adapter that is designed to be used with Cypress's PSoC and PRoC device
  2368. families, but it is possible to use it with some other devices. If you are using
  2369. this adapter with a PSoC or a PRoC, you may need to add
  2370. @command{kitprog_init_acquire_psoc} or @command{kitprog acquire_psoc} to your
  2371. configuration script.
  2372. Note that this driver is for the proprietary KitProg protocol, not the CMSIS-DAP
  2373. mode introduced in firmware 2.14. If the KitProg is in CMSIS-DAP mode, it cannot
  2374. be used with this driver, and must either be used with the cmsis-dap driver or
  2375. switched back to KitProg mode. See the Cypress KitProg User Guide for
  2376. instructions on how to switch KitProg modes.
  2377. Known limitations:
  2378. @itemize @bullet
  2379. @item The frequency of SWCLK cannot be configured, and varies between 1.6 MHz
  2380. and 2.7 MHz.
  2381. @item For firmware versions below 2.14, "JTAG to SWD" sequences are replaced by
  2382. "SWD line reset" in the driver. This is for two reasons. First, the KitProg does
  2383. not support sending arbitrary SWD sequences, and only firmware 2.14 and later
  2384. implement both "JTAG to SWD" and "SWD line reset" in firmware. Earlier firmware
  2385. versions only implement "SWD line reset". Second, due to a firmware quirk, an
  2386. SWD sequence must be sent after every target reset in order to re-establish
  2387. communications with the target.
  2388. @item Due in part to the limitation above, KitProg devices with firmware below
  2389. version 2.14 will need to use @command{kitprog_init_acquire_psoc} in order to
  2390. communicate with PSoC 5LP devices. This is because, assuming debug is not
  2391. disabled on the PSoC, the PSoC 5LP needs its JTAG interface switched to SWD
  2392. mode before communication can begin, but prior to firmware 2.14, "JTAG to SWD"
  2393. could only be sent with an acquisition sequence.
  2394. @end itemize
  2395. @deffn {Config Command} {kitprog_init_acquire_psoc}
  2396. Indicate that a PSoC acquisition sequence needs to be run during adapter init.
  2397. Please be aware that the acquisition sequence hard-resets the target.
  2398. @end deffn
  2399. @deffn {Config Command} {kitprog_serial} serial
  2400. Select a KitProg device by its @var{serial}. If left unspecified, the first
  2401. device detected by OpenOCD will be used.
  2402. @end deffn
  2403. @deffn {Command} {kitprog acquire_psoc}
  2404. Run a PSoC acquisition sequence immediately. Typically, this should not be used
  2405. outside of the target-specific configuration scripts since it hard-resets the
  2406. target as a side-effect.
  2407. This is necessary for "reset halt" on some PSoC 4 series devices.
  2408. @end deffn
  2409. @deffn {Command} {kitprog info}
  2410. Display various adapter information, such as the hardware version, firmware
  2411. version, and target voltage.
  2412. @end deffn
  2413. @end deffn
  2414. @deffn {Interface Driver} {parport}
  2415. Supports PC parallel port bit-banging cables:
  2416. Wigglers, PLD download cable, and more.
  2417. These interfaces have several commands, used to configure the driver
  2418. before initializing the JTAG scan chain:
  2419. @deffn {Config Command} {parport_cable} name
  2420. Set the layout of the parallel port cable used to connect to the target.
  2421. This is a write-once setting.
  2422. Currently valid cable @var{name} values include:
  2423. @itemize @minus
  2424. @item @b{altium} Altium Universal JTAG cable.
  2425. @item @b{arm-jtag} Same as original wiggler except SRST and
  2426. TRST connections reversed and TRST is also inverted.
  2427. @item @b{chameleon} The Amontec Chameleon's CPLD when operated
  2428. in configuration mode. This is only used to
  2429. program the Chameleon itself, not a connected target.
  2430. @item @b{dlc5} The Xilinx Parallel cable III.
  2431. @item @b{flashlink} The ST Parallel cable.
  2432. @item @b{lattice} Lattice ispDOWNLOAD Cable
  2433. @item @b{old_amt_wiggler} The Wiggler configuration that comes with
  2434. some versions of
  2435. Amontec's Chameleon Programmer. The new version available from
  2436. the website uses the original Wiggler layout ('@var{wiggler}')
  2437. @item @b{triton} The parallel port adapter found on the
  2438. ``Karo Triton 1 Development Board''.
  2439. This is also the layout used by the HollyGates design
  2440. (see @uref{http://www.lartmaker.nl/projects/jtag/}).
  2441. @item @b{wiggler} The original Wiggler layout, also supported by
  2442. several clones, such as the Olimex ARM-JTAG
  2443. @item @b{wiggler2} Same as original wiggler except an led is fitted on D5.
  2444. @item @b{wiggler_ntrst_inverted} Same as original wiggler except TRST is inverted.
  2445. @end itemize
  2446. @end deffn
  2447. @deffn {Config Command} {parport_port} [port_number]
  2448. Display either the address of the I/O port
  2449. (default: 0x378 for LPT1) or the number of the @file{/dev/parport} device.
  2450. If a parameter is provided, first switch to use that port.
  2451. This is a write-once setting.
  2452. When using PPDEV to access the parallel port, use the number of the parallel port:
  2453. @option{parport_port 0} (the default). If @option{parport_port 0x378} is specified
  2454. you may encounter a problem.
  2455. @end deffn
  2456. @deffn Command {parport_toggling_time} [nanoseconds]
  2457. Displays how many nanoseconds the hardware needs to toggle TCK;
  2458. the parport driver uses this value to obey the
  2459. @command{adapter speed} configuration.
  2460. When the optional @var{nanoseconds} parameter is given,
  2461. that setting is changed before displaying the current value.
  2462. The default setting should work reasonably well on commodity PC hardware.
  2463. However, you may want to calibrate for your specific hardware.
  2464. @quotation Tip
  2465. To measure the toggling time with a logic analyzer or a digital storage
  2466. oscilloscope, follow the procedure below:
  2467. @example
  2468. > parport_toggling_time 1000
  2469. > adapter speed 500
  2470. @end example
  2471. This sets the maximum JTAG clock speed of the hardware, but
  2472. the actual speed probably deviates from the requested 500 kHz.
  2473. Now, measure the time between the two closest spaced TCK transitions.
  2474. You can use @command{runtest 1000} or something similar to generate a
  2475. large set of samples.
  2476. Update the setting to match your measurement:
  2477. @example
  2478. > parport_toggling_time <measured nanoseconds>
  2479. @end example
  2480. Now the clock speed will be a better match for @command{adapter speed}
  2481. command given in OpenOCD scripts and event handlers.
  2482. You can do something similar with many digital multimeters, but note
  2483. that you'll probably need to run the clock continuously for several
  2484. seconds before it decides what clock rate to show. Adjust the
  2485. toggling time up or down until the measured clock rate is a good
  2486. match with the rate you specified in the @command{adapter speed} command;
  2487. be conservative.
  2488. @end quotation
  2489. @end deffn
  2490. @deffn {Config Command} {parport_write_on_exit} (@option{on}|@option{off})
  2491. This will configure the parallel driver to write a known
  2492. cable-specific value to the parallel interface on exiting OpenOCD.
  2493. @end deffn
  2494. For example, the interface configuration file for a
  2495. classic ``Wiggler'' cable on LPT2 might look something like this:
  2496. @example
  2497. adapter driver parport
  2498. parport_port 0x278
  2499. parport_cable wiggler
  2500. @end example
  2501. @end deffn
  2502. @deffn {Interface Driver} {presto}
  2503. ASIX PRESTO USB JTAG programmer.
  2504. @deffn {Config Command} {presto_serial} serial_string
  2505. Configures the USB serial number of the Presto device to use.
  2506. @end deffn
  2507. @end deffn
  2508. @deffn {Interface Driver} {rlink}
  2509. Raisonance RLink USB adapter
  2510. @end deffn
  2511. @deffn {Interface Driver} {usbprog}
  2512. usbprog is a freely programmable USB adapter.
  2513. @end deffn
  2514. @deffn {Interface Driver} {vsllink}
  2515. vsllink is part of Versaloon which is a versatile USB programmer.
  2516. @quotation Note
  2517. This defines quite a few driver-specific commands,
  2518. which are not currently documented here.
  2519. @end quotation
  2520. @end deffn
  2521. @anchor{hla_interface}
  2522. @deffn {Interface Driver} {hla}
  2523. This is a driver that supports multiple High Level Adapters.
  2524. This type of adapter does not expose some of the lower level api's
  2525. that OpenOCD would normally use to access the target.
  2526. Currently supported adapters include the STMicroelectronics ST-LINK and TI ICDI.
  2527. ST-LINK firmware version >= V2.J21.S4 recommended due to issues with earlier
  2528. versions of firmware where serial number is reset after first use. Suggest
  2529. using ST firmware update utility to upgrade ST-LINK firmware even if current
  2530. version reported is V2.J21.S4.
  2531. @deffn {Config Command} {hla_device_desc} description
  2532. Currently Not Supported.
  2533. @end deffn
  2534. @deffn {Config Command} {hla_serial} serial
  2535. Specifies the serial number of the adapter.
  2536. @end deffn
  2537. @deffn {Config Command} {hla_layout} (@option{stlink}|@option{icdi})
  2538. Specifies the adapter layout to use.
  2539. @end deffn
  2540. @deffn {Config Command} {hla_vid_pid} [vid pid]+
  2541. Pairs of vendor IDs and product IDs of the device.
  2542. @end deffn
  2543. @deffn {Command} {hla_command} command
  2544. Execute a custom adapter-specific command. The @var{command} string is
  2545. passed as is to the underlying adapter layout handler.
  2546. @end deffn
  2547. @end deffn
  2548. @anchor{st_link_dap_interface}
  2549. @deffn {Interface Driver} {st-link}
  2550. This is a driver that supports STMicroelectronics adapters ST-LINK/V2
  2551. (from firmware V2J24) and STLINK-V3, thanks to a new API that provides
  2552. directly access the arm ADIv5 DAP.
  2553. The new API provide access to multiple AP on the same DAP, but the
  2554. maximum number of the AP port is limited by the specific firmware version
  2555. (e.g. firmware V2J29 has 3 as maximum AP number, while V2J32 has 8).
  2556. An error is returned for any AP number above the maximum allowed value.
  2557. @emph{Note:} Either these same adapters and their older versions are
  2558. also supported by @ref{hla_interface, the hla interface driver}.
  2559. @deffn {Config Command} {st-link serial} serial
  2560. Specifies the serial number of the adapter.
  2561. @end deffn
  2562. @deffn {Config Command} {st-link vid_pid} [vid pid]+
  2563. Pairs of vendor IDs and product IDs of the device.
  2564. @end deffn
  2565. @end deffn
  2566. @deffn {Interface Driver} {opendous}
  2567. opendous-jtag is a freely programmable USB adapter.
  2568. @end deffn
  2569. @deffn {Interface Driver} {ulink}
  2570. This is the Keil ULINK v1 JTAG debugger.
  2571. @end deffn
  2572. @deffn {Interface Driver} {xlnx_pcie_xvc}
  2573. This driver supports the Xilinx Virtual Cable (XVC) over PCI Express.
  2574. It is commonly found in Xilinx based PCI Express designs. It allows debugging
  2575. fabric based JTAG devices such as Cortex-M1/M3 microcontrollers. Access to this is
  2576. exposed via extended capability registers in the PCI Express configuration space.
  2577. For more information see Xilinx PG245 (Section on From_PCIE_to_JTAG mode).
  2578. @deffn {Config Command} {xlnx_pcie_xvc_config} device
  2579. Specifies the PCI Express device via parameter @var{device} to use.
  2580. The correct value for @var{device} can be obtained by looking at the output
  2581. of lscpi -D (first column) for the corresponding device.
  2582. The string will be of the format "DDDD:BB:SS.F" such as "0000:65:00.1".
  2583. @end deffn
  2584. @end deffn
  2585. @deffn {Interface Driver} {ZY1000}
  2586. This is the Zylin ZY1000 JTAG debugger.
  2587. @end deffn
  2588. @quotation Note
  2589. This defines some driver-specific commands,
  2590. which are not currently documented here.
  2591. @end quotation
  2592. @deffn Command power [@option{on}|@option{off}]
  2593. Turn power switch to target on/off.
  2594. No arguments: print status.
  2595. @end deffn
  2596. @deffn {Interface Driver} {bcm2835gpio}
  2597. This SoC is present in Raspberry Pi which is a cheap single-board computer
  2598. exposing some GPIOs on its expansion header.
  2599. The driver accesses memory-mapped GPIO peripheral registers directly
  2600. for maximum performance, but the only possible race condition is for
  2601. the pins' modes/muxing (which is highly unlikely), so it should be
  2602. able to coexist nicely with both sysfs bitbanging and various
  2603. peripherals' kernel drivers. The driver restores the previous
  2604. configuration on exit.
  2605. See @file{interface/raspberrypi-native.cfg} for a sample config and
  2606. pinout.
  2607. @end deffn
  2608. @deffn {Interface Driver} {imx_gpio}
  2609. i.MX SoC is present in many community boards. Wandboard is an example
  2610. of the one which is most popular.
  2611. This driver is mostly the same as bcm2835gpio.
  2612. See @file{interface/imx-native.cfg} for a sample config and
  2613. pinout.
  2614. @end deffn
  2615. @deffn {Interface Driver} {openjtag}
  2616. OpenJTAG compatible USB adapter.
  2617. This defines some driver-specific commands:
  2618. @deffn {Config Command} {openjtag_variant} variant
  2619. Specifies the variant of the OpenJTAG adapter (see @uref{http://www.openjtag.org/}).
  2620. Currently valid @var{variant} values include:
  2621. @itemize @minus
  2622. @item @b{standard} Standard variant (default).
  2623. @item @b{cy7c65215} Cypress CY7C65215 Dual Channel USB-Serial Bridge Controller
  2624. (see @uref{http://www.cypress.com/?rID=82870}).
  2625. @end itemize
  2626. @end deffn
  2627. @deffn {Config Command} {openjtag_device_desc} string
  2628. The USB device description string of the adapter.
  2629. This value is only used with the standard variant.
  2630. @end deffn
  2631. @end deffn
  2632. @section Transport Configuration
  2633. @cindex Transport
  2634. As noted earlier, depending on the version of OpenOCD you use,
  2635. and the debug adapter you are using,
  2636. several transports may be available to
  2637. communicate with debug targets (or perhaps to program flash memory).
  2638. @deffn Command {transport list}
  2639. displays the names of the transports supported by this
  2640. version of OpenOCD.
  2641. @end deffn
  2642. @deffn Command {transport select} @option{transport_name}
  2643. Select which of the supported transports to use in this OpenOCD session.
  2644. When invoked with @option{transport_name}, attempts to select the named
  2645. transport. The transport must be supported by the debug adapter
  2646. hardware and by the version of OpenOCD you are using (including the
  2647. adapter's driver).
  2648. If no transport has been selected and no @option{transport_name} is
  2649. provided, @command{transport select} auto-selects the first transport
  2650. supported by the debug adapter.
  2651. @command{transport select} always returns the name of the session's selected
  2652. transport, if any.
  2653. @end deffn
  2654. @subsection JTAG Transport
  2655. @cindex JTAG
  2656. JTAG is the original transport supported by OpenOCD, and most
  2657. of the OpenOCD commands support it.
  2658. JTAG transports expose a chain of one or more Test Access Points (TAPs),
  2659. each of which must be explicitly declared.
  2660. JTAG supports both debugging and boundary scan testing.
  2661. Flash programming support is built on top of debug support.
  2662. JTAG transport is selected with the command @command{transport select
  2663. jtag}. Unless your adapter uses either @ref{hla_interface,the hla interface
  2664. driver} (in which case the command is @command{transport select hla_jtag})
  2665. or @ref{st_link_dap_interface,the st-link interface driver} (in which case
  2666. the command is @command{transport select dapdirect_jtag}).
  2667. @subsection SWD Transport
  2668. @cindex SWD
  2669. @cindex Serial Wire Debug
  2670. SWD (Serial Wire Debug) is an ARM-specific transport which exposes one
  2671. Debug Access Point (DAP, which must be explicitly declared.
  2672. (SWD uses fewer signal wires than JTAG.)
  2673. SWD is debug-oriented, and does not support boundary scan testing.
  2674. Flash programming support is built on top of debug support.
  2675. (Some processors support both JTAG and SWD.)
  2676. SWD transport is selected with the command @command{transport select
  2677. swd}. Unless your adapter uses either @ref{hla_interface,the hla interface
  2678. driver} (in which case the command is @command{transport select hla_swd})
  2679. or @ref{st_link_dap_interface,the st-link interface driver} (in which case
  2680. the command is @command{transport select dapdirect_swd}).
  2681. @deffn Command {swd newdap} ...
  2682. Declares a single DAP which uses SWD transport.
  2683. Parameters are currently the same as "jtag newtap" but this is
  2684. expected to change.
  2685. @end deffn
  2686. @deffn Command {swd wcr trn prescale}
  2687. Updates TRN (turnaround delay) and prescaling.fields of the
  2688. Wire Control Register (WCR).
  2689. No parameters: displays current settings.
  2690. @end deffn
  2691. @subsection SPI Transport
  2692. @cindex SPI
  2693. @cindex Serial Peripheral Interface
  2694. The Serial Peripheral Interface (SPI) is a general purpose transport
  2695. which uses four wire signaling. Some processors use it as part of a
  2696. solution for flash programming.
  2697. @anchor{jtagspeed}
  2698. @section JTAG Speed
  2699. JTAG clock setup is part of system setup.
  2700. It @emph{does not belong with interface setup} since any interface
  2701. only knows a few of the constraints for the JTAG clock speed.
  2702. Sometimes the JTAG speed is
  2703. changed during the target initialization process: (1) slow at
  2704. reset, (2) program the CPU clocks, (3) run fast.
  2705. Both the "slow" and "fast" clock rates are functions of the
  2706. oscillators used, the chip, the board design, and sometimes
  2707. power management software that may be active.
  2708. The speed used during reset, and the scan chain verification which
  2709. follows reset, can be adjusted using a @code{reset-start}
  2710. target event handler.
  2711. It can then be reconfigured to a faster speed by a
  2712. @code{reset-init} target event handler after it reprograms those
  2713. CPU clocks, or manually (if something else, such as a boot loader,
  2714. sets up those clocks).
  2715. @xref{targetevents,,Target Events}.
  2716. When the initial low JTAG speed is a chip characteristic, perhaps
  2717. because of a required oscillator speed, provide such a handler
  2718. in the target config file.
  2719. When that speed is a function of a board-specific characteristic
  2720. such as which speed oscillator is used, it belongs in the board
  2721. config file instead.
  2722. In both cases it's safest to also set the initial JTAG clock rate
  2723. to that same slow speed, so that OpenOCD never starts up using a
  2724. clock speed that's faster than the scan chain can support.
  2725. @example
  2726. jtag_rclk 3000
  2727. $_TARGET.cpu configure -event reset-start @{ jtag_rclk 3000 @}
  2728. @end example
  2729. If your system supports adaptive clocking (RTCK), configuring
  2730. JTAG to use that is probably the most robust approach.
  2731. However, it introduces delays to synchronize clocks; so it
  2732. may not be the fastest solution.
  2733. @b{NOTE:} Script writers should consider using @command{jtag_rclk}
  2734. instead of @command{adapter speed}, but only for (ARM) cores and boards
  2735. which support adaptive clocking.
  2736. @deffn {Command} adapter speed max_speed_kHz
  2737. A non-zero speed is in KHZ. Hence: 3000 is 3mhz.
  2738. JTAG interfaces usually support a limited number of
  2739. speeds. The speed actually used won't be faster
  2740. than the speed specified.
  2741. Chip data sheets generally include a top JTAG clock rate.
  2742. The actual rate is often a function of a CPU core clock,
  2743. and is normally less than that peak rate.
  2744. For example, most ARM cores accept at most one sixth of the CPU clock.
  2745. Speed 0 (khz) selects RTCK method.
  2746. @xref{faqrtck,,FAQ RTCK}.
  2747. If your system uses RTCK, you won't need to change the
  2748. JTAG clocking after setup.
  2749. Not all interfaces, boards, or targets support ``rtck''.
  2750. If the interface device can not
  2751. support it, an error is returned when you try to use RTCK.
  2752. @end deffn
  2753. @defun jtag_rclk fallback_speed_kHz
  2754. @cindex adaptive clocking
  2755. @cindex RTCK
  2756. This Tcl proc (defined in @file{startup.tcl}) attempts to enable RTCK/RCLK.
  2757. If that fails (maybe the interface, board, or target doesn't
  2758. support it), falls back to the specified frequency.
  2759. @example
  2760. # Fall back to 3mhz if RTCK is not supported
  2761. jtag_rclk 3000
  2762. @end example
  2763. @end defun
  2764. @node Reset Configuration
  2765. @chapter Reset Configuration
  2766. @cindex Reset Configuration
  2767. Every system configuration may require a different reset
  2768. configuration. This can also be quite confusing.
  2769. Resets also interact with @var{reset-init} event handlers,
  2770. which do things like setting up clocks and DRAM, and
  2771. JTAG clock rates. (@xref{jtagspeed,,JTAG Speed}.)
  2772. They can also interact with JTAG routers.
  2773. Please see the various board files for examples.
  2774. @quotation Note
  2775. To maintainers and integrators:
  2776. Reset configuration touches several things at once.
  2777. Normally the board configuration file
  2778. should define it and assume that the JTAG adapter supports
  2779. everything that's wired up to the board's JTAG connector.
  2780. However, the target configuration file could also make note
  2781. of something the silicon vendor has done inside the chip,
  2782. which will be true for most (or all) boards using that chip.
  2783. And when the JTAG adapter doesn't support everything, the
  2784. user configuration file will need to override parts of
  2785. the reset configuration provided by other files.
  2786. @end quotation
  2787. @section Types of Reset
  2788. There are many kinds of reset possible through JTAG, but
  2789. they may not all work with a given board and adapter.
  2790. That's part of why reset configuration can be error prone.
  2791. @itemize @bullet
  2792. @item
  2793. @emph{System Reset} ... the @emph{SRST} hardware signal
  2794. resets all chips connected to the JTAG adapter, such as processors,
  2795. power management chips, and I/O controllers. Normally resets triggered
  2796. with this signal behave exactly like pressing a RESET button.
  2797. @item
  2798. @emph{JTAG TAP Reset} ... the @emph{TRST} hardware signal resets
  2799. just the TAP controllers connected to the JTAG adapter.
  2800. Such resets should not be visible to the rest of the system; resetting a
  2801. device's TAP controller just puts that controller into a known state.
  2802. @item
  2803. @emph{Emulation Reset} ... many devices can be reset through JTAG
  2804. commands. These resets are often distinguishable from system
  2805. resets, either explicitly (a "reset reason" register says so)
  2806. or implicitly (not all parts of the chip get reset).
  2807. @item
  2808. @emph{Other Resets} ... system-on-chip devices often support
  2809. several other types of reset.
  2810. You may need to arrange that a watchdog timer stops
  2811. while debugging, preventing a watchdog reset.
  2812. There may be individual module resets.
  2813. @end itemize
  2814. In the best case, OpenOCD can hold SRST, then reset
  2815. the TAPs via TRST and send commands through JTAG to halt the
  2816. CPU at the reset vector before the 1st instruction is executed.
  2817. Then when it finally releases the SRST signal, the system is
  2818. halted under debugger control before any code has executed.
  2819. This is the behavior required to support the @command{reset halt}
  2820. and @command{reset init} commands; after @command{reset init} a
  2821. board-specific script might do things like setting up DRAM.
  2822. (@xref{resetcommand,,Reset Command}.)
  2823. @anchor{srstandtrstissues}
  2824. @section SRST and TRST Issues
  2825. Because SRST and TRST are hardware signals, they can have a
  2826. variety of system-specific constraints. Some of the most
  2827. common issues are:
  2828. @itemize @bullet
  2829. @item @emph{Signal not available} ... Some boards don't wire
  2830. SRST or TRST to the JTAG connector. Some JTAG adapters don't
  2831. support such signals even if they are wired up.
  2832. Use the @command{reset_config} @var{signals} options to say
  2833. when either of those signals is not connected.
  2834. When SRST is not available, your code might not be able to rely
  2835. on controllers having been fully reset during code startup.
  2836. Missing TRST is not a problem, since JTAG-level resets can
  2837. be triggered using with TMS signaling.
  2838. @item @emph{Signals shorted} ... Sometimes a chip, board, or
  2839. adapter will connect SRST to TRST, instead of keeping them separate.
  2840. Use the @command{reset_config} @var{combination} options to say
  2841. when those signals aren't properly independent.
  2842. @item @emph{Timing} ... Reset circuitry like a resistor/capacitor
  2843. delay circuit, reset supervisor, or on-chip features can extend
  2844. the effect of a JTAG adapter's reset for some time after the adapter
  2845. stops issuing the reset. For example, there may be chip or board
  2846. requirements that all reset pulses last for at least a
  2847. certain amount of time; and reset buttons commonly have
  2848. hardware debouncing.
  2849. Use the @command{adapter srst delay} and @command{jtag_ntrst_delay}
  2850. commands to say when extra delays are needed.
  2851. @item @emph{Drive type} ... Reset lines often have a pullup
  2852. resistor, letting the JTAG interface treat them as open-drain
  2853. signals. But that's not a requirement, so the adapter may need
  2854. to use push/pull output drivers.
  2855. Also, with weak pullups it may be advisable to drive
  2856. signals to both levels (push/pull) to minimize rise times.
  2857. Use the @command{reset_config} @var{trst_type} and
  2858. @var{srst_type} parameters to say how to drive reset signals.
  2859. @item @emph{Special initialization} ... Targets sometimes need
  2860. special JTAG initialization sequences to handle chip-specific
  2861. issues (not limited to errata).
  2862. For example, certain JTAG commands might need to be issued while
  2863. the system as a whole is in a reset state (SRST active)
  2864. but the JTAG scan chain is usable (TRST inactive).
  2865. Many systems treat combined assertion of SRST and TRST as a
  2866. trigger for a harder reset than SRST alone.
  2867. Such custom reset handling is discussed later in this chapter.
  2868. @end itemize
  2869. There can also be other issues.
  2870. Some devices don't fully conform to the JTAG specifications.
  2871. Trivial system-specific differences are common, such as
  2872. SRST and TRST using slightly different names.
  2873. There are also vendors who distribute key JTAG documentation for
  2874. their chips only to developers who have signed a Non-Disclosure
  2875. Agreement (NDA).
  2876. Sometimes there are chip-specific extensions like a requirement to use
  2877. the normally-optional TRST signal (precluding use of JTAG adapters which
  2878. don't pass TRST through), or needing extra steps to complete a TAP reset.
  2879. In short, SRST and especially TRST handling may be very finicky,
  2880. needing to cope with both architecture and board specific constraints.
  2881. @section Commands for Handling Resets
  2882. @deffn {Command} adapter srst pulse_width milliseconds
  2883. Minimum amount of time (in milliseconds) OpenOCD should wait
  2884. after asserting nSRST (active-low system reset) before
  2885. allowing it to be deasserted.
  2886. @end deffn
  2887. @deffn {Command} adapter srst delay milliseconds
  2888. How long (in milliseconds) OpenOCD should wait after deasserting
  2889. nSRST (active-low system reset) before starting new JTAG operations.
  2890. When a board has a reset button connected to SRST line it will
  2891. probably have hardware debouncing, implying you should use this.
  2892. @end deffn
  2893. @deffn {Command} jtag_ntrst_assert_width milliseconds
  2894. Minimum amount of time (in milliseconds) OpenOCD should wait
  2895. after asserting nTRST (active-low JTAG TAP reset) before
  2896. allowing it to be deasserted.
  2897. @end deffn
  2898. @deffn {Command} jtag_ntrst_delay milliseconds
  2899. How long (in milliseconds) OpenOCD should wait after deasserting
  2900. nTRST (active-low JTAG TAP reset) before starting new JTAG operations.
  2901. @end deffn
  2902. @anchor{reset_config}
  2903. @deffn {Command} reset_config mode_flag ...
  2904. This command displays or modifies the reset configuration
  2905. of your combination of JTAG board and target in target
  2906. configuration scripts.
  2907. Information earlier in this section describes the kind of problems
  2908. the command is intended to address (@pxref{srstandtrstissues,,SRST and TRST Issues}).
  2909. As a rule this command belongs only in board config files,
  2910. describing issues like @emph{board doesn't connect TRST};
  2911. or in user config files, addressing limitations derived
  2912. from a particular combination of interface and board.
  2913. (An unlikely example would be using a TRST-only adapter
  2914. with a board that only wires up SRST.)
  2915. The @var{mode_flag} options can be specified in any order, but only one
  2916. of each type -- @var{signals}, @var{combination}, @var{gates},
  2917. @var{trst_type}, @var{srst_type} and @var{connect_type}
  2918. -- may be specified at a time.
  2919. If you don't provide a new value for a given type, its previous
  2920. value (perhaps the default) is unchanged.
  2921. For example, this means that you don't need to say anything at all about
  2922. TRST just to declare that if the JTAG adapter should want to drive SRST,
  2923. it must explicitly be driven high (@option{srst_push_pull}).
  2924. @itemize
  2925. @item
  2926. @var{signals} can specify which of the reset signals are connected.
  2927. For example, If the JTAG interface provides SRST, but the board doesn't
  2928. connect that signal properly, then OpenOCD can't use it.
  2929. Possible values are @option{none} (the default), @option{trst_only},
  2930. @option{srst_only} and @option{trst_and_srst}.
  2931. @quotation Tip
  2932. If your board provides SRST and/or TRST through the JTAG connector,
  2933. you must declare that so those signals can be used.
  2934. @end quotation
  2935. @item
  2936. The @var{combination} is an optional value specifying broken reset
  2937. signal implementations.
  2938. The default behaviour if no option given is @option{separate},
  2939. indicating everything behaves normally.
  2940. @option{srst_pulls_trst} states that the
  2941. test logic is reset together with the reset of the system (e.g. NXP
  2942. LPC2000, "broken" board layout), @option{trst_pulls_srst} says that
  2943. the system is reset together with the test logic (only hypothetical, I
  2944. haven't seen hardware with such a bug, and can be worked around).
  2945. @option{combined} implies both @option{srst_pulls_trst} and
  2946. @option{trst_pulls_srst}.
  2947. @item
  2948. The @var{gates} tokens control flags that describe some cases where
  2949. JTAG may be unavailable during reset.
  2950. @option{srst_gates_jtag} (default)
  2951. indicates that asserting SRST gates the
  2952. JTAG clock. This means that no communication can happen on JTAG
  2953. while SRST is asserted.
  2954. Its converse is @option{srst_nogate}, indicating that JTAG commands
  2955. can safely be issued while SRST is active.
  2956. @item
  2957. The @var{connect_type} tokens control flags that describe some cases where
  2958. SRST is asserted while connecting to the target. @option{srst_nogate}
  2959. is required to use this option.
  2960. @option{connect_deassert_srst} (default)
  2961. indicates that SRST will not be asserted while connecting to the target.
  2962. Its converse is @option{connect_assert_srst}, indicating that SRST will
  2963. be asserted before any target connection.
  2964. Only some targets support this feature, STM32 and STR9 are examples.
  2965. This feature is useful if you are unable to connect to your target due
  2966. to incorrect options byte config or illegal program execution.
  2967. @end itemize
  2968. The optional @var{trst_type} and @var{srst_type} parameters allow the
  2969. driver mode of each reset line to be specified. These values only affect
  2970. JTAG interfaces with support for different driver modes, like the Amontec
  2971. JTAGkey and JTAG Accelerator. Also, they are necessarily ignored if the
  2972. relevant signal (TRST or SRST) is not connected.
  2973. @itemize
  2974. @item
  2975. Possible @var{trst_type} driver modes for the test reset signal (TRST)
  2976. are the default @option{trst_push_pull}, and @option{trst_open_drain}.
  2977. Most boards connect this signal to a pulldown, so the JTAG TAPs
  2978. never leave reset unless they are hooked up to a JTAG adapter.
  2979. @item
  2980. Possible @var{srst_type} driver modes for the system reset signal (SRST)
  2981. are the default @option{srst_open_drain}, and @option{srst_push_pull}.
  2982. Most boards connect this signal to a pullup, and allow the
  2983. signal to be pulled low by various events including system
  2984. power-up and pressing a reset button.
  2985. @end itemize
  2986. @end deffn
  2987. @section Custom Reset Handling
  2988. @cindex events
  2989. OpenOCD has several ways to help support the various reset
  2990. mechanisms provided by chip and board vendors.
  2991. The commands shown in the previous section give standard parameters.
  2992. There are also @emph{event handlers} associated with TAPs or Targets.
  2993. Those handlers are Tcl procedures you can provide, which are invoked
  2994. at particular points in the reset sequence.
  2995. @emph{When SRST is not an option} you must set
  2996. up a @code{reset-assert} event handler for your target.
  2997. For example, some JTAG adapters don't include the SRST signal;
  2998. and some boards have multiple targets, and you won't always
  2999. want to reset everything at once.
  3000. After configuring those mechanisms, you might still
  3001. find your board doesn't start up or reset correctly.
  3002. For example, maybe it needs a slightly different sequence
  3003. of SRST and/or TRST manipulations, because of quirks that
  3004. the @command{reset_config} mechanism doesn't address;
  3005. or asserting both might trigger a stronger reset, which
  3006. needs special attention.
  3007. Experiment with lower level operations, such as
  3008. @command{adapter assert}, @command{adapter deassert}
  3009. and the @command{jtag arp_*} operations shown here,
  3010. to find a sequence of operations that works.
  3011. @xref{JTAG Commands}.
  3012. When you find a working sequence, it can be used to override
  3013. @command{jtag_init}, which fires during OpenOCD startup
  3014. (@pxref{configurationstage,,Configuration Stage});
  3015. or @command{init_reset}, which fires during reset processing.
  3016. You might also want to provide some project-specific reset
  3017. schemes. For example, on a multi-target board the standard
  3018. @command{reset} command would reset all targets, but you
  3019. may need the ability to reset only one target at time and
  3020. thus want to avoid using the board-wide SRST signal.
  3021. @deffn {Overridable Procedure} init_reset mode
  3022. This is invoked near the beginning of the @command{reset} command,
  3023. usually to provide as much of a cold (power-up) reset as practical.
  3024. By default it is also invoked from @command{jtag_init} if
  3025. the scan chain does not respond to pure JTAG operations.
  3026. The @var{mode} parameter is the parameter given to the
  3027. low level reset command (@option{halt},
  3028. @option{init}, or @option{run}), @option{setup},
  3029. or potentially some other value.
  3030. The default implementation just invokes @command{jtag arp_init-reset}.
  3031. Replacements will normally build on low level JTAG
  3032. operations such as @command{adapter assert} and @command{adapter deassert}.
  3033. Operations here must not address individual TAPs
  3034. (or their associated targets)
  3035. until the JTAG scan chain has first been verified to work.
  3036. Implementations must have verified the JTAG scan chain before
  3037. they return.
  3038. This is done by calling @command{jtag arp_init}
  3039. (or @command{jtag arp_init-reset}).
  3040. @end deffn
  3041. @deffn Command {jtag arp_init}
  3042. This validates the scan chain using just the four
  3043. standard JTAG signals (TMS, TCK, TDI, TDO).
  3044. It starts by issuing a JTAG-only reset.
  3045. Then it performs checks to verify that the scan chain configuration
  3046. matches the TAPs it can observe.
  3047. Those checks include checking IDCODE values for each active TAP,
  3048. and verifying the length of their instruction registers using
  3049. TAP @code{-ircapture} and @code{-irmask} values.
  3050. If these tests all pass, TAP @code{setup} events are
  3051. issued to all TAPs with handlers for that event.
  3052. @end deffn
  3053. @deffn Command {jtag arp_init-reset}
  3054. This uses TRST and SRST to try resetting
  3055. everything on the JTAG scan chain
  3056. (and anything else connected to SRST).
  3057. It then invokes the logic of @command{jtag arp_init}.
  3058. @end deffn
  3059. @node TAP Declaration
  3060. @chapter TAP Declaration
  3061. @cindex TAP declaration
  3062. @cindex TAP configuration
  3063. @emph{Test Access Ports} (TAPs) are the core of JTAG.
  3064. TAPs serve many roles, including:
  3065. @itemize @bullet
  3066. @item @b{Debug Target} A CPU TAP can be used as a GDB debug target.
  3067. @item @b{Flash Programming} Some chips program the flash directly via JTAG.
  3068. Others do it indirectly, making a CPU do it.
  3069. @item @b{Program Download} Using the same CPU support GDB uses,
  3070. you can initialize a DRAM controller, download code to DRAM, and then
  3071. start running that code.
  3072. @item @b{Boundary Scan} Most chips support boundary scan, which
  3073. helps test for board assembly problems like solder bridges
  3074. and missing connections.
  3075. @end itemize
  3076. OpenOCD must know about the active TAPs on your board(s).
  3077. Setting up the TAPs is the core task of your configuration files.
  3078. Once those TAPs are set up, you can pass their names to code
  3079. which sets up CPUs and exports them as GDB targets,
  3080. probes flash memory, performs low-level JTAG operations, and more.
  3081. @section Scan Chains
  3082. @cindex scan chain
  3083. TAPs are part of a hardware @dfn{scan chain},
  3084. which is a daisy chain of TAPs.
  3085. They also need to be added to
  3086. OpenOCD's software mirror of that hardware list,
  3087. giving each member a name and associating other data with it.
  3088. Simple scan chains, with a single TAP, are common in
  3089. systems with a single microcontroller or microprocessor.
  3090. More complex chips may have several TAPs internally.
  3091. Very complex scan chains might have a dozen or more TAPs:
  3092. several in one chip, more in the next, and connecting
  3093. to other boards with their own chips and TAPs.
  3094. You can display the list with the @command{scan_chain} command.
  3095. (Don't confuse this with the list displayed by the @command{targets}
  3096. command, presented in the next chapter.
  3097. That only displays TAPs for CPUs which are configured as
  3098. debugging targets.)
  3099. Here's what the scan chain might look like for a chip more than one TAP:
  3100. @verbatim
  3101. TapName Enabled IdCode Expected IrLen IrCap IrMask
  3102. -- ------------------ ------- ---------- ---------- ----- ----- ------
  3103. 0 omap5912.dsp Y 0x03df1d81 0x03df1d81 38 0x01 0x03
  3104. 1 omap5912.arm Y 0x0692602f 0x0692602f 4 0x01 0x0f
  3105. 2 omap5912.unknown Y 0x00000000 0x00000000 8 0x01 0x03
  3106. @end verbatim
  3107. OpenOCD can detect some of that information, but not all
  3108. of it. @xref{autoprobing,,Autoprobing}.
  3109. Unfortunately, those TAPs can't always be autoconfigured,
  3110. because not all devices provide good support for that.
  3111. JTAG doesn't require supporting IDCODE instructions, and
  3112. chips with JTAG routers may not link TAPs into the chain
  3113. until they are told to do so.
  3114. The configuration mechanism currently supported by OpenOCD
  3115. requires explicit configuration of all TAP devices using
  3116. @command{jtag newtap} commands, as detailed later in this chapter.
  3117. A command like this would declare one tap and name it @code{chip1.cpu}:
  3118. @example
  3119. jtag newtap chip1 cpu -irlen 4 -expected-id 0x3ba00477
  3120. @end example
  3121. Each target configuration file lists the TAPs provided
  3122. by a given chip.
  3123. Board configuration files combine all the targets on a board,
  3124. and so forth.
  3125. Note that @emph{the order in which TAPs are declared is very important.}
  3126. That declaration order must match the order in the JTAG scan chain,
  3127. both inside a single chip and between them.
  3128. @xref{faqtaporder,,FAQ TAP Order}.
  3129. For example, the STMicroelectronics STR912 chip has
  3130. three separate TAPs@footnote{See the ST
  3131. document titled: @emph{STR91xFAxxx, Section 3.15 Jtag Interface, Page:
  3132. 28/102, Figure 3: JTAG chaining inside the STR91xFA}.
  3133. @url{http://eu.st.com/stonline/products/literature/ds/13495.pdf}}.
  3134. To configure those taps, @file{target/str912.cfg}
  3135. includes commands something like this:
  3136. @example
  3137. jtag newtap str912 flash ... params ...
  3138. jtag newtap str912 cpu ... params ...
  3139. jtag newtap str912 bs ... params ...
  3140. @end example
  3141. Actual config files typically use a variable such as @code{$_CHIPNAME}
  3142. instead of literals like @option{str912}, to support more than one chip
  3143. of each type. @xref{Config File Guidelines}.
  3144. @deffn Command {jtag names}
  3145. Returns the names of all current TAPs in the scan chain.
  3146. Use @command{jtag cget} or @command{jtag tapisenabled}
  3147. to examine attributes and state of each TAP.
  3148. @example
  3149. foreach t [jtag names] @{
  3150. puts [format "TAP: %s\n" $t]
  3151. @}
  3152. @end example
  3153. @end deffn
  3154. @deffn Command {scan_chain}
  3155. Displays the TAPs in the scan chain configuration,
  3156. and their status.
  3157. The set of TAPs listed by this command is fixed by
  3158. exiting the OpenOCD configuration stage,
  3159. but systems with a JTAG router can
  3160. enable or disable TAPs dynamically.
  3161. @end deffn
  3162. @c FIXME! "jtag cget" should be able to return all TAP
  3163. @c attributes, like "$target_name cget" does for targets.
  3164. @c Probably want "jtag eventlist", and a "tap-reset" event
  3165. @c (on entry to RESET state).
  3166. @section TAP Names
  3167. @cindex dotted name
  3168. When TAP objects are declared with @command{jtag newtap},
  3169. a @dfn{dotted.name} is created for the TAP, combining the
  3170. name of a module (usually a chip) and a label for the TAP.
  3171. For example: @code{xilinx.tap}, @code{str912.flash},
  3172. @code{omap3530.jrc}, @code{dm6446.dsp}, or @code{stm32.cpu}.
  3173. Many other commands use that dotted.name to manipulate or
  3174. refer to the TAP. For example, CPU configuration uses the
  3175. name, as does declaration of NAND or NOR flash banks.
  3176. The components of a dotted name should follow ``C'' symbol
  3177. name rules: start with an alphabetic character, then numbers
  3178. and underscores are OK; while others (including dots!) are not.
  3179. @section TAP Declaration Commands
  3180. @c shouldn't this be(come) a {Config Command}?
  3181. @deffn Command {jtag newtap} chipname tapname configparams...
  3182. Declares a new TAP with the dotted name @var{chipname}.@var{tapname},
  3183. and configured according to the various @var{configparams}.
  3184. The @var{chipname} is a symbolic name for the chip.
  3185. Conventionally target config files use @code{$_CHIPNAME},
  3186. defaulting to the model name given by the chip vendor but
  3187. overridable.
  3188. @cindex TAP naming convention
  3189. The @var{tapname} reflects the role of that TAP,
  3190. and should follow this convention:
  3191. @itemize @bullet
  3192. @item @code{bs} -- For boundary scan if this is a separate TAP;
  3193. @item @code{cpu} -- The main CPU of the chip, alternatively
  3194. @code{arm} and @code{dsp} on chips with both ARM and DSP CPUs,
  3195. @code{arm1} and @code{arm2} on chips with two ARMs, and so forth;
  3196. @item @code{etb} -- For an embedded trace buffer (example: an ARM ETB11);
  3197. @item @code{flash} -- If the chip has a flash TAP, like the str912;
  3198. @item @code{jrc} -- For JTAG route controller (example: the ICEPick modules
  3199. on many Texas Instruments chips, like the OMAP3530 on Beagleboards);
  3200. @item @code{tap} -- Should be used only for FPGA- or CPLD-like devices
  3201. with a single TAP;
  3202. @item @code{unknownN} -- If you have no idea what the TAP is for (N is a number);
  3203. @item @emph{when in doubt} -- Use the chip maker's name in their data sheet.
  3204. For example, the Freescale i.MX31 has a SDMA (Smart DMA) with
  3205. a JTAG TAP; that TAP should be named @code{sdma}.
  3206. @end itemize
  3207. Every TAP requires at least the following @var{configparams}:
  3208. @itemize @bullet
  3209. @item @code{-irlen} @var{NUMBER}
  3210. @*The length in bits of the
  3211. instruction register, such as 4 or 5 bits.
  3212. @end itemize
  3213. A TAP may also provide optional @var{configparams}:
  3214. @itemize @bullet
  3215. @item @code{-disable} (or @code{-enable})
  3216. @*Use the @code{-disable} parameter to flag a TAP which is not
  3217. linked into the scan chain after a reset using either TRST
  3218. or the JTAG state machine's @sc{reset} state.
  3219. You may use @code{-enable} to highlight the default state
  3220. (the TAP is linked in).
  3221. @xref{enablinganddisablingtaps,,Enabling and Disabling TAPs}.
  3222. @item @code{-expected-id} @var{NUMBER}
  3223. @*A non-zero @var{number} represents a 32-bit IDCODE
  3224. which you expect to find when the scan chain is examined.
  3225. These codes are not required by all JTAG devices.
  3226. @emph{Repeat the option} as many times as required if more than one
  3227. ID code could appear (for example, multiple versions).
  3228. Specify @var{number} as zero to suppress warnings about IDCODE
  3229. values that were found but not included in the list.
  3230. Provide this value if at all possible, since it lets OpenOCD
  3231. tell when the scan chain it sees isn't right. These values
  3232. are provided in vendors' chip documentation, usually a technical
  3233. reference manual. Sometimes you may need to probe the JTAG
  3234. hardware to find these values.
  3235. @xref{autoprobing,,Autoprobing}.
  3236. @item @code{-ignore-version}
  3237. @*Specify this to ignore the JTAG version field in the @code{-expected-id}
  3238. option. When vendors put out multiple versions of a chip, or use the same
  3239. JTAG-level ID for several largely-compatible chips, it may be more practical
  3240. to ignore the version field than to update config files to handle all of
  3241. the various chip IDs. The version field is defined as bit 28-31 of the IDCODE.
  3242. @item @code{-ircapture} @var{NUMBER}
  3243. @*The bit pattern loaded by the TAP into the JTAG shift register
  3244. on entry to the @sc{ircapture} state, such as 0x01.
  3245. JTAG requires the two LSBs of this value to be 01.
  3246. By default, @code{-ircapture} and @code{-irmask} are set
  3247. up to verify that two-bit value. You may provide
  3248. additional bits if you know them, or indicate that
  3249. a TAP doesn't conform to the JTAG specification.
  3250. @item @code{-irmask} @var{NUMBER}
  3251. @*A mask used with @code{-ircapture}
  3252. to verify that instruction scans work correctly.
  3253. Such scans are not used by OpenOCD except to verify that
  3254. there seems to be no problems with JTAG scan chain operations.
  3255. @item @code{-ignore-syspwrupack}
  3256. @*Specify this to ignore the CSYSPWRUPACK bit in the ARM DAP DP CTRL/STAT
  3257. register during initial examination and when checking the sticky error bit.
  3258. This bit is normally checked after setting the CSYSPWRUPREQ bit, but some
  3259. devices do not set the ack bit until sometime later.
  3260. @end itemize
  3261. @end deffn
  3262. @section Other TAP commands
  3263. @deffn Command {jtag cget} dotted.name @option{-idcode}
  3264. Get the value of the IDCODE found in hardware.
  3265. @end deffn
  3266. @deffn Command {jtag cget} dotted.name @option{-event} event_name
  3267. @deffnx Command {jtag configure} dotted.name @option{-event} event_name handler
  3268. At this writing this TAP attribute
  3269. mechanism is limited and used mostly for event handling.
  3270. (It is not a direct analogue of the @code{cget}/@code{configure}
  3271. mechanism for debugger targets.)
  3272. See the next section for information about the available events.
  3273. The @code{configure} subcommand assigns an event handler,
  3274. a TCL string which is evaluated when the event is triggered.
  3275. The @code{cget} subcommand returns that handler.
  3276. @end deffn
  3277. @section TAP Events
  3278. @cindex events
  3279. @cindex TAP events
  3280. OpenOCD includes two event mechanisms.
  3281. The one presented here applies to all JTAG TAPs.
  3282. The other applies to debugger targets,
  3283. which are associated with certain TAPs.
  3284. The TAP events currently defined are:
  3285. @itemize @bullet
  3286. @item @b{post-reset}
  3287. @* The TAP has just completed a JTAG reset.
  3288. The tap may still be in the JTAG @sc{reset} state.
  3289. Handlers for these events might perform initialization sequences
  3290. such as issuing TCK cycles, TMS sequences to ensure
  3291. exit from the ARM SWD mode, and more.
  3292. Because the scan chain has not yet been verified, handlers for these events
  3293. @emph{should not issue commands which scan the JTAG IR or DR registers}
  3294. of any particular target.
  3295. @b{NOTE:} As this is written (September 2009), nothing prevents such access.
  3296. @item @b{setup}
  3297. @* The scan chain has been reset and verified.
  3298. This handler may enable TAPs as needed.
  3299. @item @b{tap-disable}
  3300. @* The TAP needs to be disabled. This handler should
  3301. implement @command{jtag tapdisable}
  3302. by issuing the relevant JTAG commands.
  3303. @item @b{tap-enable}
  3304. @* The TAP needs to be enabled. This handler should
  3305. implement @command{jtag tapenable}
  3306. by issuing the relevant JTAG commands.
  3307. @end itemize
  3308. If you need some action after each JTAG reset which isn't actually
  3309. specific to any TAP (since you can't yet trust the scan chain's
  3310. contents to be accurate), you might:
  3311. @example
  3312. jtag configure CHIP.jrc -event post-reset @{
  3313. echo "JTAG Reset done"
  3314. ... non-scan jtag operations to be done after reset
  3315. @}
  3316. @end example
  3317. @anchor{enablinganddisablingtaps}
  3318. @section Enabling and Disabling TAPs
  3319. @cindex JTAG Route Controller
  3320. @cindex jrc
  3321. In some systems, a @dfn{JTAG Route Controller} (JRC)
  3322. is used to enable and/or disable specific JTAG TAPs.
  3323. Many ARM-based chips from Texas Instruments include
  3324. an ``ICEPick'' module, which is a JRC.
  3325. Such chips include DaVinci and OMAP3 processors.
  3326. A given TAP may not be visible until the JRC has been
  3327. told to link it into the scan chain; and if the JRC
  3328. has been told to unlink that TAP, it will no longer
  3329. be visible.
  3330. Such routers address problems that JTAG ``bypass mode''
  3331. ignores, such as:
  3332. @itemize
  3333. @item The scan chain can only go as fast as its slowest TAP.
  3334. @item Having many TAPs slows instruction scans, since all
  3335. TAPs receive new instructions.
  3336. @item TAPs in the scan chain must be powered up, which wastes
  3337. power and prevents debugging some power management mechanisms.
  3338. @end itemize
  3339. The IEEE 1149.1 JTAG standard has no concept of a ``disabled'' tap,
  3340. as implied by the existence of JTAG routers.
  3341. However, the upcoming IEEE 1149.7 framework (layered on top of JTAG)
  3342. does include a kind of JTAG router functionality.
  3343. @c (a) currently the event handlers don't seem to be able to
  3344. @c fail in a way that could lead to no-change-of-state.
  3345. In OpenOCD, tap enabling/disabling is invoked by the Tcl commands
  3346. shown below, and is implemented using TAP event handlers.
  3347. So for example, when defining a TAP for a CPU connected to
  3348. a JTAG router, your @file{target.cfg} file
  3349. should define TAP event handlers using
  3350. code that looks something like this:
  3351. @example
  3352. jtag configure CHIP.cpu -event tap-enable @{
  3353. ... jtag operations using CHIP.jrc
  3354. @}
  3355. jtag configure CHIP.cpu -event tap-disable @{
  3356. ... jtag operations using CHIP.jrc
  3357. @}
  3358. @end example
  3359. Then you might want that CPU's TAP enabled almost all the time:
  3360. @example
  3361. jtag configure $CHIP.jrc -event setup "jtag tapenable $CHIP.cpu"
  3362. @end example
  3363. Note how that particular setup event handler declaration
  3364. uses quotes to evaluate @code{$CHIP} when the event is configured.
  3365. Using brackets @{ @} would cause it to be evaluated later,
  3366. at runtime, when it might have a different value.
  3367. @deffn Command {jtag tapdisable} dotted.name
  3368. If necessary, disables the tap
  3369. by sending it a @option{tap-disable} event.
  3370. Returns the string "1" if the tap
  3371. specified by @var{dotted.name} is enabled,
  3372. and "0" if it is disabled.
  3373. @end deffn
  3374. @deffn Command {jtag tapenable} dotted.name
  3375. If necessary, enables the tap
  3376. by sending it a @option{tap-enable} event.
  3377. Returns the string "1" if the tap
  3378. specified by @var{dotted.name} is enabled,
  3379. and "0" if it is disabled.
  3380. @end deffn
  3381. @deffn Command {jtag tapisenabled} dotted.name
  3382. Returns the string "1" if the tap
  3383. specified by @var{dotted.name} is enabled,
  3384. and "0" if it is disabled.
  3385. @quotation Note
  3386. Humans will find the @command{scan_chain} command more helpful
  3387. for querying the state of the JTAG taps.
  3388. @end quotation
  3389. @end deffn
  3390. @anchor{autoprobing}
  3391. @section Autoprobing
  3392. @cindex autoprobe
  3393. @cindex JTAG autoprobe
  3394. TAP configuration is the first thing that needs to be done
  3395. after interface and reset configuration. Sometimes it's
  3396. hard finding out what TAPs exist, or how they are identified.
  3397. Vendor documentation is not always easy to find and use.
  3398. To help you get past such problems, OpenOCD has a limited
  3399. @emph{autoprobing} ability to look at the scan chain, doing
  3400. a @dfn{blind interrogation} and then reporting the TAPs it finds.
  3401. To use this mechanism, start the OpenOCD server with only data
  3402. that configures your JTAG interface, and arranges to come up
  3403. with a slow clock (many devices don't support fast JTAG clocks
  3404. right when they come out of reset).
  3405. For example, your @file{openocd.cfg} file might have:
  3406. @example
  3407. source [find interface/olimex-arm-usb-tiny-h.cfg]
  3408. reset_config trst_and_srst
  3409. jtag_rclk 8
  3410. @end example
  3411. When you start the server without any TAPs configured, it will
  3412. attempt to autoconfigure the TAPs. There are two parts to this:
  3413. @enumerate
  3414. @item @emph{TAP discovery} ...
  3415. After a JTAG reset (sometimes a system reset may be needed too),
  3416. each TAP's data registers will hold the contents of either the
  3417. IDCODE or BYPASS register.
  3418. If JTAG communication is working, OpenOCD will see each TAP,
  3419. and report what @option{-expected-id} to use with it.
  3420. @item @emph{IR Length discovery} ...
  3421. Unfortunately JTAG does not provide a reliable way to find out
  3422. the value of the @option{-irlen} parameter to use with a TAP
  3423. that is discovered.
  3424. If OpenOCD can discover the length of a TAP's instruction
  3425. register, it will report it.
  3426. Otherwise you may need to consult vendor documentation, such
  3427. as chip data sheets or BSDL files.
  3428. @end enumerate
  3429. In many cases your board will have a simple scan chain with just
  3430. a single device. Here's what OpenOCD reported with one board
  3431. that's a bit more complex:
  3432. @example
  3433. clock speed 8 kHz
  3434. There are no enabled taps. AUTO PROBING MIGHT NOT WORK!!
  3435. AUTO auto0.tap - use "jtag newtap auto0 tap -expected-id 0x2b900f0f ..."
  3436. AUTO auto1.tap - use "jtag newtap auto1 tap -expected-id 0x07926001 ..."
  3437. AUTO auto2.tap - use "jtag newtap auto2 tap -expected-id 0x0b73b02f ..."
  3438. AUTO auto0.tap - use "... -irlen 4"
  3439. AUTO auto1.tap - use "... -irlen 4"
  3440. AUTO auto2.tap - use "... -irlen 6"
  3441. no gdb ports allocated as no target has been specified
  3442. @end example
  3443. Given that information, you should be able to either find some existing
  3444. config files to use, or create your own. If you create your own, you
  3445. would configure from the bottom up: first a @file{target.cfg} file
  3446. with these TAPs, any targets associated with them, and any on-chip
  3447. resources; then a @file{board.cfg} with off-chip resources, clocking,
  3448. and so forth.
  3449. @anchor{dapdeclaration}
  3450. @section DAP declaration (ARMv6-M, ARMv7 and ARMv8 targets)
  3451. @cindex DAP declaration
  3452. Since OpenOCD version 0.11.0, the Debug Access Port (DAP) is
  3453. no longer implicitly created together with the target. It must be
  3454. explicitly declared using the @command{dap create} command. For all ARMv6-M, ARMv7
  3455. and ARMv8 targets, the option "@option{-dap} @var{dap_name}" has to be used
  3456. instead of "@option{-chain-position} @var{dotted.name}" when the target is created.
  3457. The @command{dap} command group supports the following sub-commands:
  3458. @deffn Command {dap create} dap_name @option{-chain-position} dotted.name configparams...
  3459. Declare a DAP instance named @var{dap_name} linked to the JTAG tap
  3460. @var{dotted.name}. This also creates a new command (@command{dap_name})
  3461. which is used for various purposes including additional configuration.
  3462. There can only be one DAP for each JTAG tap in the system.
  3463. A DAP may also provide optional @var{configparams}:
  3464. @itemize @bullet
  3465. @item @code{-ignore-syspwrupack}
  3466. @*Specify this to ignore the CSYSPWRUPACK bit in the ARM DAP DP CTRL/STAT
  3467. register during initial examination and when checking the sticky error bit.
  3468. This bit is normally checked after setting the CSYSPWRUPREQ bit, but some
  3469. devices do not set the ack bit until sometime later.
  3470. @end itemize
  3471. @end deffn
  3472. @deffn Command {dap names}
  3473. This command returns a list of all registered DAP objects. It it useful mainly
  3474. for TCL scripting.
  3475. @end deffn
  3476. @deffn Command {dap info} [num]
  3477. Displays the ROM table for MEM-AP @var{num},
  3478. defaulting to the currently selected AP of the currently selected target.
  3479. @end deffn
  3480. @deffn Command {dap init}
  3481. Initialize all registered DAPs. This command is used internally
  3482. during initialization. It can be issued at any time after the
  3483. initialization, too.
  3484. @end deffn
  3485. The following commands exist as subcommands of DAP instances:
  3486. @deffn Command {$dap_name info} [num]
  3487. Displays the ROM table for MEM-AP @var{num},
  3488. defaulting to the currently selected AP.
  3489. @end deffn
  3490. @deffn Command {$dap_name apid} [num]
  3491. Displays ID register from AP @var{num}, defaulting to the currently selected AP.
  3492. @end deffn
  3493. @anchor{DAP subcommand apreg}
  3494. @deffn Command {$dap_name apreg} ap_num reg [value]
  3495. Displays content of a register @var{reg} from AP @var{ap_num}
  3496. or set a new value @var{value}.
  3497. @var{reg} is byte address of a word register, 0, 4, 8 ... 0xfc.
  3498. @end deffn
  3499. @deffn Command {$dap_name apsel} [num]
  3500. Select AP @var{num}, defaulting to 0.
  3501. @end deffn
  3502. @deffn Command {$dap_name dpreg} reg [value]
  3503. Displays the content of DP register at address @var{reg}, or set it to a new
  3504. value @var{value}.
  3505. In case of SWD, @var{reg} is a value in packed format
  3506. @math{dpbanksel << 4 | addr} and assumes values 0, 4, 8 ... 0xfc.
  3507. In case of JTAG it only assumes values 0, 4, 8 and 0xc.
  3508. @emph{Note:} Consider using @command{poll off} to avoid any disturbing
  3509. background activity by OpenOCD while you are operating at such low-level.
  3510. @end deffn
  3511. @deffn Command {$dap_name baseaddr} [num]
  3512. Displays debug base address from MEM-AP @var{num},
  3513. defaulting to the currently selected AP.
  3514. @end deffn
  3515. @deffn Command {$dap_name memaccess} [value]
  3516. Displays the number of extra tck cycles in the JTAG idle to use for MEM-AP
  3517. memory bus access [0-255], giving additional time to respond to reads.
  3518. If @var{value} is defined, first assigns that.
  3519. @end deffn
  3520. @deffn Command {$dap_name apcsw} [value [mask]]
  3521. Displays or changes CSW bit pattern for MEM-AP transfers.
  3522. At the begin of each memory access the CSW pattern is extended (bitwise or-ed)
  3523. by @dfn{Size} and @dfn{AddrInc} bit-fields according to transfer requirements
  3524. and the result is written to the real CSW register. All bits except dynamically
  3525. updated fields @dfn{Size} and @dfn{AddrInc} can be changed by changing
  3526. the CSW pattern. Refer to ARM ADI v5 manual chapter 7.6.4 and appendix A
  3527. for details.
  3528. Use @var{value} only syntax if you want to set the new CSW pattern as a whole.
  3529. The example sets HPROT1 bit (required by Cortex-M) and clears the rest of
  3530. the pattern:
  3531. @example
  3532. kx.dap apcsw 0x2000000
  3533. @end example
  3534. If @var{mask} is also used, the CSW pattern is changed only on bit positions
  3535. where the mask bit is 1. The following example sets HPROT3 (cacheable)
  3536. and leaves the rest of the pattern intact. It configures memory access through
  3537. DCache on Cortex-M7.
  3538. @example
  3539. set CSW_HPROT3_CACHEABLE [expr 1 << 27]
  3540. samv.dap apcsw $CSW_HPROT3_CACHEABLE $CSW_HPROT3_CACHEABLE
  3541. @end example
  3542. Another example clears SPROT bit and leaves the rest of pattern intact:
  3543. @example
  3544. set CSW_SPROT [expr 1 << 30]
  3545. samv.dap apcsw 0 $CSW_SPROT
  3546. @end example
  3547. @emph{Note:} If you want to check the real value of CSW, not CSW pattern, use
  3548. @code{xxx.dap apreg 0}. @xref{DAP subcommand apreg,,}.
  3549. @emph{Warning:} Some of the CSW bits are vital for working memory transfer.
  3550. If you set a wrong CSW pattern and MEM-AP stopped working, use the following
  3551. example with a proper dap name:
  3552. @example
  3553. xxx.dap apcsw default
  3554. @end example
  3555. @end deffn
  3556. @deffn Command {$dap_name ti_be_32_quirks} [@option{enable}]
  3557. Set/get quirks mode for TI TMS450/TMS570 processors
  3558. Disabled by default
  3559. @end deffn
  3560. @node CPU Configuration
  3561. @chapter CPU Configuration
  3562. @cindex GDB target
  3563. This chapter discusses how to set up GDB debug targets for CPUs.
  3564. You can also access these targets without GDB
  3565. (@pxref{Architecture and Core Commands},
  3566. and @ref{targetstatehandling,,Target State handling}) and
  3567. through various kinds of NAND and NOR flash commands.
  3568. If you have multiple CPUs you can have multiple such targets.
  3569. We'll start by looking at how to examine the targets you have,
  3570. then look at how to add one more target and how to configure it.
  3571. @section Target List
  3572. @cindex target, current
  3573. @cindex target, list
  3574. All targets that have been set up are part of a list,
  3575. where each member has a name.
  3576. That name should normally be the same as the TAP name.
  3577. You can display the list with the @command{targets}
  3578. (plural!) command.
  3579. This display often has only one CPU; here's what it might
  3580. look like with more than one:
  3581. @verbatim
  3582. TargetName Type Endian TapName State
  3583. -- ------------------ ---------- ------ ------------------ ------------
  3584. 0* at91rm9200.cpu arm920t little at91rm9200.cpu running
  3585. 1 MyTarget cortex_m little mychip.foo tap-disabled
  3586. @end verbatim
  3587. One member of that list is the @dfn{current target}, which
  3588. is implicitly referenced by many commands.
  3589. It's the one marked with a @code{*} near the target name.
  3590. In particular, memory addresses often refer to the address
  3591. space seen by that current target.
  3592. Commands like @command{mdw} (memory display words)
  3593. and @command{flash erase_address} (erase NOR flash blocks)
  3594. are examples; and there are many more.
  3595. Several commands let you examine the list of targets:
  3596. @deffn Command {target current}
  3597. Returns the name of the current target.
  3598. @end deffn
  3599. @deffn Command {target names}
  3600. Lists the names of all current targets in the list.
  3601. @example
  3602. foreach t [target names] @{
  3603. puts [format "Target: %s\n" $t]
  3604. @}
  3605. @end example
  3606. @end deffn
  3607. @c yep, "target list" would have been better.
  3608. @c plus maybe "target setdefault".
  3609. @deffn Command targets [name]
  3610. @emph{Note: the name of this command is plural. Other target
  3611. command names are singular.}
  3612. With no parameter, this command displays a table of all known
  3613. targets in a user friendly form.
  3614. With a parameter, this command sets the current target to
  3615. the given target with the given @var{name}; this is
  3616. only relevant on boards which have more than one target.
  3617. @end deffn
  3618. @section Target CPU Types
  3619. @cindex target type
  3620. @cindex CPU type
  3621. Each target has a @dfn{CPU type}, as shown in the output of
  3622. the @command{targets} command. You need to specify that type
  3623. when calling @command{target create}.
  3624. The CPU type indicates more than just the instruction set.
  3625. It also indicates how that instruction set is implemented,
  3626. what kind of debug support it integrates,
  3627. whether it has an MMU (and if so, what kind),
  3628. what core-specific commands may be available
  3629. (@pxref{Architecture and Core Commands}),
  3630. and more.
  3631. It's easy to see what target types are supported,
  3632. since there's a command to list them.
  3633. @anchor{targettypes}
  3634. @deffn Command {target types}
  3635. Lists all supported target types.
  3636. At this writing, the supported CPU types are:
  3637. @itemize @bullet
  3638. @item @code{arm11} -- this is a generation of ARMv6 cores
  3639. @item @code{arm720t} -- this is an ARMv4 core with an MMU
  3640. @item @code{arm7tdmi} -- this is an ARMv4 core
  3641. @item @code{arm920t} -- this is an ARMv4 core with an MMU
  3642. @item @code{arm926ejs} -- this is an ARMv5 core with an MMU
  3643. @item @code{arm966e} -- this is an ARMv5 core
  3644. @item @code{arm9tdmi} -- this is an ARMv4 core
  3645. @item @code{avr} -- implements Atmel's 8-bit AVR instruction set.
  3646. (Support for this is preliminary and incomplete.)
  3647. @item @code{cortex_a} -- this is an ARMv7 core with an MMU
  3648. @item @code{cortex_m} -- this is an ARMv7 core, supporting only the
  3649. compact Thumb2 instruction set.
  3650. @item @code{aarch64} -- this is an ARMv8-A core with an MMU
  3651. @item @code{dragonite} -- resembles arm966e
  3652. @item @code{dsp563xx} -- implements Freescale's 24-bit DSP.
  3653. (Support for this is still incomplete.)
  3654. @item @code{esirisc} -- this is an EnSilica eSi-RISC core.
  3655. The current implementation supports eSi-32xx cores.
  3656. @item @code{fa526} -- resembles arm920 (w/o Thumb)
  3657. @item @code{feroceon} -- resembles arm926
  3658. @item @code{mem_ap} -- this is an ARM debug infrastructure Access Port without a CPU, through which bus read and write cycles can be generated; it may be useful for working with non-CPU hardware behind an AP or during development of support for new CPUs.
  3659. @item @code{mips_m4k} -- a MIPS core
  3660. @item @code{xscale} -- this is actually an architecture,
  3661. not a CPU type. It is based on the ARMv5 architecture.
  3662. @item @code{openrisc} -- this is an OpenRISC 1000 core.
  3663. The current implementation supports three JTAG TAP cores:
  3664. @item @code{ls1_sap} -- this is the SAP on NXP LS102x CPUs,
  3665. allowing access to physical memory addresses independently of CPU cores.
  3666. @itemize @minus
  3667. @item @code{OpenCores TAP} (See: @url{http://opencores.org/project@comma{}jtag})
  3668. @item @code{Altera Virtual JTAG TAP} (See: @url{http://www.altera.com/literature/ug/ug_virtualjtag.pdf})
  3669. @item @code{Xilinx BSCAN_* virtual JTAG interface} (See: @url{http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_2/spartan6_hdl.pdf})
  3670. @end itemize
  3671. And two debug interfaces cores:
  3672. @itemize @minus
  3673. @item @code{Advanced debug interface} (See: @url{http://opencores.org/project@comma{}adv_debug_sys})
  3674. @item @code{SoC Debug Interface} (See: @url{http://opencores.org/project@comma{}dbg_interface})
  3675. @end itemize
  3676. @end itemize
  3677. @end deffn
  3678. To avoid being confused by the variety of ARM based cores, remember
  3679. this key point: @emph{ARM is a technology licencing company}.
  3680. (See: @url{http://www.arm.com}.)
  3681. The CPU name used by OpenOCD will reflect the CPU design that was
  3682. licensed, not a vendor brand which incorporates that design.
  3683. Name prefixes like arm7, arm9, arm11, and cortex
  3684. reflect design generations;
  3685. while names like ARMv4, ARMv5, ARMv6, ARMv7 and ARMv8
  3686. reflect an architecture version implemented by a CPU design.
  3687. @anchor{targetconfiguration}
  3688. @section Target Configuration
  3689. Before creating a ``target'', you must have added its TAP to the scan chain.
  3690. When you've added that TAP, you will have a @code{dotted.name}
  3691. which is used to set up the CPU support.
  3692. The chip-specific configuration file will normally configure its CPU(s)
  3693. right after it adds all of the chip's TAPs to the scan chain.
  3694. Although you can set up a target in one step, it's often clearer if you
  3695. use shorter commands and do it in two steps: create it, then configure
  3696. optional parts.
  3697. All operations on the target after it's created will use a new
  3698. command, created as part of target creation.
  3699. The two main things to configure after target creation are
  3700. a work area, which usually has target-specific defaults even
  3701. if the board setup code overrides them later;
  3702. and event handlers (@pxref{targetevents,,Target Events}), which tend
  3703. to be much more board-specific.
  3704. The key steps you use might look something like this
  3705. @example
  3706. dap create mychip.dap -chain-position mychip.cpu
  3707. target create MyTarget cortex_m -dap mychip.dap
  3708. MyTarget configure -work-area-phys 0x08000 -work-area-size 8096
  3709. MyTarget configure -event reset-deassert-pre @{ jtag_rclk 5 @}
  3710. MyTarget configure -event reset-init @{ myboard_reinit @}
  3711. @end example
  3712. You should specify a working area if you can; typically it uses some
  3713. on-chip SRAM.
  3714. Such a working area can speed up many things, including bulk
  3715. writes to target memory;
  3716. flash operations like checking to see if memory needs to be erased;
  3717. GDB memory checksumming;
  3718. and more.
  3719. @quotation Warning
  3720. On more complex chips, the work area can become
  3721. inaccessible when application code
  3722. (such as an operating system)
  3723. enables or disables the MMU.
  3724. For example, the particular MMU context used to access the virtual
  3725. address will probably matter ... and that context might not have
  3726. easy access to other addresses needed.
  3727. At this writing, OpenOCD doesn't have much MMU intelligence.
  3728. @end quotation
  3729. It's often very useful to define a @code{reset-init} event handler.
  3730. For systems that are normally used with a boot loader,
  3731. common tasks include updating clocks and initializing memory
  3732. controllers.
  3733. That may be needed to let you write the boot loader into flash,
  3734. in order to ``de-brick'' your board; or to load programs into
  3735. external DDR memory without having run the boot loader.
  3736. @deffn Command {target create} target_name type configparams...
  3737. This command creates a GDB debug target that refers to a specific JTAG tap.
  3738. It enters that target into a list, and creates a new
  3739. command (@command{@var{target_name}}) which is used for various
  3740. purposes including additional configuration.
  3741. @itemize @bullet
  3742. @item @var{target_name} ... is the name of the debug target.
  3743. By convention this should be the same as the @emph{dotted.name}
  3744. of the TAP associated with this target, which must be specified here
  3745. using the @code{-chain-position @var{dotted.name}} configparam.
  3746. This name is also used to create the target object command,
  3747. referred to here as @command{$target_name},
  3748. and in other places the target needs to be identified.
  3749. @item @var{type} ... specifies the target type. @xref{targettypes,,target types}.
  3750. @item @var{configparams} ... all parameters accepted by
  3751. @command{$target_name configure} are permitted.
  3752. If the target is big-endian, set it here with @code{-endian big}.
  3753. You @emph{must} set the @code{-chain-position @var{dotted.name}} or
  3754. @code{-dap @var{dap_name}} here.
  3755. @end itemize
  3756. @end deffn
  3757. @deffn Command {$target_name configure} configparams...
  3758. The options accepted by this command may also be
  3759. specified as parameters to @command{target create}.
  3760. Their values can later be queried one at a time by
  3761. using the @command{$target_name cget} command.
  3762. @emph{Warning:} changing some of these after setup is dangerous.
  3763. For example, moving a target from one TAP to another;
  3764. and changing its endianness.
  3765. @itemize @bullet
  3766. @item @code{-chain-position} @var{dotted.name} -- names the TAP
  3767. used to access this target.
  3768. @item @code{-dap} @var{dap_name} -- names the DAP used to access
  3769. this target. @xref{dapdeclaration,,DAP declaration}, on how to
  3770. create and manage DAP instances.
  3771. @item @code{-endian} (@option{big}|@option{little}) -- specifies
  3772. whether the CPU uses big or little endian conventions
  3773. @item @code{-event} @var{event_name} @var{event_body} --
  3774. @xref{targetevents,,Target Events}.
  3775. Note that this updates a list of named event handlers.
  3776. Calling this twice with two different event names assigns
  3777. two different handlers, but calling it twice with the
  3778. same event name assigns only one handler.
  3779. Current target is temporarily overridden to the event issuing target
  3780. before handler code starts and switched back after handler is done.
  3781. @item @code{-work-area-backup} (@option{0}|@option{1}) -- says
  3782. whether the work area gets backed up; by default,
  3783. @emph{it is not backed up.}
  3784. When possible, use a working_area that doesn't need to be backed up,
  3785. since performing a backup slows down operations.
  3786. For example, the beginning of an SRAM block is likely to
  3787. be used by most build systems, but the end is often unused.
  3788. @item @code{-work-area-size} @var{size} -- specify work are size,
  3789. in bytes. The same size applies regardless of whether its physical
  3790. or virtual address is being used.
  3791. @item @code{-work-area-phys} @var{address} -- set the work area
  3792. base @var{address} to be used when no MMU is active.
  3793. @item @code{-work-area-virt} @var{address} -- set the work area
  3794. base @var{address} to be used when an MMU is active.
  3795. @emph{Do not specify a value for this except on targets with an MMU.}
  3796. The value should normally correspond to a static mapping for the
  3797. @code{-work-area-phys} address, set up by the current operating system.
  3798. @anchor{rtostype}
  3799. @item @code{-rtos} @var{rtos_type} -- enable rtos support for target,
  3800. @var{rtos_type} can be one of @option{auto}, @option{eCos},
  3801. @option{ThreadX}, @option{FreeRTOS}, @option{linux}, @option{ChibiOS},
  3802. @option{embKernel}, @option{mqx}, @option{uCOS-III}, @option{nuttx}
  3803. @xref{gdbrtossupport,,RTOS Support}.
  3804. @item @code{-defer-examine} -- skip target examination at initial JTAG chain
  3805. scan and after a reset. A manual call to arp_examine is required to
  3806. access the target for debugging.
  3807. @item @code{-ap-num} @var{ap_number} -- set DAP access port for target,
  3808. @var{ap_number} is the numeric index of the DAP AP the target is connected to.
  3809. Use this option with systems where multiple, independent cores are connected
  3810. to separate access ports of the same DAP.
  3811. @item @code{-cti} @var{cti_name} -- set Cross-Trigger Interface (CTI) connected
  3812. to the target. Currently, only the @code{aarch64} target makes use of this option,
  3813. where it is a mandatory configuration for the target run control.
  3814. @xref{armcrosstrigger,,ARM Cross-Trigger Interface},
  3815. for instruction on how to declare and control a CTI instance.
  3816. @anchor{gdbportoverride}
  3817. @item @code{-gdb-port} @var{number} -- see command @command{gdb_port} for the
  3818. possible values of the parameter @var{number}, which are not only numeric values.
  3819. Use this option to override, for this target only, the global parameter set with
  3820. command @command{gdb_port}.
  3821. @xref{gdb_port,,command gdb_port}.
  3822. @end itemize
  3823. @end deffn
  3824. @section Other $target_name Commands
  3825. @cindex object command
  3826. The Tcl/Tk language has the concept of object commands,
  3827. and OpenOCD adopts that same model for targets.
  3828. A good Tk example is a on screen button.
  3829. Once a button is created a button
  3830. has a name (a path in Tk terms) and that name is useable as a first
  3831. class command. For example in Tk, one can create a button and later
  3832. configure it like this:
  3833. @example
  3834. # Create
  3835. button .foobar -background red -command @{ foo @}
  3836. # Modify
  3837. .foobar configure -foreground blue
  3838. # Query
  3839. set x [.foobar cget -background]
  3840. # Report
  3841. puts [format "The button is %s" $x]
  3842. @end example
  3843. In OpenOCD's terms, the ``target'' is an object just like a Tcl/Tk
  3844. button, and its object commands are invoked the same way.
  3845. @example
  3846. str912.cpu mww 0x1234 0x42
  3847. omap3530.cpu mww 0x5555 123
  3848. @end example
  3849. The commands supported by OpenOCD target objects are:
  3850. @deffn Command {$target_name arp_examine} @option{allow-defer}
  3851. @deffnx Command {$target_name arp_halt}
  3852. @deffnx Command {$target_name arp_poll}
  3853. @deffnx Command {$target_name arp_reset}
  3854. @deffnx Command {$target_name arp_waitstate}
  3855. Internal OpenOCD scripts (most notably @file{startup.tcl})
  3856. use these to deal with specific reset cases.
  3857. They are not otherwise documented here.
  3858. @end deffn
  3859. @deffn Command {$target_name array2mem} arrayname width address count
  3860. @deffnx Command {$target_name mem2array} arrayname width address count
  3861. These provide an efficient script-oriented interface to memory.
  3862. The @code{array2mem} primitive writes bytes, halfwords, or words;
  3863. while @code{mem2array} reads them.
  3864. In both cases, the TCL side uses an array, and
  3865. the target side uses raw memory.
  3866. The efficiency comes from enabling the use of
  3867. bulk JTAG data transfer operations.
  3868. The script orientation comes from working with data
  3869. values that are packaged for use by TCL scripts;
  3870. @command{mdw} type primitives only print data they retrieve,
  3871. and neither store nor return those values.
  3872. @itemize
  3873. @item @var{arrayname} ... is the name of an array variable
  3874. @item @var{width} ... is 8/16/32 - indicating the memory access size
  3875. @item @var{address} ... is the target memory address
  3876. @item @var{count} ... is the number of elements to process
  3877. @end itemize
  3878. @end deffn
  3879. @deffn Command {$target_name cget} queryparm
  3880. Each configuration parameter accepted by
  3881. @command{$target_name configure}
  3882. can be individually queried, to return its current value.
  3883. The @var{queryparm} is a parameter name
  3884. accepted by that command, such as @code{-work-area-phys}.
  3885. There are a few special cases:
  3886. @itemize @bullet
  3887. @item @code{-event} @var{event_name} -- returns the handler for the
  3888. event named @var{event_name}.
  3889. This is a special case because setting a handler requires
  3890. two parameters.
  3891. @item @code{-type} -- returns the target type.
  3892. This is a special case because this is set using
  3893. @command{target create} and can't be changed
  3894. using @command{$target_name configure}.
  3895. @end itemize
  3896. For example, if you wanted to summarize information about
  3897. all the targets you might use something like this:
  3898. @example
  3899. foreach name [target names] @{
  3900. set y [$name cget -endian]
  3901. set z [$name cget -type]
  3902. puts [format "Chip %d is %s, Endian: %s, type: %s" \
  3903. $x $name $y $z]
  3904. @}
  3905. @end example
  3906. @end deffn
  3907. @anchor{targetcurstate}
  3908. @deffn Command {$target_name curstate}
  3909. Displays the current target state:
  3910. @code{debug-running},
  3911. @code{halted},
  3912. @code{reset},
  3913. @code{running}, or @code{unknown}.
  3914. (Also, @pxref{eventpolling,,Event Polling}.)
  3915. @end deffn
  3916. @deffn Command {$target_name eventlist}
  3917. Displays a table listing all event handlers
  3918. currently associated with this target.
  3919. @xref{targetevents,,Target Events}.
  3920. @end deffn
  3921. @deffn Command {$target_name invoke-event} event_name
  3922. Invokes the handler for the event named @var{event_name}.
  3923. (This is primarily intended for use by OpenOCD framework
  3924. code, for example by the reset code in @file{startup.tcl}.)
  3925. @end deffn
  3926. @deffn Command {$target_name mdd} [phys] addr [count]
  3927. @deffnx Command {$target_name mdw} [phys] addr [count]
  3928. @deffnx Command {$target_name mdh} [phys] addr [count]
  3929. @deffnx Command {$target_name mdb} [phys] addr [count]
  3930. Display contents of address @var{addr}, as
  3931. 64-bit doublewords (@command{mdd}),
  3932. 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
  3933. or 8-bit bytes (@command{mdb}).
  3934. When the current target has an MMU which is present and active,
  3935. @var{addr} is interpreted as a virtual address.
  3936. Otherwise, or if the optional @var{phys} flag is specified,
  3937. @var{addr} is interpreted as a physical address.
  3938. If @var{count} is specified, displays that many units.
  3939. (If you want to manipulate the data instead of displaying it,
  3940. see the @code{mem2array} primitives.)
  3941. @end deffn
  3942. @deffn Command {$target_name mwd} [phys] addr doubleword [count]
  3943. @deffnx Command {$target_name mww} [phys] addr word [count]
  3944. @deffnx Command {$target_name mwh} [phys] addr halfword [count]
  3945. @deffnx Command {$target_name mwb} [phys] addr byte [count]
  3946. Writes the specified @var{doubleword} (64 bits), @var{word} (32 bits),
  3947. @var{halfword} (16 bits), or @var{byte} (8-bit) value,
  3948. at the specified address @var{addr}.
  3949. When the current target has an MMU which is present and active,
  3950. @var{addr} is interpreted as a virtual address.
  3951. Otherwise, or if the optional @var{phys} flag is specified,
  3952. @var{addr} is interpreted as a physical address.
  3953. If @var{count} is specified, fills that many units of consecutive address.
  3954. @end deffn
  3955. @anchor{targetevents}
  3956. @section Target Events
  3957. @cindex target events
  3958. @cindex events
  3959. At various times, certain things can happen, or you want them to happen.
  3960. For example:
  3961. @itemize @bullet
  3962. @item What should happen when GDB connects? Should your target reset?
  3963. @item When GDB tries to flash the target, do you need to enable the flash via a special command?
  3964. @item Is using SRST appropriate (and possible) on your system?
  3965. Or instead of that, do you need to issue JTAG commands to trigger reset?
  3966. SRST usually resets everything on the scan chain, which can be inappropriate.
  3967. @item During reset, do you need to write to certain memory locations
  3968. to set up system clocks or
  3969. to reconfigure the SDRAM?
  3970. How about configuring the watchdog timer, or other peripherals,
  3971. to stop running while you hold the core stopped for debugging?
  3972. @end itemize
  3973. All of the above items can be addressed by target event handlers.
  3974. These are set up by @command{$target_name configure -event} or
  3975. @command{target create ... -event}.
  3976. The programmer's model matches the @code{-command} option used in Tcl/Tk
  3977. buttons and events. The two examples below act the same, but one creates
  3978. and invokes a small procedure while the other inlines it.
  3979. @example
  3980. proc my_init_proc @{ @} @{
  3981. echo "Disabling watchdog..."
  3982. mww 0xfffffd44 0x00008000
  3983. @}
  3984. mychip.cpu configure -event reset-init my_init_proc
  3985. mychip.cpu configure -event reset-init @{
  3986. echo "Disabling watchdog..."
  3987. mww 0xfffffd44 0x00008000
  3988. @}
  3989. @end example
  3990. The following target events are defined:
  3991. @itemize @bullet
  3992. @item @b{debug-halted}
  3993. @* The target has halted for debug reasons (i.e.: breakpoint)
  3994. @item @b{debug-resumed}
  3995. @* The target has resumed (i.e.: GDB said run)
  3996. @item @b{early-halted}
  3997. @* Occurs early in the halt process
  3998. @item @b{examine-start}
  3999. @* Before target examine is called.
  4000. @item @b{examine-end}
  4001. @* After target examine is called with no errors.
  4002. @item @b{gdb-attach}
  4003. @* When GDB connects. Issued before any GDB communication with the target
  4004. starts. GDB expects the target is halted during attachment.
  4005. @xref{gdbmeminspect,,GDB as a non-intrusive memory inspector}, how to
  4006. connect GDB to running target.
  4007. The event can be also used to set up the target so it is possible to probe flash.
  4008. Probing flash is necessary during GDB connect if you want to use
  4009. @pxref{programmingusinggdb,,programming using GDB}.
  4010. Another use of the flash memory map is for GDB to automatically choose
  4011. hardware or software breakpoints depending on whether the breakpoint
  4012. is in RAM or read only memory.
  4013. Default is @code{halt}
  4014. @item @b{gdb-detach}
  4015. @* When GDB disconnects
  4016. @item @b{gdb-end}
  4017. @* When the target has halted and GDB is not doing anything (see early halt)
  4018. @item @b{gdb-flash-erase-start}
  4019. @* Before the GDB flash process tries to erase the flash (default is
  4020. @code{reset init})
  4021. @item @b{gdb-flash-erase-end}
  4022. @* After the GDB flash process has finished erasing the flash
  4023. @item @b{gdb-flash-write-start}
  4024. @* Before GDB writes to the flash
  4025. @item @b{gdb-flash-write-end}
  4026. @* After GDB writes to the flash (default is @code{reset halt})
  4027. @item @b{gdb-start}
  4028. @* Before the target steps, GDB is trying to start/resume the target
  4029. @item @b{halted}
  4030. @* The target has halted
  4031. @item @b{reset-assert-pre}
  4032. @* Issued as part of @command{reset} processing
  4033. after @command{reset-start} was triggered
  4034. but before either SRST alone is asserted on the scan chain,
  4035. or @code{reset-assert} is triggered.
  4036. @item @b{reset-assert}
  4037. @* Issued as part of @command{reset} processing
  4038. after @command{reset-assert-pre} was triggered.
  4039. When such a handler is present, cores which support this event will use
  4040. it instead of asserting SRST.
  4041. This support is essential for debugging with JTAG interfaces which
  4042. don't include an SRST line (JTAG doesn't require SRST), and for
  4043. selective reset on scan chains that have multiple targets.
  4044. @item @b{reset-assert-post}
  4045. @* Issued as part of @command{reset} processing
  4046. after @code{reset-assert} has been triggered.
  4047. or the target asserted SRST on the entire scan chain.
  4048. @item @b{reset-deassert-pre}
  4049. @* Issued as part of @command{reset} processing
  4050. after @code{reset-assert-post} has been triggered.
  4051. @item @b{reset-deassert-post}
  4052. @* Issued as part of @command{reset} processing
  4053. after @code{reset-deassert-pre} has been triggered
  4054. and (if the target is using it) after SRST has been
  4055. released on the scan chain.
  4056. @item @b{reset-end}
  4057. @* Issued as the final step in @command{reset} processing.
  4058. @item @b{reset-init}
  4059. @* Used by @b{reset init} command for board-specific initialization.
  4060. This event fires after @emph{reset-deassert-post}.
  4061. This is where you would configure PLLs and clocking, set up DRAM so
  4062. you can download programs that don't fit in on-chip SRAM, set up pin
  4063. multiplexing, and so on.
  4064. (You may be able to switch to a fast JTAG clock rate here, after
  4065. the target clocks are fully set up.)
  4066. @item @b{reset-start}
  4067. @* Issued as the first step in @command{reset} processing
  4068. before @command{reset-assert-pre} is called.
  4069. This is the most robust place to use @command{jtag_rclk}
  4070. or @command{adapter speed} to switch to a low JTAG clock rate,
  4071. when reset disables PLLs needed to use a fast clock.
  4072. @item @b{resume-start}
  4073. @* Before any target is resumed
  4074. @item @b{resume-end}
  4075. @* After all targets have resumed
  4076. @item @b{resumed}
  4077. @* Target has resumed
  4078. @item @b{trace-config}
  4079. @* After target hardware trace configuration was changed
  4080. @end itemize
  4081. @node Flash Commands
  4082. @chapter Flash Commands
  4083. OpenOCD has different commands for NOR and NAND flash;
  4084. the ``flash'' command works with NOR flash, while
  4085. the ``nand'' command works with NAND flash.
  4086. This partially reflects different hardware technologies:
  4087. NOR flash usually supports direct CPU instruction and data bus access,
  4088. while data from a NAND flash must be copied to memory before it can be
  4089. used. (SPI flash must also be copied to memory before use.)
  4090. However, the documentation also uses ``flash'' as a generic term;
  4091. for example, ``Put flash configuration in board-specific files''.
  4092. Flash Steps:
  4093. @enumerate
  4094. @item Configure via the command @command{flash bank}
  4095. @* Do this in a board-specific configuration file,
  4096. passing parameters as needed by the driver.
  4097. @item Operate on the flash via @command{flash subcommand}
  4098. @* Often commands to manipulate the flash are typed by a human, or run
  4099. via a script in some automated way. Common tasks include writing a
  4100. boot loader, operating system, or other data.
  4101. @item GDB Flashing
  4102. @* Flashing via GDB requires the flash be configured via ``flash
  4103. bank'', and the GDB flash features be enabled.
  4104. @xref{gdbconfiguration,,GDB Configuration}.
  4105. @end enumerate
  4106. Many CPUs have the ability to ``boot'' from the first flash bank.
  4107. This means that misprogramming that bank can ``brick'' a system,
  4108. so that it can't boot.
  4109. JTAG tools, like OpenOCD, are often then used to ``de-brick'' the
  4110. board by (re)installing working boot firmware.
  4111. @anchor{norconfiguration}
  4112. @section Flash Configuration Commands
  4113. @cindex flash configuration
  4114. @deffn {Config Command} {flash bank} name driver base size chip_width bus_width target [driver_options]
  4115. Configures a flash bank which provides persistent storage
  4116. for addresses from @math{base} to @math{base + size - 1}.
  4117. These banks will often be visible to GDB through the target's memory map.
  4118. In some cases, configuring a flash bank will activate extra commands;
  4119. see the driver-specific documentation.
  4120. @itemize @bullet
  4121. @item @var{name} ... may be used to reference the flash bank
  4122. in other flash commands. A number is also available.
  4123. @item @var{driver} ... identifies the controller driver
  4124. associated with the flash bank being declared.
  4125. This is usually @code{cfi} for external flash, or else
  4126. the name of a microcontroller with embedded flash memory.
  4127. @xref{flashdriverlist,,Flash Driver List}.
  4128. @item @var{base} ... Base address of the flash chip.
  4129. @item @var{size} ... Size of the chip, in bytes.
  4130. For some drivers, this value is detected from the hardware.
  4131. @item @var{chip_width} ... Width of the flash chip, in bytes;
  4132. ignored for most microcontroller drivers.
  4133. @item @var{bus_width} ... Width of the data bus used to access the
  4134. chip, in bytes; ignored for most microcontroller drivers.
  4135. @item @var{target} ... Names the target used to issue
  4136. commands to the flash controller.
  4137. @comment Actually, it's currently a controller-specific parameter...
  4138. @item @var{driver_options} ... drivers may support, or require,
  4139. additional parameters. See the driver-specific documentation
  4140. for more information.
  4141. @end itemize
  4142. @quotation Note
  4143. This command is not available after OpenOCD initialization has completed.
  4144. Use it in board specific configuration files, not interactively.
  4145. @end quotation
  4146. @end deffn
  4147. @comment less confusing would be: "flash list" (like "nand list")
  4148. @deffn Command {flash banks}
  4149. Prints a one-line summary of each device that was
  4150. declared using @command{flash bank}, numbered from zero.
  4151. Note that this is the @emph{plural} form;
  4152. the @emph{singular} form is a very different command.
  4153. @end deffn
  4154. @deffn Command {flash list}
  4155. Retrieves a list of associative arrays for each device that was
  4156. declared using @command{flash bank}, numbered from zero.
  4157. This returned list can be manipulated easily from within scripts.
  4158. @end deffn
  4159. @deffn Command {flash probe} num
  4160. Identify the flash, or validate the parameters of the configured flash. Operation
  4161. depends on the flash type.
  4162. The @var{num} parameter is a value shown by @command{flash banks}.
  4163. Most flash commands will implicitly @emph{autoprobe} the bank;
  4164. flash drivers can distinguish between probing and autoprobing,
  4165. but most don't bother.
  4166. @end deffn
  4167. @section Preparing a Target before Flash Programming
  4168. The target device should be in well defined state before the flash programming
  4169. begins.
  4170. @emph{Always issue} @command{reset init} before @ref{flashprogrammingcommands,,Flash Programming Commands}.
  4171. Do not issue another @command{reset} or @command{reset halt} or @command{resume}
  4172. until the programming session is finished.
  4173. If you use @ref{programmingusinggdb,,Programming using GDB},
  4174. the target is prepared automatically in the event gdb-flash-erase-start
  4175. The jimtcl script @command{program} calls @command{reset init} explicitly.
  4176. @section Erasing, Reading, Writing to Flash
  4177. @cindex flash erasing
  4178. @cindex flash reading
  4179. @cindex flash writing
  4180. @cindex flash programming
  4181. @anchor{flashprogrammingcommands}
  4182. One feature distinguishing NOR flash from NAND or serial flash technologies
  4183. is that for read access, it acts exactly like any other addressable memory.
  4184. This means you can use normal memory read commands like @command{mdw} or
  4185. @command{dump_image} with it, with no special @command{flash} subcommands.
  4186. @xref{memoryaccess,,Memory access}, and @ref{imageaccess,,Image access}.
  4187. Write access works differently. Flash memory normally needs to be erased
  4188. before it's written. Erasing a sector turns all of its bits to ones, and
  4189. writing can turn ones into zeroes. This is why there are special commands
  4190. for interactive erasing and writing, and why GDB needs to know which parts
  4191. of the address space hold NOR flash memory.
  4192. @quotation Note
  4193. Most of these erase and write commands leverage the fact that NOR flash
  4194. chips consume target address space. They implicitly refer to the current
  4195. JTAG target, and map from an address in that target's address space
  4196. back to a flash bank.
  4197. @comment In May 2009, those mappings may fail if any bank associated
  4198. @comment with that target doesn't successfully autoprobe ... bug worth fixing?
  4199. A few commands use abstract addressing based on bank and sector numbers,
  4200. and don't depend on searching the current target and its address space.
  4201. Avoid confusing the two command models.
  4202. @end quotation
  4203. Some flash chips implement software protection against accidental writes,
  4204. since such buggy writes could in some cases ``brick'' a system.
  4205. For such systems, erasing and writing may require sector protection to be
  4206. disabled first.
  4207. Examples include CFI flash such as ``Intel Advanced Bootblock flash'',
  4208. and AT91SAM7 on-chip flash.
  4209. @xref{flashprotect,,flash protect}.
  4210. @deffn Command {flash erase_sector} num first last
  4211. Erase sectors in bank @var{num}, starting at sector @var{first}
  4212. up to and including @var{last}.
  4213. Sector numbering starts at 0.
  4214. Providing a @var{last} sector of @option{last}
  4215. specifies "to the end of the flash bank".
  4216. The @var{num} parameter is a value shown by @command{flash banks}.
  4217. @end deffn
  4218. @deffn Command {flash erase_address} [@option{pad}] [@option{unlock}] address length
  4219. Erase sectors starting at @var{address} for @var{length} bytes.
  4220. Unless @option{pad} is specified, @math{address} must begin a
  4221. flash sector, and @math{address + length - 1} must end a sector.
  4222. Specifying @option{pad} erases extra data at the beginning and/or
  4223. end of the specified region, as needed to erase only full sectors.
  4224. The flash bank to use is inferred from the @var{address}, and
  4225. the specified length must stay within that bank.
  4226. As a special case, when @var{length} is zero and @var{address} is
  4227. the start of the bank, the whole flash is erased.
  4228. If @option{unlock} is specified, then the flash is unprotected
  4229. before erase starts.
  4230. @end deffn
  4231. @deffn Command {flash fillw} address word length
  4232. @deffnx Command {flash fillh} address halfword length
  4233. @deffnx Command {flash fillb} address byte length
  4234. Fills flash memory with the specified @var{word} (32 bits),
  4235. @var{halfword} (16 bits), or @var{byte} (8-bit) pattern,
  4236. starting at @var{address} and continuing
  4237. for @var{length} units (word/halfword/byte).
  4238. No erasure is done before writing; when needed, that must be done
  4239. before issuing this command.
  4240. Writes are done in blocks of up to 1024 bytes, and each write is
  4241. verified by reading back the data and comparing it to what was written.
  4242. The flash bank to use is inferred from the @var{address} of
  4243. each block, and the specified length must stay within that bank.
  4244. @end deffn
  4245. @comment no current checks for errors if fill blocks touch multiple banks!
  4246. @deffn Command {flash write_bank} num filename [offset]
  4247. Write the binary @file{filename} to flash bank @var{num},
  4248. starting at @var{offset} bytes from the beginning of the bank. If @var{offset}
  4249. is omitted, start at the beginning of the flash bank.
  4250. The @var{num} parameter is a value shown by @command{flash banks}.
  4251. @end deffn
  4252. @deffn Command {flash read_bank} num filename [offset [length]]
  4253. Read @var{length} bytes from the flash bank @var{num} starting at @var{offset}
  4254. and write the contents to the binary @file{filename}. If @var{offset} is
  4255. omitted, start at the beginning of the flash bank. If @var{length} is omitted,
  4256. read the remaining bytes from the flash bank.
  4257. The @var{num} parameter is a value shown by @command{flash banks}.
  4258. @end deffn
  4259. @deffn Command {flash verify_bank} num filename [offset]
  4260. Compare the contents of the binary file @var{filename} with the contents of the
  4261. flash bank @var{num} starting at @var{offset}. If @var{offset} is omitted,
  4262. start at the beginning of the flash bank. Fail if the contents do not match.
  4263. The @var{num} parameter is a value shown by @command{flash banks}.
  4264. @end deffn
  4265. @deffn Command {flash write_image} [erase] [unlock] filename [offset] [type]
  4266. Write the image @file{filename} to the current target's flash bank(s).
  4267. Only loadable sections from the image are written.
  4268. A relocation @var{offset} may be specified, in which case it is added
  4269. to the base address for each section in the image.
  4270. The file [@var{type}] can be specified
  4271. explicitly as @option{bin} (binary), @option{ihex} (Intel hex),
  4272. @option{elf} (ELF file), @option{s19} (Motorola s19).
  4273. @option{mem}, or @option{builder}.
  4274. The relevant flash sectors will be erased prior to programming
  4275. if the @option{erase} parameter is given. If @option{unlock} is
  4276. provided, then the flash banks are unlocked before erase and
  4277. program. The flash bank to use is inferred from the address of
  4278. each image section.
  4279. @quotation Warning
  4280. Be careful using the @option{erase} flag when the flash is holding
  4281. data you want to preserve.
  4282. Portions of the flash outside those described in the image's
  4283. sections might be erased with no notice.
  4284. @itemize
  4285. @item
  4286. When a section of the image being written does not fill out all the
  4287. sectors it uses, the unwritten parts of those sectors are necessarily
  4288. also erased, because sectors can't be partially erased.
  4289. @item
  4290. Data stored in sector "holes" between image sections are also affected.
  4291. For example, "@command{flash write_image erase ...}" of an image with
  4292. one byte at the beginning of a flash bank and one byte at the end
  4293. erases the entire bank -- not just the two sectors being written.
  4294. @end itemize
  4295. Also, when flash protection is important, you must re-apply it after
  4296. it has been removed by the @option{unlock} flag.
  4297. @end quotation
  4298. @end deffn
  4299. @section Other Flash commands
  4300. @cindex flash protection
  4301. @deffn Command {flash erase_check} num
  4302. Check erase state of sectors in flash bank @var{num},
  4303. and display that status.
  4304. The @var{num} parameter is a value shown by @command{flash banks}.
  4305. @end deffn
  4306. @deffn Command {flash info} num [sectors]
  4307. Print info about flash bank @var{num}, a list of protection blocks
  4308. and their status. Use @option{sectors} to show a list of sectors instead.
  4309. The @var{num} parameter is a value shown by @command{flash banks}.
  4310. This command will first query the hardware, it does not print cached
  4311. and possibly stale information.
  4312. @end deffn
  4313. @anchor{flashprotect}
  4314. @deffn Command {flash protect} num first last (@option{on}|@option{off})
  4315. Enable (@option{on}) or disable (@option{off}) protection of flash blocks
  4316. in flash bank @var{num}, starting at protection block @var{first}
  4317. and continuing up to and including @var{last}.
  4318. Providing a @var{last} block of @option{last}
  4319. specifies "to the end of the flash bank".
  4320. The @var{num} parameter is a value shown by @command{flash banks}.
  4321. The protection block is usually identical to a flash sector.
  4322. Some devices may utilize a protection block distinct from flash sector.
  4323. See @command{flash info} for a list of protection blocks.
  4324. @end deffn
  4325. @deffn Command {flash padded_value} num value
  4326. Sets the default value used for padding any image sections, This should
  4327. normally match the flash bank erased value. If not specified by this
  4328. command or the flash driver then it defaults to 0xff.
  4329. @end deffn
  4330. @anchor{program}
  4331. @deffn Command {program} filename [preverify] [verify] [reset] [exit] [offset]
  4332. This is a helper script that simplifies using OpenOCD as a standalone
  4333. programmer. The only required parameter is @option{filename}, the others are optional.
  4334. @xref{Flash Programming}.
  4335. @end deffn
  4336. @anchor{flashdriverlist}
  4337. @section Flash Driver List
  4338. As noted above, the @command{flash bank} command requires a driver name,
  4339. and allows driver-specific options and behaviors.
  4340. Some drivers also activate driver-specific commands.
  4341. @deffn {Flash Driver} virtual
  4342. This is a special driver that maps a previously defined bank to another
  4343. address. All bank settings will be copied from the master physical bank.
  4344. The @var{virtual} driver defines one mandatory parameters,
  4345. @itemize
  4346. @item @var{master_bank} The bank that this virtual address refers to.
  4347. @end itemize
  4348. So in the following example addresses 0xbfc00000 and 0x9fc00000 refer to
  4349. the flash bank defined at address 0x1fc00000. Any command executed on
  4350. the virtual banks is actually performed on the physical banks.
  4351. @example
  4352. flash bank $_FLASHNAME pic32mx 0x1fc00000 0 0 0 $_TARGETNAME
  4353. flash bank vbank0 virtual 0xbfc00000 0 0 0 \
  4354. $_TARGETNAME $_FLASHNAME
  4355. flash bank vbank1 virtual 0x9fc00000 0 0 0 \
  4356. $_TARGETNAME $_FLASHNAME
  4357. @end example
  4358. @end deffn
  4359. @subsection External Flash
  4360. @deffn {Flash Driver} cfi
  4361. @cindex Common Flash Interface
  4362. @cindex CFI
  4363. The ``Common Flash Interface'' (CFI) is the main standard for
  4364. external NOR flash chips, each of which connects to a
  4365. specific external chip select on the CPU.
  4366. Frequently the first such chip is used to boot the system.
  4367. Your board's @code{reset-init} handler might need to
  4368. configure additional chip selects using other commands (like: @command{mww} to
  4369. configure a bus and its timings), or
  4370. perhaps configure a GPIO pin that controls the ``write protect'' pin
  4371. on the flash chip.
  4372. The CFI driver can use a target-specific working area to significantly
  4373. speed up operation.
  4374. The CFI driver can accept the following optional parameters, in any order:
  4375. @itemize
  4376. @item @var{jedec_probe} ... is used to detect certain non-CFI flash ROMs,
  4377. like AM29LV010 and similar types.
  4378. @item @var{x16_as_x8} ... when a 16-bit flash is hooked up to an 8-bit bus.
  4379. @item @var{bus_swap} ... when data bytes in a 16-bit flash needs to be swapped.
  4380. @item @var{data_swap} ... when data bytes in a 16-bit flash needs to be
  4381. swapped when writing data values (i.e. not CFI commands).
  4382. @end itemize
  4383. To configure two adjacent banks of 16 MBytes each, both sixteen bits (two bytes)
  4384. wide on a sixteen bit bus:
  4385. @example
  4386. flash bank $_FLASHNAME cfi 0x00000000 0x01000000 2 2 $_TARGETNAME
  4387. flash bank $_FLASHNAME cfi 0x01000000 0x01000000 2 2 $_TARGETNAME
  4388. @end example
  4389. To configure one bank of 32 MBytes
  4390. built from two sixteen bit (two byte) wide parts wired in parallel
  4391. to create a thirty-two bit (four byte) bus with doubled throughput:
  4392. @example
  4393. flash bank $_FLASHNAME cfi 0x00000000 0x02000000 2 4 $_TARGETNAME
  4394. @end example
  4395. @c "cfi part_id" disabled
  4396. @end deffn
  4397. @deffn {Flash Driver} jtagspi
  4398. @cindex Generic JTAG2SPI driver
  4399. @cindex SPI
  4400. @cindex jtagspi
  4401. @cindex bscan_spi
  4402. Several FPGAs and CPLDs can retrieve their configuration (bitstream) from a
  4403. SPI flash connected to them. To access this flash from the host, the device
  4404. is first programmed with a special proxy bitstream that
  4405. exposes the SPI flash on the device's JTAG interface. The flash can then be
  4406. accessed through JTAG.
  4407. Since signaling between JTAG and SPI is compatible, all that is required for
  4408. a proxy bitstream is to connect TDI-MOSI, TDO-MISO, TCK-CLK and activate
  4409. the flash chip select when the JTAG state machine is in SHIFT-DR. Such
  4410. a bitstream for several Xilinx FPGAs can be found in
  4411. @file{contrib/loaders/flash/fpga/xilinx_bscan_spi.py}. It requires
  4412. @uref{https://github.com/m-labs/migen, migen} and a Xilinx toolchain to build.
  4413. This flash bank driver requires a target on a JTAG tap and will access that
  4414. tap directly. Since no support from the target is needed, the target can be a
  4415. "testee" dummy. Since the target does not expose the flash memory
  4416. mapping, target commands that would otherwise be expected to access the flash
  4417. will not work. These include all @command{*_image} and
  4418. @command{$target_name m*} commands as well as @command{program}. Equivalent
  4419. functionality is available through the @command{flash write_bank},
  4420. @command{flash read_bank}, and @command{flash verify_bank} commands.
  4421. @itemize
  4422. @item @var{ir} ... is loaded into the JTAG IR to map the flash as the JTAG DR.
  4423. For the bitstreams generated from @file{xilinx_bscan_spi.py} this is the
  4424. @var{USER1} instruction.
  4425. @end itemize
  4426. @example
  4427. target create $_TARGETNAME testee -chain-position $_CHIPNAME.fpga
  4428. set _XILINX_USER1 0x02
  4429. flash bank $_FLASHNAME spi 0x0 0 0 0 \
  4430. $_TARGETNAME $_XILINX_USER1
  4431. @end example
  4432. @end deffn
  4433. @deffn {Flash Driver} xcf
  4434. @cindex Xilinx Platform flash driver
  4435. @cindex xcf
  4436. Xilinx FPGAs can be configured from specialized flash ICs named Platform Flash.
  4437. It is (almost) regular NOR flash with erase sectors, program pages, etc. The
  4438. only difference is special registers controlling its FPGA specific behavior.
  4439. They must be properly configured for successful FPGA loading using
  4440. additional @var{xcf} driver command:
  4441. @deffn Command {xcf ccb} <bank_id>
  4442. command accepts additional parameters:
  4443. @itemize
  4444. @item @var{external|internal} ... selects clock source.
  4445. @item @var{serial|parallel} ... selects serial or parallel data bus mode.
  4446. @item @var{slave|master} ... selects slave of master mode for flash device.
  4447. @item @var{40|20} ... selects clock frequency in MHz for internal clock
  4448. in master mode.
  4449. @end itemize
  4450. @example
  4451. xcf ccb 0 external parallel slave 40
  4452. @end example
  4453. All of them must be specified even if clock frequency is pointless
  4454. in slave mode. If only bank id specified than command prints current
  4455. CCB register value. Note: there is no need to write this register
  4456. every time you erase/program data sectors because it stores in
  4457. dedicated sector.
  4458. @end deffn
  4459. @deffn Command {xcf configure} <bank_id>
  4460. Initiates FPGA loading procedure. Useful if your board has no "configure"
  4461. button.
  4462. @example
  4463. xcf configure 0
  4464. @end example
  4465. @end deffn
  4466. Additional driver notes:
  4467. @itemize
  4468. @item Only single revision supported.
  4469. @item Driver automatically detects need of bit reverse, but
  4470. only "bin" (raw binary, do not confuse it with "bit") and "mcs"
  4471. (Intel hex) file types supported.
  4472. @item For additional info check xapp972.pdf and ug380.pdf.
  4473. @end itemize
  4474. @end deffn
  4475. @deffn {Flash Driver} lpcspifi
  4476. @cindex NXP SPI Flash Interface
  4477. @cindex SPIFI
  4478. @cindex lpcspifi
  4479. NXP's LPC43xx and LPC18xx families include a proprietary SPI
  4480. Flash Interface (SPIFI) peripheral that can drive and provide
  4481. memory mapped access to external SPI flash devices.
  4482. The lpcspifi driver initializes this interface and provides
  4483. program and erase functionality for these serial flash devices.
  4484. Use of this driver @b{requires} a working area of at least 1kB
  4485. to be configured on the target device; more than this will
  4486. significantly reduce flash programming times.
  4487. The setup command only requires the @var{base} parameter. All
  4488. other parameters are ignored, and the flash size and layout
  4489. are configured by the driver.
  4490. @example
  4491. flash bank $_FLASHNAME lpcspifi 0x14000000 0 0 0 $_TARGETNAME
  4492. @end example
  4493. @end deffn
  4494. @deffn {Flash Driver} stmsmi
  4495. @cindex STMicroelectronics Serial Memory Interface
  4496. @cindex SMI
  4497. @cindex stmsmi
  4498. Some devices from STMicroelectronics (e.g. STR75x MCU family,
  4499. SPEAr MPU family) include a proprietary
  4500. ``Serial Memory Interface'' (SMI) controller able to drive external
  4501. SPI flash devices.
  4502. Depending on specific device and board configuration, up to 4 external
  4503. flash devices can be connected.
  4504. SMI makes the flash content directly accessible in the CPU address
  4505. space; each external device is mapped in a memory bank.
  4506. CPU can directly read data, execute code and boot from SMI banks.
  4507. Normal OpenOCD commands like @command{mdw} can be used to display
  4508. the flash content.
  4509. The setup command only requires the @var{base} parameter in order
  4510. to identify the memory bank.
  4511. All other parameters are ignored. Additional information, like
  4512. flash size, are detected automatically.
  4513. @example
  4514. flash bank $_FLASHNAME stmsmi 0xf8000000 0 0 0 $_TARGETNAME
  4515. @end example
  4516. @end deffn
  4517. @deffn {Flash Driver} mrvlqspi
  4518. This driver supports QSPI flash controller of Marvell's Wireless
  4519. Microcontroller platform.
  4520. The flash size is autodetected based on the table of known JEDEC IDs
  4521. hardcoded in the OpenOCD sources.
  4522. @example
  4523. flash bank $_FLASHNAME mrvlqspi 0x0 0 0 0 $_TARGETNAME 0x46010000
  4524. @end example
  4525. @end deffn
  4526. @deffn {Flash Driver} ath79
  4527. @cindex Atheros ath79 SPI driver
  4528. @cindex ath79
  4529. Members of ATH79 SoC family from Atheros include a SPI interface with 3
  4530. chip selects.
  4531. On reset a SPI flash connected to the first chip select (CS0) is made
  4532. directly read-accessible in the CPU address space (up to 16MBytes)
  4533. and is usually used to store the bootloader and operating system.
  4534. Normal OpenOCD commands like @command{mdw} can be used to display
  4535. the flash content while it is in memory-mapped mode (only the first
  4536. 4MBytes are accessible without additional configuration on reset).
  4537. The setup command only requires the @var{base} parameter in order
  4538. to identify the memory bank. The actual value for the base address
  4539. is not otherwise used by the driver. However the mapping is passed
  4540. to gdb. Thus for the memory mapped flash (chipselect CS0) the base
  4541. address should be the actual memory mapped base address. For unmapped
  4542. chipselects (CS1 and CS2) care should be taken to use a base address
  4543. that does not overlap with real memory regions.
  4544. Additional information, like flash size, are detected automatically.
  4545. An optional additional parameter sets the chipselect for the bank,
  4546. with the default CS0.
  4547. CS1 and CS2 require additional GPIO setup before they can be used
  4548. since the alternate function must be enabled on the GPIO pin
  4549. CS1/CS2 is routed to on the given SoC.
  4550. @example
  4551. flash bank $_FLASHNAME ath79 0xbf000000 0 0 0 $_TARGETNAME
  4552. # When using multiple chipselects the base should be different for each,
  4553. # otherwise the write_image command is not able to distinguish the
  4554. # banks.
  4555. flash bank flash0 ath79 0xbf000000 0 0 0 $_TARGETNAME cs0
  4556. flash bank flash1 ath79 0x10000000 0 0 0 $_TARGETNAME cs1
  4557. flash bank flash2 ath79 0x20000000 0 0 0 $_TARGETNAME cs2
  4558. @end example
  4559. @end deffn
  4560. @deffn {Flash Driver} fespi
  4561. @cindex Freedom E SPI
  4562. @cindex fespi
  4563. SiFive's Freedom E SPI controller, used in HiFive and other boards.
  4564. @example
  4565. flash bank $_FLASHNAME fespi 0x20000000 0 0 0 $_TARGETNAME
  4566. @end example
  4567. @end deffn
  4568. @subsection Internal Flash (Microcontrollers)
  4569. @deffn {Flash Driver} aduc702x
  4570. The ADUC702x analog microcontrollers from Analog Devices
  4571. include internal flash and use ARM7TDMI cores.
  4572. The aduc702x flash driver works with models ADUC7019 through ADUC7028.
  4573. The setup command only requires the @var{target} argument
  4574. since all devices in this family have the same memory layout.
  4575. @example
  4576. flash bank $_FLASHNAME aduc702x 0 0 0 0 $_TARGETNAME
  4577. @end example
  4578. @end deffn
  4579. @deffn {Flash Driver} ambiqmicro
  4580. @cindex ambiqmicro
  4581. @cindex apollo
  4582. All members of the Apollo microcontroller family from
  4583. Ambiq Micro include internal flash and use ARM's Cortex-M4 core.
  4584. The host connects over USB to an FTDI interface that communicates
  4585. with the target using SWD.
  4586. The @var{ambiqmicro} driver reads the Chip Information Register detect
  4587. the device class of the MCU.
  4588. The Flash and SRAM sizes directly follow device class, and are used
  4589. to set up the flash banks.
  4590. If this fails, the driver will use default values set to the minimum
  4591. sizes of an Apollo chip.
  4592. All Apollo chips have two flash banks of the same size.
  4593. In all cases the first flash bank starts at location 0,
  4594. and the second bank starts after the first.
  4595. @example
  4596. # Flash bank 0
  4597. flash bank $_FLASHNAME ambiqmicro 0 0x00040000 0 0 $_TARGETNAME
  4598. # Flash bank 1 - same size as bank0, starts after bank 0.
  4599. flash bank $_FLASHNAME ambiqmicro 0x00040000 0x00040000 0 0 \
  4600. $_TARGETNAME
  4601. @end example
  4602. Flash is programmed using custom entry points into the bootloader.
  4603. This is the only way to program the flash as no flash control registers
  4604. are available to the user.
  4605. The @var{ambiqmicro} driver adds some additional commands:
  4606. @deffn Command {ambiqmicro mass_erase} <bank>
  4607. Erase entire bank.
  4608. @end deffn
  4609. @deffn Command {ambiqmicro page_erase} <bank> <first> <last>
  4610. Erase device pages.
  4611. @end deffn
  4612. @deffn Command {ambiqmicro program_otp} <bank> <offset> <count>
  4613. Program OTP is a one time operation to create write protected flash.
  4614. The user writes sectors to SRAM starting at 0x10000010.
  4615. Program OTP will write these sectors from SRAM to flash, and write protect
  4616. the flash.
  4617. @end deffn
  4618. @end deffn
  4619. @anchor{at91samd}
  4620. @deffn {Flash Driver} at91samd
  4621. @cindex at91samd
  4622. All members of the ATSAM D2x, D1x, D0x, ATSAMR, ATSAML and ATSAMC microcontroller
  4623. families from Atmel include internal flash and use ARM's Cortex-M0+ core.
  4624. Do not use for ATSAM D51 and E5x: use @xref{atsame5}.
  4625. The devices have one flash bank:
  4626. @example
  4627. flash bank $_FLASHNAME at91samd 0x00000000 0 1 1 $_TARGETNAME
  4628. @end example
  4629. @deffn Command {at91samd chip-erase}
  4630. Issues a complete Flash erase via the Device Service Unit (DSU). This can be
  4631. used to erase a chip back to its factory state and does not require the
  4632. processor to be halted.
  4633. @end deffn
  4634. @deffn Command {at91samd set-security}
  4635. Secures the Flash via the Set Security Bit (SSB) command. This prevents access
  4636. to the Flash and can only be undone by using the chip-erase command which
  4637. erases the Flash contents and turns off the security bit. Warning: at this
  4638. time, openocd will not be able to communicate with a secured chip and it is
  4639. therefore not possible to chip-erase it without using another tool.
  4640. @example
  4641. at91samd set-security enable
  4642. @end example
  4643. @end deffn
  4644. @deffn Command {at91samd eeprom}
  4645. Shows or sets the EEPROM emulation size configuration, stored in the User Row
  4646. of the Flash. When setting, the EEPROM size must be specified in bytes and it
  4647. must be one of the permitted sizes according to the datasheet. Settings are
  4648. written immediately but only take effect on MCU reset. EEPROM emulation
  4649. requires additional firmware support and the minimum EEPROM size may not be
  4650. the same as the minimum that the hardware supports. Set the EEPROM size to 0
  4651. in order to disable this feature.
  4652. @example
  4653. at91samd eeprom
  4654. at91samd eeprom 1024
  4655. @end example
  4656. @end deffn
  4657. @deffn Command {at91samd bootloader}
  4658. Shows or sets the bootloader size configuration, stored in the User Row of the
  4659. Flash. This is called the BOOTPROT region. When setting, the bootloader size
  4660. must be specified in bytes and it must be one of the permitted sizes according
  4661. to the datasheet. Settings are written immediately but only take effect on
  4662. MCU reset. Setting the bootloader size to 0 disables bootloader protection.
  4663. @example
  4664. at91samd bootloader
  4665. at91samd bootloader 16384
  4666. @end example
  4667. @end deffn
  4668. @deffn Command {at91samd dsu_reset_deassert}
  4669. This command releases internal reset held by DSU
  4670. and prepares reset vector catch in case of reset halt.
  4671. Command is used internally in event event reset-deassert-post.
  4672. @end deffn
  4673. @deffn Command {at91samd nvmuserrow}
  4674. Writes or reads the entire 64 bit wide NVM user row register which is located at
  4675. 0x804000. This register includes various fuses lock-bits and factory calibration
  4676. data. Reading the register is done by invoking this command without any
  4677. arguments. Writing is possible by giving 1 or 2 hex values. The first argument
  4678. is the register value to be written and the second one is an optional changemask.
  4679. Every bit which value in changemask is 0 will stay unchanged. The lock- and
  4680. reserved-bits are masked out and cannot be changed.
  4681. @example
  4682. # Read user row
  4683. >at91samd nvmuserrow
  4684. NVMUSERROW: 0xFFFFFC5DD8E0C788
  4685. # Write 0xFFFFFC5DD8E0C788 to user row
  4686. >at91samd nvmuserrow 0xFFFFFC5DD8E0C788
  4687. # Write 0x12300 to user row but leave other bits and low byte unchanged
  4688. >at91samd nvmuserrow 0x12345 0xFFF00
  4689. @end example
  4690. @end deffn
  4691. @end deffn
  4692. @anchor{at91sam3}
  4693. @deffn {Flash Driver} at91sam3
  4694. @cindex at91sam3
  4695. All members of the AT91SAM3 microcontroller family from
  4696. Atmel include internal flash and use ARM's Cortex-M3 core. The driver
  4697. currently (6/22/09) recognizes the AT91SAM3U[1/2/4][C/E] chips. Note
  4698. that the driver was orginaly developed and tested using the
  4699. AT91SAM3U4E, using a SAM3U-EK eval board. Support for other chips in
  4700. the family was cribbed from the data sheet. @emph{Note to future
  4701. readers/updaters: Please remove this worrisome comment after other
  4702. chips are confirmed.}
  4703. The AT91SAM3U4[E/C] (256K) chips have two flash banks; most other chips
  4704. have one flash bank. In all cases the flash banks are at
  4705. the following fixed locations:
  4706. @example
  4707. # Flash bank 0 - all chips
  4708. flash bank $_FLASHNAME at91sam3 0x00080000 0 1 1 $_TARGETNAME
  4709. # Flash bank 1 - only 256K chips
  4710. flash bank $_FLASHNAME at91sam3 0x00100000 0 1 1 $_TARGETNAME
  4711. @end example
  4712. Internally, the AT91SAM3 flash memory is organized as follows.
  4713. Unlike the AT91SAM7 chips, these are not used as parameters
  4714. to the @command{flash bank} command:
  4715. @itemize
  4716. @item @emph{N-Banks:} 256K chips have 2 banks, others have 1 bank.
  4717. @item @emph{Bank Size:} 128K/64K Per flash bank
  4718. @item @emph{Sectors:} 16 or 8 per bank
  4719. @item @emph{SectorSize:} 8K Per Sector
  4720. @item @emph{PageSize:} 256 bytes per page. Note that OpenOCD operates on 'sector' sizes, not page sizes.
  4721. @end itemize
  4722. The AT91SAM3 driver adds some additional commands:
  4723. @deffn Command {at91sam3 gpnvm}
  4724. @deffnx Command {at91sam3 gpnvm clear} number
  4725. @deffnx Command {at91sam3 gpnvm set} number
  4726. @deffnx Command {at91sam3 gpnvm show} [@option{all}|number]
  4727. With no parameters, @command{show} or @command{show all},
  4728. shows the status of all GPNVM bits.
  4729. With @command{show} @var{number}, displays that bit.
  4730. With @command{set} @var{number} or @command{clear} @var{number},
  4731. modifies that GPNVM bit.
  4732. @end deffn
  4733. @deffn Command {at91sam3 info}
  4734. This command attempts to display information about the AT91SAM3
  4735. chip. @emph{First} it read the @code{CHIPID_CIDR} [address 0x400e0740, see
  4736. Section 28.2.1, page 505 of the AT91SAM3U 29/may/2009 datasheet,
  4737. document id: doc6430A] and decodes the values. @emph{Second} it reads the
  4738. various clock configuration registers and attempts to display how it
  4739. believes the chip is configured. By default, the SLOWCLK is assumed to
  4740. be 32768 Hz, see the command @command{at91sam3 slowclk}.
  4741. @end deffn
  4742. @deffn Command {at91sam3 slowclk} [value]
  4743. This command shows/sets the slow clock frequency used in the
  4744. @command{at91sam3 info} command calculations above.
  4745. @end deffn
  4746. @end deffn
  4747. @deffn {Flash Driver} at91sam4
  4748. @cindex at91sam4
  4749. All members of the AT91SAM4 microcontroller family from
  4750. Atmel include internal flash and use ARM's Cortex-M4 core.
  4751. This driver uses the same command names/syntax as @xref{at91sam3}.
  4752. @end deffn
  4753. @deffn {Flash Driver} at91sam4l
  4754. @cindex at91sam4l
  4755. All members of the AT91SAM4L microcontroller family from
  4756. Atmel include internal flash and use ARM's Cortex-M4 core.
  4757. This driver uses the same command names/syntax as @xref{at91sam3}.
  4758. The AT91SAM4L driver adds some additional commands:
  4759. @deffn Command {at91sam4l smap_reset_deassert}
  4760. This command releases internal reset held by SMAP
  4761. and prepares reset vector catch in case of reset halt.
  4762. Command is used internally in event event reset-deassert-post.
  4763. @end deffn
  4764. @end deffn
  4765. @anchor{atsame5}
  4766. @deffn {Flash Driver} atsame5
  4767. @cindex atsame5
  4768. All members of the SAM E54, E53, E51 and D51 microcontroller
  4769. families from Microchip (former Atmel) include internal flash
  4770. and use ARM's Cortex-M4 core.
  4771. The devices have two ECC flash banks with a swapping feature.
  4772. This driver handles both banks together as it were one.
  4773. Bank swapping is not supported yet.
  4774. @example
  4775. flash bank $_FLASHNAME atsame5 0x00000000 0 1 1 $_TARGETNAME
  4776. @end example
  4777. @deffn Command {atsame5 bootloader}
  4778. Shows or sets the bootloader size configuration, stored in the User Page of the
  4779. Flash. This is called the BOOTPROT region. When setting, the bootloader size
  4780. must be specified in bytes. The nearest bigger protection size is used.
  4781. Settings are written immediately but only take effect on MCU reset.
  4782. Setting the bootloader size to 0 disables bootloader protection.
  4783. @example
  4784. atsame5 bootloader
  4785. atsame5 bootloader 16384
  4786. @end example
  4787. @end deffn
  4788. @deffn Command {atsame5 chip-erase}
  4789. Issues a complete Flash erase via the Device Service Unit (DSU). This can be
  4790. used to erase a chip back to its factory state and does not require the
  4791. processor to be halted.
  4792. @end deffn
  4793. @deffn Command {atsame5 dsu_reset_deassert}
  4794. This command releases internal reset held by DSU
  4795. and prepares reset vector catch in case of reset halt.
  4796. Command is used internally in event event reset-deassert-post.
  4797. @end deffn
  4798. @deffn Command {atsame5 userpage}
  4799. Writes or reads the first 64 bits of NVM User Page which is located at
  4800. 0x804000. This field includes various fuses.
  4801. Reading is done by invoking this command without any arguments.
  4802. Writing is possible by giving 1 or 2 hex values. The first argument
  4803. is the value to be written and the second one is an optional bit mask
  4804. (a zero bit in the mask means the bit stays unchanged).
  4805. The reserved fields are always masked out and cannot be changed.
  4806. @example
  4807. # Read
  4808. >atsame5 userpage
  4809. USER PAGE: 0xAEECFF80FE9A9239
  4810. # Write
  4811. >atsame5 userpage 0xAEECFF80FE9A9239
  4812. # Write 2 to SEESBLK and 4 to SEEPSZ fields but leave other bits unchanged
  4813. # (setup SmartEEPROM of virtual size 8192 bytes)
  4814. >atsame5 userpage 0x4200000000 0x7f00000000
  4815. @end example
  4816. @end deffn
  4817. @end deffn
  4818. @deffn {Flash Driver} atsamv
  4819. @cindex atsamv
  4820. All members of the ATSAMV7x, ATSAMS70, and ATSAME70 families from
  4821. Atmel include internal flash and use ARM's Cortex-M7 core.
  4822. This driver uses the same command names/syntax as @xref{at91sam3}.
  4823. @end deffn
  4824. @deffn {Flash Driver} at91sam7
  4825. All members of the AT91SAM7 microcontroller family from Atmel include
  4826. internal flash and use ARM7TDMI cores. The driver automatically
  4827. recognizes a number of these chips using the chip identification
  4828. register, and autoconfigures itself.
  4829. @example
  4830. flash bank $_FLASHNAME at91sam7 0 0 0 0 $_TARGETNAME
  4831. @end example
  4832. For chips which are not recognized by the controller driver, you must
  4833. provide additional parameters in the following order:
  4834. @itemize
  4835. @item @var{chip_model} ... label used with @command{flash info}
  4836. @item @var{banks}
  4837. @item @var{sectors_per_bank}
  4838. @item @var{pages_per_sector}
  4839. @item @var{pages_size}
  4840. @item @var{num_nvm_bits}
  4841. @item @var{freq_khz} ... required if an external clock is provided,
  4842. optional (but recommended) when the oscillator frequency is known
  4843. @end itemize
  4844. It is recommended that you provide zeroes for all of those values
  4845. except the clock frequency, so that everything except that frequency
  4846. will be autoconfigured.
  4847. Knowing the frequency helps ensure correct timings for flash access.
  4848. The flash controller handles erases automatically on a page (128/256 byte)
  4849. basis, so explicit erase commands are not necessary for flash programming.
  4850. However, there is an ``EraseAll`` command that can erase an entire flash
  4851. plane (of up to 256KB), and it will be used automatically when you issue
  4852. @command{flash erase_sector} or @command{flash erase_address} commands.
  4853. @deffn Command {at91sam7 gpnvm} bitnum (@option{set}|@option{clear})
  4854. Set or clear a ``General Purpose Non-Volatile Memory'' (GPNVM)
  4855. bit for the processor. Each processor has a number of such bits,
  4856. used for controlling features such as brownout detection (so they
  4857. are not truly general purpose).
  4858. @quotation Note
  4859. This assumes that the first flash bank (number 0) is associated with
  4860. the appropriate at91sam7 target.
  4861. @end quotation
  4862. @end deffn
  4863. @end deffn
  4864. @deffn {Flash Driver} avr
  4865. The AVR 8-bit microcontrollers from Atmel integrate flash memory.
  4866. @emph{The current implementation is incomplete.}
  4867. @comment - defines mass_erase ... pointless given flash_erase_address
  4868. @end deffn
  4869. @deffn {Flash Driver} bluenrg-x
  4870. STMicroelectronics BlueNRG-1 and BlueNRG-2 Bluetooth low energy wireless system-on-chip. They include ARM Cortex-M0 core and internal flash memory.
  4871. The driver automatically recognizes these chips using
  4872. the chip identification registers, and autoconfigures itself.
  4873. @example
  4874. flash bank $_FLASHNAME bluenrg-x 0 0 0 0 $_TARGETNAME
  4875. @end example
  4876. Note that when users ask to erase all the sectors of the flash, a mass erase command is used which is faster than erasing
  4877. each single sector one by one.
  4878. @example
  4879. flash erase_sector 0 0 79 # It will perform a mass erase on BlueNRG-1
  4880. @end example
  4881. @example
  4882. flash erase_sector 0 0 127 # It will perform a mass erase on BlueNRG-2
  4883. @end example
  4884. Triggering a mass erase is also useful when users want to disable readout protection.
  4885. @end deffn
  4886. @deffn {Flash Driver} cc26xx
  4887. All versions of the SimpleLink CC13xx and CC26xx microcontrollers from Texas
  4888. Instruments include internal flash. The cc26xx flash driver supports both the
  4889. CC13xx and CC26xx family of devices. The driver automatically recognizes the
  4890. specific version's flash parameters and autoconfigures itself. The flash bank
  4891. starts at address 0.
  4892. @example
  4893. flash bank $_FLASHNAME cc26xx 0 0 0 0 $_TARGETNAME
  4894. @end example
  4895. @end deffn
  4896. @deffn {Flash Driver} cc3220sf
  4897. The CC3220SF version of the SimpleLink CC32xx microcontrollers from Texas
  4898. Instruments includes 1MB of internal flash. The cc3220sf flash driver only
  4899. supports the internal flash. The serial flash on SimpleLink boards is
  4900. programmed via the bootloader over a UART connection. Security features of
  4901. the CC3220SF may erase the internal flash during power on reset. Refer to
  4902. documentation at @url{www.ti.com/cc3220sf} for details on security features
  4903. and programming the serial flash.
  4904. @example
  4905. flash bank $_FLASHNAME cc3220sf 0 0 0 0 $_TARGETNAME
  4906. @end example
  4907. @end deffn
  4908. @deffn {Flash Driver} efm32
  4909. All members of the EFM32 microcontroller family from Energy Micro include
  4910. internal flash and use ARM Cortex-M3 cores. The driver automatically recognizes
  4911. a number of these chips using the chip identification register, and
  4912. autoconfigures itself.
  4913. @example
  4914. flash bank $_FLASHNAME efm32 0 0 0 0 $_TARGETNAME
  4915. @end example
  4916. A special feature of efm32 controllers is that it is possible to completely disable the
  4917. debug interface by writing the correct values to the 'Debug Lock Word'. OpenOCD supports
  4918. this via the following command:
  4919. @example
  4920. efm32 debuglock num
  4921. @end example
  4922. The @var{num} parameter is a value shown by @command{flash banks}.
  4923. Note that in order for this command to take effect, the target needs to be reset.
  4924. @emph{The current implementation is incomplete. Unprotecting flash pages is not
  4925. supported.}
  4926. @end deffn
  4927. @deffn {Flash Driver} esirisc
  4928. Members of the eSi-RISC family may optionally include internal flash programmed
  4929. via the eSi-TSMC Flash interface. Additional parameters are required to
  4930. configure the driver: @option{cfg_address} is the base address of the
  4931. configuration register interface, @option{clock_hz} is the expected clock
  4932. frequency, and @option{wait_states} is the number of configured read wait states.
  4933. @example
  4934. flash bank $_FLASHNAME esirisc base_address size_bytes 0 0 \
  4935. $_TARGETNAME cfg_address clock_hz wait_states
  4936. @end example
  4937. @deffn Command {esirisc flash mass_erase} bank_id
  4938. Erase all pages in data memory for the bank identified by @option{bank_id}.
  4939. @end deffn
  4940. @deffn Command {esirisc flash ref_erase} bank_id
  4941. Erase the reference cell for the bank identified by @option{bank_id}. @emph{This
  4942. is an uncommon operation.}
  4943. @end deffn
  4944. @end deffn
  4945. @deffn {Flash Driver} fm3
  4946. All members of the FM3 microcontroller family from Fujitsu
  4947. include internal flash and use ARM Cortex-M3 cores.
  4948. The @var{fm3} driver uses the @var{target} parameter to select the
  4949. correct bank config, it can currently be one of the following:
  4950. @code{mb9bfxx1.cpu}, @code{mb9bfxx2.cpu}, @code{mb9bfxx3.cpu},
  4951. @code{mb9bfxx4.cpu}, @code{mb9bfxx5.cpu} or @code{mb9bfxx6.cpu}.
  4952. @example
  4953. flash bank $_FLASHNAME fm3 0 0 0 0 $_TARGETNAME
  4954. @end example
  4955. @end deffn
  4956. @deffn {Flash Driver} fm4
  4957. All members of the FM4 microcontroller family from Spansion (formerly Fujitsu)
  4958. include internal flash and use ARM Cortex-M4 cores.
  4959. The @var{fm4} driver uses a @var{family} parameter to select the
  4960. correct bank config, it can currently be one of the following:
  4961. @code{MB9BFx64}, @code{MB9BFx65}, @code{MB9BFx66}, @code{MB9BFx67}, @code{MB9BFx68},
  4962. @code{S6E2Cx8}, @code{S6E2Cx9}, @code{S6E2CxA} or @code{S6E2Dx},
  4963. with @code{x} treated as wildcard and otherwise case (and any trailing
  4964. characters) ignored.
  4965. @example
  4966. flash bank $@{_FLASHNAME@}0 fm4 0x00000000 0 0 0 \
  4967. $_TARGETNAME S6E2CCAJ0A
  4968. flash bank $@{_FLASHNAME@}1 fm4 0x00100000 0 0 0 \
  4969. $_TARGETNAME S6E2CCAJ0A
  4970. @end example
  4971. @emph{The current implementation is incomplete. Protection is not supported,
  4972. nor is Chip Erase (only Sector Erase is implemented).}
  4973. @end deffn
  4974. @deffn {Flash Driver} kinetis
  4975. @cindex kinetis
  4976. Kx, KLx, KVx and KE1x members of the Kinetis microcontroller family
  4977. from NXP (former Freescale) include
  4978. internal flash and use ARM Cortex-M0+ or M4 cores. The driver automatically
  4979. recognizes flash size and a number of flash banks (1-4) using the chip
  4980. identification register, and autoconfigures itself.
  4981. Use kinetis_ke driver for KE0x and KEAx devices.
  4982. The @var{kinetis} driver defines option:
  4983. @itemize
  4984. @item -sim-base @var{addr} ... base of System Integration Module where chip identification resides. Driver tries two known locations if option is omitted.
  4985. @end itemize
  4986. @example
  4987. flash bank $_FLASHNAME kinetis 0 0 0 0 $_TARGETNAME
  4988. @end example
  4989. @deffn Command {kinetis create_banks}
  4990. Configuration command enables automatic creation of additional flash banks
  4991. based on real flash layout of device. Banks are created during device probe.
  4992. Use 'flash probe 0' to force probe.
  4993. @end deffn
  4994. @deffn Command {kinetis fcf_source} [protection|write]
  4995. Select what source is used when writing to a Flash Configuration Field.
  4996. @option{protection} mode builds FCF content from protection bits previously
  4997. set by 'flash protect' command.
  4998. This mode is default. MCU is protected from unwanted locking by immediate
  4999. writing FCF after erase of relevant sector.
  5000. @option{write} mode enables direct write to FCF.
  5001. Protection cannot be set by 'flash protect' command. FCF is written along
  5002. with the rest of a flash image.
  5003. @emph{BEWARE: Incorrect flash configuration may permanently lock the device!}
  5004. @end deffn
  5005. @deffn Command {kinetis fopt} [num]
  5006. Set value to write to FOPT byte of Flash Configuration Field.
  5007. Used in kinetis 'fcf_source protection' mode only.
  5008. @end deffn
  5009. @deffn Command {kinetis mdm check_security}
  5010. Checks status of device security lock. Used internally in examine-end event.
  5011. @end deffn
  5012. @deffn Command {kinetis mdm halt}
  5013. Issues a halt via the MDM-AP. This command can be used to break a watchdog reset
  5014. loop when connecting to an unsecured target.
  5015. @end deffn
  5016. @deffn Command {kinetis mdm mass_erase}
  5017. Issues a complete flash erase via the MDM-AP. This can be used to erase a chip
  5018. back to its factory state, removing security. It does not require the processor
  5019. to be halted, however the target will remain in a halted state after this
  5020. command completes.
  5021. @end deffn
  5022. @deffn Command {kinetis nvm_partition}
  5023. For FlexNVM devices only (KxxDX and KxxFX).
  5024. Command shows or sets data flash or EEPROM backup size in kilobytes,
  5025. sets two EEPROM blocks sizes in bytes and enables/disables loading
  5026. of EEPROM contents to FlexRAM during reset.
  5027. For details see device reference manual, Flash Memory Module,
  5028. Program Partition command.
  5029. Setting is possible only once after mass_erase.
  5030. Reset the device after partition setting.
  5031. Show partition size:
  5032. @example
  5033. kinetis nvm_partition info
  5034. @end example
  5035. Set 32 KB data flash, rest of FlexNVM is EEPROM backup. EEPROM has two blocks
  5036. of 512 and 1536 bytes and its contents is loaded to FlexRAM during reset:
  5037. @example
  5038. kinetis nvm_partition dataflash 32 512 1536 on
  5039. @end example
  5040. Set 16 KB EEPROM backup, rest of FlexNVM is a data flash. EEPROM has two blocks
  5041. of 1024 bytes and its contents is not loaded to FlexRAM during reset:
  5042. @example
  5043. kinetis nvm_partition eebkp 16 1024 1024 off
  5044. @end example
  5045. @end deffn
  5046. @deffn Command {kinetis mdm reset}
  5047. Issues a reset via the MDM-AP. This causes the MCU to output a low pulse on the
  5048. RESET pin, which can be used to reset other hardware on board.
  5049. @end deffn
  5050. @deffn Command {kinetis disable_wdog}
  5051. For Kx devices only (KLx has different COP watchdog, it is not supported).
  5052. Command disables watchdog timer.
  5053. @end deffn
  5054. @end deffn
  5055. @deffn {Flash Driver} kinetis_ke
  5056. @cindex kinetis_ke
  5057. KE0x and KEAx members of the Kinetis microcontroller family from NXP include
  5058. internal flash and use ARM Cortex-M0+. The driver automatically recognizes
  5059. the KE0x sub-family using the chip identification register, and
  5060. autoconfigures itself.
  5061. Use kinetis (not kinetis_ke) driver for KE1x devices.
  5062. @example
  5063. flash bank $_FLASHNAME kinetis_ke 0 0 0 0 $_TARGETNAME
  5064. @end example
  5065. @deffn Command {kinetis_ke mdm check_security}
  5066. Checks status of device security lock. Used internally in examine-end event.
  5067. @end deffn
  5068. @deffn Command {kinetis_ke mdm mass_erase}
  5069. Issues a complete Flash erase via the MDM-AP.
  5070. This can be used to erase a chip back to its factory state.
  5071. Command removes security lock from a device (use of SRST highly recommended).
  5072. It does not require the processor to be halted.
  5073. @end deffn
  5074. @deffn Command {kinetis_ke disable_wdog}
  5075. Command disables watchdog timer.
  5076. @end deffn
  5077. @end deffn
  5078. @deffn {Flash Driver} lpc2000
  5079. This is the driver to support internal flash of all members of the
  5080. LPC11(x)00 and LPC1300 microcontroller families and most members of
  5081. the LPC800, LPC1500, LPC1700, LPC1800, LPC2000, LPC4000, LPC54100,
  5082. LPC8Nxx and NHS31xx microcontroller families from NXP.
  5083. @quotation Note
  5084. There are LPC2000 devices which are not supported by the @var{lpc2000}
  5085. driver:
  5086. The LPC2888 is supported by the @var{lpc288x} driver.
  5087. The LPC29xx family is supported by the @var{lpc2900} driver.
  5088. @end quotation
  5089. The @var{lpc2000} driver defines two mandatory and two optional parameters,
  5090. which must appear in the following order:
  5091. @itemize
  5092. @item @var{variant} ... required, may be
  5093. @option{lpc2000_v1} (older LPC21xx and LPC22xx)
  5094. @option{lpc2000_v2} (LPC213x, LPC214x, LPC210[123], LPC23xx and LPC24xx)
  5095. @option{lpc1700} (LPC175x and LPC176x and LPC177x/8x)
  5096. @option{lpc4300} - available also as @option{lpc1800} alias (LPC18x[2357] and
  5097. LPC43x[2357])
  5098. @option{lpc800} (LPC8xx)
  5099. @option{lpc1100} (LPC11(x)xx and LPC13xx)
  5100. @option{lpc1500} (LPC15xx)
  5101. @option{lpc54100} (LPC541xx)
  5102. @option{lpc4000} (LPC40xx)
  5103. or @option{auto} - automatically detects flash variant and size for LPC11(x)00,
  5104. LPC8xx, LPC13xx, LPC17xx, LPC40xx, LPC8Nxx and NHS31xx
  5105. @item @var{clock_kHz} ... the frequency, in kiloHertz,
  5106. at which the core is running
  5107. @item @option{calc_checksum} ... optional (but you probably want to provide this!),
  5108. telling the driver to calculate a valid checksum for the exception vector table.
  5109. @quotation Note
  5110. If you don't provide @option{calc_checksum} when you're writing the vector
  5111. table, the boot ROM will almost certainly ignore your flash image.
  5112. However, if you do provide it,
  5113. with most tool chains @command{verify_image} will fail.
  5114. @end quotation
  5115. @item @option{iap_entry} ... optional telling the driver to use a different
  5116. ROM IAP entry point.
  5117. @end itemize
  5118. LPC flashes don't require the chip and bus width to be specified.
  5119. @example
  5120. flash bank $_FLASHNAME lpc2000 0x0 0x7d000 0 0 $_TARGETNAME \
  5121. lpc2000_v2 14765 calc_checksum
  5122. @end example
  5123. @deffn {Command} {lpc2000 part_id} bank
  5124. Displays the four byte part identifier associated with
  5125. the specified flash @var{bank}.
  5126. @end deffn
  5127. @end deffn
  5128. @deffn {Flash Driver} lpc288x
  5129. The LPC2888 microcontroller from NXP needs slightly different flash
  5130. support from its lpc2000 siblings.
  5131. The @var{lpc288x} driver defines one mandatory parameter,
  5132. the programming clock rate in Hz.
  5133. LPC flashes don't require the chip and bus width to be specified.
  5134. @example
  5135. flash bank $_FLASHNAME lpc288x 0 0 0 0 $_TARGETNAME 12000000
  5136. @end example
  5137. @end deffn
  5138. @deffn {Flash Driver} lpc2900
  5139. This driver supports the LPC29xx ARM968E based microcontroller family
  5140. from NXP.
  5141. The predefined parameters @var{base}, @var{size}, @var{chip_width} and
  5142. @var{bus_width} of the @code{flash bank} command are ignored. Flash size and
  5143. sector layout are auto-configured by the driver.
  5144. The driver has one additional mandatory parameter: The CPU clock rate
  5145. (in kHz) at the time the flash operations will take place. Most of the time this
  5146. will not be the crystal frequency, but a higher PLL frequency. The
  5147. @code{reset-init} event handler in the board script is usually the place where
  5148. you start the PLL.
  5149. The driver rejects flashless devices (currently the LPC2930).
  5150. The EEPROM in LPC2900 devices is not mapped directly into the address space.
  5151. It must be handled much more like NAND flash memory, and will therefore be
  5152. handled by a separate @code{lpc2900_eeprom} driver (not yet available).
  5153. Sector protection in terms of the LPC2900 is handled transparently. Every time a
  5154. sector needs to be erased or programmed, it is automatically unprotected.
  5155. What is shown as protection status in the @code{flash info} command, is
  5156. actually the LPC2900 @emph{sector security}. This is a mechanism to prevent a
  5157. sector from ever being erased or programmed again. As this is an irreversible
  5158. mechanism, it is handled by a special command (@code{lpc2900 secure_sector}),
  5159. and not by the standard @code{flash protect} command.
  5160. Example for a 125 MHz clock frequency:
  5161. @example
  5162. flash bank $_FLASHNAME lpc2900 0 0 0 0 $_TARGETNAME 125000
  5163. @end example
  5164. Some @code{lpc2900}-specific commands are defined. In the following command list,
  5165. the @var{bank} parameter is the bank number as obtained by the
  5166. @code{flash banks} command.
  5167. @deffn Command {lpc2900 signature} bank
  5168. Calculates a 128-bit hash value, the @emph{signature}, from the whole flash
  5169. content. This is a hardware feature of the flash block, hence the calculation is
  5170. very fast. You may use this to verify the content of a programmed device against
  5171. a known signature.
  5172. Example:
  5173. @example
  5174. lpc2900 signature 0
  5175. signature: 0x5f40cdc8:0xc64e592e:0x10490f89:0x32a0f317
  5176. @end example
  5177. @end deffn
  5178. @deffn Command {lpc2900 read_custom} bank filename
  5179. Reads the 912 bytes of customer information from the flash index sector, and
  5180. saves it to a file in binary format.
  5181. Example:
  5182. @example
  5183. lpc2900 read_custom 0 /path_to/customer_info.bin
  5184. @end example
  5185. @end deffn
  5186. The index sector of the flash is a @emph{write-only} sector. It cannot be
  5187. erased! In order to guard against unintentional write access, all following
  5188. commands need to be preceded by a successful call to the @code{password}
  5189. command:
  5190. @deffn Command {lpc2900 password} bank password
  5191. You need to use this command right before each of the following commands:
  5192. @code{lpc2900 write_custom}, @code{lpc2900 secure_sector},
  5193. @code{lpc2900 secure_jtag}.
  5194. The password string is fixed to "I_know_what_I_am_doing".
  5195. Example:
  5196. @example
  5197. lpc2900 password 0 I_know_what_I_am_doing
  5198. Potentially dangerous operation allowed in next command!
  5199. @end example
  5200. @end deffn
  5201. @deffn Command {lpc2900 write_custom} bank filename type
  5202. Writes the content of the file into the customer info space of the flash index
  5203. sector. The filetype can be specified with the @var{type} field. Possible values
  5204. for @var{type} are: @var{bin} (binary), @var{ihex} (Intel hex format),
  5205. @var{elf} (ELF binary) or @var{s19} (Motorola S-records). The file must
  5206. contain a single section, and the contained data length must be exactly
  5207. 912 bytes.
  5208. @quotation Attention
  5209. This cannot be reverted! Be careful!
  5210. @end quotation
  5211. Example:
  5212. @example
  5213. lpc2900 write_custom 0 /path_to/customer_info.bin bin
  5214. @end example
  5215. @end deffn
  5216. @deffn Command {lpc2900 secure_sector} bank first last
  5217. Secures the sector range from @var{first} to @var{last} (including) against
  5218. further program and erase operations. The sector security will be effective
  5219. after the next power cycle.
  5220. @quotation Attention
  5221. This cannot be reverted! Be careful!
  5222. @end quotation
  5223. Secured sectors appear as @emph{protected} in the @code{flash info} command.
  5224. Example:
  5225. @example
  5226. lpc2900 secure_sector 0 1 1
  5227. flash info 0
  5228. #0 : lpc2900 at 0x20000000, size 0x000c0000, (...)
  5229. # 0: 0x00000000 (0x2000 8kB) not protected
  5230. # 1: 0x00002000 (0x2000 8kB) protected
  5231. # 2: 0x00004000 (0x2000 8kB) not protected
  5232. @end example
  5233. @end deffn
  5234. @deffn Command {lpc2900 secure_jtag} bank
  5235. Irreversibly disable the JTAG port. The new JTAG security setting will be
  5236. effective after the next power cycle.
  5237. @quotation Attention
  5238. This cannot be reverted! Be careful!
  5239. @end quotation
  5240. Examples:
  5241. @example
  5242. lpc2900 secure_jtag 0
  5243. @end example
  5244. @end deffn
  5245. @end deffn
  5246. @deffn {Flash Driver} mdr
  5247. This drivers handles the integrated NOR flash on Milandr Cortex-M
  5248. based controllers. A known limitation is that the Info memory can't be
  5249. read or verified as it's not memory mapped.
  5250. @example
  5251. flash bank <name> mdr <base> <size> \
  5252. 0 0 <target#> @var{type} @var{page_count} @var{sec_count}
  5253. @end example
  5254. @itemize @bullet
  5255. @item @var{type} - 0 for main memory, 1 for info memory
  5256. @item @var{page_count} - total number of pages
  5257. @item @var{sec_count} - number of sector per page count
  5258. @end itemize
  5259. Example usage:
  5260. @example
  5261. if @{ [info exists IMEMORY] && [string equal $IMEMORY true] @} @{
  5262. flash bank $@{_CHIPNAME@}_info.flash mdr 0x00000000 0x01000 \
  5263. 0 0 $_TARGETNAME 1 1 4
  5264. @} else @{
  5265. flash bank $_CHIPNAME.flash mdr 0x00000000 0x20000 \
  5266. 0 0 $_TARGETNAME 0 32 4
  5267. @}
  5268. @end example
  5269. @end deffn
  5270. @deffn {Flash Driver} msp432
  5271. All versions of the SimpleLink MSP432 microcontrollers from Texas
  5272. Instruments include internal flash. The msp432 flash driver automatically
  5273. recognizes the specific version's flash parameters and autoconfigures itself.
  5274. Main program flash (starting at address 0) is flash bank 0. Information flash
  5275. region on MSP432P4 versions (starting at address 0x200000) is flash bank 1.
  5276. @example
  5277. flash bank $_FLASHNAME msp432 0 0 0 0 $_TARGETNAME
  5278. @end example
  5279. @deffn Command {msp432 mass_erase} [main|all]
  5280. Performs a complete erase of flash. By default, @command{mass_erase} will erase
  5281. only the main program flash.
  5282. On MSP432P4 versions, using @command{mass_erase all} will erase both the
  5283. main program and information flash regions. To also erase the BSL in information
  5284. flash, the user must first use the @command{bsl} command.
  5285. @end deffn
  5286. @deffn Command {msp432 bsl} [unlock|lock]
  5287. On MSP432P4 versions, @command{bsl} unlocks and locks the bootstrap loader (BSL)
  5288. region in information flash so that flash commands can erase or write the BSL.
  5289. Leave the BSL locked to prevent accidentally corrupting the bootstrap loader.
  5290. To erase and program the BSL:
  5291. @example
  5292. msp432 bsl unlock
  5293. flash erase_address 0x202000 0x2000
  5294. flash write_image bsl.bin 0x202000
  5295. msp432 bsl lock
  5296. @end example
  5297. @end deffn
  5298. @end deffn
  5299. @deffn {Flash Driver} niietcm4
  5300. This drivers handles the integrated NOR flash on NIIET Cortex-M4
  5301. based controllers. Flash size and sector layout are auto-configured by the driver.
  5302. Main flash memory is called "Bootflash" and has main region and info region.
  5303. Info region is NOT memory mapped by default,
  5304. but it can replace first part of main region if needed.
  5305. Full erase, single and block writes are supported for both main and info regions.
  5306. There is additional not memory mapped flash called "Userflash", which
  5307. also have division into regions: main and info.
  5308. Purpose of userflash - to store system and user settings.
  5309. Driver has special commands to perform operations with this memory.
  5310. @example
  5311. flash bank $_FLASHNAME niietcm4 0 0 0 0 $_TARGETNAME
  5312. @end example
  5313. Some niietcm4-specific commands are defined:
  5314. @deffn Command {niietcm4 uflash_read_byte} bank ('main'|'info') address
  5315. Read byte from main or info userflash region.
  5316. @end deffn
  5317. @deffn Command {niietcm4 uflash_write_byte} bank ('main'|'info') address value
  5318. Write byte to main or info userflash region.
  5319. @end deffn
  5320. @deffn Command {niietcm4 uflash_full_erase} bank
  5321. Erase all userflash including info region.
  5322. @end deffn
  5323. @deffn Command {niietcm4 uflash_erase} bank ('main'|'info') first_sector last_sector
  5324. Erase sectors of main or info userflash region, starting at sector first up to and including last.
  5325. @end deffn
  5326. @deffn Command {niietcm4 uflash_protect_check} bank ('main'|'info')
  5327. Check sectors protect.
  5328. @end deffn
  5329. @deffn Command {niietcm4 uflash_protect} bank ('main'|'info') first_sector last_sector ('on'|'off')
  5330. Protect sectors of main or info userflash region, starting at sector first up to and including last.
  5331. @end deffn
  5332. @deffn Command {niietcm4 bflash_info_remap} bank ('on'|'off')
  5333. Enable remapping bootflash info region to 0x00000000 (or 0x40000000 if external memory boot used).
  5334. @end deffn
  5335. @deffn Command {niietcm4 extmem_cfg} bank ('gpioa'|'gpiob'|'gpioc'|'gpiod'|'gpioe'|'gpiof'|'gpiog'|'gpioh') pin_num ('func1'|'func3')
  5336. Configure external memory interface for boot.
  5337. @end deffn
  5338. @deffn Command {niietcm4 service_mode_erase} bank
  5339. Perform emergency erase of all flash (bootflash and userflash).
  5340. @end deffn
  5341. @deffn Command {niietcm4 driver_info} bank
  5342. Show information about flash driver.
  5343. @end deffn
  5344. @end deffn
  5345. @deffn {Flash Driver} nrf5
  5346. All members of the nRF51 microcontroller families from Nordic Semiconductor
  5347. include internal flash and use ARM Cortex-M0 core.
  5348. Also, the nRF52832 microcontroller from Nordic Semiconductor, which include
  5349. internal flash and use an ARM Cortex-M4F core.
  5350. @example
  5351. flash bank $_FLASHNAME nrf5 0 0x00000000 0 0 $_TARGETNAME
  5352. @end example
  5353. Some nrf5-specific commands are defined:
  5354. @deffn Command {nrf5 mass_erase}
  5355. Erases the contents of the code memory and user information
  5356. configuration registers as well. It must be noted that this command
  5357. works only for chips that do not have factory pre-programmed region 0
  5358. code.
  5359. @end deffn
  5360. @deffn Command {nrf5 info}
  5361. Decodes and shows informations from FICR and UICR registers.
  5362. @end deffn
  5363. @end deffn
  5364. @deffn {Flash Driver} ocl
  5365. This driver is an implementation of the ``on chip flash loader''
  5366. protocol proposed by Pavel Chromy.
  5367. It is a minimalistic command-response protocol intended to be used
  5368. over a DCC when communicating with an internal or external flash
  5369. loader running from RAM. An example implementation for AT91SAM7x is
  5370. available in @file{contrib/loaders/flash/at91sam7x/}.
  5371. @example
  5372. flash bank $_FLASHNAME ocl 0 0 0 0 $_TARGETNAME
  5373. @end example
  5374. @end deffn
  5375. @deffn {Flash Driver} pic32mx
  5376. The PIC32MX microcontrollers are based on the MIPS 4K cores,
  5377. and integrate flash memory.
  5378. @example
  5379. flash bank $_FLASHNAME pix32mx 0x1fc00000 0 0 0 $_TARGETNAME
  5380. flash bank $_FLASHNAME pix32mx 0x1d000000 0 0 0 $_TARGETNAME
  5381. @end example
  5382. @comment numerous *disabled* commands are defined:
  5383. @comment - chip_erase ... pointless given flash_erase_address
  5384. @comment - lock, unlock ... pointless given protect on/off (yes?)
  5385. @comment - pgm_word ... shouldn't bank be deduced from address??
  5386. Some pic32mx-specific commands are defined:
  5387. @deffn Command {pic32mx pgm_word} address value bank
  5388. Programs the specified 32-bit @var{value} at the given @var{address}
  5389. in the specified chip @var{bank}.
  5390. @end deffn
  5391. @deffn Command {pic32mx unlock} bank
  5392. Unlock and erase specified chip @var{bank}.
  5393. This will remove any Code Protection.
  5394. @end deffn
  5395. @end deffn
  5396. @deffn {Flash Driver} psoc4
  5397. All members of the PSoC 41xx/42xx microcontroller family from Cypress
  5398. include internal flash and use ARM Cortex-M0 cores.
  5399. The driver automatically recognizes a number of these chips using
  5400. the chip identification register, and autoconfigures itself.
  5401. Note: Erased internal flash reads as 00.
  5402. System ROM of PSoC 4 does not implement erase of a flash sector.
  5403. @example
  5404. flash bank $_FLASHNAME psoc4 0 0 0 0 $_TARGETNAME
  5405. @end example
  5406. psoc4-specific commands
  5407. @deffn Command {psoc4 flash_autoerase} num (on|off)
  5408. Enables or disables autoerase mode for a flash bank.
  5409. If flash_autoerase is off, use mass_erase before flash programming.
  5410. Flash erase command fails if region to erase is not whole flash memory.
  5411. If flash_autoerase is on, a sector is both erased and programmed in one
  5412. system ROM call. Flash erase command is ignored.
  5413. This mode is suitable for gdb load.
  5414. The @var{num} parameter is a value shown by @command{flash banks}.
  5415. @end deffn
  5416. @deffn Command {psoc4 mass_erase} num
  5417. Erases the contents of the flash memory, protection and security lock.
  5418. The @var{num} parameter is a value shown by @command{flash banks}.
  5419. @end deffn
  5420. @end deffn
  5421. @deffn {Flash Driver} psoc5lp
  5422. All members of the PSoC 5LP microcontroller family from Cypress
  5423. include internal program flash and use ARM Cortex-M3 cores.
  5424. The driver probes for a number of these chips and autoconfigures itself,
  5425. apart from the base address.
  5426. @example
  5427. flash bank $_FLASHNAME psoc5lp 0x00000000 0 0 0 $_TARGETNAME
  5428. @end example
  5429. @b{Note:} PSoC 5LP chips can be configured to have ECC enabled or disabled.
  5430. @quotation Attention
  5431. If flash operations are performed in ECC-disabled mode, they will also affect
  5432. the ECC flash region. Erasing a 16k flash sector in the 0x00000000 area will
  5433. then also erase the corresponding 2k data bytes in the 0x48000000 area.
  5434. Writing to the ECC data bytes in ECC-disabled mode is not implemented.
  5435. @end quotation
  5436. Commands defined in the @var{psoc5lp} driver:
  5437. @deffn Command {psoc5lp mass_erase}
  5438. Erases all flash data and ECC/configuration bytes, all flash protection rows,
  5439. and all row latches in all flash arrays on the device.
  5440. @end deffn
  5441. @end deffn
  5442. @deffn {Flash Driver} psoc5lp_eeprom
  5443. All members of the PSoC 5LP microcontroller family from Cypress
  5444. include internal EEPROM and use ARM Cortex-M3 cores.
  5445. The driver probes for a number of these chips and autoconfigures itself,
  5446. apart from the base address.
  5447. @example
  5448. flash bank $_CHIPNAME.eeprom psoc5lp_eeprom 0x40008000 0 0 0 $_TARGETNAME
  5449. @end example
  5450. @end deffn
  5451. @deffn {Flash Driver} psoc5lp_nvl
  5452. All members of the PSoC 5LP microcontroller family from Cypress
  5453. include internal Nonvolatile Latches and use ARM Cortex-M3 cores.
  5454. The driver probes for a number of these chips and autoconfigures itself.
  5455. @example
  5456. flash bank $_CHIPNAME.nvl psoc5lp_nvl 0 0 0 0 $_TARGETNAME
  5457. @end example
  5458. PSoC 5LP chips have multiple NV Latches:
  5459. @itemize
  5460. @item Device Configuration NV Latch - 4 bytes
  5461. @item Write Once (WO) NV Latch - 4 bytes
  5462. @end itemize
  5463. @b{Note:} This driver only implements the Device Configuration NVL.
  5464. The @var{psoc5lp} driver reads the ECC mode from Device Configuration NVL.
  5465. @quotation Attention
  5466. Switching ECC mode via write to Device Configuration NVL will require a reset
  5467. after successful write.
  5468. @end quotation
  5469. @end deffn
  5470. @deffn {Flash Driver} psoc6
  5471. Supports PSoC6 (CY8C6xxx) family of Cypress microcontrollers.
  5472. PSoC6 is a dual-core device with CM0+ and CM4 cores. Both cores share
  5473. the same Flash/RAM/MMIO address space.
  5474. Flash in PSoC6 is split into three regions: