Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

HOWTO: Compile your own kernel from source (WIP)

OP adrynalyne

18th April 2011, 05:06 AM   |  #1  
adrynalyne's Avatar
OP Recognized Developer
Thanks Meter: 5,762
 
9,774 posts
Join Date:Joined: Dec 2008
Updated. You can find an easier to use and more up to date version here:

http://rootzwiki.com/topic/8824-howt...n-kernel-v-01/





Hey folks,

Figured I would throw this out there for those who may want to know just what goes into compiling a kernel, and possibly, doing it themselves. This is a WIP, and is more about how to compile, than how to make changes to source or customize your own kernel.

Needed:


Linux. For this case, we will assume Ubuntu 10.10, 64 bit. This can be done with 32 bit as well, but you will need a different cross compiler.
Download | Ubuntu

dsixda's kitchen. So that we can easily split and repack kernels.
https://github.com/dsixda/Android-Ki...rchives/master

Source. You can use mine. Its fairly heavily tweaked, and compiles without any modifcations.
https://github.com/adrynalyne/kernel_htc-mecha

A cross compiler toolchain. Because I use 64 bit linux, I use a 64 bit cross compiler.
http://rapidshare.com/files/39452981...ain_4.4.4.tbz2
(Credit adwinp from XDA)



Introduction

First, we install Ubuntu. I won't be going through that, however. So, assuming we have Ubuntu already installed, and working, we are ready to dive right in.

First, we need a tool Ubuntu does not install by default. This is called git. From a terminal:

Getting Source Code
sudo apt-get install git

Once git is installed, we can grab our source. Using a terminal:

[chaos@oblivion ~]$

code
Code:
mkdir android
cd android
mkdir kernels
cd kernels
git clone git://github.com/adrynalyne/kernel_htc-mecha.git
Depending on your connection, this could take a while.

This will create a kernel_htc-mecha directory under your /home/username/android/kernels folder.


Grabbing Toolchain
Now we will grab the toolchain. Download it, decompress it, and just leave it in the 4.4.4 directory. Move it to your android directory.

Grabbing and setting up the kitchen
Download the kitchen from the link given above, and decompress it. Rename it to kitchen. Move it to your android directory. Then from a terminal:

code
Code:
cd ~/android/kitchen
chmod 755 menu
./menu
This installs the kitchen and starts it up. Now the first thing we need to do is setup a working directory. Take a rom, any rom, and copy it to the ogiinal_update folder inside the kitchen. You can then setup your working folder.

Inside the working folder, delete boot.img. Grab, one of say, my kernels, and extract it. Take boot.img from the extracted contents and copy to the kitchen.

To split the initramfs (ramdisk) from the kernel, simply choose 0 from the menu, then 20. Hitting w will extract the kernel to a BOOT-EXTRACTED directory inside the kitchen (not working folder). Inside that folder, you will find the ramdisk and a zImage. The zImage is the kernel. We will stop there for now.

Compiling the kernel
First, we move to the kernel directory.

code
Code:
cd ~/android/kernels/kernel_htc-mecha
To compile the kernel, first we must have a configuration file ready. To do this:

code
Code:
make mecha-lte_defconfig
It will configure the system for compiling.

Now to compile the kernel:

code

Code:
make -j5 ARCH=arm CROSS_COMPILE=/home/username/android/4.4.4/bin/arm-none-eabi-

Where username is your, well, username and the number after j (thats a J) is the number of cpus +1.


Depending on the speed of your system. a zImage should be created within 3-30 minutes.


Packing the kernel

The zImage will be located under ~/android/kernels/kernel_htc-mecha/arch/arm/boot directory.

We will copy that zImage into the BOOT-EXTRACTED directory of the kitchen. Then, back at our menu for the kitchen, we hit 'b' to build the kernel. Within seconds, there is a new boot.img inside our Working folder. Now, remember my kernel package you downloaded? Well, time to kang the installer! The directory you unzipped contains a META-INF and system directory. You need both of those. Copy the boot.img in with those two folders.

