Wednesday, December 28, 2011

Compile Kernel for Xperia X10 ( Android )

First of all try it at your own risk, am not responsible if you mess up your phone.

Requirements
  • Patience
  • Linux environment (Ubuntu or Linux Mint preferred)
  • Windows environment.
  • Bootloader unlocked Xperia X10.
  • Xrecovery must be installed.

Download the source from this link (This guide is written with trails run on Xperia X10 if you are on a different mobile you would need the source code of that mobile)





Untar the source ( use the archive manager i.e, double click over it ). Inside you must find four folders like this.


(Don't worry about the .config file)

I assume you have done all this on a Linux machine.
And also you would need a couple of packages to build the kernel just run
"sudo apt-get install" followed by

32bit and 64bit systems:

"git-core gnupg sun-java6-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev"

64bit only:

"ia32-libs lib32z1-dev lib32ncurses5-dev gcc-multilib g++-multilib"
And download the arm toolchain from here


Download the eabi tar ball
better use this link
https://sourcery.mentor.com/public/gnu_toolchain/arm-none-eabi/arm-2011.09-69-arm-none-eabi-i686-pc-linux-gnu.tar.bz2
Its the direct download link

Untar it and put it in a place some where easier to find and type in my computer it is ~/arm
and rename the directory from "arm-2010q"(or similar) to "arm" (makes it easier to type commands in future).

Put the kernel source similarly in a comfortable folder. I put mine in ~/x10. I assume you are on Ubuntu (kubuntu, xubuntu or any other ubuntu based system) or Linux Mint. Now open the terminal ( ctrl+alt+t ) and cd to the source folder. Cd to Kernel directory in it. And type

ARCH=arm CROSS_COMPILE=~/arm/bin/arm-none-eabi- make semc_es209ra_defconfig

"CROSS_COMPILE" should be followed by the directory where you have placed the arm toolchain. In my case it is "~/arm" followed by "/bin/arm-none-eabi-". If it doesn't work try "./home/regnarts/arm/bin/arm-none-eabi-" in my case, in your case ".//bin/arm-none-eabi-" use the same everywhere else you get the error. Rest of the article I've assumed you haven't met this problem.

Then if you want to change anything type

ARCH=arm CROSS_COMPILE=~/arm/bin/arm-none-eabi- make menuconfig

This brings out the usual blue screen of the kernel config. DO NOT CHANGE ANYTHING IF YOU DON'T UNDERSTAND WHAT IT MEANS!!!. If you want to give the kernel a custom name then go to general setup


Select append to kernel release and give it a name ( you can see that mine reads "__REGNARTS__")


Now let us build the kernel, type

ARCH=arm CROSS_COMPILE=~/arm/bin/arm-none-eabi- make

This starts the kernel build process.

Have a coke, spend some time and be back. If everything went fine you will receive a message saying

Kernel: arch/arm/boot/Image is ready
Kernel: arch/arm/boot/zImage is ready
Building modules, stage 2.
MODPOST 1 modules




Now go to "~/x10/kernel/arch/arm/boot" or "~//kernel/arch/arm/boot"

There you will find a image file named "zimage". That is your kernel but in order to flash it to your phone, there is still work to be done.

Firstly there is no "WIFI" module in this kernel. So you won't be able to use the "WIFI" we have to compile the "WIFI" module so cd to the source directory in my case "~/x10". Then cd to "vendor/atheros/wlan/host". Once there you will find files like

The image shows the files on a file browser. Run "ls" in the terminal it should bring up similar files. Now we need to edit a file to make things work. Type "gedit localmake.linux.inc" in the terminal. It opens up a text editor.


Now add

ATH_CROSS_COMPILE_TYPE := ~/arm/bin/arm-none-eabi-
ATH_LINUXPATH := ~/x10/kernel

in the 10th and 11th line and remove the "#" symbol in front of them

and also comment out the 31st line i.e, the second line below

# Some common variable

It reads

ATH_CROSS_COMPILE_TYPE := arm-eabi-
In the end it must look like

# Some common variable
ATH_ARCH_CPU_TYPE := arm
# ATH_CROSS_COMPILE_TYPE := arm-eabi-
ATH_BUS_TYPE := SDIO
ATH_OS_SUB_TYPE := linux_2_6
ATH_BUS_SUBTYPE := linux_sdio

Now save the file (ctrl+s) and exit the gedit (ctrl+q). Now let us build the wifi module. Type

ARCH=arm CROSS_COMPILE=~/arm/bin/arm-none-eabi- KERNEL_DIR=~/x10/kernel make

in the terminal. It should compile the modules without any problem.

After the compile process has been completed. we get a file by name "ar6000.ko" in "~/x10/vendor/atheros/wlan/host/.output/QUALCOMM_ARM_NATIVEMMC_BSP_REV=3240-SDIO/image" or "~//vendor/atheros/wlan/host/.output/QUALCOMM_ARM_NATIVEMMC_BSP_REV=3240-SDIO/image"

Now if you are on another phone then you already have all the things you would want just grab a ramdisk and create a boot image (boot.img) and flash it to your phone using fastboot. For X10 owners there is sill work to be done.

You will need a ramdisk but it is not difficult to get one download any of the kernel packages many developers have released them online try this

http://doomlord.sylvester20007.com/x10/x10_gb/unlocked/v05/x10_2.3.3_DooMKernel-v05.ftf

It is a link to kernel created by a developer by name "DooMLorD". Just download it and then double click over it to open it up in archive manger and extract it. You will find a directory named "META-INF" along with kernel.sin and loader.sin. We are only interested in kernel.sin. Download a perl script "unpack-kernel.sin.pl" form this link.

http://attachments.xda-developers.com/attachment.php?attachmentid=719941&stc=1&d=1316041218

Unzip it and put the script and kernel.sin in a folder. And then type

perl unpack-kernelsin.pl kernel.sin

If you face any "perl not found" error then run

sudo apt-get install perl

Now we get a file by name "kernel.sin-ramdisk.cpio.gz" along with many other files rename it to "ramdisk" ( no extensions)

Now copy the module ar6000.ko, ramdisk and zimage file to a place where you can access it from windows.

You need to download a couple of tools to do all this. Download "kernel.sin and .ftf creator" from

http://attachments.xda-developers.com/attachment.php?attachmentid=795515&stc=1&d=1322301284

And also you would need "update.zip packer" download it from here


now put ramdisk and zimage in a folder and unzip the contents of "kernel.sin and .ftf creator" to it.


Edit "BUILD-IT.bat" open it in a text editor and change the fields that say
branding: {whatever you want} >> manifest.mf
Created-By: {whomever you want} >> manifest.mf
ren kernel.jar {your file name}.ftf
Rename "zimage" to "image" and double click on "BUILD-IT.bat"

If every thing went as planned then you must have the file {your file name}.ftf. If not you probably have no java sdk on your windows machine. Then open up the "BUILD-IT.bat" and remove the lines that says

del kernel.sin

and then run it again. This time we will get a "kernel.sin" along with "manifest.mf". Copy "kernel.sin" "loader.sin" and "manifest.mf" to the linux environment and then place them in a folder and type
jar cvfm0 kernel.jar manifest.mf loader.sin kernel.sin

Then rename the kernel.jar file to {yourfilename}.ftf. You have just created a kernel that can be flashed over to the phone using flashtool. If you don't have one download it from here.


Now unzip the contents of "update.zip packer" and got to folder named "placehere"
create a folder named "system" inside which a folder named "lib" and inside which "modules" must be created. Place "ar6000.ko" inside "modules folder" and rename it to "wifi.ko". And run the script in the first directory. You will find this menu.


Select "1" and "1" again give partition as "SYSTEM" just hit enter for the next two options. Now we have to set permissions to the file. Wait, Just do this just go into "META-INF" directory then into "com" "google" and then "android" and double click on the update-script file and open it with notepad. Delete all of its contents and then paste this

copy_dir PACKAGE:SYSTEM SYSTEM:
set_perm 0 0 0644 SYSTEM:/lib/modules/wifi.ko

and save it. Now run the script again and select "2" i.e, create update.zip this thing creates a update.zip flash-able via "Xrecovery"

Install the kernel using flash-tool. Just place it in the /.firmwares folder and run the flash tool and click on flash you must find your kernel there. Then follow the instructions that come. once done copy the update.zip to your sdcard and then install it from Xrecovery.