Embedded Android Tutorial: Part I, Setting up the Pandaboard with the Linaro Android Build

Recently we have been setting up the Pandaboard with Android to get started with Embedded System Development.

In this first post we would like to share of what steps were necessary to set up the build environment, Android source from Linaro and toolchain to get started on an Ubuntu 12.04 64 Bit machine.

Android Build and Version: Linaro Android Build, 4.1.1 Jellybean
Host Machine: Lenovo T420, Ubuntu 12.04 64 Bit
Hardware Target: Pandaboard
Deployment Target: SD-Card

Please note that since the Android ICS release, the Android Source can (sadly) only be built on a 64 bit OS, without the need to do workarounds.

Important Links for further reading:

Linaro Android Project
Build Environment Initializing
Current Linaro Build version information

Setting up the build environment

Before you can get started to build the Android Source code and Kernel, you need to set up the build environment properly. Part of this is installing packages from the Ubuntu repositories (for instance build tools like make and host side gcc etc.) and also the java version (from sun/oracle) which cannot be found in the current Ubuntu repositories.

Also we recommend you set up some primary build workspace for instance in “/opt/android/”. If you are new to Ubuntu and the Bash you will find countless excellent tutorials in the net. For this guide you should already be familiar with the command line and some of Linux most prominent tools.

Let’s get started

We assume you are user user on a machine host.

First of all grab a terminal on you Host machine either by finding it in the start menu or by hitting ctrl+alt+t.

Now let’s set up some workspace for our source in the /opt directory.

user@host:~$ sudo mkdir /opt/android
user@host:~$ sudo chown -R user.user /opt/android
user@host:~$ cd /opt/android

Following the guide on the source.android.com site we set up the packages required for building android.

user@host:/opt/android$ sudo apt-get install -f git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
user@host:/opt/android$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
user@host:/opt/android$ sudo apt-get install lib32ncurses5-dev

Also we need some additional packages for debugging over the serial console and to set up the bootloader for android.

user@host:/opt/android$ sudo apt-get install minicom
user@host:/opt/android$ sudo apt-get install ia32-libs
user@host:/opt/android$ sudo apt-get install u-boot-tools

At some point we noticed some libraries had problems installing. Be sure to do this command after installing all the packages…

user@host:/opt/android$ sudo apt-get install -f

That should do it.

For the next part: It turns out the Linaro Build compiles fine with just OpenJDK. If you do have the OpenJDK already installed you can skip this part and go to Fetching the Android Source Code.
user@host:/opt/android$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.10.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

Now we need to install java. This is a tricky part, since it used to be much easier to do this in Ubuntu a while back. As far as we know Oracle forced Canonical to take down the binaries of java from their repositories. What a shame …
For the setup we configured the java installation by hand.

Navigate here and select the .bin of the 64 bit download (jre-6u34-linux-x64.bin). Because they seem very interested of who downloads their java they want you to register on their website. We actually did not try to build the source with iced-tea java, so we do not know if that works as well. However we cannot wait to be able to skip oracle’s java for building android.

As soon as you grabbed the binary you can do the following to install it and let Ubuntu know where to find all the commands.

user@host:~/Downloads$ chmod a+x jre-6u34-linux-x64.bin
user@host:~/Downloads$ mv jre-6u34-linux-x64.bin /opt/android && cd /opt/android
user@host:/opt/android$ ./jre-6u34-linux-x64.bin
user@host:/opt/android$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/android/jdk1.6.0_34/bin/java" 1
user@host:/opt/android$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/android/jdk1.6.0_34/bin/javac" 1
user@host:/opt/android$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" user@host:/opt/android$ "/opt/android/jdk1.6.0_34/bin/javaws" 1
user@host:/opt/android$ sudo update-alternatives --config java
user@host:/opt/android$ sudo update-alternatives --config javac
user@host:/opt/android$ sudo update-alternatives --config javaws

To be sure check what happens if you execute the “java” command and check the version with “java -version”. The output should look something like this:

user@host:/opt/android$ java -version
java version "1.6.0_34"
Java(TM) SE Runtime Environment (build 1.6.0_34-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.9-b04, mixed mode)

Fetching the Android Source Code

For this step you should probably get a few cups of coffee ready since depending on your network connection it might take quite a while.
First you need to fetch “repo” which is a tool that helps you to keep track of all the necessary Android GIT repositories (GIT is by the way awesome, you should look into it if you have not done that already).

user@host:/opt/android$ mkdir ~/bin/
user@host:/opt/android$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
user@host:/opt/android$ chmod a+x ~/bin/repo

