[T-Mobile Samsung Galaxy S II SGH-T989] datzstr8:
Overview

Here are the steps to build your own kernel from source. This example does nothing special. It just shows you how to build the stock kernel. It is a good starting point to making your own stuff. Experts, please correct me where I am wrong. This stuff is still new to me also.

These instructions work for both T989 (T-Mobile) and I727 (AT&T) variants of the Samsung Galaxy S2 phones.

Special Thanks

Special thanks to "interloper" and "dtm_stretch" for helping me learn all of this. Couldn't have done it without them.

Requirements

I am using Ubuntu 10.10 32-bit to do all my builds

Instructions

1) Get Samsung Source Code

First you need to get a copy of the kernel source code from Samsung. You can download it from the link below.

For T-Mobile users download the one that says T989:

https://opensource.samsung.com/reception/receptionSub.do?method=search&searchValue=SGH-T989

For AT&T users download the one that says SGH-I727:

https://opensource.samsung.com/reception/receptionSub.do?method=search&searchValue=SGH-I727

2) Unzip Samsung Source Code

Unzip the source code you just download with this command:

For T989:

unzip SGH-T989_GB_Opensource.zip

For I727:

unzip SGH-I727_ATT_Opensource.zip

There will be 4 files extracted. The one we are interested in for this exercise is SGH-T989_Kernel.tar.gz for T989 devicees or SGH-I727_ATT_Kernel.tar.gz for I727 devices.

3) Extract Kernel

Next we need to extract the kernel into a directory.

For T989:

mkdir kernel
tar xzf SGH-T989_Kernel.tar.gz -C kernel

or

For I727:

mkdir kernel
tar xzf SGH-I727_ATT_Kernel.tar.gz -C kernel

4) Get a Copy of initramfs

Next you need to get a copy of the initramfs for your phone. For T989 users you can get the stock initramfs from bubby323's github here: https://github.com/bubby323/anomaly_kernel_platform_SGH-T989

For I727 users you must use the alternate method below to get the initramfs. T989 users can choose to use the link above or go with the alternate method below.

Alternate method:

You can extract it yourself from an existing boot.img file. I got mine off of my phone using clockworkmod backup (boot.img file) and using the extractboot tool to extract the initramfs. The tool can be downloaded here: http://www.mediafire.com/?lc12eceeh617b97

Extract extractboot.tar.gz

tar xzf extractboot.tar.gz

Call this to extract your boot.img to get the initramfs folder

extractboot boot.img

If you get any errors with calling extractboot, make sure "extractboot" and "split_bootimg.pl" are executable first. If not, use "chmod a+x extractboot" (do the same for split_bootimg.pl).

Once extracted, the "out/ramdisk" folder is your extracted initramfs folder.

reference: http://www.freeyourandroid.com/guide/extract-edit-repack-boot-img-windows

5) Download Arm Toolchain

This toolchain will allow you to cross compile for your phone. There are several versions to choose. I currently use the 2010q1 version here: https://sourcery.mentor.com/sgpp/li...1-188-arm-none-eabi-i686-pc-linux-gnu.tar.bz2

Or choose another version if you like (version 2009q3 seems to be popular): https://sourcery.mentor.com/sgpp/lite/arm/portal/subscription3053

6) Extract Toolchain

tar xjf arm-2010q1-188-arm-none-eabi-i686-pc-linux-gnu.tar.bz2

7) Download mkbootimg Tools

Download mkbootimg tools from here: http://www.mediafire.com/?w06d1m6n1dgo4op

Extract the file with

tar xzf mkboottools.tar.gz

There will be three files

mkbootfs
mkbootimg
mkbootimg-sg2x

"mkbootimg" is the original program to make the boot image but is not used for our phone. Our phone requires an edit to the ramdisk address which is why I also included "mkbootimg-sg2x" which we will use instead.

*Extra Info: the default ramdisk offset is 0x01000000 while our phone needs 0x01400000.

Move the three files to somewhere in your system PATH.

8) Compile Script

Now we are ready to compile the kernel. I have provided a script below to automate the process. You will need to change the paths to work with your environment.

*For I727 users only: change "msm8660_celox_usa_tmo_defconfig" to "msm8660_celox_usa_att_defconfig" in the script below.

