OSDN Git Service

Set rpm epoch
[android-x86/bootable-newinstaller.git] / rpm / qemu-android
1 #!/bin/bash
2 # By Chih-Wei Huang <cwhuang@linux.org.tw>
3 # License: GNU Generic Public License v2
4
5 continue_or_stop()
6 {
7         echo "Please Enter to continue or Ctrl-C to stop."
8         read
9 }
10
11 QEMU_ARCH=`uname -m`
12 QEMU=qemu-system-${QEMU_ARCH}
13
14 which $QEMU > /dev/null 2>&1 || QEMU=qemu-system-i386
15 if ! which $QEMU > /dev/null 2>&1; then
16         echo -e "Please install $QEMU to run the program.\n"
17         exit 1
18 fi
19
20 cd ${OUT:-ANDROID_ROOT}
21
22 [ -e system.img ] && SYSTEMIMG=system.img || SYSTEMIMG=system.sfs
23
24 if [ -d data ]; then
25         if [ `id -u` -eq 0 ]; then
26                 DATA="-virtfs local,id=data,path=data,security_model=passthrough,mount_tag=data"
27                 DATADEV='DATA=9p'
28         else
29                 echo -e "\n$(realpath data) subfolder exists.\nIf you want to save data to it, run $0 as root:\n\n$ sudo $0\n"
30                 continue_or_stop
31         fi
32 elif [ -e data.img ]; then
33         if [ -w data.img ]; then
34                 DATA="-drive index=2,if=virtio,id=data,file=data.img"
35                 DATADEV='DATA=vdc'
36         else
37                 echo -e "\n$(realpath data.img) exists but is not writable.\nPlease grant the write permission if you want to save data to it.\n"
38                 continue_or_stop
39         fi
40 fi
41
42 run_qemu()
43 {
44         $QEMU -enable-kvm \
45         -kernel kernel \
46         -append "CMDLINE console=ttyS0 RAMDISK=vdb $DATADEV" \
47         -initrd initrd.img \
48         -m 2048 -smp 2 -cpu host \
49         -soundhw ac97 \
50         -serial mon:stdio \
51         -boot menu=on \
52         -drive index=0,if=virtio,id=system,file=$SYSTEMIMG,format=raw,readonly \
53         -drive index=1,if=virtio,id=ramdisk,file=ramdisk.img,format=raw,readonly \
54         -netdev user,id=mynet,hostfwd=tcp::5555-:5555 -device virtio-net-pci,netdev=mynet \
55         $DATA $@
56 }
57
58 # Try to run QEMU in several VGA modes
59 run_qemu -vga virtio -display sdl,gl=on $@ || \
60 run_qemu -vga std -display sdl $@ || \
61 run_qemu $@