Re: [Openocd-development] [patch 0/7] ARM11 register handling

2009-11-24 Thread Øyvind Harboe
On Tue, Nov 24, 2009 at 1:14 AM, David Brownell davi...@pacbell.net wrote:
 On Monday 23 November 2009, Ųyvind Harboe wrote:
 Wow. :-)

 I hope that's not all you'll have to say.  ;)

The arm11 stuff needed a lot of work to be streamlined with the
rest of the code and I trust you to make good choices here if
the past is anything to judge by.

I'm sure there will be regressions with as many changes, but we have
a long way to go with the arm11 support, so we need a firm foundation
to build on. I expect regressions to be bugs rather than architectural with
your normal quality. The thing I would fear the most is stuff that
just happened to work today, like some convoluted path through the
JTAG state machine that just happend to pass through or evade a state...


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] =?ISO-8859-2?Q?Re: Re: What became of the generic LPC config script=??=

2009-11-24 Thread freddie_chopin
Użytkownik  oyvind.har...@zylin.com napisał:
Could you point me to the latest version?

http://lists.berlios.de/pipermail/openocd-development/2009-September/010849.html

Why a sudden resurrection?

4\/3!!
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] feroceon-based target bring-up issue

2009-11-24 Thread Albert ARIBAUD
Hi,

I am trying to bring-up an ED Mini V2, a feroceon-based board with no 
tRST/sRST signals available, only TCLK/TMS/TDI/TDO, and an Olimex 
ARM-USB-OCD.

This ED-Mini has a working U-boot flashed already (I am aiming at 
replacing this U-boot with a newer version).

To begin with, I've made a basic config file, containing only the two 
following lines:

 source [find tcl/interface/olimex-arm-usb-ocd.cfg]
 source [find tcl/target/feroceon.cfg]
 reset_config none

Using the latest git version of openocd, if I start it with the config 
above, it gives:

 $ src/openocd -f o.cfg
 Open On-Chip Debugger 0.4.0-dev-00171-gfd2c9fd (2009-11-24-08:48)
 For bug reports, read
 http://openocd.berlios.de/doc/doxygen/bugs.html
 trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain
 jtag_nsrst_delay: 200
 jtag_ntrst_delay: 200
 Info : clock speed 6000 kHz
 Info : JTAG tap: feroceon.cpu tap/device found: 0x49602093 (mfg: 0x049, part: 
 0x9602, ver: 0x4)
 Warn : JTAG tap: feroceon.cpu   UNEXPECTED: 0x49602093 (mfg: 0x049, part: 
 0x9602, ver: 0x4)
 Error: JTAG tap: feroceon.cpu  expected 1 of 1: 0x20a023d3 (mfg: 0x1e9, part: 
 0x0a02, ver: 0x2)
 Error: Trying to use configured scan chain anyway...
 Error: feroceon.cpu: IR capture error; saw 0x09 not 0x01
 Info : JTAG tap: feroceon.cpu tap/device found: 0x49602093 (mfg: 0x049, part: 
 0x9602, ver: 0x4)
 Warn : JTAG tap: feroceon.cpu   UNEXPECTED: 0x49602093 (mfg: 0x049, part: 
 0x9602, ver: 0x4)
 Error: JTAG tap: feroceon.cpu  expected 1 of 1: 0x20a023d3 (mfg: 0x1e9, part: 
 0x0a02, ver: 0x2)
 Error: Trying to use configured scan chain anyway...
 Error: feroceon.cpu: IR capture error; saw 0x09 not 0x01

(all jtag clock speeds give the same exact output)

The UNEXPECTED line worries me, but since errata for the 88F5182-A2 SoC 
says IDCODE should not be relied upon, I used the mechanism already in 
place in feroceon.cfg and preprended the following line in my config:

 source [find tcl/interface/olimex-arm-usb-ocd.cfg]
 set CPUTAPID 0x49602093
 source [find tcl/target/feroceon.cfg]
 reset_config none

Now I get the following output:

 $ src/openocd -f o.cfg
 Open On-Chip Debugger 0.4.0-dev-00171-gfd2c9fd (2009-11-24-08:48)
 For bug reports, read
 http://openocd.berlios.de/doc/doxygen/bugs.html
 trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain
 jtag_nsrst_delay: 200
 jtag_ntrst_delay: 200
 none separate
 Info : clock speed 6000 kHz
 Info : JTAG tap: feroceon.cpu tap/device found: 0x49602093 (mfg: 0x049, part: 
 0x9602, ver: 0x4)
 Error: feroceon.cpu: IR capture error; saw 0x09 not 0x01
 Info : JTAG tap: feroceon.cpu tap/device found: 0x49602093 (mfg: 0x049, part: 
 0x9602, ver: 0x4)
 Error: feroceon.cpu: IR capture error; saw 0x09 not 0x01

The target still resets at openocd launch. I first thought this was a 
default behavior for OpenOCD, but I still get the IR capture errors and 
in the telnet daemon, I cannot control the target:
 
 $ telnet localhost 
 Trying 127.0.0.1...
 Connected to localhost.localdomain (127.0.0.1).
 Escape character is '^]'.
 Open On-Chip Debugger
 targets
 TargetName Type   Endian TapNameState
 --  -- -- -- -- 
  0* feroceon.cpu   feroceon   little feroceon.cpu   unknown
 feroceon.cpu arp_examine
 Embedded ICE version 0
 unexpected Feroceon EICE version signature
 targets
 TargetName Type   Endian TapNameState
 --  -- -- -- -- 
  0* feroceon.cpu   feroceon   little feroceon.cpu   running
 halt
 Halt timed out, wake up GDB.
 timed out while waiting for target halted
 Runtime error, file command.c, line 491:
 
 targets
 TargetName Type   Endian TapNameState
 --  -- -- -- -- 
  0* feroceon.cpu   feroceon   little feroceon.cpu   running

At this point I am unsure if the issue is at the JTAG level itself or in 
the E-ICE scan chain level, or in the board itself.

I've tried using irscan and drscan for, e.g., re-reading the IDCODE 
manually, but it doesn't seem to work:

 irscan feroceon.cpu 0xe
 drscan feroceon.cpu 32 0
 
 drscan feroceon.cpu 32 0
 
 ...

But I believe jtag is not correctly reset when I try this, because jtag 
arp_init and jtag arp_init-reset both scan the chain and thus may not 
leave the TAP in reset mode -- by the way, a scan_chain does not reset 
the board (a jtag arp_init or arp_init-reset does).

Can someone give me pointers to where I should look (in OpenOCD) in 
order to progressively debug the situation?

Amicalement,
-- 
Albert.

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] What became of the generic LPC config script?

2009-11-24 Thread Øyvind Harboe
2009/11/24  freddie_cho...@op.pl:
 Użytkownik  oyvind.har...@zylin.com napisał:
Could you point me to the latest version?

 http://lists.berlios.de/pipermail/openocd-development/2009-September/010849.html

 Why a sudden resurrection?

Because I would like to see such a feature and never had occasion
to look into it before. Also at the time there were plenty of cooks
in the kitchen working on it, so I didn't follow.


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [patch 0/7] ARM11 register handling

2009-11-24 Thread David Brownell
On Tuesday 24 November 2009, Øyvind Harboe wrote:
 On Tue, Nov 24, 2009 at 1:14 AM, David Brownell davi...@pacbell.net wrote:
  On Monday 23 November 2009, Ųyvind Harboe wrote:
  Wow. :-)
 
  I hope that's not all you'll have to say.  ;)
 
 The arm11 stuff needed a lot of work to be streamlined with the
 rest of the code and I trust you to make good choices here if
 the past is anything to judge by.

In that case I'll commit the rest of this set, now that it
passes my basic testing.  The flash erase check behaves, so
do register modifications and arm reg, single step behaves.

Overall it's now looking and acting a lot more like any other
ARM core.  (And there's soon to be a place to hang that 
context-sensitive breakpoint stuff too...)

Plus this shrinks the size of arm11.c by 20%, measured by
line count ... that type of update I like a WHOLE lot!  :)


 I'm sure there will be regressions with as many changes, but we have
 a long way to go with the arm11 support, so we need a firm foundation
 to build on. I expect regressions to be bugs rather than architectural with
 your normal quality. The thing I would fear the most is stuff that
 just happened to work today, like some convoluted path through the
 JTAG state machine that just happend to pass through or evade a state...

I haven't touched that level of code, though I think that the
ARM11 code is doing some stuff it doesn't need to do.  This is
just putting the existing lowlevel JTAG ops into the same kind
of framework other ARMs use.

However, I *have* been testing with those new even shorter
JTAG paths I sent by a while ago ... which include the more
visible initialization, building the bit vectors from lists
of states instead of just being cryptic.

I heard about an FT2232 issue we may want to pay attention to:

  http://developer.intra2net.com/mailarchive/html/libftdi/2009/msg00292.html

That would affect such low-level things.  But for now I'm
content to not worry about such issues.  :)

- Dave

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] feroceon-based target bring-up issue

2009-11-24 Thread Albert ARIBAUD
David Brownell a écrit :
 On Tuesday 24 November 2009, Albert ARIBAUD wrote:
 Error: feroceon.cpu: IR capture error; saw 0x09 not 0x01
 
 jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id 
 $_CPUTAPID
^^^
 Does 0x03 behave?

I did investigate by fixing 0x3 directly in feroceon.cfg, and it does 
not improve:

 Error: IR capture error at bit 4, saw 0x09 not 0x...3

(and it does not change anything else -- this is consistent with the 
OpenOCD docs, which state that IR capture is for information only and 
has no functional impact.)

Actually, a combination that works (i.e., shows no IR capture error) is 
obtained by using -irlen 32 -ircapture 0x1 -irmask 0x3, but an IR length 
of 32 is inconsistent with the ARM/feroceon literature available (in 
which IR length is 4 bits). Besides, other OpenOCD users have working 
configs with feroceon.cfg as it is (on another board type and/or another 
JTAG probe type).

With that abnormal -irlen 32 -ircapture 0x1 -irmask 0x3, the behavior is 
different:

 $ src/openocd -f o.cfg
 Open On-Chip Debugger 0.4.0-dev-00171-gfd2c9fd (2009-11-24-08:48)
 For bug reports, read
 http://openocd.berlios.de/doc/doxygen/bugs.html
 trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain
 jtag_nsrst_delay: 200
 jtag_ntrst_delay: 200
 none separate
 Info : clock speed 6000 kHz
 Info : JTAG tap: feroceon.cpu tap/device found: 0x49602093 (mfg: 0x049, part: 
 0x9602, ver: 0x4)
 Info : Embedded ICE version 12
 Error: unexpected Feroceon EICE version signature

And the target seems to halt (no reaction on the U-boot serial console) 
but still appears running in the telnet interface, and still cannot be 
halted

Note that if I then do a ^C and launch openOCD again, the Unexpected 
Feroceon EICE version signature message does not appear again.

Amicalement,
-- 
Albert.
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] Openocd vrs Commercial jtag dongles

2009-11-24 Thread Liam Redmond (Rock Software)
 I was always intrigued by that FX2 GPIF stuff -- that's what you're
 talking about?

Yes, they call it GPIF when the 8051 is the master (this is the more
complicated mode!), they call it Slave FIFO when an external device (the
CPLD) is the master. The CPLD just reads and writes to a 16/8 bit bus pretty
much like it was a memory device. The 8051 is only used to setup the USB
configuration, after that it sits in a loop and does nothing. The CPLD has a
direct pipe to the USB data and everything can be controlled through USB
traffic.

 That's why I mentioned Cortex-M3.  There are a lot of those around;
 and GCC handles them quite nicely.  So does OpenOCD, for that matter!

I do like the Cortex-M3 I have designed a board already for another project
using a Luminary Micro Cortex device which has Ethernet on it and the newer
ones have USB OTG, I believe they are currently sampling a device with both
Ethernet and USB.

I'm using the FX2 primarily because it was on my desk from my last project
but also because it's a fully high speed device.

Liam.

- Original Message - 
From: David Brownell davi...@pacbell.net
To: openocd-development@lists.berlios.de
Cc: Liam Redmond (Rock Software) i...@rock-software.com
Sent: Monday, November 23, 2009 11:26 PM
Subject: Re: [Openocd-development] Openocd vrs Commercial jtag dongles


 On Monday 23 November 2009, Liam Redmond (Rock Software) wrote:
  Sadly, that also requires a lot of engineering expertise to write that

 Actually the hardware description is not as bad as you might first think,
 I
 have a prototype Xilinx CoolRunnerII CPLD hooked up to a Cypress high
 speed
 FX2, this effectively gives a direct pipe from the OpenOCD USB calls to
 the
 CPLD (via the FX2 slave interface).

 I was always intrigued by that FX2 GPIF stuff -- that's what you're
 talking about?  I think they did that to speed up IDE-to-FIFO data
 transfers, so the CPU wouldn't be involved.  On the other hand, any
 8051 is a turn-off for me.  :(

 That's why I mentioned Cortex-M3.  There are a lot of those around;
 and GCC handles them quite nicely.  So does OpenOCD, for that matter!

 - Dave



___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] feroceon-based target bring-up issue

2009-11-24 Thread David Brownell
On Tuesday 24 November 2009, Albert ARIBAUD wrote:
 I did investigate by fixing 0x3 directly in feroceon.cfg, and it does 
 not improve:
 
  Error: IR capture error at bit 4, saw 0x09 not 0x...3

Are you sure you didn't make the ircapture be 0x3,
instead of the irmask?  Because masking the two LSBs (0x3)
of 0x09 gives 0x01, the specified ircapture value.

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] feroceon-based target bring-up issue

2009-11-24 Thread Albert ARIBAUD
David Brownell a écrit :
 On Tuesday 24 November 2009, Albert ARIBAUD wrote:
 I did investigate by fixing 0x3 directly in feroceon.cfg, and it does 
 not improve:

 Error: IR capture error at bit 4, saw 0x09 not 0x...3
 
 Are you sure you didn't make the ircapture be 0x3,
 instead of the irmask?  Because masking the two LSBs (0x3)
 of 0x09 gives 0x01, the specified ircapture value.

Yes, I am sure. I triple-checked feroceon.cfg:

 jtag newtap $_CHIPNAME cpu -irlen 32 -ircapture 0x1 -irmask 0x3 -expected-id 
 $_CPUTAPID

This is what gave the results I gave in my previous post.

Amicalement,
-- 
Albert.
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] feroceon-based target bring-up issue

2009-11-24 Thread Albert ARIBAUD
Albert ARIBAUD a écrit :
 David Brownell a écrit :
 On Tuesday 24 November 2009, Albert ARIBAUD wrote:
 I did investigate by fixing 0x3 directly in feroceon.cfg, and it does 
 not improve:

 Error: IR capture error at bit 4, saw 0x09 not 0x...3
 Are you sure you didn't make the ircapture be 0x3,
 instead of the irmask?  Because masking the two LSBs (0x3)
 of 0x09 gives 0x01, the specified ircapture value.
 
 Yes, I am sure. I triple-checked feroceon.cfg:
 
 jtag newtap $_CHIPNAME cpu -irlen 32 -ircapture 0x1 -irmask 0x3 -expected-id 
 $_CPUTAPID
 
 This is what gave the results I gave in my previous post.

Added info: I tried putting the JTAG in BYPASS and then shift data 
through it, using the following commands:

 irscan feroceon.cpu 0xf
 drscan feroceon.cpu 32 0xffaa0055

Using the -irlen 32, the result is:

 C0E28618

... whatever value I shift in DR:

 drscan feroceon.cpu 32 0
 C0E28618
 drscan feroceon.cpu 32 0x
 C0E28618

So, obviously, -irlen 32 is not correct (that was to be expected).

Now with -irlen 4:

 irscan feroceon.cpu 0xf
 drscan feroceon.cpu 32 0xffaa0055
 FF5400AA
 drscan feroceon.cpu 32 0
 
 drscan feroceon.cpu 32 0x
 FFFE

That's way better, and seems to work as described by e.g. ARM9EJ-S TRM 
annex B.4: TDO is TDI with a 1-bit left shift, and MSB forced at 0.

So now I'm completely sure the right irlen setting is 4.

Still, I cannot talk to the target, and even trying to get IDCODE does 
not work -- weirder yet:

- doing an irscan feroceon.cpu 0xe right after my BYPASS test causes a 
target reboot;

- doing it after a jtag arp_init does not reboot, but then a drscan 
0x32 0 returns 0, which is not the IDCODE seen by OpenOCD.

Amicalement,
-- 
Albert.
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] How to single step without interrupts?

2009-11-24 Thread Thomas Kindler
Freddie Chopin wrote:
 Thomas Kindler pisze:
 Hi!

 When single stepping on a STM32, I'm constantly caught in interrupt 
 handler code.  This makes debugging almost impossible for non-trivial 
 programs with timer and other peripheral interrupts.

 I have seen that there's an cortex_m3 maskisr on/off command, but 
 it's awkward to use from eclipse.  There seems to be no way to issue 
 monitor commands to OpenOCD during a debug session, or even bind 
 commands to a GUI button (perhaps a nice feature for Zylin-CDT?).

 Is there a good way to tell OpenOCD to mask ISRs after hitting a 
 breakpoint/single-stepping, but re-enable interrupts on run?
 
 That's not your problem.

Unfortunately - it is ;)

 On STM32 when the core is halted (whatever was the reason) some 
 peripherals (including timers) continue to operate normally. This is a 
 good thing - imagine writing a software for SMSP and no possibility to 
 halt the chip - you'd have 50% chance of frying the coil and the switch 
 when the PWM would stop working. That's why when you stop your program 
 some peripherals keep working and keep sending interrupt signals, making 
 single stepping virtually impossible.

No, these are two different things. The timer and PWM outputs may (and 
should) continue to work, I just don't want to see their interrupts.

This is exactly what cortex_m3 maskisr on/off does.

We also have some commercial JTAG interfaces in our company, and Hitex' 
HiTop, for example, offers a dialog to selectively disable interrupts 
while stepping.  The timer is left running, but doesn't fire interrupts.

After pressing run, interrupts are re-enabled automatically.

So, as David asked: yes, maskisr does solve my problem. It only lacks 
automation.

I would like to use some OpenOCD GDB events like Oyvind suggested.. 
but _how_ to do it?!

My goal, after all, is to replace our existing commercial toolchain with 
CodeSourcery/Eclipse/armgnueclipse/OpenOCD without loosing too much comfort.

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH 0/8] unify usb device opening

2009-11-24 Thread Zach Welch
On Thu, 2009-11-19 at 14:53 -0800, Zachary T Welch wrote:
 Hi all,
 
 Add jtag/usb_common.[ch] to hold routines shared between the USB JTAG
 interface drivers.  
 
 This series adds the first helper, jtag_usb_open that unifies the steps
 required to probe the USB busses and devices, matching vid/pids, and
 opening the selected device in the jtag_usb_open helper.  All of the
 driver open routines look much cleaner as a result.
 
 This paves the road for more jtag_usb_* helpers and abstraction, which
 should pave the way for switching to libusb-1.0 when completed.

Unless there are any objections, I am going to push this series today. 

--Z
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PATCH 0/8] unify usb device opening

2009-11-24 Thread David Brownell
On Tuesday 24 November 2009, Zach Welch wrote:
 Unless there are any objections, I am going to push this series today. 

Reads OK.  Doesn't affect FT2232 support.  I'd say go for it.

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] Document build broken when src != build

2009-11-24 Thread Zach Welch
On Sun, 2009-11-22 at 10:17 +0100, Øyvind Harboe wrote:
 I can no longer build docs when src != build. I believe this is trivially
 reproducible and that the breakage is relatively recent(a month
 or so).
 
 Or... perhaps I'm missing some tool on my laptop?
 
 make docs
 make doxygen
 
 = both fail
 
 make doxygen/latex/refman.pdf
 make[1]: Entering directory `/home/oyvind/workspace/build'
 make[1]: *** No rule to make target `doxygen/latex/refman.pdf'.  Stop.

Try the attached patch.  If this fixes it, I'll push it along.

--Z
From 9a004d41b0d491d1f9ce6aac2d677c0a595f5df9 Mon Sep 17 00:00:00 2001
From: Zachary T Welch z...@superlucidity.net
Date: Tue, 24 Nov 2009 08:59:45 -0800
Subject: [PATCH] fix doxygen build

Update build rules to skip the PDF unless the TeX has been created.
Also, fixes a warning regarding pattern rules being a GNU make trick.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 Makefile.am |   11 ---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index c067712..fab4704 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,9 +35,14 @@ THE_MANUAL = doxygen/latex/refman.pdf
 doxygen::
 	$(MAKE) Doxyfile
 	doxygen Doxyfile 21 | perl $(srcdir)/tools/logger.pl  doxygen.log
-	$(MAKE) $(THE_MANUAL)
-
-%.pdf: %.tex
+	@if [ -f doxygen/latex/refman.tex ]; then \
+		echo Creating $(THE_MANUAL)...; \
+		$(MAKE) $(THE_MANUAL); \
+	else \
+		echo Skipping Doxygen PDF...; \
+	fi
+
+$(THE_MANUAL): %.pdf: %.tex
 	-cd $$(dirname $*)  pdflatex $$(basename $*)
 	-cd $$(dirname $*)  pdflatex $$(basename $*)
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] [PUSHED 8/8] unify usb device opening

2009-11-24 Thread Zach Welch
On Tue, 2009-11-24 at 08:38 -0800, David Brownell wrote:
 On Tuesday 24 November 2009, Zach Welch wrote:
  Unless there are any objections, I am going to push this series today. 
 
 Reads OK.  Doesn't affect FT2232 support.  I'd say go for it.

And with this feedback, I've pushed them out.  Share and Enjoy. :)

--Z
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] How to single step without interrupts?

2009-11-24 Thread Øyvind Harboe
OpenOCD supports this, now all you have to do is:

- Read up on gdb events: gdb-start, gdb-halt.

- Use the source, get it to work, fix the bugs and submit a patch
w/documentation
and code fixes...

:-)

-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] Styleguide additions for embedded hosts

2009-11-24 Thread Øyvind Harboe
I'll push this if I don't hear anything.

The code adheres to these rules at this point pretty much.
There are a few sites that could be a bit better, but I don't
fear that there are plentiful of bad examples that are
copied and pasted.

-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
From fabad46f798579c9a18e82c5fa253e8ae77d0550 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?=C3=98yvind=20Harboe?= oyvind.har...@zylin.com
Date: Tue, 24 Nov 2009 20:26:40 +0100
Subject: [PATCH] styleguide: add some embedded style rules.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

Embedded and pthreads rely on modest and predictable
stack usage.

Signed-off-by: Øyvind Harboe oyvind.har...@zylin.com
---
 doc/manual/style.txt |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/doc/manual/style.txt b/doc/manual/style.txt
index b4d0216..0ba86c2 100644
--- a/doc/manual/style.txt
+++ b/doc/manual/style.txt
@@ -40,6 +40,12 @@ OpenOCD's Jim/TCL code as well.
 This page contains guidelines for writing new C source code for the
 OpenOCD project.
 
+...@section styleembedded Embedded hosts
+
+- allocate working space dynamically(malloc) rather than
+using lots of stack. non-MMU(embedded) hosts and pthreads
+rely on modest and predictable stack usage.
+
 @section styleformat Formatting Guide
 
 - remove any trailing white space at the end of lines.
@@ -80,6 +86,8 @@ Finally, try to avoid lines of code that are longer than than 72-80 columns:
 - designated initializers (@{ .field = value @})
 - variables declarations should occur at the point of first use
 - new block scopes for selection and iteration statements
+- do not use dynamic arrays. Dynamic arrays are problematic with
+embedded/non-MMU targets, and also somewhat with pthreads.
 
 @section styletypes Type Guidelines
 - use native types (@c int or @c unsigned) if the type is not important
-- 
1.6.3.3

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH] improve alloc_vprintf

2009-11-24 Thread Andreas Fritiofson
The previous implementation was unnecessarily complex. Get rid of the loops,
let vsnprintf() tell us directly how much storage we need and allocate that. A
second pass writes the actual string. Also add a va_end() that was missing.
This should be much faster for large strings and less wasteful for small ones.

A quirk that has been retained is that some callers patch in a newline at the
end of the returned string and depend on alloc_vprintf to allocate at least
one byte extra.

Signed-off-by: Andreas Fritiofson andreas.fritiof...@gmail.com
---
This time without the copy/paste error. Thanks Zach for spotting it.
---
 src/helper/log.c |   43 ---
 1 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/src/helper/log.c b/src/helper/log.c
index caaed42..2dcf7bb 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -395,37 +395,26 @@ int log_remove_callback(log_callback_fn fn, void *priv)
 /* return allocated string w/printf() result */
 char *alloc_vprintf(const char *fmt, va_list ap)
 {
-   /* no buffer at the beginning, force realloc to do the job */
-   char *string = NULL;
-
-   /* start with buffer size suitable for typical messages */
-   int size = 128;
-
-   for (;;)
-   {
-   char *t = string;
-   va_list ap_copy;
-   int ret;
-   string = realloc(string, size);
-   if (string == NULL)
-   {
-   if (t != NULL)
-   free(t);
-   return NULL;
-   }
+   va_list ap_copy;
+   int len;
+   char *string;
 
-   va_copy(ap_copy, ap);
+   /* determine the length of the buffer needed */
+   va_copy(ap_copy, ap);
+   len = vsnprintf(NULL, 0, fmt, ap_copy);
+   va_end(ap_copy);
 
-   ret = vsnprintf(string, size, fmt, ap_copy);
-   /* NB! The result of the vsnprintf() might be an *EMPTY* 
string! */
-   if ((ret = 0)  ((ret + 1)  size))
-   break;
+   /* allocate and make room for terminating zero. */
+   /* FIXME: The old version always allocated at least one byte extra and
+* other code depend on that. They should be probably be fixed, but for
+* now reserve the extra byte. */
+   string = malloc(len + 2);
+   if (string == NULL)
+   return NULL;
 
-   /* there was just enough or not enough space, allocate more in 
the next round */
-   size *= 2; /* double the buffer size */
-   }
+   /* do the real work */
+   vsnprintf(string, len + 1, fmt, ap);
 
-   /* the returned buffer is by principle guaranteed to be at least one 
character longer */
return string;
 }
 
-- 
1.6.3.3

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] Styleguide additions for embedded hosts

2009-11-24 Thread Zach Welch
On Tue, 2009-11-24 at 20:52 +0100, Øyvind Harboe wrote:
 I'll push this if I don't hear anything.
 
 The code adheres to these rules at this point pretty much.
 There are a few sites that could be a bit better, but I don't
 fear that there are plentiful of bad examples that are
 copied and pasted.

You're using terminology incorrectly, as a dynamic arrays include those
created by malloc().  I think you intend to add the following rule
(unless I've screwed it up too):

- Use malloc to create dynamic arrays; do @b not use @c alloca() or
create variable-length arrays on the stack.

Also, I do not like the idea of adding a new section for embedded hosts
with only one item in it.  I think the subject of Embeddeding Open
needs to be addressed more comprehensively in its own section.  There
are numerous issues that deserve to be documented, and the Style Guide
is not the right place to address any of these concerns directly.

--Z
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] Styleguide additions for embedded hosts

2009-11-24 Thread Øyvind Harboe
On Tue, Nov 24, 2009 at 9:34 PM, Zach Welch z...@superlucidity.net wrote:
 On Tue, 2009-11-24 at 20:52 +0100, Øyvind Harboe wrote:
 I'll push this if I don't hear anything.

 The code adheres to these rules at this point pretty much.
 There are a few sites that could be a bit better, but I don't
 fear that there are plentiful of bad examples that are
 copied and pasted.

 You're using terminology incorrectly, as a dynamic arrays include those
 created by malloc().  I think you intend to add the following rule
 (unless I've screwed it up too):

 - Use malloc to create dynamic arrays; do @b not use @c alloca() or
 create variable-length arrays on the stack.

Good point.


 Also, I do not like the idea of adding a new section for embedded hosts
 with only one item in it.  I think the subject of Embeddeding Open
 needs to be addressed more comprehensively in its own section.  There
 are numerous issues that deserve to be documented, and the Style Guide
 is not the right place to address any of these concerns directly.

Where then?


 --Z




-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] How to single step without interrupts?