*Update: Thanks to InstigatorX for his comment:

INITRAMFSDIR=~/t989/initramfs

export ARCH=arm
export CROSS_COMPILE=~/arm-2010q1/bin/arm-none-eabi-

cd kernel
make clean
make mrproper
make msm8660_celox_usa_tmo_defconfig
make -j4

# copy the freshly compiled modules to the initramfs.
cp crypto/ansi_cprng.ko $INITRAMFSDIR/lib/modules/
cp drivers/bluetooth/bthid/bthid.ko $INITRAMFSDIR/lib/modules/
cp arch/arm/common/cpaccess.ko $INITRAMFSDIR/lib/modules/
cp arch/arm/mach-msm/dal_remotetest.ko $INITRAMFSDIR/lib/modules/
cp drivers/net/wireless/bcm4330/dhd.ko $INITRAMFSDIR/lib/modules/
cp arch/arm/mach-msm/dma_test.ko $INITRAMFSDIR/lib/modules/
cp drivers/input/evbug.ko $INITRAMFSDIR/lib/modules/
cp drivers/media/video/gspca/gspca_main.ko $INITRAMFSDIR/lib/modules/
cp arch/arm/perfmon/ksapi.ko $INITRAMFSDIR/lib/modules/
cp drivers/video/backlight/lcd.ko $INITRAMFSDIR/lib/modules/
cp drivers/net/wireless/libra/librasdioif.ko $INITRAMFSDIR/lib/modules/
cp drivers/misc/msm_tsif.ko $INITRAMFSDIR/lib/modules/
cp arch/arm/oprofile/oprofile.ko $INITRAMFSDIR/lib/modules/
cp drivers/crypto/msm/qcedev.ko $INITRAMFSDIR/lib/modules/
cp drivers/crypto/msm/qce.ko $INITRAMFSDIR/lib/modules/
cp drivers/crypto/msm/qcrypto.ko $INITRAMFSDIR/lib/modules/
cp drivers/scsi/scsi_wait_scan.ko $INITRAMFSDIR/lib/modules/
cp drivers/spi/spidev.ko $INITRAMFSDIR/lib/modules/
cp drivers/misc/tsif_chrdev.ko $INITRAMFSDIR/lib/modules/
cp drivers/misc/vibetonz/vibrator.ko $INITRAMFSDIR/lib/modules/

9) Get Compiled Kernel

The compiled kernel image is in the kernel source folder under "arch/arm/boot/zImage"

Copy the zImage file to a working area, preferably where you keep your initramfs folder.

Here is an example folder structure:

work
- zImage
- initramfs

10) Make boot.img File

Next we need to merge the kernel and initramfs directory into a boot.img file.

zip up ramdisk

mkbootfs initramfs | gzip > ramdisk.gz

make boot image

mkbootimg-sg2x --kernel zImage --ramdisk ramdisk.gz --cmdline "androidboot.hardware=qcom msm_watchdog.appsbark=0 msm_watchdog.enable=1 loglevel=4" -o boot.img --base 0x40400000 --pagesize 2048

11) tar boot.img

Tar your boot.img file so it can be flashed with Odin.

tar cvf MyKernel.tar boot.img
md5sum -t MyKernel.tar >> MyKernel.tar
mv MyKernel.tar MyKernel.tar.md5

12) Flash with Odin

Flash MyKernel.tar.md5 with odin under PDA. Please follow the flashing guides found in other posts. They do a better job at explaining.

13) Experiment *

Now try to customize your kernel to add in new features and experiment. I am going to learn how to compile the stock platform also. Once I know how I will post up a guide for that also. If someone already has a guide to build the platform please post. Also it would be great if you can post sources for me to read so I can learn how to build the platform. Thanks.

Optional

You might notice that the modules you compiled are significantly bigger than the original stock modules that came with the phone. That is because the stock modules were stripped of all debug info. To do this you need to run the below command at the end to get the "stripped" modules. Change INSTALL_MOD_PATH to point to any folder you like to hold the modules. You then need to copy these modules instead of the ones in the build script above.

make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=~/stripped/modules modules_install

What's Next?

Go here to learn how to start making changes to your ROM: http://xdaforums.com/showthread.php?p=23343879