mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
Support for command line arguments
This commit is contained in:
parent
b092237fa6
commit
f13ad035e1
2 changed files with 31 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
from copy import copy
|
from copy import copy
|
||||||
import os
|
import os, argparse
|
||||||
|
|
||||||
from migen.fhdl.structure import *
|
from migen.fhdl.structure import *
|
||||||
from migen.corelogic.record import Record
|
from migen.corelogic.record import Record
|
||||||
|
@ -228,3 +228,15 @@ class GenericPlatform:
|
||||||
|
|
||||||
def build(self, fragment, clock_domains=None):
|
def build(self, fragment, clock_domains=None):
|
||||||
raise NotImplementedError("GenericPlatform.build must be overloaded")
|
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)
|
||||||
|
|
|
@ -78,17 +78,17 @@ def _build_files(device, sources, named_sc, named_pc, build_name):
|
||||||
-p %s""" % (build_name, build_name, device)
|
-p %s""" % (build_name, build_name, device)
|
||||||
tools.write_to_file(build_name + ".xst", xst_contents)
|
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):
|
def is_valid_version(v):
|
||||||
try:
|
try:
|
||||||
Decimal(v)
|
Decimal(v)
|
||||||
return os.path.isdir(os.path.join(xilinx_install_path, v))
|
return os.path.isdir(os.path.join(ise_path, v))
|
||||||
except:
|
except:
|
||||||
return False
|
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)
|
tools_version = max(vers)
|
||||||
bits = struct.calcsize("P")*8
|
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
|
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):
|
class XilinxISEPlatform(GenericPlatform):
|
||||||
def build(self, fragment, clock_domains=None, build_dir="build", build_name="top",
|
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)
|
tools.mkdir_noerror(build_dir)
|
||||||
os.chdir(build_dir)
|
os.chdir(build_dir)
|
||||||
|
|
||||||
|
@ -120,6 +120,18 @@ class XilinxISEPlatform(GenericPlatform):
|
||||||
sources = self.sources + [(v_file, "verilog")]
|
sources = self.sources + [(v_file, "verilog")]
|
||||||
_build_files(self.device, sources, named_sc, named_pc, build_name)
|
_build_files(self.device, sources, named_sc, named_pc, build_name)
|
||||||
if run:
|
if run:
|
||||||
_run_ise(build_name, xilinx_install_path)
|
_run_ise(build_name, ise_path)
|
||||||
|
|
||||||
os.chdir("..")
|
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")
|
||||||
|
|
Loading…
Reference in a new issue