Running Android on ZedBoard
I was very impressed when I saw this video demonstrating how you can run Android on the Mars ZX3 Zynq module from Enclustra. If they can do it we can do it. Let's give it a try.
Work in progress
I am still working on this page. Changes will be done to fix mistakes I have made and to add new stuff.
A word of warning
Before you start implementing Android, study the last part of this blog entry. I am still waiting for a solution to the boot up problem. If you want to try something that works you should install Android 2.3 instead.
Android is an operating system based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Initially developed by Android, Inc., which Google backed financially and later bought in 2005.
Android's architecture diagram
To make full use of the Android operating system we have to add a touchscreen display to our ZedBoard. We have to figure out what is the best and cheapest solution but until then I will will continue the experiment without the display.
Before starting this experiment we have make sure we have at least 50GB free disk space. The Android installation itself, takes up almost 20GB and to build Android we need at least 30GB free disk space. If you have 50GB disk space available, congratulations. I don't have. I see two possibilities:
- Start all over with a new StorEdge card.
- Use shared folders and put the Andorid source code on the host computer.
I have decided to buy one more StorEdge 128GB card and setup a new VirtualBox virtual machine, making the virtual disk 120GB and then install Ubuntu 14.04 64bit (I couldn't find Ubuntu 13.10 any longer).
Recommended RAM size
In the documentation it says that 16GB RAM is recommended to compile and build Android 4.1. I have 4GB in my virtual machine. Will that last? No idea.
Read before we start
Here is the link to the official Android build documentation.
Install Ubuntu software packages
To be able to compile and build the Android system we have to install a number of software packages. We will follow this guide from xdadevelopers. Here is a command we can use to install everything in one run:
sudo apt-get install git-core lzop ccache gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python gcc g++ cpp gcc-4.8 g++-4.8 libswitch-perl
When that is done installing, run the following command in a terminal window:
-> sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
Java programming language
Most of the Android application source code is written using the Java programming language. Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to run on another.
Java was originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform.
Java SE platform
One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any hardware/operating-system platform. This is achieved by compiling the Java language code to an intermediate representation called Java bytecode, instead of directly to platform-specific machine code. Java bytecode instructions are analogous to machine code, but they are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware.
Oracle Corporation is the current owner of the official implementation of the Java Standard Edition platform. This implementation is based on the original implementation of Java by Sun. The Oracle implementation is available for Mac OS X, Windows and Linux. Because Java lacks any formal standardization, the Oracle implementation is the de facto standard.
The Oracle implementation is packaged into two different distributions: The Java Runtime Environment (JRE) which contains the parts of the Java SE platform required to run Java programs and is intended for end-users, and the Java Development Kit (JDK), which is intended for software developers and includes development tools such as the Java compiler, Javadoc, Jar, and a debugger.
Java development kit
The Java Development Kit (JDK) is an implementation of either one of the Java SE, Java EE or Java ME platforms released by Oracle Corporation in the form of a binary product aimed at Java developers on Solaris, Linux, Mac OS X or Windows. In 2006, Sun announced that it would be released under the GNU General Public License (GPL), thus making it free software. This happened in large part in 2007, when Sun contributed the source code to the OpenJDK.
Download and install JDK
First, let's set up the correct JDK (Oracle's JDK). Many of us probably have some kind of wrong Java installed unless we're starting with a fresh Ubuntu base. Let's get rid of that. Copy and paste this into a Terminal window:
-> sudo apt-get purge openjdk-* icedtea-* icedtea6-*
Follow the instructions to remove OpenJDK. Now copy and paste the following into the Terminal:
-> sudo add-apt-repository ppa:webupd8team/java
This will add the correct PPA to our system for updated builds of Java 6 JDK that are compatible with Ubuntu 13.10. No more unrecognized Java version errors! And it will update automatically with the rest of our system. Next, we actually need to install the package. More copy-paste:
-> sudo apt-get update && sudo apt-get install oracle-java6-installer
Follow the on-screen instructions. We have to Accept the Licensing Agreement to complete the install. Let's make sure the correct version of Java is activated, run the following Terminal command:
-> java -version
Download and install Sourcery CodeBench
To build the Linux kernel we need to install the ARM toolchain. The Android source code includes a script to build the Linux kernel. This script is setup to use the GNU/Linux version of Sourcery CodeBench.
Sourcery CodeBench is a complete development environment for embedded C/C++ development on ARM, Power, ColdFire, and other architectures. Sourcery CodeBench Lite Edition includes:
- GNU C and C++ compilers
- GNU assembler and linker
- C and C++ runtime libraries
- GNU debugger
This Getting Started Guide explains how to install and use Sourcery CodeBench ARM GNU/Linux Lite.
1. Before starting the installation we have to install the following package:
-> sudo apt-get install libxst6:i386
2. Download the installer from the Mentor Graphics web page.
3. Select ARM processors and download the ARM GNU/Linux release.
4. Make the arm-2013.11-24-arm-none-linux-gnueabi.bin file executable.
-> chmod 755 arm-2013.11-33-arm-none-linux-gnueabi.bin
5. Start the installer as root.
-> sudo ./arm-2013.11-33-arm-none-linux-gnueabi.bin
6. Install the toolchain here:
7. Add the bin path to the PATH variable in the .profile file:
8. Add the following line in your .bashrc file
9. Logout and login to enable the settings for the Ubuntu system.
Download and install Android source code
The Android source tree is located in a Git repository. This document describes how to download the source tree for a specific Android code-line. We will download Android 4.1 (Jelly Bean) modified for Zynq and ZedBoard.
Repo is a tool that makes it easier to work with Git in the context of Android.
1. Make sure we have a bin directory in our home directory and that it is included in our path variable.
2. Download the Repo tool and ensure that it is executable:
-> curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
-> chmod a+x ~/bin/repo
1. We will start by adding a project directory for our Android installation:
-> mkdir Projects/Android
-> cd Projects/Android
2. Configure GIT and add our email address and name:
-> git config --global user.email email@example.com
-> git config --global user.name "Sven Andersson"
3. Initialize Repo with the GIT repository we will use:
-> repo init -u git://github.com/cambridgehackers/zynq-android4.git -b jb -m default.xml
Downloading the Android source tree
To pull down the Android source tree to our working directory from the repositories as specified in the default manifest, run:
-> repo sync
The Android source files will be located in our working directory under their project names. The initial sync operation will take an hour or more to complete. Here is the result, almost 20GB of data has been downloaded.
Fixing the code
According to this guide the downloaded Android source code has some errors that must be fixed. Let's do that.
Building the system
After downloading the Android source code and installing the JDK we are ready to build our Android system. Initialize the environment with the envsetup.sh script. Note that replacing "source" with a single dot saves a few characters, and the short form is more commonly used in documentation.
-> cd Projects/Android
-> source build/envsetup.sh
Choose a target
Choose which target to build with lunch command. The exact configuration can be passed as an argument.
If run with no arguments lunch will prompt us to choose a target from the menu.
Build the code
Build everything with make. GNU make can handle parallel tasks with a -jN argument, and it's common to use a number of tasks N that's between 1 and 2 times the number of hardware threads on the computer being used for the build. E.g. on a dual-E5520 machine (2 CPUs, 4 cores per CPU, 2 threads per core), the fastest builds are made with commands between make -j16 and make -j32. I don't know how many parallel tasks I can handle due to my 4GB of RAM available in my virtual machine. Let's try this:
-> make -j4
The build was successful and took around 5 hours on my MacBookAir with an Intel i7 dual core processor running at 1.7 GHz (turbo boost 3.3 GHz). Here are some examples of memory and CPU utilization during the build phase.
The build produced the following output stored in the directory out:
The total size
The Android installation + build takes up almost 40GB of disk space.
Running the emulator
The emulator is added to our path automatically by the build process. To run the emulator, type:
Now we are only missing a touchscreen display.
Build the Linux kernel
With the ARM toolchain installed and the Android build completed we are ready to build the Linux kernel. Here is the command we use:
-> make -j4 out/target/product/zedboard/zImage
The build takes about 15 minutes and the following files have been generated and added to the zedboard directory:
Preparing the SD card
We will boot Android from a SD card inserted in to the ZedBoard. The next step to figure out, is how to format the SD card and which files to add to the card. We will use a 16GB SanDisk SDHC card.
Format the SD card
We make one partition formatted in FAT32. See part 38 for more information on how to format an SD card. We can also use the command fdisk and follow this description. Don't forget to unmount the card before you start.
Copy the following files to the SD card. The BOOT.BIN file is taken from the original SD card.
The whole system size is approximately 1.5GB.
Boot the Android system
Time to boot our system. Follow the instruction in part 38 to setup the ZedBoard and the peripherals. Switch on the power and wait for the blue LED to light up. Don't stop the booting and wait for the Android logo to be displayed on the display connected to the HDMI port.
This is how far I came
It just hangs there. Nothing more is displayed and on the terminal the following text is passing by.
I am not the only one having this problem. Here is an explanation but where is the solution. Help needed.
Top Previous Next