• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[GUIDE]Building a Kernel from source{Mediatek}

Search This thread

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
Guide to Mediatek Building(Guide 1:=Kernel)

Here, we'll be talking about how to build kernels and how they are different than the ones we've built for Qualcomm.

Requisites
A linux machine
Required Packages(Attached in 2nd post)
C programming and a knowledge about Makefiles
NDK


Lets begin,

Step 1(Setting up the build environment):=As always we have to set up the build environment so that the linux knows we are building something.
This is how we do it
Code:
export TARGET_BUILD_VARIANT=user TARGET_PRODUCT=devicename MTK_ROOT_CUSTOM=../mediatek/custom/ TARGET_KERNEL_VERSION=devicename &&export PATH=pathToDir/arm-eabi-4.6/bin:$PATH&&export CROSS_COMPILE=arm-eabi-&&export ARCH=arm

Let me explain what this does
The BUILD_VARIANT specifies what the kernel is going to be built for. A very good article i came across for explaining the build-variants is here.
The TARGET_PRODUCT/TARGET_KERNEL_PRODUCT tells the linux machine what "device specific" files to use
The MTK_ROOT_CUSTOM specifies the directory of the mediatek/custom folder. remember this mide be in the same directory as the kernel source as well.
The PATHThis sets your toolchain executables to your path. Download toolchain(preferably arm-eabi-4.6) Or, if you want to, you could build your own toolchain from source code
The CROSS_COMPILE, A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. The toolchain facilitates this function
ARCH=arm, ARM is a family of instruction set architectures for computer processors based on a reduced instruction set computing (RISC) architecture developed by British company ARM Holdings. ARM is also used in Android. Here by typing
Code:
export ARCH=arm
we are telling linux that we are going to be building for the CPU architecture "ARM".

Thats enough theory, lets get our hands dirty :cool:

Step 2(Configuring your kernel):=This is the heart to what your phone does so be careful when you do this if you're doubtful about something dont hesitate to ask me in the thread.. the base config is usually present in the kernel_source/mediatek/config/devicename/autoconfig/kconfig/platform. this is your base config which you will use and build with different requirments(Example:SELinux). You can always build a config from the start, I advice you dont do that until you have compiled a few kernels before. for using existing config as a base
Code:
cd kernel_source
cp mediatek/config/devicename/autoconfig/kconfig/platform .config
Now,
Code:
make menuconfig
This will give a graphical interface for you to choose what features you want to add to your phone(Example:I/O Schedule,CPU Governors..) More about this here. You're now ready for compiling

Step 3(Compiling):=This is the moment of truth; This is what youve been waiting for! Now, type
Code:
make zImage

You will get something which says
Code:
arch/arm/boot/zImage Ready

Step 4(Adding MediaTek headers):=[GUIDE]Building Mediatek boot.img{Appending headers}. This is my next guide, follow this to your way to compile a whole ROM for your phone.

Now, use your source code to build a ramdisk for you by typing make bootimage. in the out folder you'll get a folder called root. This folder is the initramfs or the ramdisk. to this follow my next guide to understand how to append mediatek headers


Code:
make modules

This is almost the most important step or your ROMS wont boot. after this is complete go to your sourcedir then in search type ".ko" you'll get a bunch of .ko files copy these to your device tree/ROM to make the rom to work.

If you're moving to a device tree make sure to add this to your device_makefile
Code:
PRODUCT_COPY_FILES += \
$(MOD_SRC)/ccci.ko:$(MOD_TGT)/ccci.ko \
$(MOD_SRC)/ccci_plat.ko:$(MOD_TGT)/ccci_plat.ko \
$(MOD_SRC)/devapc.ko:$(MOD_TGT)/devapc.ko \
$(MOD_SRC)/devinfo.ko:$(MOD_TGT)/devinfo.ko \
$(MOD_SRC)/mtk_fm_drv.ko:$(MOD_TGT)/mtk_fm_drv.ko \
$(MOD_SRC)/mtk_hif_sdio.ko:$(MOD_TGT)/mtk_hif_sdio.ko \
$(MOD_SRC)/mtk_stp_bt.ko:$(MOD_TGT)/mtk_stp_bt.ko \
$(MOD_SRC)/mtk_stp_gps.ko:$(MOD_TGT)/mtk_stp_gps.ko \
$(MOD_SRC)/mtk_stp_uart.ko:$(MOD_TGT)/mtk_stp_uart.ko \
$(MOD_SRC)/mtk_stp_wmt.ko:$(MOD_TGT)/mtk_stp_wmt.ko \
$(MOD_SRC)/mtk_wmt_wifi.ko:$(MOD_TGT)/mtk_wmt_wifi.ko \
$(MOD_SRC)/mtklfb.ko:$(MOD_TGT)/mtklfb.ko \
$(MOD_SRC)/pvrsrvkm.ko:$(MOD_TGT)/pvrsrvkm.ko \
$(MOD_SRC)/scsi_tgt.ko:$(MOD_TGT)/scsi_tgt.ko \
$(MOD_SRC)/scsi_wait_scan.ko:$(MOD_TGT)/scsi_wait_scan.ko \
$(MOD_SRC)/sec.ko:$(MOD_TGT)/sec.ko \
$(MOD_SRC)/vcodec_kernel_driver.ko:$(MOD_TGT)/vcodec_kernel_driver.ko \
$(MOD_SRC)/wlan_mt6628.ko:$(MOD_TGT)/wlan_mt6628.ko

This copies your custom built modules to the Module out folder. In BoardConfig.mk add
Code:
TARGET_PREBUILT_KERNEL := $(DEVICE_FOLDER)/prebuilt/kernel
..

Remember :If you're building kernel for already existing 4.2 roms disable SELINUX support by going into security options inside menuconfig

You're done!!

All Questions and feedbacks are welcome in the thread
Be sure to drop a thanks if you thought this was usefull

Happy Building.

--------------------------------------------------
Links to my next Guides
Building the boot.img{MediaTek}
Building the ROM{MediaTek}
 
Last edited:

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
Build Packages

Required packages before building



Python 2.6 -- 2.7, which you can download from python.org.

GNU Make 3.81 -- 3.82, which you can download from gnu.org,

JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both from java.sun.com.

Git 1.7 or newer. You can find it at git-scm.com.



#Required packages

Code:
sudo apt-get install git 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 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git-core lzop ccache gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python gcc g++ cpp gcc-4.8 g++-4.8 && sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

Go to etc/udev/rules.d/51-android.rules

Code:
# adb protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
# fastboot protocol on passion (Nexus One)
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
# adb protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
# fastboot protocol on crespo/crespo4g (Nexus S)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
# adb protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
# fastboot protocol on stingray/wingray (Xoom)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
# adb protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
# fastboot protocol on maguro/toro (Galaxy Nexus)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
# adb protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
# adb protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="<username>"
# fastboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
# usbboot protocol on panda (PandaBoard)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"
# usbboot protocol on panda (PandaBoard ES)
SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"
# adb protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="<username>"
# fastboot protocol on grouper/tilapia (Nexus 7)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="<username>"
# adb protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="<username>"
# fastboot protocol on manta (Nexus 10)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="<username>"




In bash.rc
Code:
export USE_CCACHE=1

Beter way installing java
Code:
sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update && sudo apt-get install oracle-java6-installer

Reuqired package check
Code:
sudo apt-get install git-core lzop ccache gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python gcc g++ cpp gcc-4.8 g++-4.8

THIS
Code:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so




You're done
 

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
@MasterAwesome this went a little bit over my head....:confused:

i understood till making zimage,,,,,after that how to make it a boot img...:confused:

After compiling the zImage, move it to your device tree in your source code. under a folder called prebuilts. Look at my git repo for more reference a210_device_tree. As i said add a flag in the BoardConfig.mk
Code:
TARGET_PREBUILT_KERNEL:=sourcetokernel
. then, we use the the PRODUCT_COPY_FILES to copy the kernel specific files. since modules are kernel specific you'd have to use the modules you built or you'll get a boot loop.
 

Santhosh M

