
How to compile a Samsung Kernel from source
Ok folks, I am going to show you how to build a Sammy kernel from source. This will be a very long guide, so I might miss one or two things. But we will solve that if it happens.
Below is a list of requirements that you must have in order to be successful.
REQUIREMENTS
1. For the best outcome, you need to be on Linux. I dont support VM Box
2. All the android dependencies. (Which I will provide)
3. Toolchain
4. A github account or the like. Its free.
5. Be familiar with terminal commands
6. And have alot of patients
SETTING UP YOUR BUILD ENVIRONMENT
First thing we need to do is set up your build environment. So in order to do this we need to install some packages to make sure your kernel
compiles correctly.... So open a terminal on your desktop, and copy and paste the code into your terminal from below:
Code:
sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev zlib1g-dev:i386 g++-multilib python-networkx libxml2-utils bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng

HOW TO GET YOUR KERNEL SOURCE
Samsung keeps all of their source code on Samsung Open Source here. So open this in your browser...once you have you want to click on "Mobile"

The next screen will have a search box. Inside that box you need to type in YOUR model number...

The next screen will show all of the available source code for your device. Select the one that you need, the most current one...

Now you have downloaded the kernel source.......now we need to extract it. This where you need to pay attention...
You will have a "home" folder. Open it and create a "new" folder and name it anything you want. This is where you will extract the kernel source to. Once you have
your folder created you need to navigate to your download folder, thats where the kernel zip will be located. Right click on the zip and select "extract here"...it will
then extract the kernel.tar to your download folder. Once its done you will see the new folder it has made and this is what it should look like when you open it

Now, right click on kernel.tar. Then select "extract to"......a window will pop up, select the new folder you just created. It will then extract all the kernel files to that folder.
That will be your kernel source. It should look similiar to mine...

Now you have your source. But, Sammy left out some files (imagine that)......so your going to need to get them. The easiest way is for you to clone my source
from Github. So go here. See the green tab that says Clone or download? Click it, it will bring up another
small widow.....click on the clipboard icon....open a terminal in your HOME FOLDER.....inside the terminal type git clone and then paste the url after

