Automatic sourcing was not consistent between build backends (and only really supported by ISE/Vivado)
and had no real additional value vs the complexity needed to support it. Now just assume required vendor
tools are in the PATH.
This also removes distutils dependency.
# Script -------------------------------------------------------------------------------------------
-def _build_script(build_name, quartus_path, create_rbf):
+def _build_script(build_name, create_rbf):
if sys.platform in ["win32", "cygwin"]:
script_contents = "REM Autogenerated by LiteX / git: " + tools.get_litex_git_revision()
script_file = "build_" + build_name + ".bat"
def build(self, platform, fragment,
build_dir = "build",
build_name = "top",
- toolchain_path = None,
run = True,
**kwargs):
- # Get default toolchain path (if not specified)
- if toolchain_path is None:
- toolchain_path = "/opt/Altera"
-
# Create build directory
cwd = os.getcwd()
os.makedirs(build_dir, exist_ok=True)
additional_qsf_commands = self.additional_qsf_commands)
# Generate build script
- script = _build_script(build_name, toolchain_path, platform.create_rbf)
+ script = _build_script(build_name, platform.create_rbf)
# Run
if run:
# Script -------------------------------------------------------------------------------------------
-def _build_script(build_name, device, toolchain_path, ver=None):
+def _build_script(build_name, device):
if sys.platform in ("win32", "cygwin"):
script_ext = ".bat"
script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
copy_stmt = "cp"
fail_stmt = ""
- if sys.platform not in ("win32", "cygwin"):
- script_contents += "bindir={}\n".format(toolchain_path)
- script_contents += ". ${{bindir}}/diamond_env{fail_stmt}\n".format(fail_stmt=fail_stmt)
- script_contents += "{pnmainc} {tcl_script}{fail_stmt}\n".format(
- pnmainc = os.path.join(toolchain_path, "pnmainc"),
+ script_contents += "pnmainc {tcl_script}{fail_stmt}\n".format(
tcl_script = build_name + ".tcl",
fail_stmt = fail_stmt)
for ext in (".bit", ".jed"):
def build(self, platform, fragment,
build_dir = "build",
build_name = "top",
- toolchain_path = None,
run = True,
**kwargs):
# Create build directory
- if toolchain_path is None:
- toolchain_path = "/opt/Diamond"
os.makedirs(build_dir, exist_ok=True)
cwd = os.getcwd()
os.chdir(build_dir)
_build_tcl(platform.device, platform.sources, platform.verilog_include_paths, build_name)
# Generate build script
- script = _build_script(build_name, platform.device, toolchain_path)
+ script = _build_script(build_name, platform.device)
# Run
if run:
def build(self, platform, fragment,
build_dir = "build",
build_name = "top",
- toolchain_path = None,
synth_opts = "",
run = True,
**kwargs):
def build(self, platform, fragment,
build_dir = "build",
build_name = "top",
- toolchain_path = None,
run = True,
nowidelut = False,
timingstrict = False,
ignoreloops = False,
**kwargs):
- # Get default toolchain path (if not specified)
- if toolchain_path is None:
- toolchain_path = "/usr/share/trellis/"
-
# Create build directory
os.makedirs(build_dir, exist_ok=True)
cwd = os.getcwd()
# Script -------------------------------------------------------------------------------------------
-def _build_script(build_name, device, toolchain_path, ver=None):
+def _build_script(build_name, device):
if sys.platform in ("win32", "cygwin"):
script_ext = ".bat"
script_contents = "@echo off\nREM Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
def build(self, platform, fragment,
build_dir = "build",
build_name = "top",
- toolchain_path = None,
run = False,
**kwargs):
self.additional_timing_constraints)
# Generate build script
- script = _build_script(build_name, platform.device, toolchain_path)
+ script = _build_script(build_name, platform.device)
# Run
if run:
class SimVerilatorToolchain:
def build(self, platform, fragment, build_dir="build", build_name="dut",
- toolchain_path=None, serial="console", build=True, run=True, threads=1,
+ serial="console", build=True, run=True, threads=1,
verbose=True, sim_config=None, coverage=False, opt_level="O0",
trace=False, trace_fst=False, trace_start=0, trace_end=-1):
import os
import struct
-from distutils.version import StrictVersion
import re
import subprocess
import sys
f.write(contents)
-def arch_bits():
- return struct.calcsize("P")*8
-
-
-def versions(path):
- for n in os.listdir(path):
- full = os.path.join(path, n)
- if not os.path.isdir(full):
- continue
- try:
- yield StrictVersion(n)
- except ValueError:
- continue
-
-
def sub_rules(line, rules, max_matches=1):
for pattern, color in rules:
line, matches = re.subn(pattern, color, line, max_matches)
r"\g<0>" + colorama.Style.RESET_ALL),
]
-# Settings -----------------------------------------------------------------------------------------
-
-def settings(path, ver=None, sub=None):
- if ver is None:
- vers = list(tools.versions(path))
- if not vers:
- raise OSError("no version directory for Xilinx tools found in "
- + path)
- ver = max(vers)
-
- full = os.path.join(path, str(ver))
- if sub:
- full = os.path.join(full, sub)
-
- search = [64, 32]
- if tools.arch_bits() == 32:
- search.reverse()
-
- if sys.platform == "win32" or sys.platform == "cygwin":
- script_ext = "bat"
- else:
- script_ext = "sh"
-
- for b in search:
- settings = os.path.join(full, "settings{0}.{1}".format(b, script_ext))
- if os.path.exists(settings):
- return settings
-
- raise OSError("no Xilinx tools settings file found")
-
# Common MultiReg ----------------------------------------------------------------------------------
class XilinxMultiRegImpl(MultiRegImpl):
# ISE Run ------------------------------------------------------------------------------------------
-def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
- toolchain, platform, ver=None):
+def _run_ise(build_name, mode, ngdbuild_opt, toolchain, platform):
if sys.platform == "win32" or sys.platform == "cygwin":
- source_cmd = "call "
script_ext = ".bat"
shell = ["cmd", "/c"]
build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n"
fail_stmt = " || exit /b"
else:
- source_cmd = "source "
script_ext = ".sh"
shell = ["bash"]
build_script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\nset -e\n"
fail_stmt = ""
- if source:
- settings = common.settings(ise_path, ver, "ISE_DS")
- build_script_contents += source_cmd + tools.cygpath(settings) + "\n"
if mode == "edif":
ext = "ngo"
build_script_contents += """
def build(self, platform, fragment,
build_dir = "build",
build_name = "top",
- toolchain_path = None,
- source = True,
run = True,
mode = "xst",
**kwargs):
- # Get default toolchain path (if not specified)
- if toolchain_path is None:
- if sys.platform == "win32":
- toolchain_path = "C:\\Xilinx"
- elif sys.platform == "cygwin":
- toolchain_path = "/cygdrive/c/Xilinx"
- else:
- toolchain_path = "/opt/Xilinx"
-
# Create build directory
os.makedirs(build_dir, exist_ok=True)
cwd = os.getcwd()
# Run ISE
if run:
- _run_ise(build_name, toolchain_path, source, isemode, self.ngdbuild_opt, self, platform)
+ _run_ise(build_name, isemode, self.ngdbuild_opt, self, platform)
finally:
os.chdir(cwd)
import os
import sys
import subprocess
-from distutils.spawn import find_executable
from litex.build.generic_programmer import GenericProgrammer
from litex.build.xilinx import common
# Vivado -------------------------------------------------------------------------------------------
def _run_vivado(path, ver, cmds):
- if sys.platform == "win32" or sys.platform == "cygwin":
- vivado_cmd = "vivado -mode tcl"
- else:
- vivado_cmd = ""
- if not find_executable("vivado"):
- # For backwards compatibility with ISE paths, also
- # look for a version in a subdirectory named "Vivado"
- # under the current directory.
- paths_to_try = [path, os.path.join(path, "Vivado")]
- for p in paths_to_try:
- try:
- settings = common.settings(p, ver)
- except OSError:
- continue
- break
- else:
- raise OSError("Unable to locate Vivado directory or settings.")
- vivado_cmd += "source " + settings + " && "
- vivado_cmd += "vivado -mode tcl"
+ vivado_cmd = "vivado -mode tcl"
with subprocess.Popen(vivado_cmd, stdin=subprocess.PIPE, shell=True) as process:
process.stdin.write(cmds.encode("ASCII"))
process.communicate()
import subprocess
import sys
import math
-from distutils.spawn import find_executable
from migen.fhdl.structure import _Fragment
# Script -------------------------------------------------------------------------------------------
-def _build_script(build_name, vivado_path, source, ver=None):
+def _build_script(build_name):
if sys.platform in ["win32", "cygwin"]:
script_contents = "REM Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n"
script_contents += "vivado -mode batch -source " + build_name + ".tcl\n"
tools.write_to_file(script_file, script_contents)
else:
script_contents = "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\nset -e\n"
- # Only source Vivado settings if not already in our $PATH
- if not find_executable("vivado"):
- # For backwards compatibility with ISE paths, also
- # look for a version in a subdirectory named "Vivado"
- # under the current directory.
- paths_to_try = [vivado_path, os.path.join(vivado_path, "Vivado")]
- for p in paths_to_try:
- try:
- settings = common.settings(p, ver)
- except OSError:
- continue
- break
- else:
- raise OSError("Unable to locate Vivado directory or settings.")
- script_contents += "source " + settings + "\n"
-
script_contents += "vivado -mode batch -source " + build_name + ".tcl\n"
script_file = "build_" + build_name + ".sh"
tools.write_to_file(script_file, script_contents)
)
def build(self, platform, fragment,
- build_dir = "build",
- build_name = "top",
- toolchain_path = None,
- source = True, run=True,
- synth_mode = "vivado",
- enable_xpm = False,
+ build_dir = "build",
+ build_name = "top",
+ run = True,
+ synth_mode = "vivado",
+ enable_xpm = False,
**kwargs):
- # Get default toolchain path (if not specified)
- if toolchain_path is None:
- toolchain_path = "/opt/Xilinx/Vivado"
-
# Create build directory
os.makedirs(build_dir, exist_ok=True)
cwd = os.getcwd()
if run:
if synth_mode == "yosys":
common._run_yosys(platform.device, platform.sources, platform.verilog_include_paths, build_name)
- script = _build_script(build_name, toolchain_path, source)
+ script = _build_script(build_name)
_run_script(script)
os.chdir(cwd)
generated_dir = None,
compile_software = True,
compile_gateware = True,
- gateware_toolchain_path = None,
csr_json = None,
csr_csv = None):
self.soc = soc
self.compile_software = compile_software
self.compile_gateware = compile_gateware
- self.gateware_toolchain_path = gateware_toolchain_path
self.csr_csv = csr_csv
self.csr_json = csr_json
bios_data = soc_core.get_mem_data(bios_file, self.soc.cpu.endianness)
self.soc.initialize_rom(bios_data)
- def build(self, toolchain_path=None, **kwargs):
+ def build(self, **kwargs):
self.soc.platform.output_dir = self.output_dir
os.makedirs(self.gateware_dir, exist_ok=True)
os.makedirs(self.software_dir, exist_ok=True)
self._generate_csr_map(self.csr_json, self.csr_csv)
- if self.gateware_toolchain_path is not None:
- toolchain_path = self.gateware_toolchain_path
-
if "run" not in kwargs:
kwargs["run"] = self.compile_gateware
- vns = self.soc.build(build_dir=self.gateware_dir,
- toolchain_path=toolchain_path, **kwargs)
+ vns = self.soc.build(build_dir=self.gateware_dir, **kwargs)
self.soc.do_exit(vns=vns)
return vns
parser.add_argument("--no-compile-gateware", action="store_true",
help="do not compile the gateware, only generate "
"HDL source files and build scripts")
- parser.add_argument("--gateware-toolchain-path", default=None,
- help="set gateware toolchain (ISE, Quartus, etc.) "
- "installation path")
parser.add_argument("--csr-csv", default=None,
help="store CSR map in CSV format into the "
"specified file")
"generated_dir": args.generated_dir,
"compile_software": not args.no_compile_software,
"compile_gateware": not args.no_compile_gateware,
- "gateware_toolchain_path": args.gateware_toolchain_path,
"csr_csv": args.csr_csv,
"csr_json": args.csr_json,
}