2009-11-24 Thread Øyvind Harboe
On Tue, Nov 24, 2009 at 10:11 PM, Andreas Fritiofson
andreas.fritiof...@gmail.com wrote:
 On Tue, Nov 24, 2009 at 1:21 AM, Thomas Kindler mail+...@t-kindler.de wrote:
 Hi!

 When single stepping on a STM32, I'm constantly caught in interrupt
 handler code.  This makes debugging almost impossible for non-trivial
 programs with timer and other peripheral interrupts.

 I have seen that there's an cortex_m3 maskisr on/off command, but it's
 awkward to use from eclipse.  There seems to be no way to issue monitor
 commands to OpenOCD during a debug session, or even bind commands to a
 GUI button (perhaps a nice feature for Zylin-CDT?).

 Is there a good way to tell OpenOCD to mask ISRs after hitting a
 breakpoint/single-stepping, but re-enable interrupts on run?


 Yes. Use User-defined Command Hooks:
 http://sourceware.org/gdb/current/onlinedocs/gdb/Hooks.html#Hooks

 Set up your hooks such that mon cortex_m3 maskisr on is executed
 before any step command, and mon cortex_m3 maskisr off is executed
 after.

 define hook-step
 mon cortex_m3 maskisr on
 end

 define hookpost-step
 mon cortex_m3 maskisr off
 end

 Same for the next command and maybe others too (stepi, nexti). Only
 problem is that openocd is spamming quite a lot at every step.

So does this mean that we should probably remove some hooks in OpenOCD
and add a tip?


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] How to single step without interrupts?

2009-11-24 Thread Øyvind Harboe
2009/11/24 David Brownell davi...@pacbell.net:
 problem is that openocd is spamming quite a lot at every step.

 Suggesting that there should be a quiet command, maybe?

A variant on capture?

mon capture {lkasjdfklsjadfjsad}




-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 ARM11 XScale Cortex
JTAG debugger and flash programmer
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


Re: [Openocd-development] Styleguide additions for embedded hosts

2009-11-24 Thread Zach Welch
On Tue, 2009-11-24 at 13:21 -0800, David Brownell wrote:
 On Tuesday 24 November 2009, Zach Welch wrote:
   I think the subject of Embeddeding Open
  needs to be addressed more comprehensively in its own section. 
 
 I'm not disagreeing ... but what would be in that section?
 Some of the folk who've done some of this should chime in...

For the record, I think it becomes important to distinguish between
light and heavy embedded.  Right now, we can support the later by
way of embedded ARM (uC)Linux or eCos.  The former requires addressing
the points you list below.  Each requires its own type of documentation.
For now, $SUBJECT relates to the heavier platforms.

 Just for kicks, I started a cross-compile for a Cortex-M3,
 and got this error from configure:
 
  configure: error: C compiler cannot create executables
 
 Hrm, OK, I'll try some different flags then, this was just
 for test building, but ... maybe stuff like that should be
 covered.
 
 I suspect for real embedded targets, which is to say not
 just hosted on an embedded Linux, there will need to be
 build environment tweaks like:
 
  - Letting some other component finish linking the
flash image.
 
  - Selective build/link for cpu, flash, and jtag drivers.
A Thumb2 build for Cortex-A8 (not M3!) involved over
half a meg of code, which is way too huge to fit into
its portion of a 128 KB flash.  
 
  - Facilitating custom JTAG (mini?) drivers.
 
  - Disabling filesystem-dependent commands, since there
is no file system!
 
  - Allowing different ways to provide image data,
like through USB endpoints or TCP sockets
 
 That's for starters.  I suppose another thing to address
 is what is meant by an embedded host.

Yup.  There is a lot of work to do to provide these things in the
general case, and these are worthy goals to consider.  Today, we have
the ZY1000's eCos-related support, but we should be considering other
use cases with even less resources.  Personally, I think strategic
documentation will be pivotal to executing such a project, as the issues
merit full enumeration and prioritizing... outside of the style guide or
this thread.

For now, feel free to add a section to the TODO list with your points,
as I do not recall the above existing there with such specificity.

Cheers,

Zach

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [SERIES 0/6:0/84] command registration

2009-11-24 Thread Zach Welch
Hi all,

I have finished my series to convert the tree to use the improved
command registration methodology.  I apologize for the number of patches
in these series; however, only a handful of patches are bigger than 10K,
and most are just boring semi-mechanical transformations.

The following benefits can be expected from this work:
- Command registration is much simpler and easier to read and update. 
- All registrations now get proper error checking.
- Eliminates redundant calls to register command: smaller binaries.
- Improves 'help' display and add new 'usage' command.
- Changes all register_commands callbacks into command_registration *'s.

To facilitate fast and painless review, the patches have been grouped
into sequential series.  These will be posted shortly under this summary
message.  They will contain the following sets of changes:

1) Core upgrades: 
  - updates the core command registration routines,
  - provides the new facilities used in the subsequent series,
- convert registration to use struct command_registration arrays
- allows batch registration, better error checking, and more
- extended to allow command usage information to be provided
  - rewrites the 'unknown' function in C
- provides proper support for calling N-deep nested commands,
- removes the magic to try blah blah as blah_blah

2) Initial conversions:
  - converts helper and top-level modules to use new registration,
  - demonstrates command chaining possibilities in hello.c,
  - updates server and pld modules,
  - removes register_callbacks from pld_device,

3) Update JTAG module: 
  - convert each module to use new registration,
  - remove jtag_interface callback,

4) Update Flash module: 
  - convert each moduleto use new registration,
  - remove flash_driver and nand_controller callbacks,

5) Update Target module:
  - convert each moduleto use new registration, 
  - remove target_type callbacks,
  - remove etm_capture_driver callbacks,

6) Updates made possible/easier after series 1-5:
  - integrate Jim command handlers with command_registration records
  - add support for scripts to update command usage information
  - improve formatting display help output by rewriting cmd_help in C
  - moves 'hello' and 'foo' commands to dummy and faux drivers,
  - add a new 'testee' target driver, which passes 'init' okay,
  - cleanup log initialization; support OPENOCD_DEBUG_LEVEL env var,

Without feedback that holds me back, I will push these when I see fit,
so please consider pulling this tree and testing it for regressions:

   Fetch URL: git://repo.or.cz/openocd/ztw.git

Let me know what I have missed, or find out when it hits the tree

Cheers,

Zach
___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 01/12] improve startup tcl scripts

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Fix a couple of layering violations missed in the last round.
Add missing comment headers.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/startup.tcl |4 
 src/jtag/startup.tcl   |   15 +++
 src/server/startup.tcl |2 ++
 src/target/startup.tcl |   18 +++---
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl
index fc84943..845198a 100644
--- a/src/helper/startup.tcl
+++ b/src/helper/startup.tcl
@@ -61,10 +61,6 @@ proc unknown {args} {
return -code error Unknown command: $args
 }
 
-proc new_target_name { } {
-   return [target number [expr [target count] - 1 ]]
-}
-
 # Try flipping / and \ to find file if the filename does not
 # match the precise spelling
 proc find {filename} {
diff --git a/src/jtag/startup.tcl b/src/jtag/startup.tcl
index 999f5d0..ab215ba 100644
--- a/src/jtag/startup.tcl
+++ b/src/jtag/startup.tcl
@@ -9,6 +9,21 @@ proc jtag_init {} {
}
 }
 
+# This reset logic may be overridden by board/target/... scripts as needed
+# to provide a reset that, if possible, is close to a power-up reset.
+#
+# Exit requirements include:  (a) JTAG must be working, (b) the scan
+# chain was validated with jtag arp_init (or equivalent), (c) nothing
+# stays in reset.  No TAP-specific scans were performed.  It's OK if
+# some targets haven't been reset yet; they may need TAP-specific scans.
+#
+# The mode values include:  halt, init, run (from reset command);
+# startup (at OpenOCD server startup, when JTAG may not yet work); and
+# potentially more (for reset types like cold, warm, etc)
+proc init_reset { mode } {
+   jtag arp_init-reset
+}
+
 #
 
 # TODO: power_restore and power_dropout are currently neither
diff --git a/src/server/startup.tcl b/src/server/startup.tcl
index 677bb2d..7801d1b 100644
--- a/src/server/startup.tcl
+++ b/src/server/startup.tcl
@@ -1,3 +1,5 @@
+# Defines basic Tcl procs for OpenOCD server modules
+
 # Handle GDB 'R' packet. Can be overriden by configuration script,
 # but it's not something one would expect target scripts to do
 # normally
diff --git a/src/target/startup.tcl b/src/target/startup.tcl
index d480f33..b597b84 100644
--- a/src/target/startup.tcl
+++ b/src/target/startup.tcl
@@ -1,21 +1,9 @@
-#
+# Defines basic Tcl procs for OpenOCD target module
 
-# This reset logic may be overridden by board/target/... scripts as needed
-# to provide a reset that, if possible, is close to a power-up reset.
-#
-# Exit requirements include:  (a) JTAG must be working, (b) the scan
-# chain was validated with jtag arp_init (or equivalent), (c) nothing
-# stays in reset.  No TAP-specific scans were performed.  It's OK if
-# some targets haven't been reset yet; they may need TAP-specific scans.
-#
-# The mode values include:  halt, init, run (from reset command);
-# startup (at OpenOCD server startup, when JTAG may not yet work); and
-# potentially more (for reset types like cold, warm, etc)
-proc init_reset { mode } {
-   jtag arp_init-reset
+proc new_target_name { } {
+   return [target number [expr [target count] - 1 ]]
 }
 
-
 global in_process_reset
 set in_process_reset 0
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 05/12] add register_commands for batch registration

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

The register_commands API takes multiple commands in one call, allowing
modules to declare and pass a much simpler (and more explicit) array of
command_registration records.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c |   17 +
 src/helper/command.h |   19 +++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 3df60b6..51b3f9f 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -302,6 +302,23 @@ struct command* register_command(struct command_context 
*context,
return c;
 }
 
+int register_commands(struct command_context *cmd_ctx, struct command *parent,
+   const struct command_registration *cmds)
+{
+   unsigned i;
+   for (i = 0; cmds[i].name; i++)
+   {
+   struct command *c = register_command(cmd_ctx, parent, cmds + i);
+   if (NULL != c)
+   continue;
+
+   for (unsigned j = 0; j  i; j++)
+   unregister_command(cmd_ctx, parent, cmds[j].name);
+   return ERROR_FAIL;
+   }
+   return ERROR_OK;
+}
+
 int unregister_all_commands(struct command_context *context,
struct command *parent)
 {
diff --git a/src/helper/command.h b/src/helper/command.h
index b57ca75..1afaeea 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -201,6 +201,9 @@ struct command_registration {
const char *help;
 };
 
+/// Use this as the last entry in an array of command_registration records.
+#define COMMAND_REGISTRATION_DONE { .name = NULL }
+
 /**
  * Register a command @c handler that can be called from scripts during
  * the execution @c mode specified.
@@ -231,6 +234,22 @@ struct command* register_command(struct command_context 
*cmd_ctx,
})
 
 /**
+ * Register one or more commands in the specified context, as children
+ * of @c parent (or top-level commends, if NULL).
+ *
+ * @param cmd_ctx The command_context in which to register the command.
+ * @param parent Register this command as a child of this, or NULL to
+ * register a top-level command.
+ * @param cmds Pointer to an array of command_registration records that
+ * contains the desired command parameters.  The last record must have
+ * NULL for all fields.
+ * @returns ERROR_OK on success; ERROR_FAIL if any registration fails.
+ */
+int register_commands(struct command_context *cmd_ctx, struct command *parent,
+   const struct command_registration *cmds);
+
+
+/**
  * Unregisters command @c name from the given context, @c cmd_ctx.
  * @param cmd_ctx The context of the registered command.
  * @param parent The parent of the given command, or NULL.
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 04/12] add struct command_registration

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Add a structure to encapsulate command registration information, rather
than passing them all as parameters.  Enables further API changes that
require additional required or optional parameters.

Updates the register_command API and COMMAND_REGISTER macro to use it,
along with their documentation.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c |   17 +--
 src/helper/command.h |   51 ++---
 2 files changed, 45 insertions(+), 23 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 0561c6c..3df60b6 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -263,13 +263,12 @@ static void command_free(struct command *c)
 }
 
 struct command* register_command(struct command_context *context,
-   struct command *parent, const char *name,
-   command_handler_t handler, enum command_mode mode,
-   const char *help)
+   struct command *parent, const struct command_registration *cr)
 {
-   if (!context || !name)
+   if (!context || !cr-name)
return NULL;
 
+   const char *name = cr-name;
struct command **head = command_list_for_parent(context, parent);
struct command *c = command_find(*head, name);
if (NULL != c)
@@ -279,7 +278,7 @@ struct command* register_command(struct command_context 
*context,
return c;
}
 
-   c = command_new(context, parent, name, handler, mode, help);
+   c = command_new(context, parent, name, cr-handler, cr-mode, cr-help);
/* if allocation failed or it is a placeholder (no handler), we're done 
*/
if (NULL == c || NULL == c-handler)
return c;
@@ -762,8 +761,12 @@ int help_add_command(struct command_context *cmd_ctx, 
struct command *parent,
if (NULL == nc)
{
// add a new command with help text
-   nc = register_command(cmd_ctx, parent, cmd_name,
-   NULL, COMMAND_ANY, help_text);
+   struct command_registration cr = {
+   .name = cmd_name,
+   .mode = COMMAND_ANY,
+   .help = help_text,
+   };
+   nc = register_command(cmd_ctx, parent, cr);
if (NULL == nc)
{
LOG_ERROR(failed to add '%s' help text, cmd_name);
diff --git a/src/helper/command.h b/src/helper/command.h
index 25c0501..b57ca75 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -177,13 +177,9 @@ struct command
  */
 char *command_name(struct command *c, char delim);
 
-/**
- * Register a command @c handler that can be called from scripts during
- * the execution @c mode specified.
- *
- * If @c parent is non-NULL, the new command will be registered as a
- * sub-command under it; otherwise, it will be available as a top-level
- * command.
+/*
+ * Commands should be registered by filling in one or more of these
+ * structures and passing them to register_command().
  *
  * A conventioal format should be used for help strings, to provide both
  * usage and basic information:
@@ -191,25 +187,48 @@ char *command_name(struct command *c, char delim);
  * @options@ ... - some explanation text
  * @endcode
  *
- * @param cmd_ctx The command_context in which to register the command.
- * @param parent Register this command as a child of this, or NULL to
- * register a top-level command.
  * @param name The name of the command to register, which must not have
- * been registered previously.
+ * been registered previously in the intended context.
  * @param handler The callback function that will be called.  If NULL,
  * then the command serves as a placeholder for its children or a script.
  * @param mode The command mode(s) in which this command may be run.
  * @param help The help text that will be displayed to the user.
+ */
+struct command_registration {
+   const char *name;
+   command_handler_t handler;
+   enum command_mode mode;
+   const char *help;
+};
+
+/**
+ * Register a command @c handler that can be called from scripts during
+ * the execution @c mode specified.
+ *
+ * If @c parent is non-NULL, the new command will be registered as a
+ * sub-command under it; otherwise, it will be available as a top-level
+ * command.
+ *
+ * @param cmd_ctx The command_context in which to register the command.
+ * @param parent Register this command as a child of this, or NULL to
+ * register a top-level command.
+ * @param rec A command_registration record that contains the desired
+ * command parameters.
  * @returns The new command, if successful; otherwise, NULL.
  */
 struct command* register_command(struct command_context *cmd_ctx,
-   struct command *parent, const char *name,
-   command_handler_t handler, enum 

[Openocd-development] [PATCH 09/12] add command registration chaining

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Adds the ability to chain registration structures.  Modules can define a
command with the 'chain' and 'num_chain' fields defined in their
registration table, and the register_commands() function will initialize
these commands.  If the registration record creates a new command, then
the chained commands are created under it; otherwise, they are created
in the same context as the other commands (i.e. the parent argument).

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c |   30 --
 src/helper/command.h |   15 +--
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 9cc996c..b81d2d1 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -331,18 +331,36 @@ struct command* register_command(struct command_context 
*context,
 int register_commands(struct command_context *cmd_ctx, struct command *parent,
const struct command_registration *cmds)
 {
+   int retval = ERROR_OK;
unsigned i;
-   for (i = 0; cmds[i].name; i++)
+   for (i = 0; cmds[i].name || cmds[i].chain; i++)
{
-   struct command *c = register_command(cmd_ctx, parent, cmds + i);
-   if (NULL != c)
-   continue;
+   const struct command_registration *cr = cmds + i;
 
+   struct command *c = NULL;
+   if (NULL != cr-name)
+   {
+   c = register_command(cmd_ctx, parent, cr);
+   if (NULL == c)
+   {
+   retval = ERROR_FAIL;
+   break;
+   }
+   }
+   if (NULL != cr-chain)
+   {
+   struct command *p = c ? : parent;
+   retval = register_commands(cmd_ctx, p, cr-chain);
+   if (ERROR_OK != retval)
+   break;
+   }
+   }
+   if (ERROR_OK != retval)
+   {
for (unsigned j = 0; j  i; j++)
unregister_command(cmd_ctx, parent, cmds[j].name);
-   return ERROR_FAIL;
}
-   return ERROR_OK;
+   return retval;
 }
 
 int unregister_all_commands(struct command_context *context,
diff --git a/src/helper/command.h b/src/helper/command.h
index 7baa92d..6e3e93a 100644
--- a/src/helper/command.h
+++ b/src/helper/command.h
@@ -202,10 +202,18 @@ struct command_registration {
const char *help;
/// a string listing the options and arguments, required or optional
const char *usage;
+
+   /**
+* If non-NULL, the commands in @c chain will be registered in
+* the same context and scope of this registration record.
+* This allows modules to inherit lists commands from other
+* modules.
+*/
+   const struct command_registration *chain;
 };
 
 /// Use this as the last entry in an array of command_registration records.
-#define COMMAND_REGISTRATION_DONE { .name = NULL }
+#define COMMAND_REGISTRATION_DONE { .name = NULL, .chain = NULL }
 
 /**
  * Register a command @c handler that can be called from scripts during
@@ -238,7 +246,10 @@ struct command* register_command(struct command_context 
*cmd_ctx,
 
 /**
  * Register one or more commands in the specified context, as children
- * of @c parent (or top-level commends, if NULL).
+ * of @c parent (or top-level commends, if NULL).  In a registration's
+ * record contains a non-NULL @c chain member and name is NULL, the
+ * commands on the chain will be registered in the same context.
+ * Otherwise, the chained commands are added as children of the command.
  *
  * @param cmd_ctx The command_context in which to register the command.
  * @param parent Register this command as a child of this, or NULL to
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 07/12] command: use register_commands for handlers

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() to register low-level command handlers,
adding a builtin_command_handlers declaration that is easy to understand.
Splits help and usage information into their appropriate fields.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c |   51 +
 1 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index df4667b..28952fd 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -900,6 +900,39 @@ COMMAND_HANDLER(handle_sleep_command)
return ERROR_OK;
 }
 
+static const struct command_registration command_builtin_handlers[] = {
+   {
+   .name = add_help_text,
+   .handler = handle_help_add_command,
+   .mode = COMMAND_ANY,
+   .help = add new command help text,
+   .usage = command [...] help_text],
+   },
+   {
+   .name = sleep,
+   .handler = handle_sleep_command,
+   .mode = COMMAND_ANY,
+   .help = sleep for n milliseconds.  
+   \busy\ will busy wait,
+   .usage = n [busy],
+   },
+   {
+   .name = help,
+   .handler = handle_help_command,
+   .mode = COMMAND_ANY,
+   .help = show built-in command help,
+   .usage = [command_name ...],
+   },
+   {
+   .name = usage,
+   .handler = handle_usage_command,
+   .mode = COMMAND_ANY,
+   .help = show command usage,
+   .usage = [command_name ...],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 struct command_context* command_init(const char *startup_tcl)
 {
struct command_context* context = malloc(sizeof(struct 
command_context));
@@ -959,10 +992,7 @@ struct command_context* command_init(const char 
*startup_tcl)
interp-cb_fflush = openocd_jim_fflush;
interp-cb_fgets = openocd_jim_fgets;
 
-   COMMAND_REGISTER(context, NULL, add_help_text,
-   handle_help_add_command, COMMAND_ANY,
-   command [...] help_text] - 
-   add new command help text);
+   register_commands(context, NULL, command_builtin_handlers);
 
 #if !BUILD_ECOSBOARD
Jim_EventLoopOnLoad(interp);
@@ -976,19 +1006,6 @@ struct command_context* command_init(const char 
*startup_tcl)
}
Jim_DeleteAssocData(interp, context);
 
-   COMMAND_REGISTER(context, NULL, sleep,
-   handle_sleep_command, COMMAND_ANY,
-   n [busy] - sleep for n milliseconds. 
-   \busy\ means busy wait);
-
-   COMMAND_REGISTER(context, NULL, help,
-   handle_help_command, COMMAND_ANY,
-   [command_name ...] - show built-in command help);
-   COMMAND_REGISTER(context, NULL, usage,
-   handle_usage_command, COMMAND_ANY,
-   [command_name ...] | 
-   show command usage);
-
return context;
 }
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [SERIES 2/6:0/9] update misc. command registration

2009-11-24 Thread zw
Hi all,

This series updates various modules to use the new command registration:

- hello: improve the examples for developers to use
- openocd, ioutil, log, server: some of the easiest conversions
- pld: a microcosm of the subsequent three patch series
  - convert tree to use new registration
  - change register_commands callback to command_registration pointer,

Cheers,

Zach

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 12/12] rewrite 'unknown' command dispatching in C

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Rewrite the magical 'unknown' command in C as a Jim handler, allowing
it to dispatch commands to any level in the tree.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c   |   65 
 src/helper/startup.tcl |   17 
 2 files changed, 65 insertions(+), 17 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 54bfb96..dd10965 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -853,6 +853,70 @@ COMMAND_HANDLER(handle_usage_command)
return CALL_COMMAND_HANDLER(command_help_show, c, 0, false);
 }
 
+static int command_unknown_find(unsigned argc, Jim_Obj *const *argv,
+   struct command *head, struct command **out)
+{
+   if (0 == argc)
+   return argc;
+   struct command *c = command_find(head, Jim_GetString(argv[0], NULL));
+   if (NULL == c)
+   return argc;
+   *out = c;
+   return command_unknown_find(--argc, ++argv, (*out)-children, out);
+}
+
+static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+{
+   const char *cmd_name = Jim_GetString(argv[0], NULL);
+   script_debug(interp, cmd_name, argc - 1, argv + 1);
+
+   struct command_context *cmd_ctx = current_command_context();
+   struct command *c = cmd_ctx-commands;
+   int remaining = command_unknown_find(argc - 1, argv + 1, c, c);
+   // if nothing could be consumed, then it's really an unknown command
+   if (remaining == argc - 1)
+   {
+   const char *cmd = Jim_GetString(argv[1], NULL);
+   LOG_ERROR(Unknown command:\n  %s, cmd);
+   return JIM_OK;
+   }
+
+   bool found = true;
+   Jim_Obj *const *start;
+   unsigned count;
+   if (c-handler)
+   {
+   // include the command name in the list
+   count = remaining + 1;
+   start = argv + (argc - remaining - 1);
+   }
+   else
+   {
+   c = command_find(cmd_ctx-commands, help);
+   if (NULL == c)
+   {
+   LOG_ERROR(unknown command, but help is missing too);
+   return JIM_ERR;
+   }
+   count = argc - remaining;
+   start = argv;
+   found = false;
+   }
+
+   unsigned nwords;
+   const char **words = script_command_args_alloc(count, start, nwords);
+   if (NULL == words)
+   return JIM_ERR;
+
+   int retval = run_command(cmd_ctx, c, words, nwords);
+
+   script_command_args_free(words, nwords);
+
+   if (!found  ERROR_OK == retval)
+   retval = ERROR_FAIL;
+
+   return retval;
+}
 
 int help_add_command(struct command_context *cmd_ctx, struct command *parent,
const char *cmd_name, const char *help_text, const char *usage)
@@ -1032,6 +1096,7 @@ struct command_context* command_init(const char 
*startup_tcl)
Jim_SetGlobalVariableStr(interp, ocd_HOSTOS,
Jim_NewStringObj(interp, HostOs , strlen(HostOs)));
 
+   Jim_CreateCommand(interp, unknown, command_unknown, NULL, NULL);
Jim_CreateCommand(interp, ocd_find, jim_find, NULL, NULL);
Jim_CreateCommand(interp, echo, jim_echo, NULL, NULL);
Jim_CreateCommand(interp, capture, jim_capture, NULL, NULL);
diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl
index 845198a..ede8cdb 100644
--- a/src/helper/startup.tcl
+++ b/src/helper/startup.tcl
@@ -44,23 +44,6 @@ proc cmd_help {cmdname h indent} {
}
 }
 
-# If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
-#
-# We also support two level commands. flash banks is translated to
-# flash_banks
-proc unknown {args} {
-   # do the name mangling from flash banks to flash_banks
-   if {[llength $args]=2} {
-   set cmd_name [lindex $args 0]_[lindex $args 1]
-   if {[catch {info body $cmd_name}]==0} {
-   # the command exists, try it...
-   return [eval $cmd_name [lrange $args 2 end]]
-   }
-   }
-   # This really is an unknown command.
-   return -code error Unknown command: $args
-}
-
 # Try flipping / and \ to find file if the filename does not
 # match the precise spelling
 proc find {filename} {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 1/9] hello: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use new register_commands() with command registration table.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/hello.c |   52 
 1 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/src/hello.c b/src/hello.c
index 8c97a40..6f02494 100644
--- a/src/hello.c
+++ b/src/hello.c
@@ -53,24 +53,36 @@ COMMAND_HANDLER(handle_flag_command)
foo_flag, foo flag);
 }
 
+static const struct command_registration foo_command_handlers[] = {
+   {
+   .name = bar,
+   .handler = handle_foo_command,
+   .mode = COMMAND_ANY,
+   .help = address [enable|disable] - an example command,
+   },
+   {
+   .name = baz,
+   .handler = handle_foo_command,
+   .mode = COMMAND_ANY,
+   .help = address [enable|disable] - a sample command,
+   },
+   {
+   .name = flag,
+   .handler = handle_flag_command,
+   .mode = COMMAND_ANY,
+   .help = [on|off] - set a flag,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int foo_register_commands(struct command_context *cmd_ctx)
 {
// register several commands under the foo command
struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, foo,
-   NULL, COMMAND_ANY, foo: command handler skeleton);
+   NULL, COMMAND_ANY, example command handler skeleton);
 
-   COMMAND_REGISTER(cmd_ctx, cmd, bar,
-   handle_foo_command, COMMAND_ANY,
-   address [enable|disable] - an example command);
-   COMMAND_REGISTER(cmd_ctx, cmd, baz,
-   handle_foo_command, COMMAND_ANY,
-   address [enable|disable] - a sample command);
 
-   COMMAND_REGISTER(cmd_ctx, cmd, flag,
-   handle_flag_command, COMMAND_ANY,
-   [on|off] - set a flag);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, cmd, foo_command_handlers);
 }
 
 static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
@@ -99,12 +111,20 @@ COMMAND_HANDLER(handle_hello_command)
return retval;
 }
 
+static const struct command_registration hello_command_handlers[] = {
+   {
+   .name = hello,
+   .handler = handle_hello_command,
+   .mode = COMMAND_ANY,
+   .help = prints a warm welcome,
+   .usage = [name],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int hello_register_commands(struct command_context *cmd_ctx)
 {
foo_register_commands(cmd_ctx);
 
-   struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, hello,
-   handle_hello_command, COMMAND_ANY,
-   [name] - prints a warm welcome);
-   return cmd ? ERROR_OK : -ENOMEM;
+   return register_commands(cmd_ctx, NULL, hello_command_handlers);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 2/9] demonstrate chaining with foo commands

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use the new command registration chaining capabilities to eliminate
the foo_register_commands helper, folding its remaining command
handler setup into the hello_command_handlers registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/hello.c |   19 +++
 1 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/src/hello.c b/src/hello.c
index 6f02494..9a1bf92 100644
--- a/src/hello.c
+++ b/src/hello.c
@@ -75,16 +75,6 @@ static const struct command_registration 
foo_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-int foo_register_commands(struct command_context *cmd_ctx)
-{
-   // register several commands under the foo command
-   struct command *cmd = COMMAND_REGISTER(cmd_ctx, NULL, foo,
-   NULL, COMMAND_ANY, example command handler skeleton);
-
-
-   return register_commands(cmd_ctx, cmd, foo_command_handlers);
-}
-
 static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
 {
if (CMD_ARGC  1)
@@ -119,12 +109,17 @@ static const struct command_registration 
hello_command_handlers[] = {
.help = prints a warm welcome,
.usage = [name],
},
+   {
+   .name = foo,
+   .mode = COMMAND_ANY,
+   .help = example command handler skeleton,
+
+   .chain = foo_command_handlers,
+   },
COMMAND_REGISTRATION_DONE
 };
 
 int hello_register_commands(struct command_context *cmd_ctx)
 {
-   foo_register_commands(cmd_ctx);
-
return register_commands(cmd_ctx, NULL, hello_command_handlers);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 3/9] openocd: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() for top-level version and init command.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/openocd.c |   24 ++--
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/openocd.c b/src/openocd.c
index 379373c..63289e4 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -159,6 +159,23 @@ COMMAND_HANDLER(handle_init_command)
return ERROR_OK;
 }
 
+static const struct command_registration openocd_command_handlers[] = {
+   {
+   .name = version,
+   .handler = handle_version_command,
+   .mode = COMMAND_EXEC,
+   .help = show program version,
+   },
+   {
+   .name = init,
+   .handler = handle_init_command,
+   .mode = COMMAND_ANY,
+   .help = Initializes configured targets and servers.  
+   If called more than once, does nothing.,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 struct command_context *global_cmd_ctx;
 
 /// src/hello.c gives a simple example for writing new command modules
@@ -171,9 +188,7 @@ struct command_context *setup_command_handler(void)
 
global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl);
 
-   COMMAND_REGISTER(cmd_ctx, NULL, version, handle_version_command,
-COMMAND_EXEC, show OpenOCD version);
-
+   register_commands(cmd_ctx, NULL, openocd_command_handlers);
/* register subsystem commands */
hello_register_commands(cmd_ctx);
server_register_commands(cmd_ctx);
@@ -198,9 +213,6 @@ struct command_context *setup_command_handler(void)
 
LOG_OUTPUT(OPENOCD_VERSION \n);
 
-   COMMAND_REGISTER(cmd_ctx, NULL, init, handle_init_command,
-COMMAND_ANY, initializes target and 
servers - nop on subsequent invocations);
-
return cmd_ctx;
 }
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 4/9] ioutil: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use table instead of individual calls.  Add proper usage information.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/ioutil.c |   62 +--
 1 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c
index 52ecb9f..58521ee 100644
--- a/src/helper/ioutil.c
+++ b/src/helper/ioutil.c
@@ -643,27 +643,55 @@ static int zylinjtag_Jim_Command_mac(Jim_Interp *interp, 
int argc,
 
 }
 
+static const struct command_registration ioutil_command_handlers[] = {
+   {
+   .name = rm,
+   .handler = handle_rm_command,
+   .mode = COMMAND_ANY,
+   .help = remove file,
+   .usage= file_name,
+   },
+   {
+   .name = cat,
+   .handler = handle_cat_command,
+   .mode = COMMAND_ANY,
+   .help = display file content,
+   .usage= file_name,
+   },
+   {
+   .name = trunc,
+   .handler = handle_trunc_command,
+   .mode = COMMAND_ANY,
+   .help = truncate a file 0 size,
+   .usage= file_name,
+   },
+   {
+   .name = cp,
+   .handler = handle_cp_command,
+   .mode = COMMAND_ANY,
+   .help = copy a file,
+   .usage = src dst,
+   },
+   {
+   .name = append_file,
+   .handler = handle_append_command,
+   .mode = COMMAND_ANY,
+   .help = append a variable number of strings to a file,
+   .usage= file_name [string ...],
+   },
+   {
+   .name = meminfo,
+   .handler = handle_meminfo_command,
+   .mode = COMMAND_ANY,
+   .help = display available ram memory,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
 
 int ioutil_init(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, rm, handle_rm_command, COMMAND_ANY,
-   remove file);
-
-   COMMAND_REGISTER(cmd_ctx, NULL, cat, handle_cat_command, COMMAND_ANY,
-   display file content);
-
-   COMMAND_REGISTER(cmd_ctx, NULL, trunc, handle_trunc_command, 
COMMAND_ANY,
-   truncate a file to 0 size);
-
-   COMMAND_REGISTER(cmd_ctx, NULL, cp, handle_cp_command,
-COMMAND_ANY, copy a file from 
to);
-
-   COMMAND_REGISTER(cmd_ctx, NULL, append_file, handle_append_command,
-   COMMAND_ANY, append a variable number of strings to a 
file);
-
-   COMMAND_REGISTER(cmd_ctx, NULL, meminfo, handle_meminfo_command,
-   COMMAND_ANY, display available ram memory);
+   register_commands(cmd_ctx, NULL, ioutil_command_handlers);
 
 Jim_CreateCommand(interp, rm, zylinjtag_Jim_Command_rm, NULL, NULL);
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 5/9] log: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() for logging callbacks.  Improve help and add
proper usage.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/log.c |   24 +++-
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/helper/log.c b/src/helper/log.c
index b1352a3..3799fb3 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -316,15 +316,29 @@ COMMAND_HANDLER(handle_log_output_command)
return ERROR_OK;
 }
 
+static struct command_registration log_command_handlers[] = {
+   {
+   .name = log_output,
+   .handler = handle_log_output_command,
+   .mode = COMMAND_ANY,
+   .help = redirect logging to a file (default: stderr),
+   .usage = file_name,
+   },
+   {
+   .name = debug_level,
+   .handler = handle_debug_level_command,
+   .mode = COMMAND_ANY,
+   .help = sets the verbosity level of debugging output,
+   .usage = level:0-3,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int log_register_commands(struct command_context *cmd_ctx)
 {
start = timeval_ms();
-   COMMAND_REGISTER(cmd_ctx, NULL, log_output, handle_log_output_command,
-   COMMAND_ANY, redirect logging to file (default: stderr));
-   COMMAND_REGISTER(cmd_ctx, NULL, debug_level, 
handle_debug_level_command,
-   COMMAND_ANY, adjust debug level 0-3);
 
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, log_command_handlers);
 }
 
 int log_init(struct command_context *cmd_ctx)
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [SERIES 3/6:0/11] jtag: update command registration

2009-11-24 Thread zw
Hi all,

This series updates the JTAG layer to use new command registration.
Each module is converted, then the callback converted to a pointer.

Cheers,

Zach

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 04/11] ft2232: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with a command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/ft2232.c |   59 
 1 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c
index e560b22..d145505 100644
--- a/src/jtag/ft2232.c
+++ b/src/jtag/ft2232.c
@@ -3969,26 +3969,49 @@ static void ktlink_blink(void)
buffer_write(high_direction);
 }
 
+static const struct command_registration ft2232_command_handlers[] = {
+   {
+   .name = ft2232_device_desc,
+   .handler = ft2232_handle_device_desc_command,
+   .mode = COMMAND_CONFIG,
+   .help = set the USB device description of the FTDI FT2232 
device,
+   .usage = description,
+   },
+   {
+   .name = ft2232_serial,
+   .handler = ft2232_handle_serial_command,
+   .mode = COMMAND_CONFIG,
+   .help = set the serial number of the FTDI FT2232 device,
+   .usage = serial#,
+   },
+   {
+   .name = ft2232_layout,
+   .handler = ft2232_handle_layout_command,
+   .mode = COMMAND_CONFIG,
+   .help = set the layout of the FT2232 GPIO signals used 
+   to control output-enables and reset signals,
+   .usage = layout,
+   },
+   {
+   .name = ft2232_vid_pid,
+   .handler = ft2232_handle_vid_pid_command,
+   .mode = COMMAND_CONFIG,
+   .help = the vendor ID and product ID of the FTDI FT2232 
device,
+   .usage = vid pid [...],
+   },
+   {
+   .name = ft2232_latency,
+   .handler = ft2232_handle_latency_command,
+   .mode = COMMAND_CONFIG,
+   .help = set the FT2232 latency timer to a new value,
+   .usage = vid pid [...],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int ft2232_register_commands(struct command_context* cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, ft2232_device_desc,
-   ft2232_handle_device_desc_command, COMMAND_CONFIG,
-   the USB device description of the FTDI FT2232 device);
-   COMMAND_REGISTER(cmd_ctx, NULL, ft2232_serial,
-   ft2232_handle_serial_command, COMMAND_CONFIG,
-   the serial number of the FTDI FT2232 device);
-   COMMAND_REGISTER(cmd_ctx, NULL, ft2232_layout,
-   ft2232_handle_layout_command, COMMAND_CONFIG,
-   the layout of the FT2232 GPIO signals used 
-   to control output-enables and reset signals);
-   COMMAND_REGISTER(cmd_ctx, NULL, ft2232_vid_pid,
-   ft2232_handle_vid_pid_command, COMMAND_CONFIG,
-   the vendor ID and product ID of the FTDI FT2232 
device);
-   COMMAND_REGISTER(cmd_ctx, NULL, ft2232_latency,
-   ft2232_handle_latency_command, COMMAND_CONFIG,
-   set the FT2232 latency timer to a new value);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, ft2232_command_handlers);
 }
 
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 03/11] at91rm9200: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with command registration array.
---
This module was broken by previous changes, but no one has complained.
Are there still users for this modules?

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/at91rm9200.c |   13 ++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/jtag/at91rm9200.c b/src/jtag/at91rm9200.c
index 024dd6d..ff9f7a4 100644
--- a/src/jtag/at91rm9200.c
+++ b/src/jtag/at91rm9200.c
@@ -200,11 +200,18 @@ static int at91rm9200_handle_device_command(struct 
command_context *cmd_ctx, cha
return ERROR_OK;
 }
 
+static const struct command_registration at91rm9200_command_handlers[] = {
+   {
+   .name = at91rm9200_device,
+   .handler = at91rm9200_handle_device_command,
+   .mode = COMMAND_CONFIG,
+   .help = query armjtagew info,
+   },
+};
+
 static int at91rm9200_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, at91rm9200_device, 
at91rm9200_handle_device_command,
-   COMMAND_CONFIG, NULL);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, at91rm9200_command_handlers);
 }
 
 static int at91rm9200_init(void)
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 6/9] server: use register_commands

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Converts server directory to use new command registration paradigm.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/server/gdb_server.c|   72 ++-
 src/server/server.c|   19 +++
 src/server/tcl_server.c|   17 --
 src/server/telnet_server.c |   32 ---
 4 files changed, 95 insertions(+), 45 deletions(-)

diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index be1f8db..cb14cc3 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -2326,27 +2326,55 @@ COMMAND_HANDLER(handle_gdb_breakpoint_override_command)
return ERROR_OK;
 }
 
-int gdb_register_commands(struct command_context *command_context)
+static const struct command_registration gdb_command_handlers[] = {
+   {
+   .name = gdb_sync,
+   .handler = handle_gdb_sync_command,
+   .mode = COMMAND_ANY,
+   .help = next stepi will return immediately allowing 
+   GDB to fetch register state without affecting 
+   target state,
+   },
+   {
+   .name = gdb_port,
+   .handler = handle_gdb_port_command,
+   .mode = COMMAND_ANY,
+   .help = daemon configuration command gdb_port,
+   .usage = port,
+   },
+   {
+   .name = gdb_memory_map,
+   .handler = handle_gdb_memory_map_command,
+   .mode = COMMAND_CONFIG,
+   .help = enable or disable memory map,
+   .usage = enable|disable
+   },
+   {
+   .name = gdb_flash_program,
+   .handler = handle_gdb_flash_program_command,
+   .mode = COMMAND_CONFIG,
+   .help = enable or disable flash program,
+   .usage = enable|disable
+   },
+   {
+   .name = gdb_report_data_abort,
+   .handler = handle_gdb_report_data_abort_command,
+   .mode = COMMAND_CONFIG,
+   .help = enable or disable reporting data aborts,
+   .usage = enable|disable
+   },
+   {
+   .name = gdb_breakpoint_override,
+   .handler = handle_gdb_breakpoint_override_command,
+   .mode = COMMAND_EXEC,
+   .help = force type of breakpoint 
+   used by gdb 'break' commands.,
+   .usage = hard|soft|disable,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
+int gdb_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(command_context, NULL, gdb_sync,
-   handle_gdb_sync_command, COMMAND_ANY,
-   next stepi will return immediately allowing GDB to 
-   fetch register state without affecting target state);
-   COMMAND_REGISTER(command_context, NULL, gdb_port,
-   handle_gdb_port_command, COMMAND_ANY,
-   daemon configuration command gdb_port);
-   COMMAND_REGISTER(command_context, NULL, gdb_memory_map,
-   handle_gdb_memory_map_command, COMMAND_CONFIG,
-   enable or disable memory map);
-   COMMAND_REGISTER(command_context, NULL, gdb_flash_program,
-   handle_gdb_flash_program_command, COMMAND_CONFIG,
-   enable or disable flash program);
-   COMMAND_REGISTER(command_context, NULL, gdb_report_data_abort,
-   handle_gdb_report_data_abort_command, COMMAND_CONFIG,
-   enable or disable reporting data aborts);
-   COMMAND_REGISTER(command_context, NULL, gdb_breakpoint_override,
-   handle_gdb_breakpoint_override_command, COMMAND_EXEC,
-   hard/soft/disable - force type of breakpoint 
-   used by gdb 'break' commands.);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, gdb_command_handlers);
 }
diff --git a/src/server/server.c b/src/server/server.c
index 5be1316..50bc00e 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -539,16 +539,21 @@ COMMAND_HANDLER(handle_shutdown_command)
return ERROR_COMMAND_CLOSE_CONNECTION;
 }
 
-int server_register_commands(struct command_context *context)
+static const struct command_registration server_command_handlers[] = {
+   {
+   .name = shutdown,
+   .handler = handle_shutdown_command,
+   .mode = COMMAND_ANY,
+   .help = shut the server down,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
+int server_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(context, NULL, shutdown,
-   handle_shutdown_command, COMMAND_ANY,
-   shut the server down);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, 

[Openocd-development] [PATCH 01/11] amt_jtagaccel: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with command_registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/amt_jtagaccel.c |   27 +++
 1 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/jtag/amt_jtagaccel.c b/src/jtag/amt_jtagaccel.c
index 0aabdc9..c3f3279 100644
--- a/src/jtag/amt_jtagaccel.c
+++ b/src/jtag/amt_jtagaccel.c
@@ -540,16 +540,27 @@ COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command)
return ERROR_OK;
 }
 
+static const struct command_registration amtjtagaccel_command_handlers[] = {
+   {
+   .name = parport_port,
+   .handler = amt_jtagaccel_handle_parport_port_command,
+   .mode = COMMAND_CONFIG,
+   .help = configure the parallel port to use,
+   .usage = port_num,
+   },
+   {
+   .name = parport_port,
+   .handler = amt_jtagaccel_handle_rtck_command,
+   .mode = COMMAND_CONFIG,
+   .help = enable RTCK,
+   .usage = enable|disable,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int amt_jtagaccel_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, parport_port,
-   amt_jtagaccel_handle_parport_port_command, 
COMMAND_CONFIG,
-   NULL);
-   COMMAND_REGISTER(cmd_ctx, NULL, rtck,
-   amt_jtagaccel_handle_rtck_command, COMMAND_CONFIG,
-   NULL);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, amtjtagaccel_command_handlers);
 }
 
 struct jtag_interface amt_jtagaccel_interface = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 06/11] jlink: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/jlink.c |   26 ++
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c
index 1ca9c39..24fb0e8 100644
--- a/src/jtag/jlink.c
+++ b/src/jtag/jlink.c
@@ -627,16 +627,26 @@ COMMAND_HANDLER(jlink_handle_jlink_hw_jtag_command)
return ERROR_OK;
 }
 
+static const struct command_registration jlink_command_handlers[] = {
+   {
+   .name = jlink_info,
+   .handler = jlink_handle_jlink_info_command,
+   .mode = COMMAND_EXEC,
+   .help = show jlink info,
+   },
+   {
+   .name = jlink_hw_jtag,
+   .handler = jlink_handle_jlink_hw_jtag_command,
+   .mode = COMMAND_EXEC,
+   .help = access J-Link HW JTAG command version,
+   .usage = [2|3],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int jlink_register_commands(struct command_context *cmd_ctx)
 {
-
-   COMMAND_REGISTER(cmd_ctx, NULL, jlink_info,
-   jlink_handle_jlink_info_command, COMMAND_EXEC,
-   query jlink info);
-   COMMAND_REGISTER(cmd_ctx, NULL, jlink_hw_jtag,
-   jlink_handle_jlink_hw_jtag_command, COMMAND_EXEC,
-   set/get jlink hw jtag command version [2 | 3]);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, jlink_command_handlers);
 }
 
 struct jtag_interface jlink_interface = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 05/11] gw16012: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/gw16012.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/jtag/gw16012.c b/src/jtag/gw16012.c
index bc0e472..0e495f9 100644
--- a/src/jtag/gw16012.c
+++ b/src/jtag/gw16012.c
@@ -562,13 +562,20 @@ COMMAND_HANDLER(gw16012_handle_parport_port_command)
return ERROR_OK;
 }
 
+static const struct command_registration gw16012_command_handlers[] = {
+   {
+   .name = parport_port,
+   .handler = gw16012_handle_parport_port_command,
+   .mode = COMMAND_CONFIG,
+   .help = configure the parallel port to use,
+   .usage = port_num,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int gw16012_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, parport_port,
-   gw16012_handle_parport_port_command, COMMAND_CONFIG,
-   NULL);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, gw16012_command_handlers);
 }
 
 struct jtag_interface gw16012_interface = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 02/11] arm-jtag-ew: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Uses register_commands() with command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/arm-jtag-ew.c |   15 +++
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/jtag/arm-jtag-ew.c b/src/jtag/arm-jtag-ew.c
index f239371..ef2b04f 100644
--- a/src/jtag/arm-jtag-ew.c
+++ b/src/jtag/arm-jtag-ew.c
@@ -502,12 +502,19 @@ COMMAND_HANDLER(armjtagew_handle_armjtagew_info_command)
return ERROR_OK;
 }
 
+static const struct command_registration armjtagew_command_handlers[] = {
+   {
+   .name = armjtagew_info,
+   .handler = armjtagew_handle_armjtagew_info_command,
+   .mode = COMMAND_EXEC,
+   .help = query armjtagew info,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int armjtagew_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, armjtagew_info,
-   armjtagew_handle_armjtagew_info_command, COMMAND_EXEC,
-   query armjtagew info);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, armjtagew_command_handlers);
 }
 
 struct jtag_interface armjtagew_interface = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 07/20] lpc2000: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/lpc2000.c |   28 
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/flash/lpc2000.c b/src/flash/lpc2000.c
index 4a934c0..896b794 100644
--- a/src/flash/lpc2000.c
+++ b/src/flash/lpc2000.c
@@ -776,16 +776,28 @@ COMMAND_HANDLER(lpc2000_handle_part_id_command)
return ERROR_OK;
 }
 
+static const struct command_registration lpc2000_exec_command_handlers[] = {
+   {
+   .name = part_id,
+   .handler = lpc2000_handle_part_id_command,
+   .mode = COMMAND_EXEC,
+   .help = print part id of lpc2000 flash bank num,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration lpc2000_command_handlers[] = {
+   {
+   .name = lpc2000,
+   .mode = COMMAND_ANY,
+   .help = lpc2000 flash command group,
+   .chain = lpc2000_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int lpc2000_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *lpc2000_cmd = COMMAND_REGISTER(cmd_ctx, NULL, lpc2000,
-   NULL, COMMAND_ANY, NULL);
-
-   COMMAND_REGISTER(cmd_ctx, lpc2000_cmd, part_id,
-   lpc2000_handle_part_id_command, COMMAND_EXEC,
-   print part id of lpc2000 flash bank num);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, lpc2000_command_handlers);
 }
 
 struct flash_driver lpc2000_flash = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 01/20] at91sam3: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/at91sam3.c |   62 -
 1 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/src/flash/at91sam3.c b/src/flash/at91sam3.c
index d8460b0..75e8495 100644
--- a/src/flash/at91sam3.c
+++ b/src/flash/at91sam3.c
@@ -2467,35 +2467,43 @@ COMMAND_HANDLER(sam3_handle_slowclk_command)
return ERROR_OK;
 }
 
+static const struct command_registration at91sam3_exec_command_handlers[] = {
+   {
+   .name = gpnvm,
+   .handler = sam3_handle_gpnvm_command,
+   .mode = COMMAND_EXEC,
+   .usage = [(set|clear) [bit_id]],
+   .help = Without arguments, shows the gpnvm register; 
+   otherwise, sets or clear the specified bit.,
+   },
+   {
+   .name = info,
+   .handler = sam3_handle_info_command,
+   .mode = COMMAND_EXEC,
+   .help = print information about the current sam3 chip,
+   },
+   {
+   .name = slowclk,
+   .handler = sam3_handle_slowclk_command,
+   .mode = COMMAND_EXEC,
+   .usage = value,
+   .help = set the slowclock frequency (default 32768hz),
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration at91sam3_command_handlers[] = {
+   {
+   .name = at91sam3,
+   .mode = COMMAND_ANY,
+   .help = at91sam3 flash command group,
+   .chain = at91sam3_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
-static int sam3_registered;
-static int
-sam3_register_commands(struct command_context *cmd_ctx)
+static int sam3_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *pCmd;
-
-   // only register once
-   if (!sam3_registered) {
-   sam3_registered++;
-
-   pCmd = COMMAND_REGISTER(cmd_ctx, NULL, at91sam3, NULL, 
COMMAND_ANY, NULL);
-   COMMAND_REGISTER(cmd_ctx, pCmd,
- gpnvm,
- sam3_handle_gpnvm_command,
- COMMAND_EXEC,
- at91sam3 gpnvm [action 
[BIT], by default 'show', otherwise set | clear BIT);
-   COMMAND_REGISTER(cmd_ctx, pCmd,
- info,
- sam3_handle_info_command,
- COMMAND_EXEC,
- at91sam3 info - print 
information about the current sam3 chip);
-   COMMAND_REGISTER(cmd_ctx, pCmd,
- slowclk,
- sam3_handle_slowclk_command,
- COMMAND_EXEC,
- at91sam3 slowclk [VALUE] set 
the slowclock frequency (default 32768hz));
-   }
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, at91sam3_command_handlers);
 }
 
 struct flash_driver at91sam3_flash = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 03/20] avrf: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/avrf.c |   28 
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/flash/avrf.c b/src/flash/avrf.c
index 692992f..9aea47d 100644
--- a/src/flash/avrf.c
+++ b/src/flash/avrf.c
@@ -449,16 +449,28 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command)
return ERROR_OK;
 }
 
+static const struct command_registration avrf_exec_command_handlers[] = {
+   {
+   .name = mass_erase,
+   .handler = avrf_handle_mass_erase_command,
+   .mode = COMMAND_EXEC,
+   .help = erase entire device,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration avrf_command_handlers[] = {
+   {
+   .name = avrf,
+   .mode = COMMAND_ANY,
+   .help = AVR flash command group,
+   .chain = avrf_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int avrf_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *avr_cmd = COMMAND_REGISTER(cmd_ctx, NULL, avr,
-   NULL, COMMAND_ANY, avr flash specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, avr_cmd, mass_erase,
-   avrf_handle_mass_erase_command, COMMAND_EXEC,
-   mass erase device);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, avrf_command_handlers);
 }
 
 struct flash_driver avr_flash = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 06/20] flash: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Eliminates 'flash_cmd' global variable.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/flash.c |  167 +
 1 files changed, 117 insertions(+), 50 deletions(-)

diff --git a/src/flash/flash.c b/src/flash/flash.c
index 7bc74ab..de95b62 100644
--- a/src/flash/flash.c
+++ b/src/flash/flash.c
@@ -78,7 +78,6 @@ struct flash_driver *flash_drivers[] = {
 };
 
 struct flash_bank *flash_banks;
-static struct command *flash_cmd;
 
 /* wafer thin wrapper for invoking the flash driver */
 static int flash_driver_write(struct flash_bank *bank, uint8_t *buffer, 
uint32_t offset, uint32_t count)
@@ -1272,64 +1271,132 @@ int default_flash_blank_check(struct flash_bank *bank)
return ERROR_OK;
 }
 
+static const struct command_registration flash_exec_command_handlers[] = {
+   {
+   .name = probe,
+   .handler = handle_flash_probe_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank,
+   .help = identify flash bank,
+   },
+   {
+   .name = info,
+   .handler = handle_flash_info_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank,
+   .help = print bank information,
+   },
+   {
+   .name = erase_check,
+   .handler = handle_flash_erase_check_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank,
+   .help = check erase state of sectors,
+   },
+   {
+   .name = protect_check,
+   .handler = handle_flash_protect_check_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank,
+   .help = check protection state of sectors,
+   },
+   {
+   .name = erase_sector,
+   .handler = handle_flash_erase_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank first last,
+   .help = erase sectors,
+   },
+   {
+   .name = erase_address,
+   .handler = handle_flash_erase_address_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank address length,
+   .help = erase address range,
+
+   },
+   {
+   .name = fillw,
+   .handler = handle_flash_fill_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank address word_pattern count,
+   .help = fill with pattern (no autoerase),
+   },
+   {
+   .name = fillh,
+   .handler = handle_flash_fill_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank address halfword_pattern count,
+   .help = fill with pattern,
+   },
+   {
+   .name = fillb,
+   .handler = handle_flash_fill_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank address byte_pattern count,
+   .help = fill with pattern,
+
+   },
+   {
+   .name = write_bank,
+   .handler = handle_flash_write_bank_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank file offset,
+   .help = write binary data,
+   },
+   {
+   .name = write_image,
+   .handler = handle_flash_write_image_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank [erase] [unlock] file [offset] [type],
+   .help = write an image to flash
+   },
+   {
+   .name = protect,
+   .handler = handle_flash_protect_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank first last on | off,
+   .help = set protection of sectors,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int flash_init_drivers(struct command_context *cmd_ctx)
 {
register_jim(cmd_ctx, ocd_flash_banks,
jim_flash_banks, return information about the flash 
banks);
-
if (!flash_banks)
return ERROR_OK;
 
-   COMMAND_REGISTER(cmd_ctx, flash_cmd, info,
-   handle_flash_info_command, COMMAND_EXEC,
-   print info about flash bank num);
-   COMMAND_REGISTER(cmd_ctx, flash_cmd, probe,
-   handle_flash_probe_command, COMMAND_EXEC,
-   identify flash bank num);
-   COMMAND_REGISTER(cmd_ctx, flash_cmd, erase_check,
-   handle_flash_erase_check_command, COMMAND_EXEC,
-   check erase state of sectors in flash bank num);
-   COMMAND_REGISTER(cmd_ctx, flash_cmd, protect_check,
-   handle_flash_protect_check_command, COMMAND_EXEC,
-   check protection state of sectors in flash bank 
num);
-   COMMAND_REGISTER(cmd_ctx, flash_cmd, erase_sector,
-   

[Openocd-development] [SERIES 4/6:0/20] flash: update command registration

2009-11-24 Thread zw
Hi all,

This series updates the flash layer to use new command registration.
Each module is converted, then the callbacks converted to pointers.

Cheers,

Zach

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 08/20] lpc2900: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/lpc2900.c |   89 +++---
 1 files changed, 55 insertions(+), 34 deletions(-)

diff --git a/src/flash/lpc2900.c b/src/flash/lpc2900.c
index c7f1b3a..0d961e4 100644
--- a/src/flash/lpc2900.c
+++ b/src/flash/lpc2900.c
@@ -948,46 +948,67 @@ COMMAND_HANDLER(lpc2900_handle_secure_jtag_command)
 
 /***  Flash interface functions  
**/
 
+static const struct command_registration lpc2900_exec_command_handlers[] = {
+   {
+   .name = signature,
+   .handler = lpc2900_handle_signature_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank,
+   .help = print device signature of flash bank,
+   },
+   {
+   .name = read_custom,
+   .handler = lpc2900_handle_read_custom_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank filename,
+   .help = read customer information from index sector to file,
+   },
+   {
+   .name = password,
+   .handler = lpc2900_handle_password_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank password,
+   .help = enter password to enable 'dangerous' options,
+   },
+   {
+   .name = write_custom,
+   .handler = lpc2900_handle_write_custom_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank filename [type],
+   .help = write customer info from file to index sector,
+   },
+   {
+   .name = secure_sector,
+   .handler = lpc2900_handle_secure_sector_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank first last,
+   .help = activate sector security for a range of sectors,
+   },
+   {
+   .name = secure_jtag,
+   .handler = lpc2900_handle_secure_jtag_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank level,
+   .help = activate JTAG security,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration lpc2900_command_handlers[] = {
+   {
+   .name = lpc2900,
+   .mode = COMMAND_ANY,
+   .help = LPC2900 flash command group,
+   .chain = lpc2900_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
 /**
  * Register private command handlers.
  */
 static int lpc2900_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *lpc2900_cmd = COMMAND_REGISTER(cmd_ctx, NULL, lpc2900,
- NULL, COMMAND_ANY, NULL);
-
-   COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, signature,
-   lpc2900_handle_signature_command, COMMAND_EXEC,
-   bank | 
-   print device signature of flash bank);
-
-   COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, read_custom,
-   lpc2900_handle_read_custom_command, COMMAND_EXEC,
-   bank filename | 
-read customer information from index sector to file);
-
-   COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, password,
-   lpc2900_handle_password_command, COMMAND_EXEC,
-   bank password | 
-enter password to enable 'dangerous' options);
-
-   COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, write_custom,
-   lpc2900_handle_write_custom_command, COMMAND_EXEC,
-   bank filename [type] | 
-write customer info from file to index sector);
-
-   COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, secure_sector,
-   lpc2900_handle_secure_sector_command, COMMAND_EXEC,
-   bank first last | 
-activate sector security for a range of sectors);
-
-   COMMAND_REGISTER(cmd_ctx, lpc2900_cmd, secure_jtag,
-   lpc2900_handle_secure_jtag_command, COMMAND_EXEC,
-   bank level | 
-activate JTAG security);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, lpc2900_command_handlers);
 }
 
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 10/20] mflash: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/mflash.c |   71 +++
 1 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/src/flash/mflash.c b/src/flash/mflash.c
