HOWTO: Compile your own kernel from source (WIP)

Search This thread

HarshOne

Senior Member
Feb 20, 2017
52
3
Google Pixel 6
My device repositories are not available on github, But I got device tree and vendor blobs by making changes in similar device repo. That reference device's kernel's lineageos_defconfig is situated in htc msm8974 kernel repo. So how can I get lineageos_defconfig for my device, and which other my device related kernel files(.dtsi or any other) I have to push in htc msm8974 repo and get those files to make things ready for build?
Please help......
 

twilighttony

Senior Member
Dec 14, 2014
178
340
ZTE Axon 7
My device repositories are not available on github, But I got device tree and vendor blobs by making changes in similar device repo. That reference device's kernel's lineageos_defconfig is situated in htc msm8974 kernel repo. So how can I get lineageos_defconfig for my device, and which other my device related kernel files(.dtsi or any other) I have to push in htc msm8974 repo and get those files to make things ready for build?
Please help......

did you figure this out? i'd like to know as well since i am making a device tree for a device and will need that once i get the tree finished.
 

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.