Pull port number from VCS output and pass to OpenOCD.
authorRichard Xia <rxia@sifive.com>
Tue, 18 Oct 2016 21:38:24 +0000 (14:38 -0700)
committerRichard Xia <rxia@sifive.com>
Tue, 18 Oct 2016 21:38:24 +0000 (14:38 -0700)
debug/targets/freedom-e300-sim/openocd.cfg
debug/targets/freedom-u500-sim/openocd.cfg
debug/testlib.py

index e8edda4e6c660392c0deb3913c5fdb30d12b0f5c..0b808858a410a53f876d02fec4a5fc42c52e42e2 100644 (file)
@@ -1,6 +1,7 @@
 adapter_khz     10000
 
 source [find interface/jtag_vpi.cfg]
+jtag_vpi_set_port $::env(JTAG_VPI_PORT)
 
 set _CHIPNAME riscv
 jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x10e31913
index e8edda4e6c660392c0deb3913c5fdb30d12b0f5c..0b808858a410a53f876d02fec4a5fc42c52e42e2 100644 (file)
@@ -1,6 +1,7 @@
 adapter_khz     10000
 
 source [find interface/jtag_vpi.cfg]
+jtag_vpi_set_port $::env(JTAG_VPI_PORT)
 
 set _CHIPNAME riscv
 jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x10e31913
index 29fa1703efdd81f339e726a649e700bac4d77bf1..308bf2157619ceb09f33363a1acbf2ecbe9feb7d 100644 (file)
@@ -102,8 +102,11 @@ class VcsSim(object):
             line = listenfile.readline()
             if not line:
                 time.sleep(1)
-            if "Listening on port 5555" in line:
+            match = re.match(r"^Listening on port (\d+)$", line)
+            if match:
                 done = True
+                self.port = int(match.group(1))
+                print "Using port %d for JTAG VPI" % self.port
 
     def __del__(self):
         try:
@@ -137,11 +140,14 @@ class Openocd(object):
         # line, since they are executed in order.
         cmd[1:1] = ["--command", "gdb_port %d" % self.port]
 
+        env = os.environ.copy()
+        env['JTAG_VPI_PORT'] = str(otherProcess.port)
+
         logfile = open(Openocd.logname, "w")
         logfile.write("+ %s\n" % " ".join(cmd))
         logfile.flush()
         self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE,
-                stdout=logfile, stderr=logfile)
+                stdout=logfile, stderr=logfile, env=env)
 
         # Wait for OpenOCD to have made it through riscv_examine(). When using
         # OpenOCD to communicate with a simulator this may take a long time,