Skip to content

Commit

Permalink
Merge pull request #2006 from trabucayre/update_altera_build
Browse files Browse the repository at this point in the history
Update altera build
  • Loading branch information
enjoy-digital committed Jul 4, 2024
2 parents b286fe5 + 9fd6397 commit d838a9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
8 changes: 8 additions & 0 deletions litex/build/altera/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ def get_reserved_jtag_pads(self):
for pad in common.altera_reserved_jtag_pads:
r[pad] = self.request(pad)
return r

@classmethod
def fill_args(cls, toolchain, parser):
quartus.fill_args(parser)

@classmethod
def get_argdict(cls, toolchain, args):
return quartus.get_argdict(args)
27 changes: 23 additions & 4 deletions litex/build/altera/quartus.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ class AlteraQuartusToolchain(GenericToolchain):

def __init__(self):
super().__init__()
self._synth_tool = "quartus_map"
self.additional_sdc_commands = []
self.additional_qsf_commands = []
self.cst = []

def build(self, platform, fragment,
synth_tool = "quartus_map",
**kwargs):

self._synth_tool = synth_tool

return GenericToolchain.build(self, platform, fragment, **kwargs)

# IO/Placement Constraints (.qsf) --------------------------------------------------------------

def _format_constraint(self, c, signame, fmt_r):
Expand Down Expand Up @@ -143,7 +152,8 @@ def build_project(self):

# Add IPs
for filename in self.platform.ips:
qsf.append("set_global_assignment -name QSYS_FILE " + filename.replace("\\", "/"))
file_ext = os.path.splitext(filename)[1][1:].upper()
qsf.append(f"set_global_assignment -name {file_ext}_FILE " + filename.replace("\\", "/"))

# Add include paths
for path in self.platform.verilog_include_paths:
Expand Down Expand Up @@ -178,7 +188,7 @@ def build_script(self):
script_contents += "# Autogenerated by LiteX / git: " + tools.get_litex_git_revision() + "\n"
script_contents += "set -e -u -x -o pipefail\n"
script_contents += """
quartus_map --read_settings_files=on --write_settings_files=off {build_name} -c {build_name}
{synth_tool} --read_settings_files=on --write_settings_files=off {build_name} -c {build_name}
quartus_fit --read_settings_files=off --write_settings_files=off {build_name} -c {build_name}
quartus_asm --read_settings_files=off --write_settings_files=off {build_name} -c {build_name}
quartus_sta {build_name} -c {build_name}"""
Expand All @@ -196,7 +206,7 @@ def build_script(self):
quartus_cpf -c {build_name}.sof {build_name}.rbf
fi
"""
script_contents = script_contents.format(build_name=build_name)
script_contents = script_contents.format(build_name=build_name, synth_tool=self._synth_tool)
tools.write_to_file(script_file, script_contents, force_unix=True)

return script_file
Expand All @@ -207,10 +217,19 @@ def run_script(self, script):
else:
shell = ["bash"]

if which("quartus_map") is None:
if which(self._synth_tool) is None:
msg = "Unable to find Quartus toolchain, please:\n"
msg += "- Add Quartus toolchain to your $PATH."
raise OSError(msg)

if subprocess.call(shell + [script]) != 0:
raise OSError("Error occured during Quartus's script execution.")

def fill_args(parser):
toolchain_group = parser.add_argument_group(title="Quartus toolchain options")
toolchain_group.add_argument("--synth-tool", default="quartus_map", help="Synthesis mode (quartus_map or quartus_syn).")

def get_argdict(args):
return {
"synth_tool" : args.synth_tool,
}

0 comments on commit d838a9c

Please sign in to comment.