View Poll Results: This guide is useful?
Yes 7 100.00%
Not much - (Post your question) 0 0%
No - (PM me with why) 0 0%
Voters: 7. You may not vote on this poll

Post Reply

[GUIDE][TOOL] How Build/Compile your own kernel for LG G2

OP ferreirawax

8th February 2015, 11:11 PM   |  #1  
ferreirawax's Avatar
OP Member
Flag Fortaleza
Thanks Meter: 172
 
82 posts
Join Date:Joined: May 2014
More
There is still no "how to" specific to the LG G2, so I'll try to share the maximum of my experience (or almost) with ["kernel", "build", "LG G2"] here. I'll show two methods different using CM12 kernel, The method for LG ROMs is very similar, I show some tips for LG ROMs also. The first method is the "manual" and second is the "automatic" using my "tool" called DCC. So come on! For this you will need a computer running Linux (x64) and have knowledge about basic Linux commands. I'm using a laptop (i3-2328M and 4GB of RAM) running Ubuntu 14.10

Quote:

Setting Up the Environment

First install the essential tools (common environment for those already working with C/C++):

Code:
sudo apt-get install bison build-essential curl flex git gnupg gperf libesd0-dev liblz4-tool libncurses5-dev libsdl1.2-dev libwxgtk2.8-dev libxml2 libxml2-utils lzop openjdk-7-jdk openjdk-7-jre pngcrush schedtool squashfs-tools xsltproc zip zlib1g-dev g++-multilib gcc-multilib lib32ncurses5-dev lib32readline-gplv2-dev lib32z1-dev
Check Java and Java Compiler version:

Code:
java -version && javac -version
If the default Java is 1.6.x, Use this command and select java-7-openjdk as default:

Code:
sudo update-alternatives --config java

Quote:

Setting Up the kernel Environment

Code:
mkdir -p ~/android/mykernel && cd ~/android/mykernel && mkdir out
This will create a folder and two subfolder in your home, Within mykernel folder will get all the tools that we will set up. Now we set the toolchain, Particularly I use Linaro 4.9.3, the version optimized for Cortex-A15 by @Christopher83, so I will use it here.

Clone Linaro GCC 4.9.3:

Code:
git clone https://github.com/Christopher83/arm-cortex_a15-linux-gnueabihf-linaro_4.9
Now the required binaries (Common essential binaries to work with msm8974):

Code:
git clone https://github.com/ferreirawax/mkboot_exec ~/android/mykernel/executables
Clone the RAM disk compiled from CM12:

Code:
git clone -b aosp https://github.com/ferreirawax/ramdisk_g2 ~/android/mykernel/ramdisk
For stock Kitkat:

Quote:

This RAM disk was extracted from my d805 (d805 is a d802 which was released in latin america), then so will work on the d802, d805 and d806 (d806 is a d802 as the d805) If the variant is another you will have to draw your own device using a tool such AIK or search repositories of other developers.

Code:
git clone -b lge https://github.com/ferreirawax/ramdisk_g2 ~/android/mykernel/ramdisk
Now finally the source code of the kernel, Here I will use a configured kernel to compile the code without CM12 source, you can use the source code that is in the official repositories of CM12, but you will face some errors and warnings during the build that can be solved using the commits that are in my source and supply of other developers.

Clone kernel source:

Code:
git clone -b cm-12.0 https://github.com/ferreirawax/kernel_lge_msm8974-patched ~/android/mykernel/msm8974
For stock KitKat:

Code:
git clone -b lge-kitkat https://github.com/ferreirawax/kernel_lge_msm8974-patched ~/android/mykernel/msm8974
Apparently not but we already have a complete environment, see the folders in mykernel to have a shadow on it. Now let's the good part of the story.

Quote:

Compiling

Enter in kernel folder:

Code:
cd msm8974
Export Architecture and Toolchain:

Code:
export ARCH=arm
export CROSS_COMPILE=~/android/mykernel/arm-cortex_a15-linux-gnueabihf-linaro_4.9/bin/arm-eabi-
For stock KitKat you need export LZ4 path:

