summaryrefslogtreecommitdiff
path: root/fbgl_qemu_test_env.sh
blob: 6f329c3bfbba90b673e4000b153856c063439cee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash

# Variables
TINYCORE_URL="http://tinycorelinux.net/14.x/x86_64/release/CorePure64-current.iso"  # 64-bit TinyCore Linux ISO
ISO_FILE="CorePure64.iso"               # TinyCore Linux ISO file
DISK_IMAGE="tinycore_disk.img"          # Writable disk image for TinyCore
DISK_SIZE="64M"                         # Size of the writable disk
MOUNT_DIR="mnt_tinycore"                # Temporary mount point for disk
BINARY="$1"                             # Precompiled binary passed as argument

# Check if a binary is provided
if [ -z "$BINARY" ]; then
    echo "Usage: $0 <path_to_precompiled_binary>"
    exit 1
fi

# Ensure the binary exists
if [ ! -f "$BINARY" ]; then
    echo "Error: Binary file '$BINARY' not found."
    exit 1
fi

# Ensure required tools are installed
REQUIRED_TOOLS=("wget" "qemu-system-x86_64" "dd" "mkfs.ext4" "mount" "losetup")
for tool in "${REQUIRED_TOOLS[@]}"; do
    if ! command -v $tool &>/dev/null; then
        echo "Error: $tool is required but not installed. Please install it first."
        exit 1
    fi
done

# Step 1: Download 64-bit TinyCore Linux ISO if not already present
if [ ! -f "$ISO_FILE" ]; then
    echo "Downloading 64-bit TinyCore Linux ISO..."
    wget -O $ISO_FILE $TINYCORE_URL
fi

# Step 2: Create a writable disk image
echo "Creating writable disk image..."
dd if=/dev/zero of=$DISK_IMAGE bs=1M count=${DISK_SIZE/M/} status=progress
mkfs.ext4 $DISK_IMAGE

# Step 3: Mount the disk image and add the binary
echo "Mounting disk image and adding binary..."
mkdir -p $MOUNT_DIR
sudo mount -o loop $DISK_IMAGE $MOUNT_DIR
sudo cp "$BINARY" $MOUNT_DIR/
sudo umount $MOUNT_DIR
rmdir $MOUNT_DIR

# Step 4: Run TinyCore Linux in QEMU without graphical interface
echo "Running TinyCore Linux in terminal mode with QEMU..."
qemu-system-x86_64 \
    -cdrom $ISO_FILE \
    -hda $DISK_IMAGE \
    -m 512M \
    -append "loglevel=3 tce=sda1 init=/init"

echo "QEMU exited. Check above for errors or results."