• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# based on armhf-gnu/Dockerfile
2FROM ubuntu:20.04
3
4RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
5RUN apt-get update -y && apt-get install -y --no-install-recommends \
6    bc \
7    bison \
8    ca-certificates \
9    cmake \
10    cpio \
11    curl \
12    debian-ports-archive-keyring \
13    debootstrap \
14    flex \
15    gcc \
16    gcc-riscv64-linux-gnu \
17    git \
18    g++-riscv64-linux-gnu \
19    g++ \
20    libc6-dev \
21    libc6-dev-riscv64-cross \
22    make \
23    ninja-build \
24    patch \
25    python3 \
26    qemu-system-misc \
27    xz-utils
28
29ENV ARCH=riscv
30ENV CROSS_COMPILE=riscv64-linux-gnu-
31
32WORKDIR /build
33
34# From https://github.com/michaeljclark/busybear-linux/blob/master/conf/linux.config
35COPY host-x86_64/riscv64gc-linux/linux.config /build
36
37# Compile the kernel that we're going to be emulating with. This is
38# basically just done to be compatible with the QEMU target that we're going
39# to be using when running tests.
40RUN curl https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.6.16.tar.xz | tar xJf - && \
41    cp linux.config linux-5.6.16/.config && \
42    cd /build/linux-5.6.16 && \
43    make olddefconfig && \
44    make -j$(nproc) vmlinux && \
45    cp vmlinux /tmp && \
46    rm -rf linux-5.6.16
47
48# Compile an instance of busybox as this provides a lightweight system and init
49# binary which we will boot into. Only trick here is configuring busybox to
50# build static binaries.
51RUN curl https://busybox.net/downloads/busybox-1.31.1.tar.bz2 | tar xjf -
52COPY host-x86_64/riscv64gc-linux/0001-Remove-stime-function-calls.patch /build/busybox-1.31.1/
53RUN cd /build/busybox-1.31.1 && \
54    patch -p1 -i 0001-Remove-stime-function-calls.patch && \
55    make defconfig && \
56    sed -i 's/.*CONFIG_STATIC.*/CONFIG_STATIC=y/' .config && \
57    make -j$(nproc) && \
58    make install && \
59    mv _install /tmp/rootfs && \
60    cd /build && \
61    rm -rf busybox-1.31.1
62
63# Download the ubuntu rootfs, which we'll use as a chroot for all our tests
64# This is only needed to provide /lib/* and /usr/lib/*
65WORKDIR /tmp
66RUN debootstrap --variant=minbase --arch=riscv64 --foreign focal /tmp/rootfs/ubuntu
67RUN cd rootfs && mkdir proc sys dev etc etc/init.d
68# rootfs/ubuntu/proc is in a weird state (access fails with ELOOP) until
69# rootfs/ubuntu/debootstrap/debootstrap --second-stage is run (under emulation),
70# but this takes ages. Instead hack it into a good enough state.
71# /proc is used by std::env::current_exe() (which is roughly
72# `readlink /proc/self/exe`)
73RUN cd rootfs/ubuntu && rm -rf proc && mkdir proc
74
75# Copy over our init script, which starts up our test server and also a few other
76# misc tasks
77COPY scripts/qemu-bare-bones-rcS rootfs/etc/init.d/rcS
78RUN chmod +x rootfs/etc/init.d/rcS
79
80# Helper to quickly fill the entropy pool in the kernel
81COPY scripts/qemu-bare-bones-addentropy.c /tmp/addentropy.c
82RUN riscv64-linux-gnu-gcc addentropy.c -o rootfs/addentropy -static
83
84# download and build the riscv bootloader
85RUN git clone https://github.com/riscv/riscv-pk
86WORKDIR /tmp/riscv-pk
87# This revision fixes a fault in recent QEMU from 64-bit accesses to the PLIC
88# commits later than this one should work too
89RUN git checkout 7d8b7c0dab72108e3ea7bb7744d3f6cc907c7ef4
90RUN mkdir build && cd build && \
91    ../configure --with-payload=/tmp/vmlinux --host=riscv64-linux-gnu && \
92    make -j$(nproc) && \
93    cp bbl /tmp
94WORKDIR /tmp
95RUN rm -rf /tmp/riscv-pk
96
97COPY scripts/sccache.sh /scripts/
98RUN sh /scripts/sccache.sh
99
100ENV RUST_CONFIGURE_ARGS --qemu-riscv64-rootfs=/tmp/rootfs
101ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target riscv64gc-unknown-linux-gnu
102
103ENV NO_CHANGE_USER=1
104