Before we fetch the source code we also fetch the Linaro toolchain which is needed to cross compile the Android source code. Also we install the linaro image tools to deploy the Android/Kernel/uBoot images to the SD-Card once built.

Note: Before you do the next two steps, decide which build version you want to use. Have a look at the build version table for the latest releases.

user@host:/opt/android$  wget http://snapshots.linaro.org/android/~linaro-android/toolchain-4.7-2012.10/1/android-toolchain-eabi-linaro-4.7-2012.10-1-2012-10-15_16-19-17-linux-x86.tar.bz2
user@host:/opt/android$ tar -xvf android-toolchain-eabi-linaro-4.7-2012.10-1-2012-10-15_16-19-17-linux-x86.tar.bz2
user@host:/opt/android$ sudo apt-get install linaro-image-tools

At this point we create a “source” subdirectory and start fetching the Android source code from the Linaro repository.

user@host:/opt/android$ mkdir source && cd source
user@host:/opt/android$ repo init -u git://android.git.linaro.org/platform/manifest.git -b linaro-android-12.10-release -m staging-panda.xml
user@host:/opt/android$ repo sync

The upper commands may differ from what version you are using.

Building the Source Code

As soon as the source is downloaded you are ready to give it a first build. In the source directory do the following to start building for the pandaboard:

user@host:/opt/android/source$ . build/envsetup.sh
user@host:/opt/android/source$ choosecombo 1 pandaboard 3
user@host:/opt/android/source$ make -j4 TARGET_TOOLS_PREFIX=../android-toolchain-eabi/bin/arm-linux-androideabi- boottarball systemtarball userdatatarball

Make sure though that the toolchain is actually in the folder “/opt/android/android-toolchain-eabi”.

Now depending on if your package installation process from the beginning was successful or not, the build will complete successfully and output three tarballs (boot.tar.bz2, system.tar.bz2 and userdata.tar.bz2).

If the build is not successful then go back to the start of the guide and make sure ALL your packages install correctly (if apt throws errors just do a “sudo apt-get install -f” with no packages as arguments).

After completion of compiling source code (the kernel was compiled as well with the command before) you should now format an SD card and deploy the images.

If you are using GNOME (if you are not sure that you are then you ARE using GNOME :)), then you also need to do a few tricks so the SD-Partitioning runs without problems. Linaro has just updated their deployment guide recently for this.

user@host:/opt/android/source$ TMP1=$(dconf read /org/gnome/desktop/media-handling/automount)
user@host:/opt/android/source$ TMP2=$(dconf read /org/gnome/desktop/media-handling/automount-open)
user@host:/opt/android/source$ dconf write /org/gnome/desktop/media-handling/automount false
user@host:/opt/android/source$ dconf write /org/gnome/desktop/media-handling/automount-open false

The above steps are currently untested, but we trust that the guys did a good job on this 🙂

Now insert you SD-Card into your card-reader. Check with “sudo fdisk -l” which devices are available for you. Be really careful here to not pick the wrong device, since all contents of the chosen one will be DELETED irrecoverably.

So if your SD-Card is on “/dev/mmcblk0” then you would do the following command. Note that depending on your SD-Card Reader it is possible the device is found under “/dev/sdX”.

user@host:/opt/android/source$ cd out/target/product/pandaboard
user@host:/opt/android/source/out/target/product/pandaboard$ linaro-android-media-create --mmc /dev/mmcblk0 --dev panda --boot boot.tar.bz2 --system system.tar.bz2 --userdata userdata.tar.bz2

During this time the SD-Card is being formated and partitioned properly. We had sometimes difficulties on some hosts with running this script, however, the automount trick should fix the issue.

Now restart the automount feature of gnome

dconf write /org/gnome/desktop/media-handling/automount $TMP1
dconf write /org/gnome/desktop/media-handling/automount-open $TMP2

The last thing we need to do is to install the proprietary drivers of the OEM for the Pandaboard. This is done by grabbing the binaries and pushing them to the system partition of the SD-Card.

For this purpose remove the SD-Card and Plug it back in after re-enabling the automount feature of gnome.

The second partition of your SD-Card holds the contents of the “system” image. In our case this was /dev/mmcblk0p2, it might differ for you depending on your SD-Card reader it could be something like /dev/sdXp2 as well.

user@host:/opt/android/source/out/target/product/pandaboard$ wget http://people.linaro.org/~vishalbhoj/install-binaries-4.0.4.sh
user@host:/opt/android/source/out/target/product/pandaboard$ chmod a+x install-binaries-4.0.4.sh
user@host:/opt/android/source/out/target/product/pandaboard$ ./install-binaries-4.0.4.sh dev/mmcblk0p2

You are almost done. Be sure to ALWAYS do a “sync” and an “umount” BEFORE you remove your SD-Card. Doing otherwise can screw up your files!

user@host:/opt/android/source/out/target/product/pandaboard$ sync
user@host:/opt/android/source/out/target/product/pandaboard$ sudo umount /dev/mmcblk0

Now put your SD-Card into your Pandaboard and see it booting.

Console via USB-Serial Converter

For debugging you can now use minicom. To do so, hook up your USB-Serial converter to your Beagleboard and on the host run minicom.

In the config go to “Serial port setup” then press “a” and change the device according to your serial device node (“/dev/ttyUSB0” or something), then press ENTER to confirm and hit “f” to disable hardware flow control. Now hit ENTER twice and select “save setup as panda”.

user@host:/opt/android/source/out/target/product/pandaboard$ sudo minicom -s panda

Exit the terminal at any time using “ctrl+a, z, q” and reconnect with your new config using

user@host:/opt/android/source/out/target/product/pandaboard$ sudo minicom panda

You should now be able to start with the real fun. You downloaded and compiled the Android source and set up the SD-Card for deployment.

10 Replies to “Embedded Android Tutorial: Part I, Setting up the Pandaboard with the Linaro Android Build”

  1. Dear Manuel,
    Do you know how to display what (an attached camera via usb) sees on the connected android device?
    I have been looking around at scraps of examples and documentation on control and bulk transfer.
    StackOverflow and Reddit don’t seem to have much advice on this specific topic and many responses have led me to this website.

    I am currently able to establish a connection with the external camera and display the endpoints in logcat. I am doing this in the Eclipse IDE on windows.

    Any help is greatly appreciated!


    1. Hello Dave,

      That might be not so trivial. Probably you will need to engineer your own USB driver. You can try to search the linux v4l2 driver to find out how they control USB cameras.

      A good point to start would be for you to find the specific v4l2 module for your camera and see how setup and image transfer is done, or sniff with Wireshark on your USB Hub to see the transfers that are going on (you will still need to decode the image somehow though).

      I know it’s not much but I hope this can get you started a bit.

      All the best

  2. Hi. Great post. Thanks. I’m newbie in android embedded and this post very helpful for me. Can you help me in next question. I was download android source and I want change something in this source(add driver or change something else). Can I use some IDE(like visual studio for WinCe) to look in source and change it? Or I must open downloaded files and edit it in notepad? For example I want run some app when android os is load(for wince I was edit registry and build OS image). How can I do this for android?

    1. Hello Artem!

      Generally you will need to use tools like “gedit” or “nano” in your Linux Environment to modify the source code of Android (as well as to build it). Although, certain parts of the source (such as all the Java Framework Code) can be loaded as projects into Eclipse. However, the native C-code parts are best edited by a text editor.

      If you want to start an Android application when the system booted there are two options:

      – Create an Android Application that registers a BroadcastReceiver and listens for BOOT_COMPLETED.
      – Modify init.rc to run a oneshot command to execute a shell script. (something like service bootup_stuff oneshot and “sh /system/bin/myscript.sh”)

      Hope that clears up some things for you 🙂

      All the best

      1. Thanks for you answer. What book I can read for beginning about embedded android? How can I configure memory size, add device drivers ect.

  3. hi,
    first of all thanx for the post, it helped me a lot to learn

    when i’m using sync after an an hour or more i’m getting error like “fatal: read error: Connection reset by peer” i think the sync is not present so can i use “linaro-android-12.12-release” instaed of 12.10?
    or can you give me any link from where i can download the linaro source code?

    i’m using Pandaboard (REV EA3) (OMAP4430) model board …………….. please guide me in building the Jellybean images from linaro source code for my board

    before this i tried “http://omappedia.org/wiki/4AJ.2.1_OMAP4_Panda_ES” to build jellybean in that i was able to build uboot,kernel images but when i’m builing AFS i’m getting errors. so i want to try with linaro source? or can u use the same source code which i downloaded from above site to build Linaro images for my board?

    Thank you in advance.

    1. Hey Ram,

      Thank you so much.
      I think you can just continue with “repo sync” once more when there was an error with the connection. It should take on where it left of before I think.
      At the moment I am trying 12.12 as well.

      All the best

Leave a Reply

Your email address will not be published. Required fields are marked *