Skip to content

Commit

Permalink
switched to generic board
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrsr committed Aug 18, 2024
1 parent c4be894 commit a0950e6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 88 deletions.
143 changes: 59 additions & 84 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,117 +47,92 @@ RUN mkdir /mnt/root /mnt/boot \
# Clone the RPI kernel repo
RUN git clone --single-branch --branch $KERNEL_BRANCH $KERNEL_GIT $BUILD_DIR/linux/

# Copy build configuration
COPY src/conf/.config $BUILD_DIR/linux/
# Build kernel, modules and device tree blobs
RUN make -C $BUILD_DIR/linux/ -j$(nproc) Image modules dtbs

# Copy kernel, modules and device tree blobs to extracted distro
RUN cp $BUILD_DIR/linux/arch/arm64/boot/Image /mnt/boot/kernel8.img \
&& cp $BUILD_DIR/linux/arch/arm64/boot/dts/broadcom/*.dtb /mnt/boot/ \
&& cp $BUILD_DIR/linux/arch/arm64/boot/dts/overlays/*.dtb* /mnt/boot/overlays/ \
&& cp $BUILD_DIR/linux/arch/arm64/boot/dts/overlays/README /mnt/boot/overlays/ \
&& make -C $BUILD_DIR/linux/ INSTALL_MOD_PATH=/mnt/root modules_install
# Cross compile vm kernel image
RUN make -C $BUILD_DIR/linux defconfig \
&& make -C $BUILD_DIR/linux kvm_guest.config \
&& make -C $BUILD_DIR/linux/ -j$(nproc) Image

# Copy boot configuration
COPY src/conf/fstab /mnt/root/etc/
COPY src/conf/cmdline.txt /mnt/boot/
COPY src/conf/99-qemu.rules /mnt/root/etc/udev/rules.d/

# Run SSH server on startup
RUN touch /mnt/boot/ssh

# Allow SSH root login with no password
# RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /mnt/root/etc/ssh/sshd_config \
# && sed -i 's/#PermitEmptyPasswords no/permitEmptyPasswords yes/' /mnt/root/etc/ssh/sshd_config
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /mnt/root/etc/ssh/sshd_config \
&& sed -i 's/#PermitEmptyPasswords no/permitEmptyPasswords yes/' /mnt/root/etc/ssh/sshd_config

# Enable root login and remove user 'pi'
# RUN sed -i 's/^root:\*:/root::/' /mnt/root/etc/shadow \
# && sed -i '/^pi/d' /mnt/root/etc/shadow \
# && sed -i '/^pi/d' /mnt/root/etc/passwd \
# && sed -i '/^pi/d' /mnt/root/etc/group \
# && rm -r /mnt/root/home/pi
RUN sed -i 's/^root:\*:/root::/' /mnt/root/etc/shadow \
&& sed -i '/^pi/d' /mnt/root/etc/shadow \
&& sed -i '/^pi/d' /mnt/root/etc/passwd \
&& sed -i '/^pi/d' /mnt/root/etc/group \
&& rm -r /mnt/root/home/pi

# Setup root auto login
# RUN mkdir /mnt/root/etc/systemd/system/[email protected]/
# COPY src/conf/login.conf /mnt/root/etc/systemd/system/[email protected]/override.conf
RUN mkdir /mnt/root/etc/systemd/system/[email protected]/
COPY src/conf/login.conf /mnt/root/etc/systemd/system/[email protected]/override.conf

# Disable userconfig.service
RUN rm /mnt/root/usr/lib/systemd/system/userconfig.service \
&& rm /mnt/root/etc/systemd/system/multi-user.target.wants/userconfig.service

# RUN rm /mnt/root/etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service \
# && rm /mnt/root/var/lib/systemd/deb-systemd-helper-enabled/sysinit.target.wants/systemd-timesyncd.service
# Create new distro image from modified boot and root
RUN guestfish -N $BUILD_DIR/distro.img=bootroot:vfat:ext4:2G \
&& guestfish add $BUILD_DIR/distro.img : run : mount /dev/sda1 / : glob copy-in /mnt/boot/* / : umount / : mount /dev/sda2 / : glob copy-in /mnt/root/* / \
&& sfdisk --part-type $BUILD_DIR/distro.img 1 c
# Convert new distro image to sparse file
RUN qemu-img convert -f raw -O qcow2 $BUILD_DIR/distro.img $BUILD_DIR/distro.qcow2

# RUN ln -rs /mnt/root/usr/lib/systemd/system/[email protected] /mnt/root/usr/lib/systemd/system/getty.target.wants/[email protected]
CMD cp $BUILD_DIR/distro.qcow2 ./

COPY src/conf/config.txt /mnt/boot/config.txt

# ---------------------------
FROM ubuntu:24.04 AS emulator

RUN rm /mnt/root/etc/systemd/system/dev-serial1.device.wants/hciuart.service

ENTRYPOINT bash

# # Default to console instead of graphical user interface
# RUN ln -f -s \
# multi-user.target \
# /mnt/root/usr/lib/systemd/system/default.target


# # Create new distro image from modified boot and root
# RUN guestfish -N $BUILD_DIR/distro.img=bootroot:vfat:ext4:2G \
# && guestfish add $BUILD_DIR/distro.img : run : mount /dev/sda1 / : glob copy-in /mnt/boot/* / : umount / : mount /dev/sda2 / : glob copy-in /mnt/root/* / \
# && sfdisk --part-type $BUILD_DIR/distro.img 1 c
# # Convert new distro image to sparse file
# RUN qemu-img convert -f raw -O qcow2 $BUILD_DIR/distro.img $BUILD_DIR/distro.qcow2

# CMD cp $BUILD_DIR/distro.qcow2 ./


# # ---------------------------
# FROM ubuntu:24.04 AS emulator

# # Project build directory
# ARG BUILD_DIR
# # Folder containing default configuration files
# ENV BASE_DIR=/base/
# # Folder containing helper scripts
# ENV APP_DIR=/app/
# Project build directory
ARG BUILD_DIR
# Folder containing default configuration files
ENV BASE_DIR=/base/
# Folder containing helper scripts
ENV APP_DIR=/app/

# ENV IMAGE_FILE_NAME=distro.qcow2
# ENV KERNEL_FILE_NAME=kernel8.img
# ENV DTB_FILE_NAME=pi3.dtb
ENV IMAGE_FILE_NAME=distro.img
ENV KERNEL_FILE_NAME=kernel8.img
ENV DTB_FILE_NAME=pi3.dtb

# # Copy build files
# RUN mkdir $BASE_DIR
# COPY --from=0 $BUILD_DIR/distro.qcow2 $BASE_DIR/$IMAGE_FILE_NAME
# COPY --from=0 /mnt/boot/kernel8.img $BASE_DIR/$KERNEL_FILE_NAME
# COPY --from=0 /mnt/boot/bcm2710-rpi-3-b.dtb $BASE_DIR/$DTB_FILE_NAME
# Copy build files
RUN mkdir $BASE_DIR
COPY --from=0 $BUILD_DIR/distro.img $BASE_DIR/$IMAGE_FILE_NAME
COPY --from=0 $BUILD_DIR/linux/arch/arm64/boot/Image $BASE_DIR/$KERNEL_FILE_NAME

# # Install packages and build essentials
# ARG DEBIAN_FRONTEND="noninteractive"
# RUN apt-get update && apt install -y \
# python3 \
# python3-pip \
# qemu-system-arm \
# linux-image-generic \
# libguestfs-tools \
# qemu-efi-aarch64
# Install packages and build essentials
ARG DEBIAN_FRONTEND="noninteractive"
RUN apt-get update && apt install -y \
python3 \
python3-pip \
qemu-system-arm \
linux-image-generic \
libguestfs-tools \
qemu-efi-aarch64

# ENV PIP_BREAK_SYSTEM_PACKAGES 1
ENV PIP_BREAK_SYSTEM_PACKAGES 1

# # Copy requirements first
# COPY src/app/requirements.txt $APP_DIR/requirements.txt
# # Install Python dependencies
# RUN pip3 install -r $APP_DIR/requirements.txt
# Copy requirements first
COPY src/app/requirements.txt $APP_DIR/requirements.txt
# Install Python dependencies
RUN pip3 install -r $APP_DIR/requirements.txt

# # Copy helper scripts
# COPY src/app/ $APP_DIR
# Copy helper scripts
COPY src/app/ $APP_DIR

# # Helper script on running container
# ENTRYPOINT ["/app/run.py"]
# Helper script on running container
ENTRYPOINT ["/app/run.py"]

# # Helper variables
# ENV PYTHONDONTWRITEBYTECODE 1
# ENV DIST_DIR /dist
# ENV STORAGE_PATH /dev/mmcblk0
# ENV PORT 2222
# Helper variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV DIST_DIR /dist
ENV STORAGE_PATH /dev/mmcblk0
ENV PORT 2222
9 changes: 5 additions & 4 deletions src/app/func/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ def start(opts):
log.info("Starting the emulator ...")
run(f"""
qemu-system-aarch64 \
-M raspi3b \
-machine virt \
-cpu cortex-a72 \
-m 1G \
-smp 4 \
-sd {image_path} \
-drive file={image_path},format=raw,id=hd0,if=none,cache=writeback \
-device virtio-blk,drive=hd0,bootindex=0 \
-kernel {kernel_path} \
-dtb {dtb_path} \
-nographic -no-reboot \
-append \"rw console=ttyAMA1,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootdelay=1 loglevel=2 modules-load=dwc2,g_ether\"
-append \"rw console=ttyAMA0,115200 root=/dev/vda2 rootfstype=ext4 rootdelay=1 loglevel=2\"
""",
get_output=False,
stderr=None if opts.verbose else subprocess.DEVNULL
Expand Down
3 changes: 3 additions & 0 deletions src/conf/99-qemu.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
KERNEL=="vda", SYMLINK+="mmcblk0"
KERNEL=="vda1", SYMLINK+="mmcblk0p1"
KERNEL=="vda2", SYMLINK+="mmcblk0p2"

0 comments on commit a0950e6

Please sign in to comment.