Thursday, August 8, 2013

We have been kept busy with our research work on Android operating system for mobile phones. We thought it would be nice to share a short tutorial to get started on building the Android source from scratch. There were several hurdles to pass before we could really get some thing working. Our target platform was Nexus 7 or what is called as "grouper" in Android terms.

Updated for Nexus 5 Source build on Ubuntu 13.10 >>

Nexus 7 is fairly a cheap device for now, as compared to the other high end phones. For disambiguation we are using a Nexus 7 with 16GB Storage and Only Wi-Fi. Since there are two variants available in the market, this one is called as "grouper".
However off the shelf devices are not the development units so you need to mod it to work as a development device. Here we would like to issue a warning.

DISCLAIMER: If you proceed on the steps provided it will surely cause damage to your Nexus 7 device and the Author of this article will not be held responsible for any losses or damages of any type caused by following the steps below.

[0] PC and Other Requirements:

# PC configuration to have a decent build performance:
  • Processor: Quad Core 2.6GHz Intel Core i5 and above
  • RAM: 4GB DDR3 1066MHz and above
  • HDD Space: 120GB Free (build tools + Android source + build cache)
  • Internet Connection: 2mbps and above
# Nexus 7 with PC Cable
# Lots of patience and 1 day time ;-)

[1] Prepare Ubuntu 13.04 for building Android

In order to prepare the standard Ubuntu operation you can first update the installation to the most recent packages. Next follow the steps to install and configure the build system. Thanks to the Blog: soupdawg.wordpress.com
[1._ ] Most of the commands need to run in a terminal window so we need to open it before starting any of the below steps. The easy way on Ubuntu is to press the keyboard combination Ctrl + Alt + 't' else one can also go to the app launcher icon and type "terminal"

[1.a] Correcting and Installing Java

First thing that we need to perform is removing the Icedtea Java or OpenJDK
sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
Next we need to add the official last JDK from Oracle:
sudo add-apt-repository ppa:webupd8team/java
Next perform an update on Apt Sources:
sudo apt-get update
Finally Install the Java6 version of JDK:
sudo apt-get install oracle-java6-installer
Just to make sure that you have the right stuff you run the following command:
java -version
The output would be something like:
java version “1.6.0_39″
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)
So now we are done with Java which is one of the essential components needed by the Android Dalvik compiler

[1.b] Installing the package dependencies into Ubuntu

This is a long an time taking process, where nearly 900MByte+ data is downloaded. So be careful if you have limited bandwidth connection like ours. This might take up a lot of your Internet connection bandwidth.
sudo apt-get install git-core gnupg flex bison gperf \
build-essential zip curl zlib1g-dev zlib1g-dev:i386 \
libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 lib32z1-dev \
libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib \
mingw32 tofrodos python-markdown libxml2-utils \
xsltproc readline-common libreadline6-dev libreadline6 \
lib32readline-gplv2-dev libncurses5-dev lib32readline5 \
lib32readline6 libreadline-dev libreadline6-dev:i386 \
libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 vim \
libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev \
squashfs-tools pngcrush schedtool libwxgtk2.8-dev python
This would take some time to get the complete download done and then the dependency fixes need to be applied:
sudo apt-get install -f
After this we need to do the following linking:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 \
/usr/lib/i386-linux-gnu/libGL.so
This completes the installation of dependencies and necessary packaes to begin our build

[2] Downloading the Google Repository tool - repo

In order to obtain the Android source code from Google there is a special tool called "repo". This tool enables us to download all the component repositories sources that come together to make Android OS source for a specific version.
First lets create a local directory which would hold our executable code:
mkdir ~/bin
Now let us download the repo tool into this directory and apply the executable permission:
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo >\
~/bin/repo && chmod a+x ~/bin/repo
Finally adding this to the path to help us get the tool working
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc && \
source ~/.bashrc
We are now ready to obtain the source code from Google for Android OS

[3] Understanding and Downloading the Android Sources

There are multiple sources to obtain the Android OS source code. Here are a few of them:
1. Android Open Source Project - AOSP : This is the Google's official development project for android which would be detailed in this tutorial
2. AOKP from Team KANG : Offshoot with all bells-n-whistles loaded plus additional functionality
3. CyanogenMod : This project provides the complete Bootloader customization with specific Recovery and Andorid OS source integration. Slightly old but widely used to replace the official bootloader and recovery tool.

Digging deeper into the AOSP project we now need to know what are the Android OS distributions and what would be most suited towards our "grouper" device.
http://source.android.com/source/build-numbers.html
For now we would choose:
Build: JWR66V  
Repository Tag: android-4.3_r1
This is compatible to the "grouper" device so its a safe bet, there are others but possibly dont have official support for our target device.

UPDATE[4-Oct-2013] Latest version compatible for "grouper" is:
Build: JWR66Y
Repositrory Tag: android-4.3_r1.1
Please update the below commands and branch names accordingly

UPDATE[10-Nov-2013] Latest version compatible for "grouper" is:
Build: KRT16S
Repository Tag: android-4.4_r1.2
Finally we have Kitkat also for "grouper", thank to the signing campaign.
Update procedure for Kitkat have been published in another post

[3.a] Downloading the Source

To start the download we need to first create a folder eg. android-4.3_r1
mkdir android-4.3_r1
cd android-4.3_r1
Now lets Initialize the Repository for GIT configuration
git config --global user.name {Your Name}
git config --global user.email {Your@Email}
This would set up your identity that would be part of this source code checkout

Finally we can Initialize the Repository using the following command:
repo init -u https://android.googlesource.com/platform/manifest -b android-4.3_r1

The anatomy of this command is:
repo = Command
init = For Initialization
-u https://android.googlesource.com/platform/manifest = Location for all the source
-b android-4.3_r1 = Specific branch of source code that needs to be picked

This command will take some time to finish as it creates the basis for the list of location from which the different components are downloaded.

Now we are ready to receive the real code:
repo sync -j4

The anatomy of the command is:
repo = Command
sync = Download the code
-j4 = Use Quad core processing for downloading the source code

Once this command is completed you have the basic android source code available. Just to be sure that you have not missed any files try to run this command again. In case the download fails due to some reason you can ask for another download to fix any issues.
Once suggestion would be back up this basic source to have a copy that you can use to get back the older stage. Use this command to create the backup: (OPTIONAL)
cd .. && tar -jcvf android-4.3_r1_INIT.tar.bz2 --exclude ".git" \
--exclude ".repo" --exclude ".svn" android-4.3_r1/

[3.b] Getting Vendor Specific Binaries

In order to support the various sub-components in the "grouper" we would need to have the vendor binaries. These help to enable functionality + FW needed for the additional processors in the system.
One can find more info on this from the following link:
https://developers.google.com/android/nexus/drivers

For "grouper" and Android JBMR2 release download the binaries from the below location:
https://developers.google.com/android/nexus/drivers#grouperjwr66v

Download all the driver binaries into the android-4.3_r1 directory:
cd android-4.3_r1
wget -c https://dl.google.com/dl/android/aosp/asus-grouper-jwr66v-15547c77.tgz
wget -c https://dl.google.com/dl/android/aosp/broadcom-grouper-jwr66v-fa38dae8.tgz
wget -c https://dl.google.com/dl/android/aosp/elan-grouper-jwr66v-4235892f.tgz
wget -c https://dl.google.com/dl/android/aosp/invensense-grouper-jwr66v-0da5128c.tgz
wget -c https://dl.google.com/dl/android/aosp/nvidia-grouper-jwr66v-2cbbe013.tgz
wget -c https://dl.google.com/dl/android/aosp/nxp-grouper-jwr66v-202ba26a.tgz
wget -c https://dl.google.com/dl/android/aosp/widevine-grouper-jwr66v-c6bdbc54.tgz
tar -xvf asus-grouper-jwr66v-15547c77.tgz
tar -xvf broadcom-grouper-jwr66v-fa38dae8.tgz
tar -xvf elan-grouper-jwr66v-4235892f.tgz
tar -xvf invensense-grouper-jwr66v-0da5128c.tgz
tar -xvf nvidia-grouper-jwr66v-2cbbe013.tgz
tar -xvf nxp-grouper-jwr66v-202ba26a.tgz
tar -xvf nxp-grouper-jwr66v-202ba26a.tgz
rm *.tgz

