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

Add network support to Pi2/3 #21

Merged
merged 17 commits into from May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions Dockerfile
@@ -1,6 +1,6 @@
# Build stage for qemu-system-arm
FROM debian:stable-slim AS qemu-builder
ARG QEMU_VERSION=4.2.0
ARG QEMU_VERSION=6.0.0
ENV QEMU_TARBALL="qemu-${QEMU_VERSION}.tar.xz"
WORKDIR /qemu

Expand All @@ -23,7 +23,7 @@ RUN tar xvf "${QEMU_TARBALL}"

RUN # Build source
# These seem to be the only deps actually required for a successful build
RUN apt-get -y install python build-essential libglib2.0-dev libpixman-1-dev
RUN apt-get -y install python build-essential libglib2.0-dev libpixman-1-dev ninja-build
# These don't seem to be required but are specified here: https://wiki.qemu.org/Hosts/Linux
RUN apt-get -y install libfdt-dev zlib1g-dev
# Not required or specified anywhere but supress build warnings
Expand All @@ -32,7 +32,7 @@ RUN "qemu-${QEMU_VERSION}/configure" --static --target-list=arm-softmmu,aarch64-
RUN make -j$(nproc)

RUN # Strip the binary, this gives a substantial size reduction!
RUN strip "arm-softmmu/qemu-system-arm" "aarch64-softmmu/qemu-system-aarch64"
RUN strip "arm-softmmu/qemu-system-arm" "aarch64-softmmu/qemu-system-aarch64" "qemu-img"


# Build stage for fatcat
Expand Down Expand Up @@ -67,6 +67,7 @@ ARG RPI_KERNEL_CHECKSUM="295a22f1cd49ab51b9e7192103ee7c917624b063cc5ca2e11434164

COPY --from=qemu-builder /qemu/arm-softmmu/qemu-system-arm /usr/local/bin/qemu-system-arm
COPY --from=qemu-builder /qemu/aarch64-softmmu/qemu-system-aarch64 /usr/local/bin/qemu-system-aarch64
COPY --from=qemu-builder /qemu/qemu-img /usr/local/bin/qemu-img
lukechilds marked this conversation as resolved.
Show resolved Hide resolved
COPY --from=fatcat-builder /fatcat/fatcat /usr/local/bin/fatcat

ADD $RPI_KERNEL_URL /tmp/qemu-rpi-kernel.zip
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -60,7 +60,7 @@ docker run -it lukechilds/dockerpi pi2
docker run -it lukechilds/dockerpi pi3
```

> **Note:** Pi 2 and Pi 3 support is currently experimental. Networking doesn't work and QEMU hangs once the machines are powered down requiring you to `docker kill` the container. See [#4](https://github.com/lukechilds/dockerpi/pull/4) for details.
> **Note:** In the Pi 2 and Pi 3 machines, QEMU hangs once the machines are powered down requiring you to `docker kill` the container. See [#4](https://github.com/lukechilds/dockerpi/pull/4) for details.


## Wait, what?
Expand Down
24 changes: 18 additions & 6 deletions entrypoint.sh
@@ -1,5 +1,7 @@
#!/bin/sh

GIB_IN_BYTES="1073741824"

target="${1:-pi1}"
image_path="/sdcard/filesystem.img"
zip_path="/filesystem.zip"
Expand All @@ -15,28 +17,38 @@ if [ ! -e $image_path ]; then
fi
fi

qemu-img info $image_path
image_size_in_bytes=$(qemu-img info --output json $image_path | grep "virtual-size" | awk '{print $2}' | sed 's/,//')
if [[ "$(($image_size_in_bytes % ($GIB_IN_BYTES * 2)))" != "0" ]]; then
new_size_in_gib=$((($image_size_in_bytes / ($GIB_IN_BYTES * 2) + 1) * 2))
echo "Rounding image size up to ${new_size_in_gib}GiB so it's a multiple of 2GiB..."
qemu-img resize $image_path "${new_size_in_gib}G"
fi

if [ "${target}" = "pi1" ]; then
emulator=qemu-system-arm
kernel="/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster"
dtb="/root/qemu-rpi-kernel/versatile-pb.dtb"
machine=versatilepb
memory=256m
root=/dev/sda2
nic='--net nic --net user,hostfwd=tcp::5022-:22'
nic="--net nic --net user,hostfwd=tcp::5022-:22"
elif [ "${target}" = "pi2" ]; then
emulator=qemu-system-arm
machine=raspi2
machine=raspi2b
lukechilds marked this conversation as resolved.
Show resolved Hide resolved
memory=1024m
kernel_pattern=kernel7.img
dtb_pattern=bcm2709-rpi-2-b.dtb
nic=''
append="dwc_otg.fiq_fsm_enable=0"
nic="-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
elif [ "${target}" = "pi3" ]; then
emulator=qemu-system-aarch64
machine=raspi3
machine=raspi3b
memory=1024m
kernel_pattern=kernel8.img
dtb_pattern=bcm2710-rpi-3-b-plus.dtb
nic=''
append="dwc_otg.fiq_fsm_enable=0"
nic="-netdev user,id=net0,hostfwd=tcp::5022-:22 -device usb-net,netdev=net0"
else
echo "Target ${target} not supported"
echo "Supported targets: pi1 pi2 pi3"
Expand Down Expand Up @@ -78,7 +90,7 @@ exec ${emulator} \
${nic} \
--dtb "${dtb}" \
--kernel "${kernel}" \
--append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=${root} rootwait panic=1" \
--append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=${root} rootwait panic=1 ${append}" \
--no-reboot \
--display none \
--serial mon:stdio