Tuesday, August 2, 2011

Android From Scratch I

    Android is a software stack for mobile devices that includes an operating system, middleware and key applications. Android has a large community of developers writing applications ("apps") that extend the functionality of the devices. There are currently more than 250,000 apps available for Android. Developers write primarily in the Java language, controlling the device via Google-developed Java libraries.

    Android is linux based and open source. We can download sources and build images for supported boards. In this document, we will try to build kernel and rootfs for beagleboard. Beagleboard is manufactured by Texas Instruments and it is good for doing development. You can check beagleboard from here[1]. I have beagleboard C4 revision and all works below is done on it.

    There are many projects use beagleboard[2]. Some of them are aimed to run android on beagleboard such as 0xdroid, Beagledroid, Android on Beagle and Rowboat. The most popular projects which use android is Angstrom and Rowboat. Angstrom is an embedded linux distrubition for variety of embedded devices and off course it is ported for beagleboard too. Angstrom is built from Openembedded, you can check manual how to configure and build it from here[3]. Another project ,Rowboat, provides a stable Google Android base port for AM1808, OMAP35x, AM35x, AM37x, AM389x and DM37x platforms. Our board platfor is OMAP35x and we will use Rowboat to build images for beagleboard.

    There are a lot of documentation about compiling android sources for beagleboard however reading all of them takes too time and we tried to create a document to tell just necessary instructions. In document you will see links as references and if you want to go further, sure you can.

    We will use Gingerbread-2.3 version but you can see other version build instructions on reference links. Lets start!

    Android use git repository with repo tool. Then if you already do not have, you should install git and get repo tool at first as below:

        sudo apt-get install git-core
        wget http://android.git.kernel.org/repo
        chmod +x repo
        sudo mv repo /bin/

    We will use just "init" and "sync" commands of repo tool, you can see other commands and options from here[4].

    Now we need sources. You can download from repository over internet or you may download all needed repository as tar package. We will show both. 

    If you want to download tarball package just use these commands and your build environment gets ready:

        mkdir ti-android-rowboat
        cd ti-android-rowboat
        wget http://software-dl.ti.com/dsps/dsps_public_sw/sdo_tii/TI_Android_DevKit/TI_Android_GingerBread_2_3_DevKit_1_0/ exports/TI_Android_GingerBread_2_3_Sources.tar.gz
        tar xzvf TI_Android_GingerBread_2_3_Sources.tar.gz
        repo sync --local-only

    Secondly, if you want to download from repository, follow these steps:
    Create a new directory and init repository as below. Your name and mail address will be asked while initing repository, you can enter anyting.

        mkdir ti-android-rowboat
        cd ti-android-rowboat
        repo init -u git://gitorious.org/rowboat/manifest.git -m TI-Android-GingerBread-2.3-DevKit-1.0.xml
        repo sync

    By commands above, we configured our manifest file as TI-Android-GingerBread-2.3-DevKit-1.0.xml. Our build operations will be up to this file. You can think it as configuration and selected application file. By sync operation, it gets sources. It may take hours depend on your bandwith.

    At this point, we have sources, toolchain and ready to build but we should add toolchain binary path to our PATH environment to be reachable when needed. In my system I add as below, you should enter your local path where it is.

        export PATH=/store/android/ti/gingerbread/TI_Android_GingerBread_2_3_Sources/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH

    if you want to make it permanently you can add command into ~/.bashrc or ~/.profile scripts which run every shell login.

    Now time to build. Enter top directory and run commands to get kernel image and rootfs:

        cd ti-android-rowboat/TI_Android_GingerBread_2_3_Sources
        make TARGET_PRODUCT=beagleboard -j4 OMAPES=3.x

    Our target product is beagleboard. It is recommended to use more than one thread on multi core systems, specify -j number_of_threads for this. Set OMAPES variable to install proper version of SGX driver, our board is use version 3.x.

    After successful compilation, we should have kernel image in "kernel/arch/arm/boot/" directory. uImage will be used as kernel. In addition, we should have "out/target/product/beagleboard/root" and "out/target/product/beagleboard/system" directories which are our rootfs images sources. We should create a rootfs directory and copy root and system contents to this directory. Then we will create a tarball.

        cd out/target/product/beagleboard
        mkdir android_rootfs
        cp -r root/* android_rootfs
        cp -r system android_rootfs
        sudo ../../../../build/tools/mktarball.sh ../../../host/linux-x86/bin/fs_get_stats android_rootfs . rootfs rootfs.tar.bz2

    Now we should have kernel image and rootfs tarball. Next time we will explain how to write kernel and untar rootfs to mmc card partitions. Then we will use mmc card for running android on beagle board. Have a nice coding!


1. http://beagleboard.org/hardware
2. http://beagleboard.org/project
3. http://www.angstrom-distribution.org/building-angstrom
4. http://source.android.com/source/using-repo.html

No comments:

Post a Comment