Tuesday, August 30, 2011

HOWTO: custom kernel on Samsung Galaxy S II I9100

Recently I've replaced my Bravo HTC Desire with a new Android phone: a Samsung Galaxy S II I-9100. I couldn't resist too much with the stock kernel, so finally I've found some spare time to cook a custom kernel starting from the original Samsung kernel source code GT-I9100_OpenSource_Update2.

In this post I report (for me to remember later and for those who are interested) all the steps that I did to setup the build environment, cross compile the custom kernel and flash it into the phone.

DISCLAIMER: I take no responsibility for anything that may go wrong by you following these instructions. Proceed at your own risk!

=== Requirements ===

- A Samsung Galaxy S II (not necessarily rooted! you'll get a root shell when you'll flash the new kernel)
- The latest android SDK
- The arm-none-eabi cross-compile toolchain (you can get it from the CodeSourcery website)

=== HOWTO ===

Download and install the arm toolchain from the CodeSourcery website: be sure that arm-none-eabi-gcc is in your $PATH.

Get the autobuild script:
 $ git clone git://github.com/arighi/gt-i9100.git

Run the script:
 $ ./build-kernel.sh

The script downloads the "-arighi" kernel source code, a initramfs template and builds a new kernel ready to be flashed into the device.

At the end of the autobuild process the file kernel-gt-i9100-arighi.tar can be used to flash the new kernel to the phone using Odin (search on the web or in the xda-developers forum, there are tons of howtos/tutorials for this).

=== Results ===

The score with Quadrant benchmark is not bad at all, I got always > 4000, but remember that we're cheating during the IO test, due to the fsync-disable patch.

Anyway overall result looks good enough.


== Additional notes ===

- All the custom *.ko files are included into the initramfs to avoid potential errors/problems with the original kernel modules (so it is always possible to flash back the original kernel later, all the old kernel modules are still there, untouched).

- After you've flashed the -arighi kernel the first time you will also have root access to your device. The initramfs template enables adb root shell (ro.secure == 0), so an adb shell will immediately drop you to a root shell. This means you can also re-flash your device from Linux directly using the flash-kernel.sh script.

- For the complete list of all the patches applied to this kernel have a look at the git log here.

- IMPORTANT: the fsync-disable patch (enabled in the kernel by default) can increase performance and battery life, but it is dangerous, because it might eat your data!! It makes the software no longer crash safe, so if you start to randomly kill your apps you may lose some data


[UPDATE: the fsync-disable patch is no more enabled by default in the kernel, to enable it just set CONFIG_FILE_SYNC_DISABLE=y in the kernel .config)]

14 comments:

sonic said...

Hello!
I released the Nexus One USB host mode driver:
http://sven.killig.de/android/N1/2.2/usb_host
One longstanding problem is the version mismatch between my kernel and the WLAN module
/system/lib/modules/bcm4329.ko
You seem to have found a workaround for this. How does it work technically? Is the real module hidden by the one in the initramfs?
Thanks in advance!

arighi said...

sonic: yes, the workaround is to just put all the custom modules into the initramfs.

In the GS2 all kernel modules are put directly into the initramfs, so it's enough to generate a new initramfs to hide the old ones.

Instead, if you have the modules in flash, a workaround could be to copy your custom modules to a different writeable dir (i.e., /sdcard/lib/modules) and then mount this directory over the old one (/system/lib/modules for example) using --bind:

# mount --bind /sdcard/lib/modules /system/lib/modules

I used this workaround in my old HTC Desire, because the modules were in /system/lib/modules and I couldn't write to /system without S-OFF'ing the device.

sonic said...

Thanks!
Unfortunately the built in mount binary doesn't understand --bind, so this would require busybox.

Anonymous said...

Thank you very much for posting. and for those active user. :) your comments are all appreciated.

Anonymous said...
This comment has been removed by the author.
Anonymous said...
This comment has been removed by the author.
Anonymous said...

Hello there,
i've compiled the fisrt zImage for sgs2 with your script and source.
Just one problem, there it require an comment char to "line 357, col 20" before -mno-unaligned-access on linux-gt-i9100/Makefile.
Ok now i go flashed that kernel and work around! thx for share!

If my english is bad, it's not my native language!

Anonymous said...

It work perfectly and better than the original! but now i lost the boot splash when it boot!
anyone know how i can fix it?

Anonymous said...

i finaly found! debug.sf.nobootanimation=1

arighi said...

Gold_Buckle: it's weird that you need to comment -mno-unaligned-access, which compiler are you using?

It seems to build fine here with the CodeSourcery's gcc 4.5.2:

$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (Sourcery G++ Lite 2011.03-42) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Anonymous said...

Hello, i use an old build apparently : @corei7:~/bin/arm-2009q3/bin$ ./arm-none-eabi-gcc --version
arm-none-eabi-gcc (Sourcery G++ Lite 2009q3-68) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Thanks for sharing & merry christmas.

arighi said...

Yes, please, update your toolchain to a more recent version (e.g., https://sourcery.mentor.com/sgpp/lite/arm/portal/release1802) and you don't need to touch the Makefile anymore. As a bonus, it'll also produce a better code in general. :)

Abhishek Sudhakaran said...

Can this kernel run a standard GNU/Linux distribution such as Debian/Ubuntu?

akoskm said...

Is there any change to find the initramfs provided by the vendor?

Also, my phone version is XWLSD not XWKE7, will this work with my model?

Where you get the official XWKE7 GT-I9100 initramfs?