- 论坛徽章:
- 0
|
最近发现android , poky都用qemu做为虚拟机,于是决定试用一下。
修改local.conf为qemuarm,然后编译sato,bitbake poky-image-sato ,编译完成后,在build/tmp/deploy/images/目录下,执行poky-qemu
poky-qemu ./zImage-qemuarm.bin ./poky-image-sato-qemuarm.ext3
Error: No QEMU binary 'qemu' could be found.
原来poky 的qemu没有编译 , 和 ubuntu本身的qemu (sudo apt-get install qemu)不同 ,
poky 的 qemu有些新的feature ,所以需要 编译poky 的qemu ,而不能sudo apt-get install qemu
编译安装qemu ,
bitbake qemu-native
然后可以发现在/usr/bin有qemu , qemu-system-arm ,qemu是在x86 PC机器上模拟x86板子,而qemu-system-arm是在x86 PC机器上模拟arm板子.
1 qemu 的串口打印
然后再运行 poky-qemu ./zImage-qemuarm.bin ./poky-image-sato-qemuarm.ext3
等了半天没反应,郁闷 ~~~。。。
但是ps -A ,发现qemu在运行,但怎么没有输出呢?
发现poky-qemu,它是先初始化一个网络接口tap0 ,然后执行
/usr/bin/qemu-system-arm -kernel ./zImage-qemuarm.bin -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/media/H/poky-purple-3.2/scripts/poky-qemu-ifup,downscript=/media/H/poky-purple-3.2/scripts/poky-qemu-ifdown -M versatilepb -hda ./poky-image-sato-qemuarm.ext3 -usb -usbdevice wacom-tablet -no-reboot -force-pointer -show-cursor --append root=/dev/sda console=ttyAMA0 console=tty0 ip=192.168.7.2::192.168.7.1:255.255.255.0 mem=64M
研究发现,qemu有选项 -serial , 修改poky-qemu-serial ,加上-serial stdio, 重定位到stdio
这样poky-qemu就执行:
/usr/bin/qemu-system-arm -kernel ./zImage-qemuarm.bin -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/media/H/poky-purple-3.2/scripts/poky-qemu-ifup,downscript=/media/H/poky-purple-3.2/scripts/poky-qemu-ifdown -M versatilepb -hda ./poky-image-sato-qemuarm.ext3 -usb -usbdevice wacom-tablet -no-reboot -serial stdio -force-pointer -show-cursor --append root=/dev/sda console=ttyAMA0 console=tty0 ip=192.168.7.2::192.168.7.1:255.255.255.0 mem=64M
在终端上就有输出了~~~
2 qemu 上网
但是怎么在qemu里上网呢?网上有2种方法,1种是dhcp ,另外的一种就是我下面用的。
我的电脑是wifi上网的,得到的ip地址为 192.168.1.100 . 而poky-qemu的缺省地址是192.168.7.2 ,和我不在一个网段。
我把tap0网络接口的ip地址设置为192.168.1.102 , 修改poky-qemu-ifup
$IFCONFIG tap0 192.168.1.102
$IPTABLES -A POSTROUTING -t nat -j MASQUERADE -s 192.168.1.0/24
而在虚拟机里,我把ip设置为192.168.1.103,gateway为192.168.1.102 (为tap0), 修改poky-qemu-internal,
/usr/bin/qemu-system-arm -kernel ./zImage-qemuarm.bin -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=/media/H/poky-purple-3.2/scripts/poky-qemu-ifup,downscript=/media/H/poky-purple-3.2/scripts/poky-qemu-ifdown -M versatilepb -hda ./poky-image-sato-qemuarm.ext3 -usb -usbdevice wacom-tablet -no-reboot -serial stdio -force-pointer -show-cursor --append root=/dev/sda console=ttyAMA0 console=tty0 ip=192.168.1.103::192.168.1.102:255.255.255.0 mem=64M
但是在poky-image-sato-qemuarm.ext3 文件系统里面,etc/network/interfaces 里 ,
iface eth0 inet static
address 192.168.7.2
netmask 255.255.255.0
network 192.168.7.0
gateway 192.168.7.1
修改为:
iface eth0 inet static
address 192.168.1.103
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.102
这样在虚拟机里,ping 自己的主机 ,但ping www.sina.com.cn 不了,缺少dns .
怎么设置dns呢?
在终端上 nslookup 1 输出:
Server: 218.2.135.1
Address: 218.2.135.1#53
Non-authoritative answer:
Name: nj.redirect.local
Address: 202.102.110.206
在/etc/resolv.conf里
nameserver 218.2.135.1
nameserver 64.147.37.1
这样将qemu虚拟机里的dns设置和host一样就可以了,不过qemu虚拟机的resolv.conf -> /var/run/resolv.conf,这个文件在内存中,
没法保存,因此修改volatile.cache文件。
echo "nameserver 218.2.135.1 \r\n " >/var/run/resolv.conf ;
echo "nameserver 61.147.37.1 " >/var/run/resolv.conf
然后reboot,重启后,dns就可以用了,用wget测试一下。
wget http://www.zlib.net/zlib-1.2.3.tar.bz2 ,发现成功了。
3 qemu 模拟 X server
到目前为止,qemu 串口打印,上网都可以了,但是我想显示GUI,怎么办呢?怎样让qemu模拟 X server ?
启动系统后,在etc/rc5.d/目录下执行 ./S09xserver-nodm start
显示:
Starting Xserver
Fatal server error:
Server is already active for display 0
If this server is no longer running, remove /tmp/.X0-lock
and start again.
xinit: Server error.
Timeout waiting for org.matchbox_project.desktop.Loaded
执行 ./S09xserver-nodm restart
还是没任何输出
用ps 发现 xinit , matchbox都启动了
qemu -sdl
qemu: invalid option -- '-sdl'
这就奇怪了,怎么会不支持sdl选项呢?
后来发现在/usr/bin下面有qemu ,qemu-system-arm ,在/media/H/poky-purple-3.2/build/tmp/staging/i686-linux/usr/bin 也有qemu ,qemu-system-arm ,这两者还不一样 。
原来自己一直用的是系统本身的qemu,而非poky的qemu ,虽然我用bitbake qemu-native了,但是因为它编译的qemu放在/media/H/poky-purple-3.2/build/tmp/staging/i686-linux/usr/bin下面,而非/usb/bin下面。
而我们用 source ./poky-init-build-env
echo $PATH 显示
/media/H/poky-purple-3.2/bitbake//bin/:/media/H/poky-purple-3.2/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
可见 我一直用的是/usr/bin下面的qemu , qemu-system-arm
export PATH=/media/H/poky-purple-3.2/build/tmp/staging/i686-linux/usr/bin:$PATH
然后再运行 poky-qemu ./zImage-qemuarm.bin ./poky-image-sato-qemuarm.ext3
哈哈, 终于显示出GUI窗口了,可以操作Contacts ,Date ,Tasks 了。Web也可以上google了,只是输入其他的地址,比如www.sina.com.cn,不会转到sina去。
此时也可以在terminal上输入命令,也可以用鼠标在GUI窗口操作。
4 qemu的audio
Music Player,用scp从host cp一首歌曲到虚拟机里,然后用music player打开,用耳机听没有声音。
原来kernel没有把alsa编译进去。我从poky网站下载的预编译的kernel情况也一样
MACHINE=qemuarm poky-qemu ./zImage-2.6.26-r11-purple-3.2.qemuarm.bin ./poky-image-sato-qemuarm.ext3
也没有alsa 设备,原来VersatilePB板子没有任何audio硬件,所以测试不了audio 。如果要测试audio ,则需要用别的板子,比如openmoko的Neo1973.
好了,试用就到此了,以后可以用qemu来虚拟了,不用在板子上跑程序。
大功告成~~~~
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/35351/showart_2183040.html |
|