So, our directory layout currently looks like so:
META-INF
system
boot.img


We need one more file, the wifi driver, from our compiled source.

Under ~/android/kernels/kernel_htc-mecha/drivers/net/wireless/bcm4329_204 you will find a file named bcm4329.ko. Copy this into system/lib of your new kernels installer directory.

Zip these three folders and give it a name. Now its ready to install.

A couple of things of note:

You almost always have to match the wifi driver with the kernel.

make clean mrproper will clean all the precompiled and temp fikes out of your source. This is recommended when making major source changes. Don't forget to remake your configuration after running it though.


Troubleshooting

There may be some files not found errors. Please be careful with these commands.

If the files not found are libcloog.so.0 and/or libmpfr.so.1, take a look below.

Code:
sudo ln -s /usr/lib/libcloog-debian.so.0 /usr/lib/libcloog.so.0
sudo ln -s /usr/lib/libmpfr.so.4 /usr/lib/libmpfr.so.1
Last edited by adrynalyne; 4th November 2011 at 07:48 PM.
The Following 58 Users Say Thank You to adrynalyne For This Useful Post: [ View ]
18th April 2011, 05:10 AM   |  #2  
Member
Flag Jenison
Thanks Meter: 6
 
61 posts
Join Date:Joined: Jan 2011
More
Very nice write up, I've been looking into this for a while so its nice someone put it all together in one thread.

Sent from my NookColor using XDA Premium App
18th April 2011, 05:14 AM   |  #3  
Senior Member
Flag Aurora, CO
Thanks Meter: 7
 
397 posts
Join Date:Joined: Feb 2010
More
Nice Adrynalyne

Sent from my Thunderbolt using XDA Premium App
18th April 2011, 05:19 AM   |  #4  
jaskru's Avatar
Senior Member
Thanks Meter: 11
 
137 posts
Join Date:Joined: May 2010
More
I love learning new things... Thanks for sharing knowledge!

For those of us that play in a Virtual Box, any notes about issues that may come up? I used to dual boot but decided that a vb is more time efficient for me.
Last edited by jaskru; 18th April 2011 at 05:23 AM.
18th April 2011, 05:21 AM   |  #5  
Member
Thanks Meter: 5
 
48 posts
Join Date:Joined: Jul 2010
Thanks a lot, i was wondering about this too.

Sent from my ADR6400L using Tapatalk
18th April 2011, 05:27 AM   |  #6  
Jaxidian's Avatar
Senior Member
Flag Indianapolis
Thanks Meter: 221
 
719 posts
Join Date:Joined: Sep 2010
More
I'm really glad you've posted this. Time to play for those of us who are lazy (or busy)!
18th April 2011, 05:37 AM   |  #7  
Senior Member
Thanks Meter: 56
 
526 posts
Join Date:Joined: Feb 2010
awesome. I love the android community's open-ness. Not only do you post your source, but you tell people how to use it...
18th April 2011, 06:00 AM   |  #8  
happimeal's Avatar
Senior Member
Flag Lathrop
Thanks Meter: 19
 
239 posts
Join Date:Joined: Mar 2011
More
Thank you so much for spending the time to write this, i have been googleing this and your write up is the best ive found.

I know this is a work in progress, but some ideas for future revisions, at least things that I have been wondering,

The files tweaked for overclocking, undervolting, and maybe some explanations on what goes into this.

Important files and maybe files we should not touch, (if there are any).

Just things I have wondered.

Thank you again!!!
The Following User Says Thank You to happimeal For This Useful Post: [ View ]
18th April 2011, 06:18 AM   |  #9  
LexusBrian400's Avatar
Senior Member
Thanks Meter: 150
 
1,175 posts
Join Date:Joined: Mar 2010
More
Wow. Thank you for taking the time to write this up. Some of us really do appreciate it!
18th April 2011, 06:43 AM   |  #10  
Senior Member
Thanks Meter: 25
 
163 posts
Join Date:Joined: Mar 2011
You sir, are a gentleman and a scholar.

You really are amazing at what you do. Sometimes I wonder when you sleep..

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes