FORUMS
Remove All Ads from XDA

[HOWTO][SIMPLER]Compile your own kernel from source

2,025 posts
Thanks Meter: 2,203
 
By #define, Senior Member on 23rd January 2013, 10:44 PM
Post Reply Email Thread
Hey guys..
With all the awesome development thats been going on for our device, many people have been inspired to start their own versions of android development.. But, most of them do not know where to begin, or how to begin.. Or they may have some questions that remained unanswered..
Hence, I present to you(on a few requests), a simple and newbie friendly guide to compiling your own kernel for the HTC Explorer(Pico)..

Now I understand there is a custom kernel/custom ROM compiling tutorial by sakindia123 right here.. But, it has proven a little too complicated for some of the people starting out in the Android world..

I'll be making it as simple as possible..


-------------------------------------

Alright..
In order to start compiling kernels and/or ROMS, we need a certain prerequisites to be obtained...

1) A Unix based OS..
a) Ubuntu - Preferably latest, which is 12.10 as of right now.. Both 32-bit and 64-bit versions are OK for compiling kernels.. For ROMs you need 32-bit for Froyo and below, and 64-bit for Gingerbread and higher.. Beware that installing a 32-bit version twice will NOT make it a 64-bit version..

b) MacOS - Apple's very own OS.. Not much info about this with me..

2) Some knowledge to move around a Unix based system using the terminal..

3) A few packages, to let the system know we are trying to compile a kernel on it..

4) The source code of the kernel you want to compile.. There are various kernel sources you can compile from.. There's the stock HTC source, for Sense and Sense-based ROMs, there's the 2.6.38 custom kernel source by lirokoa, there's Garuda kernel source by flowish, and the more recent, 3.0.16 kernel source..

5) Some time on our hands, and patience..

-----------------------------------------------------------

Ok.. Now we begin our work..

First, we install the required packages in our Ubuntu setup.. To do that, fire up a terminal window, and type :
Code:
sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git
Now, I myself do not know what these packages exactly do.. All I know is that they help us get our work done, ie, kerneling..

Now, if you're using Ubuntu 12.04, you many need to create links of certain files, in order for them to work properly.. Run :
Code:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
Now, it's a good idea to start fresh.. So go ahead and reboot the system..

---------------------------------------------------------------------

Alright.. So now we have our packages..

Next, we need Java...

Now, in the world of Android, for us Pico users, Java 7 is of no use.. And Java 6 cannot be installed using the "conventional" methods..
So, we'll install Java 6 using the PPA feature..

Fire up a terminal on your newly rebooted system, and type :
Code:
sudo add-apt-repository ppa:ferramroberto/java
Next, run :
Code:
sudo apt-get update
Now that the repository is added and updated in our system, we'll install Java by running :
Code:
sudo apt-get-install sun-java6-jdk
This will install the correct version of Java in our system..

-----------------------------------------------------------------------------

Next up, obtaining the source, boot image tools and toolchain to compile.. You can obtain all the sources I mentioned above using Github.. Except the HTC source, which you'll find at htcdev.com ...

Boot image tools - https://github.com/sakindia123/boot-image-tools

The toolchain, you can get from here - http://www.github.com/sakindia123/android_toolchains

Once you download everything, extract it someplace.. Now, in terminal, do :
Code:
gedit .bashrc
And add(at the end) :
Code:
export PATH=${PATH}:path/to/toolchain/folder/arm-eabi-4.4.3/bin
export PATH=${PATH}:path/to/bootimagetools/folder/tools
Now close and re-open the terminal, and you're all set to compile..

-----------------------------------------------------------------------------

Now comes the fun part... Compiling the kernel...

This part I'm gonna describe in numbered steps... The path(assumed) I'm gonna take, is '~/android/kernel_source'.. And I'm assuming you are in the top of the kernel source directory...

1) You need to pull the kernel config from your phone.. To do that, connect your phone using ADB, and run :
Code:
adb pull proc/config.gz ~/android/kernel_source
2) Next, you need to extract the kernel config from the compressed file..
Code:
zcat config.gz > .config
3) Now, we have the .config file directly, so we can omit the "defconfig" command..