Optionally create a backup for these shell scripts extracted:
cd ..
tar -jcvf Nexus7Binaries.tar.bz2 ./android-4.3_r1/*.sh
cd android-4.3_r1

[3.c] Extracting the Vendor Specific Binaries

In order to install the vendor specific binaries one needs to run the .sh files generated by extracting the .tgz files in the earlier step.
The method to run the shell files:
.\extract-<filename>.sh
Once you run them you would get a prompt to read the License agreement, press Enter to start reading and then Space bar to reach the end. Finally you need to type "I ACCEPT" to make the script extract the files. Finally the 'Vendor' directory would be ready after this step
Now we are ready for the next big step - Compiling!

[4] Building the Sources

First thing to do is to setup the Environment:
cd android-4.3_r1
. ./build/envsetup.sh

Anatomy of the command
'. ' = Signifies that we would be implying to execute the command in the current shell context
./build/envsetup.sh = Command to setup the environment variables and commands

Now to select the type of device we give the following command:
lunch

This would display some selection menu like:

You're building on Linux

Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_x86-eng
     3. aosp_mips-eng
     4. vbox_x86-eng
     5. aosp_flo-userdebug
     6. full_grouper-userdebug
     7. full_tilapia-userdebug
     8. mini_armv7a_neon-userdebug
     9. mini_mips-userdebug
     10. mini_x86-userdebug
     11. full_mako-userdebug
     12. full_maguro-userdebug
     13. full_manta-userdebug
     14. full_arndale-userdebug
     15. full_toroplus-userdebug
     16. full_toro-userdebug
     17. full_panda-userdebug

Which would you like? [aosp_arm-eng]

For this you need to select the " 6. full_grouper-userdebug" choice by entering '6'
It would display the details of the selected "grouper" hardware.

Next major Step is to initiate big build process. This build process would take approximately 2hours 45minutes to complete on the machine specified above. If one has i7 then they can get even faster builds.
This command is:
make -j4

Here the "-j4" switch would help to run the build on Quad core.
After this is done you are ready with your source to flash the image into your device.

DISCLAIMER: If you proceed on the steps provided it will surely cause damage to your Nexus 7 device and the Author of this article will not be held responsible for any losses or damages of any type caused by following the steps below.

[5] Flashing the Device

This would definitely damage your device and load the image of Android OS built in the previous steps.In order to perform this step one needs to unlock the bootloader as explained in the XDA forum post.
Connect your device into the Linux PC. And give the command in the existing terminal prompt from the earlier step.
adb root
adb reboot bootloader
cd out/target/product/grouper

This would help you enter the bootloader mode. And change the directory to the place where the actual build image files are located

Final command that would kill the device and load your compiled image:
fastboot oem unlock && fastboot -w flashall

This would load the complete image into your device and then reboots it.
Now that you have successfully built and flashed the code you might not find it very useful until you add all the bells-n-whistles that a professional rom has. We would try to cover that in our next tutorial. Also next tutorials we have described how to restore the factory image.
Hope that you find this post helpful, let us know your feedback and suggestions.

Welcome to Boseji's Blog

Popular Post

Blogger templates

Welcome

Creation by Electronics Hobbyists from Bharat(India) to encourage & help people. This blog hosts the numerous innovations, discoveries and projects we provide.
Our Research Wing Adhar Labs
Contact Form | Email Address
We Support Open Source Hardware Definition v1.0
Creative Commons License
All works on this blog are licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at forbharat.wordpress.com and m8051.blogspot.com.

Permissions beyond the scope of this license may be available at http://forbharat.wordpress.com/permissions/.
Thank you for all your support.

© A.D.H.A.R Labs Research 2008-2013 . Powered by Blogger.

Follow by Email

Followers

PCB Unit Converter

mils
mm

- Copyright © Electronics for Bharat -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -