diff options
| author | Levent Kaya <levent.kaya@codefirst.io> | 2024-11-26 16:43:12 +0300 |
|---|---|---|
| committer | Levent Kaya <levent.kaya@codefirst.io> | 2024-11-26 16:43:12 +0300 |
| commit | 50d8bd2f17cf7e4fb1b876542bbf87713a93451e (patch) | |
| tree | f6d43836e281fd00f425d7ebdaea66a6b44b896c /fbgl_qemu_test_env.sh | |
| parent | 1fa0293b80683810063cc44311150bc218223168 (diff) | |
[build] test in tinycore
Diffstat (limited to 'fbgl_qemu_test_env.sh')
| -rw-r--r-- | fbgl_qemu_test_env.sh | 96 |
1 files changed, 47 insertions, 49 deletions
diff --git a/fbgl_qemu_test_env.sh b/fbgl_qemu_test_env.sh index 9957e1a..2b4a8a0 100644 --- a/fbgl_qemu_test_env.sh +++ b/fbgl_qemu_test_env.sh @@ -1,13 +1,24 @@ #!/bin/bash # Variables -BUSYBOX_VERSION="1.36.0" # BusyBox version to download -PRECOMPILED_KERNEL="https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.5.9.tar.xz" -BUSYBOX_DIR="busybox_root" # Directory for BusyBox root filesystem -BINARY="fbgl_test" # Precompiled binary -BUSYBOX_IMAGE="busybox.img" # Image file for BusyBox environment -TARGET_DIR="/mnt/root" # Mount point for the BusyBox image -KERNEL_FILE="vmlinuz" # Precompiled kernel file +TINYCORE_URL="http://tinycorelinux.net/14.x/x86/release/TinyCore-current.iso" # TinyCore ISO URL +ISO_FILE="TinyCore.iso" # Local TinyCore ISO file +DISK_IMAGE="tinycore_test.img" # Disk image for TinyCore +DISK_SIZE="128M" # Size of the disk image +MOUNT_DIR="mnt_tinycore" # Mount point for the disk image + +# Ensure a binary is provided as an argument +if [ -z "$1" ]; then + echo "Usage: $0 <path_to_precompiled_binary>" + exit 1 +fi +BINARY="$1" + +# Ensure the binary exists +if [ ! -f "$BINARY" ]; then + echo "Error: Precompiled binary '$BINARY' not found." + exit 1 +fi # Ensure dependencies are installed REQUIRED_TOOLS=("wget" "qemu-system-x86_64" "dd" "mkfs.ext4" "mount" "losetup") @@ -18,53 +29,40 @@ for tool in "${REQUIRED_TOOLS[@]}"; do fi done -# Step 1: Download and Build BusyBox -echo "Setting up BusyBox environment..." -if [ ! -d "busybox-${BUSYBOX_VERSION}" ]; then - wget https://busybox.net/downloads/busybox-${BUSYBOX_VERSION}.tar.bz2 - tar -xf busybox-${BUSYBOX_VERSION}.tar.bz2 +# Step 1: Download TinyCore Linux ISO +if [ ! -f "$ISO_FILE" ]; then + echo "Downloading TinyCore Linux ISO..." + wget -O $ISO_FILE $TINYCORE_URL fi -cd busybox-${BUSYBOX_VERSION} -make defconfig -sed -i 's/# CONFIG_STATIC/CONFIG_STATIC=y/' .config # Enable static binary -make -j$(nproc) install CONFIG_PREFIX=../$BUSYBOX_DIR -cd .. -# Step 2: Set Up BusyBox Root Filesystem -echo "Creating BusyBox root filesystem..." -mkdir -p $BUSYBOX_DIR/{dev,proc,sys,root} -sudo mknod -m 666 $BUSYBOX_DIR/dev/console c 5 1 -sudo mknod -m 666 $BUSYBOX_DIR/dev/null c 1 3 -echo "#!/bin/sh -mount -t proc none /proc -mount -t sysfs none /sys -exec /bin/sh" > $BUSYBOX_DIR/init -chmod +x $BUSYBOX_DIR/init +# Step 2: Create a Disk Image +echo "Creating disk image..." +dd if=/dev/zero of=$DISK_IMAGE bs=1M count=${DISK_SIZE/M/} +mkfs.ext4 $DISK_IMAGE -# Step 3: Create and Format Disk Image -echo "Creating and formatting 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 +# Step 3: Mount and Prepare Disk Image +echo "Mounting disk image..." +mkdir -p $MOUNT_DIR +sudo mount -o loop $DISK_IMAGE $MOUNT_DIR -# Step 4: Download Precompiled Kernel -if [ ! -f "$KERNEL_FILE" ]; then - echo "Downloading precompiled kernel..." - wget -O $KERNEL_FILE $PRECOMPILED_KERNEL -fi +echo "Preparing disk image for TinyCore Linux..." +sudo mkdir -p $MOUNT_DIR/tce +sudo cp $ISO_FILE $MOUNT_DIR/ + +# Step 4: Add Precompiled Binary +echo "Adding precompiled binary '$BINARY'..." +sudo cp "$BINARY" $MOUNT_DIR/ -# Step 5: Transfer Precompiled Binary to BusyBox -echo "Transferring binary to BusyBox..." -sudo mount -o loop $BUSYBOX_IMAGE $TARGET_DIR -sudo cp $BINARY $TARGET_DIR/bin/ -sudo umount $TARGET_DIR +# Step 5: Unmount Disk Image +echo "Unmounting disk image..." +sudo umount $MOUNT_DIR +rmdir $MOUNT_DIR -# Step 6: Boot with QEMU -echo "Booting BusyBox with QEMU..." +# Step 6: Boot TinyCore Linux in QEMU +echo "Booting TinyCore Linux with QEMU..." qemu-system-x86_64 \ - -kernel $KERNEL_FILE \ - -append "root=/dev/sda console=ttyS0 init=/init" \ - -hda $BUSYBOX_IMAGE \ + -cdrom $ISO_FILE \ + -hda $DISK_IMAGE \ + -m 512M \ + -boot d \ -nographic |
