Samsung Galaxy S/SCH-I500/Building The Kernel
There are a number of guides out there on how to build a kernel for Android phones, but they can be confusing. I figured there should be a write-up on how to build a working kernel for Samsung Fascinate. For the purposes of this guide, I will build KGB Kernel for TouchWiz Gingerbread ROMs from scratch.
A working build environment is always a Linux installation, whether real or virtualized. A reasonably recent Ubuntu 10.04 LTS or better should suffice.
Building a kernel doesn't require installation of the Android SDK or Java, but there are still a few packages that need to be obtained.
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl lzma cpio xz-utils zlib1g-dev libc6-dev squashfs-tools libncurses5-dev libreadline5-dev
If you are on 64-bit, also do:
sudo apt-get install ia32-libs lib32ncurses5-dev lib32readline5-dev lib32z-dev gcc-multilib g++-multilib libc6-dev-i386
This is probably a bit more than the bare minimum necessary to build a kernel. Some packages may already be installed, so don't worry too much about any messages to that effect.
Set Up CodeSourcery Toolchain
In order to compile the kernel, you must have a toolchain (build tools). Samsung uses arm-2009q3 from CodeSourcery, but KGB works with arm-2011.03, which is updated. For the purposes of this guide, obtain the Linux TAR [from this page]. Extract it somewhere, and note where you put it.
Get kernel source from git
mkdir -p ~/i500 cd ~/i500 git clone https://github.com/kangtastic/kgb.git
This creates a directory named i500 in your home directory, switches directories into it, and clones the default branch of the kgb repository on github. By default, git creates into a directory with the same name as the default branch (in this case, also named kgb), which means that you should eventually have the source in ~/i500/kgb.
Change toolchain paths in the kernel source
For this section, / is the kernel source root.
As indicated in /README, you must edit at least /build.sh to point to the toolchain before using the build scripts will work. Near the top of /build.sh, there are two variables named TOOLCHAIN and TOOLCHAIN_PREFIX.
The path for TOOLCHAIN must be absolute (i.e. you can't use ~/path but must expand it to /home/username/path), and includes the "/bin" at the end. Unless you are using a different toolchain, you shouldn't need to edit TOOLCHAIN_PREFIX.
It is a good idea to edit CROSS_COMPILE in /Makefile. The value of CROSS_COMPILE is "TOOLCHAIN/TOOLCHAIN_PREFIX". Browse the location where you extracted the toolchain and compare these three values in the unmodified kernel source to figure this out.
cd ~/i500/kgb ./build_log.sh
The build scripts take care of building the kernel and outputting Odin and CWM packages in ~/i500/kgb/build/out. They also do a few other useful things, which you can see if you read them.
If you used something other than abovementioned script to set up toolchain, and you don't want to manually build the kernel, you will need to reflect that in the TOOLCHAIN and TOOLCHAIN_PREFIX parameters in build.sh and CROSS_COMPILE parameter in Makefile as outlined in the previous section.
Manually building the kernel
If you do want to manually build the kernel:
make ARCH=arm CROSS_COMPILE=/usr/local/codesourcery/arm-2009q3/bin/arm-none-linux-gnueabi- kgb_defconfig make ARCH=arm CROSS_COMPILE=/usr/local/codesourcery/arm-2009q3/bin/arm-none-linux-gnueabi
Here, CROSS_COMPILE indicates that a different toolchain location is in use. The first line configures the kernel from the default kernel configuration template named kgb_defconfig, and the second line actually makes the kernel.
Then, make an Odin-flashable tar.md5.
cd ~/i500/kgb/arch/arm/boot tar -cvf kernel.tar zImage cp kernel.tar kernel.tar.md5 md5sum -t kernel.tar >>kernel.tar.md5