Inactive Recognized Developer / Contributor
@MasterAwesome

Hello..Glad that someone has given a tutorial thread for Kernel developement. I have a few queries for which i am banging my head on for a while...Though i have used slightly diff commands from what u have said the following are my queries.

I tried building kernel for two Micromax devices A117 ( Used Blu life One M source ) & A250 ( Used Blu life One X source ). These are clone devices of Micromax

I personally own a Blu life One M & have booted the kernel succesfully from the source. But i am unable to boot it up in A117.

And i compiled Blu life One X source and tried in A250 and again i wasn't able to bootup. But another guy managed to boot it up in A250 from the same Blu life one X source. ( Proof : http://forum.xda-developers.com/showpost.php?p=50489380&postcount=300 ). On messaging him he said he hasn't made any change in source and just compiled and t booted for him. I wasn't able to get further support for him.

So what could be my mistake. If u can figure out the mistake for me i can boot it up in both Micromax devices. On analysing my logcat i see gpumodule failing !
 
  • Like
Reactions: Suhas P

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
@MasterAwesome

Hello..Glad that someone has given a tutorial thread for Kernel developement. I have a few queries for which i am banging my head on for a while...Though i have used slightly diff commands from what u have said the following are my queries.

I tried building kernel for two Micromax devices A117 ( Used Blu life One M source ) & A250 ( Used Blu life One X source ). These are clone devices of Micromax

I personally own a Blu life One M & have booted the kernel succesfully from the source. But i am unable to boot it up in A117.

And i compiled Blu life One X source and tried in A250 and again i wasn't able to bootup. But another guy managed to boot it up in A250 from the same Blu life one X source. ( Proof : http://forum.xda-developers.com/showpost.php?p=50489380&postcount=300 ). On messaging him he said he hasn't made any change in source and just compiled and t booted for him. I wasn't able to get further support for him.

So what could be my mistake. If u can figure out the mistake for me i can boot it up in both Micromax devices. On analysing my logcat i see gpumodule failing !

Common errors:
Appending the headers
Not adding newly built modules

If you've done both give me the link to the source I'll make a boot.img check it out on your phone.



Sent from my Moto G using XDA Free mobile app
 

Santhosh M

Inactive Recognized Developer / Contributor
Common errors:
Appending the headers
Not adding newly built modules

If you've done both give me the link to the source I'll make a boot.img check it out on your phone.



Sent from my Moto G using XDA Free mobile app

zImage Header patch i do always by placing the compiled zImage in mediatek/build/tools and using mkbuild to patch it.

I didn't get the second point of adding newly built modules? ( I use the modules generated while compiling )
 

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
zImage Header patch i do always by placing the compiled zImage in mediatek/build/tools and using mkbuild to patch it.

I didn't get the second point of adding newly built modules? ( I use the modules generated while compiling )

Do a arm-eabi-strip - - strip-unneeded *.ko then push the ko files to /system/lib/modules. Since modules are very kernel specific if you use wrong modules you'll get all sorts of errors.

Sent from my Moto G using XDA Free mobile app
 

Santhosh M

Inactive Recognized Developer / Contributor
How to do this bro ? If u explain me the commands in detail it would be helpful..

I have pm you the commands I use...Could you have a look at it?

( Without the above command it booted for me in Blu life One M. My concern s why it ain't booting in A117 & A250. A250 has been booted by a guy who used the same source )

Sent from my BLU LIFE ONE M using Tapatalk
 

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
How to do this bro ? If u explain me the commands in detail it would be helpful..

I have pm you the commands I use...Could you have a look at it?

( Without the above command it booted for me in Blu life One M. My concern s why it ain't booting in A117 & A250. A250 has been booted by a guy who used the same source )

Sent from my BLU LIFE ONE M using Tapatalk

There's your error, don't run make mediatek-Config. Copy the kconfig present in ../mediatek/Config/blue**/autoconfig/kconfig to your source dir as a .config file here edit the file. Using make menuconfig. Also make sure your files are correct if you cloned it from a git repo, do a git reset - - hard. Run a make clean and a make mrproper.

Explanation: using make mediatek-Config will bring in the mt6589 defaults; phones require a little more than that
and make sure to check my next guide on Appending headers or the boot.img don't work. Append headers both on ramdisk and kernel.

Warnjng:git reset - - hard will delete all changes you've made to the kernel source!



Regards and good luck.

Sent from my Moto G using XDA Free mobile app
 

Santhosh M

Inactive Recognized Developer / Contributor
No I didn't clone from git...I just downloaded source and compiled...I will compile by the method you said today night...
( In blu life one m it booted by make-mediatek config )

This is the link for kernel source http://forum.xda-developers.com/showthread.php?t=2650513&page=3

Post count no 24. Can u give a try ?

Sent from my BLU LIFE ONE M using Tapatalk
 

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
No I didn't clone from git...I just downloaded source and compiled...I will compile by the method you said today night...
( In blu life one m it booted by make-mediatek config )

This is the link for kernel source http://forum.xda-developers.com/showthread.php?t=2650513&page=3

Post count no 24. Can u give a try ?

Sent from my BLU LIFE ONE M using Tapatalk

I'm actually out for a vacation is it okay if I check by Friday? Sorry :/

Are you sure that blue life m and A117 and A250 all have the same specs. Each and every hardware?

Upload a dmesg I'll look at it and tell you what's wrong. Go to your recovery then type dmesg > /sdcard/dmesg.txt then upload it.

MasterAwesome.

Sent from my Moto G using XDA Free mobile app
 
Last edited:

Santhosh M

Inactive Recognized Developer / Contributor
Ya sure bro....Your time...I don't own both devices :D I just want to boot and build kernels for that devices

Yes bro...they are clones with ditto hardware and everything similar...Blu life one x s a clone of A250 and I had shown u the proof of the guy who had booted blu life one x source in A250...Similarly blu life one m s clone of A117.

I depend upon testers for these devices...Dmesg and kmesg I have for builds I made 2 months ago..That time my compilation methods were wrong and the tester at that time was able to give whatever I asked..

My recent build I have only log cat...My new tester says he isn't able to take dmesg and kmesg :(

Logcat s k ?

Sent from my BLU LIFE ONE M using Tapatalk
 

Dr-Shadow

Inactive Recognized Developer
Sep 15, 2013
454
560
NANTES
tip

Code:
cd kernel_source
cp mediatek/config/devicename/autoconfig/kconfig/platform .config
make mediatek-configs
is better instead of your command

why ? because mtk build scripts merge multiple config files (mediatek/config/devicename/autoconfig/kconfig/platform and mediatek/config/mt6589/autoconfig/kconfig/platform and some in mediatek/config/common/)

If you want to add features, just modify mediatek/config/devicename/autoconfig/kconfig/platform and/or mediatek/config/mt6589/autoconfig/kconfig/platform

simply copying is not advised

EDIT : This is maybe why you got some weird issues :/
 

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
make mediatek-configs
is better instead of your command

why ? because mtk build scripts merge multiple config files (mediatek/config/devicename/autoconfig/kconfig/platform and mediatek/config/mt6589/autoconfig/kconfig/platform and some in mediatek/config/common/)

If you want to add features, just modify mediatek/config/devicename/autoconfig/kconfig/platform and/or mediatek/config/mt6589/autoconfig/kconfig/platform

simply copying is not advised

EDIT : This is maybe why you got some weird issues :/

Typing a make command after you've set the target product does the same thing... Stop the build after it says .config written and I compared it. I got same .config.

I was asking him to disable selinux so I asked him the kconfig from the the devicename. But I automatically assume you're right always and shall follow your method henceforth. Thank you

MasterAwesome



Sent from my Moto G
 

Dr-Shadow

Inactive Recognized Developer
Sep 15, 2013
454
560
NANTES
Typing a make command after you've set the target product does the same thing... Stop the build after it says .config written and I compared it. I got same .config.

I was asking him to disable selinux so I asked him the kconfig from the the devicename. But I automatically assume you're right always and shall follow your method henceforth. Thank you

MasterAwesome



Sent from my Moto G

On which kernel source it gives same .config ?
 

Dr-Shadow

Inactive Recognized Developer
Sep 15, 2013
454
560
NANTES
Wiko stairway

Sent from my Moto G

This doesn't give same .config

rm .config && make mediatek-configs
diff mediatek-configs ../mediatek/config/wiko/autoconfig/kconfig/project

shows this diff :

http://pastebin.com/Ef7NyksD

Be carefull, ../mediatek/config/wiko/autoconfig/kconfig/project and ../mediatek/config/out/wiko/autoconfig/kconfig are different (the out is generated files from mtk scripts so kconfig is the result of merging project/platform files)
 
  • Like
Reactions: MasterAwesome

MasterAwesome

Recognized Developer
Jun 23, 2013
2,017
3,985
This doesn't give same .config

rm .config && make mediatek-configs
diff mediatek-configs ../mediatek/config/wiko/autoconfig/kconfig/project

shows this diff :

http://pastebin.com/Ef7NyksD

Be carefull, ../mediatek/config/wiko/autoconfig/kconfig/project and ../mediatek/config/out/wiko/autoconfig/kconfig are different (the out is generated files from mtk scripts so kconfig is the result of merging project/platform files)

Thank you.. Got it :)

Sent from my Moto G
 

Top Liked Posts

  • There are no posts matching your filters.
  • 40
    Guide to Mediatek Building(Guide 1:=Kernel)

    Here, we'll be talking about how to build kernels and how they are different than the ones we've built for Qualcomm.

    Requisites
    A linux machine
    Required Packages(Attached in 2nd post)
    C programming and a knowledge about Makefiles
    NDK


    Lets begin,

    Step 1(Setting up the build environment):=As always we have to set up the build environment so that the linux knows we are building something.
    This is how we do it
    Code:
    export TARGET_BUILD_VARIANT=user TARGET_PRODUCT=devicename MTK_ROOT_CUSTOM=../mediatek/custom/ TARGET_KERNEL_VERSION=devicename &&export PATH=pathToDir/arm-eabi-4.6/bin:$PATH&&export CROSS_COMPILE=arm-eabi-&&export ARCH=arm

    Let me explain what this does
    The BUILD_VARIANT specifies what the kernel is going to be built for. A very good article i came across for explaining the build-variants is here.
    The TARGET_PRODUCT/TARGET_KERNEL_PRODUCT tells the linux machine what "device specific" files to use
    The MTK_ROOT_CUSTOM specifies the directory of the mediatek/custom folder. remember this mide be in the same directory as the kernel source as well.
    The PATHThis sets your toolchain executables to your path. Download toolchain(preferably arm-eabi-4.6) Or, if you want to, you could build your own toolchain from source code
    The CROSS_COMPILE, A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. The toolchain facilitates this function
    ARCH=arm, ARM is a family of instruction set architectures for computer processors based on a reduced instruction set computing (RISC) architecture developed by British company ARM Holdings. ARM is also used in Android. Here by typing
    Code:
    export ARCH=arm
    we are telling linux that we are going to be building for the CPU architecture "ARM".

    Thats enough theory, lets get our hands dirty :cool:

    Step 2(Configuring your kernel):=This is the heart to what your phone does so be careful when you do this if you're doubtful about something dont hesitate to ask me in the thread.. the base config is usually present in the kernel_source/mediatek/config/devicename/autoconfig/kconfig/platform. this is your base config which you will use and build with different requirments(Example:SELinux). You can always build a config from the start, I advice you dont do that until you have compiled a few kernels before. for using existing config as a base
    Code:
    cd kernel_source
    cp mediatek/config/devicename/autoconfig/kconfig/platform .config
    Now,
    Code:
    make menuconfig
    This will give a graphical interface for you to choose what features you want to add to your phone(Example:I/O Schedule,CPU Governors..) More about this here. You're now ready for compiling

    Step 3(Compiling):=This is the moment of truth; This is what youve been waiting for! Now, type
    Code:
    make zImage

    You will get something which says
    Code:
    arch/arm/boot/zImage Ready

    Step 4(Adding MediaTek headers):=[GUIDE]Building Mediatek boot.img{Appending headers}. This is my next guide, follow this to your way to compile a whole ROM for your phone.

    Now, use your source code to build a ramdisk for you by typing make bootimage. in the out folder you'll get a folder called root. This folder is the initramfs or the ramdisk. to this follow my next guide to understand how to append mediatek headers


    Code:
    make modules

    This is almost the most important step or your ROMS wont boot. after this is complete go to your sourcedir then in search type ".ko" you'll get a bunch of .ko files copy these to your device tree/ROM to make the rom to work.

    If you're moving to a device tree make sure to add this to your device_makefile
    Code:
    PRODUCT_COPY_FILES += \
    $(MOD_SRC)/ccci.ko:$(MOD_TGT)/ccci.ko \
    $(MOD_SRC)/ccci_plat.ko:$(MOD_TGT)/ccci_plat.ko \
    $(MOD_SRC)/devapc.ko:$(MOD_TGT)/devapc.ko \
    $(MOD_SRC)/devinfo.ko:$(MOD_TGT)/devinfo.ko \
    $(MOD_SRC)/mtk_fm_drv.ko:$(MOD_TGT)/mtk_fm_drv.ko \
    $(MOD_SRC)/mtk_hif_sdio.ko:$(MOD_TGT)/mtk_hif_sdio.ko \
    $(MOD_SRC)/mtk_stp_bt.ko:$(MOD_TGT)/mtk_stp_bt.ko \
    $(MOD_SRC)/mtk_stp_gps.ko:$(MOD_TGT)/mtk_stp_gps.ko \
    $(MOD_SRC)/mtk_stp_uart.ko:$(MOD_TGT)/mtk_stp_uart.ko \
    $(MOD_SRC)/mtk_stp_wmt.ko:$(MOD_TGT)/mtk_stp_wmt.ko \
    $(MOD_SRC)/mtk_wmt_wifi.ko:$(MOD_TGT)/mtk_wmt_wifi.ko \
    $(MOD_SRC)/mtklfb.ko:$(MOD_TGT)/mtklfb.ko \
    $(MOD_SRC)/pvrsrvkm.ko:$(MOD_TGT)/pvrsrvkm.ko \
    $(MOD_SRC)/scsi_tgt.ko:$(MOD_TGT)/scsi_tgt.ko \
    $(MOD_SRC)/scsi_wait_scan.ko:$(MOD_TGT)/scsi_wait_scan.ko \
    $(MOD_SRC)/sec.ko:$(MOD_TGT)/sec.ko \
    $(MOD_SRC)/vcodec_kernel_driver.ko:$(MOD_TGT)/vcodec_kernel_driver.ko \
    $(MOD_SRC)/wlan_mt6628.ko:$(MOD_TGT)/wlan_mt6628.ko

    This copies your custom built modules to the Module out folder. In BoardConfig.mk add
    Code:
    TARGET_PREBUILT_KERNEL := $(DEVICE_FOLDER)/prebuilt/kernel
    ..

    Remember :If you're building kernel for already existing 4.2 roms disable SELINUX support by going into security options inside menuconfig

    You're done!!

    All Questions and feedbacks are welcome in the thread
    Be sure to drop a thanks if you thought this was usefull

    Happy Building.

    --------------------------------------------------
    Links to my next Guides
    Building the boot.img{MediaTek}
    Building the ROM{MediaTek}
    9
    Build Packages

    Required packages before building



    Python 2.6 -- 2.7, which you can download from python.org.

    GNU Make 3.81 -- 3.82, which you can download from gnu.org,

    JDK 6 if you wish to build Gingerbread or newer; JDK 5 for Froyo or older. You can download both from java.sun.com.

    Git 1.7 or newer. You can find it at git-scm.com.



    #Required packages

    Code:
    sudo apt-get install git 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 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 git-core lzop ccache gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python gcc g++ cpp gcc-4.8 g++-4.8 && sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so

    Go to etc/udev/rules.d/51-android.rules

    Code:
    # adb protocol on passion (Nexus One)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e12", MODE="0600", OWNER="<username>"
    # fastboot protocol on passion (Nexus One)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="0fff", MODE="0600", OWNER="<username>"
    # adb protocol on crespo/crespo4g (Nexus S)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e22", MODE="0600", OWNER="<username>"
    # fastboot protocol on crespo/crespo4g (Nexus S)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e20", MODE="0600", OWNER="<username>"
    # adb protocol on stingray/wingray (Xoom)
    SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="70a9", MODE="0600", OWNER="<username>"
    # fastboot protocol on stingray/wingray (Xoom)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="708c", MODE="0600", OWNER="<username>"
    # adb protocol on maguro/toro (Galaxy Nexus)
    SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0600", OWNER="<username>"
    # fastboot protocol on maguro/toro (Galaxy Nexus)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e30", MODE="0600", OWNER="<username>"
    # adb protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d101", MODE="0600", OWNER="<username>"
    # adb protocol on panda (PandaBoard ES)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d002", MODE="0600", OWNER="<username>"
    # fastboot protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d022", MODE="0600", OWNER="<username>"
    # usbboot protocol on panda (PandaBoard)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d00f", MODE="0600", OWNER="<username>"
    # usbboot protocol on panda (PandaBoard ES)
    SUBSYSTEM=="usb", ATTR{idVendor}=="0451", ATTR{idProduct}=="d010", MODE="0600", OWNER="<username>"
    # adb protocol on grouper/tilapia (Nexus 7)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0600", OWNER="<username>"
    # fastboot protocol on grouper/tilapia (Nexus 7)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0600", OWNER="<username>"
    # adb protocol on manta (Nexus 10)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee2", MODE="0600", OWNER="<username>"
    # fastboot protocol on manta (Nexus 10)
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="<username>"




    In bash.rc
    Code:
    export USE_CCACHE=1

    Beter way installing java
    Code:
    sudo apt-get purge openjdk-\* icedtea-\* icedtea6-\*
    sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update && sudo apt-get install oracle-java6-installer

    Reuqired package check
    Code:
    sudo apt-get install git-core lzop ccache gnupg flex bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 libc6-dev lib32ncurses5 lib32z1 lib32bz2-1.0 lib32ncurses5-dev x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 lib32z-dev libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc readline-common libreadline6-dev libreadline6 lib32readline-gplv2-dev libncurses5-dev lib32readline5 lib32readline6 libreadline-dev libreadline6-dev:i386 libreadline6:i386 bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev lib32bz2-dev libsdl1.2-dev libesd0-dev squashfs-tools pngcrush schedtool libwxgtk2.8-dev python gcc g++ cpp gcc-4.8 g++-4.8

    THIS
    Code:
    sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so




    You're done
    4
    I think I`m getting error because the toolchain.
    As Grand Prime Duos has a x64 cpu arquitecture, I used this toolschains to compile: aarch64-linux-android-4.9.
    I tried with arm-linux-androideabi-4.9 (x64) too...


    Which toolchain should I have to use to compile the kernel?

    Thanks!

    Arm-eabi 4.4 / 4.6 to until JB 4.2
    Arm-eabi 4.6 for mtk KK 4.4.2
    arm-eabi 4.7 for mtk KK 4.4.4
    arm-eabi 4.8 for mtk LL 5.0/ 5.1

    You can use whatever toolchain, but depending on your source / platform core OS, you may need to fix the source to work with higher toolchains.

    The ones i mention are the recommended for The OS versions

    Linaro toolchains, will also need some work, depending on your OS version / source

    cheers
    4
    @abiolakunle
    You're getting error because
    You're dividing somthing by zero
    3
    @MasterAwesome this went a little bit over my head....:confused:

    i understood till making zimage,,,,,after that how to make it a boot img...:confused:

    After compiling the zImage, move it to your device tree in your source code. under a folder called prebuilts. Look at my git repo for more reference a210_device_tree. As i said add a flag in the BoardConfig.mk
    Code:
    TARGET_PREBUILT_KERNEL:=sourcetokernel
    . then, we use the the PRODUCT_COPY_FILES to copy the kernel specific files. since modules are kernel specific you'd have to use the modules you built or you'll get a boot loop.