Skip to content

Commit 69209ad

Browse files
[syn] Add nix devShell for example synthesis flow
Provide a .#syn_shell development environment in which the sample synthesis flow using yosys can be executed. This shell provisions the nangate45 PDK into the nix store and sets an environment variable pointing to it which is picked up by the synthesis scripts. A quick-start for how to use this shell is added to the syn/README. Signed-off-by: Harry Callahan <hcallahan@lowrisc.org>
1 parent 5effcae commit 69209ad

5 files changed

Lines changed: 135 additions & 10 deletions

File tree

flake.nix

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
url = "github:nix-community/fenix";
6666
inputs.nixpkgs.follows = "nixpkgs";
6767
};
68+
69+
# Deps for synthesis flows
70+
sv2v = {
71+
url = "github:zachjs/sv2v";
72+
flake = false;
73+
};
6874
};
6975

7076
# The lowRISC public nix-cache contains builds of nix packages used by lowRISC, primarily coming from github:lowRISC/lowrisc-nix.
@@ -86,6 +92,10 @@
8692
let
8793
pkgs = import inputs.nixpkgs {
8894
inherit system;
95+
config = {
96+
allowUnfree = true;
97+
allowBroken = true; # sv2v marked as broken.
98+
};
8999
};
90100
inherit (pkgs) lib;
91101

@@ -160,6 +170,8 @@
160170
mypy
161171
]);
162172

173+
ibex_syn = import ./nix/syn.nix {inherit inputs pkgs;};
174+
163175
# lowRISC fork of the Sail repository. The SAIL -> SV flow is used to generate the reference model.
164176
lowrisc_sail = import ./nix/lowrisc_sail.nix {
165177
inherit pkgs;
@@ -297,6 +309,12 @@
297309
'';
298310
};
299311

