• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

bootable/newinstaller


Commit MetaInfo

Revision9c63ab239f8bc07860da29dfd74d14f144b14ab4 (tree)
Time2017-04-24 11:57:16
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Add a script to run Android-x86 in QEMU

The qemu-android script is installed as a part of the rpm. Users
can run the script directly to launch Android-x86 in the QEMU
virtual machine.

The script could also be used on a build host to run the just
built images in the $OUT directory.

Change Summary

Incremental Difference

--- a/Android.mk
+++ b/Android.mk
@@ -79,13 +79,13 @@ $(ISO_IMAGE): $(boot_dir) $(BUILT_IMG)
7979 $(hide) isohybrid --uefi $@ || echo -e "isohybrid not found.\nInstall syslinux 4.0 or higher if you want to build a usb bootable iso."
8080 @echo -e "\n\n$@ is built successfully.\n\n"
8181
82-rpm: $(LOCAL_PATH)/rpm/rpm.spec $(BUILT_IMG)
82+rpm: $(wildcard $(LOCAL_PATH)/rpm/*) $(BUILT_IMG)
8383 @echo ----- Making an rpm ------
84- OUT=$(abspath $(PRODUCT_OUT)); mkdir -p $$OUT/rpm/BUILD; rm -rf mv $$OUT/rpm/RPMS/*; \
84+ OUT=$(abspath $(PRODUCT_OUT)); mkdir -p $$OUT/rpm/BUILD; rm -rf $$OUT/rpm/RPMS/*; $(ACP) $< $$OUT; \
8585 rpmbuild -bb --target=$(if $(filter x86,$(TARGET_ARCH)),i686,x86_64) -D"cmdline $(BOARD_KERNEL_CMDLINE)" \
8686 -D"_topdir $$OUT/rpm" -D"_sourcedir $$OUT" -D"systemimg $(notdir $(systemimg))" -D"ver $(VER)" \
8787 $(if $(BUILD_NAME_VARIANT),-D"name $(BUILD_NAME_VARIANT)") \
88- -D"install_prefix $(if $(INSTALL_PREFIX),$(INSTALL_PREFIX),android-$(VER))" $<; \
88+ -D"install_prefix $(if $(INSTALL_PREFIX),$(INSTALL_PREFIX),android-$(VER))" $(filter %.spec,$^); \
8989 mv $$OUT/rpm/RPMS/*/*.rpm $$OUT
9090
9191 # Note: requires dosfstools
--- a/initrd/init
+++ b/initrd/init
@@ -3,7 +3,7 @@
33 # By Chih-Wei Huang <cwhuang@linux.org.tw>
44 # and Thorsten Glaser <tg@mirbsd.org>
55 #
6-# Last updated 2017/03/24
6+# Last updated 2017/04/23
77 #
88 # License: GNU Public License
99 # We explicitely grant the right to use the scripts
@@ -84,10 +84,14 @@ check_root()
8484 mkdir /mnt/iso
8585 mount -o loop /iso/$iso /mnt/iso
8686 SRC=iso
87- elif [ ! -e /mnt/$SRC/$RAMDISK ]; then
87+ fi
88+ if [ -e /mnt/$SRC/$RAMDISK ]; then
89+ zcat /mnt/$SRC/$RAMDISK | cpio -id > /dev/null
90+ elif [ -b /dev/$RAMDISK ]; then
91+ zcat /dev/$RAMDISK | cpio -id > /dev/null
92+ else
8893 return 1
8994 fi
90- zcat /mnt/$SRC/$RAMDISK | cpio -id > /dev/null
9195 if [ -e /mnt/$SRC/system.sfs ]; then
9296 mount -o loop,noatime /mnt/$SRC/system.sfs /sfs
9397 mount -o loop,noatime /sfs/system.img system
@@ -97,6 +101,8 @@ check_root()
97101 elif [ -d /mnt/$SRC/system ]; then
98102 remount_rw
99103 mount --bind /mnt/$SRC/system system
104+ elif [ -e /mnt/build.prop ]; then
105+ mount --bind /mnt system
100106 else
101107 rm -rf *
102108 return 1
@@ -128,7 +134,7 @@ debug_shell()
128134 echo -n Detecting Android-x86...
129135
130136 [ -z "$SRC" -a -n "$BOOT_IMAGE" ] && SRC=`dirname $BOOT_IMAGE`
131-[ -z "$RAMDISK" ] && RAMDISK=ramdisk.img
137+[ -z "$RAMDISK" ] && RAMDISK=ramdisk.img || RAMDISK=${RAMDISK##/dev/}
132138
133139 for c in `cat /proc/cmdline`; do
134140 case $c in
--- a/initrd/scripts/2-mount
+++ b/initrd/scripts/2-mount
@@ -1,6 +1,6 @@
11 #
22 # By Chih-Wei Huang <cwhuang@linux.org.tw>
3-# Last updated 2017/01/10
3+# Last updated 2017/04/23
44 #
55 # License: GNU Public License
66 # We explicitely grant the right to use the scripts
@@ -15,6 +15,9 @@ mount_data()
1515 if [ -b "/dev/$blk" ]; then
1616 [ ! -e /dev/block/$blk ] && ln /dev/$blk /dev/block
1717 mount -o noatime /dev/block/$blk data
18+ elif [ "$DATA" = "9p" ]; then
19+ modprobe 9pnet_virtio
20+ mount -t 9p -o trans=virtio data data -oversion=9p2000.L,posixacl,cache=loose
1821 else
1922 remount_rw
2023 mkdir -p /mnt/$SRC/$DATA
--- /dev/null
+++ b/rpm/qemu-android
@@ -0,0 +1,53 @@
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+$QEMU -enable-kvm -vga std -sdl \
43+ -kernel kernel \
44+ -append "CMDLINE console=ttyS0 RAMDISK=vdb $DATADEV" \
45+ -initrd initrd.img \
46+ -m 2048 -smp 2 -cpu host \
47+ -soundhw ac97 \
48+ -net nic,model=e1000 -net user \
49+ -serial mon:stdio \
50+ -boot menu=on \
51+ -drive index=0,if=virtio,id=system,file=$SYSTEMIMG,format=raw,readonly \
52+ -drive index=1,if=virtio,id=ramdisk,file=ramdisk.img,format=raw,readonly \
53+ $DATA $@
--- a/rpm/rpm.spec
+++ b/rpm/rpm.spec
@@ -6,6 +6,7 @@ Source1: kernel
66 Source2: initrd.img
77 Source3: ramdisk.img
88 Source4: %{systemimg}
9+Source5: qemu-android
910 License: Apache Public License / GPLv2
1011 Group: Operating system/Android
1112 URL: http://www.android-x86.org
@@ -22,8 +23,10 @@ or later.
2223
2324 %install
2425 rm -rf %{buildroot}
25-mkdir -p %{buildroot}/%{install_prefix}
26+mkdir -p %{buildroot}/%{install_prefix} %{buildroot}%{_bindir}
2627 install -m644 %{S:1} %{S:2} %{S:3} %{S:4} %{buildroot}/%{install_prefix}
28+install -m755 %{S:5} %{buildroot}%{_bindir}
29+sed -i "s|ANDROID_ROOT|/%{install_prefix}|; s|CMDLINE|%{cmdline}|" %{buildroot}%{_bindir}/`basename %{S:5}`
2730
2831 %post
2932 . /etc/os-release
@@ -69,3 +72,4 @@ rm -rf %{buildroot}
6972
7073 %files
7174 /%{install_prefix}/*
75+%{_bindir}/*