Add Diamond toolchain support for Linux.
authorSergiusz Bazanski <q3k@q3k.org>
Thu, 20 Jul 2017 12:21:10 +0000 (13:21 +0100)
committerSergiusz Bazanski <q3k@q3k.org>
Thu, 20 Jul 2017 12:21:10 +0000 (13:21 +0100)
This tries to replicate the same setup as in the Windows buildsystem. We
also remove the Jedecgen step, as it doesn't seem to be supported nor
necessary in newer versions of Diamond.

litex/build/lattice/diamond.py
litex/build/lattice/programmer.py

index fad525f3b2735c93d4bfe1962e484668c49737eb..582d24bcfe4435337a1aaf1bc1e7edfe44d9b1b0 100644 (file)
@@ -56,19 +56,31 @@ def _build_files(device, sources, vincpaths, build_name):
     tcl.append("prj_run Map -impl implementation")
     tcl.append("prj_run PAR -impl implementation")
     tcl.append("prj_run Export -impl implementation -task Bitgen")
-    tcl.append("prj_run Export -impl implementation -task Jedecgen")
     tools.write_to_file(build_name + ".tcl", "\n".join(tcl))
 
 
-def _run_diamond(build_name, source, ver=None):
+def _run_diamond(build_name, toolchain_path, ver=None):
     if sys.platform == "win32" or sys.platform == "cygwin":
         build_script_contents = "REM Autogenerated by LiteX\n"
-        build_script_contents = "pnmainc " + build_name + ".tcl\n"
+        build_script_contents += "pnmainc " + build_name + ".tcl\n"
         build_script_file = "build_" + build_name + ".bat"
         tools.write_to_file(build_script_file, build_script_contents)
         r = subprocess.call([build_script_file])
         shutil.copy(os.path.join("implementation", build_name + "_implementation.bit"), build_name + ".bit")
         shutil.copy(os.path.join("implementation", build_name + "_implementation.jed"), build_name + ".jed")
+    elif sys.platform == "linux":
+        bindir = os.path.join(toolchain_path, 'bin/lin64')
+        envfile = os.path.join(bindir, 'diamond_env')
+        build_script_contents = "# Autogenerated by LiteX\n"
+        build_script_contents += "set -e\n"
+        build_script_contents += "bindir='{}/'\n".format(bindir)
+        build_script_contents += "source {}\n".format(envfile)
+        build_script_contents += "diamondc {}.tcl | tee build.log\n".format(build_name)
+        build_script_file = "build_{}.sh".format(build_name)
+
+        tools.write_to_file(build_script_file, build_script_contents)
+        r = subprocess.call(['/bin/sh', build_script_file])
+        shutil.copy(os.path.join("implementation", build_name + "_implementation.bit"), build_name + ".bit")
     else:
         raise NotImplementedError
 
index a34af86b38f4f86bd947312ad1052c12ce8fac10..0923a65c2deb1cd59eb03555d2794fcb8bf530ba 100644 (file)
@@ -11,8 +11,12 @@ class LatticeProgrammer(GenericProgrammer):
     def __init__(self, xcf_template):
         self.xcf_template = xcf_template
 
-    def load_bitstream(self, bitstream_file):
+    def load_bitstream(self, bitstream_file, toolchain_path=''):
         xcf_file = bitstream_file.replace(".bit", ".xcf")
         xcf_content = self.xcf_template.format(bitstream_file=bitstream_file)
         tools.write_to_file(xcf_file, xcf_content)
-        subprocess.call(["pgrcmd", "-infile", xcf_file])
+        if toolchain_path:
+            pgrcmd = os.path.join(toolchain_path, 'bin/lin64/pgrcmd')
+        else:
+            pgrcmr = 'pgrcmr'
+        subprocess.call([pgrcmd, "-infile", xcf_file])