From: Sebastien Bourdeauducq Date: Fri, 8 Feb 2013 21:23:58 +0000 (+0100) Subject: Support for command line arguments X-Git-Tag: 24jan2021_ls180~2099^2~443^2~74 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f13ad035e14b46b4098d93b621a6362d10472b98;p=litex.git Support for command line arguments --- diff --git a/mibuild/generic_platform.py b/mibuild/generic_platform.py index b78f2a4c..2f8fd4ae 100644 --- a/mibuild/generic_platform.py +++ b/mibuild/generic_platform.py @@ -1,5 +1,5 @@ from copy import copy -import os +import os, argparse from migen.fhdl.structure import * from migen.corelogic.record import Record @@ -228,3 +228,15 @@ class GenericPlatform: 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) diff --git a/mibuild/xilinx_ise.py b/mibuild/xilinx_ise.py index 0d887bec..4012ca40 100644 --- a/mibuild/xilinx_ise.py +++ b/mibuild/xilinx_ise.py @@ -78,17 +78,17 @@ def _build_files(device, sources, named_sc, named_pc, build_name): -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 @@ -110,7 +110,7 @@ bitgen -g Binary:Yes -w {build_name}-routed.ncd {build_name}.bit 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) @@ -120,6 +120,18 @@ class XilinxISEPlatform(GenericPlatform): 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")