[Android Software/Hacking General [Developers Only]] atc3030:
Hello All. I have received several requests for how to build a kernel from source so I figured I would make a guide for anyone looking.

WARNING: I CANNOT BE HELD RESPONSIBLE FOR ANY DAMAGE YOU CAUSE TO YOUR PHONE, PERSONAL RELATIONSHIPS, LIFE, OR CAR. YOU HAVE ALREADY ROOTED YOUR DEVICE SINCE YOU ARE READING THIS SO YOU KNOW IT VOIDS YOUR WARRANTY.

Now that thats over. I will walk you through how to set up a kernel building environment and walk you through building a kernel.

I.) Requirements

1.)You will need a computer. Just about any computer running linux will work, even a Virtual Machine. I will be using Ubuntu Oneiric, Server Edition for my guide. (Most commands are the same across Ubuntu Editions as well as Linux in general.)

2.)Internet Access- the faster the better

3.)Knowledge of the android kernel and what does what.

4.)The Master Branch from Google as well as the source for your device.

5.)ALOT of time.

6.)Common Sense

II.) Installing The Necessary Tools

1.)First we must download the neccesary tools.

To install java, you need to know which version of android you will be developing for.

Froyo and Lower:

$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy main multiverse"
$ sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu hardy-updates main multiverse"
$ sudo apt-get update
$ sudo apt-get install sun-java5-jdk

Gingerbread and Newer:

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

2.)Next we willl download the tools needed(You need to know if you are on a 64 bit system or 32 bit.)

For 64 bit:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc

Also you must link one thing based on your Ubuntu Version:

For 10.10:

$ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so

For 11.10:

$ sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so

For 32 bit:

$ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev tofrodos python-markdown libxml2-utils xsltproc

No linking is necessary.

NOTE: You can set up CCache on either setup. However, you will not need it necessarily due to the source is not that big compared to building a rom and therefore will not take as long.http://dnssearch.rr.com/index.php?origURL=http://www.goog.gl/&r=

III.) Downloading The Source

1.)If you already have an android Directory set up, then skip this step. If not, follow these commands. (NOTE:THIS GUIDE FOLLOWS AS IF YOU USE THIS STEP. BE CAREFUL)

$ cd $HOME
$ mkdir android
$ cd android

2.)Set up your source directory.

$ mkdir source
$ cd source
$ mkdir aosp (YOUR DEVICE)_kernel repo
$ cd repo
$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ./repo
$ chmod 755 repo
$ export PATH=$PATH:$HOME/android/source/repo/
OR
$ sudo cp repo /usr/bin/repo
$ cd ../aosp
$ mkdir master
$ cd master

3.)You are now ready to grab the source. You will need the master branch. So while in the master directory:

$ repo init -u https://android.googlesource.com/platform/manifest

THIS WILL TAKE A WHILE SO SIT BACK AND RELAX.

4.)Now you need your specific devices source. So follow those steps accordingly to get the source into the directory for you device kernel @ $HOME/android/source/(YOUR DEVICE)_kernel

You now have all the source you need.

V.) Building The Kernel

1.)Now we will set up the environment for the build.

$ export ARCH=arm
$ export CROSS_COMPILER=arm-eabi-
$ export CROSS_COMPILE=arm-eabi-
$ export PATH=$PATH:$HOME/android/source/aosp/master/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/

2.)Now you go into your device's kernel directory.

$ cd $HOME/android/source/(YOUR DEVICE)_kernel

3.)And begin the configuration.

If you like a gui like menu:

$ make menuconfig

If you like to answer questions:

$ make config

4.)Configure your kernel how you want it.

5.)Then, once thats done:

$ make -j4

This will build the kernel. This can take anywhere from 15 minutes to an hour and a half+.

VI.)Grabbing The Newly Made Kernel

1.) Your kernel will be located at:

$ $HOME/android/source/(YOUR DEVICE)_kernel/arch/arm/boot/zImage

2.) Your Wireless Module Will depend on your device. For the Ally, it would be:

$ $HOME/android/source/ally_kernel/drivers/net/wireless/bcm4329/wireless.ko

CONGRATULATIONS!!!

You have built your own kernel.

Now follow http://xdaforums.com/showthread.php?t=748106 to flash it.

Any problems or questions, let me know. Either a PM or I'm almost always in #asus-transformer on IRC.

Wanna donate to me and help me with bills? Follow this link to Donate Via PayPal:

http://goo.gl/ReRPs