Skip to content

Commit

Permalink
Refactor NextPNR for f4pga/symbiflow usage (nextpnr-xilinx specifical…
Browse files Browse the repository at this point in the history
…ly) (#330)

Update nextpnr.py
  • Loading branch information
Pocketkid2 committed Aug 10, 2022
1 parent 8c97cb9 commit 3e86136
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ doc/_build/
__pycache__
/.eggs
/.tox
.vscode/
.vscode/
build/
81 changes: 58 additions & 23 deletions edalize/tools/nextpnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def configure(self, edam):
lpf_file = ""
pcf_file = ""
netlist = ""
chipdb_file = ""
placement_constraints = []
unused_files = []
for f in self.files:
file_type = f.get("file_type", "")
Expand Down Expand Up @@ -54,6 +56,16 @@ def configure(self, edam):
)
)
pcf_file = f["name"]
if file_type == "chipdb":
if chipdb_file:
raise RuntimeError(
"Nextpnr only supports one ChipDB (bin/bba) file. Found {} and {}".format(
chipdb_file, f["name"]
)
)
chipdb_file = f["name"]
if file_type == "xdc":
placement_constraints.append(f["name"])
elif file_type == "jsonNetlist":
if netlist:
raise RuntimeError(
Expand All @@ -77,31 +89,54 @@ def configure(self, edam):

arch = self.tool_options["arch"]
arch_options = []
if arch == "ecp5":
targets = self.name + ".config"
constraints = ["--lpf", lpf_file] if lpf_file else []
output = ["--textcfg", targets]
elif arch == "gowin":
device = self.tool_options.get("device")
if not device:
raise RuntimeError("Missing required option 'device' for nextpnr-gowin")
arch_options += ["--device", device]
targets = self.name + ".pack"
constraints = ["--cst", cst_file] if cst_file else []
output = ["--write", targets]

# Specific commands for nextpnr-xilinx
if arch == "xilinx":
depends = netlist
if not chipdb_file:
raise RuntimeError("Missing required chipdb (bba/bin) file")
if not placement_constraints:
raise RuntimeError("Missing required XDC file(s)")
targets = self.name + ".fasm"
command = ["nextpnr-" + arch, "--chipdb", chipdb_file]
xdcs = []
for x in placement_constraints:
xdcs += ["--xdc", x]
command += xdcs
command += ["--json", depends]
command += ["--write", self.name + ".routed.json"]
command += ["--fasm", targets]
command += ["--log", "nextpnr.log"]
command += self.tool_options.get("nextpnr_options", [])
commands.add(command, [targets], [depends])
else:
targets = self.name + ".asc"
constraints = ["--pcf", pcf_file] if pcf_file else []
output = ["--asc", targets]
if arch == "ecp5":
targets = self.name + ".config"
constraints = ["--lpf", lpf_file] if lpf_file else []
output = ["--textcfg", targets]
elif arch == "gowin":
device = self.tool_options.get("device")
if not device:
raise RuntimeError(
"Missing required option 'device' for nextpnr-gowin"
)
arch_options += ["--device", device]
targets = self.name + ".pack"
constraints = ["--cst", cst_file] if cst_file else []
output = ["--write", 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 += arch_options + self.tool_options.get("nextpnr_options", [])
command += constraints + ["--json", depends] + output
depends = netlist
command = ["nextpnr-" + arch, "-l", "next.log"]
command += arch_options + self.tool_options.get("nextpnr_options", [])
command += constraints + ["--json", depends] + output

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

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

0 comments on commit 3e86136

Please sign in to comment.