HOWTO: Compile your own kernel from source (WIP)

Search This thread

adrynalyne

Inactive Recognized Developer
Dec 13, 2008
10,950
6,471
Updated. You can find an easier to use and more up to date version here:

http://rootzwiki.com/topic/8824-howto-compile-your-own-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-Kitchen/archives/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/394529815/HikaRi_toolchain_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:

tgallant21

Senior Member
Jan 3, 2011
61
6
Jenison
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
 

jaskru

Senior Member
May 23, 2010
145
14
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:

52brandon

Senior Member
Feb 3, 2010
615
75
awesome. I love the android community's open-ness. Not only do you post your source, but you tell people how to use it...
 

happimeal

Senior Member
Mar 16, 2011
272
30
50
Manteca
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!!!
 
  • Like
Reactions: Ghostfreak NB

UPEngineer

Senior Member
Sep 22, 2010
67
10
Chickasha, OK
Uggg, I am running Ubuntu 10.10 64bit.

I have followed this step by step but I am getting the following error:

/home/scott/android/4.4.4/bin/../libexec/gcc/arm-none-eabi/4.4.4/cc1: error while loading shared libraries: libcloog.so.0: cannot open shared object file: No such file or directory
make[2]: *** [scripts/mod/empty.o] Error 1
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2
make: INTERNAL: Exiting with 3 jobserver tokens available; should be 2!

What package am I missing? I apt-get installed libcloog-ppl0.

Any help is appreciated.
Scott
 

adrynalyne

Inactive Recognized Developer
Dec 13, 2008
10,950
6,471
Uggg, I am running Ubuntu 10.10 64bit.

I have followed this step by step but I am getting the following error:

/home/scott/android/4.4.4/bin/../libexec/gcc/arm-none-eabi/4.4.4/cc1: error while loading shared libraries: libcloog.so.0: cannot open shared object file: No such file or directory
make[2]: *** [scripts/mod/empty.o] Error 1
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2
make: INTERNAL: Exiting with 3 jobserver tokens available; should be 2!

What package am I missing? I apt-get installed libcloog-ppl0.

Any help is appreciated.
Scott

Go to /usr/lib and tell me what the name of libcloog.so.? Is. There are bound to be growing pains with this, as I originally used Fedora 64 bit when I did this. Still, its doable on Ubuntu, because I have this same toolchain on Arch as well.

Let me know what the name of that file is. I will help all I can.

Sent from my ADR6400L using XDA App
 
Last edited:
  • Like
Reactions: juanpirulo

UPEngineer

Senior Member
Sep 22, 2010
67
10
Chickasha, OK
Go to /usr/lib and tell me what the name of libcloog.so.? Is.

Sent from my ADR6400L using XDA App

Adrynalyne,

In my /usr/lib I have the following libcloog files:

libcloog.a
libcloog.so
libcloog-debian.a
libcloog-debian.so
libcloog-debian.so.0
libcloog-debian.so.0.0.0
libcloog-ppl.a
libcloog-ppl.so
libcloog-ppl.so.0

Hope this helps.... It has been a long time since I messed with Linux :)

Again, I am Ubuntu 10.10 64bit

Thanks again.
 

adrynalyne

Inactive Recognized Developer
Dec 13, 2008
10,950
6,471
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
 

happimeal

Senior Member
Mar 16, 2011
272
30
50
Manteca
Trying to run kitchen , when trying to setup working folder it doesnt appear to do anything, I hit 1 and it just sits there. I hit 0 for advanced options and it just sits there.

I have a rom in the right folder as a zip and extracted.


edit: guess you cant extract in windows and copy the files over :).
 
Last edited:

adrynalyne

Inactive Recognized Developer
Dec 13, 2008
10,950
6,471
Trying to run kitchen , when trying to setup working folder it doesnt appear to do anything, I hit 1 and it just sits there. I hit 0 for advanced options and it just sits there.

I have a rom in the right folder as a zip and extracted.

Thanks

You arent supposed to extract the rom. The kitchen needs to.
 

happimeal

Senior Member
Mar 16, 2011
272
30
50
Manteca
Yes..

all the way to the make and got some errors

/home/jroncalli/android/4.4.4/bin/arm-none-eabi-gcc: 1: ELF: not found
/home/jroncalli/android/4.4.4/bin/arm-none-eabi-gcc: 2: @: not found
/home/jroncalli/android/4.4.4/bin/arm-none-eabi-gcc: 3: Syntax error: ")" unexpected
CHK include/linux/version.h
SYMLINK include/asm -> include/asm-arm
make[1]: `include/asm-arm/mach-types.h' is up to date.
CHK include/linux/utsrelease.h
CC scripts/mod/empty.o
/home/jroncalli/android/4.4.4/bin/arm-none-eabi-gcc: 1: ELF: not found
/home/jroncalli/android/4.4.4/bin/arm-none-eabi-gcc: 2: @: not found
/home/jroncalli/android/4.4.4/bin/arm-none-eabi-gcc: 3: Syntax error: ")" unexpected
make[2]: *** [scripts/mod/empty.o] Error 2
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2


Any ideas.
 

adrynalyne

Inactive Recognized Developer
Dec 13, 2008
10,950
6,471
You need the lib32 stuff installed for Ubuntu. Not sure why, as its a 64 bit toolchain. I'm using full 64 bit Arch Linux and don't need to.
 
Last edited:

DS36

Senior Member
Apr 4, 2010
2,081
28
Florida
Where was this guide all weekend lol
been waiting for this thanks bro

now if only i can find a guide to creating flashable .zips hmm


Sent from my ADR6400L using XDA Premium App
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 58
    Updated. You can find an easier to use and more up to date version here:

    http://rootzwiki.com/topic/8824-howto-compile-your-own-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-Kitchen/archives/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/394529815/HikaRi_toolchain_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
    1
    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!!!
    1
    Uggg, I am running Ubuntu 10.10 64bit.

    I have followed this step by step but I am getting the following error:

    /home/scott/android/4.4.4/bin/../libexec/gcc/arm-none-eabi/4.4.4/cc1: error while loading shared libraries: libcloog.so.0: cannot open shared object file: No such file or directory
    make[2]: *** [scripts/mod/empty.o] Error 1
    make[1]: *** [scripts/mod] Error 2
    make: *** [scripts] Error 2
    make: INTERNAL: Exiting with 3 jobserver tokens available; should be 2!

    What package am I missing? I apt-get installed libcloog-ppl0.

    Any help is appreciated.
    Scott

    Go to /usr/lib and tell me what the name of libcloog.so.? Is. There are bound to be growing pains with this, as I originally used Fedora 64 bit when I did this. Still, its doable on Ubuntu, because I have this same toolchain on Arch as well.

    Let me know what the name of that file is. I will help all I can.

    Sent from my ADR6400L using XDA App
    1
    1.) What do you mean by taking any rom? Where can I get this from and what does the file look like (i.e. file extension, etc..)
    2.) What is the working folder
    SOrry for my ignorance - I am new to this.

    Cheers

    Raj

    1)Just copy any rom's xxxxx.zip file to the ~/android/kitchen/original_update directory. You have probably downloaded some from this forum.

    2) the working folder is the folder that is created after you run the ./menu and select number 1 - it will setup a new folder named kitchen_something.

    HTH.