summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLevent Kaya <levent.kaya@codefirst.io>2024-11-26 16:16:40 +0300
committerLevent Kaya <levent.kaya@codefirst.io>2024-11-26 16:16:40 +0300
commit10f134f1cb528bd220befbe734bd047b3995c920 (patch)
tree724d25466090c154b3982f853f921a4b82bdb6d7
parentc5a97ecccf07d02e30264e82f21ba5a31985d81c (diff)
[build] test env update
-rw-r--r--fbgl_qemu_test_env.sh206
1 files changed, 62 insertions, 144 deletions
diff --git a/fbgl_qemu_test_env.sh b/fbgl_qemu_test_env.sh
index f519b67..384ac4b 100644
--- a/fbgl_qemu_test_env.sh
+++ b/fbgl_qemu_test_env.sh
@@ -1,161 +1,79 @@
#!/bin/bash
-# Configuration
-KERNEL_VERSION="6.1.1"
-BUSYBOX_VERSION="1.36.1"
-WORKDIR="$(pwd)/fbgl-test-env"
-KERNEL_URL="https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${KERNEL_VERSION}.tar.xz"
-BUSYBOX_URL="https://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2"
-
-# Colors for output
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-NC='\033[0m' # No Color
-
-# Error handling
-set -e
-trap 'echo -e "${RED}Error: Script failed${NC}" >&2' ERR
-
-echo -e "${GREEN}Setting up FBGL test environment...${NC}"
-
-# Create working directory
-mkdir -p "${WORKDIR}"
-cd "${WORKDIR}"
-
-# Function to check if a package is installed
-check_package() {
- if ! command -v $1 &> /dev/null; then
- echo -e "${RED}Error: $1 is not installed${NC}"
- exit 1
- fi
-}
-
-# Check required packages
-required_packages=(wget make gcc g++ qemu-system-x86_64 cpio gzip bc flex bison libelf-dev)
-for package in "${required_packages[@]}"; do
- check_package $package
-done
-
-# Download and extract kernel
-if [ ! -d "linux-${KERNEL_VERSION}" ]; then
- echo "Downloading Linux kernel..."
- wget -q --show-progress "${KERNEL_URL}"
- tar xf "linux-${KERNEL_VERSION}.tar.xz"
- rm "linux-${KERNEL_VERSION}.tar.xz"
+# Variables
+BUSYBOX_DIR="busybox_root" # Directory for BusyBox root filesystem
+BINARY="fbgl_test" # Precompiled binary
+TARGET_DIR="/mnt/root" # Target directory for binary on BusyBox
+BUSYBOX_IMAGE="busybox.img" # Image file for BusyBox environment
+LOOP_DEVICE="/dev/loop0" # Loop device for BusyBox image
+
+# Ensure dependencies are installed
+if ! command -v qemu-system-x86_64 &>/dev/null; then
+ echo "Please install QEMU to run BusyBox."
+ exit 1
fi
-# Configure and build kernel
-cd "linux-${KERNEL_VERSION}"
-if [ ! -f ".config" ]; then
- echo "Configuring kernel..."
- make defconfig
- # Enable framebuffer support
- cat >> .config << EOF
-CONFIG_FB=y
-CONFIG_FB_VESA=y
-CONFIG_FB_EFI=y
-CONFIG_FB_SIMPLE=y
-CONFIG_FRAMEBUFFER_CONSOLE=y
-EOF
+if ! command -v losetup &>/dev/null; then
+ echo "Please install losetup for loop device setup."
+ exit 1
fi
-echo "Building kernel..."
-make -j$(nproc) bzImage
+# 1. Create a Minimal BusyBox Environment
+echo "Setting up BusyBox environment..."
-cd "${WORKDIR}"
-
-# Download and build Busybox
-if [ ! -d "busybox-${BUSYBOX_VERSION}" ]; then
- echo "Downloading Busybox..."
- wget -q --show-progress "${BUSYBOX_URL}"
- tar xf "busybox-${BUSYBOX_VERSION}.tar.bz2"
- rm "busybox-${BUSYBOX_VERSION}.tar.bz2"
-fi
-
-cd "busybox-${BUSYBOX_VERSION}"
-if [ ! -f ".config" ]; then
- echo "Configuring Busybox..."
- make defconfig
- # Build statically
- sed -i 's/# CONFIG_STATIC is not set/CONFIG_STATIC=y/' .config
+# Download and build BusyBox
+if [ ! -d "busybox" ]; then
+ git clone https://git.busybox.net/busybox
fi
-
-echo "Building Busybox..."
+cd busybox || exit
+make defconfig
+sed -i 's/# CONFIG_STATIC/CONFIG_STATIC=y/' .config # Enable static binary
make -j$(nproc)
-make install
+cd ..
-# Create initial ramdisk
-cd "${WORKDIR}"
-mkdir -p initramfs
-cd initramfs
-mkdir -p {bin,sbin,etc,proc,sys,usr/{bin,sbin},dev}
+# Create root filesystem
+mkdir -p $BUSYBOX_DIR/{bin,dev,etc,proc,sys,usr}
-# Copy Busybox
-cp -a ../busybox-${BUSYBOX_VERSION}/_install/* .
+# Install BusyBox binaries
+cp busybox/busybox $BUSYBOX_DIR/bin/
+chroot $BUSYBOX_DIR /bin/busybox --install -s
-# Create init script
-cat > init << 'EOF'
+# Add init script
+cat <<EOF >$BUSYBOX_DIR/init
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
-mount -t devtmpfs none /dev
-
-# Create framebuffer device
-mknod /dev/fb0 c 29 0
-
-# Set up environment
-export PATH=/bin:/sbin:/usr/bin:/usr/sbin
-
-# Create test directory
-mkdir -p /test
-cd /test
-
-# Your FBGL test program will be copied here
-# Wait for it to be copied and then execute it
-
-echo "Ready for FBGL testing!"
exec /bin/sh
EOF
-
-chmod +x init
-
-# Create initial ramdisk
-find . | cpio -H newc -o | gzip > "${WORKDIR}/initramfs.cpio.gz"
-
-# Create test script
-cd "${WORKDIR}"
-cat > run-test.sh << 'EOF'
-#!/bin/bash
-
-if [ $# -ne 1 ]; then
- echo "Usage: $0 <fbgl-test-program>"
- exit 1
-fi
-
-TEST_PROGRAM="$1"
-KERNEL="linux-6.1.1/arch/x86/boot/bzImage"
-INITRD="initramfs.cpio.gz"
-
-if [ ! -f "$TEST_PROGRAM" ]; then
- echo "Error: Test program not found: $TEST_PROGRAM"
- exit 1
-fi
-
-qemu-system-x86_64 \
- -kernel "$KERNEL" \
- -initrd "$INITRD" \
- -append "console=ttyS0 root=/dev/ram0 rw init=/init" \
- -nographic \
- -enable-kvm \
- -device virtio-vga \
- -cpu host \
- -m 1G
-
-EOF
-
-chmod +x run-test.sh
-
-echo -e "${GREEN}FBGL test environment setup complete!${NC}"
-echo "To run a test program:"
-echo "1. Build your FBGL program"
-echo "2. Run: ./run-test.sh <path-to-your-program>" \ No newline at end of file
+chmod +x $BUSYBOX_DIR/init
+
+# Create device nodes
+sudo mknod $BUSYBOX_DIR/dev/console c 5 1
+sudo mknod $BUSYBOX_DIR/dev/null c 1 3
+
+# 2. Prepare Framebuffer
+echo "Setting up framebuffer support..."
+sudo mknod $BUSYBOX_DIR/dev/fb0 c 29 0
+
+# 3. Create Image File
+echo "Creating BusyBox disk image..."
+dd if=/dev/zero of=$BUSYBOX_IMAGE bs=1M count=64
+mkfs.ext4 $BUSYBOX_IMAGE
+sudo mount -o loop $BUSYBOX_IMAGE $TARGET_DIR
+sudo cp -r $BUSYBOX_DIR/* $TARGET_DIR/
+sudo umount $TARGET_DIR
+
+# 4. Transfer Precompiled Binary
+echo "Transferring binary to BusyBox environment..."
+sudo mount -o loop $BUSYBOX_IMAGE $TARGET_DIR
+sudo cp $BINARY $TARGET_DIR/bin/
+sudo umount $TARGET_DIR
+
+# 5. Run in QEMU
+echo "Starting BusyBox in QEMU with framebuffer..."
+qemu-system-x86_64 -kernel busybox/arch/x86/boot/bzImage \
+ -append "root=/dev/sda console=ttyS0" \
+ -hda $BUSYBOX_IMAGE \
+ -nographic
+
+echo "BusyBox environment setup complete."