index a4a45dc..03a56e2 100644
--- a/src/flash/mflash.c
+++ b/src/flash/mflash.c
@@ -33,8 +33,6 @@ static int s3c2440_set_gpio_output_val (struct 
mflash_gpio_num gpio, uint8_t val
 static int pxa270_set_gpio_to_output (struct mflash_gpio_num gpio);
 static int pxa270_set_gpio_output_val (struct mflash_gpio_num gpio, uint8_t 
val);
 
-static struct command *mflash_cmd;
-
 static struct mflash_bank *mflash_bank;
 
 static struct mflash_gpio_drv pxa270_gpio = {
@@ -1268,19 +1266,42 @@ COMMAND_HANDLER(mg_config_cmd)
}
 }
 
+static const struct command_registration mflash_exec_command_handlers[] = {
+   {
+   .name = probe,
+   .handler = mg_probe_cmd,
+   .mode = COMMAND_EXEC,
+   .help = Detect bank configuration information,
+   },
+   {
+   .name = write,
+   .handler = mg_write_cmd,
+   .mode = COMMAND_EXEC,
+   .usage = num file address,
+   .help = Write a file at the specified address,
+   },
+   {
+   .name = dump,
+   .handler = mg_dump_cmd,
+   .mode = COMMAND_EXEC,
+   .usage = num file address size,
+   .help = Dump to a file from the specified address,
+   },
+   {
+   .name = config,
+   .handler = mg_config_cmd,
+   .mode = COMMAND_EXEC,
+   .usage = num stage,
+   .help = Dump to a file from the specified address,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int mflash_init_drivers(struct command_context *cmd_ctx)
 {
-   if (mflash_bank) {
-   COMMAND_REGISTER(cmd_ctx, mflash_cmd, probe, mg_probe_cmd, 
COMMAND_EXEC, NULL);
-   COMMAND_REGISTER(cmd_ctx, mflash_cmd, write, mg_write_cmd, 
COMMAND_EXEC,
-   mflash write num file address);
-   COMMAND_REGISTER(cmd_ctx, mflash_cmd, dump, mg_dump_cmd, 
COMMAND_EXEC,
-   mflash dump num file 
address size);
-   COMMAND_REGISTER(cmd_ctx, mflash_cmd, config, mg_config_cmd,
-   COMMAND_EXEC, mflash config num stage);
-   }
-
-   return ERROR_OK;
+   if (!mflash_bank)
+   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, mflash_exec_command_handlers);
 }
 
 COMMAND_HANDLER(mg_bank_cmd)
@@ -1323,10 +1344,26 @@ COMMAND_HANDLER(mg_bank_cmd)
return ERROR_OK;
 }
 
