2014年10月10日 星期五

Run an aarch64 linux on qemu

ARMv8的版子現在都超貴的,看看以下的報價就知道了。
剛剛發現最新版的qemu居然已經可以跑起aarch64了,立馬來玩玩
參考了以下兩個大大blog,終於在我的電腦上跑起來了。

http://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/
http://suihkulokki.blogspot.tw/2014/08/testing-qemu-21-arm64-support.html

記錄一下過程。
$ sudo apt-get install qemu-system-aarch64
正在讀取套件清單... 完成
正在重建相依關係        
正在讀取狀態資料... 完成
E: 找不到套件 qemu-system-aarch64

....XD

ubuntu 12.04不支持,看來只好自已build了...

$git clone git://git.qemu.org/qemu.git qemu.git
$cd qemu.git
$./configure --target-list=aarch64-softmmuconfigure
ERROR: pixman >= 0.21.8 not present. Your options:
         (1) Preferred: Install the pixman devel package (any recent
             distro should have packages as Xorg needs pixman too).
         (2) Fetch the pixman submodule, using:
             git submodule update --init pixman
$git submodule update --init pixman
$./configure --target-list=aarch64-softmmu
$make 
$wget http://people.linaro.org/~alex.bennee/images/aarch64-linux-3.15rc2-buildroot.img
$./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-linux-3.15rc2-buildroot.img --append "console=ttyAMA0"

當然不能滿足於prebuilt 好的image
以下是自已build filesystem和kernel的方法
先從filesystem開始
$git clone git://git.buildroot.net/buildroot buildroot.git
$cd buildroot.git
$make menuconfig

* Target Options -> Target Architecture(AArch64)
* Toolchain -> Toolchain type (External toolchain)
* Toolchain -> Toolchain (Linaro AArch64 14.02)
* System configuration -> Run a getty (login prompt) after boot (BR2_TARGET_GENERIC_GETTY)
* System configuration -> getty options -> TTY Port (ttyAMA0) (BR2_TARGET_GENERIC_GETTY_PORT)
* Target Packages -> Show packages that are also provided by busybox (BR2_PACKAGE_BUSYBOX_SHOW_OTHERS)
* Filesystem images -> cpio the root filesystem (for use as an initial RAM filesystem) (BR2_TARGET_ROOTFS_CPIO)
$make
產生出來的image 在output/images/rootfs.cpio

最後是最重要的kernel
先下載tool chain:
$wget http://releases.linaro.org/14.09/components/toolchain/binaries/gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux.tar.xz
$unxz < gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux.tar.xz > gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux.tar
$tar -xvf gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux.tar
$cd gcc-linaro-aarch64-linux-gnu-4.9-2014.09_linux/bin
$export PATH=`pwd`:$PATH

再來是kernel source:
$git clone git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git 
$ARCH=arm64 make menuconfig
kernel config可以參考這裡:config
要記得改
CONFIG_INITRAMFS_SOURCE="/home/callmelei/buildroot/buildroot.git/output/images/rootfs.cpio"                                          
CONFIG_CROSS_COMPILE="aarch64-linux-gnu-"                                                                             $ARCH=arm64 make -j 8
再來就是組裝了
進到qemu的folder,打入指令
$./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel aarch64-image/Image  --append "console=ttyAMA0"
當然也可以下載我prebuilt好的 image:image
一切都沒有意外的話,就開機囉

[    0.930569] drivers/rtc/hctosys.c: unable to open rtc device (rtc0)
[    0.950741] Freeing unused kernel memory: 2164K (ffffffc00060c000 - ffffffc000829000)
Starting logging: OK
Initializing random number generator... [    1.821649] random: dd urandom read with 1 bits of entropy available
done.
Starting network...

Welcome to Buildroot
buildroot login: root
# cat /proc/cpuinfo
Processor : AArch64 Processor rev 0 (aarch64)
processor : 0
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32
CPU implementer : 0x41
CPU architecture: AArch64
CPU variant : 0x1
CPU part : 0xd07
CPU revision : 0

Hardware : linux,dummy-virt

如果要退出,可以打ctrl-a c 進到qemu monitor mode來打quit,就可以離開了。


沒有留言: