標籤:emulator
準備 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 -> eglibcToolchain -> Enable C++ supportSystem 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 busyboxTarget packages -> Debugging, profiling and benchmark -> gdb -> full debuggerTarget packages -> Networking applications -> dhcpcdTarget packages -> Shell and utilities -> bashFilesystem images -> cpio the root filesystemFilesystem images -> tar the root filesystem
- $ export BR2_JLEVEL=4
- $ make linux-menuconfig
Device Drivers -> (*) Staging drivers -> (*) Android -> (*) Android Binder IPC DriverFile 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