This will now download MY source to your home folder. Now lets pay close attention here.....You need to open YOUR source in a window, and open MINE in
another window. We will be copying several files from my source to yours.
In my source navigate to drivers/video/exynos. Copy and paste "decon_dual_dsi" and "decon_dual_display" folders to YOUR source. If you already have these files
in your source, you can skip this.
Now we need to get a couple more files. (Non T-Mobile users see post #3) Download these files here. Open the zip and copy them to
your source. In another words just drop them in. Please note that the "output" folder contains empty folder for the G920T and G925T. IF you are building the G920F you need
to change the folder name. Thats very important. We will get more into the build_kernel.sh and env_setup.sh later.
Now we need to get our toolchain. I have decided to get yall to use a custom toolchain instead of stock. There are several that you can use, but for this will use UberTC. So go
here. Now open your HOME folder and then open a terminal. On the webpage click "clone", copy
and paste it into the terminal. It will now download the toolchain to your home folder.
Seeing that we have our toolchain now, we need to set the path from it to our source so the compiler will know what to use at build time. The path needs to be set in 2 places in your source.
One in the env_setup.sh, and in the Makefile......This is how you do this ANYTIME you change your toolchain:
Now navigate to your home folder, you will see the UberTC toolchain you cloned earlier. Now you want to open it like this aarch64-linux-android-5.3-kernel/bin/. Now you will
need to copy the entire address line...mine is like this: /home/sick/aarch64-linux-android-5.3-kernel/bin/ Yours should be the same except for "sick", it should be your username.
Now, you need to open env_setup.sh with your text editor (mousepad, gedit, etc).....scroll to the bottom to where you see # system compiler
export CROSS_COMPILE=/home/sick/aarch64-linux-gnu-5.3/bin/aarch64-........REPLACE /home/sick/aarch64-linux-gnu-5.3/bin/aarch64- with the address from your toolchain folder.
It should look like this when you are done /home/sick/aarch64-linux-android-5.3-kernel/bin/aarch64-linux-android-..................YES, you need to type aarch64-linux-android- after bin/
The screen shot below shows a different toolchain than what we are using. So pay that no mind.

Now open your Makefile.......I want you to replace the ENTIRE file from the one I provided below.
Open the Makefile with your text editor.....see line #7 #TOOLCHAIN_DIR = $(CURDIR)/toolchain/aarch64-linux-gnu-5.3/bin/aarch64-
Change it to this : #TOOLCHAIN_DIR=$(CURDIR)/toolchain/aarch64-linux-android-5.3-kernel/bin/aarch64-linux-android-
Line #8 need to be just like the one you set in env_setup.sh......
Mine looks like this: /home/sick/aarch64-linux-android-5.3-kernel/bin/aarch64-linux-android-
Now the toolchain is set, and the compiler will use it to build the kernel.
OK, I'm going to skip a step on editing the defconfig for now. Reason being is that once we upload your source to Github you will need some basic Github
commands when you change things within your source and need to commit them.
UPLOADING SOURCE TO GITHUB
I assume by now that you have made a Github account. So now we need to create a repository so we can upload your source. This is'nt too difficult to do....
Go to Github....There will be a green tab that says New Repository, click on it.

Now you need name the repository......name it whatever you wish

On the next 2 screen shots select the ones I have highlighted, then select Create repository


Once the new repository is created it will look like this......

Ok, minimize your Github page, (dont close it).......open your kernel source folder. Inside the folder open a terminal and type: git init

Next I want you to type EXACTLY like this: git add .

Press enter.....in a minute or two it will start to load all your files......once its complete you need to maximize your Github page. Click on the green tab, then on the
small clipboard icon, in the terminal i want you to type: git remote add origin (paste the url from the clipboard). It should look like this...

Press enter. If you dont get any errors it will look like this.

Now type this: git commit -m Stock source Where I have Stock source you can change to whatever you want

It will start uploading your source

Once that is complete you need to type: git push origin master
It will ask for your Github username and then password

Now sometimes Github can be a pain and you will get this error when you try to push your source

To get around this, you need to type: git push -f origin master........then your username and password

Once it completes the upload process go ahead and refresh your Github page and it should look like this...

You have now uploaded your source to Github.
SETTING UP env_setup.sh FOR BUILDING YOUR VARIANT
When you look at env_setup.sh you will see that on line #68 says G920T. IF you are going to build for example the G920F, you need to change it
from G920T to G920F and so on.....

Now take a look at line #70....that is the defconfig file. So in your kernel source folder go to arch/arm64/configs. You will see the original name
for one or both config files. I changed the name on mine which correspond with my env_setup.sh. If you are NOT going to change the name on the
defconfig then you must change it back to original in env_setup.sh.
Earlier I had you use the Makefile I provided instead of the one that came with your source......That is MY Makefile from Twisted. So, we are going to have
to make a couple of edits in your defconfig file so you can take advantage of a few things that are included in my Makefile......
Open the Makefile in your kernel source......look at lines 10-19. Those 2 need to be enabled in your defconfig. So now go to arch/arm64/configs. Open
the config file that you will be using with a text editor.......add I want you to add these 2 lines just as I have them....

Now we just made a change to your source. The changes are what is called local. We need to commit them to Github. In order to do that you need
to open a terminal in your kernel source and type: git status
You should see this

You need to copy like this

Then type: git add (paste it here) then enter

Now type: git commit and you will get this.....

You will need to type a commit line. If you leave it blank it WILL NOT commit your changes. See how mine is......

Now to commit those changes from above you need to type the following: Ctrl+o enter Ctrl+x.......if you did it correctly it will look like this....

Then type: git push origin master then enter. Type your username and password......And this is what it should look like
if you did it all correctly...

Now at this point you can look at your Github page and see that it has been committed.......

TIME TO COMPILE
This part is rather simple. I'm going to give 2 examples on how to build for the G920T and the G920F. Now remember, our env_setup.sh says
G920T on lines 68 and 69. So thats what we will build....
In your kernel source open a terminal and type this: sudo build_kernel.sh G920T press enter. It should look like this...

Once you type your password and hit enter it should look like these.....




Now for the G920F build.......all you need to do is change the names in your env_setup.sh. Where it says G920T you change to G920F.
Same goes for any S6 device. Just change the name in the file.
Also make sure the name of your config file matches in both the env_setup.sh and in arch/arm64/configs.......
AT THE END OF THE BUILD YOU WILL BE ASKED TO USE s=stock or c=custom DT.IMG........SELECT S!!!!
NOW YOU HAVE BUILT IT......NOW WHAT.....
If you have followed along you will have made sure the output folder in your source has the device name you were compiling. Look in that folder,
and there will be a flashable zip as well as a tar file for Odin.
Well folks, that about covers it. In post #2 I will show you how to cherry-pick commits and fix simple HEAD errors. If anyone has issues or is
lost please post the problem and I will help you the best I can.......
I dont think I missed anything. If I did we will address it when the time comes. Remember, this is a guide to get you started. I suggest you try to use
Google to find other kernel threads that has building information and so on.......
A special thanks to the following folks:
Especially to my bro @ShinySide for getting me starting in the kernel bizz
@halaszk for his awesome build script
@UpInTheAir for various code source and BUILD SCRIPTS
And of course.....ME
Telegram Invite
https://telegram.me/joinchat/DnmUJwsL2XJPvYYSezOnfA
XDA:DevDB Information
How to build a Samsung Kernel, Kernel for the Samsung Galaxy S6
Contributors
The Sickness
Kernel Special Features:
Version Information
Status: Stable
Created 2016-08-02
Last Updated 2016-08-01
Attachments
Last edited: