build/gowin: Minor cleanups.
This commit is contained in:
parent
756503ab92
commit
4fd974be10
|
@ -11,11 +11,13 @@ from shutil import which
|
||||||
|
|
||||||
from migen.fhdl.structure import _Fragment
|
from migen.fhdl.structure import _Fragment
|
||||||
|
|
||||||
from litex.build.generic_platform import Pins, IOStandard, Misc
|
from litex.build.generic_platform import *
|
||||||
from litex.build import tools
|
from litex.build import tools
|
||||||
|
|
||||||
|
# IO Constraints (.cst) ----------------------------------------------------------------------------
|
||||||
|
|
||||||
def _build_cst(named_sc, named_pc):
|
def _build_cst(named_sc, named_pc):
|
||||||
lines = []
|
cst = []
|
||||||
|
|
||||||
flat_sc = []
|
flat_sc = []
|
||||||
for name, pins, other, resource in named_sc:
|
for name, pins, other, resource in named_sc:
|
||||||
|
@ -27,41 +29,49 @@ def _build_cst(named_sc, named_pc):
|
||||||
|
|
||||||
for name, pin, other in flat_sc:
|
for name, pin, other in flat_sc:
|
||||||
if pin != "X":
|
if pin != "X":
|
||||||
lines.append(f"IO_LOC \"{name}\" {pin};")
|
cst.append(f"IO_LOC \"{name}\" {pin};")
|
||||||
|
|
||||||
for c in other:
|
for c in other:
|
||||||
if isinstance(c, IOStandard):
|
if isinstance(c, IOStandard):
|
||||||
lines.append(f"IO_PORT \"{name}\" IO_TYPE={c.name};")
|
cst.append(f"IO_PORT \"{name}\" IO_TYPE={c.name};")
|
||||||
elif isinstance(c, Misc):
|
elif isinstance(c, Misc):
|
||||||
lines.append(f"IO_PORT \"{name}\" {c.misc};")
|
cst.append(f"IO_PORT \"{name}\" {c.misc};")
|
||||||
|
|
||||||
if named_pc:
|
if named_pc:
|
||||||
lines.extend(named_pc)
|
cst.extend(named_pc)
|
||||||
|
|
||||||
cst = "\n".join(lines)
|
|
||||||
with open("top.cst", "w") as f:
|
with open("top.cst", "w") as f:
|
||||||
f.write(cst)
|
f.write("\n".join(cst))
|
||||||
|
|
||||||
def _build_script(name, partnumber, files, options):
|
# Script -------------------------------------------------------------------------------------------
|
||||||
lines = [
|
|
||||||
f"set_device -name {name} {partnumber}",
|
|
||||||
"add_file top.cst",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
def _build_tcl(name, partnumber, files, options):
|
||||||
|
tcl = []
|
||||||
|
|
||||||
|
# Set Device.
|
||||||
|
tcl.append(f"set_device -name {name} {partnumber}")
|
||||||
|
|
||||||
|
# Add IO Constraints.
|
||||||
|
tcl.append("add_file top.cst")
|
||||||
|
|
||||||
|
# Add Sources.
|
||||||
for f, typ, lib in files:
|
for f, typ, lib in files:
|
||||||
lines.append(f"add_file {f}")
|
tcl.append(f"add_file {f}")
|
||||||
|
|
||||||
|
# Set Options.
|
||||||
for opt, val in options.items():
|
for opt, val in options.items():
|
||||||
lines.append(f"set_option -{opt} {val}")
|
tcl.append(f"set_option -{opt} {val}")
|
||||||
|
|
||||||
lines.append("run all")
|
# Run.
|
||||||
|
tcl.append("run all")
|
||||||
|
|
||||||
tcl = "\n".join(lines)
|
# Generate .tcl.
|
||||||
with open("run.tcl", "w") as f:
|
with open("run.tcl", "w") as f:
|
||||||
f.write(tcl)
|
f.write("\n".join(tcl))
|
||||||
|
|
||||||
class GowinToolchain():
|
# GowinToolchain -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class GowinToolchain:
|
||||||
attr_translate = {
|
attr_translate = {
|
||||||
"keep": None,
|
"keep": None,
|
||||||
"no_retiming": None,
|
"no_retiming": None,
|
||||||
|
@ -83,7 +93,7 @@ class GowinToolchain():
|
||||||
run = True,
|
run = True,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
|
||||||
# Create build directory
|
# Create build directory.
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.makedirs(build_dir, exist_ok=True)
|
os.makedirs(build_dir, exist_ok=True)
|
||||||
os.chdir(build_dir)
|
os.chdir(build_dir)
|
||||||
|
@ -101,15 +111,15 @@ class GowinToolchain():
|
||||||
platform.add_source(v_file)
|
platform.add_source(v_file)
|
||||||
|
|
||||||
if platform.verilog_include_paths:
|
if platform.verilog_include_paths:
|
||||||
self.options['include_path'] = '{' + ';'.join(platform.verilog_include_paths) + '}'
|
self.options["include_path"] = "{" + ";".join(platform.verilog_include_paths) + "}"
|
||||||
|
|
||||||
# Generate constraints file (.cst)
|
# Generate constraints file (.cst)
|
||||||
_build_cst(
|
_build_cst(
|
||||||
named_sc = named_sc,
|
named_sc = named_sc,
|
||||||
named_pc = named_pc)
|
named_pc = named_pc)
|
||||||
|
|
||||||
# Generate TCL build script
|
# Generate build script (.tcl)
|
||||||
script = _build_script(
|
script = _build_tcl(
|
||||||
name = platform.devicename,
|
name = platform.devicename,
|
||||||
partnumber = platform.device,
|
partnumber = platform.device,
|
||||||
files = platform.sources,
|
files = platform.sources,
|
||||||
|
|
Loading…
Reference in New Issue