Skip to content

techlibs/lattice: add missing clock muxes to ECP5 block ram blackboxes #5045

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danderson
Copy link

@danderson danderson commented Apr 21, 2025

What are the reasons/motivation for this change?

Fixes #3952 , missing parameters on ECP5 EBR blackboxes.

Explain how this is achieved.

prjtrellis documentation shows that EBR clock inputs have optional inverters. The bram techmap outputs those parameters, and nextpnr consumes them. But for whatever reason, Diamond doesn't include those parameters in its blackbox models. This makes synth_lattice fail when targeting ECP5 with a design that maps block RAMs.

This change fixes up the ECP5 bram blackbox models at generation time, by adding in the missing parameters.

If applicable, please suggest to reviewers how they can test the change.

  1. Grab this synth.v https://gist.github.com/danderson/3e80ce79da41673de1ee0dff22e0e596 . The Verilog is a bit verbose, but it's just a basic 1kiB block RAM with registered output.

  2. With yosys@main: yosys -p 'read_verilog -sv -defer synth.v; hierarchy -top mkTop; synth_lattice -family ecp5'

Observe synthesis failure with error:

4.47.1. Analyzing design hierarchy..
Top module:  \mkTop
ERROR: Module `DP16KD' referenced in module `mkTop' in cell `ram_.RAM.0.0' does not have a parameter named 'CLKAMUX'.
  1. Apply this patch to yosys install tree, run same thing again: yosys -p 'read_verilog -sv -defer synth.v; hierarchy -top mkTop; synth_lattice -family ecp5'

Observe synthesis now succeeds.

  1. Also compare passing -abc9 to synth_lattice before and after. Before:
4.43.2. Executing ABC9_OPS pass (helper functions for ABC9).
/usr/bin/../share/yosys/lattice/common_sim.vh:0: ERROR: Can't find object for defparam `CLKAMUX`!

After: synthesis succeeds.

prjtrellis documentation shows that EBR clock inputs have optional inverters.
The bram techmap outputs those parameters, and nextpnr consumes them. But for
whatever reason, Diamond doesn't include those parameters in its blackbox
models. This makes synth_lattice fail when targeting ECP5 with a design that
maps block RAMs if you include any pass that needs cells_bb_ecp5.v's definitions.

This change fixes up the ECP5 bram blackbox models at generation time, by
adding the missing parameters back in.

Signed-off-by: David Anderson <[email protected]>
@danderson
Copy link
Author

Another note on the approach: this is fundamentally a slight disagreement between the ground truth of what the hardware can do (as discovered by prjtrellis), and Lattice's official tools. This PR resolves the disagreement in favor of the all-OSS toolchain, which offers a superset of the configurations that the vendor tools can express.

It was also the simplest fix, in that the yosys techmap, nextpnr, and prjtrellis all know that ECP5 EBRs have clock inverters, and handle them appropriately. The only holdout (and cause of this bug) is this one blackbox definition that was mechanically derived from the vendor tooling, and disagrees with the rest of the OSS ECP5 toolchain.

An alternative way to fix this would be to resolve in favor of vendor tooling, and strip out CLKMUX settings from the ECP5 memory techmaps. That would make synthesis output directly compatible with Diamond place&route, and I think would still work with nextpnr as I believe it applies sensible defaults for these params.

My assumption is that this compat isn't hugely compelling, because a hybrid workflow (yosys into diamond p&r) is uncommon, and mostly people stick to either the OSS toolchain or Lattice Diamond end-to-end. Plus, this is easily fixed with a post-processing script after the main synth run, if needed.

I mention this just to say that if maintainer preference is to resolve in the other direction, I can make that happen too. I don't personally need these clock inverters, I just want my synthesis to work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DP16KD blackbox model is missing at least CLKAMUX and CLKBMUX ports.
1 participant