vendor._lattice: add nextpnr-machxo2 support.

This commit is contained in:
Wanda 2024-04-19 04:16:52 +02:00 committed by Catherine
parent 09045a2724
commit cf07f938ab

View file

@ -207,11 +207,11 @@ class DDRBufferMachXO2(io.DDRBuffer):
class LatticePlatform(TemplatedPlatform): class LatticePlatform(TemplatedPlatform):
""" """
.. rubric:: Trellis toolchain (ECP5 only) .. rubric:: Trellis toolchain (ECP5, MachXO2, MachXO3)
Required tools: Required tools:
* ``yosys`` * ``yosys``
* ``nextpnr-ecp5`` * ``nextpnr-ecp5`` or ``nextpnr-machxo2``
* ``ecppack`` * ``ecppack``
The environment is populated by running the script specified in the environment variable The environment is populated by running the script specified in the environment variable
@ -220,11 +220,11 @@ class LatticePlatform(TemplatedPlatform):
Available overrides: Available overrides:
* ``verbose``: enables logging of informational messages to standard error. * ``verbose``: enables logging of informational messages to standard error.
* ``read_verilog_opts``: adds options for ``read_verilog`` Yosys command. * ``read_verilog_opts``: adds options for ``read_verilog`` Yosys command.
* ``synth_opts``: adds options for ``synth_ecp5`` Yosys command. * ``synth_opts``: adds options for ``synth_<family>`` Yosys command.
* ``script_after_read``: inserts commands after ``read_ilang`` in Yosys script. * ``script_after_read``: inserts commands after ``read_ilang`` in Yosys script.
* ``script_after_synth``: inserts commands after ``synth_ecp5`` in Yosys script. * ``script_after_synth``: inserts commands after ``synth_<family>`` in Yosys script.
* ``yosys_opts``: adds extra options for ``yosys``. * ``yosys_opts``: adds extra options for ``yosys``.
* ``nextpnr_opts``: adds extra options for ``nextpnr-ecp5``. * ``nextpnr_opts``: adds extra options for ``nextpnr-<family>``.
* ``ecppack_opts``: adds extra options for ``ecppack``. * ``ecppack_opts``: adds extra options for ``ecppack``.
* ``add_preferences``: inserts commands at the end of the LPF file. * ``add_preferences``: inserts commands at the end of the LPF file.
@ -294,11 +294,16 @@ class LatticePlatform(TemplatedPlatform):
"BG756": "caBGA756", "BG756": "caBGA756",
} }
_trellis_required_tools = [ _trellis_required_tools_ecp5 = [
"yosys", "yosys",
"nextpnr-ecp5", "nextpnr-ecp5",
"ecppack" "ecppack"
] ]
_trellis_required_tools_machxo2 = [
"yosys",
"nextpnr-machxo2",
"ecppack"
]
_trellis_file_templates = { _trellis_file_templates = {
**TemplatedPlatform.build_script_templates, **TemplatedPlatform.build_script_templates,
"{{name}}.il": r""" "{{name}}.il": r"""
@ -322,7 +327,11 @@ class LatticePlatform(TemplatedPlatform):
{% endfor %} {% endfor %}
read_ilang {{name}}.il read_ilang {{name}}.il
{{get_override("script_after_read")|default("# (script_after_read placeholder)")}} {{get_override("script_after_read")|default("# (script_after_read placeholder)")}}
{% if platform.family == "ecp5" %}
synth_ecp5 {{get_override("synth_opts")|options}} -top {{name}} synth_ecp5 {{get_override("synth_opts")|options}} -top {{name}}
{% else %}
synth_lattice -family xo2 {{get_override("synth_opts")|options}} -top {{name}}
{% endif %}
{{get_override("script_after_synth")|default("# (script_after_synth placeholder)")}} {{get_override("script_after_synth")|default("# (script_after_synth placeholder)")}}
write_json {{name}}.json write_json {{name}}.json
""", """,
@ -356,13 +365,17 @@ class LatticePlatform(TemplatedPlatform):
{{name}}.ys {{name}}.ys
""", """,
r""" r"""
{{invoke_tool("nextpnr-ecp5")}} {{invoke_tool("nextpnr-" + platform.family)}}
{{quiet("--quiet")}} {{quiet("--quiet")}}
{{get_override("nextpnr_opts")|options}} {{get_override("nextpnr_opts")|options}}
--log {{name}}.tim --log {{name}}.tim
{% if platform.family == "ecp5" %}
{{platform._nextpnr_device_options[platform.device]}} {{platform._nextpnr_device_options[platform.device]}}
--package {{platform._nextpnr_package_options[platform.package]|upper}} --package {{platform._nextpnr_package_options[platform.package]|upper}}
--speed {{platform.speed}} --speed {{platform.speed}}
{% else %}
--device {{platform.device}}-{{platform.speed}}{{platform.package}}{{platform.grade}}
{% endif %}
--json {{name}}.json --json {{name}}.json
--lpf {{name}}.lpf --lpf {{name}}.lpf
--textcfg {{name}}.config --textcfg {{name}}.config
@ -422,7 +435,7 @@ class LatticePlatform(TemplatedPlatform):
prj_run Map -impl impl prj_run Map -impl impl
prj_run PAR -impl impl prj_run PAR -impl impl
prj_run Export -impl impl -task Bitgen prj_run Export -impl impl -task Bitgen
{% if family == "machxo2" -%} {% if platform.family == "machxo2" -%}
prj_run Export -impl impl -task Jedecgen prj_run Export -impl impl -task Jedecgen
{% endif %} {% endif %}
{{get_override("script_after_export")|default("# (script_after_export placeholder)")}} {{get_override("script_after_export")|default("# (script_after_export placeholder)")}}
@ -523,7 +536,10 @@ class LatticePlatform(TemplatedPlatform):
@property @property
def required_tools(self): def required_tools(self):
if self.toolchain == "Trellis": if self.toolchain == "Trellis":
return self._trellis_required_tools if self.family == "ecp5":
return self._trellis_required_tools_ecp5
elif self.family == "machxo2":
return self._trellis_required_tools_machxo2
if self.toolchain == "Diamond": if self.toolchain == "Diamond":
return self._diamond_required_tools return self._diamond_required_tools
assert False assert False