-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build scripts for v6.10 riscv64 kernel, qemu-system-riscv64 and opensbi required to boot qemu-system inside docker container. With this approach, we are able to run tests inside qemu-system, while preserving the original output as much as possbile with ssh. This work was inspired by the work done by @endeneer in PR #91, and is the third draft proceeds #101, #104. It is expected to be replaced by the second draft #104 in the future which standardise `riscv64`. Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
- Loading branch information
1 parent
2e2e495
commit 2c5cdf9
Showing
9 changed files
with
318 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Compile QEMU 9.0.2 | ||
# --------------------------------------------------------- | ||
FROM ubuntu:22.04 AS qemu_builder | ||
|
||
COPY riscv64/build_qemu_system_riscv64.sh /opt/src/scripts/build.sh | ||
RUN /opt/src/scripts/build.sh | ||
|
||
# Compile kernel 6.10 since we need AIA drivers | ||
# --------------------------------------------------------- | ||
FROM ubuntu:22.04 AS kernel_builder | ||
|
||
COPY riscv64/build_kernel.sh /opt/src/scripts/build.sh | ||
RUN /opt/src/scripts/build.sh | ||
|
||
# Compile OpenSBI | ||
# --------------------------------------------------------- | ||
FROM ubuntu:22.04 AS opensbi_builder | ||
|
||
COPY riscv64/build_opensbi.sh /opt/src/scripts/build.sh | ||
RUN /opt/src/scripts/build.sh | ||
|
||
# Build rootfs with sshd and Rust related packages ready | ||
# --------------------------------------------------------- | ||
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 AS rootfs_builder | ||
|
||
ARG RUST_TOOLCHAIN="1.75.0" | ||
ENV PATH="$PATH:/root/.cargo/bin" | ||
COPY build_container.sh /opt/src/scripts/build.sh | ||
RUN /opt/src/scripts/build.sh | ||
|
||
# Finalize | ||
# --------------------------------------------------------- | ||
FROM ubuntu:22.04 AS final | ||
|
||
ARG OUTPUT=/output | ||
ARG QEMU_DIR=/opt/qemu | ||
ARG KERNEL_DIR=/opt/kernel | ||
ARG OPENSBI_DIR=/opt/opensbi | ||
ARG ROOTFS_DIR=/opt/rootfs | ||
|
||
COPY --from=qemu_builder $OUTPUT $QEMU_DIR | ||
COPY --from=kernel_builder $OUTPUT $KERNEL_DIR | ||
COPY --from=opensbi_builder $OUTPUT $OPENSBI_DIR | ||
COPY --from=rootfs_builder / $ROOTFS_DIR | ||
|
||
COPY riscv64/build_finalize.sh /opt/src/scripts/finalize.sh | ||
RUN /opt/src/scripts/finalize.sh | ||
|
||
ENV QEMU_DIR=$QEMU_DIR KERNEL_DIR=$KERNEL_DIR \ | ||
OPENSBI_DIR=$OPENSBI_DIR ROOTFS_DIR=$ROOTFS_DIR \ | ||
WORKDIR=/workdir | ||
|
||
# Start qemu-system-riscv64 as a background process | ||
COPY riscv64/start_in_qemu.sh /opt/src/scripts/start.sh | ||
ENTRYPOINT ["/opt/src/scripts/start.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
apt-get update | ||
|
||
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ | ||
openssh-client libslirp-dev libfdt-dev libglib2.0-dev libssl-dev \ | ||
libpixman-1-dev netcat | ||
|
||
# Setup container ssh config | ||
yes "" | ssh-keygen -P "" | ||
cat /root/.ssh/id_rsa.pub > $ROOTFS_DIR/root/.ssh/authorized_keys | ||
cat > /root/.ssh/config << EOF | ||
Host riscv-qemu | ||
HostName localhost | ||
User root | ||
Port 2222 | ||
StrictHostKeyChecking no | ||
EOF | ||
|
||
# Set `nameserver` for `resolv.conf` | ||
echo 'nameserver 8.8.8.8' > $ROOTFS_DIR/etc/resolv.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
apt-get update | ||
|
||
KERNEL_TAG=v6.10 | ||
OUTPUT=/output | ||
mkdir $OUTPUT | ||
|
||
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ | ||
git python3 python3-pip ninja-build build-essential pkg-config curl bc jq \ | ||
libslirp-dev libfdt-dev libglib2.0-dev libssl-dev libpixman-1-dev \ | ||
flex bison gcc-riscv64-linux-gnu | ||
|
||
git clone --depth 1 --branch $KERNEL_TAG https://github.com/torvalds/linux.git | ||
pushd linux | ||
# Enable kvm module instead of inserting manually | ||
sed -i "s|^CONFIG_KVM=.*|CONFIG_KVM=y|g" arch/riscv/configs/defconfig | ||
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- defconfig && \ | ||
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc) | ||
mv arch/riscv/boot/Image $OUTPUT | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
apt-get update | ||
|
||
OPENSBI_TAG=v1.3.1 | ||
OUTPUT=/output | ||
mkdir $OUTPUT | ||
|
||
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ | ||
git python3 python3-pip ninja-build build-essential pkg-config curl bc jq \ | ||
libslirp-dev libfdt-dev libglib2.0-dev libssl-dev libpixman-1-dev \ | ||
flex bison gcc-riscv64-linux-gnu | ||
|
||
git clone --depth 1 --branch $OPENSBI_TAG https://github.com/riscv-software-src/opensbi.git | ||
pushd opensbi | ||
make -j$(nproc) PLATFORM=generic CROSS_COMPILE=riscv64-linux-gnu- | ||
mv build/platform/generic/firmware/fw_jump.elf $OUTPUT | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
set -ex | ||
|
||
apt-get update | ||
|
||
QEMU_TAG=v9.0.2 | ||
OUTPUT=/output | ||
mkdir $OUTPUT | ||
|
||
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \ | ||
git python3 python3-pip ninja-build build-essential pkg-config curl bc jq \ | ||
libslirp-dev libfdt-dev libglib2.0-dev libssl-dev libpixman-1-dev \ | ||
flex bison | ||
|
||
git clone --depth 1 --branch $QEMU_TAG https://gitlab.com/qemu-project/qemu.git | ||
pushd qemu | ||
./configure --target-list=riscv64-softmmu --prefix=$OUTPUT && \ | ||
make -j$(nproc) && make install | ||
popd |
Oops, something went wrong.