debug: Checkpoint restoring Spike functionality
authorMegan Wachs <megan@sifive.com>
Mon, 17 Apr 2017 21:20:53 +0000 (14:20 -0700)
committerMegan Wachs <megan@sifive.com>
Mon, 17 Apr 2017 21:20:53 +0000 (14:20 -0700)
debug/Makefile
debug/README.md
debug/gdbserver.py
debug/targets.py
debug/testlib.py

index 79e89cbe397d912d024a26cdb09ddd081491c02f..1916bdaa964012ae4a7bcfca2abddfe8aeef9ad3 100644 (file)
@@ -1,6 +1,23 @@
 RISCV_SIM ?= spike
 XLEN ?= 64
 
+OPENOCD_INSTALL ?= $(abspath .)/openocd-install
+OPENOCD_VERSION = 860b42a3c4f6aa37d8d4fe50a71000b7cff66b85
+
+OPENOCD_DIR = $(OPENOCD_INSTALL)_$(OPENOCD_VERSION)/
+
+$(OPENOCD_DIR)/bin/openocd:
+       rm -rf riscv-openocd
+       git clone http://github.com/riscv/riscv-openocd.git
+       cd riscv-openocd ; \
+       git checkout $(OPENOCD_VERSION) ; \
+       ./bootstrap ; \
+       ./configure --enable-remote_bitbang --prefix=$(OPENOCD_INSTALL)_$(OPENOCD_VERSION) --disable-werror; \
+       make ; \
+       make install
+
+install_openocd: $(OPENOCD_DIR)/bin/openocd
+
 src_dir ?= .
 GDBSERVER_PY = $(src_dir)/gdbserver.py
 
@@ -12,7 +29,7 @@ pylint:
        pylint --rcfile=pylint.rc *.py
 
 %.log:
-       $(GDBSERVER_PY) --isolate --$(subst .log,,$@) \
+       $(GDBSERVER_PY) --isolate --$(subst .log,,$@) --server_cmd $(OPENOCD_DIR)/bin/openocd \
            > $@ 2>&1 || (sed s/^/$@:\ / $@ && false)
 
 clean:
index 56f69db07ec6a1cf6c009a97d1d1314b6b860834..04aa13a969d7304bc1d0d968063c61bf5f65a051 100644 (file)
@@ -2,9 +2,9 @@ Debug Tests
 ===========
 
 Debugging requires many system components to all work together. The tests here
-perform an end-to-end test, communicating only with gdb. If a simulator or
-hardware passes all these tests, then you can be pretty confident that the
-actual debug interface is functioning correctly.
+perform an end-to-end test, communicating with gdb and OpenOCD.
+If a simulator or hardware passes all these tests, then you can be pretty
+confident that the actual debug interface is functioning correctly.
 
 Targets
 =======
@@ -23,13 +23,14 @@ Targets
 -------------------------------------
 
 `./gdbserver.py --freedom-e300`
+`./gdbserver.py --hifive1`
+
 
 32-bit rocket-chip core in Simulation
 -------------------------------------
 
 `./gdbserver.py --freedom-e300-sim`
 
-
 Debug Tips
 ==========
 
index 6690ad92c85f1dfbe6fbc9c614a073478253acac..7220f9388f4515d701385e0a2c69f1a3623c5f03 100755 (executable)
@@ -678,7 +678,7 @@ def main():
             epilog="""
             Example command line from the real world:
             Run all RegsTest cases against a physical FPGA, with custom openocd command:
-            ./gdbserver.py --freedom-e300 --cmd "$HOME/SiFive/openocd/src/openocd -s $HOME/SiFive/openocd/tcl -d" Simple
+            ./gdbserver.py --freedom-e300 --server_cmd "$HOME/SiFive/openocd/src/openocd -s $HOME/SiFive/openocd/tcl -d" Simple
             """)
     targets.add_target_options(parser)
 
@@ -688,7 +688,7 @@ def main():
     global parsed   # pylint: disable=global-statement
     parsed = parser.parse_args()
 
-    target = parsed.target(parsed.cmd, parsed.run, parsed.isolate)
+    target = parsed.target(parsed.server_cmd, parsed.sim_cmd, parsed.isolate)
     if parsed.xlen:
         target.xlen = parsed.xlen
 
index f2728d1aed30db7ff7cdecf1f100e026f06d1577..d49b3970670598768fe7cac5dd56bbae79dd7b4f 100644 (file)
@@ -14,9 +14,9 @@ class Target(object):
     use_fpu = False
     misa = None
 