Code:
export PATH=$PATH:tools/lz4demo
Select the model of the device you want to compile your pointing due defconfig, If you are using source code directly from the repositories of the CM12, defconfig each supported model is called "cyanogenmod_MODEL_defconfig".

Select model to build (In my case I will compile for d802):

Code:
make d802_defconfig
Now let's clear the specific waste of d802:

Code:
make clean && make mrproper
Select model again to generate new .config:

Code:
make d802_defconfig
Now we start to build:

Code:
make -j4
-j4 is suitable for dual-core processors and -j5 for quad-core.

Depending on the configuration of your PC can take up to 20 minutes. In my laptop the build time is about 10 minutes. If you are using VirtualBox, can take much longer. Upon completion, will generate a zImage and some dtb (Device tree binary) files, The dtb files will be used to create a specific image (dt.img) file containing board informations. Now let's create a RAM disk and then dt.img to later put it all together and result in a final boot.img.

Enter in executables folder:

Code:
cd ~/android/mykernel/executables
Create GNUZip compressed RAM disk:

Code:
./mkbootfs ~/android/mykernel/ramdisk | gzip > ~/android/mykernel/out/ramdisk.gz
Create dt.img:

First copy the dtc file that is in executables folder to /usr/bin

Code:
gksu nautilus
This will open the file manager with root privileges, After click the left mouse button and select the dtc as executable.
You may need to restart, After that create the dt.img with the following command.

Code:
./dtbTool -s 2048 -o ~/android/mykernel/out/dt.img ~/android/mykernel/msm8974/arch/arm/boot/
Finally assemble boot.img file:

Code:
./mkbootimg --kernel ~/android/mykernel/msm8974/arch/arm/boot/zImage --ramdisk ~/android/mykernel/out/ramdisk.gz --cmdline "XXXX" --base 0x00000000 --pagesize 2048 --offset 0x05000000 --tags-addr 0x04800000 --dt ~/android/mykernel/out/dt.img -o ~/android/mykernel/out/boot.img
Quote:

Replace the XXXX for the following:

console=ttyHSL0,115200,n8 androidboot.hardware=g2 user_debug=31 msm_rtb.filter=0x0 mdss_mdp.panel=1:dsi:0:qcom,mdss_dsi_g2_lgd_cmd androidboot.selinux=permissive

Do not remove the quotes. Replace the panel model (red) for your model. if you are compiling for stock KitKat, remove everything that is green.

Now let's add a "signature" in your kernel for the damn locked LG G2 bootloader so you can not be invalidated. If you do not do this procedure, the bootloader of your LG G2 will verify that this kernel has a particular signature, as it does not have your device will be unable to boot. We have two tools for this, Loki is able to fool the bootloader and open_bump (This tool is controversy) is able to add a "valid" signature using illegal means. I'll show how to use both. To this is very simple..

open_bump method:

You need Python to run any Python code, open_bump requires Python 2.x

Code:
git clone https://github.com/CyboLabs/Open_Bump
python open_bump.py ~/android/mykernel/out/boot.img
You will now have an output "boot_bumped.img".

loki_tool method:

First get a copy of the bootloader of your G2, For this you need the adb installed and your G2 properly connected to your PC.

Get bootloader:

Code:
sudo apt-get install android-tools-adb
adb devices && adb shell "su -c dd if=/dev/block/platform/msm_sdcc.1/by-name/aboot of=/sdcard/aboot.img"
adb pull /sdcard/aboot.img
Do not forget the USB debugging enabled

Patch kernel:

Code:
./loki_patch boot aboot.img ~/android/mykernel/out/boot.img ~/android/mykernel/out/loki_boot.img
Will generate an output "loki_boot.img" on mykernel/out folder.

You can install using my easy installer (Attached at the end of post):

Download the attachment and extracted, Place your boot.img in the delta folder and
copy all the modules that are in your kernel source for the modules folder:

