Skip to content

OpenOCD for sc_riscv32

Pavel S. Smirnov edited this page Sep 27, 2017 · 13 revisions

Prerequisites

Packages

You will need to install several packages to compile and run OpenOCD. Open a terminal window and type:

sudo apt-get install make libtool autoconf texinfo libusb-dev doxygen

OpenOCD

Clone OpenOCD

Clone any available repository to working directory

git clone -b syntacore_riscv32i --recursive https://github.com/syntacore/openocd.git

Build OpenOCD

See http://elinux.org/Compiling_OpenOCD

Invoke bootstrap script

./bootstrap

Configure build

./configure --enable-maintainer-mode --disable-werror --enable-ftdi

For other configuration options see

./configure --help

Also check configuration of jimtcl, especially list of --with-ext="". Most of extensions are disabled in commit 56d163c (jimtcl: update to 0.77, the current version, enable only specific modules). Try to re-configure by default:

cd jimtcl && ./configure && cd ..

Invoke the make

touch src/openocd.c && time nice make -j

Call of touch src/openocd.c updates openocd banner by git-based version and build timestamp:

$ src/openocd --version
Open On-Chip Debugger 0.10.0+dev-00920-g98813c7 (2017-08-22-18:02)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html

Install OpenOCD

If build is successful, you can install OpenOCD and headers

sudo make install

To deinstall library and headers

sudo make uninstall

OpenOCD run

Run OpenOCD as TCP server with selected configuration files (even without install).

Use sudo if policy for your USB device is not configured.

For example ./tcl folder contains set of configuration files, using olimex-arm-usb-ocd interface for syntacore_riscv32i 2 TAPs target:

sudo src/openocd -f tcl/interface/ftdi/olimex-arm-usb-ocd.cfg -f tcl/target/syntacore_riscv32i_2tap.cfg |& tee ocd.log

After initialization OpenOCD waiting for command from the network.

OpenOCD remote session

telnet

Run telnet application in other console:

telnet localhost 4444

Print help to show list of commands. For example:

# show targets (usually last configured target is current core)
targets

# set core #0 as current core (usually for multicore configuration all but #0 cores are in parking state)
targets sc_rv32i0.cpu

# halt core (debug mode state)
halt

# load some elf image to memory
load_image /home/tools32i/test/scr5-baremetal-example/build/scr-test.elf

# resume execution from elf start address
resume 0x200

# halt core (if you need to examine registers or memory)
halt

# shutdown openocd server
shutdown

gdb

Run riscv32 gdb:

$ riscv32-unknown-elf-gdb
GNU gdb (GDB) 7.11.50.20160212-git
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=riscv32-unknown-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

Connect gdb with openocd:

(gdb) target remote localhost:3333
Remote debugging using localhost:3333

Note: openocd target should be in halt state before target remote command. gdb try to read general purpose register by G (gdb serial protocol) instruction during connection. openocd return the error "Target is not halted" if target is in running state.

openocd terminates telnet connection if gdb connection established.

Following gdb debug session can use both gdb and openocd commands. Use monitor gdb command to send openocd command.

0xffff6af8 in ?? ()
(gdb) x/i $pc
   0xffff6af8:	andi	a5,a5,1
(gdb) monitor shutdown
shutdown command invoked
(gdb) q
A debugging session is active.

	Inferior 1 [Remote target] will be detached.

Quit anyway? (y or n) y
Detaching from program: , Remote target
Remote connection closed
Clone this wiki locally