Building Android on ARM Platforms
Commands and tools on Linux based host
(instructions are for Ubuntu/Debian)The information here is according to
http://source.android.com/source/download.html instuctions.
Please always check the above page.
Notes
There are some more things to bare in mind:
- You will need a 64-bit Linux box to built Android now
- The Sun JDK is no longer in Ubuntu's main package repository.
In order to download it, you need to add the appropriate repository and indicate to the system which JDK should be used.
Java 6: for Gingerbread and newer
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo add-apt-repository "deb-src http://archive.canonical.com/ubuntu lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jdk
sudo update-java-alternatives -s java-6-sun
Java 5: for Froyo and older
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper main multiverse"
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu dapper-updates main multiverse"
sudo apt-get update
sudo apt-get install sun-java5-jdk
sudo update-java-alternatives -s java-1.5.0-sun
Preparation
To set up your development environment, install the following required packages:
$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib
g++-multilib libc6-dev-i386 lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev
lib32readline5-dev lib32z-dev
You might also want Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc.
To set up your Linux development environment, make sure you have the following:Required Packages:You might also want Valgrind, a tool that will help you find memory leaks, stack corruption, array bounds overflows, etc.Intrepid (8.10) users may need a newer version of libreadline:
Install, initialize, and configure Repo
To install, initialize, and configure Repo, follow these steps:
- Make sure you have a
~/bin
directory in your home directory, and check to be sure that this bin directory is in your path:
$ cd ~
$ mkdir bin
$ echo $PATH
- Download the repo script and make sure it is executable:
$ curl http://android.git.kernel.org/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
Initializing a Repo client
1. Create an empty directory to hold your working files:
$ mkdir mydroid
$ cd mydroid
2. Run "repo init" to bring down the latest version of Repo with all its most recent bug fixes. You must specify a URL for the manifest:
$ repo init -u git://android.git.kernel.org/platform/manifest.git
- If you would like to check out a branch other than "master", specify it with -b, like:
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b froyo
3. When prompted, configure Repo with your real name and email address. If you plan to submit code, use an email address that is associated with a
Google account . A successful initialization will end with a message such as
repo initialized in /mydroidYour client directory should now contain a
.repo
directory where files such as the manifest will be kept.
To pull down files to your working directory from the repositories as specified in the default manifest, run :
$ repo sync
The Android source files will be located in your working directory under their project names.
Patching and building the kernel
Please jump to the section that contains the info for the kernel version you wish to use.
Kernel version 2.6.33
There are various routes to getting the kernel. You could clone the
http://linux-arm.org/git?p=linux-2.6-stable.git;a=summary repo and checkout the
2.6.33-armdroid branch, which will also give you access to the latest patchset to support Android. In this case, you just need to use the respective .config files for the ARM board you want to use it on.
If you have a copy of the upstream vanilla 2.6.33 Linux kernel ( ), you need to get the
2.6.33-arm1.gz and the
2.6.33-arm1-droid1.gz patches and apply them for the top of your git tree in the following order:
$ git apply <PATH-TO-patch-2.6.33-arm1>
$ git apply <PATH-TO-patch-2.6.33-arm1-droid1>
Once you have reached this point, form either routes, use the appropriate Linux kernel
.config
files, that you can get from
hereTo use them, just copy the over in the top level of the kernel tree:
$ cp 2.6.33-pba8-armdroid1.config /.config
and then build the kernel with:
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage
which will give you a
uImage in
arch/arm/boot/
.
Kernel version 2.6.35
For the 2.6.35 kernel, use
http://linux-arm.org/git?p=linux-2.6-armdroid.git;a=heads repo and checkout the
2.6.35-armdroid branch. As for the 2.6.33 kernel above, this approach will give you access to the latest patchset to support Android.
If you have a copy of the upstream vanilla 2.6.35 Linux kernel (see here), you need to get the
patch-2.6.35-arm1-droid1.gz patches and apply them for the top of your git tree:
$ git apply <PATH-TO-patch-2.6.35-arm1-droid1>
This patchset contains the 2.6.35-arm1 patches.
Now get the appropriate Linux kernel
.config
file for the board you are using, from
http://linux-arm.org/git?p=armdroid.git;a=tree;f=kernel/config, and copy it to the top of the kernel tree as
.config
file:
$ cp 2.6.35-pba8-armdroid1.config /.config
The get the kernel to build with:
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage
This will give you a
uImage in
arch/arm/boot/
in this example for the PB-A8.
Kernel version 2.6.38
For the 2.6.38 kernel, use
http://linux-arm.org/git?p=linux-2.6-armdroid.git;a=heads repo and checkout the
2.6.38-armdroid branch. As for the 2.6.33 kernel above, this approach will give you access to the latest patchset to support Android.
If you have a copy of the upstream vanilla 2.6.38.7 Linux kernel (see here), you need to get the
patch-2.6.38-arm1-droid1.gz patches and apply them for the top of your git tree. Then use the appropriate
.config
for your board from
http://linux-arm.org/git?p=armdroid.git;a=tree;f=kernel/config and build the kernel as outlined above.
Kernel version 3.3
For the 3.3 kernel, use
http://linux-arm.org/git?p=linux-2.6-armdroid.git;a=summary and checkout
linux-3.3-armdroid branch. As for the kernel above, this will give you access to the latest patchset to support Android. If you have a copy of the upstream vanilla 3.3 rc7 (see
here), you need to get the
kernel_src_patch-3.3rc7-arm1-droid1.gz patch and apply to the top of your GIT tree. Then use the appropriate ARM dts (device tree structure – see
here) and follow the booting instructions outlined
here .
Patching the Android Source
Eclair
You will need to apply the following patches from the respective paths (indicated in the patches names) in the source tree of Android.
These patches are amending the TLS so that is uses the kernel helper functions, in bionic C library and in GLES v1.1 , v2. They also add support for the armv6k architecture as well as enabling the use of TLS in the armv7 architectures.
To apply then, navigate to the indicated directory, and apply each patch. E.g:
$ cd bionic
$ git apply
Please note that the
Eclair-vendor-arm.tar.bz2
is a tarball that should be decompressed in the
vendors
directory.
This will add the ARM board targets for the Android build system.
Froyo
Same approach for Froyo but we have a set of slightly different patches, as well as an additional patch to support the ARMv6k architecture:
Please note that the
Froyo-device-arm.tar.bz2
is a tarball that should be decompressed in the
device
directory.
This will add the ARM board targets for the Android build system.
Gingerbread
For Gingerbread we have fewer patches and a couple of changes in the device folder. You would just need:
Please note that the
Gingerbread-device-arm.tar.bz2
is a tarball that should be decompressed in the
device
directory.
This will add the
armboard_v7a
and
armboard_v7a_noneon
targets for the android build system.
Please also note that these patches are for ARMv7a, and they don't support ARMv6k architecture version yet.
Note: If you are using kernel version 2.6.38 (
git repository, then you would need to apply the patches that amend the deprecation of
oom_adj
, to replace it with the newer
oom_score_adj
. This patch is
here.
Ice Cream Sandwich
For Ice Cream Sandwich you will need to apply the following patches from the respective paths (indicated in the patch names) in the source tree of Android.
Please note that
ICS-device-arm.tar.bz2 is a tarball that should be decompressed in the device directory. This will add the
armboard_v7a and
armboard_v7a_neon targets to the android build system. Please also note that these patches are for ARMv7a.
Note: If you are using a kernel versions newer than 3.3, you need to apply the patch that amends the deprecation of FB_EARLYSUSPEND. This patch can be found
here.
Building Android - Eclair and Froyo
To build Android, e.g. for an ARMv7 board, you now need to issue the following command:
$ make PRODUCT-ARMv7-eng
Specifically for Froyo you need to enter:
$ make PRODUCT-ARMv7a-eng
that will build Android with optimisations for boards using ARMv7 architectures - boards include Versatile Express V2,
RealView PB-A8 and PBX.
For
RealView PB11MPCore? that uses ARMv6k core, you should use:
$ make PRODUCT-ARMv6k-eng
Building Android - GIngerbread and Ice Cream Sandwich
To build Android Gingerbread for armboard_v7a, you now need to issue the following command:
$ make PRODUCT-armboard_v7a-eng
That will build Android with optimisations for boards using ARMv7a architectures taking also advantage of NEON. The tested boards include Versatile Express V2,
RealView PB-A8 and PBX.
Filesystem and Images
The android system is designed to boot from flash using YAFFS2 filesystems. After you have build Android, you can either dump the filesystem image to an SD Card or USB key, without having to change anything. Or you can use the Android filesystem over the network, using NFS.
NFS
If you want to work over NFS, you need to copy the built sources to specific places:
$ cp /out/target/product//root/* /var/nfs4/armv7-board-fs
$ cp /out/target/product//system/* /var/nfs4/armv7-board-fs/system
Also, make sure you make the following changes in
init.rc.
Comment out the following lines:
mount rootfs rootfs /ro remount
mount yaffs mtd@system /system
mount yaffs2 mtd@system /system ro remout
mount yaffs2 mtd@userdata /data nosuid nodev
mount yaffs2 mtd@cache /cache nosuid nodev
The
/etc/exports
file should have the settings for the shared folder set :
/srv/nfs4/android-fs *(rw,sync,no_root_squash,no_subtree_check)
In addition to that, please make sure that the permissions and the ownership of the files in the fs are retained as they come out of the build directory. Your local user in your Linux box
should not own anything in there!
Filesystem Changes
Keyboard navigation
By default the keyboard mapping for Android doesn't have the Esc key mapped for navigating "back".
To enable that you should edit the
system/usr/keylayout/qwerty.kl
file in your filesystem, and add the following line:
DNS server
We need to set the DNS server to enable web browsing in Android. This can be done by adding the
indicated line bellow, in init.rc.
# basic network init
ifup lo
hostname localhost
domainname localdomain
---> setprop net.dns1
Gingerbread
In addition to the above changes in init.rc, you also need to comment out line 92 that reads:
on fs
Running Android
You need to have U-boot running on your board, and to set the correct bootargs.
Example of setting the boot arguments in U-boot for Android running over NFS with ARM
RealView platforms:
- PB11-MPCore:
setenv bootargs root=/dev/nfs rw nfsroot=:/srv/nfs4/android-v6k,nolock,wsize=1024,rsize=1024 ip=dhcp console=ttyAMA init=/init noinitrd user_debug=31
- PB-A8:
setenv bootargs root=/dev/nfs rw nfsroot=:/srv/nfs4/android-v7,nolock,wsize=1024,rsize=1024 ip=dhcp console=ttyAMA init=init noinitrd user_debug=31
- PB-X single-core, NEON:
setenv bootargs root=/dev/nfs rw nfsroot=:/srv/nfs4/android-v7,nolock,wsize=1024,rsize=1024 ip=dhcp console=ttyAMA init=init noinitrd user_debug=31 nosmp
- PB-X dual-core, no-NEON:
setenv bootargs root=/dev/nfs rw nfsroot=:/srv/nfs4/android-v7-noneon,nolock,wsize=1024,rsize=1024 ip=dhcp console=ttyAMA init=init noinitrd user_debug=31
- Versatile Express:
setenv bootargs root=/dev/nfs rw nfsroot=:/srv/nfs4/android-v7,nolock,wsize=1024,rsize=1024 ip=dhcp console=ttyAMA init=init noinitrd mem=1024M user_debug=31
Once this is set up, you can bootm your board.
bootm
Using ADB
Once you have Android source built, you will have
adb (Android Debug Bridge) that functions as a probing/investigating mechanism.
Add the path to adb binary to your PATH environment variable, to be able to execute it from everywhere:
$ export PATH=/out/host/linux-x86/bin:$PATH
If you know the IP of your target device, set it in the ADBHOST environment variable. E.g:
$ export ADBHOST=10.0.0.50
You can now get information about booting/starting Android with:
$ adb logcat
Or get a shell to the target:
$ adb shell
ADB supports connection to the target that is running Android, over Ethernet or USB. ~