Skip to content

Commit

Permalink
Update riscv GCC and sail reference device dockerfiles
Browse files Browse the repository at this point in the history
Reference: sysprog21#444
  • Loading branch information
henrybear327 committed Jun 16, 2024
1 parent dd9fcca commit c718b4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
18 changes: 10 additions & 8 deletions docker/Dockerfile-gcc
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
FROM ubuntu:22.04 as base
# we align the version used in riscv-toolchain-install.sh

# when using apt install gcc-riscv64-unknown-elf, this will cause "unsupported ISA subset 'z'" during compilation
# thus, we are building from scratch, following the version here -> https://github.com/sysprog21/rv32emu/blob/master/.ci/riscv-toolchain-install.sh
# for x86-64, we can optimize this part and take the nightly build directly, but not for aarch64
FROM ubuntu:24.04 as base

# for x86-64, we can optimize this part and take the upstream (nightly) build directly
# for aarch64, we need to build from scratch because the upstream toolchain is only built for x86-64
RUN apt-get update && \
apt install -y \
git autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev && \
git && \
rm -rf /var/lib/apt/lists/*
RUN git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
RUN cd riscv-gnu-toolchain && \
git checkout tags/2023.10.06 && \
./.github/setup-apt.sh && rm -rf /var/lib/apt/lists/* && \
git checkout tags/2024.04.12 && \
./configure --prefix=/opt/riscv --with-arch=rv32gc --with-abi=ilp32d && \
make -j$(nproc) && \
make -j$(nproc) newlib && \
make clean

FROM ubuntu:22.04 as final
FROM ubuntu:24.04 as final

# Keep the GNU Toolchain files only
COPY --from=base /opt/riscv/ /opt/riscv/
26 changes: 12 additions & 14 deletions docker/Dockerfile-sail
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
# builds the base image of rv32emu (the toolchains)
# docker build --progress=plain -t sysprog21/rv32emu-base -f Dockerfile-base . 2>&1 | tee build.log
FROM ubuntu:22.04 as base
FROM ubuntu:24.04 as base

# the default reference emulator is x86-64-based
# we need to build it ourselves if we are using it on aarch64
# https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models
# the above commands are modified to match the current build flow as indicated in the Github CI -> https://github.com/riscv/sail-riscv/blob/master/.github/workflows/compile.yml
# The upstream reference emulator is built for x86-64, and the releases are pretty out of date
# Thus, we build it ourselves for both x86-64 and aarch64
#
# The following dockerfile commands are modified from references [1][2]
# Dependencies are pinned at certain versions. Within pinning, the build won't be reproducible
# [1] https://riscof.readthedocs.io/en/stable/installation.html#install-plugin-models
# [2] https://github.com/riscv/sail-riscv/blob/master/.github/workflows/compile.yml
RUN apt-get update && \
apt install -y opam zlib1g-dev pkg-config libgmp-dev z3 device-tree-compiler && \
rm -rf /var/lib/apt/lists/*
RUN opam init --disable-sandboxing -y
RUN opam switch create ocaml-base-compiler.4.13.1 # opam switch list-available
RUN opam switch create ocaml-base-compiler.5.2.0 # opam switch list-available
RUN opam search sail
# https://opam.ocaml.org/packages/sail/sail.0.16/
RUN opam install -y sail.0.16 # latest version 0.17.x will cause complication issues for sail-riscv on commit 9547a3
RUN opam install -y sail.0.17.1
RUN git clone https://github.com/riscv/sail-riscv.git
# based on this commit https://github.com/sysprog21/rv32emu/commit/01b00b6f175f57ef39ffd1f4fa6a611891e36df3#diff-3b436c5e32c40ecca4095bdacc1fb69c0759096f86e029238ce34bbe73c6e68f
# we infer that the sail-riscv binary was taken from commit 9547a30bf84572c458476591b569a95f5232c1c7
RUN cd sail-riscv && \
git checkout 9547a30bf84572c458476591b569a95f5232c1c7 && \
git checkout 0e9850fed5bee44346e583f334c6e2a6a25d5cd3 && \
eval $(opam env) && \
make && \
ARCH=RV32 make

FROM ubuntu:22.04 as final
FROM ubuntu:24.04 as final

# keep the emulator only
COPY --from=base /sail-riscv/c_emulator/riscv_sim_RV32 /home/root/riscv_sim_RV32

0 comments on commit c718b4a

Please sign in to comment.