From 503df5e93e3fe3fc3c115e4f8933e976ed4b23bd Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Thu, 20 Jul 2017 13:21:10 +0100 Subject: [PATCH] Add Diamond toolchain support for Linux. 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 | 18 +++++++++++++++--- litex/build/lattice/programmer.py | 8 ++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/litex/build/lattice/diamond.py b/litex/build/lattice/diamond.py index fad525f3b..582d24bcf 100644 --- a/litex/build/lattice/diamond.py +++ b/litex/build/lattice/diamond.py @@ -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 diff --git a/litex/build/lattice/programmer.py b/litex/build/lattice/programmer.py index a34af86b3..0923a65c2 100644 --- a/litex/build/lattice/programmer.py +++ b/litex/build/lattice/programmer.py @@ -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])