[Guide][Noobs Familiar]How To Build Android Kernel With Features!

Search This thread

Albe96

Senior Member
Mar 10, 2016
3,023
4,088
kernel-logo-600.png


What Is Kernel?
The kernel is a computer program that is the core of a computer's operating system, with complete control over everything in the system.[1] It is the first program loaded on start-up. It handles the rest of start-up as well as input/output requests from software, translating them into data-processing instructions for the central processing unit. It handles memory and peripherals like keyboards, monitors, printers, and speakers.

Is There A Connection Between Kernel And Android?
Haha,Sorry but yes.Kernel is the main component for Android.Basically Android devices use the Linux kernel, but it's not the exact same kernel other Linux-based operating systems use. There's a lot of Android specific code built in, and Google's Android kernel maintainers have their work cut out for them. OEMs have to contribute as well, because they need to develop hardware drivers for the parts they're using for the kernel version they're using. This is why it takes a while for independent Android developers and hackers to port new versions to older devices and get everything working. Drivers written to work with the Gingerbread kernel on a phone won't necessarily work with the Ice Cream Sandwich kernel. And that's important, because one of the kernel's main functions is to control the hardware. It's a whole lot of source code, with more options while building it than you can imagine, but in the end it's just the intermediary between the hardware and the software. So basically if any instruction is given to mobile it first gives the command to kernel for the particular task execution.​



Ah It's Work Time! Lets Get Started!​

Part – I​
Setting Up Your Build Environment​
Open The Terminal and Paste following Command!

Upgrade The Built-In Environments!
Code:
sudo apt-get update && sudo apt-get upgrade

Install Required Tools.
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


PART-I.II​
Get The Kernel Source!​
Now When It Comes About Kernel Source,Where You'll Find That?

No Worries,Search In Your Device Open Source Projects Websites To Get The Source OR You May Met With Github. Search In Github For Kernel Source For Your Device!

Here Are Some Sites,Where You Can Download Kernel Source Though:

For HTC: http://www.htcdev.com/
For Samsung: http://opensource.samsung.com/
For Sony: http://developer.sonymobile.com/wportal/devworld/search-downloads/opensource
For LG: http://opensource.lge.com/index

Note: If You've Download The Source Then Extract It In A Directory. Or If You Want To Clone/Download Source From Github Then Follow Next Steps!


How To Download/Clone Kernel Source From Github?​
To Clone From Github,You Have To Install Repo Tool!

A. Open The Terminal and Paste Following Command!
Code:
sudo apt-get install phablet-tools

1. To Clone Go To Your Kernel Source Page.Like This -->>
DzuPYiD.jpg


2.Then Click On Clone Or Download Button,And Copy The Link!
yXuzXUQ.jpg



B. Open A Terminal And Type This Command!
Code:
git clone <the link that you copied from github> android/kernel

For Me I Type The Following -->>
Code:
git clone https://github.com/Alberteno/android_kernel_samsung_on7xelte.git android/kernel

ezi8OJI.jpg



Explaination:
1. <the link that you copied from github> -->> Replace With The Link You Copied From Github To Clone The Source!
2. android/kernel ->> This Is My Directory Where I Want To Clone It!

C. Done.You Cloned The Source!
 

Albe96

Senior Member
Mar 10, 2016
3,023
4,088
Part-II
How To Add Features To Kernel?
Ah.So Here I'm With Following Guides.What We're Gonna Learn Today?.Lets Go Ahed.

Here are some features you can add via cherry-picking.Check out those-> https://forum.xda-developers.com/showpost.php?p=77089212&postcount=41


How To Upstream Android Kernel?
Well,I'm Not Gonna Spam Or Do Somethings Like This,Here's A Simple Guide By @The Flash To Upstream!

Here Is The Link-->> [url]https://forum.xda-developers.com/android/software-hacking/reference-how-to-upstream-android-kernel-t3626913[/URL]




How To Add I/O Scheduler Or Governor To Kernel?
To Add Governor Or I/O Scheduler To Kernel,You Have To Learn Cherry-Picking! Well,I'm Not Gonna Make A Tutorial For That![Or Maybe I'll].For Now Follow What I Say In Next Steps.

A.
1. So Basically There's Many Governors/IO Schedulers Available In Internet To Add.Choose One Governor,Well I Choosed Nightmare Governor For Example. I'm Showing How To Add A Governor In The Guide.

2. Now What You Have To Do Is To Go To Github,And Type "Add Nightmare Governor" In Search Bar Then Hit Enter.
3. You'll Get Some Many Results,Open One Of Them That Include Many Files About The Governor.Like This -->>
9osJIUl.jpg


4. Now Where You'll Find The Commit ID To Cherry-Pick It To Your Kernel Source? See Below Pick To Get Idea Which One Is The Idea -->>
9osJIUl.jpg


5.Yay,So You Got It! Now Open A Terminal And Go To Your Kernel Source Folder! For Me I Typed -->>
Code:
cd android/kernel

ZSSlKDE.jpg


6. Now To Cherry-Pick You Have To Fetch The Kernel Source From Which You'll Cherry-Pick.To Do That Type Following In Terminal -- >>
Code:
git remote add <anyname> <link of the kernel source from which you're taking the governor commit>

For Me I Typed This -->>
Code:
git remote add lol [url]https://github.com/B14CKB1RD-Kernel/B14CKB1RD_Kernel_OnePlus3_Unified.git[/url]

Explaination:
1. <anyname> - What Ever You Want.
2. <link of the kernel source from which you're taking the governor commit> - Where You'll Find? Check Below Image.The Blue Selected Image In URL Bar Is the "<link of the kernel source from which you're taking the governor commit>"
eC37nbL.jpg


7.Then Type This In Terminal -->>
Code:
git fetch <anyname>

For Me I Typed This -->>
Code:
git fetch lol

B.
1.In Terminal Type -->>
Code:
 git cherry-pick <commit id>

For Me I Typed This Change <commit id> with the id you copied from github-->>
[code]git cherry-pick 042b5123de94e9875e717efb0ac1d344fdf2282e

2.Now You'll Get Some Conflicts,How To Solve Them? Use This Guide By @jabza .
Here Is The Guide -->> [url]https://forum.xda-developers.com/showthread.php?t=2763236[/URL]

3.Solve The Conflicts And You're Done Adding Governor To Kernel!




How To Add Support Force Fast Charging?(Only For Snapdragon Devices)

1. In Kernel Source Go To "arch/arm/mach-msm" Folder.
2. Then Open The "Kconfig" File And The Following Code -->>

Code:
config FORCE_FAST_CHARGE
	bool "Force AC charge mode at will"
	default y
	help
	  A simple sysfs interface to force adapters that
	  are detected as USB to charge as AC.

3. Save It,Then Open "Makefile" And Add The Following Code-->>
Code:
obj-$(CONFIG_FORCE_FAST_CHARGE) += fastchg.o

4. Save The Makefile,Now Create/Add The Fast Charge File In That Directory! Where Is That File? Here Is It -->> Here

5. Now Go To kernel source/drivers/usb/otg directory And Open "msm_otg.c" File, And Add The Following Code -->>
Code:
#ifdef CONFIG_FORCE_FAST_CHARGE
#include <linux/fastchg.h>
#define USB_FASTCHG_LOAD 1000 /* uA */
#endif

And This Code -->>
Code:
#ifdef CONFIG_FORCE_FAST_CHARGE
	if (force_fast_charge == 1) {
			mA = USB_FASTCHG_LOAD;
			pr_info("USB fast charging is ON - 1000mA.\n");
	} else {
		pr_info("USB fast charging is OFF.\n");
	}
#endif

6. Save msm_otg.c File.Now Go To "include/linux" Directory And Add "fastchg.h" File.Here's The Link For That File -->> Here

7. Well Done You've Added Force Fast Charging Support! :fingers-crossed:



How To Add Support Voltage Control For MSM Devices?
1. Go To arch/arm/mach-msm Folder,And Open "Kconfig" File,And Add Following Codes-->>
Code:
config CPU_VOLTAGE_TABLE
	bool "Enable CPU Voltage Table via sysfs for adjustements"
	default n
	help
	  Krait User Votlage Control

2.Save Kconfig File.Now open "acpuclock-krait.c" File.Add This Code-->>
Code:
#ifdef CONFIG_CPU_VOLTAGE_TABLE

#define HFPLL_MIN_VDD		 800000
#define HFPLL_MAX_VDD		1350000

