Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add Jtag VPI support for sim #1095

Merged
merged 9 commits into from
May 13, 2023
Merged

Conversation

allexoll
Copy link
Contributor

@allexoll allexoll commented Apr 22, 2023

Closes #

Context, Motivation & Description

This PR brings in some initial support for Jtag VPI, as an alternative to TcpJtag which require a forked openOCD. The VPI does not.

Impact on code generation

none

Checklist

  • Unit tests were added
  • API changes are or will be documented:

Copy link
Collaborator

@andreasWallner andreasWallner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments from reading the code. One general comment: please run scalafmt on the code.

I'll try it out later today, have to go and buy some groceries now...

@andreasWallner
Copy link
Collaborator

Btw. do you by any chance have an usage example somewhere online for trying it out?

@allexoll
Copy link
Contributor Author

allexoll commented Apr 22, 2023

not a complete one, but it is essentially a drop-in replacement for JtagTcp, like in Murax. An example openOCD config.

If you want to test it with murax, you only need to change the JtagTcp line in the sim file, and change the cfg for openocd to the jtag_vpi interface with source [find interface/jtag_vpi.cfg]

Copy link
Collaborator

@andreasWallner andreasWallner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying it here I stumbled over some minor things that I commented in the source. The thing is that I could not get it to work with Murax. (sorry it took me a bit since I had to recompile the spinal openocd fork, for some reason the one I had lying aroung did not support the vpi interface)

I tried by modifying MuraxSim from VexRiscv to use JtagVpi:

val jtagvpi = JtagVpi(dut.io.jtag, jtagClkPeriod=((12 MHz) / 4 ).toTime)

instead of the JtagTcp it was using.

With the JtagTcp openocd/gdb worked as expected (command line src/openocd -f tcl/interface/jtag_tcp.cfg -c 'set MURAX_CPU0_YAML ../VexRiscv/cpu0.yaml' -f tcl/target/murax.cfg, that finds a device on the scanchain with ID 0x10001fff) but with JtagVpi I get errors (command line src/openocd -f tcl/interface/jtag_vpi.cfg -c 'set MURAX_CPU0_YAML ../VexRiscv/cpu0.yaml' -f tcl/target/murax.cfg).

% src/openocd -f tcl/interface/jtag_vpi.cfg -c 'set MURAX_CPU0_YAML ../VexRiscv/cpu0.yaml' -f tcl/target/murax.cfg 
Open On-Chip Debugger 0.11.0+dev-04033-g058dfa50d (2023-04-24-01:20)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : jtag_vpi: server port set to 5555
Info : jtag_vpi: server address set to 127.0.0.1
../VexRiscv/cpu0.yaml
DEPRECATED! use 'adapter speed' not 'adapter_khz'
DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
Info : set servers polling period to 50ms
Info : jtag_vpi: Connection to 127.0.0.1 : 5555 successful
Info : This adapter doesn't support configurable speed
Info : JTAG tap: fpga_spinal.bridge tap/device found: 0x20003fff (mfg: 0x7ff (<invalid>), part: 0x0003, ver: 0x2)
Warn : JTAG tap: fpga_spinal.bridge       UNEXPECTED: 0x20003fff (mfg: 0x7ff (<invalid>), part: 0x0003, ver: 0x2)
Error: JTAG tap: fpga_spinal.bridge  expected 1 of 1: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)
Info : TAP auto0.tap does not have valid IDCODE (idcode=0xfffffffe)
Error: Trying to use configured scan chain anyway...
Error: fpga_spinal.bridge: IR capture error; saw 0x03 not 0x01
Warn : Bypassing JTAG setup events due to errors
Error: !!!
Error: Can't communicate with the CPU
Error: !!!

Kind of interesting might be that already the id of the device on the scanchain differs from the one I get via the JtagTcp interface.
Is there something in addition that I have to change to make it work?

lib/src/main/scala/spinal/lib/com/jtag/sim/JtagVpi.scala Outdated Show resolved Hide resolved
import spinal.lib.com.jtag.Jtag

import java.nio.{ByteBuffer, ByteOrder}
import spinal.lib.com.jtag.sim.JtagDriver
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this import (since both files are in the same package once the package above is fixed), it actually generates a compile warning for me.

Suggested change
import spinal.lib.com.jtag.sim.JtagDriver

lib/src/main/scala/spinal/lib/com/jtag/sim/JtagVpi.scala Outdated Show resolved Hide resolved
@allexoll
Copy link
Contributor Author

In regard to your test, did you enable the jtag-vpi interface (is disabled by default by ./configure).

to test it, I compiled the spinal fork and built with `

./configure --enable-ftdi --enable-dummy --enable-jtag_vpi
make -j
sudo make install

and then ran with -f tcl/interface/jtag_vpi.cfg -c 'set MURAX_CPU0_YAML ../VexRiscv/cpu0.yaml' -f tcl/target/murax.cfg

It worked:

Open On-Chip Debugger 0.11.0+dev-04033-g058dfa50d-dirty (2023-04-24-09:06)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : jtag_vpi: server port set to 5555
Info : jtag_vpi: server address set to 127.0.0.1
../VexRiscv/cpu0.yaml
DEPRECATED! use 'adapter speed' not 'adapter_khz'
DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
Info : set servers polling period to 50ms
Info : jtag_vpi: Connection to 127.0.0.1 : 5555 successful
Info : This adapter doesn't support configurable speed
Info : JTAG tap: fpga_spinal.bridge tap/device found: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)

Did you change anything else from sock in you configuration? the error you see looks like a misconfiguration of -irlen in the configuration (so all the bits are shifted by one)

@andreasWallner
Copy link
Collaborator

andreasWallner commented Apr 24, 2023

In regard to your test, did you enable the jtag-vpi interface (is disabled by default by ./configure).
Sure, that's why I needed to recompile, just to be sure I ran through the steps again.

The changes that I did in Murax (tried with current VexRiscv master, c52433575dec04f10063b2fd7cebd0545c8b1be9):

diff --git a/src/test/scala/vexriscv/MuraxSim.scala b/src/test/scala/vexriscv/MuraxSim.scala
index 6a6a19c..5fa1fd6 100644
--- a/src/test/scala/vexriscv/MuraxSim.scala
+++ b/src/test/scala/vexriscv/MuraxSim.scala
@@ -9,7 +9,7 @@ import spinal.core.sim._
 import vexriscv.demo.{Murax, MuraxConfig}
 import javax.swing._
 
-import spinal.lib.com.jtag.sim.JtagTcp
+import spinal.lib.com.jtag.sim.{JtagTcp, JtagVpi}
 import spinal.lib.com.uart.sim.{UartDecoder, UartEncoder}
 import vexriscv.test.{JLedArray, JSwitchArray}
 
@@ -32,10 +32,11 @@ object MuraxSim {
       clockDomain.forkStimulus(mainClkPeriod)
 //      clockDomain.forkSimSpeedPrinter(2)
 
-      val tcpJtag = JtagTcp(
-        jtag = dut.io.jtag,
-        jtagClkPeriod = jtagClkPeriod
-      )
+      //val tcpJtag = JtagTcp(
+      //  jtag = dut.io.jtag,
+      //  jtagClkPeriod = jtagClkPeriod
+      //)
+      val jtagvpi = JtagVpi(dut.io.jtag, jtagClkPeriod=((12 MHz) / 8).toTime)
 
       val uartTx = UartDecoder(
         uartPin = dut.io.uart.txd,

With a build.sbt to use the SpinalHDL with the patch from you:

val spinalVersion = "1.8.1"

lazy val spinalHdlIdslPlugin = ProjectRef(file("../SpinalHDL"), "idslplugin")
lazy val spinalHdlSim = ProjectRef(file("../SpinalHDL"), "sim")
lazy val spinalHdlCore = ProjectRef(file("../SpinalHDL"), "core")
lazy val spinalHdlLib = ProjectRef(file("../SpinalHDL"), "lib")

lazy val root = (project in file(".")).
  settings(
    inThisBuild(List(
      organization := "com.github.spinalhdl",
      scalaVersion := "2.11.12",
      version      := "2.0.0"
    )),
    libraryDependencies ++= Seq(
      "org.scalatest" %% "scalatest" % "3.2.5",
      "org.yaml" % "snakeyaml" % "1.8"
    ),
    name := "VexRiscv",
    scalacOptions += (spinalHdlIdslPlugin / Compile / packageBin / artifactPath).map { file => s"-Xplugin:${file.getAbsolutePath}" }.value
  ).dependsOn(spinalHdlCore, spinalHdlLib, spinalHdlSim, spinalHdlIdslPlugin)

fork := true

I run it via sbt 'test:runMain vexriscv.MuraxSim'

OpenOCD (riscv_spinal branch, 058dfa50d625893bee9fecf8d604141911fac125):

git clone git@github.com:SpinalHDL/openocd_riscv.git
cd openocd_riscv
./bootstrap
./configure --enable-ftdi --enable-dummy --enable-jtag_vpi --disable-werror --prefix /opt/openocd_riscv
make -j 16
sudo make install
src/openocd -f tcl/interface/jtag_vpi.cfg -c 'set MURAX_CPU0_YAML ../VexRiscv/cpu0.yaml' -f tcl/target/murax.cfg

Gives:

1 ~/git/openocd_riscv[riscv_spinal]% openocd -f tcl/interface/jtag_vpi.cfg -c 'set MURAX_CPU0_YAML ../VexRiscv/cpu0.yaml' -f tcl/target/murax.cfg
Open On-Chip Debugger 0.11.0+dev-04033-g058dfa50d (2023-04-24-21:59)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : jtag_vpi: server port set to 5555
Info : jtag_vpi: server address set to 127.0.0.1
../VexRiscv/cpu0.yaml
DEPRECATED! use 'adapter speed' not 'adapter_khz'
DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
Info : set servers polling period to 50ms
Info : jtag_vpi: Connection to 127.0.0.1 : 5555 successful
Info : This adapter doesn't support configurable speed
Info : JTAG tap: fpga_spinal.bridge tap/device found: 0x20003fff (mfg: 0x7ff (<invalid>), part: 0x0003, ver: 0x2)
Warn : JTAG tap: fpga_spinal.bridge       UNEXPECTED: 0x20003fff (mfg: 0x7ff (<invalid>), part: 0x0003, ver: 0x2)
Error: JTAG tap: fpga_spinal.bridge  expected 1 of 1: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)
Info : TAP auto0.tap does not have valid IDCODE (idcode=0xfffffffe)
Error: Trying to use configured scan chain anyway...
Error: fpga_spinal.bridge: IR capture error; saw 0x03 not 0x01
Warn : Bypassing JTAG setup events due to errors

The log on a higher log level:

User : 3 2 options.c:63 configuration_output_handler(): debug_level: 4
User : 4 2 options.c:63 configuration_output_handler(): 
Debug: 5 2 options.c:244 add_default_dirs(): bindir=/usr/local/bin
Debug: 6 2 options.c:245 add_default_dirs(): pkgdatadir=/usr/local/share/openocd
Debug: 7 2 options.c:246 add_default_dirs(): exepath=/opt/openocd_riscv/bin
Debug: 8 2 options.c:247 add_default_dirs(): bin2data=../share/openocd
Debug: 9 2 configuration.c:44 add_script_search_dir(): adding /home/.../.config/openocd
Debug: 10 2 configuration.c:44 add_script_search_dir(): adding /home/.../.openocd
Debug: 11 2 configuration.c:44 add_script_search_dir(): adding /opt/openocd_riscv/bin/../share/openocd/site
Debug: 12 2 configuration.c:44 add_script_search_dir(): adding /opt/openocd_riscv/bin/../share/openocd/scripts
Debug: 13 2 command.c:166 script_debug(): command - ocd_find tcl/interface/jtag_vpi.cfg
Debug: 14 2 configuration.c:99 find_file(): found tcl/interface/jtag_vpi.cfg
Debug: 15 2 command.c:166 script_debug(): command - adapter driver jtag_vpi
Info : 16 2 transport.c:118 allow_transports(): only one transport option; autoselect 'jtag'
Debug: 17 2 command.c:166 script_debug(): command - jtag_vpi set_port 5555
Info : 18 2 jtag_vpi.c:613 jtag_vpi_set_port(): jtag_vpi: server port set to 5555
Debug: 19 2 command.c:166 script_debug(): command - jtag_vpi set_address 127.0.0.1
Info : 20 2 jtag_vpi.c:628 jtag_vpi_set_address(): jtag_vpi: server address set to 127.0.0.1
User : 21 2 options.c:63 configuration_output_handler(): ../VexRiscv/cpu0.yamlUser : 22 2 options.c:63 configuration_output_handler(): 
Debug: 23 2 command.c:166 script_debug(): command - ocd_find tcl/target/murax.cfg
Debug: 24 2 configuration.c:99 find_file(): found tcl/target/murax.cfg
Debug: 25 2 command.c:166 script_debug(): command - echo DEPRECATED! use 'adapter speed' not 'adapter_khz'
User : 26 2 command.c:696 handle_echo(): DEPRECATED! use 'adapter speed' not 'adapter_khz'
Debug: 27 2 command.c:166 script_debug(): command - adapter speed 800
Debug: 28 2 adapter.c:176 adapter_config_khz(): handle adapter khz
Debug: 29 2 adapter.c:140 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 30 2 adapter.c:140 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 31 2 command.c:166 script_debug(): command - echo DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
User : 32 2 command.c:696 handle_echo(): DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
Debug: 33 2 command.c:166 script_debug(): command - adapter srst delay 260
Debug: 34 2 command.c:166 script_debug(): command - jtag_ntrst_delay 250
Debug: 35 2 command.c:166 script_debug(): command - jtag newtap fpga_spinal bridge -expected-id 0x10001fff -irlen 4 -ircapture 0x1 -irmask 0xF
Debug: 36 2 tcl.c:568 jim_newtap_cmd(): Creating New Tap, Chip: fpga_spinal, Tap: bridge, Dotted: fpga_spinal.bridge, 8 params
Debug: 37 2 tcl.c:593 jim_newtap_cmd(): Processing option: -expected-id
Debug: 38 2 tcl.c:593 jim_newtap_cmd(): Processing option: -irlen
Debug: 39 2 tcl.c:593 jim_newtap_cmd(): Processing option: -ircapture
Debug: 40 2 tcl.c:593 jim_newtap_cmd(): Processing option: -irmask
Debug: 41 2 core.c:1468 jtag_tap_init(): Created Tap: fpga_spinal.bridge @ abs position 0, irlen 4, capture: 0x1 mask: 0xf
Debug: 42 2 command.c:166 script_debug(): command - target create fpga_spinal.cpu0 vexriscv -endian little -chain-position fpga_spinal.bridge -coreid 0 -dbgbase 0xF00F0000
Debug: 43 2 target.c:2215 target_free_all_working_areas_restore(): freeing all working areas
Debug: 44 2 vexriscv.c:273 vexriscv_target_create(): vexriscv_target_create

Debug: 45 3 command.c:166 script_debug(): command - vexriscv readWaitCycles 12
Debug: 46 3 command.c:166 script_debug(): command - vexriscv cpuConfigFile ../VexRiscv/cpu0.yaml
Debug: 47 3 command.c:166 script_debug(): command - poll_period 50
Info : 48 3 server.c:783 handle_poll_period_command(): set servers polling period to 50ms
Debug: 49 3 command.c:166 script_debug(): command - init
Debug: 50 3 command.c:166 script_debug(): command - target init
Debug: 51 3 command.c:166 script_debug(): command - target names
Debug: 52 3 command.c:166 script_debug(): command - fpga_spinal.cpu0 cget -event gdb-flash-erase-start
Debug: 53 3 command.c:166 script_debug(): command - fpga_spinal.cpu0 configure -event gdb-flash-erase-start reset init
Debug: 54 3 command.c:166 script_debug(): command - fpga_spinal.cpu0 cget -event gdb-flash-write-end
Debug: 55 3 command.c:166 script_debug(): command - fpga_spinal.cpu0 configure -event gdb-flash-write-end reset halt
Debug: 56 3 command.c:166 script_debug(): command - fpga_spinal.cpu0 cget -event gdb-attach
Debug: 57 3 command.c:166 script_debug(): command - fpga_spinal.cpu0 configure -event gdb-attach halt 1000
Debug: 58 3 target.c:1672 handle_target_init_command(): Initializing targets...
Debug: 59 3 vexriscv.c:669 vexriscv_init_target(): vexriscv_init_target

Debug: 60 3 vexriscv.c:670 vexriscv_init_target(): vexriscv_init_target
Debug: 61 3 vexriscv.c:433 vexriscv_build_reg_cache(): -
Debug: 62 4 semihosting_common.c:130 semihosting_common_init():  
Info : 63 4 jtag_vpi.c:576 jtag_vpi_init(): jtag_vpi: Connection to 127.0.0.1 : 5555 successful
Info : 64 4 adapter.c:75 adapter_init(): This adapter doesn't support configurable speed
Debug: 65 4 openocd.c:143 handle_init_command(): Debug Adapter init complete
Debug: 66 4 command.c:166 script_debug(): command - transport init
Debug: 67 4 transport.c:230 handle_transport_init(): handle_transport_init
Debug: 68 4 jtag_vpi.c:122 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_RESET, length=0, nb_bits=0
Debug: 69 4 core.c:985 default_interface_jtag_execute_queue(): JTAG RESET deassert TRST, deassert SRST
Debug: 70 4 core.c:712 legacy_jtag_add_reset(): SRST line released
Debug: 71 4 core.c:736 legacy_jtag_add_reset(): TRST line released
Debug: 72 4 core.c:322 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 73 520 core.c:994 default_interface_jtag_execute_queue(): JTAG SLEEP (TODO)
Debug: 74 520 core.c:994 default_interface_jtag_execute_queue(): JTAG SLEEP (TODO)
Debug: 75 520 command.c:166 script_debug(): command - jtag arp_init
Debug: 76 520 target.c:1858 target_call_event_callbacks(): target event 0 (gdb-halt) for core fpga_spinal.cpu0
Debug: 77 520 target.c:3073 handle_target(): [fpga_spinal.cpu0] target_poll() -> -4, next attempt in 100ms
Debug: 78 520 core.c:1503 jtag_init_inner(): Init JTAG chain
Debug: 79 520 core.c:322 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 80 520 core.c:972 default_interface_jtag_execute_queue(): JTAG TLR RESET to RESET
Debug: 81 520 core.c:1228 jtag_examine_chain(): DR scan interrogation for IDCODE/BYPASS
Debug: 82 520 core.c:322 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 83 520 commands.c:210 jtag_build_buffer(): DRSCAN num_fields: 1
Debug: 84 520 commands.c:222 jtag_build_buffer(): fields[0].out_value[672]: 0xffffffffffffffff
Debug: 85 520 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=7, buf_out=0x17
Debug: 86 520 jtag_vpi.c:298 jtag_vpi_state_move(): tap_set_state(DRSHIFT)
Debug: 87 520 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_SCAN_CHAIN_FLIP_TMS, length=84, nb_bits=672, buf_out=0xffffffffffffffff(...)
Debug: 88 557 jtag_vpi.c:332 jtag_vpi_queue_tdi_xfer(): recvd JTAG VPI data: nb_bits=672, buf_in=0xfffffffe20003ffe(...)
Debug: 89 557 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=1, buf_out=0x00
Debug: 90 557 jtag_vpi.c:436 jtag_vpi_scan(): tap_set_state(DRPAUSE)
Debug: 91 557 commands.c:265 jtag_read_buffer(): fields[0].in_value[672]: 0xfffffffe20003ffe
Debug: 92 557 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=7, buf_out=0x7f
Debug: 93 557 jtag_vpi.c:298 jtag_vpi_state_move(): tap_set_state(RESET)
Debug: 94 558 core.c:954 default_interface_jtag_execute_queue(): JTAG DR SCAN to DRPAUSE
Debug: 95 558 core.c:961 default_interface_jtag_execute_queue():   672b out: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Debug: 96 558 core.c:966 default_interface_jtag_execute_queue():   672b  in: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe20003ffe
Debug: 97 558 core.c:972 default_interface_jtag_execute_queue(): JTAG TLR RESET to RESET
Info : 98 558 core.c:1278 jtag_examine_chain(): TAP fpga_spinal.bridge does not have valid IDCODE (idcode=0x20003ffe)
Debug: 99 558 core.c:1468 jtag_tap_init(): Created Tap: auto0.tap @ abs position 1, irlen 0, capture: 0x1 mask: 0x3
Debug: 100 558 jep106.c:33 jep106_table_manufacturer(): BUG: Caller passed out-of-range JEP106 ID!
Info : 101 558 core.c:1127 jtag_examine_chain_display(): JTAG tap: auto0.tap tap/device found: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)
Debug: 102 558 core.c:1358 jtag_validate_ircapture(): IR capture validation scan
Debug: 103 558 commands.c:210 jtag_build_buffer(): IRSCAN num_fields: 1
Debug: 104 558 commands.c:222 jtag_build_buffer(): fields[0].out_value[66]: 0xffffffffffffffff
Debug: 105 558 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=7, buf_out=0x1b
Debug: 106 558 jtag_vpi.c:298 jtag_vpi_state_move(): tap_set_state(IRSHIFT)
Debug: 107 558 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_SCAN_CHAIN_FLIP_TMS, length=9, nb_bits=66, buf_out=0xffffffffffffffff(...)
Debug: 108 566 jtag_vpi.c:332 jtag_vpi_queue_tdi_xfer(): recvd JTAG VPI data: nb_bits=66, buf_in=0xffffffffffffffe3(...)
Debug: 109 566 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=1, buf_out=0x00
Debug: 110 566 jtag_vpi.c:434 jtag_vpi_scan(): tap_set_state(IRPAUSE)
Debug: 111 566 commands.c:265 jtag_read_buffer(): fields[0].in_value[66]: 0xffffffffffffffe3
Debug: 112 566 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=3, buf_out=0x03
Debug: 113 566 jtag_vpi.c:298 jtag_vpi_state_move(): tap_set_state(RUN/IDLE)
Debug: 114 566 core.c:954 default_interface_jtag_execute_queue(): JTAG IR SCAN to RUN/IDLE
Debug: 115 566 core.c:961 default_interface_jtag_execute_queue():   66b out: 03ffffffffffffffff
Debug: 116 566 core.c:966 default_interface_jtag_execute_queue():   66b  in: 03ffffffffffffffe3
Error: 117 566 core.c:1407 jtag_validate_ircapture(): fpga_spinal.bridge: IR capture error; saw 0x03 not 0x01
Debug: 118 566 core.c:322 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 119 566 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=7, buf_out=0x7f
Debug: 120 566 jtag_vpi.c:298 jtag_vpi_state_move(): tap_set_state(RESET)
Debug: 121 566 core.c:972 default_interface_jtag_execute_queue(): JTAG TLR RESET to RESET
Warn : 122 566 core.c:1571 jtag_init_inner(): Bypassing JTAG setup events due to errors
...

@allexoll
Copy link
Contributor Author

I just tried this in a clean docker, with no issues...:

root@06c4d45ea855:/home/root/openocd_riscv# src/openocd -f tcl/interface/jtag_vpi.cfg -c 'debug_level 4; set MURAX_CPU0_YAML ../VexRiscv/cpu0.yaml' -f tcl/target/murax.cfg
Open On-Chip Debugger 0.11.0+dev-04033-g058dfa50d (2023-04-25-09:22)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Info : jtag_vpi: server port set to 5555
Info : jtag_vpi: server address set to 127.0.0.1
User : 6 3 options.c:63 configuration_output_handler(): ../VexRiscv/cpu0.yamlUser : 7 3 options.c:63 configuration_output_handler(): 
Debug: 8 3 command.c:166 script_debug(): command - ocd_find tcl/target/murax.cfg
Debug: 9 3 configuration.c:99 find_file(): found tcl/target/murax.cfg
Debug: 10 4 command.c:166 script_debug(): command - echo DEPRECATED! use 'adapter speed' not 'adapter_khz'
User : 11 4 command.c:696 handle_echo(): DEPRECATED! use 'adapter speed' not 'adapter_khz'
Debug: 12 4 command.c:166 script_debug(): command - adapter speed 800
Debug: 13 4 adapter.c:176 adapter_config_khz(): handle adapter khz
Debug: 14 4 adapter.c:140 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 15 4 adapter.c:140 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 16 4 command.c:166 script_debug(): command - echo DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
User : 17 4 command.c:696 handle_echo(): DEPRECATED! use 'adapter srst delay' not 'adapter_nsrst_delay'
Debug: 18 4 command.c:166 script_debug(): command - adapter srst delay 260
Debug: 19 4 command.c:166 script_debug(): command - jtag_ntrst_delay 250
Debug: 20 4 command.c:166 script_debug(): command - jtag newtap fpga_spinal bridge -expected-id 0x10001fff -irlen 4 -ircapture 0x1 -irmask 0xF
Debug: 21 4 tcl.c:568 jim_newtap_cmd(): Creating New Tap, Chip: fpga_spinal, Tap: bridge, Dotted: fpga_spinal.bridge, 8 params
Debug: 22 4 tcl.c:593 jim_newtap_cmd(): Processing option: -expected-id
Debug: 23 4 tcl.c:593 jim_newtap_cmd(): Processing option: -irlen
Debug: 24 4 tcl.c:593 jim_newtap_cmd(): Processing option: -ircapture
Debug: 25 4 tcl.c:593 jim_newtap_cmd(): Processing option: -irmask
Debug: 26 4 core.c:1468 jtag_tap_init(): Created Tap: fpga_spinal.bridge @ abs position 0, irlen 4, capture: 0x1 mask: 0xf
Debug: 27 4 command.c:166 script_debug(): command - target create fpga_spinal.cpu0 vexriscv -endian little -chain-position fpga_spinal.bridge -coreid 0 -dbgbase 0xF00F0000
Debug: 28 4 target.c:2215 target_free_all_working_areas_restore(): freeing all working areas
Debug: 29 4 vexriscv.c:273 vexriscv_target_create(): vexriscv_target_create

Debug: 30 4 command.c:166 script_debug(): command - vexriscv readWaitCycles 12
Debug: 31 4 command.c:166 script_debug(): command - vexriscv cpuConfigFile ../VexRiscv/cpu0.yaml
Debug: 32 4 command.c:166 script_debug(): command - poll_period 50
Info : 33 4 server.c:783 handle_poll_period_command(): set servers polling period to 50ms
Debug: 34 4 command.c:166 script_debug(): command - init
Debug: 35 4 command.c:166 script_debug(): command - target init
Debug: 36 4 command.c:166 script_debug(): command - target names
Debug: 37 4 command.c:166 script_debug(): command - fpga_spinal.cpu0 cget -event gdb-flash-erase-start
Debug: 38 4 command.c:166 script_debug(): command - fpga_spinal.cpu0 configure -event gdb-flash-erase-start reset init
Debug: 39 4 command.c:166 script_debug(): command - fpga_spinal.cpu0 cget -event gdb-flash-write-end
Debug: 40 4 command.c:166 script_debug(): command - fpga_spinal.cpu0 configure -event gdb-flash-write-end reset halt
Debug: 41 4 command.c:166 script_debug(): command - fpga_spinal.cpu0 cget -event gdb-attach
Debug: 42 4 command.c:166 script_debug(): command - fpga_spinal.cpu0 configure -event gdb-attach halt 1000
Debug: 43 4 target.c:1672 handle_target_init_command(): Initializing targets...
Debug: 44 4 vexriscv.c:669 vexriscv_init_target(): vexriscv_init_target

Debug: 45 4 vexriscv.c:670 vexriscv_init_target(): vexriscv_init_target
Debug: 46 5 vexriscv.c:433 vexriscv_build_reg_cache(): -
Debug: 47 6 semihosting_common.c:130 semihosting_common_init():  
Info : 48 6 jtag_vpi.c:576 jtag_vpi_init(): jtag_vpi: Connection to 127.0.0.1 : 5555 successful
Info : 49 6 adapter.c:75 adapter_init(): This adapter doesn't support configurable speed
Debug: 50 6 openocd.c:143 handle_init_command(): Debug Adapter init complete
Debug: 51 6 command.c:166 script_debug(): command - transport init
Debug: 52 6 transport.c:230 handle_transport_init(): handle_transport_init
Debug: 53 6 jtag_vpi.c:122 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_RESET, length=0, nb_bits=0
Debug: 54 6 core.c:985 default_interface_jtag_execute_queue(): JTAG RESET deassert TRST, deassert SRST
Debug: 55 6 core.c:712 legacy_jtag_add_reset(): SRST line released
Debug: 56 6 core.c:736 legacy_jtag_add_reset(): TRST line released
Debug: 57 6 core.c:322 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 58 606 core.c:994 default_interface_jtag_execute_queue(): JTAG SLEEP (TODO)
Debug: 59 606 core.c:994 default_interface_jtag_execute_queue(): JTAG SLEEP (TODO)
Debug: 60 606 command.c:166 script_debug(): command - jtag arp_init
Debug: 61 606 target.c:1858 target_call_event_callbacks(): target event 0 (gdb-halt) for core fpga_spinal.cpu0
Debug: 62 606 target.c:3073 handle_target(): [fpga_spinal.cpu0] target_poll() -> -4, next attempt in 100ms
Debug: 63 606 core.c:1503 jtag_init_inner(): Init JTAG chain
Debug: 64 606 core.c:322 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 65 607 core.c:972 default_interface_jtag_execute_queue(): JTAG TLR RESET to RESET
Debug: 66 607 core.c:1228 jtag_examine_chain(): DR scan interrogation for IDCODE/BYPASS
Debug: 67 607 core.c:322 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 68 607 commands.c:210 jtag_build_buffer(): DRSCAN num_fields: 1
Debug: 69 607 commands.c:222 jtag_build_buffer(): fields[0].out_value[672]: 0xffffffffffffffff
Debug: 70 607 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=7, buf_out=0x17
Debug: 71 608 jtag_vpi.c:298 jtag_vpi_state_move(): tap_set_state(DRSHIFT)
Debug: 72 608 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_SCAN_CHAIN_FLIP_TMS, length=84, nb_bits=672, buf_out=0xffffffffffffffff(...)
Debug: 73 663 jtag_vpi.c:332 jtag_vpi_queue_tdi_xfer(): recvd JTAG VPI data: nb_bits=672, buf_in=0xffffffff10001fff(...)
Debug: 74 663 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=1, buf_out=0x00
Debug: 75 663 jtag_vpi.c:436 jtag_vpi_scan(): tap_set_state(DRPAUSE)
Debug: 76 663 commands.c:265 jtag_read_buffer(): fields[0].in_value[672]: 0xffffffff10001fff
Debug: 77 663 jtag_vpi.c:110 jtag_vpi_send_cmd(): sending JTAG VPI cmd: cmd=CMD_TMS_SEQ, length=1, nb_bits=7, buf_out=0x7f
Debug: 78 663 jtag_vpi.c:298 jtag_vpi_state_move(): tap_set_state(RESET)
Debug: 79 663 core.c:954 default_interface_jtag_execute_queue(): JTAG DR SCAN to DRPAUSE
Debug: 80 663 core.c:961 default_interface_jtag_execute_queue():   672b out: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Debug: 81 664 core.c:966 default_interface_jtag_execute_queue():   672b  in: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff10001fff
Debug: 82 664 core.c:972 default_interface_jtag_execute_queue(): JTAG TLR RESET to RESET
Debug: 83 664 jep106.c:33 jep106_table_manufacturer(): BUG: Caller passed out-of-range JEP106 ID!
Info : 84 664 core.c:1127 jtag_examine_chain_display(): JTAG tap: fpga_spinal.bridge tap/device found: 0x10001fff (mfg: 0x7ff (<invalid>), part: 0x0001, ver: 0x1)

I just tried the same thing in a ubuntu docker, with all HEAD version and compiled: verilator, SpinalHDL/openocd_riscv, allexoll/SpinalHDL:jtag-vpi, SpinalHDL/Vexriscv, and no problem running it.

can you give me the hash for the Spinal ref?

@andreasWallner
Copy link
Collaborator

andreasWallner commented Apr 25, 2023

SpinalHDL ref is 57c6f880
This is really weird, I'll give it a try in on another machine/docker - won't be able to make it today though.

@allexoll
Copy link
Contributor Author

allexoll commented Apr 26, 2023

If you need it there's a simple dockerfile as a basis, just need to clone and modify Vexriscv as you did before and test it with openocd:

FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y curl build-essential git perl gnupg2 python3 make help2man autoconf g++ flex bison ccache libgoogle-perftools-dev numactl perl-doc libfl2 libfl-dev zlib1g zlib1g-dev libtool automake libusb-1.0.0-dev texinfo libusb-dev libyaml-dev pkg-config default-jdk scala verilator

#install SBT
RUN echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | tee /etc/apt/sources.list.d/sbt.list && \
    echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | tee /etc/apt/sources.list.d/sbt_old.list && \
    curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | apt-key add && \
    apt-get update && \
    apt-get install sbt

# conf sbt with more memory
ENV SBT_OPTS="-XX:+CMSClassUnloadingEnabled -Xmx4G -Xms4G"

RUN git clone https://github.com/SpinalHDL/openocd_riscv && \
    cd openocd_riscv && \
    ./bootstrap && \
    ./configure --enable-jtag_pi && \
    make -j && \
    make install

RUN git clone https://github.com/allexoll/SpinalHDL && \
    cd SpinalHDL && \
    git checkout jtag-vpi && \
    sbt clean publishLocal

tdoSeq(i) = jtag.tdo.toBoolean
doClockCycles(1)
}
tdoSeq.to[collection.immutable.Seq]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't work since the type parameters for Seq are missing

Suggested change
tdoSeq.to[collection.immutable.Seq]
tdoSeq.toSeq

See also https://scastie.scala-lang.org/t1vaui2CR1qdlCtpZDfAFA

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's weird, I do not get a warning on my setup, but I do get one with toSeq as it gives me a "remove redundant collection conversion"... would it make sense then to juste return tdoSeq?

@andreasWallner
Copy link
Collaborator

I tried with your Dockerfile but:

  • the build command line has a typo (jtag_pi -> jtag_vpi)
  • with the verilator in there I can't run the simulation. I get a few errors like: /VexRiscv/tmp/job_1/Murax.v:7282:17: Unsupported or unknown PLI call: '$urandom' , looks like the verilator version is too old (installed is Verilator 4.038 which is far below what Spinal needs which is >= 4.218), I used the one from oss-cad-suite instead
  • Afterward I got issue since the container doesn't have an X server - easily fixed by commenting that part out

After those fixes it works in the resulting container.
I also tried on another 2 machines, on both of the it works - it seems I'll have to find out what's weird about my local machine here...
Thanks for your patience, a bit of life happened ;-)

If you could have a look at the scala 2.13 comment above we can merge this I think (I figured out btw. why the CI doesn't complain, PR in the works :-) )

@andreasWallner
Copy link
Collaborator

andreasWallner commented May 13, 2023

Rebased this so that it runs in CI against all supported scala versions.
Sorry for the long wait, I somehow didn't get that you had responded to the review comment above.
FYI: you can check locally by running sbt "++compile" - that will build for all versions.

@allexoll
Copy link
Contributor Author

I think this is finally done... my editor still tells me that the "toSeq" is redundant, but since the CI is not complaining anymore, I'm fine with it as is...

@andreasWallner andreasWallner merged commit 6a5c38a into SpinalHDL:dev May 13, 2023
13 checks passed
@andreasWallner
Copy link
Collaborator

Thanks so much!

@allexoll
Copy link
Contributor Author

thanks to you for dealing with all this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants