Freescale i.MX51 Android Build

Due to an upcoming project I'm starting off with building a headless android system for a Freescale i.MX51 processor. This page reflects my findings in building for that system.

The documentation for the Freescale Android builds is not as clear as it could be, and (at the time of this post) is horribly out of date with the recent changes in Android build instructions. I'll attempt to clear up those as run across them.

My build machine is an Ubuntu 11.10 box that I keep pretty up to date. These build instructions will be focused primarily on that environment. YMMV.


Initialize Build Environment
Make sure you use the right Java implementation. On Ubuntu after installing the sun-java-jdk I had to do:
sudo update-alternatives --config jar
sudo update-alternatives --config java 
Select the sun Java instead of the default one for both options.

Download Freescale Patches

Download the Freescale Android sources. I used the r10.3.1 (imx-android-r10.3.1) which requires you to download r10.3 and build it first. So, get imx-android-r10.3, and follow the instructions from the documentation bundle.

Freescale Android can be found here:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=IMX51ANDROID&fsrch=1&sr=6

You need to register with Freescale to download their software bundles. You will need the documentation bundle as well as the source code bundle. The source code bundle I used is imx-android-r10.tar.gz. The documentation bundle that describes building it is Android IMX5X_R10_3_ANDROID_DOCS_BUNDLE.zip.

In order to get things to work I had to merge their instructions from the docs bundle and the instructions from android. Note, the Freescale patches in the r10.3 bundle are all based on Gingerbread.

Setup and Download Android

Follow:
http://source.android.com/source/initializing.html
Note, if you have an older repo (anything more than a few weeks) you may need to delete your .repo directory and get the new repo (see above URL).

Then follow:
http://source.android.com/source/downloading.html
I used this repo:
repo init -u https://android.googlesource.com/platform/manifest -b gingerbread
repo sync
Get Linux Kernel

You have to use git to download the kernel. You can not just copy it in. Unfortunately, the git command in the documentation no longer works. You have to use this one instead:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
Then the following will work:
git checkout v2.6.35.3
Get uBoot

Since the development board I'm using uses uBoot to boot Linux, I also got the uBoot code. Nothing special here, I just followed the instructions in section 2.1 of the r10.3 Users Guide from Freescale.

Patch Android for Freescale

Follow the Freescale instructions to patch for i.MX (section 2.2 of the r10.3 Users Guide).

Missing Package

The mtd-utils package was missing. This turned out to be a real pain. The sources you get from googlesource.com do not contain the mtd-utils package any more. After a lot of unsuccessful digging on the Internet, I finally just removed the packages from the patch system.

Remove the line from /opt/imx-android-r10.3/code/r10.3/baseversions that references mtd-utils.

Build uBoot and Kernel

Follow the Freescale instructions to build uBoot and the Linux kernel for i.MX (sections 2.3 and 2.4 of the r10.3 Users Guide).

Building Android (Gingerbread)

Follow the Freescale instructions to build Android after the Kernel and uBoot were built (section 2.5 of the r10.3 Users Guide).

For reference, the Android build instructions can be found here:
http://source.android.com/source/building.html


Error 1
I am building on Ubuntu 11.10, and the C++ compiler doesn't like something in the base framework. I got the following error:
frameworks/base/libs/utils/RefBase.cpp: In member function ‘void android::RefBase::weakref_type::trackMe(bool, bool)’:
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing ‘const android::RefBase::weakref_impl’ as ‘this’ argument of ‘void android::RefBase::weakref_impl::trackMe(bool, bool)’ discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1
And found a resolution here:
http://forum.oxygen.im/viewtopic.php?pid=9966
Which was to do this:
cd frameworks/base/ git cherry-pick c4fbbe06

Error 2
The next problem I encountered was this error:
error: "_FORTIFY_SOURCE" redefined [-Werror]
I found the resolution here:
http://code.google.com/p/android/issues/detail?id=20795
So by following his suggestion and editing the build/core/combo/HOST_linux-x86.mk file to do this:
-HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
+HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 
The build continued nicely.


Error 3
The final error I ran into was with the CellBroadcastReceiver. It was missing symbols. Since I don't need it for my headless android project, I just deleted the source directory packages/apps/CellBroadcastReceiver.



Tip To Remember
If, after you build the code, you notice in the process list that the boot logo keeps showing up, and that things are restarting over and over, connect up adb and look at the logcat. Usually you will see some Null Pointer exception. What I've found is that, with a proper build, sometimes things will crash with old data in the DATA partition. That partition needs to be wiped clean to get rid of the old data.



1 comment: