From e36df2a6fba27f67ab5a4abc2ac5dc76b90612a4 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 2 Jan 2020 10:23:05 +0100 Subject: [PATCH] build/lattice/icestorm: increase similarities with trellis. --- litex/build/lattice/icestorm.py | 36 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/litex/build/lattice/icestorm.py b/litex/build/lattice/icestorm.py index 9a6602610..51d6b6949 100644 --- a/litex/build/lattice/icestorm.py +++ b/litex/build/lattice/icestorm.py @@ -37,10 +37,10 @@ def _build_pre_pack(vns, clocks): # Yosys/Nextpnr Helpers/Templates ------------------------------------------------------------------ -yosys_template = [ +_yosys_template = [ "{read_files}", "attrmap -tocase keep -imap keep=\"true\" keep=1 -imap keep=\"false\" keep=0 -remove keep=0", - "synth_ice40 {synth_opts} -top {build_name} -json {build_name}.json", + "synth_ice40 {synth_opts} -json {build_name}.json -top {build_name}", ] def _yosys_import_sources(platform): @@ -76,24 +76,25 @@ def parse_device(device): "up5k": ["sg48", "uwg30"], } - (family, serie, package) = device.split("-") + (family, architecture, package) = device.split("-") if family not in ["ice40"]: raise ValueError("Unknown device family {}".format(family)) - if serie not in ["lp384", "lp1k", "hx1k", "lp8k", "hx8k", "up5k"]: - raise ValueError("Invalid device serie {}".format(serie)) - if package not in packages[serie]: + if architecture not in ["lp384", "lp1k", "hx1k", "lp8k", "hx8k", "up5k"]: + raise ValueError("Invalid device architecture {}".format(architecture)) + if package not in packages[architecture]: raise ValueError("Invalid device package {}".format(package)) - return (family, serie, package) + return (family, architecture, package) # Script ------------------------------------------------------------------------------------------- -build_template = [ +_build_template = [ "yosys -q -l {build_name}.rpt {build_name}.ys", - "nextpnr-ice40 {pnr_pkg_opts} --pcf {build_name}.pcf --json {build_name}.json --asc {build_name}.txt --pre-pack {build_name}_pre_pack.py", + "nextpnr-ice40 --json {build_name}.json --pcf {build_name}.pcf --asc {build_name}.txt \ + --pre-pack {build_name}_pre_pack.py --{architecture} --package {package}", "icepack {build_name}.txt {build_name}.bin" ] -def _build_script(build_template, build_name, **kwargs): +def _build_script(build_template, build_name, architecture, package): if sys.platform in ("win32", "cygwin"): script_ext = ".bat" build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n" @@ -105,7 +106,11 @@ def _build_script(build_template, build_name, **kwargs): for s in build_template: s_fail = s + "{fail_stmt}\n" # Required so Windows scripts fail early. - build_script_contents += s_fail.format(build_name=build_name, fail_stmt=fail_stmt, **kwargs) + build_script_contents += s_fail.format( + build_name = build_name, + architecture = architecture, + package = package, + fail_stmt = fail_stmt) build_script_file = "build_" + build_name + script_ext tools.write_to_file(build_script_file, build_script_contents,force_unix=False) @@ -139,8 +144,8 @@ class LatticeIceStormToolchain: special_overrides = common.lattice_ice40_special_overrides def __init__(self): - self.yosys_template = yosys_template - self.build_template = build_template + self.yosys_template = _yosys_template + self.build_template = _build_template self.clocks = dict() def build(self, platform, fragment, @@ -178,11 +183,10 @@ class LatticeIceStormToolchain: _build_yosys(self.yosys_template, platform, build_name, synth_opts=synth_opts) # Translate device to Nextpnr architecture/package - (family, serie, package) = parse_device(platform.device) - pnr_pkg_opts = "--" + serie + " --package " + package + (family, architecture, package) = parse_device(platform.device) # Generate build script - script = _build_script(self.build_template, build_name, pnr_pkg_opts=pnr_pkg_opts) + script = _build_script(self.build_template, build_name, architecture, package) # Run if run: