build/lattice/icestorm: increase similarities with trellis.
This commit is contained in:
parent
197edad34e
commit
e36df2a6fb
|
@ -37,10 +37,10 @@ def _build_pre_pack(vns, clocks):
|
||||||
|
|
||||||
# Yosys/Nextpnr Helpers/Templates ------------------------------------------------------------------
|
# Yosys/Nextpnr Helpers/Templates ------------------------------------------------------------------
|
||||||
|
|
||||||
yosys_template = [
|
_yosys_template = [
|
||||||
"{read_files}",
|
"{read_files}",
|
||||||
"attrmap -tocase keep -imap keep=\"true\" keep=1 -imap keep=\"false\" keep=0 -remove keep=0",
|
"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):
|
def _yosys_import_sources(platform):
|
||||||
|
@ -76,24 +76,25 @@ def parse_device(device):
|
||||||
"up5k": ["sg48", "uwg30"],
|
"up5k": ["sg48", "uwg30"],
|
||||||
}
|
}
|
||||||
|
|
||||||
(family, serie, package) = device.split("-")
|
(family, architecture, package) = device.split("-")
|
||||||
if family not in ["ice40"]:
|
if family not in ["ice40"]:
|
||||||
raise ValueError("Unknown device family {}".format(family))
|
raise ValueError("Unknown device family {}".format(family))
|
||||||
if serie not in ["lp384", "lp1k", "hx1k", "lp8k", "hx8k", "up5k"]:
|
if architecture not in ["lp384", "lp1k", "hx1k", "lp8k", "hx8k", "up5k"]:
|
||||||
raise ValueError("Invalid device serie {}".format(serie))
|
raise ValueError("Invalid device architecture {}".format(architecture))
|
||||||
if package not in packages[serie]:
|
if package not in packages[architecture]:
|
||||||
raise ValueError("Invalid device package {}".format(package))
|
raise ValueError("Invalid device package {}".format(package))
|
||||||
return (family, serie, package)
|
return (family, architecture, package)
|
||||||
|
|
||||||
# Script -------------------------------------------------------------------------------------------
|
# Script -------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
build_template = [
|
_build_template = [
|
||||||
"yosys -q -l {build_name}.rpt {build_name}.ys",
|
"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"
|
"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"):
|
if sys.platform in ("win32", "cygwin"):
|
||||||
script_ext = ".bat"
|
script_ext = ".bat"
|
||||||
build_script_contents = "@echo off\nrem Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n\n"
|
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:
|
for s in build_template:
|
||||||
s_fail = s + "{fail_stmt}\n" # Required so Windows scripts fail early.
|
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
|
build_script_file = "build_" + build_name + script_ext
|
||||||
tools.write_to_file(build_script_file, build_script_contents,force_unix=False)
|
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
|
special_overrides = common.lattice_ice40_special_overrides
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.yosys_template = yosys_template
|
self.yosys_template = _yosys_template
|
||||||
self.build_template = build_template
|
self.build_template = _build_template
|
||||||
self.clocks = dict()
|
self.clocks = dict()
|
||||||
|
|
||||||
def build(self, platform, fragment,
|
def build(self, platform, fragment,
|
||||||
|
@ -178,11 +183,10 @@ class LatticeIceStormToolchain:
|
||||||
_build_yosys(self.yosys_template, platform, build_name, synth_opts=synth_opts)
|
_build_yosys(self.yosys_template, platform, build_name, synth_opts=synth_opts)
|
||||||
|
|
||||||
# Translate device to Nextpnr architecture/package
|
# Translate device to Nextpnr architecture/package
|
||||||
(family, serie, package) = parse_device(platform.device)
|
(family, architecture, package) = parse_device(platform.device)
|
||||||
pnr_pkg_opts = "--" + serie + " --package " + package
|
|
||||||
|
|
||||||
# Generate build script
|
# 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
|
# Run
|
||||||
if run:
|
if run:
|
||||||
|
|
Loading…
Reference in New Issue