mirror of
https://github.com/lukechilds/dockerpi.git
synced 2026-07-25 11:54:04 +00:00
Add extraction support and raspi2/3 machines
1. Added 'fatcat' to extract from the boot filesystem from a standard RPI image 2. Added qemu-system-aarch64 to support raspi3 machines 3. Extracted images to search for kernel7/8.img and correct dtb files to boot kernel 4. Disabled nic for raspi2/3 as USB is not supported (yet)
This commit is contained in:
parent
4bb1b91e1d
commit
747fde62bc
2 changed files with 94 additions and 12 deletions
28
Dockerfile
28
Dockerfile
|
|
@ -28,11 +28,33 @@ RUN apt-get -y install python build-essential libglib2.0-dev libpixman-1-dev
|
|||
RUN apt-get -y install libfdt-dev zlib1g-dev
|
||||
# Not required or specified anywhere but supress build warnings
|
||||
RUN apt-get -y install flex bison
|
||||
RUN "qemu-${QEMU_VERSION}/configure" --static --target-list=arm-softmmu
|
||||
RUN "qemu-${QEMU_VERSION}/configure" --static --target-list=arm-softmmu,aarch64-softmmu
|
||||
RUN make -j$(nproc)
|
||||
|
||||
RUN # Strip the binary, this gives a substantial size reduction!
|
||||
RUN strip "arm-softmmu/qemu-system-arm"
|
||||
RUN strip "arm-softmmu/qemu-system-arm" "aarch64-softmmu/qemu-system-aarch64"
|
||||
|
||||
|
||||
# Build stage for fatcat
|
||||
FROM debian:stable-slim AS fatcat-builder
|
||||
ARG FATCAT_VERSION=1.1.0
|
||||
ENV FATCAT_TARBALL="v${FATCAT_VERSION}.tar.gz"
|
||||
WORKDIR /fatcat
|
||||
|
||||
RUN # Update package lists
|
||||
RUN apt-get update
|
||||
|
||||
RUN # Pull source
|
||||
RUN apt-get -y install wget
|
||||
RUN wget "https://github.com/Gregwar/fatcat/archive/${FATCAT_TARBALL}"
|
||||
|
||||
RUN # Extract source tarball
|
||||
RUN tar xvf "${FATCAT_TARBALL}"
|
||||
|
||||
RUN # Build source
|
||||
RUN apt-get -y install build-essential cmake
|
||||
RUN cmake "fatcat-${FATCAT_VERSION}" -DCMAKE_CXX_FLAGS='-static'
|
||||
RUN make -j$(nproc)
|
||||
|
||||
|
||||
# Build the dockerpi VM image
|
||||
|
|
@ -42,6 +64,8 @@ ARG RPI_KERNEL_URL="https://github.com/dhruvvyas90/qemu-rpi-kernel/archive/afe41
|
|||
ARG RPI_KERNEL_CHECKSUM="295a22f1cd49ab51b9e7192103ee7c917624b063cc5ca2e11434164638aad5f4"
|
||||
|
||||
COPY --from=qemu-system-arm-builder /qemu/arm-softmmu/qemu-system-arm /usr/local/bin/qemu-system-arm
|
||||
COPY --from=qemu-system-arm-builder /qemu/aarch64-softmmu/qemu-system-aarch64 /usr/local/bin/qemu-system-aarch64
|
||||
COPY --from=fatcat-builder /fatcat/fatcat /usr/local/bin/fatcat
|
||||
|
||||
ADD $RPI_KERNEL_URL /tmp/qemu-rpi-kernel.zip
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
target="${1:-versatilepb}"
|
||||
image_path="/sdcard/filesystem.img"
|
||||
zip_path="/filesystem.zip"
|
||||
|
||||
|
|
@ -8,22 +9,79 @@ if [ ! -e $image_path ]; then
|
|||
if [ -e $zip_path ]; then
|
||||
echo "Extracting fresh filesystem..."
|
||||
unzip $zip_path
|
||||
mv *.img $image_path
|
||||
mv -- *.img $image_path
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
exec qemu-system-arm \
|
||||
--machine versatilepb \
|
||||
fat_path="/fat.img"
|
||||
if [ "${target}" != "versatilepb" ];
|
||||
then
|
||||
echo "Extracting partitions"
|
||||
fdisk -l ${image_path} \
|
||||
| awk "/^[^ ]*1/{print \"dd if=${image_path} of=${fat_path} bs=512 skip=\"\$4\" count=\"\$6}" \
|
||||
| sh
|
||||
fi
|
||||
if [ "${target}" = "raspi2" ];
|
||||
then
|
||||
emulator=qemu-system-arm
|
||||
machine=raspi2
|
||||
memory=1024m
|
||||
kernel_pattern=kernel7.img
|
||||
dtb_pattern=bcm2709-rpi-2-b.dtb
|
||||
nic=''
|
||||
elif [ "${target}" = "raspi3" ];
|
||||
then
|
||||
emulator=qemu-system-aarch64
|
||||
machine=raspi3
|
||||
memory=1024m
|
||||
kernel_pattern=kernel8.img
|
||||
dtb_pattern=bcm2710-rpi-3-b-plus.dtb
|
||||
nic=''
|
||||
elif [ "${target}" = "versatilepb" ];
|
||||
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'
|
||||
else
|
||||
echo "Target ${target} not supported"
|
||||
echo "Supported targets: raspi2 raspi3 versatilepb"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [ -f "${fat_path}" ];
|
||||
then
|
||||
echo "Extracting boot filesystem"
|
||||
fat_folder="/fat"
|
||||
mkdir -p "${fat_folder}"
|
||||
fatcat -x "${fat_folder}" "${fat_path}"
|
||||
echo "Searching for kernel='${kernel_pattern}'"
|
||||
kernel=$(find "${fat_folder}" -name "${kernel_pattern}")
|
||||
echo "Searching for dtb='${dtb_pattern}'"
|
||||
dtb=$(find "${fat_folder}" -name "${dtb_pattern}")
|
||||
root=/dev/mmcblk0p2
|
||||
fi
|
||||
if [ "${kernel}" = "" ] || [ "${dtb}" = "" ];
|
||||
then
|
||||
echo "Missing kernel='${kernel}' or dtb='${dtb}'"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
echo "Booting with kernel=${kernel} dtb=${dtb}"
|
||||
exec ${emulator} \
|
||||
--machine "${machine}" \
|
||||
--cpu arm1176 \
|
||||
--m 256M \
|
||||
--hda /sdcard/filesystem.img \
|
||||
--net nic \
|
||||
--net user,hostfwd=tcp::5022-:22 \
|
||||
--dtb /root/qemu-rpi-kernel/versatile-pb.dtb \
|
||||
--kernel /root/qemu-rpi-kernel/kernel-qemu-4.19.50-buster \
|
||||
--append "root=/dev/sda2 panic=1" \
|
||||
--m "${memory}" \
|
||||
--hda "${image_path}" \
|
||||
${nic} \
|
||||
--dtb "${dtb}" \
|
||||
--kernel "${kernel}" \
|
||||
--append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=${root} rootwait panic=1" \
|
||||
--no-reboot \
|
||||
--display none \
|
||||
--serial mon:stdio
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue