d050bdbfbcfbe60382d7d4aa86a1d1b5e387768e
[AGL/meta-agl-demo.git] / recipes-extended / agl-qemu-runner / files / agl-qemu-runner.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: Apache-2.0
3
4 if [ -z "$1" ]; then
5     echo "Usage: ${basename $0} <image name>"
6     exit 1
7 fi
8 image="$1"
9
10 conf="/etc/agl-qemu-runner/${image}.conf"
11 if [ ! -f "$conf" ]; then
12     echo "No configuration file $conf"
13     exit 1
14 fi
15
16 . $conf
17
18 arch="$(uname -m)"
19 if [ -z "$QEMU_IMAGE_ARCH" ]; then
20     QEMU_IMAGE_ARCH="virtio-${arch}"
21 fi
22
23 disk="/var/lib/machines/${image}/${image}-${QEMU_IMAGE_ARCH}.ext4"
24 if [ ! -f "$disk" ]; then
25     echo "No disk image for $image"
26     exit 1
27 fi
28 kernel="/var/lib/machines/${image}/Image-${QEMU_IMAGE_ARCH}.bin"
29 if [ ! -f "$kernel" ]; then
30     echo "No kernel for $image"
31     exit 1
32 fi
33
34 TASKSET_CMD=""
35 if [ -n "$QEMU_TASKSET_CPUS" ]; then
36     TASKSET_CMD="taskset -c ${QEMU_TASKSET_CPUS}"
37 fi
38     
39 export SDL_VIDEODRIVER=wayland 
40 export XDG_RUNTIME_DIR=/run/user/200
41 # The following may be needed if the socket is not wayland-0, as SDL
42 # seems to lack detection logic for that case.
43 #export WAYLAND_DISPLAY=wayland-1
44
45 # This sets the XDG app id, which we need for setting outputs with
46 # agl-compositor
47 export SDL_VIDEO_WAYLAND_WMCLASS="${image}"
48
49 ${TASKSET_CMD} \
50 qemu-system-${arch} \
51         -enable-kvm \
52         -machine virt,gic-version=max,iommu=smmuv3 \
53         -cpu host \
54         ${QEMU_SMP_OPT} \
55         ${QEMU_MEM_OPT} \
56         -kernel $kernel \
57         -append "${QEMU_KERNEL_CMDLINE_APPEND}" \
58         -drive id=disk0,file=${disk},format=raw,if=none \
59         -serial mon:pty \
60         -object rng-random,filename=/dev/urandom,id=rng0 \
61         -device virtio-blk-device,drive=disk0 \
62         -device virtio-rng-device,rng=rng0 \
63         ${QEMU_NET_OPT} \
64         ${QEMU_INPUT_OPT} \
65         -global virtio-mmio.force-legacy=false \
66         -device virtio-gpu-gl-device \
67         -display sdl,gl=on -vga std \
68         ${QEMU_AUDIO_OPT} \
69         ${QEMU_CAN_OPT} \
70         ${QEMU_EXTRA_OPT} \
71         -full-screen