Pull in b2740d9 from Migen. nextpnr now default, write out build scripts on dry run.
authorWilliam D. Jones <thor0505@comcast.net>
Tue, 18 Sep 2018 01:17:24 +0000 (21:17 -0400)
committerWilliam D. Jones <thor0505@comcast.net>
Tue, 18 Sep 2018 01:17:24 +0000 (21:17 -0400)
litex/build/lattice/icestorm.py

index bc22992fafafd3ec9334d8ceaaa9746e7bc9efd7..4e281c4dc5c709d033f8311d730d9115251db209 100644 (file)
@@ -33,16 +33,14 @@ def _build_pcf(named_sc, named_pc):
     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 = ""
 
@@ -57,9 +55,16 @@ def _run_icestorm(source, build_template, build_name, pnr_pkg_opts,
     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")
 
 
@@ -88,7 +93,7 @@ class LatticeIceStormToolchain:
 
     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.
@@ -122,7 +127,7 @@ class LatticeIceStormToolchain:
 
     # 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)
@@ -149,23 +154,25 @@ class LatticeIceStormToolchain:
 
         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)