Building Android (AOSP)

The below page is a brief instruction for people willing to build their own Android filesystems to be used for Codezero’s Android guest. Thanks to Android Open Source Project it’s not difficult to build and alter Android images according to the particular needs of paravirtualized container.

Preparing environment

Use AOSP: Initializing a Build Environment to find out what software packages you need install on your development machine to be able to compile Android. Not following this step carefully often results in compilation problems, especially related to Java tools.

Downloading the AOSP source code

AOSP uses a repo tool for handling the Android source tree. To be able to compile the Android FS, you must first download the whole source tree locally.

Follow the AOSP: Downloading the Source Tree page. In short:

$ mkdir ~/bin
$ PATH=~/bin:$PATH
$ curl > ~/bin/repo
$ chmod a+x ~/bin/repo
$ repo init -u -b android-4.0.3_r1
$ repo sync

Note: android-4.0.3_r1 is the only branch that is currently supported with Codezero.

Installing propriety binary drivers

Some platforms require binary drivers to be installed in the source tree for the resulting build to work correctly. For Galaxy Nexus see Galaxy Nexus AOSP binary drivers page.

Patching the source code

This step is only required if you’re building filesystem for the second guest in dual-android configuration. Due to having no access some of the hardware that is assigned to a first guest, the Android filesystem must be stripped of some parts.

See the maguro android cont1 fs patches for a list of patches that should be applied in AOSP repository. The *.path files contain the path of directory where the corresponding patch should get applied.

Building the filesystem and ramdisk

Check the AOSP: Building the System for full information.

$ source build/
$ lunch full_maguro-userdebug

The full_maguro-userdebug mean full build for maguro (codename for Galaxy Nexus GSM version) with userdebug build options (debug and such). You should use different lunch argument for different devices and filesystem debug level options.

To start building you can use the following commands:

$ export USE_CCACHE=1
$ export CCACHE_DIR="`pwd`/../android-ccache"
$ ccache -M 40G
$ nice -n 20 make -j 8

Make sure to look at Known Issues in case of any problems.

After successful build which can take even few hours, you can find resulting *.img files in out/target/product/maguro/ directory:

  • boot.img – Native system boot image.
  • ramdisk.img – Ramdisk rootfs. Will be required for combining with Codezero Image file (see Building paravirt-boot.img using mkbootimg.
  • recovery.img – Recovery image.
  • ramdisk-recovery.img – Ramdisk rootfs for Recovery.
  • system.img – System data (/system directory)
  • userdata.img – User data (/data directory)

Building paravirt-boot.img

AOSP uses prebuilt kernel images, so the boot.img file is of no use for virtualized Android guest. However, you can flash it as boot partition in case you want to switch to native Android system.

To boot virtualized Android binaries, we need to produce the boot image containing Codezero kernel. It’s usually named paravirt-boot.img to distinct it from native boot.img.

The Android kernel handling is done via Codezero build system so it’s necessary to follow the Configuring and Building instruction first. After executing make command in the codezero-meta directory the current/codezero/Image file will be produced. This is the raw binary executable, which is similar to what zImage is for Linux system, but containing Codezero kernel and guests binaries.

Android bootloaders expect boot partition to be flashed with boot.img file, which combines meta information about load address, entry poing and Linux Image binary along with ramdisk.img. The boot.img is created automatically by AOSP building system. To produce corresponding file from Codezero Image, execute the following command:

$ mkbootimg \
        -o "paravirt-boot.img" \
        --kernel "current/codezero/Image" \
        --ramdisk "path/to/ramdisk.img" \

The mkbootimg is created in AOSP tree under out/host/linux-x86/bin/mkbootimg path.

The $CONFIG_PARAVIRT_CONT_PHYS_START is a base loading address and can be found using:

$ grep CONT_PHYS_START current/cont0/.config

exected in codezero-meta dir.

The paravirt-boot.img is ment to be flashed using fastboot just like the boot.img:

$ fastboot flash boot paravirt-boot.img

All this commands are combined for convenience in tools/ script which requires the following configuration entires in codezero-meta/ file:


Known issues

On Ubuntu version 11.10 and newer you will get compilation errors. This problem is mentioned in AOSP original Known Issues section but the fix (switching branch to master) is not applicable in our case. You must manually fix the compilation problems. Use android-4.0.1_r1 reference fix output generated with repo forall -c "pwd; git diff" command as a guide.

Comments are closed.