Skip to content

Commit ef63417

Browse files
Add nix flow for creating project development shell
Add instructions for deploying vivado through nix - This is not enabled by default, but still present in the project. Add missing dependencies to nixpkgs verilator - zlib and libelf were needed for our simulation, probably missing or optional from the upstream package. Add ascii-art to 'nix develop' splash Add instructions for loading packages from USB cache
1 parent 2f1c69d commit ef63417

18 files changed

+1076
-75
lines changed

README.md

Lines changed: 317 additions & 75 deletions
Large diffs are not rendered by default.

data/lowrisc.art

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
╓╗Φ╬╬╫╫╬╬Æ╗w
2+
╔╬╫╫╫╫╫╫╫╫M "╣╬╗
3+
╔╣╫╫╫╫╣╝╝╣╫╫╕ ╬╫╫╫╗
4+
╬╫Å╝╝╝╛ ╟╫╫╬ ß╣╫╫╫╫╫▌ .╓,
5+
╔╜╓╬╬╬╬N ,╣╫╫╫⌐╢╫╫╫╫╫╫╣^ ║█▌ ║█████▓⌐ ╫█▌ ╓▓████▌ ▄▓████▌
6+
╔╬╫╫Å╜╙╝╫╫╫╫╫╫╫Å,╬╫╫╫╫▌"╔╣ ║█▌ ╓▄▓▓# Φ▓⌐ ▓▓ ▓▓ ╫█▌ ▓█▌ ▓█▌ ▀█▌▄╓, ▓█▌
7+
╣╫╫M ╟╫╫╫╫M,Φ╫╫╫╫Å`╔╣╫╫ ║█▌ █▌ '█M╙█▌╓██▌║█▌ ╫█████▀ ▓█▌ `╙▀██▓ ██▌
8+
╙╫╣╜╓,,╔╣╫╣╜╓╬╫╫╫╫M,╗▓╫╫╫M ║█▌ ▀█▄▄▓█ ╢██▌╙██▌ ╫█▌ ╙██▄ ▓█▌ ╣▓▄▄▓█▀ ╙██▓▄▓▓▌
9+
"╔╣╫╫╫╫▌╨╔╬╫Å╝╣╜╓╬╫╫╫╫╫Å `` `` `` `` ``` ` ``` ``` """`
10+
╙╣╫╫Å"╔╣╫╬ ╙╫╫╫╫╫╫╜
11+
"`╗╣╫╫╫╬, ╔╫╫╫╣╜
12+
`╙╝╝Φ╣╣ΦÅ╝╜"

dependencies/edalize.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ lib, buildPythonPackage, fetchPypi,
2+
jinja2, setuptools_scm, simplesat
3+
}:
4+
buildPythonPackage rec {
5+
pname = "edalize";
6+
version = "0.3.3";
7+
src = fetchPypi {
8+
inherit pname version;
9+
sha256 = "1734aprwzm0z2l60xapqrfxxw747n9h9fflv3n0x4iaradf75abj";
10+
};
11+
SETUPTOOLS_SCM_PRETEND_VERSION = "${version}";
12+
nativeBuildInputs = [ setuptools_scm ];
13+
propagatedBuildInputs = [ jinja2 simplesat ];
14+
doCheck = false;
15+
}

dependencies/flake.lock

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dependencies/flake.nix

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
description = "ibex simple_system dependencies";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
6+
lowrisc_fusesoc_src = { url = "github:lowRISC/fusesoc?ref=ot-0.2"; flake = false; };
7+
lowrisc_edalize_src = { url = "github:lowRISC/edalize?ref=ot-0.2"; flake = false; };
8+
};
9+
10+
outputs = {self, nixpkgs,
11+
lowrisc_fusesoc_src, lowrisc_edalize_src,
12+
}:
13+
let
14+
system = "x86_64-linux";
15+
pkgs = import nixpkgs {
16+
inherit system;
17+
config = { allowUnfree = true; };
18+
};
19+
20+
lowRISC_python_overrides = pfinal: pprev: {
21+
fusesoc = pprev.fusesoc.overridePythonAttrs (oldAttrs: {
22+
version = "0.3.3.dev";
23+
src = lowrisc_fusesoc_src;
24+
});
25+
edalize = pprev.edalize.overridePythonAttrs (oldAttrs: {
26+
version = "0.3.3.dev";
27+
src = lowrisc_edalize_src;
28+
});
29+
};
30+
31+
lowRISC_spike_override = final: prev: {
32+
riscv-isa-sim = prev.riscv-isa-sim.overrideAttrs (oldAttrs: rec {
33+
version = "ibex-cosim-v0.3";
34+
src = pkgs.fetchFromGitHub {
35+
owner = "lowrisc";
36+
repo = oldAttrs.pname;
37+
rev = version;
38+
sha256 = "sha256-pKuOpzybOI8UqWV1TSFq4hqTHf7Bft/3WL19fRpwmfU=";
39+
};
40+
});
41+
};
42+
43+
# Using requireFile prevents rehashing each time.
44+
# This saves much seconds during rebuilds.
45+
vivado_bundled_installer_src = pkgs.requireFile rec {
46+
name = "vivado_bundled.tar.gz";
47+
sha256 = "1yxx6crvawhzvary9js0m8bzm35vv6pzfqdkv095r84lb13fyp7b";
48+
# Print the following message if the name / hash are not
49+
# found in the store.
50+
message = ''
51+
requireFile :
52+
file/dir not found in /nix/store
53+
file = ${name}
54+
hash = ${sha256}
55+
56+
This nix expression requires that ${name} is already part of the store.
57+
- Login to xilinx.com
58+
- Download Unified Installer from https://www.xilinx.com/support/download.html,
59+
- Run installer, specify a 'Download Image (Install Seperately)'
60+
- Gzip the bundled installed image directory
61+
- Rename the file to ${name}
62+
- Add it to the nix store with
63+
nix-prefetch-url --type sha256 file:/path/to/${name}
64+
- Change the sha256 key above to $HASH
65+
'';
66+
};
67+
68+
vivado = pkgs.callPackage (import ./vivado.nix) {
69+
# We need to prepare the pre-downloaded installer to
70+
# execute within a nix build. Make use of the included java deps,
71+
# but we still need to do a little patching to make it work.
72+
vivado-src = pkgs.stdenv.mkDerivation rec {
73+
pname = "vivado_src";
74+
version = "2022.2";
75+
src = vivado_bundled_installer_src;
76+
postPatch = ''
77+
patchShebangs .
78+
patchelf \
79+
--set-interpreter $(cat ${pkgs.stdenv.cc}/nix-support/dynamic-linker) \
80+
tps/lnx64/jre*/bin/java
81+
'';
82+
dontBuild = true; dontFixup = true;
83+
installPhase = ''
84+
mkdir -p $out
85+
cp -R * $out
86+
'';
87+
};
88+
};
89+
90+
in
91+
{
92+
overlay_pkgs = pkgs.lib.composeManyExtensions [
93+
(import ./overlay.nix)
94+
lowRISC_spike_override
95+
(final: prev: {
96+
inherit vivado;
97+
})
98+
];
99+
overlay_python = pkgs.lib.composeManyExtensions [
100+
(import ./python-overlay.nix)
101+
lowRISC_python_overrides
102+
];
103+
};
104+
}

dependencies/fusesoc.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ lib, buildPythonPackage, fetchPypi,
2+
setuptools_scm, pyparsing, pyyaml, simplesat, ipyxact, edalize
3+
}:
4+
buildPythonPackage rec {
5+
pname = "fusesoc";
6+
version = "1.12.0";
7+
src = fetchPypi {
8+
inherit pname version;
9+
sha256 = "1065arwk1hylf4lqmgqb77fw9izgh7jaib5qnl2dqwdic11c2w44";
10+
};
11+
SETUPTOOLS_SCM_PRETEND_VERSION = "${version}"; # Hack
12+
nativeBuildInputs = [ setuptools_scm ];
13+
propagatedBuildInputs = [ pyparsing pyyaml simplesat ipyxact edalize ];
14+
doCheck = false;
15+
}

dependencies/ipyxact.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ lib, buildPythonPackage, fetchPypi,
2+
pyyaml }:
3+
buildPythonPackage rec {
4+
pname = "ipyxact";
5+
version = "0.3.1";
6+
src = fetchPypi {
7+
inherit pname version;
8+
sha256 = "09rv8zn6gqwhdnwgx246mz9biln0q71hsxjf6sb9ilhan75fsn0z";
9+
};
10+
propagatedBuildInputs = [ pyyaml ];
11+
doCheck = false;
12+
}

dependencies/okonomiyaki.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ lib, buildPythonPackage, fetchPypi,
2+
attrs, jsonschema, six, zipfile2, distro }:
3+
buildPythonPackage rec {
4+
pname = "okonomiyaki";
5+
version = "1.3.2";
6+
src = fetchPypi {
7+
inherit pname version;
8+
sha256 = "1dw9di7s92z201lwq7aqy5h9h53af73ffx6pnl5iz3lnfi0zf85p";
9+
};
10+
propagatedBuildInputs = [ attrs jsonschema six zipfile2 distro ];
11+
doCheck = false;
12+
}

dependencies/overlay.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
final: prev: {
2+
riscv-gcc-toolchain-lowrisc = prev.callPackage ./riscv-gcc-toolchain-lowrisc.nix {};
3+
riscv-isa-sim = prev.callPackage ./riscv-isa-sim.nix {};
4+
}

dependencies/python-overlay.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pfinal: pprev: {
2+
ipyxact = pfinal.callPackage ./ipyxact.nix {};
3+
zipfile2 = pfinal.callPackage ./zipfile2.nix {};
4+
simplesat = pfinal.callPackage ./simplesat.nix {};
5+
okonomiyaki = pfinal.callPackage ./okonomiyaki.nix {};
6+
fusesoc = pfinal.callPackage ./fusesoc.nix {};
7+
edalize = pfinal.callPackage ./edalize.nix {};
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{ pkgs, lib, stdenv,
2+
fetchzip, zlib, ncurses5,
3+
}:
4+
5+
# Used for reference...
6+
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/gcc-arm-embedded/10/default.nix
7+
8+
stdenv.mkDerivation rec {
9+
name = "riscv-gcc-toolchain";
10+
version = "20220210-1";
11+
src = fetchzip {
12+
url = "https://github.com/lowRISC/lowrisc-toolchains/releases/download/${version}/lowrisc-toolchain-gcc-rv32imc-${version}.tar.xz";
13+
sha256 = "1m708xfdzf3jzclm2zw51my3nryvlsfwqkgps3xxa0xnhq4ly1bl";
14+
};
15+
16+
dontConfigure = true;
17+
dontBuild = true;
18+
dontPatchELF = true; # We will do this manually in preFixup
19+
dontStrip = true;
20+
21+
installPhase = ''
22+
mkdir -p $out
23+
cp -R * $out
24+
'';
25+
preFixup = ''
26+
find $out -type f ! -name ".o" | while read f; do
27+
patchelf "$f" > /dev/null 2>&1 || continue
28+
patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$f" || true
29+
patchelf --set-rpath ${lib.makeLibraryPath [ "$out" stdenv.cc.cc ncurses5 ]} "$f" || true
30+
done
31+
'';
32+
}

dependencies/riscv-isa-sim.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{ lib, stdenv, fetchFromGitHub,
2+
dtc
3+
}:
4+
5+
stdenv.mkDerivation rec {
6+
name = "spike";
7+
pname = "riscv-isa-sim";
8+
version = "1.1.1-dev";
9+
10+
src = fetchFromGitHub {
11+
owner = "riscv-software-src";
12+
repo = pname;
13+
rev = "ac466a21df442c59962589ba296c702631e041b5";
14+
sha256 = "sha256-1OLGEdj0dGnNREKZOrkAyKET7d2L+VFebOGm2oxtkHw=";
15+
};
16+
17+
enableParallelBuilding = true;
18+
# buildInputs = [ ];
19+
nativeBuildInputs = [ dtc ];
20+
configureFlags = [ "--enable-commitlog" "--enable-misaligned" ];
21+
22+
doCheck = false;
23+
dontInstall = false;
24+
25+
meta = with lib; {
26+
description = "Riscv golden-reference simulator Spike";
27+
homepage = "https://github.com/riscv-software-src/riscv-isa-sim";
28+
license = with licenses; [];
29+
platforms = platforms.unix;
30+
maintainers = with maintainers; [];
31+
};
32+
}

dependencies/riscv_gcc.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{ # Chosen toolchain subarchitecture, e.g. 'rv32imc'
2+
riscv-arch
3+
4+
# Package set
5+
, pkgs
6+
}:
7+
8+
# --------------------------
9+
# RISC-V GCC Toolchain Setup
10+
11+
let
12+
riscv-toolchain-ver = "8.2.0";
13+
riscv-src = pkgs.fetchFromGitHub {
14+
owner = "lowRISC";
15+
repo = "lowrisc-toolchains";
16+
rev = "2cac2b9797d96a5c46d86d463c71e0a66926f473";
17+
sha256 = "sha256-DNEkdJ5G8wpN2nQbD+nzvAQixWWGCG5RbJrXg5IRteg=";
18+
};
19+
#
20+
# given an architecture like 'rv32i', this will generate the given
21+
# toolchain derivation based on the above source code.
22+
make-riscv-toolchain = arch:
23+
pkgs.stdenv.mkDerivation rec {
24+
name = "riscv-${arch}-toolchain-${version}";
25+
version = "${riscv-toolchain-ver}-${builtins.substring 0 7 src.rev}";
26+
src = riscv-src;
27+
28+
configureFlags = [ "--with-arch=${arch}" ];
29+
installPhase = ":"; # 'make' installs on its own
30+
# installPhase = ''
31+
# mkdir -p $out
32+
# cp -r * $out
33+
# '';
34+
hardeningDisable = [ "all" ];
35+
enableParallelBuilding = true;
36+
37+
# Stripping/fixups break the resulting libgcc.a archives, somehow.
38+
# Maybe something in stdenv that does this...
39+
dontStrip = true;
40+
dontFixup = true;
41+
42+
nativeBuildInputs = with pkgs; [ curl gawk texinfo bison flex gperf ];
43+
buildInputs = with pkgs; [ libmpc mpfr gmp expat ];
44+
};
45+
46+
in make-riscv-toolchain riscv-arch

dependencies/simplesat.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ lib, buildPythonPackage, fetchPypi,
2+
okonomiyaki, attrs, six, enum34
3+
}:
4+
buildPythonPackage rec {
5+
pname = "simplesat";
6+
version = "0.8.2";
7+
src = fetchPypi {
8+
inherit pname version;
9+
sha256 = "0n6qm2gzwji19ykp3i6wm6vjw7dnn92h2flm42708fxh6lkz6hqr";
10+
};
11+
propagatedBuildInputs = [ okonomiyaki attrs six enum34 ];
12+
doCheck = false;
13+
}

0 commit comments

Comments
 (0)