Skip to content
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

Simulation documentation: add Docker instructions #359

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions doc/dev/simulation.md
Original file line number Diff line number Diff line change
@@ -26,6 +26,67 @@ fusesoc --cores-root=. run \

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

## Notes on building natively

**This is only for advanced users.**

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:

```Dockerfile
# Download LLVM toolchain
FROM ubuntu:24.04 as llvm-download
RUN apt update && apt install -y curl unzip
RUN curl -O https://api.cirrus-ci.com/v1/artifact/github/CHERIoT-Platform/llvm-project/Build%20and%20upload%20artefact%20$(uname -p)/binaries.zip
RUN unzip binaries.zip

# Build Verilator
FROM ubuntu:24.04 AS verilator-build
# Verilator dependencies
RUN apt update && apt install -y git help2man perl python3 make g++ libfl2 libfl-dev zlib1g zlib1g-dev autoconf flex bison
WORKDIR /
# Build Verilator
RUN git clone https://github.com/verilator/verilator
WORKDIR verilator
RUN git checkout v5.024
RUN mkdir install
RUN autoconf \
&& ./configure --prefix=/verilator/install \
&& make -j `nproc` \
&& make install

# Build Sonata simulator
FROM ubuntu:24.04 as sonata-build
# Sonata dependencies
RUN apt update && apt install -y git python3 python3-venv build-essential libelf-dev libxml2-dev
# Install LLVM for sim boot stub.
RUN mkdir -p /cheriot-tools/bin
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/
# Create the LLVM tool symlinks.
RUN cd /cheriot-tools/bin \
&& ln -s clang-13 clang \
&& ln -s clang clang++ \
&& ln -s lld ld.lld \
&& ln -s llvm-objcopy objcopy \
&& ln -s llvm-objdump objdump \
&& chmod +x *
COPY --from=verilator-build "/verilator/install" /verilator
WORKDIR /
# Build Sonata simulator
RUN git clone https://github.com/lowRISC/sonata-system
WORKDIR sonata-system
RUN python3 -m venv .venv \
&& . .venv/bin/activate \
&& pip install -r python-requirements.txt \
&& export PATH=/verilator/bin:$PATH \
&& fusesoc --cores-root=. run --target=sim --tool=verilator --setup --build lowrisc:sonata:system
RUN cp build/lowrisc_sonata_system_0/sim-verilator/Vtop_verilator /sonata_simulator
# Build Sonata simulator boot stub
WORKDIR sw/cheri/sim_boot_stub
RUN export PATH=/cheriot-tools/bin:$PATH \
&& make
RUN cp sim_boot_stub /sonata_simulator_boot_stub
```

## Running baremetal

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