I’ve been working on seeing if I can get OpenOCD to work with the Rev B (since OpenOCD should have J-link OB support since 0.10). I have made some progress, but have hit a roadblock that is stumping me.
First up, it seems OpenOCD can’t connect because the J-Link OB uses a new PID that libjaylink is not aware of–by patching libjaylink in openocd I can actually get the USB device to be opened
diff --git a/src/jtag/drivers/libjaylink/libjaylink/discovery_usb.c b/src/jtag/drivers/libjaylink/libjaylink/discovery_usb.c
index 48d532292..9d979013c 100644
--- a/src/jtag/drivers/libjaylink/libjaylink/discovery_usb.c
+++ b/src/jtag/drivers/libjaylink/libjaylink/discovery_usb.c
@@ -59,7 +59,8 @@ static const uint16_t pids[][2] = {
{0x1015, 0},
{0x1016, 0},
{0x1017, 0},
- {0x1018, 0}
+ {0x1018, 0},
+ {0x1051, 0},
};
Then, from there I’ve been working on getting an openocd.cfg that can work with the RevB. So far, I have this:
interface jlink
transport select jtag
adapter_khz 4000
set _CHIPNAME riscv
jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x20000913
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME.0 riscv -chain-position $_TARGETNAME
$_TARGETNAME.0 configure -work-area-phys 0x80000000 -work-area-size 10000 -work-area-backup 1
flash bank spi0 fespi 0x20000000 0 0 0 $_TARGETNAME.0 0x10014000
And with this, I can start openocd and connect to it from riscv-gdb after loading an example elf and connect with target extended-remote localhost:3333
and gdb will connect and print the current execution
0x200152ae in __metal_driver_sifive_uart0_getc (uart=0x2, c=0x80000fe4)
at freedom-e-sdk/freedom-metal/src/drivers/sifive_uart0.c:71
71 *c = ch & 0x0ff;
Whoo! This was fantastic! But, this is where I’m stuck. If I try to run the rest of the commands to turn off flash protect, halt the processor, then load the elf, things…do not work. There’s lots of errors that occur (small snippet)
(gdb) monitor reset halt
JTAG tap: riscv.cpu tap/device found: 0x20000913 (mfg: 0x489 (SiFive Inc), part: 0x0000, ver: 0x2)
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Sending data to device timed out.
transport_write() failed: timeout occurred.
jaylink_jtag_io() failed: timeout occurred.
dmi_scan failed jtag scan
Failed read (NOP) at 0x11; value=0x0, status=2
Last read operation left 68 bytes.
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Sending data to device timed out.
transport_write() failed: timeout occurred.
jaylink_jtag_io() failed: timeout occurred.
dmi_scan failed jtag scan
failed read at 0x11, status=2
(gdb) monitor flash protect 0 64 last off
Last read operation left 281 bytes.
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Sending data to device timed out.
transport_write() failed: timeout occurred.
jaylink_jtag_io() failed: timeout occurred.
dmi_scan failed jtag scan
failed read at 0x11, status=2
Last read operation left 281 bytes.
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Failed to send data to device: LIBUSB_ERROR_TIMEOUT.
Sending data to device timed out.
transport_write() failed: timeout occurred.
jaylink_jtag_io() failed: timeout occurred.
dmi_scan failed jtag scan
Failed read (NOP) at 0x11; value=0x0, status=2
ERROR: first sector must be <= last
The last line seemed to be from flash protect, and if I add the following to my openocd.cfg
init
halt
flash protect 0 64 last off
Then I don’t see any timeouts, but I do see the flash error
Open On-Chip Debugger 0.10.0+dev-00841-g1449af5bd (2020-03-03-20:03)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : J-Link OB-K22-SiFive compiled Feb 28 2019 12:46:23
Info : Hardware version: 1.00
Info : VTarget = 3.300 V
Info : clock speed 4000 kHz
Info : JTAG tap: riscv.cpu tap/device found: 0x20000913 (mfg: 0x489 (SiFive Inc), part: 0x0000, ver: 0x2)
Info : datacount=1 progbufsize=16
Info : Disabling abstract command reads from CSRs.
Info : Examined RISC-V core; found 1 harts
Info : hart 0: XLEN=32, misa=0x40101105
Info : Listening on port 3333 for gdb connections
Info : Found flash device 'issi is25lp032' (ID 0x0016609d)
ERROR: first sector must be <= last
…and this still happens even if I specify a size in the flash bank portion (and if I specify size for flash protect instead of last, then I see ERROR: last sector must be <= 63
)
This all seems to me that the flash bank is not being properly setup. It does seem it is getting detected by openocd through jlink/jtag, but not sure what’s going wrong (also, flash banks
isn’t printing on my build… but can debug that on my own at least).
I have been able to flash the board using USB mass storage, so I at least know the cable is good ;D
Any ideas?