3a) If you wanna run the defconfig, then omit steps 1 and 2, and instead run :
Code:
make ARCH=arm CROSS_COMPILE=arm-eabi- msm7627a_defconfig  ---> For Sense kernel

make ARCH=arm CROSS_COMPILE=arm-eabi- htc_pico_defconfig ----> For lirokoa's and flowish's kernel source

make ARCH=arm CROSS_COMPILE=arm-eabi- pico_defconfig -----> For 3.0.16 kernel..
4) Now, we run the main compiling command :
Code:
make ARCH=arm CROSS_COMPILE=arm-eabi- -jX
The X can be replaced by the maximum number of jobs your computer can handle simultaneously.. The higher this number, the faster the compiling will get.. But do not enter a number too high, your computer may explode due to overheating.. Wouldnt want that, would we??

5) If all goes well, at the end of 15-mins to 1 hour(depending on your PC hardware), you'll have a zImage...

6) Now, we create a working directory :
Code:
mkdir workspace
7) Next, we copy our zImage to the working directory :
Code:
cp arch/arm/boot/zImage workspace
8) Next up, modules..
Code:
find . -name '*ko' -exec cp '{}' workspace \;
9) Now, we take a working boot.img from a ROM zip.. We do this for the ramdisk.. But keep in mind that different ROMs have different ramdisks.. For eg, a kernel made with CM9 ramdisk will not work on CM10.. So take the boot.img from the ROM you wanna use the kernel on..

10) We unpack the boot.img :
Code:
unpackbootimg -i boot.img
When we do this, we'll get a lot of files.. We only need the file named 'boot.img-ramdisk.gz'..

11) Finally, we make a new boot.img file, which will incorporate our compiled zImage, and the ramdisk we just extracted..
Code:
mkbootimg --kernel zImage --ramdisk boot.img-ramdisk.gz --cmdline no_console_suspend=1-console=null --base 12c00000 --output boot-new.img
And Voila!! We have a freshly compiled kernel, 'boot-new.img'..

12) To use it, put your phone in fastboot mode, and run :
Code:
fastboot flash boot boot-new.img
13) Now do not reboot the phone... Boot the phone in recovery mode, mount system from the recovery, connect the phone to PC, and then run :
Code:
$ adb remount

$ adb push '*ko' system/lib/modules ----> run this from the directory where you copied all the modules

$ adb reboot
And there you have it, your very own kernel..

----------------------------------------------------------------

Ok.. Sometimes you may get weird errors when trying to connect your phone to your computer via ADB... Its mostly a permission problem.. Fortunately, instead of running ADB as root, we have another solution..

Fire up a terminal, and type :
Code:
$ sudo gedit /etc/udev/rules.d/51-android.rules
A file will open up.. Add the following content into that file and save it :
Code:
###################################################### 
#  Project:  http://code.google.com/p/51-android/    #
#  File:     /etc/udev/rules.d/51-android.rules      #
#  Author:   snowdream     #
#  Date:     2010.06.07                              #
######################################################

#Acer
SUBSYSTEM=="usb", ATTRS{idVendor}=="0502", MODE="0660", OWNER="snowdream"


#ASUS
SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", MODE="0660", OWNER="snowdream"


#Dell
SUBSYSTEM=="usb", ATTRS{idVendor}=="413", MODE="0660", OWNER="snowdream"


#Foxconn
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", MODE="0660", OWNER="snowdream"


#Fujitsu/Fujitsu Toshiba
SUBSYSTEM=="usb", ATTRS{idVendor}=="04c5", MODE="0660", OWNER="snowdream"


#Garmin-Asus
SUBSYSTEM=="usb", ATTRS{idVendor}=="091e", MODE="0660", OWNER="snowdream"


#Google
SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", MODE="0660", OWNER="snowdream"


#Hisense
SUBSYSTEM=="usb", ATTRS{idVendor}=="109b", MODE="0660", OWNER="snowdream"

#HTC
SUBSYSTEM=="usb", ATTRS{idVendor}=="0bb4", MODE="0660", OWNER="snowdream"

#HTC HERO


#Huawei
SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0660", OWNER="snowdream"


#K-Touch
SUBSYSTEM=="usb", ATTRS{idVendor}=="24e3", MODE="0660", OWNER="snowdream"


#KT Tech
SUBSYSTEM=="usb", ATTRS{idVendor}=="2116", MODE="0660", OWNER="snowdream"


#Kyocera
SUBSYSTEM=="usb", ATTRS{idVendor}=="0482", MODE="0660", OWNER="snowdream"


#Lenovo
SUBSYSTEM=="usb", ATTRS{idVendor}=="2006", MODE="0660", OWNER="snowdream"


#LG
SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", MODE="0660", OWNER="snowdream"


#Motorola
SUBSYSTEM=="usb", ATTRS{idVendor}=="22b8", MODE="0660", OWNER="snowdream"


#NEC
SUBSYSTEM=="usb", ATTRS{idVendor}=="0409", MODE="0660", OWNER="snowdream"


#Nook
SUBSYSTEM=="usb", ATTRS{idVendor}=="2080", MODE="0660", OWNER="snowdream"


#Nvidia
SUBSYSTEM=="usb", ATTRS{idVendor}=="0955", MODE="0660", OWNER="snowdream"


#OTGV
SUBSYSTEM=="usb", ATTRS{idVendor}=="2257", MODE="0660", OWNER="snowdream"


#Pantech
SUBSYSTEM=="usb", ATTRS{idVendor}=="10a9", MODE="0660", OWNER="snowdream"


#Pegatron
SUBSYSTEM=="usb", ATTRS{idVendor}=="1d4d", MODE="0660", OWNER="snowdream"


#Philips
SUBSYSTEM=="usb", ATTRS{idVendor}=="0471", MODE="0660", OWNER="snowdream"


#PMC-Sierra
SUBSYSTEM=="usb", ATTRS{idVendor}=="04da", MODE="0660", OWNER="snowdream"


#Qualcomm
SUBSYSTEM=="usb", ATTRS{idVendor}=="05c6", MODE="0660", OWNER="snowdream"


#SK Telesys
SUBSYSTEM=="usb", ATTRS{idVendor}=="1f53", MODE="0660", OWNER="snowdream"


#Samsung
SUBSYSTEM=="usb", ATTRS{idVendor}=="04e8", MODE="0660", OWNER="snowdream"


#Sharp
SUBSYSTEM=="usb", ATTRS{idVendor}=="04dd", MODE="0660", OWNER="snowdream"


#Sony
SUBSYSTEM=="usb", ATTRS{idVendor}=="054c", MODE="0660", OWNER="snowdream"


#Sony Ericsson
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fce", MODE="0660", OWNER="snowdream"


#Teleepoch
SUBSYSTEM=="usb", ATTRS{idVendor}=="2340", MODE="0660", OWNER="snowdream"


#Toshiba
SUBSYSTEM=="usb", ATTRS{idVendor}=="0930", MODE="0660", OWNER="snowdream"


#ZTE
SUBSYSTEM=="usb", ATTRS{idVendor}=="19d2", MODE="0660", OWNER="snowdream"
Note : Replace "snowdream" with your username.. Keep the double quotes..

Now, we need to give executing permissions to this file.. So :
Code:
$ sudo chmod a+r /etc/udev/rules.d/51-android.rules

$ sudo service udev restart
And this will solve the permission problem when connecting through ADB or FASTBOOT...
The Following 54 Users Say Thank You to #define For This Useful Post: [ View ] Gift #define Ad-Free
 
 
24th January 2013, 03:01 AM |#2  
chikanchilly's Avatar
Senior Member
Flag Mumbai
Thanks Meter: 181
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
I recommend android ndk for toolchain. Its better

Sent from my potato with a microchip
24th January 2013, 06:29 AM |#3  
#define's Avatar
OP Senior Member
Thanks Meter: 2,203
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
Quote:
Originally Posted by gautzzzy

I recommend android ndk for toolchain. Its better

Sent from my potato with a microchip

Whatever works for you bro...

Sent from my HTC Explorer A310e using Tapatalk 2
The Following 4 Users Say Thank You to #define For This Useful Post: [ View ] Gift #define Ad-Free
24th January 2013, 06:31 AM |#4  
Red Devil's Avatar
Senior Member
Flag Mumbai
Thanks Meter: 2,552
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
Thanks .. sorry limited to 8 thanks . Lol wtf. Good guide bro.

Sent from my HTC Explorer A310e using xda app-developers app
The Following 2 Users Say Thank You to Red Devil For This Useful Post: [ View ] Gift Red Devil Ad-Free
24th January 2013, 06:35 AM |#5  
Neel.Aryan's Avatar
Senior Member
Flag Kolkata
Thanks Meter: 33
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
In ubuntu 12.10, folks might face problem (as i faced) while typing adb commands. It might say, "No permission for this device."
Or, when someone types, adb devices, it might say...
Quote:

List of attached devices
???????? No Permissions

Required to add rules to get past this issue.

Sent from my HTC Explorer A310e using xda app-developers app
The Following User Says Thank You to Neel.Aryan For This Useful Post: [ View ] Gift Neel.Aryan Ad-Free
24th January 2013, 06:36 AM |#6  
#define's Avatar
OP Senior Member
Thanks Meter: 2,203
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
Quote:
Originally Posted by akshat.shenoy

Thanks .. sorry limited to 8 thanks . Lol wtf. Good guide bro.

Sent from my HTC Explorer A310e using xda app-developers app

Thank you.. thanks meter aint important bro... dont worry...
PS : The xda mobile app isnt limited to 8 thanks...

Sent from my HTC Explorer A310e using Tapatalk 2
24th January 2013, 07:24 AM |#7  
#define's Avatar
OP Senior Member
Thanks Meter: 2,203
 
More
Quote:
Originally Posted by Neel.Aryan

In ubuntu 12.10, folks might face problem (as i faced) while typing adb commands. It might say, "No permission for this device."
Or, when someone types, adb devices, it might say...


Required to add rules to get past this issue.

Sent from my HTC Explorer A310e using xda app-developers app

Damn.. How did i miss that?? Updating... Thanks...
24th January 2013, 07:39 AM |#8  
Nihar.G's Avatar
Senior Member
Flag Pune
Thanks Meter: 1,199
 
More
Nice! Very easy to understand. Good Job
The Following User Says Thank You to Nihar.G For This Useful Post: [ View ] Gift Nihar.G Ad-Free
24th January 2013, 09:04 AM |#9  
Red Devil's Avatar
Senior Member
Flag Mumbai
Thanks Meter: 2,552
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
Oh really ?It comes action failed contact forum administrator...
Oops sorry for spam..
BTW 12.10 Ubuntu .. and other platforms ? What some other examples?

Oh crap my bad had already thanked .
Sent from my HTC Explorer A310e using xda app-developers app
24th January 2013, 09:52 AM |#10  
#define's Avatar
OP Senior Member
Thanks Meter: 2,203
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
Quote:
Originally Posted by akshat.shenoy

Oh really ?It comes action failed contact forum administrator...
Oops sorry for spam..
BTW 12.10 Ubuntu .. and other platforms ? What some other examples?

Oh crap my bad had already thanked .
Sent from my HTC Explorer A310e using xda app-developers app

Lots... arch linux, bbq linux, mint, fedora, older versions of ubuntu, such as 10.04, 11.10, 12.04, etc...
Mac os can compile upto lion... i havent found anything for mountain lion...

Sent from my HTC Explorer A310e
The Following User Says Thank You to #define For This Useful Post: [ View ] Gift #define Ad-Free
24th January 2013, 10:07 AM |#11  
Neel.Aryan's Avatar
Senior Member
Flag Kolkata
Thanks Meter: 33
 
More
Re: [HOWTO][SIMPLER]Compile your own kernel from source
I wrote the udev rules 4 times.
For...
Quote:

#Normal Blade
#Debug Blade
#Recovery Blade
#Fastboot Blade

And, also, i put MODE="0666".

Difference ?

Sent from my HTC Explorer A310e using xda app-developers app
Post Reply Subscribe to Thread

Tags
howto, kernel, pico, pico-kernel

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes