[OnePlus 2 General] Brandon Indar:
Hi all...

Happy Holidays:D

I have been looking around haven't found a tutorial on compiling kernel for oneplus2, so i decided on making one for those who are new to compiling kernel from source.

This tutorial will be divided into 3 parts...

>Preparing the build environment... (Ubuntu 16.04 LTS).

>Downloading source code, Toolchain and compiling.

>Testing

######################################################################

Preparing the build environment

Preparing the build environment is easy. If u haven't install Ubuntu yet, check out how to dual-boot alongside windows from here.

If u are looking for something easier like running it from a virtual machine check out this.

Right now i have Ubuntu 16.04 LTS installed which i will be using.

Once u have booted into Ubuntu, it's time to head to the terminal.

Lunch the terminal by right clicking on desktop an select "open terminal"

Once in terminal type in these commands individually (note: some commands will prompt u to type y and enter):

sudo apt-get install synaptic

sudo apt-get install libncurses5-dev

sudo apt-get install git-core 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 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386

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

sudo apt-get install -y ccache &&echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc &&source ~/.bashrc && echo $PATH

export USE_CCACHE=1

Installing repo...

mkdir ~/bin

export PATH=~/bin:$PATH

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

chmod a+x ~/bin/repo

Installing Java...

sudo add-apt-repository ppa:webupd8team/java

sudo apt update; sudo apt install oracle-java8-installer

sudo apt install oracle-java8-set-default

Run this command to check if Java is installed correctly:

javac -version

If it says something like this (javac 1.8.0_111) then u are good to go.

That's it for preparing the build environment. Easy... right.:highfive:

######################################################################

Downloading source code, Toolchain and compiling

Now it's time to download the source, u will be creating a folder to download the source in so type to commands below,

mkdir oneplus2-kernel

cd oneplus2-kernel

(The folder can be found in the home directory)

If u are building for cm, download the kernel source using command below...

git clone https://github.com/CyanogenMod/android_kernel_oneplus_msm8994.git

If u are building for other rom use this one...

git clone https://github.com/OnePlusOSS/android_kernel_oneplus_msm8994.git

Once download is completed, u need to download the toolchain which is the tool used in compiling the kernel.

It can be downloaded from here.

When download completed, move the zip file to the oneplus2-kernel folder u made earlier and then right click and select extract here.

U can now delete the zip file when extracted. So now u would have 2 folders to in ur oneplus2-kernel folder. One is the kernel and the other is the toolchain.

Time to compile the kernel... But first u need to point the variable to toolchains path. To do this, u need to go to the kernel source, folder(which is called android_kernel_oneplus_msm8994 in the oneplus2-kernel folder) right click and open in terminal, then run the command

export CROSS_COMPILE=/home/[B]"UR_USERNAME"[/B]/oneplus2-kernel/aarch64-linux-android-4.9-uber-master/bin/aarch64-linux-android-

(NOTE:Replace "UR_USERNAME" with the name u used when installing ubuntu)

Now run the commands below in the same terminal:

export ARCH=arm64

export SUBARCH=arm64

export USE_CCACHE=1

U will need to locate the defconfig file. If u are compiling for cm, the file name will be "cm_oneplus2_defconfig", and for the other source, name will be "msm8994-OnePlus2_defconfig". It is located in /home/"UR_USERNAME"/oneplus2-kernel/android_kernel_oneplus_msm8994/arch/arm64/configs/...

(Note: The defconfig file may vary for different roms ur building for so pay attention to that.)

So if u are compiling for cm, run the command:

make cm_oneplus2_defconfig

to add it to the config file. Change name of defconfig file accordingly as said above.

Now it's time to give ur kernel a name so run the command:

make menuconfig

This will look like when u boot into the BIOS, so use the arrow keys to navigate. This menu allows the u to choose the features of the kernel (and other options) that will be compiled. To add the name, go to "General setup" then "(-perf) Local version - append to kernel release", then type in the name for ur custom kernel and save/exit.

Finally type this command to compile...

make -j2

(Replace -j2 with the number of cpu cores)

IF (make -j2) gives errors try:

make

This will take A WHILE, so let it do it's ting.;)

If it compiled without errors, u will find the kernel file named "Image.gz-dtb" located in /home/"UR_USERNAME"/oneplus2-kernel/android_kernel_oneplus_msm8994/arch/arm64/boot/...

:good:SUCCESS:good::victory:

If FAILED:crying: , u can post a screen-shot of ur error below and i will try an help u out.:cool:

######################################################################

Testing

Time to test ur newly built kernel, since everything went smoothly and u cant wait to boot it up.

Well download this flashable zip from here.

Open the zip file using Archive Manager without extracting.

Delete the file named "Image.gz-dtb" and replace with ur kernel located at /home/"UR_USERNAME"/oneplus2-kernel/android_kernel_oneplus_msm8994/arch/arm64/boot/Image.gz-dtb.

That's it...Just copy the zip to ur device and flash away...

As i said early... any problem u are having with compiling, just post a screen-shot of ur error below and i will try an help u.

:good:REMEMBER TO HIT THANKS/LIKE:good: