From: David Barrass Subject: Re: OpenOCD 0.11.0 config example To: ports@openbsd.org, sadeep@asciimx.com Date: Sun, 8 Sep 2024 11:46:34 +0100 On 08/09/24 02:30, Sadeep Madurange wrote: > On 2024-09-07 16:26:46, David Barrass wrote: >> On 07/09/24 12:14, Sadeep Madurange wrote: >>> I'm trying to flash a ATSAM3X8E chip using the OpenOCD package. >>> OpenOCD version we have appears to be a bit old. So my openocd.cfg >>> doesn't seem to work. >>> >>> Does anyone happen to have an example I could use? My current >>> openocd.cfg is, >>> >>> source [find interface/stlink.cfg] >>> transport select hla_swd >>> adapter speed 1800 >>> set CPUTAPID 0x2ba01477 >>> source [find target/at91sam3XXX.cfg] >>> >> Hi Sadeep, >> >> There are many pieces to getting a successful debug session, so which >> bit is broken? >> >> It is not very helpful to just say "doesn't seem to work" - a log of >> the session would be helpful. So I can't assist further without more >> information. >> >> You are using stlink - is this correct? stlinkv2 is the more recent >> version. >> >> Are you sure that you have selected the correct transport? Your config >> shows SWD - is this correct. (Very probably but JTAG is valid also.) >> >> Is the target at91sam3XXX actually present in the target directory? >> >> It is VERY unlikely that your problem is anything to do with the >> OpenOCD version. STLINKv2 has been supported for a long time as has >> the AT91SAM family. Does OpenOCD/OpenBSD actually detect the stlink >> device? >> >> More detail is absolutely essential in order to diagnose and resolve >> this issue. >> >> I can see at91sam3XXX in my 0.10 version of openocd and all the stlink >> devices so your problem is not the version, just the device driver or >> configuration. > > Apologies, I was checking with the OpenOCD list, and presumed the > package version to be the case. You are right that this has nothing to > do with the package version. > > When I run the following command with the config I posted, I get the > following error. > > # openocd -f openocd-due.cfg -c "program a.hex verify reset exit" > > Warn : Could not determine executable path, using configured BINDIR. > Info : The selected transport took over low-level target control. The > results might differ compared to plain JTAG/SWD > Info : clock speed 500 kHz > Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748 > Info : Target voltage: 3.197910 > Info : sam3.cpu: hardware has 6 breakpoints, 4 watchpoints > Info : starting gdb server for sam3.cpu on 3333 > Info : Listening on port 3333 for gdb connections > target halted due to debug-request, current mode: Thread > xPSR: 0x01000000 pc: 0x0010004c msp: 0x20001000 > ** Programming Started ** > flash > flash bank bank_id driver_name base_address size_bytes > chip_width_bytes > bus_width_bytes target [driver_options ...] > flash banks > flash init > flash list > gdb_flash_program ('enable'|'disable') > nand > program [address] [pre-verify] [verify] [reset] [exit] > Error: invalid subcommand "write_image erase a.elf" > ** Programming Failed ** > shutdown command invoked > embedded:startup.tcl:583: Error: > at file "embedded:startup.tcl", line 583 > > Then I changed the config to > > source [find interface/stlink.cfg] > transport select hla_swd > adapter speed 1800 > set CPUTAPID 0x2ba01477 > source [find target/at91sam3ax_8x.cfg] > > the error changes to > > Warn : Could not determine executable path, using configured BINDIR. > Info : The selected transport took over low-level target control. The > results might differ compared to plain JTAG/SWD > Info : clock speed 500 kHz > Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748 > Info : Target voltage: 3.197910 > Info : sam3.cpu: hardware has 6 breakpoints, 4 watchpoints > Info : starting gdb server for sam3.cpu on 3333 > Info : Listening on port 3333 for gdb connections > target halted due to debug-request, current mode: Thread > xPSR: 0x01000000 pc: 0x0010004c msp: 0x20001000 > ** Programming Started ** > Warn : no flash bank found for address 0x0000800c > Warn : no flash bank found for address 0x0000ad70 > ** Programming Finished ** > ** Verify Started ** > Error: checksum mismatch - attempting binary compare > ** Verify Failed ** > shutdown command invoked > > I checked with the OpenOCD list and they confirmed that OpenOCD supports > flashing my part, but that I may have to change the target file to align > the addresses and sizes correctly. > > So, the problem is with my config not the package version, which I will > work on. Apologies for the noise (if anyone has a config for this part, > do share anyway :). > Hi Sadeep, That's MUCH more helpful. When debugging, break things down into simple pieces - so the first thing I see in your logfile is the warning about BINDIR. I don't ever see this warning so this very firmly points to something in your environment. 1. $echo $BINDIR What message do you see? 2. Can OpenOCD find your adapter? openocd -f //scripts/interface/ If I do:- openocd -f /usr/local/share/openocd/scripts/interface/stlink-v1.cfg I see the sign-on message and a raft of error messages which I expect to see because I don't have an stlink connected because I usually use a Jlink or a flyswatter but at least this tells me that OpenOCD is trying to find it and it helpfully prints out a list of debug adapters that it does know about. Looking at your message, OpenOCD DOES find your debug adapter and can actually read the target voltage which at 3.179V looks reasonable. The SAM3 device is also found. Looking very good so far. I see that you are using gdb on 3333 which is fine but you then get a message about flash bank not found. So, wind back a bit and try to connect on port 4444 which should give you the raw OpenOCD view of the target. OpenOCD has a comprehensive set of commands that should allow you to to find the flash banks and program using the "write_image" command. Once you have a raw telnet connection on 4444 type the OpenOCD help command to see the list of supported commands. This reply is already too long for this list so if you don't get any further following my suggested course of action let us take this off-list because it is NOT relevant to OpenBSD. Regards, David