Skip to content

Instantly share code, notes, and snippets.

Created March 17, 2015 17:01
Show Gist options
  • Save anonymous/87b0b319eb0ea5e54036 to your computer and use it in GitHub Desktop.
Save anonymous/87b0b319eb0ea5e54036 to your computer and use it in GitHub Desktop.

build android guest on linux-kvm-arm host on arm Fast Model

all files

binaries/
├── config                (download from virtualopensystem)
├── cookies.txt           (download from virtualopensystem)
├── jb_ve_4_1_1.bz2       (download from virtualopensystem)
├── linux-system-semi.axf (download from virtualopensystem)
└── zImage                (download from virtualopensystem)

linux-kvm-arm/            (clone from github:virtualopensystem/linux-kvm-arm)
qemu/                     (clone from github:virtualopensystem/qemu)
boot-wrapper/             (clone from github:virtualopensystem/boot-wrapper)

misc/
└── files/                (download from ITRI's email)
    ├── busybox
    ├── utelnetd
    └── qemu.tar

result/
├── arm_fastmodel_license (download from ARM Fast Model, 名子可以自己取, 網頁上會直接噴 license 的內容給你複製)
├── linux-system-semi.axf (build from boot-wrapper or binaries/linux-system-semi.axf)
├── pure_zImage           (build from linux-kvm-arm)
├── zImage                (build from linux-kvm-arm, and append dtb, or binaries/zImage)
├── host.img
└── guest.img

main routine

  • ARM Fast Model & license

    • ARM 官網 download, 軟體有 license
    • download url: https://silver.arm.com/browse/browse_eval.tm
      • 申請帳號
      • 下載 Fast Model 跟拿 license, 要求填入 MAC address
    • installation: ./setup.sh (要求 pre-install 一些 packages, sudo apt-get install ...)
    • running: source FastModelsTools_9.2/source_all.sh && FastModelsTools_9.2/bin/sgcanvas & (sh/bash)
    • In FastModel, build a simulation executable (isim-system, 詳情見 slide)
  • kernel (linux-kvm-arm) & boot wrapper (choose one of 1. and 2.)

    1. binary from virtualopensystem
    • kernel: see Download from virtualopensystem
    • boot wrapper: see Download from virtualopensystem
    1. source from github and build
    • [build|arm] kernel source: virtual-open-system's github

      • kernel config: see Download from virtualopensystem

      • build:

        # use sh/bash
        # copy config into linux-kvm-arm/.config
        CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make
        CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make dtbs
        # append dtb to zImage
        cp arch/arm/boot/zImage ../result/zImage
        arch/arm/boot/dts/rtsm_ve-cortex_a15x1.dtb >> ../result/zImage
        
    • [build|arm] bootloader source: virtual-open-system's github

      • build:

        LOADADDR=0x80008000 CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make
        
  • Image(host.img & guest.img & qemu)

    • guest.img

      • dd an 700MB empty image, format file system as ext3, mount as loop device, dump android userland files to image.

      • detail command:

        dd if=/dev/zero of=./guest.img bs=1MiB count=700
        mkfs.ext3 ./guest.img
        mkdir mnt
        sudo mount -o loop guest.img mnt
        sudo tar xpjvf ../binaries/jb_ve_4_1_1.bz2 -C mnt/ --numeric-owner
        sudo umount mnt
        
    • host.img

      • same as guest.img, but image was 1.7GB (larger than guest.img, but smaller than 2GB).
      • move qemu, busybox, utelnetd on host.img
      • move binaries/qemu.tar's keymaps on host.img
      • move guest.img, pure_zImage on host.img
        • notice: zImage here using pure image, without appending dtb file. (virtualopensystem's zImage isn't pure)
    • qemu

      • source from github:virtualopensystem/qemu

      • make a patch to qemu: use qemu.tar's keymaps(/usr/local/share/qemu/keymaps) replace origin (pc_bios/keymaps)

      • sudo apt-get install pkg-config-arm-linux-gnueabi

      • build zlib from xapt: see cross compile

      • build:

        ./configure --cross-prefix=arm-linux-gnueabi- \
        --target-list=arm-softmmu \
        --audio-drv-list="" \
        --audio-card-list="" \
        --enable-fdt \
        --enable-kvm \
        --disable-seccomp \
        --static
        make -j4
        

running

  • android-host on ARM Fast Model

    • host.img + zImage

    • run Fast Model:

      # use sh/bash
      ARMLMD_LICENSE_FILE=~/android_kvm_on_FM/result/arm_fastmodel_license \
      ~/ARM/FastModelsPortfolio_9.2/examples/FVP_VE/Build_Cortex-A15x1/Linux64-Release-GCC-4.7/isim_system \
      -a cluster.cpu0=~/android_kvm_on_FM/result/linux-system-semi.axf \
      -C motherboard.smsc_91c111.enabled=1 \
      -C motherboard.mmc.p_mmc_file="result/host.img" \
      -C motherboard.hostbridge.interfaceName="tap0" \
      -C cluster.cpu0.semihosting-cmd_line="--kernel ~/result/zImage  -- earlyprintk console=ttyAMA0,38400n8 mem=1500M ip=dhcp root=/dev/mmcblk0 rw init=/init"
      
  • android-guest on qemu-kvm

    • guest.img + zImage

    • run qemu-kvm:

      #strace \
      ./qemu-system-arm \
      -vnc :0 \
      -k en-us \
      -enable-kvm \
      -serial stdio \
      -kernel zImage \
      -m 512 -M vexpress-a15 -cpu cortex-a15 \
      -drive file=/vm/guest.img,id=virtio-blk,if=none \
      -device virtio-blk,drive=virtio-blk,transport=virtio-mmio.0 \
      -append "virtio_mmio.device=1M@0x4e000000:74:0 init=/init
               console=ttyAMA0 mem=512M root=/dev/vda rw"
      

Download from virtualopensystem

# Download things from virtual-open-system, login first and save cookie
wget --save-cookies cookies.txt --post-data 'username=downloader&password=uploading1' http://www.virtualopensystems.com/logintrml/

# Download kernel config
wget --load-cookies cookies.txt http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/config
# [if needed] Download kernel(binary image): zImage
wget --load-cookies cookies.txt http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/zImage
# [if needed] Download boot-wrapper: linux-system-semi.axf
wget --load-cookies cookies.txt http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/linux-system-semi.axf
# [if needed] Download qemu binary: qemu.zip
wget --load-cookies cookies.txt http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/qemu.zip

cross compilation at arm

install cross compiler:

apt-get install gcc-arm-linux-gnueabi

For cross compile QEMU, must install cross compiled version dev-libs. (./configure need this libs) Since we are using -el- version, we do the following. (notice: Ubuntu 14.04 doesn't have -el- version. please use 12.04 in armel-precise.list)

sudo apt-get install xapt

sudo joe /etc/apt/sources.list.d/armel-precise.list
    deb [arch=armel] http://ports.ubuntu.com/ubuntu-ports precise main restricted universe multiverse
    deb-src [arch=armel] http://ports.ubuntu.com/ubuntu-ports precise main restricted universe multiverse

sudo xapt -a armel -m -b zlib1g-dev libglib2.0-dev libfdt-dev libpixman-1-dev
sudo dpkg -i /var/lib/xapt/output/*.deb

application

  • network setting in ubuntu(tap0):

    sudo ip tuntap add tap0 mode tap
    sudo ip link set tap0 up
    sudo ip addr add 1.1.1.1/24 dev tap0
    sudo ifconfig tap0 up
    
  • network setting in android(tap0):

    busybox ifconfig eth0 up # if eth0 is not up.
    busybox ifconfig eth0 1.1.1.2/24
    
  • telnet server: utelnetd -l /system/bin/sh &

debug kernel

cat /proc/kmsg

strace userland program

Misc

  • ARM Fast Model
    • arm board fast prototype and simluation, for early developing software in special ARM board.
  • armel v.s. armhf
  • xapt
    • convert Debian packages to cross version on-the-fly
    • Limitation: when doing apt-get upgrade, if dependency of xapt-installed packages needed to be upgraded, xapt-installed packages will be removed.
    • Thus, the best option is to use "xapt" inside a disposable chroot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment