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.
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 https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo $ chmod a+x ~/bin/repo $ mkdir WORKING_DIRECTORY $ cd WORKING_DIRECTORY $ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.3_r1 $ repo sync
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/envsetup.sh $ lunch full_maguro-userdebug
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
boot.img– Native system boot image.
rootfs. Will be required for combining with Codezero
Imagefile (see Building
recovery.img– Recovery image.
system.img– System data (
userdata.img– User data (
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
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
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" \ --base "$CONFIG_PARAVIRT_CONT_PHYS_START"
mkbootimg is created in AOSP tree under
$CONFIG_PARAVIRT_CONT_PHYS_START is a base loading address and can be found using:
$ grep CONT_PHYS_START current/cont0/.config
paravirt-boot.img is ment to be flashed using
fastboot just like the
$ fastboot flash boot paravirt-boot.img
All this commands are combined for convenience in
tools/aosp-install.sh script which requires the following configuration entires in
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.