Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nextpnr: Support interchange format and write a Makefile #120

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions edalize/nextpnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ def configure_main(self):
cst_file = ""
lpf_file = ""
pcf_file = ""
xdc_file = ""
pdc_file = ""
qsf_file = ""
netlist = ""
unused_files = []

arch = self.tool_options["arch"]
is_interchange = arch == "fpga_interchange"
chipdb = self.tool_options.get("chipdb")
if is_interchange and (chipdb is None):
raise RuntimeError(
"Nextpnr-fpga_interchange require chipdb to be specified."
)
package = self.tool_options.get("package")

for f in self.files:
if f["file_type"] == "CST":
if cst_file:
Expand Down Expand Up @@ -65,6 +76,14 @@ def configure_main(self):
)
)
pcf_file = f["name"]
elif f["file_type"] == "XDC":
if xdc_file:
raise RuntimeError(
"Nextpnr only supports one XDC file. Found {} and {}".format(
xdc_file, f["name"]
)
)
xdc_file = f["name"]
if f["file_type"] == "QSF":
if qsf_file:
raise RuntimeError(
Expand All @@ -80,6 +99,26 @@ def configure_main(self):
netlist, f["name"]
)
)
if is_interchange:
raise RuntimeError(
"Nextpnr-fpga_interchange requires fpga-interchange logical netlist instead of JSON, found{}".format(
f["name"]
)
)
netlist = f["name"]
elif f["file_type"] == "fpgaInterchangeNetlist":
if netlist:
raise RuntimeError(
"Nextpnr only supports one netlist. Found {} and {}".format(
netlist, f["name"]
)
)
if not is_interchange:
raise RuntimeError(
"Non-interchange variants of Nextpnr require JSON netlist, found{}".format(
f["name"]
)
)
netlist = f["name"]
else:
unused_files.append(f)
Expand All @@ -93,7 +132,6 @@ def configure_main(self):
# Write Makefile
commands = EdaCommands()

arch = self.flow_config["arch"]
arch_options = []
if arch == "ecp5":
targets = self.name + ".config"
Expand Down Expand Up @@ -125,19 +163,33 @@ def configure_main(self):
targets = self.name + ".pack"
constraints = ["--cst", cst_file] if cst_file else []
output = ["--write", targets]
elif arch == "fpga_interchange":
targets = self.name + ".phys"
constraints = ["--xdc", xdc_file]
output = ["--phys", targets]
else:
targets = self.name + ".asc"
constraints = ["--pcf", pcf_file] if pcf_file else []
output = ["--asc", targets]

depends = netlist
command = ["nextpnr-" + arch, "-l", "next.log"]
command = ["nextpnr-" + arch]
command += arch_options + self.tool_options.get("nextpnr_options", [])
command += constraints + ["--json", depends] + output
command += constraints
if is_interchange:
command += ["--netlist", depends, "--chipdb", chipdb]
else:
command += ["--json", depends]
if package is not None:
command += ["--package", package]
command += output

# CLI target
commands.add(command, [targets], [depends])

# GUI target
commands.add(command + ["--gui"], ["build-gui"], [depends])
self.commands = commands.commands

commands.set_default_target(targets)
commands.write(os.path.join(self.work_root, "Makefile"))
49 changes: 45 additions & 4 deletions edalize/tools/nextpnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ def configure(self, edam):
cst_file = ""
lpf_file = ""
pcf_file = ""
xdc_file = ""
netlist = ""
unused_files = []

arch = self.tool_options["arch"]

is_interchange = arch == "fpga_interchange"

for f in self.files:
file_type = f.get("file_type", "")
if file_type == "CST":
Expand All @@ -38,29 +44,56 @@ def configure(self, edam):
)
)
cst_file = f["name"]
if file_type == "LPF":
elif file_type == "LPF":
if lpf_file:
raise RuntimeError(
"Nextpnr only supports one LPF file. Found {} and {}".format(
pcf_file, f["name"]
)
)
lpf_file = f["name"]
if file_type == "PCF":
elif file_type == "PCF":
if pcf_file:
raise RuntimeError(
"Nextpnr only supports one PCF file. Found {} and {}".format(
pcf_file, f["name"]
)
)
pcf_file = f["name"]
elif file_type == "XDC":
if xdc_file:
raise RuntimeError(
"Nextpnr only supports one XDC file. Found {} and {}".format(
xdc_file, f["name"]
)
)
elif file_type == "jsonNetlist":
if netlist:
raise RuntimeError(
"Nextpnr only supports one netlist. Found {} and {}".format(
netlist, f["name"]
)
)
if is_interchange:
raise RuntimeError(
"Nextpnr-fpga_interchange requires fpga-interchange logical netlist instead of JSON, found{}".format(
f["name"]
)
)
netlist = f["name"]
elif file_type == "fpgaInterchangeNetlist":
if netlist:
raise RuntimeError(
"Nextpnr only supports one netlist. Found {} and {}".format(
netlist, f["name"]
)
)
if not is_interchange:
raise RuntimeError(
"Non-interchange variants of Nextpnr require JSON netlist, found{}".format(
f["name"]
)
)
netlist = f["name"]
else:
unused_files.append(f)
Expand All @@ -75,7 +108,6 @@ def configure(self, edam):
# Write Makefile
commands = EdaCommands()

arch = self.tool_options["arch"]
arch_options = []
if arch == "ecp5":
targets = self.name + ".config"
Expand All @@ -89,6 +121,10 @@ def configure(self, edam):
targets = self.name + ".pack"
constraints = ["--cst", cst_file] if cst_file else []
output = ["--write", targets]
elif arch == "fpga_interchange":
targets = self.name + ".phys"
constraints = ["--xdc", xdc_file]
output = ["--phys", targets]
else:
targets = self.name + ".asc"
constraints = ["--pcf", pcf_file] if pcf_file else []
Expand All @@ -97,7 +133,12 @@ def configure(self, edam):
depends = netlist
command = ["nextpnr-" + arch, "-l", "next.log"]
command += arch_options + self.tool_options.get("nextpnr_options", [])
command += constraints + ["--json", depends] + output
command += constraints
if is_interchange:
command += ["--netlist", depends]
else:
command += ["--json", depends]
command += output

# CLI target
commands.add(command, [targets], [depends])
Expand Down