AndroidHow To's

How to Build MediaTek Android Kernal from Source

Many Android users enjoy installing customized kernels, which can offer a range of performance and battery life enhancing tweaks. But if you can’t find a kernel you like, or none are available for your device, sometimes you just have to build your own. This guide will focus on how to build a kernel from source for Mediatek devices.

Please be warned this guide is not for newbies, it is intended for people with an understanding of customizing Android ROMs, working in Linux terminals, and just overall a bit of working knowledge about what we’re doing.

Requirements:

  1. A Linux operating system
  2. Some basic C knowledge and how to work with Makefiles
  3. Android NDK

To begin, you’re going to need to download the following packages for Linux:

  • Python
  • GNU Make
  • JDK
  • Git

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

Now go to etc/udev/rules.d/51-android.rules:

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

And in bash.rc:

export USE_CCACHE=1
Now finally:

sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
So now we’re ready to set up the build environment. In the terminal, type:

export TARGET_BUILD_VARIANT=user TARGET_PRODUCT=devicename MTK_ROOT_CUSTOM=../mediatek/custom/ TARGET_KERNEL_V
Here’s what these commands are going to do:

BUILD_VARIANT: specifies what the kernel is going to be built for.
TARGET_PRODUCT/TARGET_KERNEL_PRODUCT: tells Linux which device specific files to use.
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.
PATH: sets your toolchain executables to your path.
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.

So when we type ‘export ARCH=arm’ into the terminal, we’re basically telling Linux that we’re building for the ARM architecture.

So now we’re ready to begin configuring the kernel. You need to be extremely careful, because the kernel is basically the controller for your phone. So just follow along carefully.

 


You’ll most likely find the base config in the kernel_source/mediatek/config/devicename/autoconfig/kconfig/platform.
We can use this base config and build it with different requirements, for example SELinux permissions enabled or disabled. You could always just build a base config from scratch, but I really don’t recommend it.

So now let’s type into the Linux terminal:

cd kernel_source
cp mediatek/config/devicename/autoconfig/kconfig/platform .config
make menuconfig

This is going to create a graphical interface that will allow you to add features to the kernel. For example, you can tweak the I/O Schedule, CPU Governors, GPU Frequency, etc.
Once you’ve tweaked your desired settings, you’re ready to compile the kernel. So type into the Linux terminal:
make zImage

And it should return something like:

arch/arm/boot/zImage Ready

Leave a Reply

Your email address will not be published.

Expert Tip

How to Build MediaTek Android Kernal from Source

If the issue is with your Computer or a Laptop you should try using Reimage Plus which can scan the repositories and replace corrupt and missing files. This works in most cases, where the issue is originated due to a system corruption. You can download Reimage by clicking the Download button below.

Download Now

I'm not interested

Close