Skip to content

Commit

Permalink
build/lattice/icestorm: increase similarities with trellis.
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoy-digital committed Jan 2, 2020
1 parent 197edad commit e36df2a
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions litex/build/lattice/icestorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -178,11 +183,10 @@ def build(self, platform, fragment,
_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:
Expand Down

0 comments on commit e36df2a

Please sign in to comment.