Home > Android, Testing > How to Build and Run Android L 64-bit ARM in QEMU

How to Build and Run Android L 64-bit ARM in QEMU

Most people can’t afford Juno Cortex A57/A53 development board, and mobile processors based on the latest 64-bit ARM cores are only expected by early 2015. But thanks to a small team at Linaro, you can now build and run Android L 64-bit ARM in the latest version of QEMU that supports Aarch64. Alex Bennée, an engineer working for Linaro, wrote a blog post in Linaro’s Core Dump blog explaining the Android emulator is actually based on QEMU,  the differences compared to mainline QEMU, the work they’ve done on Android L at Linaro, and most importantly, provided the basic steps showing how to build and try Android L 64-bit ARM (ARMv8) in QEMU. I’ve just done that, but unfortunately, albeit the builds complete, I could not manage to start Android L in QEMU yet. [Update: working now]. If you want to give it a try, you’ll need a Linux PC, and patience, as it may take about one day to retrieve the source code, and build everything from source.

Android_L_64-bit_ARM_QEMU

I’ve done all this in a computer running Ubuntu 14.04 with an AMD FX8350 processor and 16 GB RAM.

First, you’ll need to install an ARM 64-bit toolchain, some dependencies, and tools:

sudo apt-get install gcc-aarch64-linux-gnu build-essentials git bison zlib1g-dev \
libglib2.0-dev libpixman-1-dev gperf android-tools-adb vncviewer

The next step is to cross-compile a Linux 3.10 kernel for Android:

mkdir -p ~/edev/linaro
git clone https://git.linaro.org/people/christoffer.dall/linux-android.git
cd linux-android
git checkout ranchu-linaro-beta1

