FORUMS

[GUIDE] How to compile a custom kernel for OnePlus 2

183 posts
Thanks Meter: 410
 
By Brandon Indar, Senior Member on 22nd December 2016, 10:23 PM
Post Reply Email Thread
Hi all...
Happy Holidays

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):
Code:
sudo apt-get install synaptic
Code:
sudo apt-get install libncurses5-dev
Code:
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
Code:
sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
Code:
sudo apt-get install -y ccache &&echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc &&source ~/.bashrc && echo $PATH
Code:
export USE_CCACHE=1
Installing repo...
Code:
mkdir ~/bin
Code:
export PATH=~/bin:$PATH
Code:
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
Code:
chmod a+x ~/bin/repo
Installing Java...
Code:
sudo add-apt-repository ppa:webupd8team/java
Code:
sudo apt update; sudo apt install oracle-java8-installer
Code:
sudo apt install oracle-java8-set-default
Run this command to check if Java is installed correctly:
Code:
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.

################################################## ####################
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,
Code:
mkdir oneplus2-kernel
Code:
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...
Code:
git clone https://github.com/CyanogenMod/android_kernel_oneplus_msm8994.git
If u are building for other rom use this one...
Code:
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
Code:
export CROSS_COMPILE=/home/"UR_USERNAME"/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:
Code:
export ARCH=arm64
Code:
export SUBARCH=arm64
Code:
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:
Code:
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:
Code:
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...
Code:
make -j2
(Replace -j2 with the number of cpu cores)
IF (make -j2) gives errors try:
Code:
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/...

SUCCESS

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

################################################## ####################
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.

REMEMBER TO HIT THANKS/LIKE
The Following 14 Users Say Thank You to Brandon Indar For This Useful Post: [ View ] Gift Brandon Indar Ad-Free
22nd December 2016, 10:24 PM |#2  
Brandon Indar's Avatar
OP Senior Member
Flag Williamsville
Thanks Meter: 410
 
Donate to Me
More
reserved
1st June 2017, 04:31 PM |#3  
Member
Thanks Meter: 6
 
More
So I've decided to give this a try today. Run into a slight problem though.

1. When I execute make msm8994-OnePlus2_defconfig I receive an error 'make: Nothing to be done for msm8994-OnePlus2_defconfig'. This file did already exist under the folder structure.
2. When I execute make menuconfig I receive an error 'No rule to make target menuconfig. Stop'.

Any ideas to what I am doing wrong?

Thanks in advance.
1st June 2017, 04:53 PM |#4  
Senior Member
Flag Los Angeles
Thanks Meter: 55
 
More
Quote:
Originally Posted by Woodzrul

So I've decided to give this a try today. Run into a slight problem though.

1. When I execute make msm8994-OnePlus2_defconfig I receive an error 'make: Nothing to be done for msm8994-OnePlus2_defconfig'. This file did already exist under the folder structure.
2. When I execute make menuconfig I receive an error 'No rule to make target menuconfig. Stop'.

Any ideas to what I am doing wrong?

Thanks in advance.

It been a while but I'll try to help ima assume you building the latest lineage kernel right? If so use

make oneplus2_defconfig

Then

make -j4

The menu config is to name the kernel if you want to it appears after the Linux version default is often perf+, but not required

example: 3.10.93 perf+
1st June 2017, 05:04 PM |#5  
Member
Thanks Meter: 6
 
More
Appreciate the prompt response. I shall give this ago. Have clicked the Thanks! button.
25th July 2017, 07:38 PM |#6  
Member
Flag Pune
Thanks Meter: 13
 
More
Quote:
Originally Posted by Brandon Indar

reserved

Sir I'm trying to compile from boeffla kernel sources But I'm just stuck here...i also tried "make cm_oneplus2_defconfig" but no use I followed all the below steps also installed java and I'm on Ubuntu 17.04 (dualboot)..
Any help would be appreciated
26th July 2017, 02:46 AM |#7  
Brandon Indar's Avatar
OP Senior Member
Flag Williamsville
Thanks Meter: 410
 
Donate to Me
More
Quote:
Originally Posted by Prathamesh Kapure

Sir I'm trying to compile from boeffla kernel sources But I'm just stuck here...i also tried "make cm_oneplus2_defconfig" but no use I followed all the below steps also installed java and I'm on Ubuntu 17.04 (dualboot)..
Any help would be appreciated

Hi...
What error exactly u are getting when u running the command:
"make cm_oneplus2_defconfig"

Sent from my ONE A2005 using Tapatalk
26th July 2017, 04:17 AM |#8  
Member
Flag Pune
Thanks Meter: 13
 
More
Quote:
Originally Posted by Brandon Indar

Hi...
What error exactly u are getting when u running the command:
"make cm_oneplus2_defconfig"

The error wguch i get always is "make: *** No rule to make target 'cm_oneplus2_defconfig'. Stop"
Edit:the error can be seen in the attachment

---------- Post added at 04:17 AM ---------- Previous post was at 04:11 AM ----------

Quote:
Originally Posted by Prathamesh Kapure

The error wguch i get always is "make: *** No rule to make target 'cm_oneplus2_defconfig'. Stop"
Edit:the error can be seen in the attachment

Edit 2:At first one of my developer frnd said try "make boeffla_defconfig" it didn't work thwn he said try "make cm_oneplus2_defconfig" this also didn't work so i thought i might post it here and get some help..
26th July 2017, 04:27 AM |#9  
Senior Member
Flag Los Angeles
Thanks Meter: 55
 
More
Quote:
Originally Posted by Prathamesh Kapure

The error wguch i get always is "make: *** No rule to make target 'cm_oneplus2_defconfig'. Stop"
Edit:the error can be seen in the attachment

---------- Post added at 04:17 AM ---------- Previous post was at 04:11 AM ----------



Edit 2:At first one of my developer frnd said try "make boeffla_defconfig" it didn't work thwn he said try "make cm_oneplus2_defconfig" this also didn't work so i thought i might post it here and get some help..

Look at the arch/boot/arm64/configuration inside the kernel source and the files in there will give you an idea what you can build the usually one is oneplus2_defconfig sometimes developers will make another Defconfig and you'll find it there. typically for LineageOS oneplus2_defconfig is the one used.

After looking at boeffla source cm Defconfig is old and prob will break something, "make boeffla_defconfig" should work and make sure your inside the kernel source as you do the make Defconfig command
26th July 2017, 04:36 AM |#10  
Member
Flag Pune
Thanks Meter: 13
 
More
Quote:
Originally Posted by Dr_DjEnder

Look at the arch/boot/arm64/configuration inside the kernel source and the files in there will give you an idea what you can build the usually one is oneplus2_defconfig sometimes developers will make another Defconfig and you'll find it there. typically for LineageOS oneplus2_defconfig is the one used.

After looking at boeffla source cm Defconfig is old and prob will break something, "make boeffla_defconfig" should work and make sure your inside the kernel source as you do the make Defconfig command

Ok Thank you sir.. I'll try and report
Offtopic: Do u know any of our whatsapp and telegram group? If so can u plz add me
26th July 2017, 05:46 AM |#11  
Member
Flag Pune
Thanks Meter: 13
 
More
Quote:
Originally Posted by Dr_DjEnder

Look at the arch/boot/arm64/configuration inside the kernel source and the files in there will give you an idea what you can build the usually one is oneplus2_defconfig sometimes developers will make another Defconfig and you'll find it there. typically for LineageOS oneplus2_defconfig is the one used.

After looking at boeffla source cm Defconfig is old and prob will break something, "make boeffla_defconfig" should work and make sure your inside the kernel source as you do the make Defconfig command

Sir i tried but no use i get same error but i just noticed some bottom commands show a bit different error "make: Nothing to be done for 'oneplus_2' and also for 'make boeffla_defconfig'
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes