Commit Graph

108 Commits

Author SHA1 Message Date
Antonio Borneo b86f296ac6 openocd: src: replace the GPL-2.0-or-later license tag
Replace the FSF boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: I30cd66ac7d737f1973c68fdbb841ffcf00e917c4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7072
Tested-by: jenkins
2022-07-23 13:59:13 +00:00
Antonio Borneo 96202cda19 openocd: build: add SPDX tag
Add the SPDX tag to makefiles, configuration scripts and tcl files
present in the folders under src/

Change-Id: I1e4552aafe46ef4893d510da9d732c5f181784a4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7051
Tested-by: jenkins
2022-07-23 13:06:38 +00:00
Antonio Borneo 08ee7bb982 openocd: fix simple cases of NULL comparison
There are more than 1000 NULL comparisons to be aligned to the
coding style.
For recurrent NULL comparison it's preferable using trivial
scripts in order to minimize the review effort.

Patch generated automatically with the command:
	sed -i PATTERN $(find src/ -type f)
where PATTERN is in the list:
	's/(\([a-z][a-z0-9_]*\) == NULL)/(!\1)/g'
	's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) == NULL)/(!\1)/g'
	's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) == NULL)/(!\1)/g'

	's/(\([a-z][a-z0-9_]*\) != NULL)/(\1)/g'
	's/(\([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\) != NULL)/(\1)/g'
	's/(\([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\) != NULL)/(\1)/g'

	's/(NULL == \([a-z][a-z0-9_]*\))/(!\1)/g'
	's/(NULL == \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(!\1)/g'
	's/(NULL == \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(!\1)/g'

	's/(NULL != \([a-z][a-z0-9_]*\))/(\1)/g'
	's/(NULL != \([a-z][a-z0-9_]*->[a-z][a-z0-9_]*\))/(\1)/g'
	's/(NULL != \([a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\))/(\1)/g'

Change-Id: Ida103e325d6d0600fb69c0b7a1557ee969db4417
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6350
Tested-by: jenkins
2021-07-24 10:37:49 +01:00
Antonio Borneo 3c4206936d openocd: fix some minor typo
Minor typos found by the new checkpatch boosted by the dictionary
provided by 'codespell'.

Change-Id: I7b4cae1798ff5ea048fcbc671a397af763fdc605
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6218
Tested-by: jenkins
2021-05-22 10:06:51 +01:00
Tim Newsome 87c90393fe Cleanup of config/includes.
Remove a use of AH_BOTTOM from configure.ac. This macro is used by
autoheader to add '#include' of some include file to the end of
config.h.in and then to config.h. OpenOCD can be built with a custom
config.h, so it's preferable to move these '#include' statement directly
in the C files that need them dropping this unneeded dependency.

It also causes problems when I want to use the gnulib library (which
comes with its own Makefile, and does not have the same include path as
the top-level Makefile).

So this change touches a lot of files, but is actually really simple. It
does not affect functionality at all.

Change-Id: I52c70bf15eb2edc1dd10e0fde23b2bcd4caec000
Signed-off-by: Tim Newsome <tim@sifive.com>
Reviewed-on: http://openocd.zylin.com/6171
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2021-05-01 14:35:09 +01:00
Antonio Borneo 4e98d44fd1 openocd: avoid checking for non NULL pointer to free it
The function free() can be called with a NULL pointer as argument,
no need to check the argument before. If the pointer is NULL, no
operation is performed by free().

Remove the occurrences of pattern:
	if (ptr)
		free(ptr);

