#!/bin/bash # Variables FBGL_BINARY="./fbgl_program" # Path to your fbgl program binary BUSYBOX_VERSION="1.36.1" # BusyBox version to download BUSYBOX_SRC="busybox-${BUSYBOX_VERSION}.tar.bz2" BUSYBOX_DIR="busybox-${BUSYBOX_VERSION}" BUSYBOX_IMAGE="busybox.img" # Output image file QEMU_ARCH="x86_64" # Architecture for QEMU MEMORY="512M" # Memory for QEMU # Function to download and build BusyBox build_busybox() { echo "Downloading BusyBox..." wget "https://busybox.net/downloads/${BUSYBOX_SRC}" || { echo "Failed to download BusyBox."; exit 1; } echo "Extracting BusyBox..." tar -xjf "${BUSYBOX_SRC}" || { echo "Failed to extract BusyBox."; exit 1; } echo "Configuring and building BusyBox..." cd "${BUSYBOX_DIR}" || exit make defconfig sed -i 's/.*CONFIG_STATIC is not set.*/CONFIG_STATIC=y/' .config # Enable static build make -j$(nproc) || { echo "Failed to build BusyBox."; exit 1; } echo "Creating root filesystem..." mkdir -p rootfs make install CONFIG_PREFIX=rootfs echo "Adding init script..." cat > rootfs/init < ../../"${BUSYBOX_IMAGE}" || { echo "Failed to create BusyBox image."; exit 1; } cd ../.. echo "BusyBox image created successfully: ${BUSYBOX_IMAGE}" } # Ensure fbgl binary exists if [[ ! -f $FBGL_BINARY ]]; then echo "FBGL binary not found at $FBGL_BINARY. Compile or provide the correct path." exit 1 fi # Ensure BusyBox image exists or build it if [[ ! -f $BUSYBOX_IMAGE ]]; then echo "BusyBox image not found. Building it now..." build_busybox fi # Run QEMU with fbgl and BusyBox echo "Starting QEMU with BusyBox and FBGL..." qemu-system-$QEMU_ARCH \ -m $MEMORY \ -kernel $BUSYBOX_IMAGE \ -append "console=ttyS0" \ -nographic \ -initrd $FBGL_BINARY \ -net nic -net user \ -serial mon:stdio