-    def __init__(self, cmd, run, isolate):
-        self.cmd = cmd
-        self.run = run
+    def __init__(self, server_cmd, sim_cmd, isolate):
+        self.server_cmd = server_cmd
+        self.sim_cmd = sim_cmd
         self.isolate = isolate
 
     def target(self):
@@ -26,7 +26,7 @@ class Target(object):
     def server(self):
         """Start the debug server that gdb connects to, eg. OpenOCD."""
         if self.openocd_config:
-            return testlib.Openocd(cmd=self.cmd, config=self.openocd_config)
+            return testlib.Openocd(server_cmd=self.server_cmd, config=self.openocd_config)
         else:
             raise NotImplementedError
 
@@ -76,14 +76,14 @@ class Spike64Target(SpikeTarget):
     use_fpu = True
 
     def target(self):
-        return testlib.Spike(self.cmd, halted=True)
+        return testlib.Spike(self.sim_cmd, halted=True)
 
 class Spike32Target(SpikeTarget):
     name = "spike32"
     xlen = 32
 
     def target(self):
-        return testlib.Spike(self.cmd, halted=True, xlen=32)
+        return testlib.Spike(self.sim_cmd, halted=True, xlen=32)
 
 class FreedomE300Target(Target):
     name = "freedom-e300"
@@ -107,7 +107,7 @@ class FreedomE300SimTarget(Target):
     openocd_config = "targets/%s/openocd.cfg" % name
 
     def target(self):
-        return testlib.VcsSim(simv=self.run, debug=False)
+        return testlib.VcsSim(simv=self.sim_cmd, debug=False)
 
 class FreedomU500Target(Target):
     name = "freedom-u500"
@@ -127,7 +127,7 @@ class FreedomU500SimTarget(Target):
     openocd_config = "targets/%s/openocd.cfg" % name
 
     def target(self):
-        return testlib.VcsSim(simv=self.run, debug=False)
+        return testlib.VcsSim(simv=self.sim_cmd, debug=False)
 
 targets = [
         Spike32Target,
@@ -143,11 +143,11 @@ def add_target_options(parser):
     for t in targets:
         group.add_argument("--%s" % t.name, action="store_const", const=t,
                 dest="target")
-    parser.add_argument("--run",
+    parser.add_argument("--sim_cmd",
             help="The command to use to start the actual target (e.g. "
             "simulation)")
-    parser.add_argument("--cmd",
-            help="The command to use to start the debug server.")
+    parser.add_argument("--server_cmd",
+            help="The command to use to start the debug server (e.g. OpenOCD)")
 
     xlen_group = parser.add_mutually_exclusive_group()
     xlen_group.add_argument("--32", action="store_const", const=32, dest="xlen",
index 71bd60966abdab6cb5ab8298de91e49db3b67418..f1f0fe1606d42b3fa02027a1d25aa679cad640fd 100644 (file)
@@ -57,14 +57,15 @@ def unused_port():
 class Spike(object):
     logname = "spike.log"
 
-    def __init__(self, cmd, binary=None, halted=False, with_jtag_gdb=True,
+    def __init__(self, sim_cmd, binary=None, halted=False, with_jtag_gdb=True,
             timeout=None, xlen=64):
         """Launch spike. Return tuple of its process and the port it's running
         on."""
-        if cmd:
-            cmd = shlex.split(cmd)
+        if sim_cmd:
+            cmd = shlex.split(sim_cmd)
         else:
-            cmd = ["spike"]
+            spike = os.path.expandvars("$RISCV/bin/spike")
+            cmd = [spike]
         if xlen == 32:
             cmd += ["--isa", "RV32"]
 
@@ -110,8 +111,8 @@ class Spike(object):
         return self.process.wait(*args, **kwargs)
 
 class VcsSim(object):
-    def __init__(self, simv=None, debug=False):
-        if simv:
+    def __init__(self, sim_cmd=None, debug=False):
+        if sim_cmd:
             cmd = shlex.split(simv)
         else:
             cmd = ["simv"]
@@ -147,12 +148,15 @@ class VcsSim(object):
 class Openocd(object):
     logname = "openocd.log"
 
-    def __init__(self, cmd=None, config=None, debug=False):
-        if cmd:
-            cmd = shlex.split(cmd)
+    def __init__(self, server_cmd=None, config=None, debug=False):
+        if server_cmd:
+            cmd = shlex.split(server_cmd)
         else:
-            cmd = ["openocd", "-d"]
-
+            openocd = os.path.expandvars("$RISCV/bin/riscv-openocd")
+            cmd = [openocd]
+            if (debug):
+                cmd.append("-d")
+        
         # This command needs to come before any config scripts on the command
         # line, since they are executed in order.
         cmd += [