ssize_t acpuclk_get_vdd_levels_str(char *buf) {

	int i, len = 0;

	if (buf) {
		mutex_lock(&driver_lock);

		for (i = 0; drv.acpu_freq_tbl[i].speed.khz; i++) {
			/* updated to use uv required by 8x60 architecture - faux123 */
			len += sprintf(buf + len, "%8lu: %8d\n", drv.acpu_freq_tbl[i].speed.khz,
				drv.acpu_freq_tbl[i].vdd_core );
		}

		mutex_unlock(&driver_lock);
	}
	return len;
}

/* updated to use uv required by 8x60 architecture - faux123 */
void acpuclk_set_vdd(unsigned int khz, int vdd_uv) {

	int i;
	unsigned int new_vdd_uv;

	mutex_lock(&driver_lock);

	for (i = 0; drv.acpu_freq_tbl[i].speed.khz; i++) {
		if (khz == 0)
			new_vdd_uv = min(max((unsigned int)(drv.acpu_freq_tbl[i].vdd_core + vdd_uv),
				(unsigned int)HFPLL_MIN_VDD), (unsigned int)HFPLL_MAX_VDD);
		else if ( drv.acpu_freq_tbl[i].speed.khz == khz)
			new_vdd_uv = min(max((unsigned int)vdd_uv,
				(unsigned int)HFPLL_MIN_VDD), (unsigned int)HFPLL_MAX_VDD);
		else 
			continue;

		drv.acpu_freq_tbl[i].vdd_core = new_vdd_uv;
	}
	pr_warn("faux123: user voltage table modified!\n");
	mutex_unlock(&driver_lock);
}
#endif	/* CONFIG_CPU_VOTALGE_TABLE */

3.Save The File.Done! You've Added It To Your Kernel. :)




How To Add Init.d Support To Kernel?
1. Copy Your boot.img To A Folder In Ubuntu And Open A Terminal With boot.img directory.
2. Now Type The Following In Terminal -->>
Code:
abootimg -x boot.img

3. You'll Get 3 Files From It(bootimg.cfg, initrd.img, zImage)

4. Now Create A New Work Folder And Decompress "initrd.img" Using The Following Commands -->>
Code:
mkdir work
cd work
zcat ../initrd.img | cpio -i

5. Now Open The Work Folder.Now Open The "init.rc" File And Add This Line At The End Of This File -->>
Code:
# Execute files in /etc/init.d during boot
service userinit /system/xbin/busybox run-parts /system/etc/init.d
       oneshot
       class late_start
       user root
       group root

6.Save "init.rc" File And You're Done!

Or Try This Guide By @alireza7991 -->> Here :laugh:



How To Make Kernel Boot In Permissive Mode(A Small Guide)
1. Go To "Kernel Source/security/selinux" Folder And Open "hooks.c".

2. Find This Line -->>
Code:
selinux_enforcing = enforcing ? 1 : 0;

3. Change It To -->>
Code:
selinux_enforcing = 0;// enforcing ? 1 : 0;

4. Now Save "hooks.c" File.Now Open "selinuxfs.c" File And Search For This Line -->>
Code:
if (new_value != selinux_enforcing) {

5. Add Below Code Above "if (new_value != selinux_enforcing) {" line -->>
Code:
new_value = 0;

6. Yo.You Finally Made The Kernel Boot In Permissive Mode,To Check If It Got Permissive Or Not -->> Go To Settings -> About Phone -> SE-Linux Status (You'll See Its "Permissive")
 
Last edited:

Albe96

Senior Member
Mar 10, 2016
3,023
4,088
How To Build The Kernel?

1. Clone A Toolchain That Supports Your Device[
2. Point the Makefile To Your Compiler (run this from within the toolchain folder!!)
Code:
export CROSS_COMPILE=$(pwd)/bin/<toolchain_prefix>-

Example:
Code:
export CROSS_COMPILE=$(pwd)/bin/aarch64-linux-android-

3. Tell Makefile About The Architecture Of Your Device Using This Command -->>
Code:
export ARCH=<arch> && export SUBARCH=<arch>

Example:
Code:
export ARCH=arm64 && export SUBARCH=arm64

4. Locate Your Proper Defconfig File.Where You Will Found That?
Go To "arch/<arch>/configs" Folder,And There You'll Find A Defconfig File Along With Your Device Codename Like For S7 Edge, Its --> "exynos8890_hero2lte-defconfig"

5. Now Come Back To Main Kernel Source Directory Then Enter These Command To Start Building!
Code:
make clean
make mrproper
make <defconfig_name>
make -s -j$(nproc --all) [B][U]Or[/U][/B] make zImage -j4

6.And You're Done! Where You'll Find The zImage?
When Building Finished,The Terminal Will Show The Directory!


How To Flash The zImage?

1. Pull Your Device's Boot Image From The Latest Image Available For Your Device (Whether It Be A ROM Or Stock).
2. Download The Latest Android Image Kitchen From This thread
3. Run The Following With The Boot Image:
Code:
unpackimg.sh <image_name>.img
4. Locate The New zImage File And Replace It With Your Kernel Image (rename it to what came out of the boot image)

5. Run The Following To Repack:
Code:
repackimg.sh

6. Flash The New Boot Image With TWRP!​
 
Last edited:

krasCGQ

Recognized Contributor
Apr 13, 2015
5,436
4,953
21
Kendari
kud.my.id
Xiaomi Mi 9 SE
6.And You're Done! Where You'll Find The zImage?
When Building Finished,The Terminal Will Show The Directory!
It won't if you use -s switch after make :p
Which will silent the output!

The resulting kernel image will be located at:
ARM: arch/arm/boot/zImage(-dtb)
ARM64: arch/arm64/boot/Image.gz(-dtb)
x86: arch/x86/boot/bzImage(-dtb)

ARM64 only:
If kernel image creation fails, complaining missing dtb, symlink dtb from ARM dts folder:
Code:
$ ln -s ../../../arm/boot/dts/<dtb-name>.dtb arch/arm64/boot/dts/<dtb-name>.dtb

Sent from my Redmi 3 using XDA Labs
 
Last edited:

Albe96

Senior Member
Mar 10, 2016
3,023
4,088
It won't if you use -s switch after make :p
Which will silent the output!

The resulting kernel image will be located at:
ARM: arch/arm/boot/zImage(-dtb)
ARM64: arch/arm64/boot/Image.gz(-dtb)
x86: arch/x86/boot/bzImage(-dtb)

ARM64 only:
If kernel image creation fails, complaining missing dtb, symlink dtb from ARM dts folder:
Thanks you sir! Will Update It Soon!
 

ashwini215

Senior Member
Nov 17, 2014
376
97
Mumbai
Hi @Albe96
Can you please help me compile?
I have Samsung J7 prime SM-G610F (nougat).
I Have downloaded GCC "arm-linux-androideabi-4.9" ( as written in the readme_kernel.txt file of kernel source).

I am not sure if my device is 32-bit or 64-bit.
The readme_kernel.txt file points to 64-bit architecture so I am assuming its 64-bit.

Now the problem:-
When compiling as per your codes, when I type:
make clean,
I'm getting the error "make: *** No rule to make target 'clean'. Stop." and same for every other code after that.

Attaching the readme_kernel.txt file for your reference.
 

Attachments

  • README_Kernel.txt
    715 bytes · Views: 44

Albe96

Senior Member
Mar 10, 2016
3,023
4,088
Hi @Albe96
Can you please help me compile?
I have Samsung J7 prime SM-G610F (nougat).
I Have downloaded GCC "arm-linux-androideabi-4.9" ( as written in the readme_kernel.txt file of kernel source).

I am not sure if my device is 32-bit or 64-bit.
The readme_kernel.txt file points to 64-bit architecture so I am assuming its 64-bit.

Now the problem:-
When compiling as per your codes, when I type:
make clean,
I'm getting the error "make: *** No rule to make target 'clean'. Stop." and same for every other code after that.

Attaching the readme_kernel.txt file for your reference.
the error you're saying me is not a error I assume.Post full error log so I can look into it
 

ashwini215

Senior Member
Nov 17, 2014
376
97
Mumbai
the error you're saying me is not a error I assume.Post full error log so I can look into it

So, I corrected my previous mistake and finally was able to compile :)

Towards the end of compilation, I got this message :

/scripts/fips_crypto_utils.c: In function ‘main’:
./scripts/fips_crypto_utils.c:28:7: warning: implicit declaration of function ‘strcmp’ [-Wimplicit-function-declaration]
if (!strcmp ("-u", argv[1]))
^~~~~~
./scripts/fips_crypto_utils.c:52:10: warning: implicit declaration of function ‘update_crypto_hmac’ [-Wimplicit-function-declaration]
return update_crypto_hmac (vmlinux_file, hmac_file, offset);
^~~~~~~~~~~~~~~~~~
./scripts/fips_crypto_utils.c:82:10: warning: implicit declaration of function ‘collect_crypto_bytes’ [-Wimplicit-function-declaration]
return collect_crypto_bytes (in_file, section_name, offset, size, out_file);
^~~~~~~~~~~~~~~~~~~~
HMAC-SHA256(builtime_bytes.bin)= 80387d4cca5322a3de63d73fe615c492385801c8ae36494795eda733492d5a10
OBJCOPY arch/arm64/boot/Image
GZIP arch/arm64/boot/Image.gz

Is this anything to be concerned about?
Can I flash the kernel?

Have added the complete log.
 
Last edited:

hightech316

Senior Member
Jan 27, 2011
1,222
204
github.com
OnePlus 8T
I was able to complete with no errors! ( after running into a dozen )

Although I cannot find zimage anywhere.

I do notice that a bunch of folders / file's modified date has updated throughout the kernels source code folder .

I am building a Samsung exynos 7850 kernel .

Thanks for this great write up!
 

Albe96

Senior Member
Mar 10, 2016
3,023
4,088
I was able to complete with no errors! ( after running into a dozen )

Although I cannot find zimage anywhere.

I do notice that a bunch of folders / file's modified date has updated throughout the kernels source code folder .

I am building a Samsung exynos 7850 kernel .

Thanks for this great write up!
It should be inside arch/(arm/arm64)/boot folder
 

Top Liked Posts

  • There are no posts matching your filters.
  • 26
    kernel-logo-600.png


    What Is Kernel?
    The kernel is a computer program that is the core of a computer's operating system, with complete control over everything in the system.[1] It is the first program loaded on start-up. It handles the rest of start-up as well as input/output requests from software, translating them into data-processing instructions for the central processing unit. It handles memory and peripherals like keyboards, monitors, printers, and speakers.

    Is There A Connection Between Kernel And Android?
    Haha,Sorry but yes.Kernel is the main component for Android.Basically Android devices use the Linux kernel, but it's not the exact same kernel other Linux-based operating systems use. There's a lot of Android specific code built in, and Google's Android kernel maintainers have their work cut out for them. OEMs have to contribute as well, because they need to develop hardware drivers for the parts they're using for the kernel version they're using. This is why it takes a while for independent Android developers and hackers to port new versions to older devices and get everything working. Drivers written to work with the Gingerbread kernel on a phone won't necessarily work with the Ice Cream Sandwich kernel. And that's important, because one of the kernel's main functions is to control the hardware. It's a whole lot of source code, with more options while building it than you can imagine, but in the end it's just the intermediary between the hardware and the software. So basically if any instruction is given to mobile it first gives the command to kernel for the particular task execution.​



    Ah It's Work Time! Lets Get Started!​

    Part – I​
    Setting Up Your Build Environment​
    Open The Terminal and Paste following Command!

    Upgrade The Built-In Environments!
    Code:
    sudo apt-get update && sudo apt-get upgrade

    Install Required Tools.
    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


    PART-I.II​
    Get The Kernel Source!​
    Now When It Comes About Kernel Source,Where You'll Find That?

    No Worries,Search In Your Device Open Source Projects Websites To Get The Source OR You May Met With Github. Search In Github For Kernel Source For Your Device!

    Here Are Some Sites,Where You Can Download Kernel Source Though:

    For HTC: http://www.htcdev.com/
    For Samsung: http://opensource.samsung.com/
    For Sony: http://developer.sonymobile.com/wportal/devworld/search-downloads/opensource
    For LG: http://opensource.lge.com/index

    Note: If You've Download The Source Then Extract It In A Directory. Or If You Want To Clone/Download Source From Github Then Follow Next Steps!


    How To Download/Clone Kernel Source From Github?​
    To Clone From Github,You Have To Install Repo Tool!

    A. Open The Terminal and Paste Following Command!
    Code:
    sudo apt-get install phablet-tools

    1. To Clone Go To Your Kernel Source Page.Like This -->>
    DzuPYiD.jpg


    2.Then Click On Clone Or Download Button,And Copy The Link!
    yXuzXUQ.jpg



    B. Open A Terminal And Type This Command!
    Code:
    git clone <the link that you copied from github> android/kernel

    For Me I Type The Following -->>
    Code:
    git clone https://github.com/Alberteno/android_kernel_samsung_on7xelte.git android/kernel

    ezi8OJI.jpg



    Explaination:
    1. <the link that you copied from github> -->> Replace With The Link You Copied From Github To Clone The Source!
    2. android/kernel ->> This Is My Directory Where I Want To Clone It!

    C. Done.You Cloned The Source!
    18
    Part-II
    How To Add Features To Kernel?
    Ah.So Here I'm With Following Guides.What We're Gonna Learn Today?.Lets Go Ahed.

    Here are some features you can add via cherry-picking.Check out those-> https://forum.xda-developers.com/showpost.php?p=77089212&postcount=41


    How To Upstream Android Kernel?
    Well,I'm Not Gonna Spam Or Do Somethings Like This,Here's A Simple Guide By @The Flash To Upstream!

    Here Is The Link-->> [url]https://forum.xda-developers.com/android/software-hacking/reference-how-to-upstream-android-kernel-t3626913[/URL]




    How To Add I/O Scheduler Or Governor To Kernel?
    To Add Governor Or I/O Scheduler To Kernel,You Have To Learn Cherry-Picking! Well,I'm Not Gonna Make A Tutorial For That![Or Maybe I'll].For Now Follow What I Say In Next Steps.

    A.
    1. So Basically There's Many Governors/IO Schedulers Available In Internet To Add.Choose One Governor,Well I Choosed Nightmare Governor For Example. I'm Showing How To Add A Governor In The Guide.

    2. Now What You Have To Do Is To Go To Github,And Type "Add Nightmare Governor" In Search Bar Then Hit Enter.
    3. You'll Get Some Many Results,Open One Of Them That Include Many Files About The Governor.Like This -->>
    9osJIUl.jpg


    4. Now Where You'll Find The Commit ID To Cherry-Pick It To Your Kernel Source? See Below Pick To Get Idea Which One Is The Idea -->>
    9osJIUl.jpg


    5.Yay,So You Got It! Now Open A Terminal And Go To Your Kernel Source Folder! For Me I Typed -->>
    Code:
    cd android/kernel

    ZSSlKDE.jpg


    6. Now To Cherry-Pick You Have To Fetch The Kernel Source From Which You'll Cherry-Pick.To Do That Type Following In Terminal -- >>
    Code:
    git remote add <anyname> <link of the kernel source from which you're taking the governor commit>

    For Me I Typed This -->>
    Code:
    git remote add lol [url]https://github.com/B14CKB1RD-Kernel/B14CKB1RD_Kernel_OnePlus3_Unified.git[/url]

    Explaination:
    1. <anyname> - What Ever You Want.
    2. <link of the kernel source from which you're taking the governor commit> - Where You'll Find? Check Below Image.The Blue Selected Image In URL Bar Is the "<link of the kernel source from which you're taking the governor commit>"
    eC37nbL.jpg


    7.Then Type This In Terminal -->>
    Code:
    git fetch <anyname>

    For Me I Typed This -->>
    Code:
    git fetch lol

    B.
    1.In Terminal Type -->>
    Code:
     git cherry-pick <commit id>
    
    For Me I Typed This Change <commit id> with the id you copied from github-->>
    [code]git cherry-pick 042b5123de94e9875e717efb0ac1d344fdf2282e

    2.Now You'll Get Some Conflicts,How To Solve Them? Use This Guide By @jabza .
    Here Is The Guide -->> [url]https://forum.xda-developers.com/showthread.php?t=2763236[/URL]

    3.Solve The Conflicts And You're Done Adding Governor To Kernel!




    How To Add Support Force Fast Charging?(Only For Snapdragon Devices)

    1. In Kernel Source Go To "arch/arm/mach-msm" Folder.
    2. Then Open The "Kconfig" File And The Following Code -->>

    Code:
    config FORCE_FAST_CHARGE
    	bool "Force AC charge mode at will"
    	default y
    	help
    	  A simple sysfs interface to force adapters that
    	  are detected as USB to charge as AC.

    3. Save It,Then Open "Makefile" And Add The Following Code-->>
    Code:
    obj-$(CONFIG_FORCE_FAST_CHARGE) += fastchg.o

    4. Save The Makefile,Now Create/Add The Fast Charge File In That Directory! Where Is That File? Here Is It -->> Here

    5. Now Go To kernel source/drivers/usb/otg directory And Open "msm_otg.c" File, And Add The Following Code -->>
    Code:
    #ifdef CONFIG_FORCE_FAST_CHARGE
    #include <linux/fastchg.h>
    #define USB_FASTCHG_LOAD 1000 /* uA */
    #endif

    And This Code -->>
    Code:
    #ifdef CONFIG_FORCE_FAST_CHARGE
    	if (force_fast_charge == 1) {
    			mA = USB_FASTCHG_LOAD;
    			pr_info("USB fast charging is ON - 1000mA.\n");
    	} else {
    		pr_info("USB fast charging is OFF.\n");
    	}
    #endif

    6. Save msm_otg.c File.Now Go To "include/linux" Directory And Add "fastchg.h" File.Here's The Link For That File -->> Here

    7. Well Done You've Added Force Fast Charging Support! :fingers-crossed:



    How To Add Support Voltage Control For MSM Devices?
    1. Go To arch/arm/mach-msm Folder,And Open "Kconfig" File,And Add Following Codes-->>
    Code:
    config CPU_VOLTAGE_TABLE
    	bool "Enable CPU Voltage Table via sysfs for adjustements"
    	default n
    	help
    	  Krait User Votlage Control

    2.Save Kconfig File.Now open "acpuclock-krait.c" File.Add This Code-->>
    Code:
    #ifdef CONFIG_CPU_VOLTAGE_TABLE
    
    #define HFPLL_MIN_VDD		 800000
    #define HFPLL_MAX_VDD		1350000
    
    ssize_t acpuclk_get_vdd_levels_str(char *buf) {
    
    	int i, len = 0;
    
    	if (buf) {
    		mutex_lock(&driver_lock);
    
    		for (i = 0; drv.acpu_freq_tbl[i].speed.khz; i++) {
    			/* updated to use uv required by 8x60 architecture - faux123 */
    			len += sprintf(buf + len, "%8lu: %8d\n", drv.acpu_freq_tbl[i].speed.khz,
    				drv.acpu_freq_tbl[i].vdd_core );
    		}
    
    		mutex_unlock(&driver_lock);
    	}
    	return len;
    }
    
    /* updated to use uv required by 8x60 architecture - faux123 */
    void acpuclk_set_vdd(unsigned int khz, int vdd_uv) {
    
    	int i;
    	unsigned int new_vdd_uv;
    
    	mutex_lock(&driver_lock);
    
    	for (i = 0; drv.acpu_freq_tbl[i].speed.khz; i++) {
    		if (khz == 0)
    			new_vdd_uv = min(max((unsigned int)(drv.acpu_freq_tbl[i].vdd_core + vdd_uv),
    				(unsigned int)HFPLL_MIN_VDD), (unsigned int)HFPLL_MAX_VDD);
    		else if ( drv.acpu_freq_tbl[i].speed.khz == khz)
    			new_vdd_uv = min(max((unsigned int)vdd_uv,
    				(unsigned int)HFPLL_MIN_VDD), (unsigned int)HFPLL_MAX_VDD);
    		else 
    			continue;
    
    		drv.acpu_freq_tbl[i].vdd_core = new_vdd_uv;
    	}
    	pr_warn("faux123: user voltage table modified!\n");
    	mutex_unlock(&driver_lock);
    }
    #endif	/* CONFIG_CPU_VOTALGE_TABLE */

    3.Save The File.Done! You've Added It To Your Kernel. :)




    How To Add Init.d Support To Kernel?
    1. Copy Your boot.img To A Folder In Ubuntu And Open A Terminal With boot.img directory.
    2. Now Type The Following In Terminal -->>
    Code:
    abootimg -x boot.img

    3. You'll Get 3 Files From It(bootimg.cfg, initrd.img, zImage)

    4. Now Create A New Work Folder And Decompress "initrd.img" Using The Following Commands -->>
    Code:
    mkdir work
    cd work
    zcat ../initrd.img | cpio -i

    5. Now Open The Work Folder.Now Open The "init.rc" File And Add This Line At The End Of This File -->>
    Code:
    # Execute files in /etc/init.d during boot
    service userinit /system/xbin/busybox run-parts /system/etc/init.d
           oneshot
           class late_start
           user root
           group root

    6.Save "init.rc" File And You're Done!

    Or Try This Guide By @alireza7991 -->> Here :laugh:



    How To Make Kernel Boot In Permissive Mode(A Small Guide)
    1. Go To "Kernel Source/security/selinux" Folder And Open "hooks.c".

    2. Find This Line -->>
    Code:
    selinux_enforcing = enforcing ? 1 : 0;

    3. Change It To -->>
    Code:
    selinux_enforcing = 0;// enforcing ? 1 : 0;

    4. Now Save "hooks.c" File.Now Open "selinuxfs.c" File And Search For This Line -->>
    Code:
    if (new_value != selinux_enforcing) {

    5. Add Below Code Above "if (new_value != selinux_enforcing) {" line -->>
    Code:
    new_value = 0;

    6. Yo.You Finally Made The Kernel Boot In Permissive Mode,To Check If It Got Permissive Or Not -->> Go To Settings -> About Phone -> SE-Linux Status (You'll See Its "Permissive")
    18
    How To Build The Kernel?

    1. Clone A Toolchain That Supports Your Device[
    2. Point the Makefile To Your Compiler (run this from within the toolchain folder!!)
    Code:
    export CROSS_COMPILE=$(pwd)/bin/<toolchain_prefix>-

    Example:
    Code:
    export CROSS_COMPILE=$(pwd)/bin/aarch64-linux-android-

    3. Tell Makefile About The Architecture Of Your Device Using This Command -->>
    Code:
    export ARCH=<arch> && export SUBARCH=<arch>

    Example:
    Code:
    export ARCH=arm64 && export SUBARCH=arm64

    4. Locate Your Proper Defconfig File.Where You Will Found That?
    Go To "arch/<arch>/configs" Folder,And There You'll Find A Defconfig File Along With Your Device Codename Like For S7 Edge, Its --> "exynos8890_hero2lte-defconfig"

    5. Now Come Back To Main Kernel Source Directory Then Enter These Command To Start Building!
    Code:
    make clean
    make mrproper
    make <defconfig_name>
    make -s -j$(nproc --all) [B][U]Or[/U][/B] make zImage -j4

    6.And You're Done! Where You'll Find The zImage?
    When Building Finished,The Terminal Will Show The Directory!


    How To Flash The zImage?

    1. Pull Your Device's Boot Image From The Latest Image Available For Your Device (Whether It Be A ROM Or Stock).
    2. Download The Latest Android Image Kitchen From This thread
    3. Run The Following With The Boot Image:
    Code:
    unpackimg.sh <image_name>.img
    4. Locate The New zImage File And Replace It With Your Kernel Image (rename it to what came out of the boot image)

    5. Run The Following To Repack:
    Code:
    repackimg.sh

    6. Flash The New Boot Image With TWRP!​
    9
    Mentions:

    @LahKeda For Always Being With Me. (My AOSP Teacher) :)
    @The Flash
    @MZO
    @krasCGQ
    @flar2
    @jazba

    And All Devs Being With Me! :)
    3
    6.And You're Done! Where You'll Find The zImage?
    When Building Finished,The Terminal Will Show The Directory!
    It won't if you use -s switch after make :p
    Which will silent the output!

    The resulting kernel image will be located at:
    ARM: arch/arm/boot/zImage(-dtb)
    ARM64: arch/arm64/boot/Image.gz(-dtb)
    x86: arch/x86/boot/bzImage(-dtb)

    ARM64 only:
    If kernel image creation fails, complaining missing dtb, symlink dtb from ARM dts folder:
    Code:
    $ ln -s ../../../arm/boot/dts/<dtb-name>.dtb arch/arm64/boot/dts/<dtb-name>.dtb

    Sent from my Redmi 3 using XDA Labs