Skip to content

Commit c3a935c

Browse files
committed
flake.nix cleanup
* Removed verilator overlay. It's sufficient to add the dependencies to buildInputs * Remove unneeded comment and code * Use toolchain from lowrisc-nix
1 parent 901548e commit c3a935c

File tree

4 files changed

+122
-186
lines changed

4 files changed

+122
-186
lines changed

dependencies/overlay.nix

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

dependencies/riscv-gcc-toolchain-lowrisc.nix

Lines changed: 0 additions & 35 deletions
This file was deleted.

flake.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 121 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -13,158 +13,130 @@
1313
};
1414
};
1515

16-
outputs = all @ {
16+
outputs = inputs @ {
1717
self,
18+
lowrisc-nix,
1819
nixpkgs,
1920
flake-utils,
2021
deps,
2122
...
22-
}:
23-
(
24-
flake-utils.lib.eachDefaultSystem (system: let
25-
pkgs = import nixpkgs {
26-
inherit system;
27-
config = {allowUnfree = true;};
28-
overlays = [
29-
# Add extra packages we might need
30-
# Currently this contains the lowrisc riscv-toolchain, and spike
31-
deps.overlay_pkgs
32-
# Add all the python packages we need that aren't in nixpkgs
33-
# (See the ./dependencies folder for more info)
34-
(final: prev: {
35-
python3 = prev.python3.override {
36-
packageOverrides = deps.overlay_python;
37-
};
38-
})
39-
# Add some missing dependencies to nixpkgs#verilator
40-
(final: prev: {
41-
verilator = prev.verilator.overrideAttrs (oldAttrs: {
42-
propagatedBuildInputs = [final.zlib final.libelf];
43-
});
44-
})
45-
];
46-
};
47-
48-
# Currently we don't build the riscv-toolchain from src, we use a github release
49-
# (See ./dependencies/riscv-gcc-toolchain-lowrisc.nix)
50-
51-
# riscv-toolchain (built from src) # BROKEN
52-
# riscv-gcc-toolchain-lowrisc-src = pkgs.callPackage \
53-
# ./dependencies/riscv_gcc.nix {
54-
# riscv-arch = "rv32imc";
55-
# };
56-
57-
pythonEnv = pkgs.python3.withPackages (
58-
ps:
59-
with ps; [pip fusesoc edalize pyyaml Mako]
60-
);
61-
62-
# This is the final list of dependencies we need to build the project.
63-
project_deps =
64-
[
65-
pythonEnv
66-
]
67-
++ (with pkgs; [
68-
cmake
69-
openocd
70-
screen
71-
verilator
72-
riscv-gcc-toolchain-lowrisc
73-
gtkwave
74-
srecord
75-
openfpgaloader
76-
# vivado
77-
]);
78-
in {
79-
packages.dockertest = pkgs.dockerTools.buildImage {
80-
name = "hello-docker";
81-
copyToRoot = pkgs.buildEnv {
82-
name = "image-root";
83-
paths = [
84-
pkgs.coreutils
85-
pkgs.sl
86-
];
87-
};
88-
config = {
89-
Cmd = ["${pkgs.sl}/bin/sl"];
90-
};
91-
};
92-
devShells.default = pkgs.mkShell {
93-
name = "labenv";
94-
buildInputs = project_deps;
95-
shellHook = ''
96-
# FIXME This works on Ubuntu, may not on other distros. FIXME
97-
export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive
98-
99-
# HACK fixup some paths to use our sandboxed python environment
100-
# Currently, fusesoc tries to invoke the program 'python3' from the
101-
# PATH, which when running under a nix python environment, resolves
102-
# to the raw python binary, not wrapped and not including the
103-
# environment's packages. Hence, the first time an import is evaluated
104-
# we will error out.
105-
sed -i -- \
106-
's|interpreter:.*|interpreter: ${pythonEnv}/bin/python3|g' \
107-
vendor/lowrisc_ibex/vendor/lowrisc_ip/dv/tools/ralgen/ralgen.core
108-
sed -i -- \
109-
's|interpreter:.*|interpreter: ${pythonEnv}/bin/python3|g' \
110-
vendor/lowrisc_ibex/vendor/lowrisc_ip/ip/prim/primgen.core
111-
112-
export PS1='labenv(HiPEAC) (ibex-demo-system) \$ '
113-
114-
echo
115-
echo
116-
cat ./data/lowrisc.art
117-
echo "---------------------------------------------------"
118-
echo "Welcome to the 'ibex-demo-system' nix environment!"
119-
echo "---------------------------------------------------"
120-
121-
helpstr=$(cat <<'EOF'
122-
123-
Build ibex software :
124-
mkdir sw/c/build && pushd sw/c/build && cmake ../ && make && popd
125-
Build ibex simulation verilator model :
126-
fusesoc --cores-root=. run --target=sim --tool=verilator --setup --build lowrisc:ibex:demo_system
127-
Run ibex simulator verilator model :
128-
./build/lowrisc_ibex_demo_system_0/sim-verilator/Vibex_demo_system -t \
129-
--meminit=ram,sw/c/build/demo/hello_world/demo
130-
Build ibex-demo-system FPGA bitstream for Arty-A7 :
131-
fusesoc --cores-root=. run --target=synth --setup --build lowrisc:ibex:demo_system
132-
Program Arty-A7 FPGA with bitstream :
133-
openFPGALoader -b arty_a7_35t build/lowrisc_ibex_demo_system_0/synth-vivado/lowrisc_ibex_demo_system_0.bit
134-
Load ibex software to the programmed FPGA :
135-
./util/load_demo_system.sh run ./sw/c/build/demo/lcd_st7735/lcd_st7735
136-
Start an OpenOCD instance, connected to the Arty-A7 ibex
137-
openocd -f util/arty-a7-openocd-cfg.tcl
138-
Connect gdb to a running program on the FPGA (In a different terminal to the OpenOCD instance):
139-
riscv32-unknown-elf-gdb -ex "target extended-remote localhost:3333" ./sw/c/build/demo/hello_world/demo
140-
141-
To leave the environment:
142-
exit
143-
144-
EOF
145-
)
146-
helpme(){ echo "$helpstr"; }
147-
helpme
148-
149-
echo
150-
echo "Run 'helpme' in your shell to see this message again."
151-
echo
152-
'';
153-
};
154-
formatter = pkgs.alejandra;
155-
})
156-
)
157-
// {
158-
overlay = final: prev: {};
159-
overlays = {exampleOverlay = self.overlay;};
160-
161-
# Utilized by `nix run .#<name>`
162-
# apps.x86_64-linux.hello = {
163-
# type = "app";
164-
# program = c-hello.packages.x86_64-linux.hello;
165-
# };
166-
167-
# Utilized by `nix run . -- <args?>`
168-
# defaultApp.x86_64-linux = self.apps.x86_64-linux.hello;
169-
};
23+
}: let
24+
all_system_outputs = flake-utils.lib.eachDefaultSystem (system: let
25+
pkgs = import nixpkgs {
26+
inherit system;
27+
config = {allowUnfree = true;};
28+
overlays = [
29+
# Add extra packages we might need
30+
# Currently this contains spike
31+
deps.overlay_pkgs
32+
# Add all the python packages we need that aren't in nixpkgs
33+
# (See the ./dependencies folder for more info)
34+
(final: prev: {
35+
python3 = prev.python3.override {
36+
packageOverrides = deps.overlay_python;
37+
};
38+
})
39+
];
40+
};
41+
42+
pythonEnv = pkgs.python3.withPackages (
43+
ps:
44+
with ps; [pip fusesoc edalize pyyaml Mako]
45+
);
46+
47+
# This is the final list of dependencies we need to build the project.
48+
project_deps =
49+
[
50+
pythonEnv
51+
]
52+
++ (with pkgs; [
53+
cmake
54+
openocd
55+
screen
56+
verilator
57+
58+
# Currently we don't build the riscv-toolchain from src, we use a github release
59+
# See https://github.com/lowRISC/lowrisc-nix/blob/main/pkgs/lowrisc-toolchain-gcc-rv32imcb.nix
60+
61+
# riscv-toolchain (built from src) # BROKEN
62+
# riscv-gcc-toolchain-lowrisc-src = pkgs.callPackage \
63+
# ./dependencies/riscv_gcc.nix {
64+
# riscv-arch = "rv32imc";
65+
# };
66+
lowrisc-nix.packages.${system}.lowrisc-toolchain-gcc-rv32imcb
67+
68+
gtkwave
69+
srecord
70+
openfpgaloader
71+
libelf
72+
zlib
73+
# vivado
74+
]);
75+
in {
76+
devShells.default = pkgs.mkShell {
77+
name = "labenv";
78+
buildInputs = project_deps;
79+
shellHook = ''
80+
# FIXME This works on Ubuntu, may not on other distros. FIXME
81+
export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive
82+
83+
# HACK fixup some paths to use our sandboxed python environment
84+
# Currently, fusesoc tries to invoke the program 'python3' from the
85+
# PATH, which when running under a nix python environment, resolves
86+
# to the raw python binary, not wrapped and not including the
87+
# environment's packages. Hence, the first time an import is evaluated
88+
# we will error out.
89+
sed -i -- \
90+
's|interpreter:.*|interpreter: ${pythonEnv}/bin/python3|g' \
91+
vendor/lowrisc_ibex/vendor/lowrisc_ip/dv/tools/ralgen/ralgen.core
92+
sed -i -- \
93+
's|interpreter:.*|interpreter: ${pythonEnv}/bin/python3|g' \
94+
vendor/lowrisc_ibex/vendor/lowrisc_ip/ip/prim/primgen.core
95+
96+
export PS1='labenv(HiPEAC) (ibex-demo-system) \$ '
97+
98+
echo
99+
echo
100+
cat ./data/lowrisc.art
101+
echo "---------------------------------------------------"
102+
echo "Welcome to the 'ibex-demo-system' nix environment!"
103+
echo "---------------------------------------------------"
104+
105+
helpstr=$(cat <<'EOF'
106+
107+
Build ibex software :
108+
mkdir sw/c/build && pushd sw/c/build && cmake ../ && make && popd
109+
Build ibex simulation verilator model :
110+
fusesoc --cores-root=. run --target=sim --tool=verilator --setup --build lowrisc:ibex:demo_system
111+
Run ibex simulator verilator model :
112+
./build/lowrisc_ibex_demo_system_0/sim-verilator/Vibex_demo_system -t \
113+
--meminit=ram,sw/c/build/demo/hello_world/demo
114+
Build ibex-demo-system FPGA bitstream for Arty-A7 :
115+
fusesoc --cores-root=. run --target=synth --setup --build lowrisc:ibex:demo_system
116+
Program Arty-A7 FPGA with bitstream :
117+
openFPGALoader -b arty_a7_35t build/lowrisc_ibex_demo_system_0/synth-vivado/lowrisc_ibex_demo_system_0.bit
118+
Load ibex software to the programmed FPGA :
119+
./util/load_demo_system.sh run ./sw/c/build/demo/lcd_st7735/lcd_st7735
120+
Start an OpenOCD instance, connected to the Arty-A7 ibex
121+
openocd -f util/arty-a7-openocd-cfg.tcl
122+
Connect gdb to a running program on the FPGA (In a different terminal to the OpenOCD instance):
123+
riscv32-unknown-elf-gdb -ex "target extended-remote localhost:3333" ./sw/c/build/demo/hello_world/demo
124+
125+
To leave the environment:
126+
exit
127+
128+
EOF
129+
)
130+
helpme(){ echo "$helpstr"; }
131+
helpme
132+
133+
echo
134+
echo "Run 'helpme' in your shell to see this message again."
135+
echo
136+
'';
137+
};
138+
formatter = pkgs.alejandra;
139+
});
140+
in
141+
all_system_outputs;
170142
}

0 commit comments

Comments
 (0)