Mar 15, 2012

Building Android Kernel From Source on Linux

In DELL VENUE THUNDER PAGE have been explained how to prepare a PC to develop little android project for own use.
Android as well as other operating system, having "hearth" ... the hearth of Android OS is the Kernel. Android kernel build based on Linux Kernel source code. Building android kernel is 87% similar with building linux kernel for PC (x86) machine. However to build Android Kernel need more trick. To build android kernel we can use full android system source tree, however if we want to have tweaked kernel only full android source tree is not required.
Get Prepared
To prepare your machine for little android development please visit Dell Venue Page. This article is "next step" of dell venue page and discuss to build android kernel only.
To enable build android kernel we need kernel source code. In general, kernel source code released by android phone vendor. However some Open Source Project also provide Kernel Source Code, they are :
1.AOSP - Android Open Source Project
2.CyanogenMod Project
3.Code Aurora Forum

This article will provide step by step guide to build android kernel from CyanogenMod source code. I have personal project to build android kernel for DELL VENUE, but at the point of time this article wrote. I still unable to have BOOTING KERNEL for Dell Venue. I wrote this article, expecting to have someone willing to work together and give me help to build booting kernel for dell venue with available source on Public with target to build full android rom for dell venue based on android 2.3.x and android 4.0.x (Hopefully)

Seting Up Toolchain
I used a PC which is x86 machine, thus I need toolchain to enable build a kernel for android phone with arm architecture. Use a lot of terminaling command on ubuntu linux machine (mine is 10.04 lts version). Open terminal and navigate to home folder. Many of toolchain available on internet. One of most popular is CodeSourcery. But I prefer to use prebuilt provided by google
$ git clone https://android.googlesource.com/platform/prebuilt

Aftef downloading complete we will have prebuilt folder in home folder and toolchain is inside prebuilt folder. I make it simple
Create Your own Tools
Basic instruction in command make (gnu linux basic command) within x86 PC is for PC architecture. In using toolchain and we do frequently due to learning or testing will very annoying to do long commands line like
$make ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-eabi-

every time going to compile android kernel. To make it simple, I suggested create an executable file named armmake at /usr/bin folder. Open terminal (again) and type :
$sudo gedit /usr/bin/armmake
A gedit window will come up > copy and paste the following words :
#!/bin/bash
PATH=$PATH:~/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin
make ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-eabi- $1

Saved abd closes, then execute
$sudo chmod a+x /usr/bin/armmake
$sudo chown YOUR_USER_NAME /usr/bin/armmake
This will safe your time in typing, anytime you need to compile arm kernel just execute > armmake !!
Downloading Kernel Source

As described at Dell venue Article. we have folder named cm7 at home folder. We need to create another folder named kernel in cm7 folder. Execute
$mkdir /~cm7/kernel
$cd ~/cm7/kernel
$git clone git://github.com/CyanogenMod/cm-kernel.git

This will download entire cyanogenmod kernel source and create cm-kernel folder
Complie and Build
From above we have complete kernel source tree from cyanogen project. To configure a kernel for certain device we need configuration file named .config How we can get this file (?) the best way is obtaining from a live android device. Ensure you have adb setting up properly and live. Connect a live device to usb port and execute command :
$sudo adb start-server
$sudo adb pull /proc/config.gz
Now we have config.gz file among kernel source tree
$gunzip config.gz > .config

We have everything to start setting kernel configuration and build a kernel for a device. Just execute :
$ armmake menuconfig

a window will come up like this image :


Completing your configuration or make necessary changed you want or just save and build to have exactly similar configuration with kernel on live device, now execute :
$time armmake -j5
Your kernel will be build. Command time is not mandatory, it is optional to know how long your machine compiling a kernel. If everything went well (mean WITHOUT ANY ERROR), a kernel will be ready at folder arch/arm/boot/zImage

Is it that Easy to build a kernel ?
The answer is YES ... thats all the basic instruction. However in real life, we probably face some error and make us clueless to solve the problem, since every one having specific error

could not execute command 'lessc' odoo 9.0

Well ... odoo installed properly and running well on local server. However after creating a data base and successfully logging in, the od...