from copy import copy
-import os
+import os, argparse
from migen.fhdl.structure import *
from migen.corelogic.record import Record
def build(self, fragment, clock_domains=None):
raise NotImplementedError("GenericPlatform.build must be overloaded")
+
+ def add_arguments(self, parser):
+ pass # default: no arguments
+
+ def build_arg_ns(self, ns, *args, **kwargs):
+ self.build(*args, **kwargs)
+
+ def build_cmdline(self, *args, **kwargs):
+ parser = argparse.ArgumentParser(description="FPGA bitstream build system")
+ self.add_arguments(parser)
+ ns = parser.parse_args()
+ self.build_arg_ns(ns, *args, **kwargs)
-p %s""" % (build_name, build_name, device)
tools.write_to_file(build_name + ".xst", xst_contents)
-def _run_ise(build_name, xilinx_install_path):
+def _run_ise(build_name, ise_path):
def is_valid_version(v):
try:
Decimal(v)
- return os.path.isdir(os.path.join(xilinx_install_path, v))
+ return os.path.isdir(os.path.join(ise_path, v))
except:
return False
- vers = [ver for ver in os.listdir(xilinx_install_path) if is_valid_version(ver)]
+ vers = [ver for ver in os.listdir(ise_path) if is_valid_version(ver)]
tools_version = max(vers)
bits = struct.calcsize("P")*8
- xilinx_settings_file = '%s/%s/ISE_DS/settings%d.sh' % (xilinx_install_path, tools_version, bits)
+ xilinx_settings_file = '%s/%s/ISE_DS/settings%d.sh' % (ise_path, tools_version, bits)
build_script_contents = """# Autogenerated by mibuild
class XilinxISEPlatform(GenericPlatform):
def build(self, fragment, clock_domains=None, build_dir="build", build_name="top",
- xilinx_install_path="/opt/Xilinx", run=True):
+ ise_path="/opt/Xilinx", run=True):
tools.mkdir_noerror(build_dir)
os.chdir(build_dir)
sources = self.sources + [(v_file, "verilog")]
_build_files(self.device, sources, named_sc, named_pc, build_name)
if run:
- _run_ise(build_name, xilinx_install_path)
+ _run_ise(build_name, ise_path)
os.chdir("..")
+
+ def build_arg_ns(self, ns, *args, **kwargs):
+ for n in ["build_dir", "build_name", "ise_path"]:
+ kwargs[n] = getattr(ns, n)
+ kwargs["run"] = not ns.no_run
+ self.build(*args, **kwargs)
+
+ def add_arguments(self, parser):
+ parser.add_argument("--build-dir", default="build", help="Set the directory in which to generate files and run ISE")
+ parser.add_argument("--build-name", default="top", help="Base name for the generated files")
+ parser.add_argument("--ise-path", default="/opt/Xilinx", help="ISE installation path (without version directory)")
+ parser.add_argument("--no-run", action="store_true", help="Only generate files, do not run ISE")