Code:
find ~/android/mykernel/msm8974/. -name "*.ko" -exec cp {} ~/android/mykernel/installer/system/lib/modules
Now zip folder and install on your device. This installer already have panel detection script by @dr87





Finally now you have your own kernel! Now I will show the second method of how to automatic compile your kernel using my tool.

To rebuild you have to use the following:

Code:
make clean && make mrproper
make MODEL_defconfig
make -j4

Quote:

Some tips

To not export the toolchain path every time you restart the system, Create a Shell executable in /etc/profile.d as follows:

Code:
sudo nano /etc/profile.d/export_gcc.sh
Copy and paste:
Quote:

export PATH=~/android/mykernel/arm-cortex_a15-linux-gnueabihf-linaro_4.9/bin:$PATH

CTRL + X, Y, ENTER

Now you just use:

Code:
export ARCH=arm
export CROSS_COMPILE=arm-eabi-
Useful guides:

If you are new, you can start learning about git, One of the main tools for working with modifications to your kernel. Below I leave some links with some guides that can help you.

How to use Github
How to cherry-pick a github commit

Attached Files
File Type: zip installer.zip - [Click for QR Code] (168.7 KB, 18 views)
Last edited by ferreirawax; 14th February 2015 at 09:47 PM.
The Following 22 Users Say Thank You to ferreirawax For This Useful Post: [ View ]
8th February 2015, 11:11 PM   |  #2  
ferreirawax's Avatar
OP Member
Flag Fortaleza
Thanks Meter: 172
 
82 posts
Join Date:Joined: May 2014
More
DCC is a tool I developed to simplify my day, DCC is just a simple Python code that can help you save your time! See the features:
  • Command-line arguments like M$'s DiskPart
  • Real-time Shell executer
  • Manage builds for AOSP and LG ROMs
  • Build for single or ALL variants in same time
  • Manage the parameters of your kernel
  • DCC works with embedded open_bump
  • Manage your favorite toolchain
  • Easy to configure and use

I'll show how to use DCC is easy

Setup kernel environment:
Code:
reset && cd $HOME
mkdir dev && cd dev
git clone https://github.com/ferreirawax/dcc
cd dcc
git clone https://github.com/ferreirawax/ramdisk_g2_aosp  ramdisk/aosp
git clone https://github.com/ferreirawax/kernel_lge_msm8974-patched msm8974/aosp
Build kernel:
Code:
python dcc.py
do boot d802
exit
You know what happens to these magical commands? An immediate flashable zip of your kernel ready to flash. But for that you need to "setup" to your taste, see the page on github.
Last edited by ferreirawax; 13th February 2015 at 03:38 PM.
The Following 13 Users Say Thank You to ferreirawax For This Useful Post: [ View ]
9th February 2015, 12:16 AM   |  #3  
Boris31's Avatar
Member
Flag Novi Sad
Thanks Meter: 23
 
96 posts
Join Date:Joined: Feb 2012
Donate to Me
More
Thumbs up
@ferreirawax this is great i was waiting for something like this so much, tommorow i will try your guide and post the results

EDIT
I followed everything and got stuck here:

simex@Simex:~/android/mykernel/msm8974$ make clean && make mrproper
make: /home/simex/android/mykenel/arm-cortex_a15-linux-gnueabihf-linaro_4.9/bin/arm-eabi-gcc: Command not found

THANKS for help

EDIT 2
I tried method with DCC and im stuck here:

simex@Simex:~/dev/dcc$ python dcc.py
Traceback (most recent call last):
File "dcc.py", line 19, in <module>
from colorama import *
ImportError: No module named colorama
simex@Simex:~/dev/dcc$

Sorry if im annoying but i hope someone can help me
Last edited by Boris31; 9th February 2015 at 02:07 AM.
The Following User Says Thank You to Boris31 For This Useful Post: [ View ]
9th February 2015, 02:27 AM   |  #4  
ferreirawax's Avatar
OP Member
Flag Fortaleza
Thanks Meter: 172
 
82 posts
Join Date:Joined: May 2014
More
Quote:
Originally Posted by Boris31