312+
syn_shell = shell.override (prev: {
313+
name = "ibex-devshell-synthesis";
314+
nativeBuildInputs = prev.nativeBuildInputs ++ ibex_syn.deps;
315+
shellHook = prev.shellHook + ibex_syn.profile;
316+
});
317+
300318
# This shell uses mkShellNoCC as the stdenv CC can interfere with EDA tools.
301319
eda_shell = pkgs.lib.makeOverridable pkgs.mkShellNoCC {
302320
name = "ibex-devshell-eda";
@@ -320,7 +338,7 @@
320338
inherit lowrisc_sail;
321339
};
322340
devShells = rec {
323-
inherit shell eda_shell;
341+
inherit shell syn_shell eda_shell;
324342
formal = mkshell-minimal {
325343
packages = standard_deps;
326344
shellHook = check_jg + exports;

nix/sv2v.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright lowRISC Contributors.
2+
# Licensed under the MIT License, see LICENSE for details.
3+
# SPDX-License-Identifier: MIT
4+
5+
# Taken from:
6+
# https://github.com/deemp/gists/blob/master/haskellPackage/flake.nix
7+
8+
{
9+
inputs,
10+
pkgs,
11+
...
12+
}: let
13+
packageName = "sv2v";
14+
ghcVersion = "928";
15+
16+
inherit (pkgs.haskell.lib) overrideCabal justStaticExecutables;
17+
hpkgs = pkgs.haskell.packages."ghc${ghcVersion}";
18+
19+
# executableToolDepends - from "sv2v" expression in https://raw.githubusercontent.com/NixOS/nixpkgs/nixos-unstable/pkgs/development/haskell-modules/hackage-packages.nix
20+
package = overrideCabal (hpkgs.callCabal2nix packageName inputs.sv2v.outPath { })
21+
(x: {
22+
executableToolDepends = (x.executableToolDepends or [ ]) ++ (
23+
# Add the following extra dependencies
24+
with pkgs; [
25+
alex
26+
happy
27+
]
28+
);
29+
});
30+
31+
in {
32+
default = justStaticExecutables package;
33+
inherit package;
34+
}

nix/syn.nix

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright lowRISC Contributors.
2+
# Licensed under the MIT License, see LICENSE for details.
3+
# SPDX-License-Identifier: MIT
4+
5+
# Deps for Ibex synthesis jobs
6+
7+
{
8+
inputs,
9+
pkgs,
10+
...
11+
}: let
12+
13+
sv2v_local = import ./sv2v.nix {inherit inputs pkgs;};
14+
15+
ibex_syn_deps = [
16+
sv2v_local.default
17+
] ++ (with pkgs; [
18+
# haskellPackages.sv2v # broken
19+
yosys
20+
openroad
21+
]);
22+
23+
# Create a dumb package of nangate45
24+
# > All we need is a path to the sources
25+
nangate45 = pkgs.stdenv.mkDerivation rec {
26+
pname = "openroad-nangate45";
27+
version = "PDKv1.3_v2010_12.Apache.CCL";
28+
src = pkgs.fetchFromGitHub {
29+
owner = "The-OpenROAD-Project";
30+
repo = "OpenROAD-flow-scripts";
31+
rev = "181e9133776117ea1b9f74dbacbfdaadff8c331b"; # Tag: v3.0
32+
hash = "sha256-fYAdhBsMcuCXmPMQVCRdm75Tk0rd9zLnLfJdjhnhC00=";
33+
};
34+
sourceRoot = "${src.name}/flow/platforms/nangate45";
35+
phases = [ "unpackPhase" "installPhase" ];
36+
installPhase = ''
37+
mkdir -p $out
38+
cp -r ./* $out
39+
'';
40+
};
41+
42+
ibex_syn_profile = ''
43+
export LR_SYNTH_CELL_LIBRARY_NAME=nangate
44+
export LR_SYNTH_CELL_LIBRARY_PATH=${nangate45}/lib/NangateOpenCellLibrary_typical.lib
45+
'';
46+
47+
in {
48+
49+
deps = ibex_syn_deps;
50+
profile = ibex_syn_profile;
51+
52+
}

syn/README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
tape-out quality netlists and area/timing numbers it generates are not
33
representative of what would be achievable with a tape-out quality flow**
44

5+
# Quick start with Nix
6+
7+
If you have Nix with flakes enabled, all dependencies and the Nangate45 cell
8+
library are provided automatically via the `syn_shell` devShell. Enter the
9+
shell and run the flow:
10+
11+
```sh
12+
nix develop .#syn_shell
13+
cd syn
14+
./syn_yosys.sh
15+
```
16+
17+
No further setup is needed — `syn_setup.sh` is pre-configured and
18+
`LR_SYNTH_CELL_LIBRARY_PATH`/`LR_SYNTH_CELL_LIBRARY_NAME` are exported by the
19+
shell hook. The remaining sections describe manual installation for non-Nix
20+
environments.
21+
522
# Yosys/OpenSTA Ibex Synthesis Flow
623

724
This is a synthesis-only implementation flow using Yosys for Synthesis and
@@ -39,13 +56,14 @@ format. The following Open Libraries can be used:
3956

4057
# Synthesis flow setup
4158

42-
The synthesis flow is configured via environment variables. The `syn_setup.sh`
43-
file is used to set the environment variables for the flow and any changes made
44-
should be placed there. An example `syn_setup.example.sh` is included. A copy
45-
of this named `syn_setup.sh` must be made and the values in it set appropriately
46-
for the flow to work.
59+
The synthesis flow is configured via environment variables. `syn_setup.sh` sets
60+
the environment variables for the flow.
61+
62+
When using `nix develop .#syn_shell`, the cell library variables below are
63+
exported automatically by the shell hook and no edits to `syn_setup.sh` are
64+
needed. For non-Nix environments, set them manually in `syn_setup.sh`.
4765

48-
The environment variables that must be set in `syn_setup.sh` are
66+
The environment variables that must be set are:
4967

5068
* `LR_SYNTH_CELL_LIBRARY_PATH` - The path to the standard cell library, this
5169
should point to the absolute path of the Nangate45 library
@@ -56,7 +74,7 @@ The environment variables that must be set in `syn_setup.sh` are
5674

5775
# Running the synthesis flow
5876

59-
Once `syn_setup.sh` has been created, call `syn_yosys.sh` to run the entire
77+
Once the environment is configured, call `syn_yosys.sh` to run the entire
6078
flow. All outputs are placed under the `syn/syn_out` directory with the prefix
6179
`ibex_` with the current date/time forming the rest of the name, e.g.
6280
`syn/syn_out/ibex_06_01_2020_11_19_15`
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ fi
1818
export LR_SYNTH_TIMING_RUN=1
1919
export LR_SYNTH_FLATTEN=1
2020

21-
# SETUP CELL LIBRARY PATH
22-
# Uncomment the lines below and set the path to an appropriate .lib file
21+
# When using `nix develop .#syn_shell`, the following are set automatically by
22+
# the shell hook (via nix/syn.nix):
23+
# LR_SYNTH_CELL_LIBRARY_PATH (path to NangateOpenCellLibrary_typical.lib)
24+
# LR_SYNTH_CELL_LIBRARY_NAME (nangate)
25+
# For non-Nix environments, uncomment and set these manually:
2326
# export LR_SYNTH_CELL_LIBRARY_PATH=/path/to/NangateOpenCellLibrary_typical.lib
2427
# export LR_SYNTH_CELL_LIBRARY_NAME=nangate

0 commit comments

Comments
 (0)