2015/07/06

Run ARM64 on Qemu

Install Required Tools
  
  sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ncurses-dev g++


Toolchain Installation
Linaro toolchain is believed to be more stable and more complete, easier to install compared to install from main repository.
https://www.linaro.org/downloads/
Choose the Linux version of "linaro-toolchain-binaries (little-endian)"
Latest link when this document is composed:
https://releases.linaro.org/15.02/components/toolchain/binaries/arm-linux-gnueabihf/gcc-linaro-4.9-2015.02-3-x86_64_arm-linux-gnueabihf.tar.xz
Download toolchain to ~/src
  
  tar xvf gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu.tar.xz 
  export PATH=~/src/gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu/bin/:$PATH


Build Qemu
Get a copy of Qemu from http://wiki.qemu.org/Download, saved to ~/src
  
  cd ~/src
  tar xvf qemu-2.3.0.tar.bz2
  cd qemu-2.3.0
  mkdir -p bin
  cd bin
  ../configure --enable-debug --target-list=aarch64-softmmu
  make -j9
The executable could be find at ~/src/qemu-2.3.0/bin/aarch64-softmmu/qemu-system-aarch64


Build RAM File System
Get a build root copy from http://buildroot.uclibc.org/download.html, save to ~/src
  
  cd ~/src
  tar xvf buildroot-2015.05.tar.bz2
  cd buildroot-2015.05
  make menuconfig
    have below configuration configured
    * Target Options -> Target Architecture(AArch64)
    * Toolchain -> Toolchain type (External toolchain)
    * Toolchain -> Toolchain (Custom toolchain)
    * Toolchain -> Toolchain origin (Pre-installed toolchain)
    * Toolchain -> Toolchain path (/home/xgu/src/gcc-linaro-4.9-2015.02-3-x86_64_aarch64-linux-gnu)    
    * Toolchain -> Toolchain prefix ($(ARCH)-linux-gnu)
    * Toolchain -> External Toolchain kernel headers series (3.17.x)
    * Toolchain -> External Toolchain C library (glibc/eglibc)
    * Toolchain -> Toolchain has RPC support? (enable)
    * Toolchain -> Toolchain has C++ support? (enable)
    * 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)
  
    or a simpler configure is to use build-in toolchain (lower version)
    * Target Options -> Target Architecture(AArch64)
    * Toolchain -> Toolchain type (External toolchain)
    * Toolchain -> Toolchain (Linaro AArch64 14.09)
    * 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
You will find image generated at output/images/rootfs.cpio
 
 
Build Linux Kernel
Get a copy of kernel at https://www.kernel.org/, save it to ~/src
  
  cd ~/src
  tar xvf linux-4.1.1.tar.xz
  cd linux-4.1.1
  export ARCH=arm64
  make defconfig    
  ./scripts/config --file .config --set-str CONFIG_CROSS_COMPILE aarch64-linux-gnu-
  ./scripts/config --file .config --set-str CONFIG_INITRAMFS_SOURCE ~/src/buildroot-2015.05/output/images/rootfs.cpio
  make -j9
You will find image generated at linux_dir/arch/arm64/boot/Image


Run Everything Together
  cd ~/src/qemu-2.3.0/bin
  ./aarch64-softmmu/qemu-system-aarch64 -machine virt -cpu cortex-a57 -nographic -smp 1 -m 512 -kernel ~/src/linux-4.1.1/arch/arm64/boot/Image --append "console=ttyAMA0"


Reference
http://www.bennee.com/~alex/blog/2014/05/09/running-linux-in-qemus-aarch64-system-emulation-mode/
http://wiki.qemu.org/Hosts/Linux

No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...