Commit Graph

136 Commits

Author SHA1 Message Date
Andreas Fritiofson 7c957b601f jim-nvp: Make Jim_GetOpt_String const-correct
Change-Id: Iae9824f6ff47a1944e674e59bfaa970904645082
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/3178
Tested-by: jenkins
2016-02-29 20:32:31 +00:00
Paul Fertser 20fcd0729e jtag/tcl: fix incorrect memcpy in jim_newtap_expected_id
Found by clang static checker.

On the very first call of jim_newtap_expected_id() pTap->expected_ids
and expected_len are null, and there's nothing to copy. This patch
changes this cryptic code to use realloc() instead.

Change-Id: Ic0b5140d08257a906f15b55a2ae64db7bc06d5f1
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2562
Reviewed-by: Stian Skjelstad <stian@nixia.no>
Tested-by: jenkins
2015-04-14 12:09:48 +01:00
Paul Fertser ef02b69b14 drivers/cmsis-dap: port to common SWD framework
Valgrind-tested.

Comparison of flashing performance on an FRDM-KL25Z board running mbed
CMSIS-DAP variant, 5MHz clock, old driver:

wrote 28096 bytes from file demo.elf in 26.833590s (1.023 KiB/s)
verified 27264 bytes in 1.754972s (15.171 KiB/s)

this implementation:

wrote 28096 bytes from file demo.elf in 3.691939s (7.432 KiB/s)
verified 27264 bytes in 0.598987s (44.450 KiB/s)

Also tested "Keil ULINK-ME CMSIS-DAP" with an STM32F100 target, 5MHz
clock, results reading from flash, old driver:

dumped 131072 bytes in 98.445305s (1.300 KiB/s)

this implementation:

dumped 131072 bytes in 8.242686s (15.529 KiB/s)

Change-Id: Ic64d3124b1d6cd9dd1016445bb627c71e189ae95
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2356
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2015-03-25 21:31:09 +00:00
Paul Fertser bd0409aa93 jtag: always configure enabled tap parameter appropriately
Commit f701c0cb seems to have introduced a regression for non-JTAG
transports as the newly created "tap" (DAP actually) ended up being
disabled, thus resulting in total lack of functionality.

This was exposed by a debug log demonstrating ftdi SWD transport
connection to mdr32f9q2i, the target wasn't examined on init and
couldn't be reset.

Change-Id: If53cbe800d4adc177aa3ac3219860e7fa15b3e49
Reported-by: Хайруллин Эльдар <eldar.khayrullin@mail.ru>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2261
Tested-by: jenkins
Reviewed-by: Angus Gratton <gus@projectgus.com>
Reviewed-by: Nemui Trinomius <nemuisan_kawausogasuki@live.jp>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2014-08-22 07:38:42 +00:00
Angus Gratton f701c0cbeb newdap: Ignore -irlen/-irmask/etc newdap params on SWD or CMSIS-DAP
Previously the -irlen parameter was required even though it is not
a part of the SWD or CMSIS-DAP transports.

This may eventually need to be changed for CMSIS-DAP once that
supports JTAG as well.

Change-Id: Ia02b67840c19c7cf1c7a75063648c0174176a311
Signed-off-by: Angus Gratton <gus@projectgus.com>
Reviewed-on: http://openocd.zylin.com/2226
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2014-08-11 20:49:05 +00:00
Paul Fertser bb0ef230ca tcl/drscan: handle invalid syntax with a conditional, not assert
When "drscan" command is used improperly, such as in:
drscan stm32f1x.cpu -endstate drpause
there're no fields to scan, and so the assert leads to a
segfault. This should be treated like any other syntax error instead.

Change-Id: Id1743f5d641038e1e3754c6f3097aabc5d1916b9
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/1927
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2014-02-24 12:01:52 +00:00
Spencer Oliver 4dc8cd201c cmsis-dap: add initial cmsis-dap support
This is based on work from:
https://github.com/TheShed/OpenOCD-CMSIS-DAP/tree/cmsis-dap

Main changes include moving over to using HIDAPI rather than libusb-1.0
and cleaning up to merge into master. Support for reset using srst has
also been added.

It has been tested on all the mbed boards as well as the Freedom board
from Freescale. These boards only implement SWD mode, however JTAG mode
has been tested with a Keil ULINK2 and a stm32 target - but requires a lot
more work.

Change-Id: I96d5ee1993bc9c0526219ab754c5aad3b55d812d
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com>
Reviewed-on: http://openocd.zylin.com/1542
Tested-by: jenkins
2014-01-09 15:20:51 +00:00
Andreas Fritiofson 517ba0690d Clean up const usage to avoid excessive casting
Don't use const on pointers that hold heap allocated data, because that
means functions that free them must cast away the const.

Do use const on pointer parameters or fields that needn't be modified.

Remove pointer casts that are no longer needed after fixing the constness.

Change-Id: I5d206f5019982fd1950bc6d6d07b6062dc24e886
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1668
Tested-by: jenkins
Reviewed-by: Mathias Küster <kesmtp@freenet.de>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2013-10-31 20:42:34 +00:00
Andreas Fritiofson 85830c32bf jtag/tcl: Avoid casting away const
Here, in_value == out_value, so free the non-const one.

Change-Id: I017ad9e7519711ac0c9da79265be7daaa846f356
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1667
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2013-10-07 19:03:30 +00:00
Andreas Fritiofson d96010ae71 jtag/tcl: Remove no-op free
And use calloc instead of malloc+memset.

Change-Id: Icc1ed6e34904972bb5d3728307dcae5c55b32fc3
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1666
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2013-10-07 19:03:18 +00:00
Andreas Fritiofson 2a0ed1ee7f jtag/tcl: Fix double free in jtag newtap argument parsing
Found when grepping for void* casts. I'm pretty sure there are about
*picking a number out of the blue* 0.31 bugs per pointer cast in OpenOCD.

Verified by valgrind, i.e.:
valgrind openocd -f interface/jtagkey.cfg -c "jtag newtap dummy cpu -irlen foo"

Change-Id: Idc12e8f18036cc908fdb572828fa46563be14242
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/1665
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2013-10-07 19:03:02 +00:00
Evan Hunter 7641fb6ac6 Add support for 64 bit parameter to irscan
Change-Id: I89e0422456c59ee86c4b6d9bd3b3ad32051b31ac
Signed-off-by: Evan Hunter <ehunter@broadcom.com>
Reviewed-on: http://openocd.zylin.com/831
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2013-07-01 08:37:14 +00:00
Spencer Oliver 08d4411b59 update files to correct FSF address
Change-Id: I429f7fd51f77b0e7c86d7a7f110ca31afd76c173
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/1426
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2013-06-05 19:52:42 +00:00
Simon Qian 7743e0fb43 topic: add reset functions for SWD
Add swd_init_reset and swd_add_reset.
Add adapter_assert_reset and adapter_deassert_reset, and call them instead
of JTAG reset functions.

Change-Id: Ib2551c6fbb45513e0ae0dc331cfe3ee3f922298a
Signed-off-by: Simon Qian <simonqian.openocd@gmail.com>
Reviewed-on: http://openocd.zylin.com/526
Tested-by: jenkins
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2012-04-10 12:14:00 +00:00
Spencer Oliver d431af34fe jtag: fix cmd scan_chain expected_ids bug
This fixes scan_chain to correctly print all the expected_ids.

Change-Id: I93738980d85e0fe369d40c58b19339424d37ec34
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/474
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2012-02-26 01:12:01 +00:00
Spencer Oliver 38f8e5eefa build: cleanup src/jtag directory
Change-Id: I7caf57ca3d9dfbe152504472a6bb26c2a28b92e8
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/423
Tested-by: jenkins
2012-02-06 10:57:27 +00:00
Spencer Oliver 0c2f8b6eb8 cmd: add missing usage vars
we should have caught them all - hopefully.

Change-Id: I35435317fccaf5ad0216244d69f76db6857bb582
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/381
Tested-by: jenkins
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
2012-01-18 21:45:02 +00:00
Mathias K 1d873623a0 Make jim functions public accessible.
Change this 2 functions to make it accessible for other tcl interfaces.

Change-Id: Idee07fcc779941b037a05a40c021e3fb0b1a4a7a
Signed-off-by: Mathias K <kesmtp@freenet.de>
Reviewed-on: http://openocd.zylin.com/277
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2012-01-03 21:12:06 +00:00
Øyvind Harboe fe2fd812fa clang: fix warning by adding assert that shows that a variable is used
Change-Id: I26e0ba9f1ae9d43c9a14c42c4225746782dc4d66
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Reviewed-on: http://openocd.zylin.com/134
Tested-by: jenkins
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
2011-10-29 13:13:45 +00:00
Øyvind Harboe 4e079d18bf clang: fix malloc() warning with assert
Change-Id: I989d2655622a9f11f4a0a2994014e42822587ecd
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Reviewed-on: http://openocd.zylin.com/41
Tested-by: jenkins
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
2011-10-23 11:55:02 +00:00
Rodrigo L. Rosa 194e3c5bc5 fix tapenabler return code
if tap enable/disable failed then a warning was written to the log, but JIM_OK was returned. if using openocd via a TCP interface to the TCL port, there is no way to catch that the command failed (it didn't enable the tap, so it failed)
now it return an error if it fails.
2011-08-09 20:59:40 +02:00
Øyvind Harboe c3c6a6e1d4 jtag: add wait_srst_deassert command
Useful to do something *real quick* after a SRST deassert.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2011-02-25 16:36:42 +01:00
Eric Wetzel 0535531d27 nit: more LOG_* \n fixes
Remove extra \n from LOG_DEBUG, LOG_INFO, and LOG_WARNING messages

Remove LOG_INFO_N
LOG_INFO_N was only used once and had a \n at the end

Change LOG_USER_N calls that end with \n to LOG_USER
2011-01-09 21:35:23 +01:00
David Brownell 7cd2617384 initial SWD transport (SWD infrastructure #2)
This piggy backs on JTAG so it's not yet pretty, but that
seems unavoidable so far given today's OpenOCD internals.

SWD init and data transfer  are unfinished and untested, but
that should cause no regressions, and will be addressed by
the time drivers start using this infrastructure.  Checking
in whould get the code working better sooner, and turn up any
structural/architectural issues while they're easier to fix.

The debug adapter drivers will provide simple SWD driver
structs with methods that kick in as needed (instead of JTAG).
So far just one adapter driver has been updated (not yet
ready to use or circulate).

The biggest issues are probably
  - fault handling, where the ARM Debug Interface V5 pipelining
    needs work in both JTAG and SWD modes and
  - missing  rewrite of block I/O code to work on both of our
Cortex-ready transports (Current code is  hard-wired to JTAG);
relates also to the pipelining issue.
  - omitted support to activate/deactivate SWO/SWV trace (this is
    technically trivial, but configuring what to trace is NOT.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
----

 doc/openocd.texi        |   17 ++
 src/jtag/core.c         |    3
 src/jtag/interface.h    |    4
 src/jtag/jtag.h         |    2
 src/jtag/swd.h          |  114 +++++++++++++++++++
 src/jtag/tcl.c          |    2
 src/target/adi_v5_swd.c |  281 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/target/arm_adi_v5.c |    8 +
 src/target/arm_adi_v5.h |    3
 9 files changed, 425 insertions(+), 9 deletions(-)
2010-12-24 18:50:41 -08:00
Øyvind Harboe 559d08c19e jim tests: use installed
Delete obsolete jim that comes with OpenOCD.
2010-10-29 15:10:51 +02:00
Thomas Koeller 07e0bd4685 jtag: fix handling of 'tap enable' error
if a tap could not be _enabled_, the error message was
'failed to disable tap'. Fixed that. Also, display the failing
tap's name.

Signed-off-by: Thomas Koeller <thomas.koeller@baslerweb.com>
2010-08-12 08:59:05 +02:00
Øyvind Harboe 803351ec59 jtag: add jtag_flush_queue_sleep debug command
it can be useful to throttle performance: test
differences in behavior, test performance effect
of long roundtrips.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-08-02 09:54:06 +02:00
Øyvind Harboe 91b9f3de0b command context: fix errors when running certain commands on startup
Various commands, e.g. "arm mcr xxxx" would fail if invoked upon startup
since it there was no command context defined for the jim interpreter
in that case.

A Jim interpreter is now associated with a command context(telnet,
gdb server's) or the default global command context.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-05-05 15:24:24 +02:00
David Brownell d37a10da52 buildfix
Without this, a system using gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
aborts builds after reporting:

tcl.c: In function ‘handle_irscan_command’:
tcl.c:1168: warning: passing argument 1 of ‘buf_set_u32’ discards qualifiers from pointer target type

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-04-03 18:36:07 -07:00
David Brownell d60ebc0ab5 jtag/tcl.c cleanup -- split out "adapter.c"
Clean up the jtag/tcl.c file, which was one of the biggest and
messiest ones in that directory.  Do it by splitting out all the
generic adapter commands to a separate "adapter.c" file (leaving
the "tcl.c" file holding only JTAG utilities).

Also rename the little-used "jtag interface" to "adapter_name", which
should have been at least re-categorized earlier (it's not jtag-only).

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-03-27 10:07:13 -07:00
Øyvind Harboe 5dcad2d34f jtag: make out_value const
Tightens up the jtag_add_xxx_scan() API

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-03-21 19:13:49 +01:00
David Brownell a540033a71 move "reset_config" out of JTAG command group
The SRST configuration options are not specific to JTAG, so this
command may be needed with non-JTAG debug sessions.  Just move
the command to a different group.

(The TRST options are, however, clearly JTAG-specific, but for
compatibility, they're now left alone.  The flags they control
could later be disabled in non-JTAG sessions.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-03-15 08:43:16 -07:00
David Brownell 1bd3ae3986 rename jtag_nsrst_assert_width as adapter_nsrst_assert_width
Globally rename "jtag_nsrst_assert_width" as "adapter_nsrst_assert_width",
and move it out of the "jtag" command group ...  it needs to be used with
non-JTAG transports

Includes a migration aid (in jtag/startup.tcl) so that old user scripts
won't break.  That aid should Sunset in about a year.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-03-15 08:42:26 -07:00
David Brownell b559b273b5 rename jtag_nsrst_delay as adapter_nsrst_delay
Globally rename "jtag_nsrst_delay" as "adapter_nsrst_delay", and move it
out of the "jtag" command group ...  it needs to be used with non-JTAG
transports

Includes a migration aid (in jtag/startup.tcl) so that old user scripts
won't break.  That aid should Sunset in about a year.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-03-15 08:41:30 -07:00
David Brownell 96f9790279 rename jtag_khz as adapter_khz
Globally rename "jtag_khz" as "adapter_khz", and move it out of the "jtag"
command group ...  it needs to be used with non-JTAG transports

Includes a migration aid (in jtag/startup.tcl) so that old user scripts
won't break.  That aid should Sunset in about a year.  (We may want to
update it to include a nag message too.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-03-15 08:37:43 -07:00
David Brownell c25fda2c95 rename jtag_interface_{init,quit}()
These routines apply to non-JTAG debug adapters too.  To
reduce confusion, give them better (non-misleading) names.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-03-14 13:13:39 -07:00
David Brownell 591e0bbab9 split "interface" commands from "jtag" ones
We'll need to be able to work with debug adapter interfaces (drivers)
even when they're not used for JTAG ... for example, while there are
multi-transport drivers which support JTAG *and* several other
transports (or just one more, like SWD) there are also adapters
with more limited goals (and no JTAG support at all).

Start decoupling the two concepts ("debug adapter driver", "jtag")
by having two command groups, which initialize separately.

This will help us support OpenOCD sessions using only non-JTAG
transports, in which JTAG commands should not be registered.
Update docs to mention that the JTAG, SVF, and XSVF commands
won't work without a JTAG transport.

Note that at least commands working with SRST are still inappropriately
coupled  to JTAG ... inappropriate because (a) SRST is not part of the
JTAG standard, for all that many platforms (like ARM) expect it; and also
(b) because they're used with non-JTAG debug and programming interfaces,
too.  They should perhaps become generic "interface" operations at some
point.  (Similarly with the clock rate to be used by a given adapter.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-03-11 09:47:47 -08:00
Øyvind Harboe 57d7743639 jtag: jtag_add_ir_scan() now takes a single field
In the code a single field was all that was ever used. Makes
jtag_add_ir_scan() simpler and leaves more complicated stuff
to jtag_add_plain_ir_scan().

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-03-08 08:12:25 +01:00
Øyvind Harboe e018c7c1d2 jtag: retire tap field
jtag_add_dr/ir_scan() now takes the tap as the first
argument, rather than for each of the fields passed
in.

The code never exercised the path where there was
more than one tap being scanned, who knows if it even
worked.

This simplifies the implementation and reduces clutter
in the calling code.

use jtag_add_ir/dr_plain_scan() for more fancy situations.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-03-08 08:12:25 +01:00
Øyvind Harboe 56d2c86500 commands: allow scan_chain command to be executed during config
Adding taps and then dumping them is quite reasonable thing
to do in a config script.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-01-18 21:42:34 +01:00
Øyvind Harboe e5349bfb49 target: return JIM_OK instead of ERROR_OK
No change in actual binary as JIM_OK == ERROR_OK,
but JIM_OK is correct here.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-01-11 15:01:02 +01:00
David Brownell ab4307e693 jtag/tcl help/usage fixups
The usual: expand several helptexts to be more correct and to use
full sentences; make the usage messages use the same EBNF as the
User's Guide; use function names for their addresses.

Also add a comment about that odd jtag_command_handlers_to_move[] thing.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-01-09 22:15:57 -08:00
David Brownell 2c3e413d49 JTAG: shrink "scan_chain" output
Tweak the "scan_chain" output by removing column separators.  Also
remove the "current instruction" state ... which changes constantly.

Now its style resembles the "targets" output, and can even fit on
one line in standard terminals and in the PDF docs.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2009-12-16 14:19:44 -08:00
David Brownell af79925eb1 jtag: add '-ignore-version' option
Add a "-ignore-version" to "jtag newtap" which makes the IDCODE
comparison logic optionally ignore version differences.

Update the "scan_chain" command to illustrate this by showing
the "*" character instead of the (ignored) version nibble.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2009-12-14 15:55:51 -08:00
Zachary T Welch 79a73a786e separate Jim from jtag/core.c
After previous efforts, only one Jim routine remained in jtag/core.c,
and moving it to jtag/tcl.c painlessly finishes separating these layers.
The headers need separating, but the implementation is clean.
2009-12-04 03:34:32 -08:00
Zachary T Welch eae56d27c3 allow 'jtag init' to be run in any mode
Help alleviate further potential problems with interactive startup.
2009-12-04 03:29:15 -08:00
Zachary T Welch ac1887c703 jtag: factor init into 'jtag init'
Adds 'jtag init' command handler, which can be called as part of a
fine-grained 'init' process.
2009-12-02 13:26:22 -08:00
Zachary T Welch e1ee270265 jtag: avoid using interp global variable
Adds 'interp' field to jtag_tap_event_action structure to avoid
using the global variable of same name.
2009-11-30 16:29:34 -08:00
Zachary T Welch f8a62fb9c6 split jim_newtap_cmd into pieces
Moves the ID and IR-related option parsing to static helpers, removing
two levels of indent.
2009-11-28 13:00:39 -08:00
Zachary T Welch 7124be8247 improve jtag_tap_configure
Splits bulk of the jtag_tap_configure into jtag_tap_configure_event,
removing three or four levels of indentation in the process.
The resulting code was stylistically improved in other ways, but it
should be functionally identical.
2009-11-28 13:00:39 -08:00