Building and Deploying Android AOSP 6.01 for the Wandboard

While our guide of how to build deploy vanilla AOSP on the Wandboard has helped many to understand more about the Android and Linux build tools, it is often required for applications to have hardware graphics acceleration.

The following guide shows how to download the Wandboard AOSP source, how to compile and deploy it and how to reconfigure Android for custom purpose.

The source code for all kernel / u-boot and AOSP can be found on wandboard.org as tarball here, direct link to the tarball here.

Before starting, a couple of dependencies need to be installed in order to compile the source.

First off install the required java version, which is openjdk-7-jdk. However the package is not available in the default 16.04 Ubuntu repos, the easiest way to install the sources is from the ppa (thread on askubuntu here).

Please note that while the official AOSP documentation suggest installing openjdk-8-jdk, we have been more successful with openjdk-7-jdk on this particular build.

If you have previously installed one or more versions of java it is necessary to change at least the java and javac executable to the appropriate version. On Ubuntu, “update-alternatives” is used for this purpose.

Note that the Android build system will look for an environment variable “$JAVA_HOME” and – if it is defined – use this particular java installation (disregarding any possible changes made with update-alternatives). If you have installed other java versions, it is possible that this variable is set somewhere inside /etc/profile.d/ or similar.

# check if JAVA_HOME variable is set
echo $JAVA_HOME
/usr/lib/jvm/java-6-oracle
# In our case, JAVA_HOME is already defined
# We can either unset it temporarily in our current shell before building Android
unset JAVA_HOME
# Or add our own JAVA_HOME export to .bashrc or .profile
# Or search and remove the definitions inside /etc folders
# (in that case you need to logout and login again)
cd /etc
grep -sr "JAVA_HOME" .
profile.d/jdk.sh:export JAVA_HOME=/usr/lib/jvm/java-6-oracle
profile.d/jdk.csh:setenv JAVA_HOME /usr/lib/jvm/java-6-oracle
ca-certificates/update.d/jks-keystore:export JAVA_HOME=/usr/lib/jvm/$jvm
ca-certificates/update.d/jks-keystore:PATH=$JAVA_HOME/bin:$PATH

Besides fixing the above issue, it is necessary to apply a few modifications to the default configuration of the android framework as well as the mounting table found in fstab.freescale.

First let’s have a look at the framework config

# change into the device folder from the top directory
cd device/fsl/wandboard
# edit defaults.xml of the SettingsProvider
gedit overlay/frameworks/base/packages/SettingsProvider/res/values/defaults.xml

After these changes, you are now ready to compile the Kernel, the Uboot bootloader as well as the Android OS (consisting mainly of system image and ramdisk).

There are actually two ways of how to compile Android at this stage. Under the folder /cookers you will find an environment setup that will allow you to just use the “cook” command which in turn calls make in all kernel, uboot and AOSP. While this might be a good idea for a quick build, there is added value in compiling each of the parts separately in order to gain a deeper understanding of configuring building and deploying the various parts involved.

Building with the “cook” script

These commands allow the build to be kicked off without any further understanding of the source:

In order to start the AOSP build, the u-boot bootloader and Linux kernel need to be compiled first, because the wandboard target recipe has dependencies on both u-boot and kernel binaries.

Building the Linux kernel

# change into the Android top directory (/opt/android/wand in our case)
# ... and set up CROSS_COMPILE and ARCH
export ARCH=arm
export CROSS_COMPILE="/opt/android/wand/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-"
# change into kernel directory
cd kernel_imx
# if you would like to clean a prior build
make distclean
# if you want to clean the current configuration (.config) as well
make mrproper
# prepare the kernel configuration
make wandboard_android_defconfig
# edit the config to your liking to add or remove device drivers
make menuconfig
# build the kernel, -j tells the make file system how many jobs to launch in parallel
make -j4 zImage
# the output after building the kernel successfully will look something like this
...
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
#### make completed successfully (02:43 (mm:ss)) ####
# also build modules and dtbs
make -j4 modules
make dtbs

partitions on the sd card for deploying Android 6.0.1 on the Wandboard Quad

Once the SD-Card is formatted, it is time to mount the BOOT and SYSTEM partition and deploy the files. The data and cache partition remain empty for deployment, on first boot the data partition will be populated by Android.

Deploying Android onto an SD-Card

It is essential to understand that deployment of Android on any media is highly customisable. While most Android images found on embedded platforms follow the pattern to deploy partitions such as modem, recovery or external sdcard, none of these are mandatory.

The Android OS expects though to have a /cache and /data partition as well as a mount point for /system.

While by default a ramdisk is extracted into memory and mounted as root partition, even that behavior may be changed in favor of one root partition containing both ramdisk content as well as /system directory.

In our case we will favor to use a ramdisk and a separate /system partition.

Furthermore it is necessary to understand that while the /system partition contents have been compiled into the out/target/product/wandboard/system directory, the permissions and mods of the contents are not set appropriate for deployment. However these files are also written into the disk images out/target/product/wandboard/system.img and the raw image out/target/product/wandboard/system_raw.img. While system.img cannot be easily mounted on an Ubuntu host, system_raw.img is a plain ext4 partition image of the Android /system directory containing all the right file mods and permissions.

The system_raw.img can be recompiled using the simg2img utility which is also helpful when restoring system partitions directly from a device or rom.

After this procedure the SD-Card is ready to boot and will start Android. Using an USB-to-serial adapter, it is now possible to observe the system booting using your preferred serial terminal program (minicom, screen, putty, etc.).