There’s a bug include the current version of the toolchain in Ubuntu 14.04 (https://bugs.launchpad.net/linaro-linux-baseline/+bug/1258013) which prevents the build to complete. You can either remove CONFIG_DEBUG_INFO=Y in arch/arm64/configs/ranchu_defconfig (I did that), or update your toolchain. Let’s complete the build:

ARCH=arm64 make ranchu_defconfig
ARCH=arm64 make CROSS_COMPILE=aarch64-linux-gnu- -j8

Now you need to build the Android Open Source Project (AOSP). If you haven’t done so, you’ll have to install the repo tool:

mkdir ~/bin
PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo

Then get AOSP source code (master as below, or l-preview branch):

cd ..
mkdir AOSP
repo init -u https://android.googlesource.com/platform/manifest
repo sync

The last step can take a few hours depending on your internet connection to Google servers.
Now download and apply a patch made by Linaro:

wget http://people.linaro.org/~christoffer.dall/linaro-devices.tar.gz
tar -xvf linaro-devices.tar.gz

Possibly configure git:

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

You need to apply a patch for qemu:

pushd system/core
wget http://people.linaro.org/~alex.bennee/android/android-init-tweaks.diff
patch -p1 < android-init-tweaks.diff 
popd

And build Android L for ARMv8:

source build/envsetup.sh
lunch ranchu-userdebug
m -j8

The last step will again take a while. It took my machine 2 or 3 hours, and the total time was actually a bit more than than as my PC suffered two thermal shutdowns during the build, and I had to restart the build twice. The last time, I decided to underclock my CPU to 3.4 GHz, and the build went through.

The last step before running Android L is to build QEMU:

cd ..
git clone https://git.linaro.org/people/peter.maydell/qemu-arm.git
cd qemu-arm
git checkout ranchu-linaro-beta1
make -j8

Builds should now all be successfully complete. We just need to create some symlinks helping to shorten qemu command line, start the ADB server, and run QEMU:

cd ..
ln -s linux-android/arch/arm64/boot/ ranchu-kernel
ln -s AOSP/out/target/product/ranchu/ ranchu-build
adb start-server
./qemu-arm/aarch64-softmmu/qemu-system-aarch64 -cpu cortex-a57 -machine type=ranchu -m 4096 \
-kernel ./ranchu-kernel/Image -append 'console=ttyAMA0,38400 keep_bootcon' -monitor stdio \
-initrd ranchu-build/ramdisk.img -drive index=2,id=userdata,file=ranchu-build/userdata.img \
-device virtio-blk-device,drive=userdata -device virtio-blk-device,drive=cache \
-drive index=1,id=cache,file=ranchu-build/cache.img -device virtio-blk-device,drive=system \
-drive index=0,id=system,file=ranchu-build/system.img -netdev user,id=mynet \
-device virtio-net-device,netdev=mynet -show-cursor

That’s the output I get:

QEMU 2.0.50 monitor - type 'help' for more information
console on port 5554, ADB on port 5555
VNC server running on `127.0.0.1:5900'

So it’s quite possible there’s a problem with adb, but Google did not help, and I failed to go further. More detailed instructions will soon be posted in Linaro Wiki, so I may be able to find out where I made a mistake once it’s posted.

Finally, start vncviewer to access Android user’s interface:

vncviewer 127.0.0.1:5009

Here’s a screenshot of the “About Device” menu in Android L 64-bit ARM running in QEMU.
Android_64-bit_ARM_Qemu

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

  1. svarthol
    August 24th, 2014 at 08:37 | #1

    To change or remove CONFIG_DEBUG_INFO=Y before compiling the kernel
    I needed to go into file “arch/arm64/configs/ranchu_defconfig”

  2. August 24th, 2014 at 09:48 | #2

    @svarthol
    Thanks. I’ve updated the post.
    Let me know if you manage to start Android L.

  3. August 25th, 2014 at 16:18 | #3

    I think your also missing the patch that links /dev/qemu_pipe to /dev/android_pipe in the Android build which is why adb isn’t starting.

  4. August 25th, 2014 at 20:07 | #4

    @Alex Bennee
    Thanks, I just wongly assumed it was part of the patched AOSP tree, but it is a separate patch then. However, when I follow https://android-review.googlesource.com/#/c/104722/, it asks me to login to gerrit (which I did), and then says

    “Not Found
    The page you requested was not found, or you do not have permission to view this page.”

  5. August 27th, 2014 at 01:06 | #5

    Many apologies, it looks like the patches aren’t visible in draft form (and I don’t actually want to push them upstream yet). You can find a combined diff here: http://people.linaro.org/~alex.bennee/android/android-init-tweaks.diff

  6. Rodney Lederer
    August 28th, 2014 at 08:23 | #6

    Seems the build is broken. I repo’d just the l-preview branch. I get fatal errors on building chromium.. exact error:

    In file included from external/chromium/chrome/browser/autofill/personal_data_manager.h:24:0,
    from external/chromium/android/autofill/profile_android.cc:28:
    external/chromium/chrome/browser/webdata/web_data_service.h:27:52: fatal error: third_party/skia/include/core/SkBitmap.h: No such file or directory
    #include “third_party/skia/include/core/SkBitmap.h”
    ^
    ubuntu 13.10 for environment

  7. August 30th, 2014 at 17:21 | #7

    @Alex Bennee
    Thanks I’ve applied the patch in system/core, and build android again. But no luck, still the same error. I’ve updated the post in case somebody manages to get it working. I think I’ll just wait for the Wiki entry in Linaro.

  8. xfim
    September 1st, 2014 at 01:51 | #8

    Hi, is there a version of this for 32 bit ARMv7 SBCs running Linux like my Jetson TK1 with Tegra K1?
    Thanks.

  9. TK
    September 1st, 2014 at 12:08 | #9

    @cnxsoft
    I encountered the same error, i.e “adb_server_notify: Failed to establish connection to ADB server”. And my solution is to lunch an ADB server at localhost. It’s quiet simple, just type “adb start-server” in the console, and it will lunch an ADB server at localhost. Once QEMU conntects to ADB server, it will boot the Android64 after few minutes. I successfully booted it and the model number showed “AOSP on Linaro arm64 Emulator”. Though the browser failed to lunch for unknown reasons.

  10. September 1st, 2014 at 19:24 | #10

    @TK
    Thanks it works now! I also had to install and run vncviewer. I’ve updated the instructions.
    The Android version is a bit funny 4.4.43.43.43… Maybe that’s what Android L is now called because Google have not figured out which version they want to give yet…

  11. September 3rd, 2014 at 09:09 | #11

    Instructions to install Android Aarch64 on Juno development board -> http://www.youtube.com/watch?v=ojg4eZ-l3Po

  12. September 15th, 2014 at 18:46 | #12

    I have done all like you,but system will stay in “ANDROID” and have log ” No [stack] line found in /proc/self/maps!” when logcat in adb shell.My AOSP is downloaded at 19th August.Is it some error in AOSP?

  1. September 16th, 2014 at 21:15 | #1