@ferreirawax this is great i was waiting for something like this so much, tommorow i will try your guide and post the results

EDIT
I followed everything and got stuck here:

simex@Simex:~/android/mykernel/msm8974$ make clean && make mrproper
make: /home/simex/android/mykenel/arm-cortex_a15-linux-gnueabihf-linaro_4.9/bin/arm-eabi-gcc: Command not found

THANKS for help

EDIT 2
I tried method with DCC and im stuck here:

simex@Simex:~/dev/dcc$ python dcc.py
Traceback (most recent call last):
File "dcc.py", line 19, in <module>
from colorama import *
ImportError: No module named colorama
simex@Simex:~/dev/dcc$

Sorry if im annoying but i hope someone can help me

This error happens when the toolchain path is wrong.

Colorama module need to use DCC (I forgot to mention that)
Code:
sudo pip install colorama
The Following 3 Users Say Thank You to ferreirawax For This Useful Post: [ View ]
9th February 2015, 09:15 AM   |  #5  
Norside's Avatar
Senior Member
Flag A place south in the north!
Thanks Meter: 169
 
438 posts
Join Date:Joined: Aug 2013
More
Really exited to see sutch a complete guide for how to make a kernel for our G2
Will try and see if I can manager to compile my first kernel with this guide today..
9th February 2015, 10:59 AM   |  #6  
Boris31's Avatar
Member
Flag Novi Sad
Thanks Meter: 23
 
96 posts
Join Date:Joined: Feb 2012
Donate to Me
More
Quote:
Originally Posted by ferreirawax

This error happens when the toolchain path is wrong.

Colorama module need to use DCC (I forgot to mention that)

Code:
sudo pip install colorama

ok thanks i got i working

[SIZE=1]---------- Post added at 10:43 AM ---------- Previous post was at 10:21 AM --------- @ferreirawax you got a typing mistake here thats why method 1 didnt work i finaly figured it out:

Export Architecture and Toolchain:

Code:

export ARCH=arm
export CROSS_COMPILE=~/android/mykenel/arm-cortex_a15-linux-gnueabihf-linaro_4.9/bin/arm-eabi-

It should be myKERNEL and that it works

Now i succesfully build my kernel but im having problems with bump, i cant get past this:
simex@Simex:~$ python open_bump.py ~/android/mykernel/out/boot.img
python: can't open file 'open_bump.py': [Errno 2] No such file or directory

but im sure its there i tryed nearly everything but cant get bumped boot.img
Last edited by Boris31; 9th February 2015 at 04:41 PM.
The Following User Says Thank You to Boris31 For This Useful Post: [ View ]
9th February 2015, 11:21 AM   |  #7  
Member
Thanks Meter: 10
 
62 posts
Join Date:Joined: Feb 2014
More
Thumbs up
Thank you!!!! I have wanted something like this to compile different kernels .
Last edited by bolt890; 9th February 2015 at 08:01 PM.
9th February 2015, 02:40 PM   |  #8  
Norside's Avatar
Senior Member
Flag A place south in the north!
Thanks Meter: 169
 
438 posts
Join Date:Joined: Aug 2013
More
It would have been totally awesome if @dorimanx did a tutorial once where he shared how he makes his (stock) kernels..anyways will this work on a 11 year old PC with 1gb RAM and 1,7 GHz processor? :P
9th February 2015, 04:44 PM   |  #9  
Boris31's Avatar
Member
Flag Novi Sad
Thanks Meter: 23
 
96 posts
Join Date:Joined: Feb 2012
Donate to Me
More
any help for bumping boot.img ?
9th February 2015, 04:53 PM   |  #10  
6ril1's Avatar
Senior Member
Thanks Meter: 297
 
315 posts
Join Date:Joined: Jan 2010
More
Quote:
Originally Posted by Boris31

any help for bumping boot.img ?

http://forum.xda-developers.com/show...php?p=56987541

(OP gave cmd lines too)
Last edited by 6ril1; 9th February 2015 at 04:57 PM.

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes