[HTC Wildfire S] Parisbre56:
====================================================================

How to compile Linux kernel for rooted ARM HTC Android 2.2+

====================================================================

(The process should be similar for other devices (if you can get your hands on their source). These instructions were used to compile successfully in Ubuntu 12.04.1 LTS for a rooted HTC Wildfire S, Android version 2.3.5)

0. Most Ubuntu installations should be ready to go, however just to be on the safe side you can use the command 'sudo apt-get install build-essential kernel-package libncurses5-dev bzip2' to install any missing packages.

1. First download the kernel source from HTC: ' http://htcdev.com/devcenter/downloads '.

Make sure to check Settings->About phone->Software information->more for the correct version.

2. Then download the android NDK: ' http://developer.android.com/tools/sdk/ndk/index.html '

(should be revision 5c but any NDK with the arm-eabi (NOT the arm-android-eabi) cross compiler should work (in fact any crosscompiler you can find for arm-eabi should work, as there are some custom/non-android ones around))

!!THIS IS IMPORTANT!!: DO NOT USE THE ARM-ANDROID-EABI CROSSCOMPILER!!! If you do, the kernel will (probably) compile but its modules will (probably) not load.

3. Untar the files somewhere, then export these variables: 'CROSS_COMPILE=/home/paris/ndk-r5c/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/arm-eabi-'

'ARCH=arm'

(You should change '/home/paris/ndk-r5c/' to the path of your own ndk. It is also possible to give this as a variable to the kernel Makefile, either by editing it and adding these decelerations to its first lines or by giving them as arguments when calling from the command line. Finally, you can add the bin folder to your path and export 'CROSS_COMPILE=arm-eabi-')

4. Pull the config file for your devices kernel from your device, using the adb (android debug bridge) command 'adb pull /proc/config.gz'. Open the archive and rename the config file inside to '.config' and copy it to the folder the kernel makefile is.

(Alternatively you can use one of the defconfig files with the comand 'make <device name>_defconfig'. See folder '<kernel source>/arch/<your architecture, usually 'arm'>/configs' for a list of defconfigs)

5. Use the command 'make menuconfig' to alter the configuration file. The menu should be pretty self explanatory and selecting Help will... help you understand more about the options. If you don't know what something is, you should probably leave it be. When done exit and save.

(Remember, when selecting modules [M] means the module will be compiled separately while [*] means the module will be compiled in the kernel. To load separate modules module support for the kernel must be enabled in the kernel options.)

6. Now everything should be ready. Use the command 'make -j<number of threads, used to compile faster on multicore machines>'

7. If everything went well, your kernel should be in the folder '<kernel source>/arch/<your arch>/boot' with the name 'zImage'.

8. Now !!BACKUP YOUR DEVICE!! (seriously, if you screw up and can't restore your device because you haven't backed it up, I'm not responsible). I use clockworkmod's backup option but any FULL backup will do. If your phone is rooted, you should already know how to do this.

9. Most backups contain an Image file named 'boot.img'. If your backup doesn't have this (it probably either compresses the backup somehow or it's a crappy backup) then search for alternate methods of obtaining the .boot.img'. Copy this image to your PC.

10. Download the python script 'split_boot_img.py' from Vicente Hernando: ' http://linuxclues.blogspot.gr/2012/11/split-bootimg-python-android.html ' or ' https://github.com/vhernando/split_boot_img '

Put it in the same folder as 'boot.img'.If you don't have python use apt-get install python to install it. Use the command 'python split_boot_img.py -i boot.img -o <output folder name, I used 'old'> -v'. You should get an output similar to this:

'Creating directory: old

boot_magic correct: ANDROID!

kernel size: 2484384

kernel address: 314605568

Base: 314572800 (hex): 0x12c00000 <--

ramdisk size: 449189

ramdisk address: 331350016

second size: 0

second address: 330301440

tags address: 314573056

page size: 2048 <--

product name:

cmdline: no_console_suspend=1 console=null

File old/zImage written (length=2484384).

File old/ramdisk.gz written (length=449189).'

Copy these lines and save them in a text file. Pay attention to the lines with the arrow.

11. Copy the ramdisk.gz from the old folder to a new folder. Copy the zImage you compiled to the new directory.

12. Download 'android_bootimg_tools.tar.gz' from: ' http://code.google.com/p/android-se...il?name=android_bootimg_tools.tar.gz&can=2&q= '

Untar/unzip the archive and copy the file named 'mkbootimg' to the folder where the zImage you compiled and ramdisk.gz you extracted from the old boot image are.

13. Use the command 'mkbootimg --kernel zImage --ramdisk ramdisk.gz --base 12c00000 --pagesize 2048 -o boot.img' Remember to change the 'base' and 'pagesize' arguments to the numbers you got on step [10]. (Remember the arrows?) You should now have your 'boot.img' file.

14. Now restart the device in bootloader mode and select fastboot. Connect your device to your computer via USB. You should see 'FASTBOOT USB' somewhere on screen now.

(Most devices boot in bootloader mode if you hold down the power button and volume down button when in hard off. You navigate the menus using the volume buttons and power button. Of course if you have rooted your phone you should already know how to do that. If not, Google and xda is your friend.)

15. Flash the new image using the ADB tool fastboot, by using the command: 'fastboot flash boot boot.img'

16. Select reboot. Your phone may take a while to restart but THAT'S OK! It's probably just rebuilding the dalvik cache. Just let it finish. If there's an error it will show up now. Just restore your backup and it'll be as good as new (or as good as it was when you backed it up). Remember that some things might not be working well yet since you haven't installed the appropriate modules. (You can verify that you are indeed running the new kernel by checking Settings->About phone->Software information->more where your computer name, time of compilation and EXTRAVERSION will be displayed)

17. Now simply mount your '/system' partition as read/write (google for instructions if you don't know how, it usually helps to run 'adb shell' to open a shell if you don't have a file manager that can remount the system partition as rw) and copy/replace the modules you will use to the appropriate folder, usually '/system/lib/modules/'. To find the modules you can simply use the command 'find -iname "*.ko"', either on your android device (if you have busybox installed) or your PC's kernel source directory. (There might be other commands necessary to activate new, user created modules. I'll update this post when I find out.)

That's all folks. If I have made any mistake or if I am unclear somewhere please tell me. Also tell me if I've made anything stupid or unnecessary.

Since most tutorials I found were outdated I decided I should make one and post it here for all to see.

I can't stress this enough: I compiled my kernel and wrote this tutorial by using info and tutorials by other people. I'll try to help in the best of my ability with any questions, but I'll probably be unable to answer them all.

====================================================================

Some tips

====================================================================

You can alter the 'EXTRAVERSION=' line in the Makefile to give your kernel a custom name/version. However, remember that most modules only load to kernels with the same name/version.

You can use the command 'make clean' to delete the compiled files, modules and kernel. Useful if you change something and want to be sure the new compilation is different.

You can use the command 'make mrproper' to delete the configuration files, making your source code truly clean.

You can use the command 'make -j<number of threads> modules' to only compile the .ko modules and not the kernel itself.

You can change the governor, cpu frequency, power options and more with the menuconfig, but be careful when you do so; it might fry your phone.

====================================================================

Thanks to

====================================================================

xda-developers, CyanogenWiki, Vicente Hernando and others for the info and files I used

(this is especially useful: http://xdaforums.com/showpost.php?p=28646648&postcount=1 )

ohheyitslou for his tutorial: http://ohheyitslou.blogspot.gr/2011/09/ohheyitslou-custom-android-kernel-guide.html

ClockworkMod Recovery for its phone-saving usefulness

HTC for the free kernel and unlockable bootloader

google for Android and its search engine