Installing OpenOCD from sources
Most GNU/Linux distributions offer the possibility to install OpenOCD directly using their packages management system, however these package may refer to not so updated releases of the software and this means that some CPUs may not be supported at all! That’s way could be very useful to know how to install OpenOCD from sources in order to get its latest release!
Downloading the code
First of all we need to download the official GIT source or a related mirror (I’m going to use the Spen’s Official OpenOCD Mirror):
git clone https://github.com/ntfreak/openocd.git
The needed extra packages
Once the sources have been downloaded we need some extra packages in order to get them compiled. On my Ubuntu Xenial I used the following command to install such software:
$ sudo apt-get install libtool automake libhidapi-dev
Compiling OpenOCD
Now we are ready! Just enter into the openocd
directory and executing the bootstrap
script as follow:
$ cd openocd $ ./bootstrap
After that we can start configuring the sources by using the usual configure
script which is able to auto detect our hardware. However we can force any special feature we want by simply adding one or more option arguments as shown below:
$ ./configure --enable-cmsis-dap
In the command above I force the CMSIS-DAP compliant debugger support which I need to program my SAME70 based board.
When configure
script has finished its job we can start the OpenOCD compilation and installation with the usual UNIX commands:
$ make -j8 $ sudo make install
Please, note that I used the -j8
option argument in order to have 8 compilation threads and the sudo
command to be able to install the software into the system without permissions erros.
Testing the code
Once the compilation is finished we can test our new OpenOCD as follow (remeber that for this test I used my SAME70 based board). On a terminal we have to execute OpenOCD specifying the board’s script we wish to manage:
$ sudo openocd -f /usr/local/share/openocd/scripts/board/atmel_same70_xplained.cfg
Note that the sudo
command may be mandatory in case you need to use an USB connection!
Note also that the path /usr/local/share/openocd/scripts/board/atmel_same70_xplained.cfg
may vary in case you decide to install OpenOCD into a custom directory.
If everything works well you should see something like the following:
$ sudo openocd -f /usr/local/share/openocd/scripts/board/atmel_same70_xplained.cfg Open On-Chip Debugger 0.10.0+dev-00512-gfd04460 (2018-08-09-18:25) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'. adapter speed: 1800 kHz cortex_m reset_config sysresetreq Info : flash bank command srst_only separate srst_gates_jtag srst_open_drain connect_deassert_srst Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections Info : CMSIS-DAP: SWD Supported Info : CMSIS-DAP: FW Version = 02.09.0169 Info : CMSIS-DAP: Serial# = ATML2637010000000000 Info : CMSIS-DAP: Interface Initialised (SWD) Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1 Info : CMSIS-DAP: Interface ready Info : clock speed 1800 kHz Info : SWD DPIDR 0x0bd11477 Warn : Silicon bug: single stepping will enter pending exception handler! Info : atsame70q21.cpu: hardware has 8 breakpoints, 4 watchpoints Info : Listening on port 3333 for gdb connections
Now we can use different connections types to control OpenOCD. I use the telnet
connection as below:
$ telnet localhost 4444 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger >
Then I can easily reprogram the CPU’s internal flash with the following commands:
> halt > flash write_image erase unlock /tmp/nuttx.hex 0 ihex auto erase enabled auto unlock enabled device id = 0xa1020e00 erasing lock regions 0-8... erasing lock region 0 erasing lock region 1 erasing lock region 2 erasing lock region 3 erasing lock region 4 erasing lock region 5 erasing lock region 6 erasing lock region 7 erasing lock region 8 wrote 147456 bytes from file /tmp/nuttx.hex in 3.278660s (43.920 KiB/s) > reset >
Note that file /tmp/nuttx.hex
is the new image I wish to program into my CPU.