How 2 Build Android Kernel
How 2 Build Android Kernel
How 2 Build Android Kernel
Albe96
Senior Member
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.
Part – I
Setting Up Your Build Environment
Open The Terminal and Paste following Command!
Code:
Code:
sudo apt-get install git ccache automake lzop bison gperf build-essential zip curl zlib1g-dev
PART-I.II
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:
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!
Code:
sudo apt-get install phablet-tools
Code:
git clone <the link that you copied from github> android/kernel
For Me I Type The Following -->>
Code:
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!
Albe96
Senior Member
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
Well,I'm Not Gonna Spam Or Do Somethings Like This,Here's A Simple Guide By @The Flash To Upstream!
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 -->>
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 -->>
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
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 governo
Code:
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>"
Code:
git fetch <anyname>
Code:
B.
1.In Terminal Type -->>
Code:
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]
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.
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
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
Code:
config CPU_VOLTAGE_TABLE
bool "Enable CPU Voltage Table via sysfs for adjustements"
default n
help
Krait User Votlage Control
int i, len = 0;
if (buf) {
mutex_lock(&driver_lock);
mutex_unlock(&driver_lock);
}
return len;
}
int i;
unsigned int new_vdd_uv;
mutex_lock(&driver_lock);
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 */
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
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:
Code:
selinux_enforcing = enforcing ? 1 : 0;
3. Change It To -->>
Code:
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")
Albe96
Senior Member
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:
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
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)
Code:
repackimg.sh
Albe96
Senior Member
Mentions:
@LahKeda For Always Being With Me. (My AOSP Teacher) Log in
@The Flash
@MZO
New posts Manufacturers What's new Search forums Members
@krasCGQ
@flar2
@jazba
MZO
Senior Member
Albe96
krasCGQ
Inactive Recognized Contributor
Albe96 said:
6.And You're Done! Where You'll Find The zImage?
When Building Finished,The Terminal Will Show The Directory!
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
Albe96
Senior Member
krasCGQ said:
Click to expand...
ARM64 only:
Albe96
Senior Member
Aug 10, 2017 #8
MZO said:
But There's So New Though.I Just Explained My Guide To Help Some Noobs ?
clmenz
C New member
Sep 4, 2017 #9
Louis1977
Senior Member
clmenz said:
bartys
B Senior Member
Nov 19, 2017 #11
luisgonzales1977
Albe96
Senior Member
lolnwl said:
ashwini215
A Senior Member
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).
Attachments
README_Kernel.txt
Albe96
Senior Member
ashwini215 said:
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).
the error you're saying me is not a error I assume.Post full error log so I can look into it
nikkali25
Senior Member
Albe96
Senior Member
nikkali25
nikkali25
Senior Member
Albe96 said:
ashwini215
A Senior Member
Albe96 said:
the error you're saying me is not a error I assume.Post full error log so I can look into it
hightech316
Senior Member
I do notice that a bunch of folders / file's modified date has updated throughout the kernels source code folder .
Albe96
Senior Member
hightech316 said:
I do notice that a bunch of folders / file's modified date has updated throughout the kernels source code folder .
Share:
Similar threads
Albe96
26
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.
Albe96
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
Albe96
18
How To Build The Kernel?
Code:
export CROSS_COMPILE=$(pwd)/bin/<toolchain_prefix>-
Albe96
9
Mentions:
krasCGQ
3
Albe96 said:
6.And You're Done! Where You'll Find The zImage?
When Building Finished,The Terminal Will Show The Directory!
NEW POSTS
Install One UI 6 (Android 14) beta on unsupported countries - Thread for all supported
How To Guide
Galaxy models
Latest: Aizenvalt · 2 minutes ago
Samsung Galaxy S23 Ultra
M General AWGJ - AUG | GALAXY S23 Ultra 5G | Official Firmware (SM-S918B) | 6th August
Latest: mirceaandrei · 9 minutes ago
Samsung Galaxy S23 Ultra
[ROM][OFFICIAL] Paranoid Android Topaz Stable 4 - POCO F2 Pro / Redmi K30 Pro / Redmi K30 Pro Zoom
Edition [lmi/lmipro]
Latest: mickaelmendes50 · 10 minutes ago
Xiaomi Poco F2 Pro (Redmi K30 Pro) ROMs, Kernels,
XDA Developers was founded by developers, for developers. It is now a valuable resource for people who want to
make the most of their mobile devices, from customizing the look and feel to adding new functionality.
Crafted by Audentio
Receive the freshest Android & development news right in your inbox!
your@email
XDA - Dark