Merge remote-tracking branch 'origin/priv-1.10' into HEAD
authorMegan Wachs <megan@sifive.com>
Mon, 17 Apr 2017 18:33:46 +0000 (11:33 -0700)
committerMegan Wachs <megan@sifive.com>
Mon, 17 Apr 2017 18:33:46 +0000 (11:33 -0700)
debug/Makefile
debug/gdbserver.py
debug/targets.py
debug/targets/spike/openocd.cfg [new file with mode: 0644]
debug/testlib.py

index 56db73178201087e6817e5af7a0d35d0887347d2..79e89cbe397d912d024a26cdb09ddd081491c02f 100644 (file)
@@ -12,7 +12,7 @@ pylint:
        pylint --rcfile=pylint.rc *.py
 
 %.log:
-       $(GDBSERVER_PY) --isolate --$(subst .log,,$@) --cmd $(RISCV_SIM) \
+       $(GDBSERVER_PY) --isolate --$(subst .log,,$@) \
            > $@ 2>&1 || (sed s/^/$@:\ / $@ && false)
 
 clean:
index 3d4533e1393960787ede1ac4c6067d74c5d757be..6690ad92c85f1dfbe6fbc9c614a073478253acac 100755 (executable)
@@ -6,6 +6,7 @@ import random
 import sys
 import tempfile
 import time
+import os
 
 import targets
 import testlib
@@ -571,38 +572,41 @@ class DownloadTest(GdbTest):
     def setup(self):
         # pylint: disable=attribute-defined-outside-init
         length = min(2**20, self.target.ram_size - 2048)
