[Miscellaneous Android Development] rmbq:
Hi guys!

I wrote this guide because after a few month of kernel development i found useful tools and tricks than helped me a lot and speeded up my work and i want to share with you this knowledge.

Setup computer and download sources​

Minumum reqirement:
* C knowledge
* Ubuntu 12.04 (13.10 if you want use Kdevelop + linux kernel plugin)
* Internet connection, possibly fast and unlimited
* the boot.img of the ROM you want to support with your kernel (AOSP, SENSE etc etc...)
* [URL="http://xdaforums.com/showthread.php?t=2519416"]zImage switcher[/URL]

Install required package:

Linux 12.04;

sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2 bin86 libqt3-headers libqt3-mt-dev wget libncurses5 git-core nautilus-open-terminal

linux 13.10:

sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2 bin86 qt4-dev-tools wget libncurses5 git-core nautilus-open-terminal

and restart your PC.

Download Source:

Go to /home/<username>, create a new folder called "kernel", and enter in that folder.

right click somewhere in "kernel" folder and select "open terminal here" (CooL AH?)

and run

git clone <kernel-source-code-for-your-device-repository>

for example for HTC One S will be

git clone https://github.com/CyanogenMod/android_kernel_htc_msm8960.git

Download the toolchain

There are a lot of toolchain, stock, linaro optimized, based on gcc 4.7, based on gcc 4.8 the choice is yours! in this tutorial we use google gcc 4.7 toolchain.

Go to /home/<username>, create a new folder called "toolchains", and enter in that folder.

right click -> open terminal here

git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7

Build the kernel​

Build the kernel:

in this part we will work in "/home/<username>/kernels/<kernel-folder>" folder, i'll call it <root>

go to "<root>/arch/arm/configs" and copy "<you-device-name>_defconfig" to <root>

rename <you-device-name>_defconfig to ".config"

open a terminal window in <root>

type:

make ARCH=arm CROSS_COMPILE=/home/<username>/toolchains/arm-eabi-4.7/bin/arm-eabi- > compileLog

and the compilation will start.

Some explanation:

Pack the kernel to boot.img:

Unpack zImage switcher somewhere, i'll call that folder <ZimgSw>.

copy in the same folder of "repack.sh" file the stock boot.img and yout zImage, you can find it in <root>/arch/arm/boot.

run the script

./repack.sh

now in <ZimgSw> there's a new file called newBoot.img, that's your kernel!

to find the modules (*.ko files) open a teminal windows to <root> and type

find ./ -name "*.ko" -exec cp {} <absolute/path/destination/folder> \;

now you have the boot.img and the modules, download a custom kernel and use the flashable zip to make your flashable zip, just replace the modules and the boot.img!

Add features​

Add features to kernel:

"Woah! i'd like to add intellimand governor to my kernel"

First you need to find a git repository that contains intellimand governor, than the commit that added the governor.

for example https://github.com/rmbq/android_kernel_htc_msm8960/commit/6c87d0e0b3c82ffff8c0704dfde7369872f5602f

Open a terminal window in <root>

type:

git remote add rmbq https://github.com/rmbq/android_kernel_htc_msm8960.git -b cm-10.2
git fetch rmbq
git cherry-pick 6c87d0e0b3c82ffff8c0704dfde7369872f5602f

Explanations:

in termial window type:

make ARCH=arm xconfig

will open a new window where you can configure your kernel's features

press ctrl+f (find) and serach for "intellimand" and tick the checkbox. save clicking the floppy disk in upper left corner.

the modified configuration file will be saved in ".config"

now we can build the kernel again, but first type

make ARCH=arm clean CROSS_COMPILE=/home/<username>/toolchains/prebuilts_gcc_linux-x86_arm_arm-linux-androideabi-4.8/bin/arm-linux-androideabi-

this will remove all the compiled files of previous build.

View git commits history​

you can easly view all the commits in your repo:

open a terminal window in <root> and type

gitk

will open a GUI where you can see all the commits, what files were modified for each commit, the author of the commit.

you can also revert commits.

There are other GUI for git, i also like "gitg"

Hacking the kernel

suggested by [MENTION=2351000]pirlano[/MENTION]​

for easy work on kernel sources, add features & co. you can use kdevelop + linux kernel plugin, here is a guide

http://www.gnurou.org/code/kdevelop-kernel

and a video guide:

http://video.linux.com/videos/kernel-browsing-and-hacking-using-kdevelop

NOTE: for linux kernel plugin ubuntu 13.10 is required