Android & Virtualization on Fast Models
A guide for utilizing Android as host and guest on ARM Fast Models
This Virtual Open Systems guide explains how to virtualize Android Jelly Bean on an ARM Cortex-A15 Fast Models development environment. An Android guest is virtualized by the KVM on ARM hypervisor running on a host Android Jelly Bean operating system.
Introduction to Android KVM virtualization
The advent of tablets and smartphones has revolutionized the mobile market. Currently, many of the ARM-based tablet and smartphone products are running the Android software. With the newly released version of Android, the Jelly Bean, Google unifies tablets and mobile devices, by incorporating the Honeycomb features and various enhancements into the new OS. In addition a new generation of tablet and mobile products based on ARM Cortex-A15 MPCore has been introduced to the market. The ARM multicore architecture provides an out-of-order super-scalar pipeline running at up to 2.5 GHz and supports ARMv7 instruction set. Cortex-A15 is the first ARM processor which supports the Hardware-Assisted Virtualization (HAV) and the Large Physical Address Extensions (LPAE).
With these features, ARM Cortex-A15 is suitable for both consumer market and for lightweight server tasks, like running a web server and in a micro-server configuration for cloud computing. Within this context, virtualization is an ubiquitous technology in enterprise data-centers and cloud computing infrastructures. Virtualization introduces one level of indirection between logical and physical context. Such indirection has proven to be remarkably powerful and efficient. In modern platforms, for consumer and server markets, this indirection is used in numerous ways. For instance in a hypervisor, a software layer that decouples an operating system and its applications from the real hardware, or in a Virtual Machine (VM) that is a software layer emulating a hardware platform.
In order to start software development for modern platforms based on Cortex-A15 that use virtualization technologies, it is possible to provide a virtual representation of the hardware ahead of the real platform. Using technologies such as the ARM Fast Models, software developers can satisfy different application scenarios in advance. Thus Fast Models can help engineers to debug, optimize and analyze software applications and middle-ware environments, such as Android. In this document, we will describe how to boot an Android Jelly Bean host and guest on ARM Fast Models (refer also to the Android on FastModels virtualization video demo).
KVM (Kernel-based Virtual Machine) is an open-source hypervisor, used extensively for achieving full hardware virtualization (and optionally paravirtualization). KVM relies on the Linux kernel's process and memory management features, to handle Virtual Machines. Instead of performing emulation by itself, it uses a user space driver program e.g. QEMU (Quick Emulator), to set up guest VM address space and map peripheral devices.
KVM can take advantage of CPU-specific hardware extensions, such as Intel VT, AMD-V and ARM, to optimize and accelerate the virtualization process. The Cortex-A15 is the first ARM processor using the hardware virtualization extensions, for which KVM has been ported. Virtual Open Systems is active in developing the KVM port for the latest ARM multicore processors, such as the Cortex-A15, big.LITTLE, ARMv7 and ARMv8 architectures.
The following components will either be described or provided, for successfully completing this guide:
Installation and setup of the simulation platform ARM Fast Models simulator is needed to generate a Cortex-A15 Versatile Express model.
An Android-ready Linux kernel We provide a pre-compiled kernel which will boot Android on the simulation platform.
The Android Jelly Bean OS userland files Pre-compiled Android Open Source Project (AOSP) binaries (v4.1.1) to boot the host OS.
QEMU and an Android guest Utilize QEMU in conjunction with KVM, to boot Android as a guest under our Android host.
The new Cortex-A15 MPCore processor, is the first ARM-A series processor to introduce hardware virtualization extensions, together with increased performance (up to 40% faster than A9) and the standard ARM low power features. Key features include:
Full Virtualization using Hardware Extensions
Large Physical Address Extensions (LPAE)
VFPv4 Floating point
NEON Advanced SIMD extensions
1-4x SMP within a single processor cluster and up to 2 clusters per chip
Cortex-A15 block diagram
The Versatile Express family of development platforms provides the right environment for prototyping the next generation of system-on-chip designs. Thanks to its flexible, modular architecture, and high-speed interfaces, hardware and software applications can be developed and debugged quickly and efficiently.
Versatile Express Fast Models Block Diagram
The platform consist of three main blocks:
Motherboard: Consists of several peripherals and the optional addition of plug-in daughter boards.
CoreTile: CPU block supporting Cortex-A15, Cortex-A9 and Cortex-A5 processors.
LogicTiles: Optional daughter board blocks for the purpose of enhancing the usability of the platform, providing various customizable features.
Versatile Express diagram
Some of the major peripheral components of the Versatile Express platform are:
PL011 UART (serial communication)
PL031 Real Time Clock
PS2 Mouse & Keyboard
PL111 Color LCD (Software Rendering, no GPU)
MultiMedia Card Interface (MMCI)
SP805 Watchdog timer
PL390 Generic Interrupt Controller (GIC)
SMSC91C111 Ethernet Controller
PL041_AACI audio interface (partially implemented)
Android Jelly Bean & ARM Fast Models
As described in the official documentation, Android 4.1 (Jelly Bean) is the latest version of the Android platform for various devices, including but not limited to mobile phones, tablets and net-books. It continues to advance and optimize things people love most about Android — easy multitasking, rich notifications, customizable home screens, sizable widgets, and deep interactivity — and adds powerful new ways of communicating and sharing.
Android consists of a multi level architecture based on top of a customized Linux kernel. Middleware and libraries are written in C, while application software is utilizing a Java compatible framework. It also includes the Dalvik virtual machine, which enables further optimizations by just-in-time compilation of Java bytecode.
Main Android features:
Application framework (Java compatible)
Dalvik Virtual Machine (JIT compilation)
Rich development environment (device emulator, debugging, profiling etc.)
Linux kernel (hardware drivers, networking, file system access etc.)
Android system architecture
The model of the hardware platform that we use in the simulator is that of the Versatile Express platform, together with a Cortex-A15 core tile. As the name suggests, ARM provides this product family for the development of flexible and modular prototyping systems.
To install and setup Fast Models (version 8), it is advised to follow the installation procedure in our previous KVM-on-ARM guide. Additionally, it is recommended to choose a 32 bit build configuration even if using Fast Models on a 64 bit system, due to slightly better performance. For example, under Select Active Project Configuration, choose Linux-Release-GCC-4.1 instead of Linux64-Release-GCC-4.1.
Build a static version of the model
Optionally, the user can choose to build a static version of the model by selecting the Integrated simulator (ISIM system) check-box option in the "Targets" tab, under Settings. This will create an isim_system executable that can be used directly, instead of loading the cadi_system library under model shell.
Fast Models offers a range of processors and platforms to simulate. On this guide we will mainly focus on the Versatile Express platform, with Cortex-A15.
The following models can be used for this guide:
Linux kernel & bootwrapper
If you want to skip compiling the kernel and bootwrapper, download pre-compiled binaries from Virtual Open Systems:
$ wget http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/zImage $ wget http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/linux-system-semi.axf
Compiling the kernel
First, checkout the kernel source:
$ git clone git://github.com/virtualopensystems/linux-kvm-arm.git -b kvm-vexpress-3.9
Then, download a proper kernel configuration in the kernel source directory:
$ curl http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/config >.config $ CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make
Finally create the device tree blob for our target, and concatenate it to the kernel image
$ CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make dtbs $ cp arch/arm/boot/zImage boot-wrapper/ $ cat arch/arm/boot/dtbs/rtsm_ve-cortex_a15x1.dtb >> boot-wrapper/zImage
For a more detailed process of compiling the kernel, consult our previous KVM-on-ARM guide.
We cannot run directly the resulting uImage on Fast Models. Other than basic initialization, the CPU needs to be in Hypervisor mode when the kernel is booted. For these reasons we need a small boot loader.
Grab the bootwrapper source (best to check out this repository within the kernel source directory) and compile:
$ git clone git://github.com/virtualopensystems/boot-wrapper.git $ LOADADDR=0x80008000 CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm make
The Makefile of the bootwrapper will search for the kernel directory (check config-default.mk) and will create the bootwrapper binary along with copying the compiled uImage on the bootwrapper directory. Note that there are two bootwrapper binaries: linux-system.axf and linux-system-semi.axf. The difference is that the later, uses the semihosting feature in order to pass various information (such as kernel arguments) into Fast Models, instead of having such data hard-coded into the binary. For this guide we will only use linux-system-semi.axf
Userland and simulation execution
First, we need to download the Android userland files:
$ wget http://www.virtualopensystems.com/downloads/guides/kvm_android_on_fastmodels/jb_ve_4_1_1.bz2
Then, create an image file and format it as an ext3 filesystem:
$ dd if=/dev/zero of=./android.img bs=1MiB count=1024 $ mkfs.ext3 ./android.img
Finally, mount the image file and extract the userland files in it:
$ mkdir mnt $ sudo mount -o loop android.img mnt $ sudo tar xpjvf jb_ve_4_1_1.bz2 -C mnt/ --numeric-owner" $ sudo umount mnt
Note that you should repeat this process when creating the guest filesystem, so make sure that the host image has enough space when copying the guest image in it. Also, make sure that the host image is not larger than 2GB, Fast Models is known to have troubles reading files more than 2GB in size.
Before running the simulator it is a good time to setup bridge networking for Fast Models. Run the following script to create a bridge, and add your network interface together with a TUN/TAP device. This TUN/TAP device will then be used from Fast Models to access the local network. Make sure to edit the two last lines according to your network setup:
$ brctl addbr br0 $ tunctl -u root $ ifconfig eth0 0.0.0.0 up $ ifconfig tap0 0.0.0.0 up $ brctl addif br0 eth0 $ brctl addif br0 tap0 $ ifconfig br0 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255 $ route add default gw 192.168.1.254
We are now able to start the simulator and boot our system with the following command. The boot process will take somewhere around 3-5 minutes (depending on the host machine) to completely boot Android:
$ ./isim_system \ -a cluster.cpu0=linux-system-semi.axf \ -C motherboard.smsc_91c111.enabled=1 \ -C motherboard.mmc.p_mmc_file="android.img" \ -C motherboard.hostbridge.interfaceName="tap0" \ -C cluster.cpu0.semihosting-cmd_line="--kernel zImage -- earlyprintk console=ttyAMA0,38400n8 mem=1024M ip=dhcp root=/dev/mmcblk0 rw init=/init"
Upon booting click the middle right part in the CLCD display to open the Android main menu.
Login or register to access full information