[GUIDE] Build Your Own Android Kernel{Easiest and Fastest Way] [Using The NDK]

Search This thread

D1stRU3T0R

Senior Member
Oct 16, 2016
3,412
1,791
24
Huawei P8lite/P8 Lite
LeEco Le Pro3
Hi! A nice guide!
Hey there i have a question.
I do have a device with chipset Mediatek MT6580 and a kernel 3.18.19 running Android Marshmallow 6.0.1.
Iwanna boot Android Nougat on this same device, where Android Nougat kernel version is 3.18.35!
So what file do i need to replace or edit to upgrade from Marshmallow to Nougat, to make my device boot Nougat.
Please help me out!

If I'm not wrong, you will have that kernel after you update to nougat automatically...
 
  • Like
Reactions: Sands207

HoldMySoul69

Account currently disabled
Jun 24, 2017
821
197
25
Usa
cutt.ly
Huawei P8lite/P8 Lite
This is the quickest and easiest way to build your own Kernel using the Android NDK

Note:I will be reffering to the following


Note:I am only showing you how to make it to be flashed via CWM. If you wan't a tuttorial on how to make a boot.img comment and i will make it.

What you will need


Step 1:Installing the required files

Open a terminal and type the following (copy-paste)
Code:
sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
This will install the packages you need

Download the kernel source code for your device (This is important. We are going to build the kernel from this)

Find your device and click Download

Download The NDK

Move the NDK and your device Kernel source code in your home folder
Extract both the NDK and your kernel source code
Rename the folder were you have the NDK installed to NDK. And rename the folder where you have the kernel installed to Kernel

Now we are ready to build.

Step 2:Tweaking the kernel

Navigate to the kernel folder
Code:
cd /home/[COLOR="red"]yourusername[/COLOR]/Kernel

Next we need to point the NDK tools to the kernel folder
Code:
export CROSS_COMPILE=/home/[COLOR="red"]yourusername[/COLOR]/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-

We've pointed the NDK tolls and now we can use the NDK to tweak the kernel

Next we need to clean the previous work just incase:
Code:
make clean && make mrproper

If everything goes well you are good to go. If you have an Error(s) then something is wrong.

Now we are ready.
Next we need to add the kernel features to the NDK so we can modife them
Firs open your kernel source code folder go to arch/arm/configs
Here you will all the configs.
We need only one. Find that. It is called:Yourdevicecode_somethingbalblabla.defconfig
Rename it to maker.defconfig
Now type this in your terminal
Code:
make maker.defconfig