+static const struct command_registration mflash_config_command_handlers[] = {
+   {
+   .name = bank,
+   .handler = mg_bank_cmd,
+   .mode = COMMAND_CONFIG,
+   .help = configure a mflash device bank,
+   .usage = soc base RST pin target #,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration mflash_command_handler[] = {
+   {
+   .name = mflash,
+   .mode = COMMAND_ANY,
+   .help = mflash command group,
+   .chain = mflash_config_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 int mflash_register_commands(struct command_context *cmd_ctx)
 {
-   mflash_cmd = COMMAND_REGISTER(cmd_ctx, NULL, mflash, NULL, 
COMMAND_ANY, NULL);
-   COMMAND_REGISTER(cmd_ctx, mflash_cmd, bank, mg_bank_cmd, 
COMMAND_CONFIG,
-   mflash bank soc base RST pin target #);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, mflash_command_handler);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 11/20] nand: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Eliminates 'nand_cmd' global variable.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/nand.c |  145 -
 1 files changed, 98 insertions(+), 47 deletions(-)

diff --git a/src/flash/nand.c b/src/flash/nand.c
index 2438ddd..bc0e350 100644
--- a/src/flash/nand.c
+++ b/src/flash/nand.c
@@ -63,7 +63,6 @@ static struct nand_flash_controller *nand_flash_controllers[] 
=
 
 /* configured NAND devices and NAND Flash command handler */
 static struct nand_device *nand_devices = NULL;
-static struct command *nand_cmd;
 
 /* Chip ID list
  *
@@ -279,19 +278,34 @@ COMMAND_HANDLER(handle_nand_device_command)
return CALL_COMMAND_HANDLER(handle_nand_list_drivers);
 }
 
+static const struct command_registration nand_config_command_handlers[] = {
+   {
+   .name = device,
+   .handler = handle_nand_device_command,
+   .mode = COMMAND_CONFIG,
+   .help = defines a new NAND bank,
+   },
+   {
+   .name = drivers,
+   .handler = handle_nand_list_drivers,
+   .mode = COMMAND_ANY,
+   .help = lists available NAND drivers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration nand_command_handlers[] = {
+   {
+   .name = nand,
+   .mode = COMMAND_ANY,
+   .help = NAND flash command group,
+   .chain = nand_config_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int nand_register_commands(struct command_context *cmd_ctx)
 {
-   nand_cmd = COMMAND_REGISTER(cmd_ctx, NULL, nand,
-   NULL, COMMAND_ANY, NAND specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, nand_cmd, device,
-   handle_nand_device_command, COMMAND_CONFIG,
-   defines a new NAND bank);
-   COMMAND_REGISTER(cmd_ctx, nand_cmd, drivers,
-   handle_nand_list_drivers, COMMAND_ANY,
-   lists available NAND drivers);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, nand_command_handlers);
 }
 
 struct nand_device *get_nand_device_by_name(const char *name)
@@ -1700,43 +1714,80 @@ COMMAND_HANDLER(handle_nand_raw_access_command)
return ERROR_OK;
 }
 
+static const struct command_registration nand_exec_command_handlers[] = {
+   {
+   .name = list,
+   .handler = handle_nand_list_command,
+   .mode = COMMAND_EXEC,
+   .help = list configured NAND flash devices,
+   },
+   {
+   .name = info,
+   .handler = handle_nand_info_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank,
+   .help = print info about a NAND flash device,
+   },
+   {
+   .name = probe,
+   .handler = handle_nand_probe_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank,
+   .help = identify NAND flash device num,
+
+   },
+   {
+   .name = check_bad_blocks,
+   .handler = handle_nand_check_bad_blocks_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank [offset length],
+   .help = check NAND flash device num for bad blocks,
+   },
+   {
+   .name = erase,
+   .handler = handle_nand_erase_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank [offset length],
+   .help = erase blocks on NAND flash device,
+   },
+   {
+   .name = dump,
+   .handler = handle_nand_dump_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank filename offset length 
+   [oob_raw | oob_only],
+   .help = dump from NAND flash device,
+   },
+   {
+   .name = verify,
+   .handler = handle_nand_verify_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank filename offset 
+   [oob_raw | oob_only | oob_softecc | oob_softecc_kw],
+   .help = verify NAND flash device,
+   },
+   {
+   .name = write,
+   .handler = handle_nand_write_command,
+   .mode = COMMAND_EXEC,
+   .usage = bank filename offset 
+   [oob_raw | oob_only | oob_softecc | oob_softecc_kw],
+   .help = write to NAND flash device,
+   },
+   {
+   .name = raw_access,
+   .handler = handle_nand_raw_access_command,
+   .mode = COMMAND_EXEC,
+   .usage = num ['enable'|'disable'],
+   .help = raw access to NAND flash device,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int nand_init(struct command_context *cmd_ctx)
 {
if (!nand_devices)
  

[Openocd-development] [PATCH 12/20] pic32mx: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/pic32mx.c |   42 +-
 1 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/flash/pic32mx.c b/src/flash/pic32mx.c
index c6d4615..1950e05 100644
--- a/src/flash/pic32mx.c
+++ b/src/flash/pic32mx.c
@@ -882,26 +882,34 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command)
 
return ERROR_OK;
 }
+static const struct command_registration pic32mx_exec_command_handlers[] = {
+   {
+   .name = chip_erase,
+   .handler = pic32mx_handle_chip_erase_command,
+   .mode = COMMAND_EXEC,
+   .help = erase device,
+   },
+   {
+   .name = pgm_word,
+   .handler = pic32mx_handle_pgm_word_command,
+   .mode = COMMAND_EXEC,
+   .help = program a word,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration pic32mx_command_handlers[] = {
+   {
+   .name = pic32mx,
+   .mode = COMMAND_ANY,
+   .help = pic32mx flash command group,
+   .chain = pic32mx_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
 static int pic32mx_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *pic32mx_cmd = COMMAND_REGISTER(cmd_ctx, NULL, pic32mx,
-   NULL, COMMAND_ANY, pic32mx flash specific commands);
-#if 0
-   COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, lock,
-   pic32mx_handle_lock_command, COMMAND_EXEC,
-   lock device);
-   COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, unlock,
-   pic32mx_handle_unlock_command, COMMAND_EXEC,
-   unlock protected device);
-#endif
-   COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, chip_erase,
-   pic32mx_handle_chip_erase_command, COMMAND_EXEC,
-   erase device);
-   COMMAND_REGISTER(cmd_ctx, pic32mx_cmd, pgm_word,
-   pic32mx_handle_pgm_word_command, COMMAND_EXEC,
-   program a word);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, pic32mx_command_handlers);
 }
 
 struct flash_driver pic32mx_flash = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 14/20] stm32x: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/stm32x.c |   65 +++
 1 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/flash/stm32x.c b/src/flash/stm32x.c
index c628f18..808e32c 100644
--- a/src/flash/stm32x.c
+++ b/src/flash/stm32x.c
@@ -1182,30 +1182,53 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
return ERROR_OK;
 }
 
+static const struct command_registration stm32x_exec_command_handlers[] = {
+   {
+   .name = lock,
+   .handler = stm32x_handle_lock_command,
+   .mode = COMMAND_EXEC,
+   .help = lock device,
+   },
+   {
+   .name = unlock,
+   .handler = stm32x_handle_unlock_command,
+   .mode = COMMAND_EXEC,
+   .help = unlock protected device,
+   },
+   {
+   .name = mass_erase,
+   .handler = stm32x_handle_mass_erase_command,
+   .mode = COMMAND_EXEC,
+   .help = mass erase device,
+   },
+   {
+   .name = options_read,
+   .handler = stm32x_handle_options_read_command,
+   .mode = COMMAND_EXEC,
+   .help = read device option bytes,
+   },
+   {
+   .name = options_write,
+   .handler = stm32x_handle_options_write_command,
+   .mode = COMMAND_EXEC,
+   .help = write device option bytes,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration stm32x_command_handlers[] = {
+   {
+   .name = stm32x,
+   .mode = COMMAND_ANY,
+   .help = stm32x flash command group,
+   .chain = stm32x_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int stm32x_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, stm32x,
-   NULL, COMMAND_ANY, stm32x flash specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, stm32x_cmd, lock,
-   stm32x_handle_lock_command, COMMAND_EXEC,
-   lock device);
-   COMMAND_REGISTER(cmd_ctx, stm32x_cmd, unlock,
-   stm32x_handle_unlock_command, COMMAND_EXEC,
-   unlock protected device);
-   COMMAND_REGISTER(cmd_ctx, stm32x_cmd, mass_erase,
-   stm32x_handle_mass_erase_command, COMMAND_EXEC,
-   mass erase device);
-   COMMAND_REGISTER(cmd_ctx, stm32x_cmd, options_read,
-   stm32x_handle_options_read_command, COMMAND_EXEC,
-   read device option bytes);
-   COMMAND_REGISTER(cmd_ctx, stm32x_cmd, options_write,
-   stm32x_handle_options_write_command, COMMAND_EXEC,
-   write device option bytes);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, stm32x_command_handlers);
 }
-
 struct flash_driver stm32x_flash = {
.name = stm32x,
.register_commands = stm32x_register_commands,
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 16/20] str9x: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/str9x.c |   29 +
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/flash/str9x.c b/src/flash/str9x.c
index 6d556d9..f6ad51a 100644
--- a/src/flash/str9x.c
+++ b/src/flash/str9x.c
@@ -676,16 +676,29 @@ COMMAND_HANDLER(str9x_handle_flash_config_command)
return ERROR_OK;
 }
 
+static const struct command_registration str9x_config_command_handlers[] = {
+   {
+   .name = disable_jtag,
+   .handler = str9x_handle_flash_config_command,
+   .mode = COMMAND_EXEC,
+   .help = configure str9x flash controller,
+   .usage = bank_id BBSR NBBSR BBADR NBBADR,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration str9x_command_handlers[] = {
+   {
+   .name = str9x,
+   .mode = COMMAND_ANY,
+   .help = str9x flash command group,
+   .chain = str9x_config_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int str9x_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *str9x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, str9x,
-   NULL, COMMAND_ANY, str9x flash commands);
-
-   COMMAND_REGISTER(cmd_ctx, str9x_cmd, flash_config,
-   str9x_handle_flash_config_command, COMMAND_EXEC,
-   configure str9 flash controller);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, str9x_command_handlers);
 }
 
 struct flash_driver str9x_flash = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 04/22] arm920t: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm920t.c |   74 +++--
 1 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/src/target/arm920t.c b/src/target/arm920t.c
index e927844..1e6019c 100644
--- a/src/target/arm920t.c
+++ b/src/target/arm920t.c
@@ -1361,36 +1361,56 @@ static int arm920t_mcr(struct target *target, int 
cpnum, uint32_t op1, uint32_t
return arm920t_write_cp15_interpreted(target, mrc_opcode(cpnum, op1, 
op2, CRn, CRm), 0, value);
 }
 
+static const struct command_registration arm920t_exec_command_handlers[] = {
+   {
+   .name = cp15,
+   .handler = arm920t_handle_cp15_command,
+   .mode = COMMAND_EXEC,
+   .help = display/modify cp15 register,
+   .usage = num [value],
+   },
+   {
+   .name = cp15i,
+   .handler = arm920t_handle_cp15i_command,
+   .mode = COMMAND_EXEC,
+   .help = display/modify cp15 (interpreted access),
+   .usage = opcode [value] [address],
+   },
+   {
+   .name = cache_info,
+   .handler = arm920t_handle_cache_info_command,
+   .mode = COMMAND_EXEC,
+   .help = display information about target caches,
+   },
+   {
+   .name = read_cache,
+   .handler = arm920t_handle_read_cache_command,
+   .mode = COMMAND_EXEC,
+   .help = display I/D cache content,
+   },
+   {
+   .name = read_mmu,
+   .handler = arm920t_handle_read_mmu_command,
+   .mode = COMMAND_EXEC,
+   .help = display I/D mmu content,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration arm920t_command_handlers[] = {
+   {
+   .name = arm920t,
+   .mode = COMMAND_ANY,
+   .help = arm920t command group,
+   .chain = arm920t_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 /** Registers commands to access coprocessor, cache, and MMU resources. */
 int arm920t_register_commands(struct command_context *cmd_ctx)
 {
-   int retval;
-   struct command *arm920t_cmd;
-
-   retval = arm9tdmi_register_commands(cmd_ctx);
-
-   arm920t_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm920t,
-   NULL, COMMAND_ANY,
-   arm920t specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, arm920t_cmd, cp15,
-   arm920t_handle_cp15_command, COMMAND_EXEC,
-   display/modify cp15 register num [value]);
-   COMMAND_REGISTER(cmd_ctx, arm920t_cmd, cp15i,
-   arm920t_handle_cp15i_command, COMMAND_EXEC,
-   display/modify cp15 (interpreted access) 
-   opcode [value] [address]);
-   COMMAND_REGISTER(cmd_ctx, arm920t_cmd, cache_info,
-   arm920t_handle_cache_info_command, COMMAND_EXEC,
-   display information about target caches);
-   COMMAND_REGISTER(cmd_ctx, arm920t_cmd, read_cache,
-   arm920t_handle_read_cache_command, COMMAND_EXEC,
-   display I/D cache content);
-   COMMAND_REGISTER(cmd_ctx, arm920t_cmd, read_mmu,
-   arm920t_handle_read_mmu_command, COMMAND_EXEC,
-   display I/D mmu content);
-
-   return retval;
+   arm9tdmi_register_commands(cmd_ctx);
+   return register_commands(cmd_ctx, NULL, arm920t_command_handlers);
 }
 
 /** Holds methods for ARM920 targets. */
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 08/22] armv4_5: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/armv4_5.c |   52 -
 1 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c
index ec6d5a0..dfb7094 100644
--- a/src/target/armv4_5.c
+++ b/src/target/armv4_5.c
@@ -786,26 +786,42 @@ usage:
return retval;
 }
 
+static const struct command_registration arm_exec_command_handlers[] = {
+   {
+   .name = reg,
+   .handler = handle_armv4_5_reg_command,
+   .mode = COMMAND_EXEC,
+   .help = display ARM core registers,
+   },
+   {
+   .name = core_state,
+   .handler = handle_armv4_5_core_state_command,
+   .mode = COMMAND_EXEC,
+   .usage = arm | thumb,
+   .help = display/change ARM core state,
+   },
+   {
+   .name = disassemble,
+   .handler = handle_armv4_5_disassemble_command,
+   .mode = COMMAND_EXEC,
+   .usage = address [count ['thumb']],
+   .help = disassemble instructions ,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration arm_command_handlers[] = {
+   {
+   .name = arm,
+   .mode = COMMAND_ANY,
+   .help = ARM command group,
+   .chain = arm_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int armv4_5_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *armv4_5_cmd;
-
-   armv4_5_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm,
-   NULL, COMMAND_ANY,
-   generic ARM commands);
-
-   COMMAND_REGISTER(cmd_ctx, armv4_5_cmd, reg,
-   handle_armv4_5_reg_command, COMMAND_EXEC,
-   display ARM core registers);
-   COMMAND_REGISTER(cmd_ctx, armv4_5_cmd, core_state,
-   handle_armv4_5_core_state_command, COMMAND_EXEC,
-   display/change ARM core state arm | thumb);
-   COMMAND_REGISTER(cmd_ctx, armv4_5_cmd, disassemble,
-   handle_armv4_5_disassemble_command, COMMAND_EXEC,
-   disassemble instructions 
-   address [count ['thumb']]);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, arm_command_handlers);
 }
 
 int armv4_5_get_gdb_reg_list(struct target *target, struct reg **reg_list[], 
int *reg_list_size)
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 11/22] cortex_a8: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/cortex_a8.c |   42 +-
 1 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/target/cortex_a8.c b/src/target/cortex_a8.c
index b1bc463..7d82d6a 100644
--- a/src/target/cortex_a8.c
+++ b/src/target/cortex_a8.c
@@ -1679,28 +1679,36 @@ COMMAND_HANDLER(cortex_a8_handle_dbginit_command)
return ERROR_OK;
 }
 
+static const struct command_registration cortex_a8_exec_command_handlers[] = {
+   {
+   .name = cache_info,
+   .handler = cortex_a8_handle_cache_info_command,
+   .mode = COMMAND_EXEC,
+   .help = display information about target caches,
+   },
+   {
+   .name = dbginit,
+   .handler = cortex_a8_handle_dbginit_command,
+   .mode = COMMAND_EXEC,
+   .help = Initialize core debug,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration cortex_a8_command_handlers[] = {
+   {
+   .name = cortex_a8,
+   .mode = COMMAND_ANY,
+   .help = Cortex-A8 command group,
+   .chain = cortex_a8_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
 static int cortex_a8_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *cortex_a8_cmd;
-   int retval = ERROR_OK;
-
armv4_5_register_commands(cmd_ctx);
armv7a_register_commands(cmd_ctx);
-
-   cortex_a8_cmd = COMMAND_REGISTER(cmd_ctx, NULL, cortex_a8,
-   NULL, COMMAND_ANY,
-   cortex_a8 specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, cortex_a8_cmd, cache_info,
-   cortex_a8_handle_cache_info_command, COMMAND_EXEC,
-   display information about target caches);
-
-   COMMAND_REGISTER(cmd_ctx, cortex_a8_cmd, dbginit,
-   cortex_a8_handle_dbginit_command, COMMAND_EXEC,
-   Initialize core debug);
-
-   return retval;
+   return register_commands(cmd_ctx, NULL, cortex_a8_command_handlers);
 }
 
 struct target_type cortexa8_target = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 12/22] cortex_m3: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/cortex_m3.c |   55 +++
 1 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/src/target/cortex_m3.c b/src/target/cortex_m3.c
index 47052e9..be81af9 100644
--- a/src/target/cortex_m3.c
+++ b/src/target/cortex_m3.c
@@ -1912,27 +1912,44 @@ 
COMMAND_HANDLER(handle_cortex_m3_mask_interrupts_command)
return ERROR_OK;
 }
 
+static const struct command_registration cortex_m3_exec_command_handlers[] = {
+   {
+   .name = disassemble,
+   .handler = handle_cortex_m3_disassemble_command,
+   .mode = COMMAND_EXEC,
+   .help = disassemble Thumb2 instructions,
+   .usage = address [count],
+   },
+   {
+   .name = maskisr,
+   .handler = handle_cortex_m3_mask_interrupts_command,
+   .mode = COMMAND_EXEC,
+   .help = mask cortex_m3 interrupts,
+   .usage = ['on'|'off'],
+   },
+   {
+   .name = vector_catch,
+   .handler = handle_cortex_m3_vector_catch_command,
+   .mode = COMMAND_EXEC,
+   .help = catch hardware vectors,
+   .usage = ['all'|'none'|list],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration cortex_m3_command_handlers[] = {
+   {
+   .name = cortex_m3,
+   .mode = COMMAND_ANY,
+   .help = Cortex-M3 command group,
+   .chain = cortex_m3_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int cortex_m3_register_commands(struct command_context *cmd_ctx)
 {
-   int retval;
-   struct command *cortex_m3_cmd;
-
-   retval = armv7m_register_commands(cmd_ctx);
-
-   cortex_m3_cmd = COMMAND_REGISTER(cmd_ctx, NULL, cortex_m3,
-   NULL, COMMAND_ANY, cortex_m3 specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, cortex_m3_cmd, disassemble,
-   handle_cortex_m3_disassemble_command, COMMAND_EXEC,
-   disassemble Thumb2 instructions address [count]);
-   COMMAND_REGISTER(cmd_ctx, cortex_m3_cmd, maskisr,
-   handle_cortex_m3_mask_interrupts_command, COMMAND_EXEC,
-   mask cortex_m3 interrupts ['on'|'off']);
-   COMMAND_REGISTER(cmd_ctx, cortex_m3_cmd, vector_catch,
-   handle_cortex_m3_vector_catch_command, COMMAND_EXEC,
-   catch hardware vectors ['all'|'none'|list]);
-
-   return retval;
+   armv7m_register_commands(cmd_ctx);
+   return register_commands(cmd_ctx, NULL, cortex_m3_command_handlers);
 }
 
 struct target_type cortexm3_target =
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 13/22] etb: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/etb.c |   28 
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/target/etb.c b/src/target/etb.c
index 1f44d3a..63dee18 100644
--- a/src/target/etb.c
+++ b/src/target/etb.c
@@ -402,16 +402,28 @@ COMMAND_HANDLER(handle_etb_config_command)
return ERROR_OK;
 }
 
+static const struct command_registration etb_config_command_handlers[] = {
+   {
+   .name = config,
+   .handler = handle_etb_config_command,
+   .mode = COMMAND_CONFIG,
+   .usage = target tap,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration etb_command_handlers[] = {
+   {
+   .name = etb,
+   .mode = COMMAND_ANY,
+   .help = Emebdded Trace Buffer command group,
+   .chain = etb_config_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int etb_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *etb_cmd = COMMAND_REGISTER(cmd_ctx, NULL, etb,
-   NULL, COMMAND_ANY, Embedded Trace Buffer);
-
-   COMMAND_REGISTER(cmd_ctx, etb_cmd, config,
-   handle_etb_config_command, COMMAND_CONFIG,
-   NULL);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, etb_command_handlers);
 }
 
 static int etb_init(struct etm_context *etm_ctx)
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 10/22] armv7m: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/armv7m.c |   76 ---
 1 files changed, 48 insertions(+), 28 deletions(-)

diff --git a/src/target/armv7m.c b/src/target/armv7m.c
index 9fd24e9..6d8ad5f 100644
--- a/src/target/armv7m.c
+++ b/src/target/armv7m.c
@@ -795,34 +795,54 @@ COMMAND_HANDLER(handle_dap_info_command)
return dap_info_command(CMD_CTX, swjdp, apsel);
 }
 
-/** Registers commands used to access DAP resources. */
+static const struct command_registration armv7m_exec_command_handlers[] = {
+   {
+   .name = info,
+   .handler = handle_dap_info_command,
+   .mode = COMMAND_EXEC,
+   .help = dap info for ap [num], 
+   default currently selected AP,
+   },
+   {
+   .name = apsel,
+   .handler = handle_dap_apsel_command,
+   .mode = COMMAND_EXEC,
+   .help = select a different AP [num] (default 0),
+   },
+   {
+   .name = apid,
+   .handler = handle_dap_apid_command,
+   .mode = COMMAND_EXEC,
+   .help = return id reg from AP [num], 
+   default currently selected AP,
+   },
+   {
+   .name = baseaddr,
+   .handler = handle_dap_baseaddr_command,
+   .mode = COMMAND_EXEC,
+   .help = return debug base address from AP [num], 
+   default currently selected AP,
+   },
+   {
+   .name = memaccess,
+   .handler = handle_dap_memaccess_command,
+   .mode = COMMAND_EXEC,
+   .help = set/get number of extra tck for mem-ap memory 
+   bus access [0-255],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration armv7m_command_handlers[] = {
+   {
+   .name = dap,
+   .mode = COMMAND_ANY,
+   .help = Cortex DAP command group,
+   .chain = armv7m_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int armv7m_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *arm_adi_v5_dap_cmd;
-
-   arm_adi_v5_dap_cmd = COMMAND_REGISTER(cmd_ctx, NULL, dap,
-   NULL, COMMAND_ANY,
-   cortex dap specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, arm_adi_v5_dap_cmd, info,
-   handle_dap_info_command, COMMAND_EXEC,
-   Displays dap info for ap [num],
-   default currently selected AP);
-   COMMAND_REGISTER(cmd_ctx, arm_adi_v5_dap_cmd, apsel,
-   handle_dap_apsel_command, COMMAND_EXEC,
-   Select a different AP [num] (default 0));
-   COMMAND_REGISTER(cmd_ctx, arm_adi_v5_dap_cmd, apid,
-   handle_dap_apid_command, COMMAND_EXEC,
-   Displays id reg from AP [num], 
-   default currently selected AP);
-   COMMAND_REGISTER(cmd_ctx, arm_adi_v5_dap_cmd, baseaddr,
-   handle_dap_baseaddr_command, COMMAND_EXEC,
-   Displays debug base address from AP [num],
-   default currently selected AP);
-   COMMAND_REGISTER(cmd_ctx, arm_adi_v5_dap_cmd, memaccess,
-   handle_dap_memaccess_command, COMMAND_EXEC,
-   set/get number of extra tck for mem-ap 
-   memory bus access [0-255]);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, armv7m_command_handlers);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 14/22] etm: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/etm.c |  126 ++
 1 files changed, 89 insertions(+), 37 deletions(-)

diff --git a/src/target/etm.c b/src/target/etm.c
index 6df354a..0f7b41e 100644
--- a/src/target/etm.c
+++ b/src/target/etm.c
@@ -221,8 +221,6 @@ static int etm_register_user_commands(struct 
command_context *cmd_ctx);
 static int etm_set_reg_w_exec(struct reg *reg, uint8_t *buf);
 static int etm_write_reg(struct reg *reg, uint32_t value);
 
-static struct command *etm_cmd;
-
 static const struct reg_arch_type etm_scan6_type = {
.get = etm_get_reg,
.set = etm_set_reg_w_exec,
@@ -2095,45 +2093,99 @@ COMMAND_HANDLER(handle_etm_analyze_command)
return retval;
 }
 
+static const struct command_registration etm_config_command_handlers[] = {
+   {
+   .name = config,
+   .handler = handle_etm_config_command,
+   .mode = COMMAND_CONFIG,
+   .usage = target port_width port_mode 
+   clocking capture_driver,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration etm_command_handlers[] = {
+   {
+   .name = etm,
+   .mode = COMMAND_ANY,
+   .help = Emebdded Trace Macrocell command group,
+   .chain = etm_config_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int etm_register_commands(struct command_context *cmd_ctx)
 {
-   etm_cmd = COMMAND_REGISTER(cmd_ctx, NULL, etm, NULL, COMMAND_ANY, 
Embedded Trace Macrocell);
-
-   COMMAND_REGISTER(cmd_ctx, etm_cmd, config, handle_etm_config_command,
-   COMMAND_CONFIG, etm config target port_width port_mode 
clocking capture_driver);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, etm_command_handlers);
 }
 
+static const struct command_registration etm_exec_command_handlers[] = {
+   {
+   .name = tracemode, handle_etm_tracemode_command,
+   .mode = COMMAND_EXEC,
+   .help = configure/display trace mode,
+   .usage = none | data | address | all 
+   context_id_bits cycle_accurate branch_output,
+   },
+   {
+   .name = info,
+   .handler = handle_etm_info_command,
+   .mode = COMMAND_EXEC,
+   .help = display info about the current target's ETM,
+   },
+   {
+   .name = trigger_percent,
+   .handler = handle_etm_trigger_percent_command,
+   .mode = COMMAND_EXEC,
+   .help = amount (percent) of trace buffer 
+   to be filled after the trigger occured,
+   },
+   {
+   .name = status,
+   .handler = handle_etm_status_command,
+   .mode = COMMAND_EXEC,
+   .help = display current target's ETM status,
+   },
+   {
+   .name = start,
+   .handler = handle_etm_start_command,
+   .mode = COMMAND_EXEC,
+   .help = start ETM trace collection,
+   },
+   {
+   .name = stop,
+   .handler = handle_etm_stop_command,
+   .mode = COMMAND_EXEC,
+   .help = stop ETM trace collection,
+   },
+   {
+   .name = analyze,
+   .handler = handle_etm_analyze_command,
+   .mode = COMMAND_EXEC,
+   .help = anaylze collected ETM trace,
+   },
+   {
+   .name = image,
+   .handler = handle_etm_image_command,
+   .mode = COMMAND_EXEC,
+   .help = load image from file [base address],
+   },
+   {
+   .name = dump,
+   .handler = handle_etm_dump_command,
+   .mode = COMMAND_EXEC,
+   .help = dump captured trace data file,
+   },
+   {
+   .name = load,
+   .handler = handle_etm_load_command,
+   .mode = COMMAND_EXEC,
+   .help = load trace data for analysis file,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int etm_register_user_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, etm_cmd, tracemode, 
handle_etm_tracemode_command,
-   COMMAND_EXEC, configure/display trace mode: 
-   none | data | address | all 
-   context_id_bits cycle_accurate branch_output);
-
-   COMMAND_REGISTER(cmd_ctx, etm_cmd, info, handle_etm_info_command,
-   COMMAND_EXEC, display info about the current target's ETM);
-
-   COMMAND_REGISTER(cmd_ctx, etm_cmd, trigger_percent, 
handle_etm_trigger_percent_command,
-   COMMAND_EXEC, amount (percent) of trace buffer to be filled 
after the trigger occured);
-   COMMAND_REGISTER(cmd_ctx, 

[Openocd-development] [PATCH 16/22] oocd_trace: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/oocd_trace.c |   42 --
 1 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/src/target/oocd_trace.c b/src/target/oocd_trace.c
index 596a4d6..a34c63c 100644
--- a/src/target/oocd_trace.c
+++ b/src/target/oocd_trace.c
@@ -407,16 +407,38 @@ COMMAND_HANDLER(handle_oocd_trace_resync_command)
return ERROR_OK;
 }
 
+static const struct command_registration oocd_trace_all_command_handlers[] = {
+   {
+   .name = config,
+   .handler = handle_oocd_trace_config_command,
+   .mode = COMMAND_CONFIG,
+   .usage = target,
+   },
+   {
+   .name = status,
+   .handler = handle_oocd_trace_status_command,
+   .mode = COMMAND_EXEC,
+   .help = display OpenOCD + trace status,
+   },
+   {
+   .name = resync,
+   .handler = handle_oocd_trace_resync_command,
+   .mode = COMMAND_EXEC,
+   .help = resync OpenOCD + trace capture clock,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration oocd_trace_command_handlers[] = {
+   {
+   .name = oocd_trace,
+   .mode = COMMAND_ANY,
+   .help = OpenOCD trace capture driver command group,
+   .chain = oocd_trace_all_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int oocd_trace_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *oocd_trace_cmd;
-
-   oocd_trace_cmd = COMMAND_REGISTER(cmd_ctx, NULL, oocd_trace, NULL, 
COMMAND_ANY, OpenOCD + trace);
-
-   COMMAND_REGISTER(cmd_ctx, oocd_trace_cmd, config, 
handle_oocd_trace_config_command, COMMAND_CONFIG, NULL);
-
-   COMMAND_REGISTER(cmd_ctx, oocd_trace_cmd, status, 
handle_oocd_trace_status_command, COMMAND_EXEC, display OpenOCD + trace 
status);
-   COMMAND_REGISTER(cmd_ctx, oocd_trace_cmd, resync, 
handle_oocd_trace_resync_command, COMMAND_EXEC, resync OpenOCD + trace capture 
clock);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, oocd_trace_command_handlers);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 18/22] target_request: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/target_request.c |   29 +
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/target/target_request.c b/src/target/target_request.c
index a02e2c1..9e78178 100644
--- a/src/target/target_request.c
+++ b/src/target/target_request.c
@@ -35,7 +35,6 @@
 #include log.h
 
 
-static struct command *target_request_cmd = NULL;
 static int charmsg_mode = 0;
 
 static int target_asciimsg(struct target *target, uint32_t length)
@@ -300,13 +299,27 @@ COMMAND_HANDLER(handle_target_request_debugmsgs_command)
return ERROR_OK;
 }
 
+static const struct command_registration target_req_exec_command_handlers[] = {
+   {
+   .name = debugmsgs,
+   .handler = handle_target_request_debugmsgs_command,
+   .mode = COMMAND_EXEC,
+   .help = set reception of debug messages from target,
+   .usage = (enable|disable),
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration target_req_command_handlers[] = {
+   {
+   .name = target_request,
+   .mode = COMMAND_ANY,
+   .help = target request command group,
+   .chain = target_req_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int target_request_register_commands(struct command_context *cmd_ctx)
 {
-   target_request_cmd =
-   COMMAND_REGISTER(cmd_ctx, NULL, target_request, NULL, 
COMMAND_ANY, target_request commands);
-
-   COMMAND_REGISTER(cmd_ctx, target_request_cmd, debugmsgs, 
handle_target_request_debugmsgs_command,
-   COMMAND_EXEC, enable/disable reception of debug messages from 
target);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, target_req_command_handlers);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 17/22] target: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/target.c |  305 +-
 1 files changed, 201 insertions(+), 104 deletions(-)

diff --git a/src/target/target.c b/src/target/target.c
index 2e93382..6f48808 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -4762,19 +4762,211 @@ static int jim_mcrmrc(Jim_Interp *interp, int argc, 
Jim_Obj *const *argv)
return JIM_OK;
 }
 
+static const struct command_registration target_command_handlers[] = {
+   {
+   .name = targets,
+   .handler = handle_targets_command,
+   .mode = COMMAND_ANY,
+   .help = change current command line target (one parameter) 
+   or list targets (no parameters),
+   .usage = [new_current_target],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int target_register_commands(struct command_context *cmd_ctx)
 {
-
-   COMMAND_REGISTER(cmd_ctx, NULL, targets,
-   handle_targets_command, COMMAND_EXEC,
-   change current command line target (one parameter) 
-   or list targets (no parameters));
-
register_jim(cmd_ctx, target, jim_target, configure target);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, target_command_handlers);
 }
 
+static const struct command_registration target_exec_command_handlers[] = {
+   {
+   .name = fast_load_image,
+   .handler = handle_fast_load_image_command,
+   .mode = COMMAND_ANY,
+   .help = Load image into memory, mainly for profiling purposes,
+   .usage = file address ['bin'|'ihex'|'elf'|'s19'] 
+   [min_address] [max_length],
+   },
+   {
+   .name = fast_load,
+   .handler = handle_fast_load_command,
+   .mode = COMMAND_ANY,
+   .help = loads active fast load image to current target 
+   - mainly for profiling purposes,
+   },
+   {
+   .name = profile,
+   .handler = handle_profile_command,
+   .mode = COMMAND_EXEC,
+   .help = profiling samples the CPU PC,
+   },
+   /** @todo don't register virt2phys() unless target supports it */
+   {
+   .name = virt2phys,
+   .handler = handle_virt2phys_command,
+   .mode = COMMAND_ANY,
+   .help = translate a virtual address into a physical address,
+   },
+
+   {
+   .name = reg,
+   .handler = handle_reg_command,
+   .mode = COMMAND_EXEC,
+   .help = display or set a register,
+   },
+
+   {
+   .name = poll,
+   .handler = handle_poll_command,
+   .mode = COMMAND_EXEC,
+   .help = poll target state,
+   },
+   {
+   .name = wait_halt,
+   .handler = handle_wait_halt_command,
+   .mode = COMMAND_EXEC,
+   .help = wait for target halt,
+   .usage = [time (s)],
+   },
+   {
+   .name = halt,
+   .handler = handle_halt_command,
+   .mode = COMMAND_EXEC,
+   .help = halt target,
+   },
+   {
+   .name = resume,
+   .handler = handle_resume_command,
+   .mode = COMMAND_EXEC,
+   .help = resume target,
+   .usage = [address],
+   },
+   {
+   .name = reset,
+   .handler = handle_reset_command,
+   .mode = COMMAND_EXEC,
+   .usage = [run|halt|init],
+   .help = Reset all targets into the specified mode.
+   Default reset mode is run, if not given.,
+   },
+   {
+   .name = soft_reset_halt,
+   .handler = handle_soft_reset_halt_command,
+   .mode = COMMAND_EXEC,
+   .help = halt the target and do a soft reset,
+   },
+   {
+
+   .name = step,
+   .handler = handle_step_command,
+   .mode = COMMAND_EXEC,
+   .help = step one instruction from current PC or [addr],
+   .usage = [address],
+   },
+   {
+
+   .name = mdw,
+   .handler = handle_md_command,
+   .mode = COMMAND_EXEC,
+   .help = display memory words,
+   .usage = [phys] addr [count],
+   },
+   {
+   .name = mdh,
+   .handler = handle_md_command,
+   .mode = COMMAND_EXEC,
+   .help = display memory half-words,
+   .usage = [phys] addr [count],
+   },
+   {
+   .name = mdb,
+   .handler = handle_md_command,
+   .mode = COMMAND_EXEC,
+   

[Openocd-development] [PATCH 20/22] xscale: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/xscale.c |  130 ++-
 1 files changed, 107 insertions(+), 23 deletions(-)

diff --git a/src/target/xscale.c b/src/target/xscale.c
index c2b3493..965ac52 100644
--- a/src/target/xscale.c
+++ b/src/target/xscale.c
@@ -3554,31 +3554,115 @@ COMMAND_HANDLER(xscale_handle_cp15)
return ERROR_OK;
 }
 
+static const struct command_registration xscale_exec_command_handlers[] = {
+   {
+   .name = cache_info,
+   .handler = xscale_handle_cache_info_command,
+   .mode = COMMAND_EXEC, NULL,
+   },
+
+   {
+   .name = mmu,
+   .handler = xscale_handle_mmu_command,
+   .mode = COMMAND_EXEC,
+   .usage = [enable|disable],
+   .help = enable or disable the MMU,
+   },
+   {
+   .name = icache,
+   .handler = xscale_handle_idcache_command,
+   .mode = COMMAND_EXEC,
+   .usage = [enable|disable],
+   .help = enable or disable the ICache,
+   },
+   {
+   .name = dcache,
+   .handler = xscale_handle_idcache_command,
+   .mode = COMMAND_EXEC,
+   .usage = [enable|disable],
+   .help = enable or disable the DCache,
+   },
+
+   {
+   .name = vector_catch,
+   .handler = xscale_handle_vector_catch_command,
+   .mode = COMMAND_EXEC,
+   .help = mask of vectors that should be caught,
+   .usage = [mask],
+   },
+   {
+   .name = vector_table,
+   .handler = xscale_handle_vector_table_command,
+   .mode = COMMAND_EXEC,
+   .usage = high|low index code,
+   .help = set static code for exception handler entry,
+   },
+
+   {
+   .name = trace_buffer,
+   .handler = xscale_handle_trace_buffer_command,
+   .mode = COMMAND_EXEC,
+   .usage = enable | disable [fill [n]|wrap],
+   },
+   {
+   .name = dump_trace,
+   .handler = xscale_handle_dump_trace_command,
+   .mode = COMMAND_EXEC,
+   .help = dump content of trace buffer to file,
+   .usage = file,
+   },
+   {
+   .name = analyze_trace,
+   .handler = xscale_handle_analyze_trace_buffer_command,
+   .mode = COMMAND_EXEC,
+   .help = analyze content of trace buffer,
+   },
+   {
+   .name = trace_image,
+   .handler = xscale_handle_trace_image_command,
+   COMMAND_EXEC,
+   .help = load image from file [base address],
+   .usage = file [address] [type],
+   },
+
+   {
+   .name = cp15,
+   .handler = xscale_handle_cp15,
+   .mode = COMMAND_EXEC,
+   .help = access coproc 15,
+   .usage = register [value],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration xscale_any_command_handlers[] = {
+   {
+   .name = debug_handler,
+   .handler = xscale_handle_debug_handler_command,
+   .mode = COMMAND_ANY,
+   .usage = target# address,
+   },
+   {
+   .name = cache_clean_address,
+   .handler = xscale_handle_cache_clean_address_command,
+   .mode = COMMAND_ANY,
+   },
+   {
+   .chain = xscale_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration xscale_command_handlers[] = {
+   {
+   .name = xscale,
+   .mode = COMMAND_ANY,
+   .help = xscale command group,
+   .chain = xscale_any_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int xscale_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *xscale_cmd;
-
-   xscale_cmd = COMMAND_REGISTER(cmd_ctx, NULL, xscale, NULL, 
COMMAND_ANY, xscale specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, xscale_cmd, debug_handler, 
xscale_handle_debug_handler_command, COMMAND_ANY, 'xscale debug_handler 
target# address' command takes two required operands);
-   COMMAND_REGISTER(cmd_ctx, xscale_cmd, cache_clean_address, 
xscale_handle_cache_clean_address_command, COMMAND_ANY, NULL);
-
-   COMMAND_REGISTER(cmd_ctx, xscale_cmd, cache_info, 
xscale_handle_cache_info_command, COMMAND_EXEC, NULL);
-   COMMAND_REGISTER(cmd_ctx, xscale_cmd, mmu, xscale_handle_mmu_command, 
COMMAND_EXEC, ['enable'|'disable'] the MMU);
-   COMMAND_REGISTER(cmd_ctx, xscale_cmd, icache, 
xscale_handle_idcache_command, COMMAND_EXEC, ['enable'|'disable'] the ICache);
-   

[Openocd-development] [PATCH 22/22] remove register_commands from etm_capture_driver

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Converts callback to an array of command_registration records.
Moves oocd_trace driver definition to end of file to eliminate
useless forward declaration.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/etb.c|7 +--
 src/target/etm.c|5 +++--
 src/target/etm.h|2 +-
 src/target/etm_dummy.c  |7 +--
 src/target/oocd_trace.c |   27 +++
 5 files changed, 17 insertions(+), 31 deletions(-)

diff --git a/src/target/etb.c b/src/target/etb.c
index 63dee18..bc0e1bf 100644
--- a/src/target/etb.c
+++ b/src/target/etb.c
@@ -421,11 +421,6 @@ static const struct command_registration 
etb_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int etb_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, etb_command_handlers);
-}
-
 static int etb_init(struct etm_context *etm_ctx)
 {
struct etb *etb = etm_ctx-capture_driver_priv;
@@ -696,7 +691,7 @@ static int etb_stop_capture(struct etm_context *etm_ctx)
 struct etm_capture_driver etb_capture_driver =
 {
.name = etb,
-   .register_commands = etb_register_commands,
+   .commands = etb_command_handlers,
.init = etb_init,
.status = etb_status,
.start_capture = etb_start_capture,
diff --git a/src/target/etm.c b/src/target/etm.c
index 2465d5c..4e7f917 100644
--- a/src/target/etm.c
+++ b/src/target/etm.c
@@ -1471,8 +1471,9 @@ COMMAND_HANDLER(handle_etm_config_command)
{
if (strcmp(CMD_ARGV[4], etm_capture_drivers[i]-name) == 0)
{
-   int retval;
-   if ((retval = 
etm_capture_drivers[i]-register_commands(CMD_CTX)) != ERROR_OK)
+   int retval = register_commands(CMD_CTX, NULL,
+   etm_capture_drivers[i]-commands);
+   if (ERROR_OK != retval)
{
free(etm_ctx);
return retval;
diff --git a/src/target/etm.h b/src/target/etm.h
index 05e5495..c8da794 100644
--- a/src/target/etm.h
+++ b/src/target/etm.h
@@ -126,7 +126,7 @@ struct etm_context;
 struct etm_capture_driver
 {
char *name;
-   int (*register_commands)(struct command_context *cmd_ctx);
+   const struct command_registration *commands;
int (*init)(struct etm_context *etm_ctx);
trace_status_t (*status)(struct etm_context *etm_ctx);
int (*read_trace)(struct etm_context *etm_ctx);
diff --git a/src/target/etm_dummy.c b/src/target/etm_dummy.c
index 27a8eec..647774f 100644
--- a/src/target/etm_dummy.c
+++ b/src/target/etm_dummy.c
@@ -77,11 +77,6 @@ static const struct command_registration 
etm_dummy_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int etm_dummy_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, etm_dummy_command_handlers);
-}
-
 static int etm_dummy_init(struct etm_context *etm_ctx)
 {
return ERROR_OK;
@@ -110,7 +105,7 @@ static int etm_dummy_stop_capture(struct etm_context 
*etm_ctx)
 struct etm_capture_driver etm_dummy_capture_driver =
 {
.name = dummy,
-   .register_commands = etm_dummy_register_commands,
+   .commands = etm_dummy_command_handlers,
.init = etm_dummy_init,
.status = etm_dummy_status,
.start_capture = etm_dummy_start_capture,
diff --git a/src/target/oocd_trace.c b/src/target/oocd_trace.c
index a34c63c..ac79f18 100644
--- a/src/target/oocd_trace.c
+++ b/src/target/oocd_trace.c
@@ -30,8 +30,6 @@
  */
 
 
-static int oocd_trace_register_commands(struct command_context *cmd_ctx);
-
 static int oocd_trace_read_reg(struct oocd_trace *oocd_trace, int reg, 
uint32_t *value)
 {
size_t bytes_written, bytes_read, bytes_to_read;
@@ -278,17 +276,6 @@ static int oocd_trace_stop_capture(struct etm_context 
*etm_ctx)
return ERROR_OK;
 }
 
-struct etm_capture_driver oocd_trace_capture_driver =
-{
-   .name = oocd_trace,
-   .register_commands = oocd_trace_register_commands,
-   .init = oocd_trace_init,
-   .status = oocd_trace_status,
-   .start_capture = oocd_trace_start_capture,
-   .stop_capture = oocd_trace_stop_capture,
-   .read_trace = oocd_trace_read_trace,
-};
-
 COMMAND_HANDLER(handle_oocd_trace_config_command)
 {
struct target *target;
@@ -438,7 +425,15 @@ static const struct command_registration 
oocd_trace_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-int oocd_trace_register_commands(struct command_context *cmd_ctx)
+struct etm_capture_driver oocd_trace_capture_driver =
 {
-   return register_commands(cmd_ctx, NULL, oocd_trace_command_handlers);
-}
+   .name = oocd_trace,
+   .commands = oocd_trace_command_handlers,
+   .init = oocd_trace_init,
+   .status = 

[Openocd-development] [PATCH 21/22] remove target_type register_command callback

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Uses chaining of command_registration structures to eliminate all
target_type register_callback routines.  Exports the command_handler
registration arrays for those target types that are used by others.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm11.c |   15 +++
 src/target/arm720t.c   |   11 ---
 src/target/arm7_9_common.c |   15 +++
 src/target/arm7_9_common.h |2 +-
 src/target/arm7tdmi.c  |2 +-
 src/target/arm920t.c   |   14 +-
 src/target/arm920t.h   |3 ++-
 src/target/arm926ejs.c |   14 +-
 src/target/arm926ejs.h |3 ++-
 src/target/arm966e.c   |   14 +-
 src/target/arm966e.h   |3 ++-
 src/target/arm9tdmi.c  |   13 +
 src/target/arm9tdmi.h  |2 +-
 src/target/armv4_5.c   |7 +--
 src/target/armv4_5.h   |5 -
 src/target/armv7a.c|6 +-
 src/target/armv7a.h|3 ++-
 src/target/armv7m.c|7 +--
 src/target/armv7m.h|3 ++-
 src/target/avrt.c  |   10 --
 src/target/cortex_a8.c |   15 +++
 src/target/cortex_m3.c |   14 +++---
 src/target/etm.c   |7 +--
 src/target/etm.h   |2 +-
 src/target/fa526.c |2 +-
 src/target/feroceon.c  |4 ++--
 src/target/mips32.c|5 -
 src/target/mips_m4k.c  |   10 --
 src/target/target.c|   12 +++-
 src/target/target_type.h   |2 +-
 src/target/xscale.c|   13 -
 31 files changed, 89 insertions(+), 149 deletions(-)

diff --git a/src/target/arm11.c b/src/target/arm11.c
index 835234c..7c6d39c 100644
--- a/src/target/arm11.c
+++ b/src/target/arm11.c
@@ -1617,6 +1617,12 @@ static const struct command_registration 
arm11_any_command_handlers[] = {
 };
 static const struct command_registration arm11_command_handlers[] = {
{
+   .chain = arm_command_handlers,
+   },
+   {
+   .chain = etm_command_handlers,
+   },
+   {
.name = arm11,
.mode = COMMAND_ANY,
.help = ARM11 command group,
@@ -1625,13 +1631,6 @@ static const struct command_registration 
arm11_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int arm11_register_commands(struct command_context *cmd_ctx)
-{
-   armv4_5_register_commands(cmd_ctx);
-   etm_register_commands(cmd_ctx);
-   return register_commands(cmd_ctx, NULL, arm11_command_handlers);
-}
-
 /** Holds methods for ARM11xx targets. */
 struct target_type arm11_target = {
.name = arm11,
@@ -1666,7 +1665,7 @@ struct target_type arm11_target = {
 
.run_algorithm =armv4_5_run_algorithm,
 
-   .register_commands =arm11_register_commands,
+   .commands = arm11_command_handlers,
.target_create =arm11_target_create,
.init_target =  arm11_init_target,
.examine =  arm11_examine,
diff --git a/src/target/arm720t.c b/src/target/arm720t.c
index 52a311c..bae2561 100644
--- a/src/target/arm720t.c
+++ b/src/target/arm720t.c
@@ -504,6 +504,9 @@ static const struct command_registration 
arm720t_exec_command_handlers[] = {
 
 static const struct command_registration arm720t_command_handlers[] = {
{
+   .chain = arm7_9_command_handlers,
+   },
+   {
.name = arm720t,
.mode = COMMAND_ANY,
.help = arm720t command group,
@@ -512,12 +515,6 @@ static const struct command_registration 
arm720t_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int arm720t_register_commands(struct command_context *cmd_ctx)
-{
-   arm7_9_register_commands(cmd_ctx);
-   return register_commands(cmd_ctx, NULL, arm720t_command_handlers);
-}
-
 /** Holds methods for ARM720 targets. */
 struct target_type arm720t_target =
 {
@@ -555,7 +552,7 @@ struct target_type arm720t_target =
.add_watchpoint = arm7_9_add_watchpoint,
.remove_watchpoint = arm7_9_remove_watchpoint,
 
-   .register_commands = arm720t_register_commands,
+   .commands = arm720t_command_handlers,
.target_create = arm720t_target_create,
.init_target = arm720t_init_target,
.examine = arm7_9_examine,
diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c
index b40be8d..c4775e8 100644
--- a/src/target/arm7_9_common.c
+++ b/src/target/arm7_9_common.c
@@ -2873,7 +2873,13 @@ static const struct command_registration 
arm7_9_any_command_handlers[] = {
},
COMMAND_REGISTRATION_DONE
 };
-static const struct command_registration arm7_9_command_handlers[] = {
+const struct command_registration arm7_9_command_handlers[] = {
+   {
+   .chain = arm_command_handlers,
+   },
+   {
+

[Openocd-development] [SERIES 6/6:0/10] final command registration bits

2009-11-24 Thread zw
Hi all,

This series contains some bits and pieces that fell out of the series,
but needed to wait for the other changes to go into the tree.

- integrate Jim command handlers with command_registration records
- add support for scripts to update command usage information
- Moves 'hello' and 'foo' commands into 'faux' and 'dummy' drivers.
- Adds the 'testee' target type, using the example commands.
- improves help/usage output by rewriting 'cmd_help' in C.
- log init cleanup: adds OPENOCD_DEBUG_LEVEL envirnoment setting

Cheers,

Zach

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 01/10] refactor command_new to use command_registration

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Save stack space: use a struct.  Makes it easier to add new parameters.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c |   22 ++
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index dd10965..8d710c9 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -238,23 +238,21 @@ static struct command **command_list_for_parent(
 }
 
 static struct command *command_new(struct command_context *cmd_ctx,
-   struct command *parent, const char *name,
-   command_handler_t handler, enum command_mode mode,
-   const char *help, const char *usage)
+   struct command *parent, const struct command_registration *cr)
 {
-   assert(name);
+   assert(cr-name);
 
struct command *c = malloc(sizeof(struct command));
memset(c, 0, sizeof(struct command));
 
-   c-name = strdup(name);
-   if (help)
-   c-help = strdup(help);
-   if (usage)
-   c-usage = strdup(usage);
+   c-name = strdup(cr-name);
+   if (cr-help)
+   c-help = strdup(cr-help);
+   if (cr-usage)
+   c-usage = strdup(cr-usage);
c-parent = parent;
-   c-handler = handler;
-   c-mode = mode;
+   c-handler = cr-handler;
+   c-mode = cr-mode;
 
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
 
@@ -328,7 +326,7 @@ struct command* register_command(struct command_context 
*context,
return c;
}
 
-   c = command_new(context, parent, name, cr-handler, cr-mode, cr-help, 
cr-usage);
+   c = command_new(context, parent, cr);
/* if allocation failed or it is a placeholder (no handler), we're done 
*/
if (NULL == c || NULL == c-handler)
return c;
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 02/10] add jim_handler to command_registration

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Adding jim_handler field to command_registration allows removing the
register_jim helper.  All command registrations now go through the
register_command{,s}() functions.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/flash.c|9 --
 src/helper/command.c |   42 --
 src/helper/command.h |7 +++--
 src/helper/ioutil.c  |   60 ++-
 src/jtag/tcl.c   |   43 ---
 src/target/target.c  |   68 +-
 6 files changed, 146 insertions(+), 83 deletions(-)

diff --git a/src/flash/flash.c b/src/flash/flash.c
index 4584c5d..bbdbaa8 100644
--- a/src/flash/flash.c
+++ b/src/flash/flash.c
@@ -1368,8 +1368,6 @@ static const struct command_registration 
flash_exec_command_handlers[] = {
 
 int flash_init_drivers(struct command_context *cmd_ctx)
 {
-   register_jim(cmd_ctx, ocd_flash_banks,
-   jim_flash_banks, return information about the flash 
banks);
if (!flash_banks)
return ERROR_OK;
 
@@ -1377,7 +1375,6 @@ int flash_init_drivers(struct command_context *cmd_ctx)
return register_commands(cmd_ctx, parent, flash_exec_command_handlers);
 }
 
-
 static const struct command_registration flash_config_command_handlers[] = {
{
.name = bank,
@@ -1389,6 +1386,12 @@ static const struct command_registration 
flash_config_command_handlers[] = {
.help = Define a new bank with the given name, 
using the specified NOR flash driver.,
},
+   {
+   .name = banks,
+   .mode = COMMAND_ANY,
+   .jim_handler = jim_flash_banks,
+   .help = return information about the flash banks,
+   },
COMMAND_REGISTRATION_DONE
 };
 static const struct command_registration flash_command_handlers[] = {
diff --git a/src/helper/command.c b/src/helper/command.c
index 8d710c9..3cb36ea 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -252,6 +252,8 @@ static struct command *command_new(struct command_context 
*cmd_ctx,
c-usage = strdup(cr-usage);
c-parent = parent;
c-handler = cr-handler;
+   c-jim_handler = cr-jim_handler;
+   c-jim_handler_data = cr-jim_handler_data;
c-mode = cr-mode;
 
command_add_child(command_list_for_parent(cmd_ctx, parent), c);
@@ -327,16 +329,22 @@ struct command* register_command(struct command_context 
*context,
}
 
c = command_new(context, parent, cr);
-   /* if allocation failed or it is a placeholder (no handler), we're done 
*/
-   if (NULL == c || NULL == c-handler)
-   return c;
+   if (NULL == c)
+   return NULL;
 
-   int retval = register_command_handler(c);
-   if (ERROR_OK != retval)
+   if (NULL != c-handler)
{
-   unregister_command(context, parent, name);
-   c = NULL;
+   int retval = register_command_handler(c);
+   if (ERROR_OK != retval)
+   {
+   unregister_command(context, parent, name);
+   return NULL;
+   }
}
+
+   if (NULL != cr-jim_handler  NULL == parent)
+   Jim_CreateCommand(interp, cr-name, cr-jim_handler, 
cr-jim_handler_data, NULL);
+
return c;
 }
 
@@ -882,7 +890,7 @@ static int command_unknown(Jim_Interp *interp, int argc, 
Jim_Obj *const *argv)
bool found = true;
Jim_Obj *const *start;
unsigned count;
-   if (c-handler)
+   if (c-handler || c-jim_handler)
{
// include the command name in the list
count = remaining + 1;
@@ -900,6 +908,12 @@ static int command_unknown(Jim_Interp *interp, int argc, 
Jim_Obj *const *argv)
start = argv;
found = false;
}
+   // pass the command through to the intended handler
+   if (c-jim_handler)
+   {
+   interp-cmdPrivData = c-jim_handler_data;
+   return (*c-jim_handler)(interp, count, start);
+   }
 
unsigned nwords;
const char **words = script_command_args_alloc(count, start, nwords);
@@ -1149,18 +1163,6 @@ void process_jim_events(void)
 #endif
 }
 
-void register_jim(struct command_context *cmd_ctx, const char *name,
-   Jim_CmdProc cmd, const char *help)
-{
-   Jim_CreateCommand(interp, name, cmd, NULL, NULL);
-
-   Jim_Obj *cmd_list = Jim_NewListObj(interp, NULL, 0);
-   Jim_ListAppendElement(interp, cmd_list,
-   Jim_NewStringObj(interp, name, -1));
-
-   help_add_command(cmd_ctx, NULL, name, help, NULL);
-}
-
 #define DEFINE_PARSE_NUM_TYPE(name, type, func, min, max) \
int parse##name(const char *str, type *ul) \
{ \
diff --git a/src/helper/command.h 

[Openocd-development] [PATCH 19/22] trace: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/trace.c |   39 +--
 1 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/target/trace.c b/src/target/trace.c
index c3897a0..f257592 100644
--- a/src/target/trace.c
+++ b/src/target/trace.c
@@ -156,16 +156,35 @@ COMMAND_HANDLER(handle_trace_history_command)
return ERROR_OK;
 }
 
+static const struct command_registration trace_exec_command_handlers[] = {
+   {
+   .name = history,
+   .handler = handle_trace_history_command,
+   .mode = COMMAND_EXEC,
+   .help = display trace history, clear history or set [size],
+   .usage = [clear|size],
+   },
+   {
+   .name = point,
+   .handler = handle_trace_point_command,
+   .mode = COMMAND_EXEC,
+   .help = display trace points, clear list of trace points, 
+   or add new tracepoint at [address],
+   .usage = [clear|address],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration trace_command_handlers[] = {
+   {
+   .name = trace,
+   .mode = COMMAND_ANY,
+   .help = trace command group,
+   .chain = trace_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int trace_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *trace_cmd =
-   COMMAND_REGISTER(cmd_ctx, NULL, trace, NULL, COMMAND_ANY, 
trace commands);
-
-   COMMAND_REGISTER(cmd_ctx, trace_cmd, history, 
handle_trace_history_command,
-   COMMAND_EXEC, display trace history, ['clear'] history or set 
[size]);
-
-   COMMAND_REGISTER(cmd_ctx, trace_cmd, point, 
handle_trace_point_command,
-   COMMAND_EXEC, display trace points, ['clear'] list of trace 
points, or add new tracepoint at [address]);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, trace_command_handlers);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 03/10] httpd: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Updates httpd_start() to use register_commands() for 'readform' and
'writeform' commands.  Adds server/httpd.h to export the new signatures
for this function (and httpd_stop), which allows removing the obsoleted
declarations inside openocd.c.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/openocd.c  |7 ++-
 src/server/Makefile.am |1 +
 src/server/httpd.c |   35 ---
 src/server/httpd.h |   28 
 4 files changed, 51 insertions(+), 20 deletions(-)
 create mode 100644 src/server/httpd.h

diff --git a/src/openocd.c b/src/openocd.c
index 63289e4..e38c84e 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -41,6 +41,7 @@
 #include telnet_server.h
 #include gdb_server.h
 #include tcl_server.h
+#include httpd.h
 
 #ifdef HAVE_STRINGS_H
 #include strings.h
@@ -216,10 +217,6 @@ struct command_context *setup_command_handler(void)
return cmd_ctx;
 }
 
-int httpd_start(void);
-void httpd_stop(void);
-
-
 #if !BUILD_HTTPD  !BUILD_ECOSBOARD
 /* implementations of OpenOCD that uses multithreading needs to know when
  * OpenOCD is sleeping. No-op in vanilla OpenOCD
@@ -269,7 +266,7 @@ int openocd_main(int argc, char *argv[])
return EXIT_FAILURE;
 
 #if BUILD_HTTPD
-   if (httpd_start() != ERROR_OK)
+   if (httpd_start(cmd_ctx) != ERROR_OK)
return EXIT_FAILURE;
 #endif
 
diff --git a/src/server/Makefile.am b/src/server/Makefile.am
index bb7d5ef..95fb519 100644
--- a/src/server/Makefile.am
+++ b/src/server/Makefile.am
@@ -14,6 +14,7 @@ libserver_la_SOURCES = server.c telnet_server.c gdb_server.c
 if HTTPD
 libserver_la_SOURCES += httpd.c
 endif
+noinst_HEADERS += httpd.h
 
 libserver_la_CFLAGS =
 if IS_MINGW
diff --git a/src/server/httpd.c b/src/server/httpd.c
index 1c5e6d2..8c1d3db 100644
--- a/src/server/httpd.c
+++ b/src/server/httpd.c
@@ -460,7 +460,25 @@ static int ahc_echo(void * cls, struct MHD_Connection * 
connection,
 
 static struct MHD_Daemon * d;
 
-int httpd_start(void)
+static const struct command_registration httpd_command_handlers[] = {
+   {
+   .name = formfetch,
+   .jim_handler = httpd_Jim_Command_formfetch,
+   .mode = COMMAND_EXEC,
+   .usage = parameter_name,
+   .help = Reads a posted form value.,
+   },
+   {
+   .name = writeform,
+   .jim_handler = httpd_Jim_Command_writeform,
+   .mode = COMMAND_EXEC,
+   .usage = parameter_name file,
+   .help = Writes a form value to a file.,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
+int httpd_start(struct command_context *cmd_ctx)
 {
pthread_mutexattr_t attr;
pthread_mutexattr_init(attr);
@@ -475,20 +493,7 @@ int httpd_start(void)
if (d == NULL)
return ERROR_FAIL;
 
-   Jim_CreateCommand(interp,
- formfetch,
- httpd_Jim_Command_formfetch,
- NULL,
- NULL);
-
-Jim_CreateCommand(interp,
-  writeform,
-  httpd_Jim_Command_writeform,
-  NULL,
-  NULL);
-
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, httpd_command_handlers);
 }
 
 void httpd_stop(void)
diff --git a/src/server/httpd.h b/src/server/httpd.h
new file mode 100644
index 000..0502deb
--- /dev/null
+++ b/src/server/httpd.h
@@ -0,0 +1,28 @@
+/***
+ *   Copyright (C) 2009 Zachary T Welch z...@superlucidity.net *
+ * *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or *
+ *   (at your option) any later version.   *
+ * *
+ *   This program is distributed in the hope that it will be useful,   *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of*
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *
+ *   GNU General Public License for more details.  *
+ * *
+ *   You should have received a copy of the GNU General Public License *
+ *   along with this program; if not, write to the *
+ *   Free Software Foundation, Inc.,   *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 

[Openocd-development] [PATCH 04/10] allow scripts to update usage information

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

The add_usage_text command uses the same C handler, which was updated
to support its new polymorphic role.  This patch updates the two script
commands that needed this support: 'find' and 'script'.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c   |   36 
 src/helper/startup.tcl |7 ---
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 3cb36ea..1263a93 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -951,8 +951,9 @@ int help_add_command(struct command_context *cmd_ctx, 
struct command *parent,
return ERROR_FAIL;
}
LOG_DEBUG(added '%s' help text, cmd_name);
+   return ERROR_OK;
}
-   else
+   if (help_text)
{
bool replaced = false;
if (nc-help)
@@ -961,12 +962,25 @@ int help_add_command(struct command_context *cmd_ctx, 
struct command *parent,
replaced = true;
}
nc-help = strdup(help_text);
-
if (replaced)
LOG_INFO(replaced existing '%s' help, cmd_name);
else
LOG_DEBUG(added '%s' help text, cmd_name);
}
+   if (usage)
+   {
+   bool replaced = false;
+   if (nc-usage)
+   {
+   free((void *)nc-usage);
+   replaced = true;
+   }
+   nc-usage = strdup(usage);
+   if (replaced)
+   LOG_INFO(replaced existing '%s' usage, cmd_name);
+   else
+   LOG_DEBUG(added '%s' usage text, cmd_name);
+   }
return ERROR_OK;
 }
 
@@ -979,7 +993,14 @@ COMMAND_HANDLER(handle_help_add_command)
}
 
// save help text and remove it from argument list
-   const char *help_text = CMD_ARGV[--CMD_ARGC];
+   const char *str = CMD_ARGV[--CMD_ARGC];
+   const char *help = !strcmp(CMD_NAME, add_help_text) ? str : NULL;
+   const char *usage = !strcmp(CMD_NAME, add_usage_text) ? str : NULL;
+   if (!help  !usage)
+   {
+   LOG_ERROR(command name '%s' is unknown, CMD_NAME);
+   return ERROR_INVALID_ARGUMENTS;
+   }
// likewise for the leaf command name
const char *cmd_name = CMD_ARGV[--CMD_ARGC];
 
@@ -991,7 +1012,7 @@ COMMAND_HANDLER(handle_help_add_command)
if (ERROR_OK != retval)
return retval;
}
-   return help_add_command(CMD_CTX, c, cmd_name, help_text, NULL);
+   return help_add_command(CMD_CTX, c, cmd_name, help, usage);
 }
 
 /* sleep command sleeps for n miliseconds
@@ -1039,6 +1060,13 @@ static const struct command_registration 
command_builtin_handlers[] = {
.usage = command [...] help_text],
},
{
+   .name = add_usage_text,
+   .handler = handle_help_add_command,
+   .mode = COMMAND_ANY,
+   .help = add new command usage text,
+   .usage = command [...] usage_text],
+   },
+   {
.name = sleep,
.handler = handle_sleep_command,
.mode = COMMAND_ANY,
diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl
index ede8cdb..5969cfe 100644
--- a/src/helper/startup.tcl
+++ b/src/helper/startup.tcl
@@ -59,14 +59,15 @@ proc find {filename} {
# make sure error message matches original input string
return -code error Can't find $filename
 }
-add_help_text find file - print full path to file according to OpenOCD 
search rules
+add_usage_text find file
+add_help_text find print full path to file according to OpenOCD search rules
 
 # Run script
 proc script {filename} {
source [find $filename]
 }
-
-add_help_text script filename - filename of OpenOCD script (tcl) to run
+add_help_text script filename of OpenOCD script (tcl) to run
+add_usage_text script file
 
 #
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 05/10] improve usage and help command output

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Rewrite formatting code in C, removing last remenants of TCL help code.
Sinificantly improves the readability by using smarter indent and wrap.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c   |   48 ++--
 src/helper/startup.tcl |   34 --
 2 files changed, 38 insertions(+), 44 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 1263a93..a1ba358 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -811,20 +811,48 @@ static COMMAND_HELPER(command_help_show_list, struct 
command *head, unsigned n,
CALL_COMMAND_HANDLER(command_help_show, c, n, show_help);
return ERROR_OK;
 }
+
+#define HELP_LINE_WIDTH(_n) (int)(76 - (2 * _n))
+
+static void command_help_show_indent(unsigned n)
+{
+   for (unsigned i = 0; i  n; i++)
+   LOG_USER_N(  );
+}
+static void command_help_show_wrap(const char *str, unsigned n, unsigned n2)
+{
+   const char *cp = str, *last = str;
+   while (*cp)
+   {
+   const char *next = last;
+   do {
+   cp = next;
+   do {
+   next++;
+   } while (*next != ' '  *next != '\t'  *next != 
'\0');
+   } while ((next - last  HELP_LINE_WIDTH(n))  *next != '\0');
+   if (next - last  HELP_LINE_WIDTH(n))
+   cp = next;
+   command_help_show_indent(n);
+   LOG_USER_N(%.*s, (int)(cp - last), last);
+   LOG_USER_N(\n);
+   last = cp + 1;
+   n = n2;
+   }
+}
 static COMMAND_HELPER(command_help_show, struct command *c, unsigned n,
bool show_help)
 {
-   const char *usage = c-usage ? : ;
-   const char *help = ;
-   const char *sep = ;
-   if (show_help  c-help)
-   {
-   help = c-help ? : ;
-   sep = c-usage ?  |  : ;
+   command_help_show_indent(n);
+   LOG_USER_N(%s, command_name(c, ' '));
+   if (c-usage) {
+   LOG_USER_N( );
+   command_help_show_wrap(c-usage, 0, n + 5);
}
-   command_run_linef(CMD_CTX, cmd_help {%s} {%s%s%s} %d,
-   command_name(c, ' '), usage, sep, help, n);
-
+   else
+   LOG_USER_N(\n);
+   if (show_help  c-help)
+   command_help_show_wrap(c-help, n + 3, n + 3);
if (++n = 2)
return ERROR_OK;
 
diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl
index 5969cfe..f11d5b6 100644
--- a/src/helper/startup.tcl
+++ b/src/helper/startup.tcl
@@ -10,40 +10,6 @@ proc exit {} {
ocd_throw exit
 }
 
-# Help text list. A list of command + help text pairs.
-proc cmd_help {cmdname h indent} {
-   set indent [expr $indent * 2]
-
-   set fmt_str [format %%%ds%%-%ds %%s $indent [expr 25 - $indent]]
-   set w [expr 50 - $indent]
-   set n 0
-
-   while 1 {
-   if {$n  [string length $h]} {break}
-
-   set next_a [expr $n + $w]
-   if {[string length $h]  $n + $w} \
-   {
-   set  [string range $h $n [expr $n + $w]]
-   for {set lastpos [expr [string length $] - 1]} \
-   {$lastpos = 0  [string compare \
-   [string range $ $lastpos $lastpos] 
 ] != 0} \
-   {set lastpos [expr $lastpos - 1]} \
-   {
-   }
-   #set next_a -1
-   if {$lastpos != -1} {
-   set next_a [expr $lastpos + $n + 1]
-   }
-   }
-
-   puts [format $fmt_str  $cmdname \
-   [string range $h $n [expr $next_a - 1]] ]
-   set cmdname 
-   set n [expr $next_a]
-   }
-}
-
 # Try flipping / and \ to find file if the filename does not
 # match the precise spelling
 proc find {filename} {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 06/10] improve command handling examples

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Removes hello and foo commands from top-level registration.  Instead,
the dummy interface driver and faux flash driver have been augmented
to register these commands as sub-commands.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/faux.c |   12 
 src/hello.c  |2 +-
 src/hello.h  |   35 +++
 src/jtag/dummy.c |   14 ++
 src/openocd.c|4 
 5 files changed, 62 insertions(+), 5 deletions(-)
 create mode 100644 src/hello.h

diff --git a/src/flash/faux.c b/src/flash/faux.c
index adfc7bd..caec2c7 100644
--- a/src/flash/faux.c
+++ b/src/flash/faux.c
@@ -23,6 +23,7 @@
 
 #include flash.h
 #include image.h
+#include ../hello.h
 
 
 struct faux_flash_bank
@@ -123,8 +124,19 @@ static int faux_probe(struct flash_bank *bank)
return ERROR_OK;
 }
 
+static const struct command_registration faux_command_handlers[] = {
+   {
+   .name = faux,
+   .mode = COMMAND_ANY,
+   .help = faux flash command group,
+   .chain = hello_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 struct flash_driver faux_flash = {
.name = faux,
+   .commands = faux_command_handlers,
.flash_bank_command = faux_flash_bank_command,
.erase = faux_erase,
.protect = faux_protect,
diff --git a/src/hello.c b/src/hello.c
index 9a1bf92..2e5c928 100644
--- a/src/hello.c
+++ b/src/hello.c
@@ -101,7 +101,7 @@ COMMAND_HANDLER(handle_hello_command)
return retval;
 }
 
-static const struct command_registration hello_command_handlers[] = {
+const struct command_registration hello_command_handlers[] = {
{
.name = hello,
.handler = handle_hello_command,
diff --git a/src/hello.h b/src/hello.h
new file mode 100644
index 000..fc674ad
--- /dev/null
+++ b/src/hello.h
@@ -0,0 +1,35 @@
+/***
+ *   Copyright (C) 2009 Zachary T Welch z...@superlucidity.net *
+ * *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or *
+ *   (at your option) any later version.   *
+ * *
+ *   This program is distributed in the hope that it will be useful,   *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of*
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *
+ *   GNU General Public License for more details.  *
+ * *
+ *   You should have received a copy of the GNU General Public License *
+ *   along with this program; if not, write to the *
+ *   Free Software Foundation, Inc.,   *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
+ ***/
+
+#ifndef OPENOCD_HELLO_H
+#define OPENOCD_HELLO_H
+
+struct command_context;
+struct command_registration;
+
+/// Register the hello commands in the specified command_context
+int hello_register_commands(struct command_context *cmd_ctx);
+
+/**
+ * Export the registration for the hello command group, so it can be
+ * embedded in example drivers.
+ */
+extern const struct command_registration hello_command_handlers[];
+
+#endif // OPENOCD_HELLO_H
diff --git a/src/jtag/dummy.c b/src/jtag/dummy.c
index 11b6f71..c2beb09 100644
--- a/src/jtag/dummy.c
+++ b/src/jtag/dummy.c
@@ -23,6 +23,7 @@
 
 #include interface.h
 #include bitbang.h
+#include ../hello.h
 
 
 /* my private tap controller state, which tracks state for calling code */
@@ -146,12 +147,25 @@ static int dummy_quit(void)
return ERROR_OK;
 }
 
+static const struct command_registration dummy_command_handlers[] = {
+   {
+   .name = dummy,
+   .mode = COMMAND_ANY,
+   .help = dummy interface driver commands,
+
+   .chain = hello_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE,
+};
+
 /* The dummy driver is used to easily check the code path
  * where the target is unresponsive.
  */
 struct jtag_interface dummy_interface = {
.name = dummy,
 
+   .commands = dummy_command_handlers,
+
.execute_queue = bitbang_execute_queue,
 
.speed = dummy_speed,
diff --git a/src/openocd.c b/src/openocd.c
index e38c84e..1f29acd 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -179,9 +179,6 @@ 

[Openocd-development] [PATCH 07/10] allow target_type.h to be included alone

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

It is an error to require other headers to be included first, so declare
what we can (struct declarations) and include the rest (Jim types).

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/target_type.h |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/target/target_type.h b/src/target/target_type.h
index 9a0709d..7504b02 100644
--- a/src/target/target_type.h
+++ b/src/target/target_type.h
@@ -27,8 +27,15 @@
 #define TARGET_TYPE_H
 
 #include types.h
+#include jim.h
 
 struct target;
+struct reg;
+struct reg_param;
+struct mem_param;
+struct breakpoint;
+struct watchpoint;
+struct command_context;
 
 /**
  * This holds methods shared between all instances of a given target
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 08/10] add 'testee' target type

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Alliteration aside, this should provide the final piece of the puzzle
for developers that want to get started writing a new target type.
In this way, it also seeks to complement the 'dummy' interface driver
and 'faux' NOR flash driver.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/Makefile.am |3 ++-
 src/target/target.c|2 ++
 src/target/testee.c|   47 +++
 3 files changed, 51 insertions(+), 1 deletions(-)
 create mode 100644 src/target/testee.c

diff --git a/src/target/Makefile.am b/src/target/Makefile.am
index a367fd4..d00b0e4 100644
--- a/src/target/Makefile.am
+++ b/src/target/Makefile.am
@@ -42,7 +42,8 @@ TARGET_CORE_SRC = \
image.c \
breakpoints.c \
target.c \
-   target_request.c
+   target_request.c \
+   testee.c
 
 ARMV4_5_SRC = \
armv4_5.c \
diff --git a/src/target/target.c b/src/target/target.c
index 4a9095a..97a93c0 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -65,6 +65,7 @@ extern struct target_type cortexa8_target;
 extern struct target_type arm11_target;
 extern struct target_type mips_m4k_target;
 extern struct target_type avr_target;
+extern struct target_type testee_target;
 
 struct target_type *target_types[] =
 {
@@ -83,6 +84,7 @@ struct target_type *target_types[] =
arm11_target,
mips_m4k_target,
avr_target,
+   testee_target,
NULL,
 };
 
diff --git a/src/target/testee.c b/src/target/testee.c
new file mode 100644
index 000..65fd427
--- /dev/null
+++ b/src/target/testee.c
@@ -0,0 +1,47 @@
+/***
+ *   Copyright (C) 2009 Zachary T Welch z...@superlucidity.net *
+ * *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or *
+ *   (at your option) any later version.   *
+ * *
+ *   This program is distributed in the hope that it will be useful,   *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of*
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *
+ *   GNU General Public License for more details.  *
+ * *
+ *   You should have received a copy of the GNU General Public License *
+ *   along with this program; if not, write to the *
+ *   Free Software Foundation, Inc.,   *
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. *
+ ***/
+
+#ifdef HAVE_CONFIG_H
+#include config.h
+#endif
+#include target_type.h
+#include log.h
+#include ../hello.h
+
+static const struct command_registration testee_command_handlers[] = {
+   {
+   .name = testee,
+   .mode = COMMAND_ANY,
+   .help = testee target commands,
+
+   .chain = hello_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
+static int testee_init(struct command_context *cmd_ctx, struct target *target)
+{
+   return ERROR_OK;
+}
+
+struct target_type testee_target = {
+   .name = testee,
+   .init_target = testee_init,
+   .commands = testee_command_handlers,
+};
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 06/12] add command usage, separate from help

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Adds the usage command, to display usage information for commands.
The output for this command will remain erronenously empty until
commands are updated to use these new coventions.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c |   63 ++---
 src/helper/command.h |3 ++
 2 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 51b3f9f..df4667b 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -226,7 +226,7 @@ static struct command **command_list_for_parent(
 static struct command *command_new(struct command_context *cmd_ctx,
struct command *parent, const char *name,
command_handler_t handler, enum command_mode mode,
-   const char *help)
+   const char *help, const char *usage)
 {
assert(name);
 
@@ -236,6 +236,8 @@ static struct command *command_new(struct command_context 
*cmd_ctx,
c-name = strdup(name);
if (help)
c-help = strdup(help);
+   if (usage)
+   c-usage = strdup(usage);
c-parent = parent;
c-handler = handler;
c-mode = mode;
@@ -259,6 +261,8 @@ static void command_free(struct command *c)
free(c-name);
if (c-help)
free((void*)c-help);
+   if (c-usage)
+   free((void*)c-usage);
free(c);
 }
 
@@ -278,7 +282,7 @@ struct command* register_command(struct command_context 
*context,
return c;
}
 
-   c = command_new(context, parent, name, cr-handler, cr-mode, cr-help);
+   c = command_new(context, parent, name, cr-handler, cr-mode, cr-help, 
cr-usage);
/* if allocation failed or it is a placeholder (no handler), we're done 
*/
if (NULL == c || NULL == c-handler)
return c;
@@ -737,41 +741,67 @@ static COMMAND_HELPER(command_help_find, struct command 
*head,
return CALL_COMMAND_HANDLER(command_help_find, (*out)-children, out);
 }
 
-static COMMAND_HELPER(command_help_show, struct command *c, unsigned n);
+static COMMAND_HELPER(command_help_show, struct command *c, unsigned n,
+   bool show_help);
 
-static COMMAND_HELPER(command_help_show_list, struct command *head, unsigned n)
+static COMMAND_HELPER(command_help_show_list, struct command *head, unsigned n,
+   bool show_help)
 {
for (struct command *c = head; NULL != c; c = c-next)
-   CALL_COMMAND_HANDLER(command_help_show, c, n);
+   CALL_COMMAND_HANDLER(command_help_show, c, n, show_help);
return ERROR_OK;
 }
-static COMMAND_HELPER(command_help_show, struct command *c, unsigned n)
+static COMMAND_HELPER(command_help_show, struct command *c, unsigned n,
+   bool show_help)
 {
-   command_run_linef(CMD_CTX, cmd_help {%s} {%s} %d, command_name(c, ' 
'),
-   c-help ? : no help available, n);
+   const char *usage = c-usage ? : ;
+   const char *help = ;
+   const char *sep = ;
+   if (show_help  c-help)
+   {
+   help = c-help ? : ;
+   sep = c-usage ?  |  : ;
+   }
+   command_run_linef(CMD_CTX, cmd_help {%s} {%s%s%s} %d,
+   command_name(c, ' '), usage, sep, help, n);
 
if (++n = 2)
return ERROR_OK;
 
-   return CALL_COMMAND_HANDLER(command_help_show_list, c-children, n);
+   return CALL_COMMAND_HANDLER(command_help_show_list,
+   c-children, n, show_help);
 }
 COMMAND_HANDLER(handle_help_command)
 {
struct command *c = CMD_CTX-commands;
 
if (0 == CMD_ARGC)
-   return CALL_COMMAND_HANDLER(command_help_show_list, c, 0);
+   return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, true);
+
+   int retval = CALL_COMMAND_HANDLER(command_help_find, c, c);
+   if (ERROR_OK != retval)
+   return retval;
+
+   return CALL_COMMAND_HANDLER(command_help_show, c, 0, true);
+}
+
+COMMAND_HANDLER(handle_usage_command)
+{
+   struct command *c = CMD_CTX-commands;
+
+   if (0 == CMD_ARGC)
+   return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, 
false);
 
int retval = CALL_COMMAND_HANDLER(command_help_find, c, c);
if (ERROR_OK != retval)
return retval;
 
-   return CALL_COMMAND_HANDLER(command_help_show, c, 0);
+   return CALL_COMMAND_HANDLER(command_help_show, c, 0, false);
 }
 
 
 int help_add_command(struct command_context *cmd_ctx, struct command *parent,
-   const char *cmd_name, const char *help_text)
+   const char *cmd_name, const char *help_text, const char *usage)
 {
struct command **head = command_list_for_parent(cmd_ctx, parent);
struct command *nc = command_find(*head, cmd_name);
@@ -782,6 +812,7 @@ int 

[Openocd-development] [PATCH 08/12] more command registration refactoring

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Split out the handler registration into its own function, and add a
few obviously missing NULL pointer error checking.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/command.c |   54 +++--
 1 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/src/helper/command.c b/src/helper/command.c
index 28952fd..9cc996c 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -266,6 +266,38 @@ static void command_free(struct command *c)
free(c);
 }
 
+static int register_command_handler(struct command *c)
+{
+   int retval = -ENOMEM;
+   const char *full_name = command_name(c, '_');
+   if (NULL == full_name)
+   return retval;
+
+   const char *ocd_name = alloc_printf(ocd_%s, full_name);
+   if (NULL == full_name)
+   goto free_full_name;
+
+   Jim_CreateCommand(interp, ocd_name, script_command, c, NULL);
+   free((void *)ocd_name);
+
+   /* we now need to add an overrideable proc */
+   const char *override_name = alloc_printf(proc %s {args} {
+   if {[catch {eval ocd_%s $args}] == 0} 
+   {return \\} else {return -code error}},
+   full_name, full_name);
+   if (NULL == full_name)
+   goto free_full_name;
+
+   Jim_Eval_Named(interp, override_name, __THIS__FILE__, __LINE__);
+   free((void *)override_name);
+
+   retval = ERROR_OK;
+
+free_full_name:
+   free((void *)full_name);
+   return retval;
+}
+
 struct command* register_command(struct command_context *context,
struct command *parent, const struct command_registration *cr)
 {
@@ -287,22 +319,12 @@ struct command* register_command(struct command_context 
*context,
if (NULL == c || NULL == c-handler)
return c;
 
-   const char *full_name = command_name(c, '_');
-
-   const char *ocd_name = alloc_printf(ocd_%s, full_name);
-   Jim_CreateCommand(interp, ocd_name, script_command, c, NULL);
-   free((void *)ocd_name);
-
-   /* we now need to add an overrideable proc */
-   const char *override_name = alloc_printf(proc %s {args} {
-   if {[catch {eval ocd_%s $args}] == 0} 
-   {return \\} else {return -code error}},
-   full_name, full_name);
-   Jim_Eval_Named(interp, override_name, __THIS__FILE__, __LINE__);
-   free((void *)override_name);
-
-   free((void *)full_name);
-
+   int retval = register_command_handler(c);
+   if (ERROR_OK != retval)
+   {
+   unregister_command(context, parent, name);
+   c = NULL;
+   }
return c;
 }
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 7/9] {, x}svf: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() for registering {,x}svf commands.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/svf/svf.c   |   17 -
 src/xsvf/xsvf.c |   20 +++-
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/svf/svf.c b/src/svf/svf.c
index 1fc3835..e01b933 100644
--- a/src/svf/svf.c
+++ b/src/svf/svf.c
@@ -1460,11 +1460,18 @@ static int svf_run_command(struct command_context 
*cmd_ctx, char *cmd_str)
return ERROR_OK;
 }
 
+static const struct command_registration svf_command_handlers[] = {
+   {
+   .name = svf,
+   .handler = handle_svf_command,
+   .mode = COMMAND_EXEC,
+   .help = Runs a SVF file.,
+   .usage = file,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int svf_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, svf,
-   handle_svf_command, COMMAND_EXEC,
-   run svf file);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, svf_command_handlers);
 }
diff --git a/src/xsvf/xsvf.c b/src/xsvf/xsvf.c
index 82ddb84..f5c89d4 100644
--- a/src/xsvf/xsvf.c
+++ b/src/xsvf/xsvf.c
@@ -1050,13 +1050,23 @@ COMMAND_HANDLER(handle_xsvf_command)
return ERROR_OK;
 }
 
+static const struct command_registration xsvf_command_handlers[] = {
+   {
+   .name = xsvf,
+   .handler = handle_xsvf_command,
+   .mode = COMMAND_EXEC,
+   .help = Runs a XSVF file.  If 'virt2' is given, xruntest 
+   counts are interpreted as TCK cycles rather than 
+   as microseconds.  Without the 'quiet' option, all 
+   comments, retries, and mismatches will be reported.,
+   .usage = file [virt2] [quiet],
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int xsvf_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, xsvf,
-   handle_xsvf_command, COMMAND_EXEC,
-   run xsvf file [virt2] [quiet]);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, xsvf_command_handlers);
 }
 
 #if 0   /* this comment style used to try and keep uncrustify from adding * at 
begin of line */
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 8/9] pld: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Updates core PLD and virtex2 commands to use register_commands().

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/pld/pld.c |   53 +++--
 src/pld/virtex2.c |   29 +
 2 files changed, 60 insertions(+), 22 deletions(-)

diff --git a/src/pld/pld.c b/src/pld/pld.c
index 021a8e6..421fc61 100644
--- a/src/pld/pld.c
+++ b/src/pld/pld.c
@@ -37,7 +37,6 @@ static struct pld_driver *pld_drivers[] =
 };
 
 static struct pld_device *pld_devices;
-static struct command *pld_cmd;
 
 struct pld_device *get_pld_device_by_num(int num)
 {
@@ -184,26 +183,52 @@ COMMAND_HANDLER(handle_pld_load_command)
return ERROR_OK;
 }
 
+static const struct command_registration pld_exec_command_handlers[] = {
+   {
+   .name = devices,
+   .handler = handle_pld_devices_command,
+   .mode = COMMAND_EXEC,
+   .help = list configured pld devices,
+   },
+   {
+   .name = load,
+   .handler = handle_pld_load_command,
+   .mode = COMMAND_EXEC,
+   .help = load configuration file into PLD,
+   .usage = device# file,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 int pld_init(struct command_context *cmd_ctx)
 {
if (!pld_devices)
return ERROR_OK;
 
-   COMMAND_REGISTER(cmd_ctx, pld_cmd, devices,
-   handle_pld_devices_command, COMMAND_EXEC,
-   list configured pld devices);
-   COMMAND_REGISTER(cmd_ctx, pld_cmd, load,
-   handle_pld_load_command, COMMAND_EXEC,
-   load configuration file into programmable logic 
device);
-
-   return ERROR_OK;
+   struct command *parent = command_find_in_context(cmd_ctx, pld);
+   return register_commands(cmd_ctx, parent, pld_exec_command_handlers);
 }
 
+static const struct command_registration pld_config_command_handlers[] = {
+   {
+   .name = device,
+   .mode = COMMAND_CONFIG,
+   .handler = handle_pld_device_command,
+   .help = configure a PLD device,
+   .usage = driver ...,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration pld_command_handler[] = {
+   {
+   .name = pld,
+   .mode = COMMAND_ANY,
+   .help = programmable logic device commands,
+
+   .chain = pld_config_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 int pld_register_commands(struct command_context *cmd_ctx)
 {
-   pld_cmd = COMMAND_REGISTER(cmd_ctx, NULL, pld, NULL, COMMAND_ANY, 
programmable logic device commands);
-
-   COMMAND_REGISTER(cmd_ctx, pld_cmd, device, handle_pld_device_command, 
COMMAND_CONFIG, NULL);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, pld_command_handler);
 }
diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c
index 527434a..1025e61 100644
--- a/src/pld/virtex2.c
+++ b/src/pld/virtex2.c
@@ -233,16 +233,29 @@ PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command)
return ERROR_OK;
 }
 
+static const struct command_registration virtex2_exec_command_handlers[] = {
+   {
+   .name = read_stat,
+   .mode = COMMAND_EXEC,
+   .handler = virtex2_handle_read_stat_command,
+   .help = read status register,
+   .usage = device_id,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration virtex2_command_handler[] = {
+   {
+   .name = virtex2,
+   .mode = COMMAND_ANY,
+   .help = Virtex-II specific commands,
+   .chain = virtex2_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int virtex2_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *virtex2_cmd = COMMAND_REGISTER(cmd_ctx, NULL, virtex2,
-   NULL, COMMAND_ANY, virtex2 specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, virtex2_cmd, read_stat,
-   virtex2_handle_read_stat_command, COMMAND_EXEC,
-   read Virtex-II status register);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, virtex2_command_handler);
 }
 
 struct pld_driver virtex2_pld = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 9/9] pld: use static registration instead of callback

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Remove register_callbacks from pld_device structure, using an array
of command_registration records instead.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/pld/pld.c |   15 ++-
 src/pld/pld.h |2 +-
 src/pld/virtex2.c |7 +--
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/pld/pld.c b/src/pld/pld.c
index 421fc61..24afd07 100644
--- a/src/pld/pld.c
+++ b/src/pld/pld.c
@@ -74,17 +74,22 @@ COMMAND_HANDLER(handle_pld_device_command)
struct pld_device *p, *c;
 
/* register pld specific commands */
-   if (pld_drivers[i]-register_commands(CMD_CTX) != 
ERROR_OK)
-   {
-   LOG_ERROR(couldn't register '%s' commands, 
CMD_ARGV[0]);
-   exit(-1);
+   int retval;
+   if (pld_drivers[i]-commands) {
+   retval = register_commands(CMD_CTX, NULL, 
+   pld_drivers[i]-commands);
+   if (ERROR_OK != retval)
+   {
+   LOG_ERROR(couldn't register '%s' 
commands, CMD_ARGV[0]);
+   return ERROR_FAIL;
+   }
}
 
c = malloc(sizeof(struct pld_device));
c-driver = pld_drivers[i];
c-next = NULL;
 
-   int retval = 
CALL_COMMAND_HANDLER(pld_drivers[i]-pld_device_command, c);
+   retval = 
CALL_COMMAND_HANDLER(pld_drivers[i]-pld_device_command, c);
if (ERROR_OK != retval)
{
LOG_ERROR('%s' driver rejected pld device, 
CMD_ARGV[0]);
diff --git a/src/pld/pld.h b/src/pld/pld.h
index b183e3e..1ae775c 100644
--- a/src/pld/pld.h
+++ b/src/pld/pld.h
@@ -31,7 +31,7 @@ struct pld_driver
 {
char *name;
__PLD_DEVICE_COMMAND((*pld_device_command));
-   int (*register_commands)(struct command_context *cmd_ctx);
+   const struct command_registration *commands;
int (*load)(struct pld_device *pld_device, const char *filename);
 };
 
diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c
index 1025e61..77eb866 100644
--- a/src/pld/virtex2.c
+++ b/src/pld/virtex2.c
@@ -253,14 +253,9 @@ static const struct command_registration 
virtex2_command_handler[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int virtex2_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, virtex2_command_handler);
-}
-
 struct pld_driver virtex2_pld = {
.name = virtex2,
-   .register_commands = virtex2_register_commands,
+   .commands = virtex2_command_handler,
.pld_device_command = virtex2_pld_device_command,
.load = virtex2_load,
};
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 08/11] presto: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/presto.c |   15 ---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/jtag/presto.c b/src/jtag/presto.c
index f22bd9e..dc40750 100644
--- a/src/jtag/presto.c
+++ b/src/jtag/presto.c
@@ -739,11 +739,20 @@ COMMAND_HANDLER(presto_handle_serial_command)
return ERROR_OK;
 }
 
+static const struct command_registration presto_command_handlers[] = {
+   {
+   .name = presto_serial,
+   .handler = presto_handle_serial_command,
+   .mode = COMMAND_CONFIG,
+   .help = configure serial port,
+   .usage = devname,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int presto_jtag_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, presto_serial, 
presto_handle_serial_command,
-   COMMAND_CONFIG, NULL);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, presto_command_handlers);
 }
 
 static int presto_jtag_init(void)
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 07/11] parport: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with a command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/parport.c |   57 +--
 1 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/jtag/parport.c b/src/jtag/parport.c
index 4b4df09..abf0d29 100644
--- a/src/jtag/parport.c
+++ b/src/jtag/parport.c
@@ -482,28 +482,45 @@ 
COMMAND_HANDLER(parport_handle_parport_toggling_time_command)
return ERROR_OK;
 }
 
-static int parport_register_commands(struct command_context *cmd_ctx)
-{
-   COMMAND_REGISTER(cmd_ctx, NULL, parport_port,
-   parport_handle_parport_port_command, COMMAND_CONFIG,
-   either the address of the I/O port 
-   or the number of the '/dev/parport' device);
-
-   COMMAND_REGISTER(cmd_ctx, NULL, parport_cable,
-   parport_handle_parport_cable_command, COMMAND_CONFIG,
-   the layout of the parallel port cable 
-   used to connect to the target);
-
-   COMMAND_REGISTER(cmd_ctx, NULL, parport_write_on_exit,
-   parport_handle_write_on_exit_command, COMMAND_CONFIG,
-   configure the parallel driver to write 
-   a known value to the parallel interface);
+static const struct command_registration parport_command_handlers[] = {
+   {
+   .name = parport_port,
+   .handler = parport_handle_parport_port_command,
+   .mode = COMMAND_CONFIG,
+   .help = either the address of the I/O port 
+   or the number of the '/dev/parport' device,
+   .usage = [port|devname],
+   },
+   {
+   .name = parport_cable,
+   .handler = parport_handle_parport_cable_command,
+   .mode = COMMAND_CONFIG,
+   .help = the layout of the parallel port cable 
+   used to connect to the target,
+   .usage = [layout],
+   },
+   {
+   .name = parport_write_on_exit,
+   .handler = parport_handle_write_on_exit_command,
+   .mode = COMMAND_CONFIG,
+   .help = configure the parallel driver to write 
+   a known value to the parallel interface,
+   .usage = [on|off],
+   },
+   {
+   .name = parport_toggling_time,
+   .handler = parport_handle_parport_toggling_time_command,
+   .mode = COMMAND_CONFIG,
+   .help = time ns it takes for the hardware to toggle TCK,
+   .usage = [ns],
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
-   COMMAND_REGISTER(cmd_ctx, NULL, parport_toggling_time,
-   parport_handle_parport_toggling_time_command, 
COMMAND_ANY,
-   time ns it takes for the hardware to toggle TCK);
 
-   return ERROR_OK;
+static int parport_register_commands(struct command_context *cmd_ctx)
+{
+   return register_commands(cmd_ctx, NULL, parport_command_handlers);
 }
 
 struct jtag_interface parport_interface = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 10/11] vsllink: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register_commands() with command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/vsllink.c |   55 +--
 1 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/src/jtag/vsllink.c b/src/jtag/vsllink.c
index 3526198..8287e84 100644
--- a/src/jtag/vsllink.c
+++ b/src/jtag/vsllink.c
@@ -1856,28 +1856,43 @@ static void vsllink_debug_buffer(uint8_t *buffer, int 
length)
 }
 #endif // _DEBUG_USB_COMMS_ || _DEBUG_JTAG_IO_
 
+static const struct command_registration vsllink_command_handlers[] = {
+   {
+   .name = vsllink_usb_vid,
+   .handler = vsllink_handle_usb_vid_command,
+   .mode = COMMAND_CONFIG,
+   },
+   {
+   .name = vsllink_usb_pid,
+   .handler = vsllink_handle_usb_pid_command,
+   .mode = COMMAND_CONFIG,
+   },
+   {
+   .name = vsllink_usb_bulkin,
+   .handler = vsllink_handle_usb_bulkin_command,
+   .mode = COMMAND_CONFIG,
+   },
+   {
+   .name = vsllink_usb_bulkout,
+   .handler = vsllink_handle_usb_bulkout_command,
+   .mode = COMMAND_CONFIG,
+   },
+   {
+   .name = vsllink_usb_interface,
+   .handler = vsllink_handle_usb_interface_command,
+   .mode = COMMAND_CONFIG,
+   },
+   {
+   .name = vsllink_mode,
+   .handler = vsllink_handle_mode_command,
+   .mode = COMMAND_CONFIG,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int vsllink_register_commands(struct command_context *cmd_ctx)
 {
-   COMMAND_REGISTER(cmd_ctx, NULL, vsllink_usb_vid,
-   vsllink_handle_usb_vid_command, COMMAND_CONFIG,
-   NULL);
-   COMMAND_REGISTER(cmd_ctx, NULL, vsllink_usb_pid,
-   vsllink_handle_usb_pid_command, COMMAND_CONFIG,
-   NULL);
-   COMMAND_REGISTER(cmd_ctx, NULL, vsllink_usb_bulkin,
-   vsllink_handle_usb_bulkin_command, COMMAND_CONFIG,
-   NULL);
-   COMMAND_REGISTER(cmd_ctx, NULL, vsllink_usb_bulkout,
-   vsllink_handle_usb_bulkout_command, COMMAND_CONFIG,
-   NULL);
-   COMMAND_REGISTER(cmd_ctx, NULL, vsllink_usb_interface,
-   vsllink_handle_usb_interface_command, COMMAND_CONFIG,
-   NULL);
-   COMMAND_REGISTER(cmd_ctx, NULL, vsllink_mode,
-   vsllink_handle_mode_command, COMMAND_CONFIG,
-   NULL);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, vsllink_command_handlers);
 }
 
 struct jtag_interface vsllink_interface = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 09/11] jtag: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Use register commands with command registration array.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/tcl.c |  186 
 1 files changed, 119 insertions(+), 67 deletions(-)

diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c
index bd672b6..81dbdb5 100644
--- a/src/jtag/tcl.c
+++ b/src/jtag/tcl.c
@@ -1413,66 +1413,129 @@ COMMAND_HANDLER(handle_tms_sequence_command)
return ERROR_OK;
 }
 
+static const struct command_registration jtag_command_handlers[] = {
+   {
+   .name = interface,
+   .handler = handle_interface_command,
+   .mode = COMMAND_CONFIG,
+   .help = select a JTAG interface,
+   .usage = driver_name,
+   },
+   {
+   .name = interface_list,
+   .handler = handle_interface_list_command,
+   .mode = COMMAND_ANY,
+   .help = list all built-in interfaces,
+   },
+   {
+   .name = jtag_khz,
+   .handler = handle_jtag_khz_command,
+   .mode = COMMAND_ANY,
+   .help = set maximum jtag speed (if supported),
+   .usage = khz:0=rtck,
+   },
+   {
+   .name = jtag_rclk,
+   .handler = handle_jtag_rclk_command,
+   .mode = COMMAND_ANY,
+   .help = set JTAG speed to RCLK or use fallback speed,
+   .usage = fallback_speed_khz,
+   },
+   {
+   .name = reset_config,
+   .handler = handle_reset_config_command,
+   .mode = COMMAND_ANY,
+   .help = configure JTAG reset behavior,
+   .usage = [none|trst_only|srst_only|trst_and_srst] 
+   [srst_pulls_trst|trst_pulls_srst|combined|separate] 
+   [srst_gates_jtag|srst_nogate] 
+   [trst_push_pull|trst_open_drain] 
+   [srst_push_pull|srst_open_drain],
+   },
+   {
+   .name = jtag_nsrst_delay,
+   .handler = handle_jtag_nsrst_delay_command,
+   .mode = COMMAND_ANY,
+   .help = delay after deasserting srst in ms,
+   .usage = ms,
+   },
+   {
+   .name = jtag_ntrst_delay,
+   .handler = handle_jtag_ntrst_delay_command,
+   .mode = COMMAND_ANY,
+   .help = delay after deasserting trst in ms,
+   .usage = ms
+   },
+   {
+   .name = jtag_nsrst_assert_width,
+   .handler = handle_jtag_nsrst_assert_width_command,
+   .mode = COMMAND_ANY,
+   .help = delay after asserting srst in ms,
+   .usage = ms
+   },
+   {
+   .name = jtag_ntrst_assert_width,
+   .handler = handle_jtag_ntrst_assert_width_command,
+   .mode = COMMAND_ANY,
+   .help = delay after asserting trst in ms,
+   .usage = ms
+   },
+   {
+   .name = scan_chain,
+   .handler = handle_scan_chain_command,
+   .mode = COMMAND_EXEC,
+   .help = print current scan chain configuration,
+   },
+   {
+   .name = jtag_reset,
+   .handler = handle_jtag_reset_command,
+   .mode = COMMAND_EXEC,
+   .help = toggle reset lines,
+   .usage = trst srst,
+   },
+   {
+   .name = runtest,
+   .handler = handle_runtest_command,
+   .mode = COMMAND_EXEC,
+   .help = move to Run-Test/Idle, and execute num_cycles,
+   .usage = num_cycles
+   },
+   {
+   .name = irscan,
+   .handler = handle_irscan_command,
+   .mode = COMMAND_EXEC,
+   .help = execute IR scan,
+   .usage = device instr [dev2] [instr2] ...,
+   },
+   {
+   .name = verify_ircapture,
+   .handler = handle_verify_ircapture_command,
+   .mode = COMMAND_ANY,
+   .help = verify value captured during Capture-IR,
+   .usage = enable | disable,
+   },
+   {
+   .name = verify_jtag,
+   .handler = handle_verify_jtag_command,
+   .mode = COMMAND_ANY,
+   .help = verify value capture,
+   .usage = enable | disable,
+   },
+   {
+   .name = tms_sequence,
+   .handler = handle_tms_sequence_command,
+   .mode = COMMAND_ANY,
+   .help = choose short(default) or long tms_sequence,
+   .usage = short | long,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int jtag_register_commands(struct command_context *cmd_ctx)
 {
register_jim(cmd_ctx, jtag, jim_jtag_command,
perform jtag tap actions);
 
-   

[Openocd-development] [PATCH 19/20] remove flash_driver-register_callbacks

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Replace flash_driver callback with pointer to command_registration.
Eliminates all related routines and allows drivers to omit commands.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/at91sam3.c  |7 +--
 src/flash/at91sam7.c  |7 +--
 src/flash/avrf.c  |7 +--
 src/flash/cfi.c   |6 --
 src/flash/ecos.c  |6 --
 src/flash/faux.c  |6 --
 src/flash/flash.c |   15 ++-
 src/flash/flash.h |8 +++-
 src/flash/lpc2000.c   |7 +--
 src/flash/lpc2900.c   |   11 +--
 src/flash/pic32mx.c   |7 +--
 src/flash/stellaris.c |8 +---
 src/flash/stm32x.c|6 +-
 src/flash/str7x.c |7 +--
 src/flash/str9x.c |7 +--
 src/flash/str9xpec.c  |8 +---
 src/flash/tms470.c|7 +--
 17 files changed, 25 insertions(+), 105 deletions(-)

diff --git a/src/flash/at91sam3.c b/src/flash/at91sam3.c
index 75e8495..be17a5f 100644
--- a/src/flash/at91sam3.c
+++ b/src/flash/at91sam3.c
@@ -2501,14 +2501,9 @@ static const struct command_registration 
at91sam3_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int sam3_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, at91sam3_command_handlers);
-}
-
 struct flash_driver at91sam3_flash = {
.name = at91sam3,
-   .register_commands = sam3_register_commands,
+   .commands = at91sam3_command_handlers,
.flash_bank_command = sam3_flash_bank_command,
.erase = sam3_erase,
.protect = sam3_protect,
diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c
index 0204660..f9b87ba 100644
--- a/src/flash/at91sam7.c
+++ b/src/flash/at91sam7.c
@@ -1198,14 +1198,9 @@ static const struct command_registration 
at91sam7_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int at91sam7_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, at91sam7_command_handlers);
-}
-
 struct flash_driver at91sam7_flash = {
.name = at91sam7,
-   .register_commands = at91sam7_register_commands,
+   .commands = at91sam7_command_handlers,
.flash_bank_command = at91sam7_flash_bank_command,
.erase = at91sam7_erase,
.protect = at91sam7_protect,
diff --git a/src/flash/avrf.c b/src/flash/avrf.c
index 9aea47d..1c48464 100644
--- a/src/flash/avrf.c
+++ b/src/flash/avrf.c
@@ -468,14 +468,9 @@ static const struct command_registration 
avrf_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int avrf_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, avrf_command_handlers);
-}
-
 struct flash_driver avr_flash = {
.name = avr,
-   .register_commands = avrf_register_commands,
+   .commands = avrf_command_handlers,
.flash_bank_command = avrf_flash_bank_command,
.erase = avrf_erase,
.protect = avrf_protect,
diff --git a/src/flash/cfi.c b/src/flash/cfi.c
index b92ecbd..6dbffb9 100644
--- a/src/flash/cfi.c
+++ b/src/flash/cfi.c
@@ -589,11 +589,6 @@ static int cfi_intel_info(struct flash_bank *bank, char 
*buf, int buf_size)
return ERROR_OK;
 }
 
-static int cfi_register_commands(struct command_context *cmd_ctx)
-{
-   return ERROR_OK;
-}
-
 /* flash_bank cfi base size chip_width bus_width target# [options]
  */
 FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command)
@@ -2623,7 +2618,6 @@ static int cfi_info(struct flash_bank *bank, char *buf, 
int buf_size)
 
 struct flash_driver cfi_flash = {
.name = cfi,
-   .register_commands = cfi_register_commands,
.flash_bank_command = cfi_flash_bank_command,
.erase = cfi_erase,
.protect = cfi_protect,
diff --git a/src/flash/ecos.c b/src/flash/ecos.c
index f6f3307..7a0b26f 100644
--- a/src/flash/ecos.c
+++ b/src/flash/ecos.c
@@ -336,11 +336,6 @@ static int ecosflash_probe(struct flash_bank *bank)
return ERROR_OK;
 }
 
-static int ecosflash_register_commands(struct command_context *cmd_ctx)
-{
-   return ERROR_OK;
-}
-
 #if 0
 static void command(struct flash_bank *bank, uint8_t cmd, uint8_t *cmd_buf)
 {
@@ -437,7 +432,6 @@ static int ecosflash_handle_gpnvm_command(struct 
command_context *cmd_ctx, char
 
 struct flash_driver ecosflash_flash = {
.name = ecosflash,
-   .register_commands = ecosflash_register_commands,
.flash_bank_command = ecosflash_flash_bank_command,
.erase = ecosflash_erase,
.protect = ecosflash_protect,
diff --git a/src/flash/faux.c b/src/flash/faux.c
index 558d7b0..adfc7bd 100644
--- a/src/flash/faux.c
+++ b/src/flash/faux.c
@@ 

[Openocd-development] [PATCH 01/22] arm11: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm11.c |   97 +---
 1 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/src/target/arm11.c b/src/target/arm11.c
index 66954fa..835234c 100644
--- a/src/target/arm11.c
+++ b/src/target/arm11.c
@@ -1565,44 +1565,71 @@ static int arm11_mcr(struct target *target, int cpnum,
return arm11_mrc_inner(target, cpnum, op1, op2, CRn, CRm, value, 
false);
 }
 
+static const struct command_registration arm11_mw_command_handlers[] = {
+   {
+   .name = burst,
+   .handler = arm11_handle_bool_memwrite_burst,
+   .mode = COMMAND_ANY,
+   .help = Enable/Disable non-standard but fast burst mode
+(default: enabled),
+   },
+   {
+   .name = error_fatal,
+   .handler = arm11_handle_bool_memwrite_error_fatal,
+   .mode = COMMAND_ANY,
+   .help = Terminate program if transfer error was found
+(default: enabled),
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration arm11_any_command_handlers[] = {
+   {
+   /* hardware_step is only here to check if the default
+* simulate + breakpoint implementation is broken.
+* TEMPORARY! NOT DOCUMENTED! */
+   .name = hardware_step,
+   .handler = arm11_handle_bool_hardware_step,
+   .mode = COMMAND_ANY,
+   .help = DEBUG ONLY - Hardware single stepping
+(default: disabled),
+   .usage = (enable|disable),
+   },
+   {
+   .name = memwrite,
+   .mode = COMMAND_ANY,
+   .help = memwrite command group,
+   .chain = arm11_mw_command_handlers,
+   },
+   {
+   .name = step_irq_enable,
+   .handler = arm11_handle_bool_step_irq_enable,
+   .mode = COMMAND_ANY,
+   .help = Enable interrupts while stepping
+(default: disabled),
+   },
+   {
+   .name = vcr,
+   .handler = arm11_handle_vcr,
+   .mode = COMMAND_ANY,
+   .help = Control (Interrupt) Vector Catch Register,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration arm11_command_handlers[] = {
+   {
+   .name = arm11,
+   .mode = COMMAND_ANY,
+   .help = ARM11 command group,
+   .chain = arm11_any_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int arm11_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *top_cmd, *mw_cmd;
-
armv4_5_register_commands(cmd_ctx);
-
-   top_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm11,
-   NULL, COMMAND_ANY, NULL);
-
-   /* hardware_step is only here to check if the default
-* simulate + breakpoint implementation is broken.
-* TEMPORARY! NOT DOCUMENTED!
-*/
-   COMMAND_REGISTER(cmd_ctx, top_cmd, hardware_step,
-   arm11_handle_bool_hardware_step, COMMAND_ANY,
-   DEBUG ONLY - Hardware single stepping
-(default: disabled));
-
-   mw_cmd = COMMAND_REGISTER(cmd_ctx, top_cmd, memwrite,
-   NULL, COMMAND_ANY, NULL);
-   COMMAND_REGISTER(cmd_ctx, mw_cmd, burst,
-   arm11_handle_bool_memwrite_burst, COMMAND_ANY,
-   Enable/Disable non-standard but fast burst mode
-(default: enabled));
-   COMMAND_REGISTER(cmd_ctx, mw_cmd, error_fatal,
-   arm11_handle_bool_memwrite_error_fatal, COMMAND_ANY,
-   Terminate program if transfer error was found
-(default: enabled));
-
-   COMMAND_REGISTER(cmd_ctx, top_cmd, step_irq_enable,
-   arm11_handle_bool_step_irq_enable, COMMAND_ANY,
-   Enable interrupts while stepping
-(default: disabled));
-   COMMAND_REGISTER(cmd_ctx, top_cmd, vcr,
-   arm11_handle_vcr, COMMAND_ANY,
-   Control (Interrupt) Vector Catch Register);
-
-   return etm_register_commands(cmd_ctx);
+   etm_register_commands(cmd_ctx);
+   return register_commands(cmd_ctx, NULL, arm11_command_handlers);
 }
 
 /** Holds methods for ARM11xx targets. */
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 02/22] arm720t: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm720t.c |   38 +++---
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/target/arm720t.c b/src/target/arm720t.c
index 4ca80e1..52a311c 100644
--- a/src/target/arm720t.c
+++ b/src/target/arm720t.c
@@ -491,23 +491,31 @@ static int arm720t_mcr(struct target *target, int cpnum, 
uint32_t op1, uint32_t
return arm720t_write_cp15(target, mrc_opcode(cpnum, op1, op2, CRn, 
CRm), value);
 }
 
-static int arm720t_register_commands(struct command_context *cmd_ctx)
-{
-   int retval;
-   struct command *arm720t_cmd;
-
-
-   retval = arm7_9_register_commands(cmd_ctx);
-
-   arm720t_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm720t,
-   NULL, COMMAND_ANY,
-   arm720t specific commands);
+static const struct command_registration arm720t_exec_command_handlers[] = {
+   {
+   .name = cp15,
+   .handler = arm720t_handle_cp15_command,
+   .mode = COMMAND_EXEC,
+   .usage = opcode [value],
+   .help = display/modify cp15 register,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
-   COMMAND_REGISTER(cmd_ctx, arm720t_cmd, cp15,
-   arm720t_handle_cp15_command, COMMAND_EXEC,
-   display/modify cp15 register opcode [value]);
+static const struct command_registration arm720t_command_handlers[] = {
+   {
+   .name = arm720t,
+   .mode = COMMAND_ANY,
+   .help = arm720t command group,
+   .chain = arm720t_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
 
-   return ERROR_OK;
+static int arm720t_register_commands(struct command_context *cmd_ctx)
+{
+   arm7_9_register_commands(cmd_ctx);
+   return register_commands(cmd_ctx, NULL, arm720t_command_handlers);
 }
 
 /** Holds methods for ARM720 targets. */
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 03/22] arm7_9_common: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm7_9_common.c |   57 ---
 1 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c
index 1601ee1..b40be8d 100644
--- a/src/target/arm7_9_common.c
+++ b/src/target/arm7_9_common.c
@@ -2847,28 +2847,45 @@ int arm7_9_init_arch_info(struct target *target, struct 
arm7_9_common *arm7_9)
1, 1, target);
 }
 
+static const struct command_registration arm7_9_any_command_handlers[] = {
+   {
+   dbgrq,
+   .handler = handle_arm7_9_dbgrq_command,
+   .mode = COMMAND_ANY,
+   .usage = enable|disable,
+   .help = use EmbeddedICE dbgrq instead of breakpoint 
+   for target halt requests,
+   },
+   {
+   fast_memory_access,
+   .handler = handle_arm7_9_fast_memory_access_command,
+   .mode = COMMAND_ANY,
+   .usage = enable|disable,
+   .help = use fast memory accesses instead of slower 
+   but potentially safer accesses,
+   },
+   {
+   dcc_downloads,
+   .handler = handle_arm7_9_dcc_downloads_command,
+   .mode = COMMAND_ANY,
+   .usage = enable | disable,
+   .help = use DCC downloads for larger memory writes,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration arm7_9_command_handlers[] = {
+   {
+   .name = arm7_9,
+   .mode = COMMAND_ANY,
+   .help = arm7/9 specific commands,
+   .chain = arm7_9_any_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int arm7_9_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *arm7_9_cmd;
-
-   arm7_9_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm7_9,
-   NULL, COMMAND_ANY, arm7/9 specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, arm7_9_cmd, dbgrq,
-   handle_arm7_9_dbgrq_command, COMMAND_ANY,
-   use EmbeddedICE dbgrq instead of breakpoint 
-   for target halt requests enable | disable);
-   COMMAND_REGISTER(cmd_ctx, arm7_9_cmd, fast_memory_access,
-   handle_arm7_9_fast_memory_access_command, COMMAND_ANY,
-   use fast memory accesses instead of slower 
-   but potentially safer accesses enable | disable);
-   COMMAND_REGISTER(cmd_ctx, arm7_9_cmd, dcc_downloads,
-   handle_arm7_9_dcc_downloads_command, COMMAND_ANY,
-   use DCC downloads for larger memory writes enable | 
disable);
-
armv4_5_register_commands(cmd_ctx);
-
etm_register_commands(cmd_ctx);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, arm7_9_command_handlers);
 }
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 05/22] arm926ejs: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm926ejs.c |   36 ++--
 1 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c
index 030405a..329aa12 100644
--- a/src/target/arm926ejs.c
+++ b/src/target/arm926ejs.c
@@ -756,23 +756,31 @@ static int arm926ejs_mmu(struct target *target, int 
*enabled)
return ERROR_OK;
 }
 
+static const struct command_registration arm926ejs_exec_command_handlers[] = {
+   {
+   .name = cache_info,
+   .handler = arm926ejs_handle_cache_info_command,
+   .mode = COMMAND_EXEC,
+   .help = display information about target caches,
+
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration arm926ejs_command_handlers[] = {
+   {
+   .name = arm926ejs,
+   .mode = COMMAND_ANY,
+   .help = arm926ejs command group,
+   .chain = arm926ejs_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 /** Registers commands to access coprocessor, cache, and debug resources.  */
 int arm926ejs_register_commands(struct command_context *cmd_ctx)
 {
-   int retval;
-   struct command *arm926ejs_cmd;
-
-   retval = arm9tdmi_register_commands(cmd_ctx);
-
-   arm926ejs_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm926ejs,
-   NULL, COMMAND_ANY,
-   arm926ejs specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, arm926ejs_cmd, cache_info,
-   arm926ejs_handle_cache_info_command, COMMAND_EXEC,
-   display information about target caches);
-
-   return retval;
+   arm9tdmi_register_commands(cmd_ctx);
+   return register_commands(cmd_ctx, NULL, arm926ejs_command_handlers);
 }
 
 /** Holds methods for ARM926 targets. */
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 06/22] arm966e: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm966e.c |   35 +++
 1 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/target/arm966e.c b/src/target/arm966e.c
index f617875..70cc3c4 100644
--- a/src/target/arm966e.c
+++ b/src/target/arm966e.c
@@ -221,21 +221,32 @@ COMMAND_HANDLER(arm966e_handle_cp15_command)
return ERROR_OK;
 }
 
+static const struct command_registration arm966e_exec_command_handlers[] = {
+   {
+   .name = cp15,
+   .handler = arm966e_handle_cp15_command,
+   .mode = COMMAND_EXEC,
+   .usage = opcode [value],
+   .help = display/modify cp15 register,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
+static const struct command_registration arm966e_command_handlers[] = {
+   {
+   .name = arm966e,
+   .mode = COMMAND_ANY,
+   .help = arm966e command group,
+   .chain = arm966e_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 /** Registers commands used to access coprocessor resources. */
 int arm966e_register_commands(struct command_context *cmd_ctx)
 {
-   int retval;
-   struct command *arm966e_cmd;
-
-   retval = arm9tdmi_register_commands(cmd_ctx);
-   arm966e_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm966e,
-   NULL, COMMAND_ANY,
-   arm966e specific commands);
-   COMMAND_REGISTER(cmd_ctx, arm966e_cmd, cp15,
-   arm966e_handle_cp15_command, COMMAND_EXEC,
-   display/modify cp15 register num [value]);
-
-   return retval;
+   arm9tdmi_register_commands(cmd_ctx);
+   return register_commands(cmd_ctx, NULL, arm966e_command_handlers);
 }
 
 /** Holds methods for ARM966 targets. */
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 07/22] arm9tdmi: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/target/arm9tdmi.c |   33 +
 1 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c
index f965429..87ace05 100644
--- a/src/target/arm9tdmi.c
+++ b/src/target/arm9tdmi.c
@@ -908,20 +908,29 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command)
return ERROR_OK;
 }
 
+static const struct command_registration arm9tdmi_exec_command_handlers[] = {
+   {
+   .name = vector_catch,
+   .handler = handle_arm9tdmi_catch_vectors_command,
+   .mode = COMMAND_EXEC,
+   .usage = [all|none|reset|undef|swi|pabt|dabt|irq|fiq] ...,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration arm9tdmi_command_handlers[] = {
+   {
+   .name = arm9tdmi,
+   .mode = COMMAND_ANY,
+   .help = arm9tdmi command group,
+   .chain = arm9tdmi_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 int arm9tdmi_register_commands(struct command_context *cmd_ctx)
 {
-   int retval;
-   struct command *arm9tdmi_cmd;
-
-   retval = arm7_9_register_commands(cmd_ctx);
-   arm9tdmi_cmd = COMMAND_REGISTER(cmd_ctx, NULL, arm9,
-   NULL, COMMAND_ANY,
-   arm9 specific commands);
-   COMMAND_REGISTER(cmd_ctx, arm9tdmi_cmd, vector_catch,
-   handle_arm9tdmi_catch_vectors_command, COMMAND_EXEC,
-   arm9 vector_catch 
[all|none|reset|undef|swi|pabt|dabt|irq|fiq] ...);
-
-   return retval;
+   arm7_9_register_commands(cmd_ctx);
+   return register_commands(cmd_ctx, NULL, arm9tdmi_command_handlers);
 }
 
 /** Holds methods for ARM9TDMI targets. */
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 10/10] support OPENOCD_DEBUG_LEVEL environment setting

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Detect the OPENOCD_DEBUG_LEVEL setting in log_init(), allowing the
very early startup phases to be debugged.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/log.c |   13 +
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/helper/log.c b/src/helper/log.c
index 27fa831..3067ecc 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -346,6 +346,19 @@ void log_init(void)
if (debug_level == -1)
debug_level = LOG_LVL_INFO;
 
+   char *debug_env = getenv(OPENOCD_DEBUG_LEVEL);
+   if (NULL != debug_env)
+   {
+   int value;
+   int retval = parse_int(debug_env, value);
+   if (ERROR_OK == retval 
+   debug_level = LOG_LVL_SILENT 
+   debug_level = LOG_LVL_DEBUG)
+   {
+   debug_level = value;
+   }
+   }
+
if (log_output == NULL)
log_output = stderr;
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 09/10] log: improve initialization

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Removes redundant assignment of start_ms from log_register_commands().
Eliminates command_context parameter and return value.
Adds Doxygen comment block for this API call.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/helper/log.c |   11 +++
 src/helper/log.h |5 -
 src/openocd.c|9 -
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/src/helper/log.c b/src/helper/log.c
index 3799fb3..27fa831 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -336,25 +336,20 @@ static struct command_registration log_command_handlers[] 
= {
 
 int log_register_commands(struct command_context *cmd_ctx)
 {
-   start = timeval_ms();
-
return register_commands(cmd_ctx, NULL, log_command_handlers);
 }
 
-int log_init(struct command_context *cmd_ctx)
+void log_init(void)
 {
-   /* set defaults for daemon configuration, if not set by cmdline or 
cfgfile */
+   /* set defaults for daemon configuration,
+* if not set by cmdline or cfgfile */
if (debug_level == -1)
debug_level = LOG_LVL_INFO;
 
if (log_output == NULL)
-   {
log_output = stderr;
-   }
 
start = last_time = timeval_ms();
-
-   return ERROR_OK;
 }
 
 int set_log_output(struct command_context *cmd_ctx, FILE *output)
diff --git a/src/helper/log.h b/src/helper/log.h
index 6f7c24a..f2d19d1 100644
--- a/src/helper/log.h
+++ b/src/helper/log.h
@@ -66,7 +66,10 @@ void log_printf_lf(enum log_levels level, const char *file, 
unsigned line,
const char *function, const char *format, ...)
 __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6)));
 
-int log_init(struct command_context *cmd_ctx);
+/**
+ * Initialize logging module.  Call during program startup.
+ */
+void log_init(void);
 int set_log_output(struct command_context *cmd_ctx, FILE *output);
 
 int log_register_commands(struct command_context *cmd_ctx);
diff --git a/src/openocd.c b/src/openocd.c
index 1f29acd..629d50a 100644
--- a/src/openocd.c
+++ b/src/openocd.c
@@ -182,6 +182,9 @@ struct command_context *global_cmd_ctx;
 /* NB! this fn can be invoked outside this file for non PC hosted builds */
 struct command_context *setup_command_handler(void)
 {
+   log_init();
+   LOG_DEBUG(log_init: complete);
+
struct command_context *cmd_ctx;
 
global_cmd_ctx = cmd_ctx = command_init(openocd_startup_tcl);
@@ -202,11 +205,7 @@ struct command_context *setup_command_handler(void)
pld_register_commands(cmd_ctx);
mflash_register_commands(cmd_ctx);
 
-   if (log_init(cmd_ctx) != ERROR_OK)
-   {
-   exit(-1);
-   }
-   LOG_DEBUG(log init complete);
+   LOG_DEBUG(command registration: complete);
 
LOG_OUTPUT(OPENOCD_VERSION \n);
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 02/20] at91sam7: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/at91sam7.c |   30 +-
 1 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/flash/at91sam7.c b/src/flash/at91sam7.c
index 1665b91..0204660 100644
--- a/src/flash/at91sam7.c
+++ b/src/flash/at91sam7.c
@@ -1178,17 +1178,29 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command)
return ERROR_OK;
 }
 
+static const struct command_registration at91sam7_exec_command_handlers[] = {
+   {
+   .name = gpnvm,
+   .handler = at91sam7_handle_gpnvm_command,
+   .mode = COMMAND_EXEC,
+   .usage = gpnvm bit set | clear, 
+   set or clear one gpnvm bit,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration at91sam7_command_handlers[] = {
+   {
+   .name = at91sam7,
+   .mode = COMMAND_ANY,
+   .help = at91sam7 flash command group,
+   .chain = at91sam7_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int at91sam7_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *at91sam7_cmd = COMMAND_REGISTER(cmd_ctx, NULL, 
at91sam7,
-   NULL, COMMAND_ANY, NULL);
-
-   COMMAND_REGISTER(cmd_ctx, at91sam7_cmd, gpnvm,
-   at91sam7_handle_gpnvm_command, COMMAND_EXEC,
-   at91sam7 gpnvm bit set | clear, 
-   set or clear one gpnvm bit);
-
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, at91sam7_command_handlers);
 }
 
 struct flash_driver at91sam7_flash = {
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 11/11] remove register_callbacks from jtag interface

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net

Changes the jtag_interface-register_callbacks field to a list of
commands to be registered.  Changes callback to invocation of
register_commands() with that command registration list.  Removes all
JTAG interface driver register_command callback functions, which the
previous commits had converted into identical calls.

Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/jtag/amt_jtagaccel.c |7 +--
 src/jtag/arm-jtag-ew.c   |   10 --
 src/jtag/dummy.c |6 --
 src/jtag/ft2232.c|8 +---
 src/jtag/gw16012.c   |7 +--
 src/jtag/interface.h |4 +---
 src/jtag/jlink.c |   10 --
 src/jtag/parport.c   |   26 --
 src/jtag/presto.c|   10 --
 src/jtag/rlink/rlink.c   |   44 
 src/jtag/tcl.c   |5 +++--
 src/jtag/vsllink.c   |8 ++--
 12 files changed, 33 insertions(+), 112 deletions(-)

diff --git a/src/jtag/amt_jtagaccel.c b/src/jtag/amt_jtagaccel.c
index c3f3279..d26482a 100644
--- a/src/jtag/amt_jtagaccel.c
+++ b/src/jtag/amt_jtagaccel.c
@@ -558,14 +558,9 @@ static const struct command_registration 
amtjtagaccel_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int amt_jtagaccel_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, amtjtagaccel_command_handlers);
-}
-
 struct jtag_interface amt_jtagaccel_interface = {
.name = amt_jtagaccel,
-   .register_commands = amt_jtagaccel_register_commands,
+   .commands = amtjtagaccel_command_handlers,
.init = amt_jtagaccel_init,
.quit = amt_jtagaccel_quit,
.speed = amt_jtagaccel_speed,
diff --git a/src/jtag/arm-jtag-ew.c b/src/jtag/arm-jtag-ew.c
index ef2b04f..46c3107 100644
--- a/src/jtag/arm-jtag-ew.c
+++ b/src/jtag/arm-jtag-ew.c
@@ -512,17 +512,15 @@ static const struct command_registration 
armjtagew_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int armjtagew_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, armjtagew_command_handlers);
-}
-
 struct jtag_interface armjtagew_interface = {
.name = arm-jtag-ew,
+
+   .commands = armjtagew_command_handlers,
+
.execute_queue = armjtagew_execute_queue,
.speed = armjtagew_speed,
.khz = armjtagew_khz,
-   .register_commands = armjtagew_register_commands,
+
.init = armjtagew_init,
.quit = armjtagew_quit,
};
diff --git a/src/jtag/dummy.c b/src/jtag/dummy.c
index 0516790..11b6f71 100644
--- a/src/jtag/dummy.c
+++ b/src/jtag/dummy.c
@@ -134,11 +134,6 @@ static int dummy_speed(int speed)
return ERROR_OK;
 }
 
-static int dummy_register_commands(struct command_context *cmd_ctx)
-{
-   return ERROR_OK;
-}
-
 static int dummy_init(void)
 {
bitbang_interface = dummy_bitbang;
@@ -160,7 +155,6 @@ struct jtag_interface dummy_interface = {
.execute_queue = bitbang_execute_queue,
 
.speed = dummy_speed,
-   .register_commands = dummy_register_commands,
.khz = dummy_khz,
.speed_div = dummy_speed_div,
 
diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c
index d145505..73cbaf3 100644
--- a/src/jtag/ft2232.c
+++ b/src/jtag/ft2232.c
@@ -4009,15 +4009,9 @@ static const struct command_registration 
ft2232_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int ft2232_register_commands(struct command_context* cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, ft2232_command_handlers);
-}
-
-
 struct jtag_interface ft2232_interface = {
.name = ft2232,
-   .register_commands = ft2232_register_commands,
+   .commands = ft2232_command_handlers,
.init = ft2232_init,
.quit = ft2232_quit,
.speed = ft2232_speed,
diff --git a/src/jtag/gw16012.c b/src/jtag/gw16012.c
index 0e495f9..b827fd5 100644
--- a/src/jtag/gw16012.c
+++ b/src/jtag/gw16012.c
@@ -573,14 +573,9 @@ static const struct command_registration 
gw16012_command_handlers[] = {
COMMAND_REGISTRATION_DONE
 };
 
-static int gw16012_register_commands(struct command_context *cmd_ctx)
-{
-   return register_commands(cmd_ctx, NULL, gw16012_command_handlers);
-}
-
 struct jtag_interface gw16012_interface = {
.name = gw16012,
-   .register_commands = gw16012_register_commands,
+   .commands = gw16012_command_handlers,
.init = gw16012_init,
.quit = gw16012_quit,
.speed = gw16012_speed,
diff --git a/src/jtag/interface.h b/src/jtag/interface.h
index 05e4048..d55782a 100644
--- a/src/jtag/interface.h
+++ 

[Openocd-development] [PATCH 13/20] stellaris: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/stellaris.c |   27 ---
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/flash/stellaris.c b/src/flash/stellaris.c
index 2d653ec..1cff486 100644
--- a/src/flash/stellaris.c
+++ b/src/flash/stellaris.c
@@ -1161,15 +1161,28 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command)
return ERROR_OK;
 }
 
+static const struct command_registration stellaris_exec_command_handlers[] = {
+   {
+   .name = mass_erase,
+   .handler = stellaris_handle_mass_erase_command,
+   .mode = COMMAND_EXEC,
+   .help = erase entire device,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration stellaris_command_handlers[] = {
+   {
+   .name = stellaris,
+   .mode = COMMAND_ANY,
+   .help = Stellaris flash command group,
+   .chain = stellaris_exec_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int stellaris_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, 
stellaris,
-   NULL, COMMAND_ANY, stellaris flash specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, stm32x_cmd, mass_erase,
-   stellaris_handle_mass_erase_command, COMMAND_EXEC,
-   mass erase device);
-   return ERROR_OK;
+   return register_commands(cmd_ctx, NULL, stellaris_command_handlers);
 }
 
 
-- 
1.6.4.4

___
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development


[Openocd-development] [PATCH 17/20] str9xpec: use register_commands()

2009-11-24 Thread zw
From: Zachary T Welch z...@superlucidity.net


Signed-off-by: Zachary T Welch z...@superlucidity.net
---
 src/flash/str9xpec.c |  119 ++
 1 files changed, 81 insertions(+), 38 deletions(-)

diff --git a/src/flash/str9xpec.c b/src/flash/str9xpec.c
index 7519413..7f6a29a 100644
--- a/src/flash/str9xpec.c
+++ b/src/flash/str9xpec.c
@@ -1163,48 +1163,91 @@ 
COMMAND_HANDLER(str9xpec_handle_flash_disable_turbo_command)
return ERROR_OK;
 }
 
+static const struct command_registration str9xpec_config_command_handlers[] = {
+   {
+   .name = enable_turbo,
+   .handler = str9xpec_handle_flash_enable_turbo_command,
+   .mode = COMMAND_EXEC,
+   .help = enable str9xpec turbo mode,
+   },
+   {
+   .name = disable_turbo,
+   .handler = str9xpec_handle_flash_disable_turbo_command,
+   .mode = COMMAND_EXEC,
+   .help = disable str9xpec turbo mode,
+   },
+   {
+   .name = options_cmap,
+   .handler = str9xpec_handle_flash_options_cmap_command,
+   .mode = COMMAND_EXEC,
+   .help = configure str9xpec boot sector,
+   },
+   {
+   .name = options_lvdthd,
+   .handler = str9xpec_handle_flash_options_lvdthd_command,
+   .mode = COMMAND_EXEC,
+   .help = configure str9xpec lvd threshold,
+   },
+   {
+   .name = options_lvdsel,
+   .handler = str9xpec_handle_flash_options_lvdsel_command,
+   .mode = COMMAND_EXEC,
+   .help = configure str9xpec lvd selection,
+   },
+   {
+   .name = options_lvdwarn,
+   .handler = str9xpec_handle_flash_options_lvdwarn_command,
+   .mode = COMMAND_EXEC,
+   .help = configure str9xpec lvd warning,
+   },
+   {
+   .name = options_read,
+   .handler = str9xpec_handle_flash_options_read_command,
+   .mode = COMMAND_EXEC,
+   .help = read str9xpec options,
+   },
+   {
+   .name = options_write,
+   .handler = str9xpec_handle_flash_options_write_command,
+   .mode = COMMAND_EXEC,
+   .help = write str9xpec options,
+   },
+   {
+   .name = lock,
+   .handler = str9xpec_handle_flash_lock_command,
+   .mode = COMMAND_EXEC,
+   .help = lock str9xpec device,
+   },
+   {
+   .name = unlock,
+   .handler = str9xpec_handle_flash_unlock_command,
+   .mode = COMMAND_EXEC,
+   .help = unlock str9xpec device,
+   },
+   {
+   .name = part_id,
+   .handler = str9xpec_handle_part_id_command,
+   .mode = COMMAND_EXEC,
+   .help = print part id of str9xpec flash bank num,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+static const struct command_registration str9xpec_command_handlers[] = {
+   {
+   .name = str9xpec,
+   .mode = COMMAND_ANY,
+   .help = str9xpec flash command group,
+   .chain = str9xpec_config_command_handlers,
+   },
+   COMMAND_REGISTRATION_DONE
+};
+
 static int str9xpec_register_commands(struct command_context *cmd_ctx)
 {
-   struct command *str9xpec_cmd = COMMAND_REGISTER(cmd_ctx, NULL, 
str9xpec,
-   NULL, COMMAND_ANY, str9xpec flash specific commands);
-
-   COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, enable_turbo,
-   str9xpec_handle_flash_enable_turbo_command,
-   COMMAND_EXEC, enable str9xpec turbo mode);
-   COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, disable_turbo,
-   str9xpec_handle_flash_disable_turbo_command,
-   COMMAND_EXEC, disable str9xpec turbo mode);
-   COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, options_cmap,
-   str9xpec_handle_flash_options_cmap_command,
-   COMMAND_EXEC, configure str9xpec boot sector);
-   COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, options_lvdthd,
-   str9xpec_handle_flash_options_lvdthd_command,
-   COMMAND_EXEC, configure str9xpec lvd threshold);
-   COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, options_lvdsel,
-   str9xpec_handle_flash_options_lvdsel_command,
-   COMMAND_EXEC, configure str9xpec lvd selection);
-   COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, options_lvdwarn,
-   str9xpec_handle_flash_options_lvdwarn_command,
-   COMMAND_EXEC, configure str9xpec lvd warning);
-   COMMAND_REGISTER(cmd_ctx, str9xpec_cmd, options_read,
-   str9xpec_handle_flash_options_read_command,
-   COMMAND_EXEC, read str9xpec options);
-   

  1   2   >