Skip to content

Commit

Permalink
[openocd] add helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting committed Feb 2, 2025
1 parent 7e3583e commit a599dac
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
15 changes: 15 additions & 0 deletions sw/openocd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## NEORV32 OpenOCD Scripts

* `openocd_neorv32.cfg` For the default **single-core** processor configuration
* `openocd_neorv32.dual_core.cfg` For the **SMP dual-core** processor configuration

### Helper Scripts

The _helper scripts_ are called by the main OpenOCD configuration files.
Hence, these scripts are not meant for stand-alone operation.

* `authentication.cfg` Authenticate debug access via the RISC-V DM authentication commands.
Modify this file (but not the helper procedures) if you are using a
**custom/non-default authenticator** processor hardware module.
* `interface.cfg` Physical adapter configuration. Adjust this file to match your specific adapter board.
* `target.cfg` CPU core(s) and GDB configuration. This file should not be altered.
37 changes: 37 additions & 0 deletions sw/openocd/authentication.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -------------------------------------------------------------------
# Authenticator helper functions. Do not edit.
# -------------------------------------------------------------------

# write 32-bit data word to authenticator data input
proc authenticator_write {WDATA} {
riscv authdata_write $WDATA
}

# read 32-bit data word from authenticator data output
proc authenticator_read {} {
return [riscv authdata_read]
}

# check if authentication was successful (bit 7 in dmstatus)
proc authenticator_check {} {
set DMSTATUS [riscv dmi_read 0x11]
if { [expr {$DMSTATUS & (1<<7)}] } {
echo "Authentication passed."
} else {
echo "AUTHENTICATION FAILED!"
exit
}
}

# ---------------------------------------------------------
# Authentication process.
# Adjust this for your custom/non-default authenticator.
# ---------------------------------------------------------
# read challenge
set CHALLENGE [authenticator_read]
# compute response (default authenticator module)
set RESPONSE [expr {$CHALLENGE | 1}]
# send response
authenticator_write $RESPONSE
# success?
authenticator_check
10 changes: 10 additions & 0 deletions sw/openocd/interface.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -------------------------------------------------------------------
# Physical interface configuration.
# Adjust this file for your specific debug adapter.
# -------------------------------------------------------------------
adapter driver ftdi
ftdi vid_pid 0x0403 0x6010
ftdi channel 0
ftdi layout_init 0x0038 0x003b
adapter speed 4000
transport select jtag
52 changes: 52 additions & 0 deletions sw/openocd/target.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -------------------------------------------------------------------
# Target configuration and (session) initialization
# Do not edits this file.
# -------------------------------------------------------------------
proc target_setup { {NUM_CORES 1} } {

# path of this file
set PATH [ file dirname [ file normalize [ info script ] ] ]

# configure physical interface
source [file join $PATH interface.cfg]

set CORENAME neorv32

# configures JTAG tap
jtag newtap $CORENAME cpu -irlen 5

# attach core(s)
if { $NUM_CORES == 1 } {
set TARGETNAME $CORENAME.cpu
target create $TARGETNAME riscv -chain-position $TARGETNAME
} elseif { $NUM_CORES == 2 } {
set TARGETNAME_0 $CORENAME.cpu0
set TARGETNAME_1 $CORENAME.cpu1
target create $TARGETNAME_0 riscv -chain-position $CORENAME.cpu -rtos hwthread
target create $TARGETNAME_1 riscv -chain-position $CORENAME.cpu -coreid 1
target smp $TARGETNAME_0 $TARGETNAME_1
} else {
echo "ERROR: Invalid NUM_CORE configuration!"
}

# GDB server configuration
gdb report_data_abort enable
gdb report_register_access_error enable

# expose additional / NEORV32-specific CSRs
riscv expose_csrs 2048=cfureg0
riscv expose_csrs 2049=cfureg1
riscv expose_csrs 2050=cfureg2
riscv expose_csrs 2051=cfureg3
riscv expose_csrs 4032=mxisa

# initialize target
init

# authenticate
source [file join $PATH authentication.cfg]

# halt
halt
echo "Target HALTED. Ready for remote connections."
}

0 comments on commit a599dac

Please sign in to comment.