-
Notifications
You must be signed in to change notification settings - Fork 5
OpenOCD for sc_riscv32
You will need to install several packages to compile and run OpenOCD. Open a terminal window and type:
sudo apt-get install pkg-config make libtool autoconf texinfo libusb-1.0-0-dev libusb-dev doxygen
Clone any available repository to working directory
export OPENOCD_SRC_DIR=your_OpenOCD_source_directory
git clone --branch syntacore --recursive -- \
https://github.com/syntacore/openocd.git \
${OPENOCD_SRC_DIR}
See http://elinux.org/Compiling_OpenOCD
cd ${OPENOCD_SRC_DIR}
./bootstrap
You can build openocd in ${OPENOCD_SRC_DIR}
export OPENOCD_BLD_DIR=${OPENOCD_SRC_DIR}
or create additional build directory
export OPENOCD_BLD_DIR=your_build_dir
mkdir -p ${OPENOCD_BLD_DIR}
cd ${OPENOCD_BLD_DIR}
${OPENOCD_SRC_DIR}/configure --enable-maintainer-mode --enable-ftdi --disable-werror --enable-target64
For other configuration options see
${OPENOCD_SRC_DIR}/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 ${OPENOCD_BLD_DIR}/jimtcl && ${OPENOCD_SRC_DIR}/jimtcl/configure && cd ..
touch ${OPENOCD_SRC_DIR}/src/openocd.c && time nice make -C ${OPENOCD_BLD_DIR} -j
Call of touch ${OPENOCD_SRC_DIR}/src/openocd.c
updates openocd
banner by git-based version and build timestamp:
$ ${OPENOCD_BLD_DIR}/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
If build is successful, you can run it from ${OPENOCD_BLD_DIR}/src
directory or install OpenOCD
and headers.
By default, make install
will install all the files in /usr/local/bin
, /usr/local/lib
etc.
You can specify an installation prefix other than /usr/local
using --prefix
argument of configure
, for instance --prefix=$HOME
.
sudo make install
To uninstall library and headers
sudo make uninstall
Run OpenOCD
as TCP server with selected configuration files (even without install).
Use sudo if policy for your USB device is not configured (edit /etc/udev/rules.d/olimex-arm-usb-ocd.rules).
For example ./tcl folder contains set of configuration files, using olimex-arm-usb-ocd-h interface for syntacore_riscv32_v2 (priv spec 1.10) target:
sudo ${OPENOCD_BLD_DIR}/src/openocd \
-s ${OPENOCD_SRC_DIR}/tcl \
-f interface/ftdi/olimex-arm-usb-ocd-h.cfg \
-f target/syntacore_riscv32_v2.cfg \
|& tee ocd.log
For "RISC-V External Debug Support Version 0.13-DRAFT" riscv
target:
sudo ${OPENOCD_BLD_DIR}/src/openocd \
-s ${OPENOCD_SRC_DIR}/tcl \
-f interface/ftdi/olimex-arm-usb-ocd-h.cfg \
-f target/syntacore_riscv.cfg \
|& tee ocd.log
After initialization OpenOCD waiting for command from the network.
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 scr.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
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