Obtaining and Compiling Samsung Kernel Source
On lazy weekends when it's raining as usual in Seattle I like to get to work on projects, one recent venture which I'm still working on is Kernel development. Compared to HTC, compiling Samsung source is much easier than dealing with HTC Source. Despite some issues with actually getting source released, which I admit that Samsung is improving exponentially on, It's fairly simple to get setup. By the end of this article you will have compiled your very own Samsung kernel for your device.
Use the Source!
By now most Samsung devices have their Kernel sources released, you can look for yours by going to http://opensource.samsung.com/ then under the Mobile tab, click Mobile Phones. You will then be presented with a large table full of device models and links. For this demo I will be using the Verizon Samsung Fascinate ED01 Source "SCH-I500_VZW_Froyo.zip". Click the link and choose to Agree to the Legalese you're presented with, your download should start immediatly after. While that is downloading, let's go over the ideal environment for Kernel development:
- Multi-Core CPU for fast compiling
- Linux OS, either installed or running in a Virtual Machine
- Familiarity with a terminal
- General understanding of what a Kernel is
- A phone to test on
Aside from those general needs, be patient, learning new things takes time and you may run into issues. By now your source is almost done downloading and now to get all setup...
Getting down to business
Now that the source is downloaded we need to get busy in a terminal, go ahead and extract the source to your home directory (/home/username) then open a terminal. For this demonstration I will be using Ubuntu 11.04 Natty Narwahl. With the terminal open, navigate to the directory where you extracted the two tar.gz files.
krtek@krtek:~$ cd /home/krtek/
krtek@krtek:~$ tar -xvf SCH-I500_VZR_Froyo_Kernel.tar.gz
You will now see it spit out all the files it has extracted, we can now go to working with the kernel source. For this demo we will just be compiling a stock kernel, to modify your kernel by adding such features as overclocking you can go look at other developers source and compare kernels with yours and theirs and find the diffs for certain files (Remember to always give credit!). Next we will take a look at the structure of the kernel and how to compile it simply.
krtek@krtek:~$ cd /home/krtek/Kernel/
krtek@krtek:~/Kernel$ ls
Below is the output of ls
arch COPYING crypto drivers fs init Kbuild lib Makefile net REPORTING-BUGS scripts sound test.txxt usr block CREDITS Documentation firmware include ipc kernel MAINTAINERS mm README samples security test.txt tools virt
Let's go over some of the main folders/files listed here and what they do:
- arch — all of the architecture dependent code
- crypto — the API for the crytography features
- drivers — The code for hardware drivers
- fs — All of the code for the filesystems in support in Linux
- include — The Kernel header files are located here
- init — This directory performs the bootstrapping function along with initialization of the OS
- ipc — Interprocess Communication Support code
- kernel — Kernel space code
- lib — Helper functions for the kernel
- mm — Memory management
- net — Code for the network protocols and functions
- sound — Sound support
And within each of these common directories are many sub-directories, the Linux kernel, as of March 14th, 2011, contains 14,294,439 lines of code in the 2.6.38 release [1].
Now that we know what all of this is, let's get our cross compiler setup and compile a kernel. In your terminal do:
krtek@krtek:~/Kernel$ sudo mkdir /opt/toolchain
krtek@krtek:~/Kernel$ cd /opt/toolchain
krtek@krtek:/opt/toolchain$ sudo wget http://smp-on-qemu.googlecode.com/files/arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
krtek@krtek:/opt/toolchain$ sudo tar -xjf arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
krtek@krtek:/opt/toolchain$ ls
arm-2009q3 arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
arm-2009q3 is our toolchain that we will be using for compiling the kernel. Now onto that process!
Compiling the Kernel
Now that the toolchain is setup and our source is setup we must navigate back to where we were working:
krtek@krtek:/opt/toolchain$ cd /home/krtek/Kernel
krtek@krtek:~/Kernel$ make arch=arm atlas_03_defconfig
krtek@krtek:~/Kernel$ make ARCH=arm HOSTCFLAGS="-g -O3" -j8 CROSS_COMPILE=/opt/toolchain/arm-2009q3/bin/arm-none-linux-gnueabi-
Then go break out some coffee, when you return it should be done. It can take a long time if you're on a single or even dual core machine. If all went well it should spit out
Kernel: arch/arm/boot/zImage is ready
If not then check over all the command and make sure you have all the prerequisites fulfilled.
The Gnu Public License (GPL)
The Android Kernel, which is primarily the Linux Kernel with OEM Drivers, is licensed under the Gnu Public License, GPL for short. This license requires that all changes made to the Kernel be published. If you plan on compiling your own Kernel and releasing it in any form then you must abide by the GPL and release your source files used to compile. To learn more about the Gnu Public License and read its terms and conditions then visit http://www.gnu.org/licenses/gpl.html . Stay tuned for a guide on using revision control tools such as Git, Subversion, and Bazaar, which can all be used for sharing Kernel sources.
Acknowledgments
Huge thanks to Mark Dietz (Username: imnuts) for helping with troubleshooting a few issues and for teaching me a while ago.
1 - http://www.h-online.com/open/features/What-s-new-in-Linux-2-6-38-1205467.html?page=6