首先,計畫才一開始,甚麼頭緒也沒有。所以我們先嘗試著建置學習環境,建置過程中再慢慢思考需要研究哪些topic幫助了解64bit的世界。
參考了幾個網站之後,主要是 http://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/
建置環境的步驟如下:
0. 準備toolchain
$ wget http://releases.linaro.org/12.10/components/toolchain/gcc-linaro/aarch64/rc3/gcc-linaro-aarch64-linux-gnu-4.7+bzr115029-20121015+bzr2506_linux.tar.bz2
$ tar xf gcc-linaro-aarch64-linux-gnu-4.7+bzr115029-20121015+bzr2506_linux.tar.bz2
$ export PATH=$PATH:$PWD/gcc-linaro-aarch64-linux-gnu-4.7+bzr115029-20121015+bzr2506_linux/bin
1. 取得kernel source。
$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
2. Setup ARM64 QEMU. (以QEMU做為我們硬體的環境)
$ git clone git://git.qemu.org/qemu.git qemu.git
$ cd qemu.git
$ ./configure --target-list=aarch64-softmmu
$ make
3. Build your own rootfs
$ git clone git://git.buildroot.net/buildroot buildroot.git
$ cd buildroot.git
$ make menuconfig
Configure it
* 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)
* System configuration -> getty options -> TTY Port (ttyAMA0)
(BR2_TARGET_GENERIC_GETTY_PORT)
* Target Packages -> Show packages that are also provided by busybox
* 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 images -> cpio the root filesystem (for use as an initial RAM
filesystem) (BR2_TARGET_ROOTFS_CPIO)
$ make
4. Build Kernel and Run it on QEMU.
以上,應該可以跑起來。下個階段嘗試使用GDB進入,以便進行kernel source level的單步執行。
$ make
4. Build Kernel and Run it on QEMU.
Configure Kernel
* CONFIG_CROSS_COMPILE="aarch64-linux-gnu-" # needs to match your cross-compiler prefix
* CONFIG_INITRAMFS_SOURCE=
"/home/alex/lsrc/qemu/buildroot.git/output/images/rootfs.cpio"
# points at your buildroot image
* CONFIG_NET_9P=y # needed for virtfs mount
* CONFIG_NET_9P_VIRTIO=y
$ ARCH=arm64 make -j 8 5. Run your kernel and rootfs on ARM64 QEMU
$ ./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -machine type=virt -nographic -smp 1 -m 2048 -kernel ../linux.git/arch/arm64/boot/Image --append "console=ttyAMA0"
以上,應該可以跑起來。下個階段嘗試使用GDB進入,以便進行kernel source level的單步執行。
沒有留言:
張貼留言