robherring / generic_device

A generic android device repository

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About running qemu/kvm

lintcoder opened this issue · comments

I have built my own Image(arm64), system.img and ramdisk.img successfully. I refer to https://github.com/robherring/generic_device/wiki/Running-QEMU-KVM
for how to run qemu, here is my script:

#!/bin/sh -e
if [ -n "$1" ]; then
INSTANCE_ID=$(printf "%02d" $1)
INSTANCE_DIR=run-${INSTANCE_ID}
mkdir -p ${INSTANCE_DIR}
shift
else
echo "Must specify instance id"
exit 1
fi

ANDROID_IMAGE_PATH=./

if [ ! -f ${ANDROID_IMAGE_PATH}/system.img ]; then
echo "Missing system.img"
exit 1
fi

QEMU_ARCH=$(arch)

QEMU_DISPLAY="-device virtio-gpu-pci,virgl -display gtk,gl=off"

QEMU_OPTS="-machine virt,gic-version=host -cpu host -smp 4 -enable-kvm"
KERNEL_CMDLINE='console=ttyAMA0,38400'
KERNEL=Image

if [ ! -f system.raw -o ${ANDROID_IMAGE_PATH}/system.img -nt system.raw ]; then
simg2img ${ANDROID_IMAGE_PATH}/system.img system.raw
fi

if [ ! -f ${INSTANCE_DIR}/cache.raw -o system.raw -nt ${INSTANCE_DIR}/cache.raw ]; then
rm -f ${INSTANCE_DIR}/*.raw
mkfs.ext4 -L cache ${INSTANCE_DIR}/cache.raw 128M
mkfs.ext4 -L data ${INSTANCE_DIR}/userdata.raw 512M
fi

../myqemu/bin/qemu-system-${QEMU_ARCH}
${QEMU_OPTS}
-append "${KERNEL_CMDLINE} vt.global_cursor_default=0 androidboot.selinux=permissive debug drm.debug=0 qemu=0"
-m 2048
-kernel ${ANDROID_IMAGE_PATH}/$KERNEL
-initrd ${ANDROID_IMAGE_PATH}/ramdisk.img
-drive index=0,if=none,format=raw,id=system,file=system.raw
-device virtio-blk-pci,drive=system
-drive index=1,if=none,format=raw,id=cache,file=${INSTANCE_DIR}/cache.raw
-device virtio-blk-pci,drive=cache
-drive index=2,if=none,format=raw,id=userdata,file=${INSTANCE_DIR}/userdata.raw
-device virtio-blk-pci,drive=userdata
-netdev user,id=mynet,hostfwd=tcp::54${INSTANCE_ID}-:5555 -device virtio-net-pci,netdev=mynet
-device virtio-mouse-pci -device virtio-keyboard-pci
-d guest_errors
-nodefaults
-serial stdio
${QEMU_DISPLAY}
$*

while output of console keeps printing the following logs, I wonder how can I fixed this and how can I get the display with h/w rendering since vnc or spice not supported on h/w rendering.

[ 9.610021] init: starting service 'surfaceflinger'...
[ 9.615573] init: property_set("ro.boottime.surfaceflinger", "9568305740") failed: property already set
[ 9.622341] init: starting service 'zygote'...
[ 9.627305] init: property_set("ro.boottime.zygote", "9580076950") failed: property already set
[ 14.450101] init: starting service 'netd'...
[ 14.455001] init: property_set("ro.boottime.netd", "14407743670") failed: property already set
[ 14.455498] init: Created socket '/dev/socket/netd', mode 660, user 0, group 1000
[ 14.455798] init: Created socket '/dev/socket/dnsproxyd', mode 660, user 0, group 3003
[ 14.456071] init: Created socket '/dev/socket/mdns', mode 660, user 0, group 1000
[ 14.456346] init: Created socket '/dev/socket/fwmarkd', mode 660, user 0, group 3003
[ 14.459012] type=1400 audit(1516850240.944:97): avc: granted { getattr } for pid=2160 comm="iptables" path="/vendor" dev="rootfs" ino=2117 scontext=u:r:netd:s0 tcontext=u:object_r:rootfs:s0 tclass=lnk_file
[ 14.459021] type=1400 audit(1516850245.864:166): avc: granted { getattr } for pid=2213 comm="netd" path="/vendor" dev="rootfs" ino=2117 scontext=u:r:netd:s0 tcontext=u:object_r:rootfs:s0 tclass=lnk_file
[ 14.480145] type=1400 audit(1516850245.864:166): avc: granted { getattr } for pid=2213 comm="netd" path="/vendor" dev="rootfs" ino=2117 scontext=u:r:netd:s0 tcontext=u:object_r:rootfs:s0 tclass=lnk_file
[ 14.480151] type=1400 audit(1516850245.884:167): avc: granted { getattr } for pid=2214 comm="iptables-restor" path="/vendor" dev="rootfs" ino=2117 scontext=u:r:netd:s0 tcontext=u:object_r:rootfs:s0 tclass=lnk_file
[ 14.485079] type=1400 audit(1516850245.884:167): avc: granted { getattr } for pid=2214 comm="iptables-restor" path="/vendor" dev="rootfs" ino=2117 scontext=u:r:netd:s0 tcontext=u:object_r:rootfs:s0 tclass=lnk_file
[ 14.485085] type=1400 audit(1516850245.884:168): avc: granted { lock } for pid=2214 comm="iptables-restor" path="/system/etc/xtables.lock" dev="vda" ino=638 scontext=u:r:netd:s0 tcontext=u:object_r:system_file:s0 tclass=file
[ 14.488401] type=1400 audit(1516850245.884:168): avc: granted { lock } for pid=2214 comm="iptables-restor" path="/system/etc/xtables.lock" dev="vda" ino=638 scontext=u:r:netd:s0 tcontext=u:object_r:system_file:s0 tclass=file
[ 14.488406] type=1400 audit(1516850245.892:169): avc: granted { getattr } for pid=2215 comm="ip6tables-resto" path="/vendor" dev="rootfs" ino=2117 scontext=u:r:netd:s0 tcontext=u:object_r:rootfs:s0 tclass=lnk_file
[ 14.493475] type=1400 audit(1516850245.892:169): avc: granted { getattr } for pid=2215 comm="ip6tables-resto" path="/vendor" dev="rootfs" ino=2117 scontext=u:r:netd:s0 tcontext=u:object_r:rootfs:s0 tclass=lnk_file
[ 14.493480] type=1400 audit(1516850245.896:170): avc: granted { lock } for pid=2215 comm="ip6tables-resto" path="/system/etc/xtables.lock" dev="vda" ino=638 scontext=u:r:netd:s0 tcontext=u:object_r:system_file:s0 tclass=file
[ 14.553492] audit: audit_lost=99 audit_rate_limit=20 audit_backlog_limit=64
[ 14.553494] audit: rate limit exceeded

If surfaceflinger is exiting, you need to look at logcat and see why.

Also, virgl still requires out of tree patches for kernel and mesa for explicit fence support. Make sure you have those.

@robherring I refer https://github.com/robherring/generic_device/wiki/Building for the steps, and my qemu can run successfully, android desktop can be seen, but mouse input is broken, I can't see it in vnc window. My GTK is 3.18 and the method to force ‘gtk_gl=”no”' doesn't work for me, I wonder what can I do to solve the problem?