Now we need to tweak those configs.
Code:
make menuconfig
A user interface will pop out showing you all the tweaks you can do. I am not going to show you whow to use it. Google it(Sorry don't have that enough space)
When you are ready close the UI and click SAVE

Step 3 Building
So we tweaked the Kernel and we are ready to build.

Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type
Code:
make -j5 ARCH=arm
This will build the Kernel. It will take about 10 minutes.

Step 4: Finalizing
Now that kernel is ready you will need to find a kernel flashable zip for your device(Just google it)
Download the zip file and leave it in your home folder.

Now got to your kernel source and go to arch/arm/boot and copy zImage
Paste your Zimage to the zip file and replace it.

Now we need the WI-FI modules otherwise your WI-FI will not be working
Go to the Kernel source code folder and go to driver/net/wireless/bcm4329_204 and copy bcm4329.ko
Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko

You are ready all you need to do is flash it.
Do You Think can i make kernel on Linux emulator? Like Linux Debian? (It is for Android)
 

shr!pad

Senior Member
Nov 2, 2017
124
75
Bangalore
it stuck at this point,,pls help how to solve!??
shripad@shripad ~/Desktop/kernel/moto-c $ make clean && make mrproper
./scripts/gcc-goto.sh: line 4: $'\r': command not found
./scripts/gcc-goto.sh: line 21: warning: here-document at line 5 delimited by end-of-file (wanted `END')
./scripts/Makefile.clean:17: drivers/misc/mediatek/base/power/mt2701_dcm/Makefile: No such file or directory
make[6]: *** No rule to make target `drivers/misc/mediatek/base/power/mt2701_dcm/Makefile'. Stop.
make[5]: *** [drivers/misc/mediatek/base/power/mt2701_dcm] Error 2
make[4]: *** [drivers/misc/mediatek/base/power] Error 2
make[3]: *** [drivers/misc/mediatek/base] Error 2
make[2]: *** [drivers/misc/mediatek] Error 2
make[1]: *** [drivers/misc] Error 2
make: *** [_clean_drivers] Error 2
 

0theus

New member
Jun 3, 2018
1
0
Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type
Code:
make -j5 ARCH=arm
*facepalm* the -j option specifies how many jobs to start on the *compiler* and should be about the number of CPUs you have on your compiling workstation, not your "device". (If you are in a VM, it should be the number of virtual CPUs you have allocated to the VM. If you've got other stuff running, use n-1).

---------- Post added at 05:53 AM ---------- Previous post was at 05:47 AM ----------

it stuck at this point,,pls help how to solve!??
shripad@shripad ~/Desktop/kernel/moto-c $ make clean && make mrproper
./scripts/gcc-goto.sh: line 4: $'\r': command not found
./scripts/gcc-goto.sh: line 21: warning: here-document at line 5 delimited by end-of-file (wanted `END')
./scripts/Makefile.clean:17: drivers/misc/mediatek/base/power/mt2701_dcm/Makefile: No such file or directory
make[6]: *** No rule to make target `drivers/misc/mediatek/base/power/mt2701_dcm/Makefile'. Stop.
make[5]: *** [drivers/misc/mediatek/base/power/mt2701_dcm] Error 2
make[4]: *** [drivers/misc/mediatek/base/power] Error 2
make[3]: *** [drivers/misc/mediatek/base] Error 2
make[2]: *** [drivers/misc/mediatek] Error 2
make[1]: *** [drivers/misc] Error 2
make: *** [_clean_drivers] Error 2

Those drivers in "misc" are probably device-specific, meaning, from the manufacturer. According to the GPL, they are supposed to provide working code that can be used to build into an image. This is not "working code" (the "Makefile" may not be code to them, but it is for purposes of the GPL).

If you're lucky, you can resolve by converting the Makefile from windows-text file to unix-text file. Look for ways to convert "CRLF" to LF on your host. Usually this is simply
Code:
tr -d '\015' Makefile >Makefile.new && mv Makefile.new Makefile
[code]
See https://stackoverflow.com/a/802451 for explanation.
 

shr!pad

Senior Member
Nov 2, 2017
124
75
Bangalore
*facepalm* the -j option specifies how many jobs to start on the *compiler* and should be about the number of CPUs you have on your compiling workstation, not your "device". (If you are in a VM, it should be the number of virtual CPUs you have allocated to the VM. If you've got other stuff running, use n-1).

---------- Post added at 05:53 AM ---------- Previous post was at 05:47 AM ----------



Those drivers in "misc" are probably device-specific, meaning, from the manufacturer. According to the GPL, they are supposed to provide working code that can be used to build into an image. This is not "working code" (the "Makefile" may not be code to them, but it is for purposes of the GPL).

If you're lucky, you can resolve by converting the Makefile from windows-text file to unix-text file. Look for ways to convert "CRLF" to LF on your host. Usually this is simply
Code:
tr -d '\015' Makefile >Makefile.new && mv Makefile.new Makefile
[code]
See https://stackoverflow.com/a/802451 for explanation.[/QUOTE]

ok thank you
 

xswapsx

Member
Apr 13, 2013
9
0
Mumbai, Nagpur
I am not able to find my device_code.defconfig file in config folder of the source

The device specific defconfig file is not present in the config folder (kernel/arch/arm64/config) of the kernel source, please guide me what to do??
 
Last edited:

Lieta

Member
Dec 22, 2013
14
4
Riga
Which NDK revision should I download, the latest or specific for my device? If the latter, then how do I find out which?
 

Top Liked Posts

  • There are no posts matching your filters.
  • 78
    This is the quickest and easiest way to build your own Kernel using the Android NDK

    Note:I will be reffering to the following
    yourusername=the username that you are logged in to
    devicecode=The codename for the device you are building a kernel for(Google it on what is the code name

    Note:I am only showing you how to make it to be flashed via CWM. If you wan't a tuttorial on how to make a boot.img comment and i will make it.

    What you will need
    Ubuntu 12.04 or newer
    A lot of patience

    Step 1:Installing the required files

    Open a terminal and type the following (copy-paste)
    Code:
    sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
    This will install the packages you need

    Download the kernel source code for your device (This is important. We are going to build the kernel from this)
    Find your device and click Download

    Download The NDK

    Move the NDK and your device Kernel source code in your home folder
    Extract both the NDK and your kernel source code
    Rename the folder were you have the NDK installed to NDK. And rename the folder where you have the kernel installed to Kernel

    Now we are ready to build.

    Step 2:Tweaking the kernel

    Navigate to the kernel folder
    Code:
    cd /home/[COLOR="red"]yourusername[/COLOR]/Kernel

    Next we need to point the NDK tools to the kernel folder
    Code:
    export CROSS_COMPILE=/home/[COLOR="red"]yourusername[/COLOR]/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-

    We've pointed the NDK tolls and now we can use the NDK to tweak the kernel

    Next we need to clean the previous work just incase:
    Code:
    make clean && make mrproper

    If everything goes well you are good to go. If you have an Error(s) then something is wrong.

    Now we are ready.
    Next we need to add the kernel features to the NDK so we can modife them
    Firs open your kernel source code folder go to arch/arm/configs
    Here you will all the configs.
    We need only one. Find that. It is called:Yourdevicecode_somethingbalblabla.defconfig
    Rename it to maker.defconfig
    Now type this in your terminal
    Code:
    make maker.defconfig

    Now we need to tweak those configs.
    Code:
    make menuconfig
    A user interface will pop out showing you all the tweaks you can do. I am not going to show you whow to use it. Google it(Sorry don't have that enough space)
    When you are ready close the UI and click SAVE

    Step 3 Building
    So we tweaked the Kernel and we are ready to build.
    Note:The # means the number of CPU cores +1. For example my device has a quad core CPU and I will type
    Code:
    make -j5 ARCH=arm
    This will build the Kernel. It will take about 10 minutes.

    Step 4: Finalizing
    Now that kernel is ready you will need to find a kernel flashable zip for your device(Just google it)
    Download the zip file and leave it in your home folder.

    Now got to your kernel source and go to arch/arm/boot and copy zImage
    Paste your Zimage to the zip file and replace it.

    Now we need the WI-FI modules otherwise your WI-FI will not be working
    Go to the Kernel source code folder and go to driver/net/wireless/bcm4329_204 and copy bcm4329.ko
    Got the zip file go to the System folder and replace it's bcm4329.ko with your bcm4329.ko

    You are ready all you need to do is flash it.
    3
    mmm..interesting...i always build without the ndk,but simpy sdk.what's the advantages?
    and i usually do the git clone to download all the sources,in my case nexus7 and maguro.
    thanks for this!

    What are you building? If a whole ROM like AOSP,AOKP,PA or CM then they typically bundle the toolchain/kernel with the source, making this totally unneeded.

    ---------- Post added at 12:18 PM ---------- Previous post was at 12:17 PM ----------

    Sorry if this is a stupid question but do we need 64 bit like we do for ROM compiling, or will this work fine for 32 bit (I'm running Ubuntu 12.10 32 bit). Also, roughly how much is there to download? Thanks :)

    No 32-bit is fine, just install the right libraries. I actually believe that you can compile a ROM on 32-bit as well.

    Self-Plug http://xdaforums.com/showthread.php?t=1748297
    2
    Thanks, do you know how large all the files are once installed on the system (you might have guessed I'm slightly short of space atm)
    About 700 MB
    1
    mmm..interesting...i always build without the ndk,but simpy sdk.what's the advantages?
    and i usually do the git clone to download all the sources,in my case nexus7 and maguro.
    thanks for this!
    1
    :good: Thanks! I'm use Ubuntu 10.04 64 bit don't know if can?