1. 安裝 qemu
$ sudo apt-get install qemu-system-arm
2. 建立測試目錄,下載 toochain 以及 kernel
$ mkdir qemu_test
$ cd qemu_test
$ wget https://releases.linaro.org/components/toolchain/binaries/6.4-2017.11/arm-linux-gnueabihf/ gcc-linaro-6.4.1-2017.11-i686_arm-linux-gnueabihf.tar.xz
$ tar xvf gcc-linaro-6.4.1-2017.11-i686_arm-linux-gnueabihf.tar.xz
$ wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.14.tar.xz
$ tar xvf ./linux-4.14.tar.xz
3. 修改環境變數
$ vi ~/.bashrcexport ARCH=arm$ source ~/.bashrc
export CROSS_COMPILE=arm-linux-gnueabihf-
export PATH=$PATH:/home/albert/qemu_test/gcc-linaro-6.4.1-2017.11-i686_arm-linux-gnueabihf/bin
4. 編譯 kernel
$ cd linux-4.14
$ vi arch/arm/configs/vexpress_defconfig
參考此篇 http://awe31402-blog.logdown.com/posts/528593
$ make vexpress_defconfig
$ make clean;make
$ ls -al arch/arm/boot/dts/*.dtb
此時應該會出現 vexpress-v2p-ca9.dtb
$ ls -al ./arch/arm/boot/
此處應該會出現 zImage
5. 建立虛擬網卡介面
$ sudo apt-get install uml-utilities
$ sudo tunctl -t tap0 -u albert
$ sudo ifconfig tap0 192.168.7.1 netmask 255.255.255.0 promisc
6. 建立 nfs 使用的 rootfs (之前已經透過 yocto 建立,此步驟省略)
7. 執行程式
$ cd ~/qemu_test
$ QEMU_AUDIO_DRV=none qemu-system-arm -kernel ./linux-4.14/arch/arm/boot/zImage -M vexpress-a9 -m 512 \
-dtb ./linux-4.14/arch/arm/boot/dts/vexpress-v2p-ca9.dtb \
-append "/dev/nfs nfsroot=192.168.7.1:/srv/nfs/qemuarm rw ip=192.168.7.2:192.168.7.1:255.255.255.0 console=ttyAMA0,115200" \
-smp 1 -net nic,vlan=0 -net tap,vlan=0,ifname=tap0,script=no -nographic
參考資料:
http://awe31402-blog.logdown.com/posts/528593
http://daydreamer.idv.tw/rewrite.php/read-42.html