summaryrefslogtreecommitdiff
path: root/fbgl_qemu_test_env.sh
blob: f519b67f0d079bb1661ed451729486f366167115 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/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"
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
fi

echo "Building kernel..."
make -j$(nproc) bzImage

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
fi

echo "Building Busybox..."
make -j$(nproc)
make install

# Create initial ramdisk
cd "${WORKDIR}"
mkdir -p initramfs
cd initramfs
mkdir -p {bin,sbin,etc,proc,sys,usr/{bin,sbin},dev}

# Copy Busybox
cp -a ../busybox-${BUSYBOX_VERSION}/_install/* .

# Create init script
cat > init << 'EOF'
#!/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>"