1

I am using openocd to debug / flash a Raspberry Pi Pico over a picoprobe.

If I just start up openocd as a server, then connect to it with a telnet client, then I usually get some informative feedback from the commands in my telnet session. Example: in one terminal, I start openocd like this:

$ /path/to/openocd.exe -s /path/to/openocd/tcl -f interface/picoprobe.cfg -f target/rp2040.cfg
Open On-Chip Debugger 0.11.0-g610f137 (2022-03-29-13:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 5000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x10000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
...
Info : accepting 'telnet' connection on tcp/4444

... then in another terminal, I can have a telnet session like this:

$ telnet 127.0.0.1 4444
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Open On-Chip Debugger
> reset init
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
> flash banks
#0 : rp2040.flash (rp2040_flash) at 0x10000000, size 0x00200000, buswidth 32, chipwidth 1

> flash list
{name rp2040_flash base 268435456 size 2097152 bus_width 32 chip_width 1}

Notice how I got a response to, say, the flash banks command, the response being "#0 : rp2040.flash (rp2040_flash) at 0x10000000, size 0x00200000, buswidth 32, chipwidth 1".

Now, I want to do the same thing, from the command line, using the -c ("run ") argument of openocd. It turns out, openocd being primarily a server, the command line usage is not exactly the same as over telnet; note for instance Thread: Re: [Openocd-development] Command line programming | OpenOCD - Open On-Chip Debugger:

You need to add another command before any non-configuration command - "init". It works through telnet, because "init" is executed automatically after processing and executing ALL command line parameteres, so if you want to do something this way, add "-c "init"" before your file or add "init" command before commands like "reset halt".

Ok, so, let's say I just want to retrieve the response to flash banks command over the command line. So I try this:

$ /path/to/openocd.exe -s /path/to/openocd/tcl -f interface/picoprobe.cfg \
  -f target/rp2040.cfg -c "init; reset init; flash banks; exit"
Open On-Chip Debugger 0.11.0-g610f137 (2022-03-29-13:44)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 5000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x10000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00

So, in this case, openocd dumped a bunch of lines on the output (note, these lines are printed on stderr, not stdout) - but definitely not the expected response "#0 : rp2040.flash (rp2040_flash) at 0x10000000, size 0x00200000, buswidth 32, chipwidth 1".

So, is there any possibility, for me to issue openocd commands strictly on the command line, via the -c command line option - and obtain the expected command output in the same terminal (stdout or stderr doesn't matter - though it would be nice to be able to filter out all of those strings openocd usually writes, like "target halted due to debug-request", that are not relevant to me in this case)?

sdbbs
  • 4,270
  • 5
  • 32
  • 87
  • 1
    Don't know if it will work, but I noticed stange behaviour with openocd11 command line. Try to split your command argument like this: /path/to/openocd.exe -s /path/to/openocd/tcl -f interface/picoprobe.cfg \ -f target/rp2040.cfg -c "init" -c "reset init" -c "flash banks" -c "exit". It has worked for me in same situation (ocd didn't output "wrote 256321 bytes from file....) – ludelle Apr 13 '23 at 08:00

0 Answers0