-        download_c = tempfile.NamedTemporaryFile(prefix="download_",
-                suffix=".c")
-        download_c.write("#include <stdint.h>\n")
-        download_c.write(
+        self.download_c = tempfile.NamedTemporaryFile(prefix="download_",
+                suffix=".c", delete=False)
+        self.download_c.write("#include <stdint.h>\n")
+        self.download_c.write(
                 "unsigned int crc32a(uint8_t *message, unsigned int size);\n")
-        download_c.write("uint32_t length = %d;\n" % length)
-        download_c.write("uint8_t d[%d] = {\n" % length)
+        self.download_c.write("uint32_t length = %d;\n" % length)
+        self.download_c.write("uint8_t d[%d] = {\n" % length)
         self.crc = 0
+        assert length % 16 == 0
         for i in range(length / 16):
-            download_c.write("  /* 0x%04x */ " % (i * 16))
+            self.download_c.write("  /* 0x%04x */ " % (i * 16))
             for _ in range(16):
                 value = random.randrange(1<<8)
-                download_c.write("%d, " % value)
+                self.download_c.write("0x%02x, " % value)
                 self.crc = binascii.crc32("%c" % value, self.crc)
-            download_c.write("\n")
-        download_c.write("};\n")
-        download_c.write("uint8_t *data = &d[0];\n")
-        download_c.write("uint32_t main() { return crc32a(data, length); }\n")
-        download_c.flush()
+            self.download_c.write("\n")
+        self.download_c.write("};\n")
+        self.download_c.write("uint8_t *data = &d[0];\n")
+        self.download_c.write(
+                "uint32_t main() { return crc32a(data, length); }\n")
+        self.download_c.flush()
 
         if self.crc < 0:
             self.crc += 2**32
 
-        self.binary = self.target.compile(download_c.name,
+        self.binary = self.target.compile(self.download_c.name,
                 "programs/checksum.c")
         self.gdb.command("file %s" % self.binary)
 
     def test(self):
         self.gdb.load()
         self.gdb.command("b _exit")
-        self.gdb.c()
+        self.gdb.c(timeout=60)
         assertEqual(self.gdb.p("status"), self.crc)
+        os.unlink(self.download_c.name)
 
 class MprvTest(GdbTest):
     compile_args = ("programs/mprv.S", )
index 52b623cc59262353b4a84d4582b1a862c1438588..5ac62a83de518f934f89aca4ef7733d38ad53861 100644 (file)
@@ -68,20 +68,21 @@ class SpikeTarget(Target):
     ram_size = 5 * 1024 * 1024
     instruction_hardware_breakpoint_count = 4
     reset_vector = 0x1000
+    openocd_config = "targets/%s/openocd.cfg" % directory
 
 class Spike64Target(SpikeTarget):
     name = "spike64"
     xlen = 64
     use_fpu = True
 
-    def server(self):
+    def target(self):
         return testlib.Spike(self.cmd, halted=True)
 
 class Spike32Target(SpikeTarget):
     name = "spike32"
     xlen = 32
 
-    def server(self):
+    def target(self):
         return testlib.Spike(self.cmd, halted=True, xlen=32)
 
 class FreedomE300Target(Target):
diff --git a/debug/targets/spike/openocd.cfg b/debug/targets/spike/openocd.cfg
new file mode 100644 (file)
index 0000000..5389da8
--- /dev/null
@@ -0,0 +1,17 @@
+adapter_khz     10000
+
+interface remote_bitbang
+remote_bitbang_host $::env(REMOTE_BITBANG_HOST)
+remote_bitbang_port $::env(REMOTE_BITBANG_PORT)
+
+set _CHIPNAME riscv
+jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x10e31913
+
+set _TARGETNAME $_CHIPNAME.cpu
+target create $_TARGETNAME riscv -chain-position $_TARGETNAME
+
+gdb_report_data_abort enable
+
+init
+
+halt
index a762174df18240a2309d3f8def20f14ff998d3c5..392772291f2ffa633b38b9d462dcec1005a59941 100644 (file)
@@ -51,7 +51,7 @@ def unused_port():
 class Spike(object):
     logname = "spike.log"
 
-    def __init__(self, cmd, binary=None, halted=False, with_gdb=True,
+    def __init__(self, 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."""
@@ -67,9 +67,9 @@ class Spike(object):
 
         if halted:
             cmd.append('-H')
-        if with_gdb:
-            self.port = unused_port()
-            cmd += ['--gdb-port', str(self.port)]
+        if with_jtag_gdb:
+            cmd += ['--rbb-port', '0']
+            os.environ['REMOTE_BITBANG_HOST'] = 'localhost'
         cmd.append("-m32")
         cmd.append('pk')
         if binary:
@@ -80,6 +80,19 @@ class Spike(object):
         self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                 stdout=logfile, stderr=logfile)
 
+        if with_jtag_gdb:
+            self.port = None
+            for _ in range(30):
+                m = re.search(r"Listening for remote bitbang connection on "
+                        r"port (\d+).", open(self.logname).read())
+                if m:
+                    self.port = int(m.group(1))
+                    os.environ['REMOTE_BITBANG_PORT'] = m.group(1)
+                    break
+                time.sleep(0.11)
+            assert self.port, "Didn't get spike message about bitbang " \
+                    "connection"
+
     def __del__(self):
         try:
             self.process.kill()
@@ -132,15 +145,11 @@ class Openocd(object):
         if cmd:
             cmd = shlex.split(cmd)
         else:
-            cmd = ["openocd"]
-        if config:
-            cmd += ["-f", find_file(config)]
-        if debug:
-            cmd.append("-d")
+            cmd = ["openocd", "-d"]
 
         # This command needs to come before any config scripts on the command
         # line, since they are executed in order.
-        cmd[1:1] = [
+        cmd += [
             # Tell OpenOCD to bind gdb to an unused, ephemeral port.
             "--command",
             "gdb_port 0",
@@ -153,6 +162,16 @@ class Openocd(object):
             "telnet_port disabled",
         ]
 
+        if config:
+            f = find_file(config)
+            if f is None:
+                print("Unable to read file " + config)
+                exit(1)
+
+            cmd += ["-f", f]
+        if debug:
+            cmd.append("-d")
+
         logfile = open(Openocd.logname, "w")
         logfile.write("+ %s\n" % " ".join(cmd))
         logfile.flush()
@@ -267,9 +286,9 @@ class Gdb(object):
         self.child.expect(r"\(gdb\)", timeout=timeout)
         return self.child.before.strip()
 
-    def c(self, wait=True):
+    def c(self, wait=True, timeout=-1):
         if wait:
-            output = self.command("c")
+            output = self.command("c", timeout=timeout)
             assert "Continuing" in output
             return output
         else: