[Sony Xperia S, Acro S, Ion] abcdjdj:
Hi guys!

In this tutorial I am going to show you how to compile a kernel for our devices. In this tutorial I will be using Xperia S as an example[stock ics 6.1.A.2.55]. So, let's get started.

Thins you will need:-

--->A Linux PC [32 bit works fine:D]

--->Sony sources from here - http://developer.sonymobile.com/downloads/opensource/

--->Stock kernel.sin of the same firmware

--->Flashtool

--->DoomLorD's prebuilt toolchain

--->Android kernel kitchen [Optional - only if you want to make changes in the ramdisk]

---.Time and patience:angel:

Instructions :-

1. Firstly, start off by downloading the source code for our kernel from the above link.

2. Now run this command - mkdir android

3. Now copy the tar.bz2 file to this android folder and run this command -

cd android
tar -xjvf *.*

It will begin extracting the kernel files.

4. Now we must download the toolchain so run this command -

https://github.com/DooMLoRD/android_prebuilt_toolchains.git

It will take some time to download the toolchain.

5. Once it is done, open a new terminal window and execute the following commands:-

NOTE:- In the 3rd command, replace fuji_nozomi_defconfig with the appropriate config for your device -

Xperia NX SO-02D => fuji_nozomi_dcm_defconfig

Xperia S => fuji_nozomi_defconfig

Xperia acro HD SO-03D => fuji_hikari_defconfig

Xperia acro S => fuji_hikari_row_defconfig

Xperia acro HD IS12S => fuji_hayate_defconfig

Xperia SL => fuji_nozomi2_defconfig

cd android
cd kernel
ARCH=arm CROSS_COMPILE=~/android_prebuilt_toolchains/arm-eabi-4.4.3/bin/arm-eabi- make fuji_nozomi_defconfig
make ARCH=arm CROSS_COMPILE=~/android_prebuilt_toolchains/arm-eabi-4.4.3/bin/arm-eabi- menuconfig

Now you have a wide choice of options to do any tweaks or changes. Once you are done, save and exit the menu config file. Now we will build the zImage. Run this command -

ARCH=arm CROSS_COMPILE=~/android_prebuilt_toolchains/arm-eabi-4.4.3/bin/arm-eabi- make

It will take some time for the zImage to be compiled so till then, we can get the ramdisk ready.

6. Minimize the terminal window in which the kernel was being compiled. Now, open Flashtool and click on Tools--->SIN Editor and chose the kernel.sin [You can get the stock kernel.sin by opening the ftf with archive mounter or any unzipping utility]. Then press on Dump data and you will get the output as kernel.elf. Now, go to Tools--->Extractors--->ELF Extractor and chose the kernel.elf file which we had just now dumped. Then press on the extract button. Now out of all the files that got extracted, we need only 2 files which are - kernel.elf.ramdisk.gz and kernel.elf.rpm.bin

7. Run this command now -

mkdir compile

and copy the above two required files to this directory and rename the files respectively :-

kernel.elf.ramdisk.gz ---> ramdisk.img

kernel.elf.rpm.bin ---> RPM.bin [CASE SENSITIVE]

Then download this file - http://developer.sonymobile.com/downloads/tool/image_generation_script_for_xperia_s/

Extract the zip and copy mkelf.py to the "compile" folder.

8. Now, let's come back to the compiling and check if the kernel has got compiled. Just check the terminal window if it has stopped because of an error. If there are no errors and it has finished compiling then go to android/kernel/arch/arm/boot and you will see a file called zImage over there. Copy this zImage to our "compile" folder in the root directory.

9. Now, in your compile folder you must have the following files -

---> ramdisk.img

--->zImage

--->RPM.bin

--->mkelf.py

Now we left to only build our kernel.elf.

At this point, you have 2 options - if you want to make changes in the ramdisk then continue or else go to step 12

10. Run this command in the terminal -

git clone https://github.com/championswimmer/kernel-tools.git

Then copy ramdisk.img to /kernel-tools/input and then double click on the file called "menu". Then chose run in terminal and chose option 4 in the main menu. Chose extract ramdisk and follow the on-screen instructions.

11. Then make any changes that you want to make and copy the ramdisk-contents folder back to the input folder and now chose option 4 in the main menu and select pack ramdisk. Follow the on-screen instructions and then copy the ramdisk.cpio.gz from output directory to our "compile" folder and rename it to ramdisk.img

12. Now open a terminal and run cd to the "compile" directory and run the following command -

IF COMPILING FOR JB, then run this -

python mkelf.py -o kernel.elf zImage@0x40208000 ramdisk.img@0x41300000,ramdisk RPM.bin@0x20000,rpm

IF COMPILING FOR ICS, then run this -

python mkelf.py -o kernel.elf zImage@0x40208000 ramdisk.img@0x41500000,ramdisk RPM.bin@0x20000,rpm

BUT IF COMPILING FOR GB, then run this -

python mkelf.py -o kernel.elf zImage@0x40208000 ramdisk.img@0x41200000,ramdisk RPM.bin@0x20000,rpm

13. Then a kernel.elf file will be generated which can be readily flashed to your phone!:D

Use this command to flash it -

fastboot -i 0x0fce flash boot kernel.elf

Enjoy and happy developing!:)

Credits :-

--->DoomLorD [Toolchain and lots of help:)]

--->Androxyde [Flashtool]

--->Championswimmer [Android Kernel Kitchen]

--->Sony for their various guides and support to the dev community

#include<iForgotYou.h>;)

//Please PM me if you feel that your name should be here.