[Galaxy S II Android Development] superatmos:
Building kernel

Okay. Let's learn how to build kernel for GT-I9100. There are many ways to build. I am just presenting here the way I build and make kernel.

NOTE 1: Follow the instructions exactly.

NOTE 2: Kernel is opensource. If you make any changes to it, you're expected to share your source. (Usually people share it over github :-))

NOTE 3: FLASHING KERNEL IS RISKY AND DANGEROUS. BE CAREFUL. BUILD AND FLASH ON YOUR OWN RISK.

What you need to have:

Ubuntu 10.04 and above (I use 10.04 :-))

ARM tool chain (Download HERE. Click on IA32 GNU/Linux TAR under Advanced Packages)

Samsung's opensource kernel for GT-I9100 (Download HERE. Go to Mobile->Mobile Phone-> Select I9100 (update 3 for Gingerbread and update 4 for ICS) and download the zip)

Setting up toolchain:

Extract the tar you downloaded(Suggestion: Extract to one folder where you can have everything. In my case /home/superatmos/build_kernel).

After extracting, you'll see a folder named arm-2010q1. Inside there will be many folders (ex. bin, lib and so on.)

Folder structure will be: /home/<your_name>/build_kernel/arm-2010q1

Setting up kernel:

Extract the zip you've downloaded from samsung's opensource.

You'll find two zips.

Extract GT-I9100_Kernel.tar.gz to /home/<your_name>/build_kernel/

Folder structure: /home/<your_name>/build_kernel/GT-I9100_Kernel

Setting up initramfs:

Samsung's zImage is divided into two parts: Opensource kernel (which you downloaded from samsung's website) and initramfs (which is root file system to boot up the device).

You can extract initramfs from your zImage using the below mentioned links (Credits and Thanks to Chenglu) Original Thread: HERE

To extract initramfs from Gingerbread zImage: HERE

To extract initramfs from ICS zImage: HERE

Folder structure: /home/<your_name>/build_kernel/initramfs

Now the entire setup is ready. Let's start modifying kernel configuration. :)

Setting up kernel config:

For Gingerbread:

Go to /home/<your_name>/build_kernel/GT-I9100_Kernel/arch/arm/configs folder.

Copy

c1_rev02_defconfig

file and paste it in kernel root folder (/home/<your_name>/build_kernel/GT-I9100_Kernel/).

Rename c1_rev02_defconfig to .config in kernel root folder.

Now open Makefile which is in your kernel root folder(/home/<your_name>/build_kernel/GT-I9100_Kernel/).

Modify the below lines (I guess line 195 and 196).

For ICS:

Go to /home/<your_name>/build_kernel/GT-I9100_Kernel/arch/arm/configs folder.

Copy

u1_defconfig

file and paste it in kernel root folder (/home/<your_name>/build_kernel/GT-I9100_Kernel/).

Rename u1_defconfig to .config in kernel root folder.

Now open Makefile which is in your kernel root folder(/home/<your_name>/build_kernel/GT-I9100_Kernel/).

Modify the below lines (I guess line 195 and 196).

ARCH ?= arm
CROSS_COMPILE ?= /home/<your_name>/build_kernel/arm-2010q1/bin/arm-none-linux-gnueabi-

Save and close.

Modifying kernel configuration:

Now open .config file(which you renamed). If its not seen, it might be hidden. ;) Go to View->Show hidden files and there you go. :)

Do the below things:

Adding local version:

Change CONFIG_LOCALVERSION=" " to anything you like. I add this way:

CONFIG_LOCALVERSION="-I9100-superatmos" :cool:

Adding initramfs path:

You need to let kernel know the path from which it needs to take initramfs.

Change CONFIG_INITRAMFS_SOURCE=" " to ../initramfs (In this tutorial it's the path. If you had copied anywhere else, give the path properly).

Enough for now. Once you get experience, you can modify many configurations as per your liking and save. This configuration can be changed by GUI too with the command make menuconfig.

The Important part: Building the kernel: :)

For Gingerbread:

Open terminal.

Go to path /home/<your_name>/build_kernel/GT-I9100_Kernel/

Type make.

For ICS:

Open terminal.

Go to path /home/<your_name>/build_kernel/GT-I9100_Kernel/

Type export USE_SEC_FIPS_MODE=true

Type make.

THAT'S ALL. YOUR zImage is ready and is available in /home/<your_name>/build_kernel/GT-I9100_Kernel/arch/arm/boot/zImage. :)

Install the zImage on the device:

Go to the path where zImage is present and type the below line in command line.

tar cvf I9100_kernel.tar zImage

Flash the tar using odin.

DONE. CONGRATULATIONS. NOW YOU'VE YOUR OWN KERNEL. :)

Give me your feedback so that I can improve this tutorial. And post here about how your build went. All the best. :)