While there replace a sequence malloc(size)+memset(,0,size) with a
calloc(1,size).
Replace a pointer assignment to '0' with an assignment to NULL.
In server/*, an error is logged if the ptr was already NULL. This
cannot happen since the pointer was already referenced few lines
before and openocd would have been already SIGSEGV in that case,
so remove the log.

Change-Id: I10822029fe8390b59edff4070575bf7f754e44ac
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5808
Reviewed-by: Adrian M Negreanu <adrian.negreanu@nxp.com>
Tested-by: jenkins
2020-09-05 17:11:50 +01:00
Antonio Borneo 890048eec4 xsvf: fix minor typos
Change-Id: Ib36b2178eacf79dd26ebd2e15ba385853825c198
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5765
Tested-by: jenkins
2020-07-26 20:14:22 +01:00
Tomas Vanek 35d9bf9917 xsvf: fix memory leak
Discovered by clang static analyzer.

Change-Id: I2980586aea5ee43226adb1f4cf72e7ba1dfddd83
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5372
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-01-16 09:44:33 +00:00
Antonio Borneo 6cb5ba6f11 helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.

Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
	sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
	's/\(command_print(cmd\)->ctx,/\1,/'
	's/\(command_print(CMD\)_CTX,/\1,/'
	's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
	's/\(command_print_sameline(cmd\)->ctx,/\1,/'
	's/\(command_print_sameline(CMD\)_CTX,/\1,/'
	's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'

This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.

Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-14 19:37:11 +01:00
Andreas Fritiofson 5be455a710 Convert to non-recursive make
Change-Id: I11f8bc8553957e2ff083c09e72e16881e4d3bb6f
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/3865
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2016-12-08 16:23:10 +00:00
Marc Schink d4b7cbff88 Make #include guard naming consistent
Change-Id: Ie13e8af0bb74ed290f811dcad64ad06c9d8cb4fa
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/2956
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2016-05-24 22:30:55 +01:00
Marc Schink d0e763ac7e Remove FSF address from GPL notices
Also make GPL notices consistent according to:
https://www.gnu.org/licenses/gpl-howto.html

Change-Id: I84c9df40a774958a7ed91460c5d931cfab9f45ba
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/3488
Tested-by: jenkins
Reviewed-by: Andreas Färber <afaerber@suse.de>
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2016-05-24 22:30:01 +01:00
Paul Fertser 893de2fe95 xsvf: output a warning suggesting using SVF
Change-Id: Iff13019aa96c528268a2be029b4acd65a00a598e
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2907
Tested-by: jenkins
2015-11-30 10:11:16 +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
Spencer Oliver f7772ccb49 build: cleanup src/xsvf directory
Change-Id: I5325980b240fba841d8cce81985f4da369ad9052
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/410
Tested-by: jenkins
2012-02-06 10:45:43 +00:00
Spencer Oliver 06d1580ff7 xsvf: fix clang warning
clang reports 'Function call argument is an uninitialized value'.

Change-Id: I50f4a7932b59930a5f1e3ece70b12c59e85ea3c6
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/360
Tested-by: jenkins
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
2012-01-12 20:38:51 +00:00
Mathias K 16b6b5e7a8 Change return value on error.
On wrong parameters a error is signalized to the calling function.

Change-Id: I484443fdb39938e20382edc9246d5ec546a5c960
Signed-off-by: Mathias K <kesmtp@freenet.de>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Reviewed-on: http://openocd.zylin.com/282
Tested-by: jenkins
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
2012-01-04 17:56:46 +00:00
Øyvind Harboe 3bab899063 xsvf: add missing error propagation
Change-Id: Ibc70deb980d6d18ceb376b72d9104e6180b16acf
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Reviewed-on: http://openocd.zylin.com/176
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2011-11-07 20:35:42 +00:00
Eric Wetzel a665ef716a nit: do not add \n at end of LOG_ERROR
Fixed in many other places, and submitted in response to Øyvind's invitation.
2011-01-05 21:46:12 +01:00
Spencer Oliver 838cd58e24 build: add common.mk
Rather than specifying common makefile variables move
them all to a common.mk.

Signed-off-by: Spencer Oliver <ntfreak@users.sourceforge.net>
2010-11-18 14:05:56 +00:00
Edgar Grimberg f44eeba16f xsvf: Fix shadow issues on Mac
wait is declared in /usr/include/sys/wait.h

Signed-off-by: Edgar Grimberg <edgar.grimberg@zylin.com>
2010-06-22 08:24:26 +02:00
Øyvind Harboe dcba070958 jtag: do not use jtag_get_error()
normal code should not call jtag_get_error(), but rather check
the return code from jtag_execute_queue().

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-06-21 13:43:23 +02:00
Øyvind Harboe cd9c61cc06 xsvf: -Wshadow warning fixes
I think this fixed an error message where the error
message would show the *previous* uc code rather than
the current unsupported uc code.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-06-16 08:19:25 +02:00
Øyvind Harboe 36df240cea jtag: cut down on usage of unintended modification of global end state
jtag_get/set_end_state() is now deprecated.

There were lots of places in the code where the end state was
unintentionally modified.

The big Q is whether there were any places where the intention
was to modify the end state. 0.5 is a long way off, so we'll
get a fair amount of testing.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-03-18 08:43:19 +01:00
Øyvind Harboe 50dc56a488 jtag: simplify jtag_add_plain_ir/dr_scan
These fn's now clearly just clock out/in bits. No mystical
fields are involved.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2010-03-08 08:12:26 +01: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
David Brownell b800eb0336 *SVF: help/usage updates
Usage messages should use the same EBNF as the User's Guide;
no angle brackets.  Be more complete too ... some params were
missing.

Don't use "&function"; its name is its address.

Unrelated: fix typo in one "target.c" usage message.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2010-01-08 20:16:05 -08:00
Øyvind Harboe eb1bc657ae build: add build/src to include path
This allows including generated include files.

Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2009-12-08 10:16:10 +01:00
Zachary T Welch 822c06d9e3 remove tertiary include paths
With all #include directives converted, we only need to have the
top-level src/ directory in the search path.
2009-12-03 04:24:50 -08:00
Zachary T Welch 66e45ba611 change #include "svf.h" to <svf/svf.h>
Changes from the flat namespace to heirarchical one.  Instead of writing:

	#include "svf.h"

the following form should be used.

	#include <svf/svf.h>

The exception is from .c files in the same directory.
2009-12-03 04:24:49 -08:00
Zachary T Welch cb4a475f6c change #include "jtag.h" to <jtag/jtag.h>
Changes from the flat namespace to heirarchical one.  Instead of writing:

	#include "jtag.h"

the following form should be used.

	#include <jtag/jtag.h>

The exception is from .c files in the same directory.
2009-12-03 04:24:33 -08:00
Zachary T Welch 264d24495d change #include "command.h" to <helper/command.h>
Changes from the flat namespace to heirarchical one.  Instead of writing:

	#include "command.h"

the following form should be used.

	#include <helper/command.h>

The exception is from .c files in the same directory.
2009-12-03 04:22:48 -08:00
Zachary T Welch 896ac8d4ef allow #include directives to use module name
Includes the src directory in the search path, so header files may be
migrated from:

  #include "foo.h"

to
  #include <module/foo.h>

which is more conducive for installation.
2009-12-03 01:54:15 -08:00
Zachary T Welch 75e37b5348 {,x}svf: use register_commands()
Use register_commands() for registering {,x}svf commands.
2009-11-24 21:37:33 -08:00
Zachary T Welch 833e7f5248 use COMMAND_REGISTER macro
Replaces direct calls to register_command() with a macro, to allow
its parameters to be changed and callers updated in phases.
2009-11-24 21:37:29 -08:00
Zachary T Welch 2861877b32 command_handler: change 'cmd_ctx' to CMD_CTX
Convert all command handler 'cmd_ctx' parameter usage with CMD_CTX.
2009-11-17 11:40:06 -08:00
Zachary T Welch 23402315ce command_handler: change 'args' to CMD_ARGV
This patch converts all instances of 'args' in COMMAND_HANDLER routines
to use CMD_ARGV macro.
2009-11-17 11:38:07 -08:00
Zachary T Welch 7bf1a86e47 command_handler: change to 'argc' to CMD_ARGC
This patch converts all instances of 'argc' in COMMAND_HANDLER routines
to use CMD_ARGC.
2009-11-17 11:38:06 -08:00
Zachary T Welch dc1685ca25 move ARRAY_SIZE macro to types.h
The ARRAY_SIZE macro was defined in several target files, so move it
to types.h.

This patch also removes two other identical macros: DIM (from jtag.h)
and asizeof (from arm11.h).
2009-11-16 09:58:11 -08:00
Zachary T Welch a94748ec6d rename CEIL as DIV_ROUND_UP
Improves the name of this macro, moves it to types.h, and adds a block
of Doxygen comments to describe what it does.
2009-11-16 09:58:11 -08:00
Zachary T Welch 98723c4ecd command_context_t -> struct command_context
Remove misleading typedef and redundant suffix from struct command_context.
2009-11-13 13:25:47 -08:00
Zachary T Welch d0809ac060 scan_field_t -> struct scan_field
Remove useless structure typedef.
2009-11-13 11:58:04 -08:00
Zachary T Welch 42ef503d37 jtag_tap_t -> struct jtag_tap
Search and destroy the jtag_tap_t typedef.  This also cleans up a
layering violation, removing the declaration from types.h.
2009-11-13 11:58:04 -08:00
Zachary T Welch cfc4d5c6b7 use COMMAND_HANDLER macro to define all commands 2009-11-13 10:51:45 -08:00
Zachary T Welch ca594adb5a add const keyword to some APIs
Add 'const' keyword to 'char *' parameters to allow command handlers to
pass constant string arguments.  These changes allow the 'args' command
handler to be changed to 'const' in a subsequent patch.
2009-11-11 11:53:22 -08:00
Zachary T Welch db6c2871dd svf,xsvf,arm7_9_common: trim forard declarations
Remove forward declarations by reordering command registration.
2009-11-09 21:39:46 -08:00
Zachary T Welch 994a63c3fe src/{server,pld,svf,xsvf}: remove 'extern' keyword
Removes 'extern' keyword from function declarations in header filess.
2009-11-09 09:44:33 -08:00
David Brownell 0c4d5b8b1f XSVF: bugfix handling state paths
Implement XSVF support for detailed state path transitions,
by collecting sequences of XSTATE transitions into paths
and then calling pathmove().

It seems that the Xilinx tools want to force state-by-state
transitions instead of relying on the standardized SVF paths.
Like maybe there are XSVF tools not implementing SVF paths,
which are all that we support using svf_statemove().

So from IRPAUSE, instead of just issuing "XSTATE DRPAUSE"
they will issue XSTATES for each intermediate state: first
IREXIT2, then IRUPDATE, DRSELECT, DRCAPTURE, DREXIT1, and
finally DRPAUSE.  This works now.

Handling of paths that go *through* reset is a trifle dodgey,
but it should be safe.

Tested-by: Wookey <wookey@wookware.org>

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2009-10-29 12:42:41 -07:00
David Brownell 7556a93aed XSVF: use svf_add_statemove()
XSVF improvements:

 - Layer parts of XSVF directly over SVF, calling svf_add_statemove()
   instead of expecting jtag_add_statemove() to conform to the SVF/XSVF
   requirements (which it doesn't).

   This should improve XSTATE handling a lot; it removes most users of
   jtag_add_statemove(), and the comments about how it should really do
   what svf_add_statemove() does.

 - Update XSTATE logic to be a closer match to the XSVF spec.  The main
   open issue here is (still) that this implementation doesn't know how
   to build and submit paths from single-state transitions ... but now
   it will report that error case.

 - Update the User's Guide to mention the two utility scripts for
   working with XSVF, and to mention the five extension opcodes.

Handling of state transition paths is, overall, still a mess.  I think
they should all be specified as paths not unlike SVF uses, and compiled
to the bitstrings later ... so that we can actually make sense of the
paths.  (And see the extra clocks, detours through RUN, etc.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2009-10-20 20:04:36 -07:00