return r
-def _run_icestorm(source, build_template, build_name, pnr_pkg_opts,
+def _build_script(source, build_template, build_name, pnr_pkg_opts,
icetime_pkg_opts, freq_constraint):
- if sys.platform == "win32" or sys.platform == "cygwin":
+ if sys.platform in ("win32", "cygwin"):
script_ext = ".bat"
- shell = ["cmd", "/c"]
build_script_contents = "@echo off\nrem Autogenerated by LiteX\n"
fail_stmt = " || exit /b"
else:
script_ext = ".sh"
- shell = ["bash"]
build_script_contents = "# Autogenerated by LiteX\nset -e\n"
fail_stmt = ""
build_script_file = "build_" + build_name + script_ext
tools.write_to_file(build_script_file, build_script_contents,
force_unix=False)
- command = shell + [build_script_file]
- r = subprocess.call(command)
- if r != 0:
+ return build_script_file
+
+
+def _run_script(script):
+ if sys.platform in ("win32", "cygwin"):
+ shell = ["cmd", "/c"]
+ else:
+ shell = ["bash"]
+
+ if subprocess.call(shell + [script]) != 0:
raise OSError("Subprocess failed")
special_overrides = common.icestorm_special_overrides
- def __init__(self, use_nextpnr=False):
+ def __init__(self):
# Variables within replacement fields should be backend-aware and
# update their syntax accordingly. Currently, only {pnr_pkg_opts}
# needs this functionality.
# platform.device should be of the form "ice40-{lp384, hx1k, etc}-{tq144, etc}"
def build(self, platform, fragment, build_dir="build", build_name="top",
- toolchain_path=None, use_nextpnr=False, run=True):
+ toolchain_path=None, use_nextpnr=True, run=True):
os.makedirs(build_dir, exist_ok=True)
cwd = os.getcwd()
os.chdir(build_dir)
tools.write_to_file(build_name + ".pcf",
_build_pcf(named_sc, named_pc))
+ (family, series_size, package) = self.parse_device_string(platform.device)
+ if use_nextpnr:
+ pnr_pkg_opts = "--" + series_size + " --package " + package
+ else:
+ pnr_pkg_opts = "-d " + self.get_size_string(series_size) + \
+ " -P " + package
+ icetime_pkg_opts = "-P " + package + " -d " + series_size
+ freq_constraint = str(max(self.freq_constraints.values(),
+ default=0.0))
+
+ if use_nextpnr:
+ chosen_build_template = self.nextpnr_build_template
+ else:
+ chosen_build_template = self.build_template
+ script = _build_script(False, chosen_build_template, build_name,
+ pnr_pkg_opts, icetime_pkg_opts, freq_constraint)
+
if run:
- (family, series_size, package) = self.parse_device_string(platform.device)
- if use_nextpnr:
- pnr_pkg_opts = "--" + series_size + " --package " + package
- else:
- pnr_pkg_opts = "-d " + self.get_size_string(series_size) + \
- " -P " + package
- icetime_pkg_opts = "-P " + package + " -d " + series_size
- freq_constraint = str(max(self.freq_constraints.values(),
- default=0.0))
-
- if use_nextpnr:
- chosen_build_template = self.nextpnr_build_template
- else:
- chosen_build_template = self.build_template
- _run_icestorm(False, chosen_build_template, build_name,
- pnr_pkg_opts, icetime_pkg_opts, freq_constraint)
+ _run_script(script)
os.chdir(cwd)