准备 qemu, 编译 arm 的运行环境
- $ wget http://wiki.qemu-project.org/download/qemu-2.0.0.tar.bz2
- $ tar xzvf qemu-2.0.0.tar.bz2
- $ mkdir ./qemu-2.0.0/bin
- $ cd ./qemu-2.0.0/bin/
- $ ../configure --target-list=arm-softmmu
- $ make
(system 模式,是模拟整个硬件了,user 模式是只模拟arm cpu, sys call 转变为对 host linux-x86的调用)
准备build root, build root 自动下载需要文件编译需要的 kernel, rootfs
- $ wget http://buildroot.uclibc.org/downloads/buildroot-2014.05.tar.bz2
- $ tar xjvf buildroot-2014.05.tar.bz2
- $ cd buildroot-2014.05/
- $ make qemu_arm_vexpress_defconfig
- $ make menuconfig
Toolchain -> C library -> eglibc Toolchain -> Enable C++ support System configuration -> Root filesystem overlay directories -> <path to your alien rootfs dir, e.g. /home/payne/qemu/rootfs_my/> Target packages -> Show packages that are also provided by busybox Target packages -> Debugging, profiling and benchmark -> gdb -> full debugger Target packages -> Networking applications -> dhcpcd Target packages -> Shell and utilities -> bash Filesystem images -> cpio the root filesystem Filesystem images -> tar the root filesystem
- $ export BR2_JLEVEL=4
- $ make linux-menuconfig
Device Drivers -> (*) Staging drivers -> (*) Android -> (*) Android Binder IPC Driver File systems -> (*) FUSE (Filesystem in Userspace) support
- $ make
可以指定自己的rootfs, 把 target arm 的可执行文件,放在此目录/home/payne/qemu/rootfs_my/, 运行qemu-arm 的时候,就可以在shell 中执行了
运行qemu, 使用的ZImage和rootfs 都是在buildroot中生成的
- $ ./qemu-2.0.0/bin/system/arm-softmmu/qemu-system-arm -M vexpress-a9 -m 1G -kernel ./buildroot-2014.05/output/images/zImage -drive file=./buildroot-2014.05/output/images/rootfs.ext2,if=sd -append "console=ttyAMA0,115200 root=/dev/mmcblk0" -serial stdio -net nic,model=lan9118 -net user -redir tcp:5900::5900
- Input "root" when you see the login prompt
- # dhcpcd
- #
值得注意的是, qemu并不自动netwrok, 要运行dhcpcd获得ip(更android 一样,10.0.2.15是自己,10.0.2.2
是host), 在qemu中能访问外部internet,但是要外部访问内部需要用端口转发-redir tcp:5900::5900,就是把guest os 的5900 和host os 的5900做map, 这样访问host os 5900就是访问guest os 的5900