Skip to content

Commit

Permalink
vm: Add new board type 'pivirt' for performance reaosons.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosperate committed Dec 31, 2023
1 parent 37ac36b commit 49c922b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
34 changes: 34 additions & 0 deletions vm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,39 @@ RUN cmake fatcat-* -DCMAKE_CXX_FLAGS='-static'
RUN make -j$(nproc)


# Building the kernell for virt Qemu machine type
FROM ubuntu:23.10 AS kernel-builder

ARG KERNEL_VERSION=5.10.205
ARG KERNEL_URL="https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${KERNEL_VERSION}.tar.xz"
ARG KERNEL_SIG="https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-${KERNEL_VERSION}.tar.sign"

RUN # Install cross compiler, build tools, and other dependencies
RUN apt-get update -qq && \
apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi && \
apt-get install -y build-essential flex bison libssl-dev libelf-dev bc && \
apt-get install -y wget xz-utils

RUN # Pull source
WORKDIR /kernel
RUN wget "${KERNEL_URL}" && \
tar xvJf linux-${KERNEL_VERSION}.tar.xz
WORKDIR /kernel/linux-${KERNEL_VERSION}

RUN # Build kernel
RUN export ARCH=arm && \
export CROSS_COMPILE=arm-linux-gnueabi- && \
export CONFIG_PCI=y && \
export CONFIG_VIRTIO_PCI=y && \
export CONFIG_PCI_HOST_GENERIC=y && \
export CONFIG_DRM=y && \
export CONFIG_DRM_VIRTIO_GPU=y && \
make defconfig && \
make kvm_guest.config && \
make -j$(nproc)
RUN mv arch/arm/boot/ ../boot


# Build the dockerpi VM image
FROM busybox:1.36 AS dockerpi-vm
LABEL maintainer="Luke Childs <lukechilds123@gmail.com>"
Expand All @@ -72,6 +105,7 @@ COPY --from=qemu-builder /qemu/build/arm-softmmu/qemu-system-arm /usr/local/bin/
COPY --from=qemu-builder /qemu/build/aarch64-softmmu/qemu-system-aarch64 /usr/local/bin/qemu-system-aarch64
COPY --from=qemu-builder /qemu/build/qemu-img /usr/local/bin/qemu-img
COPY --from=fatcat-builder /fatcat/fatcat /usr/local/bin/fatcat
COPY --from=kernel-builder /kernel/boot/zImage /root/zImage

ADD $RPI_KERNEL_URL /tmp/qemu-rpi-kernel.zip

Expand Down
6 changes: 6 additions & 0 deletions vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ List of changes:
https://bugs.launchpad.net/ubuntu/+source/libslirp/+bug/2029431
https://www.mail-archive.com/qemu-devel@nongnu.org/msg903610.html
- `entrypoint.sh`: Output of `qemu-img info` now returns multiple `virtual-size` keys and only one needed
- Create an additional board type for performance reasons
- https://github.com/carlosperate/docker-qemu-rpi-os/issues/3
- Uses the `virt` machine type: https://www.qemu.org/docs/master/system/arm/virt.html
- This is not an accurate Pi emulation, but has better performance and 1 GB of RAM
- Docker image has to build the kernel, as the pi kernel does not include the required configuration
- commit [xxxxx](https://github.com/carlosperate/docker-qemu-rpi-os/commit/xxxx)
- Added developer documentation for this fork to parent directory [../dev-docs.md](../dev-docs.md)

The rest of the original README can be seen below.
Expand Down
41 changes: 36 additions & 5 deletions vm/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ if [ "${target}" = "pi1" ]; then
kernel="/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster"
dtb="/root/qemu-rpi-kernel/versatile-pb.dtb"
machine=versatilepb
cpu=arm1176
smp=1
memory=256m
root=/dev/sda2
nic="--net nic --net user,hostfwd=tcp::5022-:22"
elif [ "${target}" = "pi2" ]; then
emulator=qemu-system-arm
machine=raspi2b
cpu=cortex-a7
smp=4
memory=1024m
kernel_pattern=kernel7.img
dtb_pattern=bcm2709-rpi-2-b.dtb
Expand All @@ -44,11 +48,29 @@ elif [ "${target}" = "pi2" ]; then
elif [ "${target}" = "pi3" ]; then
emulator=qemu-system-aarch64
machine=raspi3b
cpu=cortex-a53
smp=4
memory=1024m
kernel_pattern=kernel8.img
dtb_pattern=bcm2710-rpi-3-b-plus.dtb
append="dwc_otg.fiq_fsm_enable=0"
nic="-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
elif [ "${target}" = "pivirt" ]; then
emulator=qemu-system-arm
machine=virt
cpu=cortex-a7
smp="$(nproc)"
memory=1024m
dtb_pattern=""
#dtb="/root/qemu-rpi-kernel/bcm2836-rpi-2-b.dtb"
dtb=""
kernel_pattern=""
kernel="/root/zImage"
append=""
root=/dev/vda2
nic="-netdev user,id=mynet,hostfwd=tcp::5022-:22 -device virtio-net-device,netdev=mynet"
img_options=",if=none,id=hd0"
drive_extra="-device virtio-blk-device,drive=hd0,bootindex=0"
else
echo "Target ${target} not supported"
echo "Supported targets: pi1 pi2 pi3"
Expand Down Expand Up @@ -76,19 +98,28 @@ if [ "${kernel_pattern}" ] && [ "${dtb_pattern}" ]; then
dtb=$(find "${fat_folder}" -name "${dtb_pattern}")
fi

if [ "${kernel}" = "" ] || [ "${dtb}" = "" ]; then
echo "Missing kernel='${kernel}' or dtb='${dtb}'"
if [ "${kernel}" = "" ] || ([ "${dtb}" = "" ] && [ "${dtb_pattern}" != "" ]); then
echo "Missing kernel='${kernel}' or (dtb='${dtb}' for dtb_pattern='${dtb_pattern}')"
exit 2
fi

# Some configurations don't need a dtb file and the flag should be skipped
if [ -n "$dtb" ]; then
dtb_flag="--dtb ${dtb}"
else
dtb_flag=""
fi

echo "Booting QEMU machine \"${machine}\" with kernel=${kernel} dtb=${dtb}"
set -x
exec ${emulator} \
--machine "${machine}" \
--cpu arm1176 \
--cpu "${cpu}" \
--smp "${smp}" \
--m "${memory}" \
--drive "format=raw,file=${image_path}" \
--drive "format=raw,file=${image_path}${img_options}" ${drive_extra} \
${nic} \
--dtb "${dtb}" \
${dtb_flag} \
--kernel "${kernel}" \
--append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=${root} rootwait panic=1 ${append}" \
--no-reboot \
Expand Down

0 comments on commit 49c922b

Please sign in to comment.