Browse Source

Add network support to Pi2/3 (#21)

Co-authored-by: Luke Childs <lukechilds123@gmail.com>
pull/48/head
Ben Hardill 3 years ago
committed by GitHub
parent
commit
6c1ac8edab
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      Dockerfile
  2. 2
      README.md
  3. 24
      entrypoint.sh

7
Dockerfile

@ -1,6 +1,6 @@
# Build stage for qemu-system-arm # Build stage for qemu-system-arm
FROM debian:stable-slim AS qemu-builder 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" ENV QEMU_TARBALL="qemu-${QEMU_VERSION}.tar.xz"
WORKDIR /qemu WORKDIR /qemu
@ -23,7 +23,7 @@ RUN tar xvf "${QEMU_TARBALL}"
RUN # Build source RUN # Build source
# These seem to be the only deps actually required for a successful build # 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 # 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 RUN apt-get -y install libfdt-dev zlib1g-dev
# Not required or specified anywhere but supress build warnings # Not required or specified anywhere but supress build warnings
@ -32,7 +32,7 @@ RUN "qemu-${QEMU_VERSION}/configure" --static --target-list=arm-softmmu,aarch64-
RUN make -j$(nproc) RUN make -j$(nproc)
RUN # Strip the binary, this gives a substantial size reduction! 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 # Build stage for fatcat
@ -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/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/aarch64-softmmu/qemu-system-aarch64 /usr/local/bin/qemu-system-aarch64
COPY --from=qemu-builder /qemu/qemu-img /usr/local/bin/qemu-img
COPY --from=fatcat-builder /fatcat/fatcat /usr/local/bin/fatcat COPY --from=fatcat-builder /fatcat/fatcat /usr/local/bin/fatcat
ADD $RPI_KERNEL_URL /tmp/qemu-rpi-kernel.zip ADD $RPI_KERNEL_URL /tmp/qemu-rpi-kernel.zip

2
README.md

@ -60,7 +60,7 @@ docker run -it lukechilds/dockerpi pi2
docker run -it lukechilds/dockerpi pi3 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? ## Wait, what?

24
entrypoint.sh

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
GIB_IN_BYTES="1073741824"
target="${1:-pi1}" target="${1:-pi1}"
image_path="/sdcard/filesystem.img" image_path="/sdcard/filesystem.img"
zip_path="/filesystem.zip" zip_path="/filesystem.zip"
@ -15,6 +17,14 @@ if [ ! -e $image_path ]; then
fi fi
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 if [ "${target}" = "pi1" ]; then
emulator=qemu-system-arm emulator=qemu-system-arm
kernel="/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster" kernel="/root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster"
@ -22,21 +32,23 @@ if [ "${target}" = "pi1" ]; then
machine=versatilepb machine=versatilepb
memory=256m memory=256m
root=/dev/sda2 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 elif [ "${target}" = "pi2" ]; then
emulator=qemu-system-arm emulator=qemu-system-arm
machine=raspi2 machine=raspi2b
memory=1024m memory=1024m
kernel_pattern=kernel7.img kernel_pattern=kernel7.img
dtb_pattern=bcm2709-rpi-2-b.dtb 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 elif [ "${target}" = "pi3" ]; then
emulator=qemu-system-aarch64 emulator=qemu-system-aarch64
machine=raspi3 machine=raspi3b
memory=1024m memory=1024m
kernel_pattern=kernel8.img kernel_pattern=kernel8.img
dtb_pattern=bcm2710-rpi-3-b-plus.dtb 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 else
echo "Target ${target} not supported" echo "Target ${target} not supported"
echo "Supported targets: pi1 pi2 pi3" echo "Supported targets: pi1 pi2 pi3"
@ -78,7 +90,7 @@ exec ${emulator} \
${nic} \ ${nic} \
--dtb "${dtb}" \ --dtb "${dtb}" \
--kernel "${kernel}" \ --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 \ --no-reboot \
--display none \ --display none \
--serial mon:stdio --serial mon:stdio

Loading…
Cancel
Save