Skip to content

Commit 46497b7

Browse files
Simulation documentation: add Docker instructions
1 parent 4a52971 commit 46497b7

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

doc/dev/simulation.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,67 @@ fusesoc --cores-root=. run \
2626

2727
*To enable tracing append, `--verilator_options='+define+RVFI'` to the command above.*
2828

29+
## Notes on building natively
30+
31+
**This is only for advanced users.**
32+
33+
If for some reason you do not want to use the nix environment and need to set up your own environment, here are some commands that you can use if you're running using podman or Docker:
34+
35+
```Dockerfile
36+
# Download LLVM toolchain
37+
FROM ubuntu:24.04 as llvm-download
38+
RUN apt update && apt install -y curl unzip
39+
RUN curl -O https://api.cirrus-ci.com/v1/artifact/github/CHERIoT-Platform/llvm-project/Build%20and%20upload%20artefact%20$(uname -p)/binaries.zip
40+
RUN unzip binaries.zip
41+
42+
# Build Verilator
43+
FROM ubuntu:24.04 AS verilator-build
44+
# Verilator dependencies
45+
RUN apt update && apt install -y git help2man perl python3 make g++ libfl2 libfl-dev zlib1g zlib1g-dev autoconf flex bison
46+
WORKDIR /
47+
# Build Verilator
48+
RUN git clone https://github.com/verilator/verilator
49+
WORKDIR verilator
50+
RUN git checkout v5.024
51+
RUN mkdir install
52+
RUN autoconf \
53+
&& ./configure --prefix=/verilator/install \
54+
&& make -j `nproc` \
55+
&& make install
56+
57+
# Build Sonata simulator
58+
FROM ubuntu:24.04 as sonata-build
59+
# Sonata dependencies
60+
RUN apt update && apt install -y git python3 python3-venv build-essential libelf-dev libxml2-dev
61+
# Install LLVM for sim boot stub.
62+
RUN mkdir -p /cheriot-tools/bin
63+
COPY --from=llvm-download "/Build/install/bin/clang-13" "/Build/install/bin/lld" "/Build/install/bin/llvm-objcopy" "/Build/install/bin/llvm-objdump" "/Build/install/bin/clangd" "/Build/install/bin/clang-format" "/Build/install/bin/clang-tidy" /cheriot-tools/bin/
64+
# Create the LLVM tool symlinks.
65+
RUN cd /cheriot-tools/bin \
66+
&& ln -s clang-13 clang \
67+
&& ln -s clang clang++ \
68+
&& ln -s lld ld.lld \
69+
&& ln -s llvm-objcopy objcopy \
70+
&& ln -s llvm-objdump objdump \
71+
&& chmod +x *
72+
COPY --from=verilator-build "/verilator/install" /verilator
73+
WORKDIR /
74+
# Build Sonata simulator
75+
RUN git clone https://github.com/lowRISC/sonata-system
76+
WORKDIR sonata-system
77+
RUN python3 -m venv .venv \
78+
&& . .venv/bin/activate \
79+
&& pip install -r python-requirements.txt \
80+
&& export PATH=/verilator/bin:$PATH \
81+
&& fusesoc --cores-root=. run --target=sim --tool=verilator --setup --build lowrisc:sonata:system
82+
RUN cp build/lowrisc_sonata_system_0/sim-verilator/Vtop_verilator /sonata_simulator
83+
# Build Sonata simulator boot stub
84+
WORKDIR sw/cheri/sim_boot_stub
85+
RUN export PATH=/cheriot-tools/bin:$PATH \
86+
&& make
87+
RUN cp sim_boot_stub /sonata_simulator_boot_stub
88+
```
89+
2990
## Running baremetal
3091

3192
Running the simulator can be accomplished with the following command, where you can change the `meminit` argument to a different program if you wish:

0 commit comments

Comments
 (0)