FORUMS
Remove All Ads from XDA

[GUIDE][WIP]Working with Android Kernel from Scratch [Qualcomm]

928 posts
Thanks Meter: 2,125
 
Thread Closed Email Thread
Introduction:

This guide is still in WIP. I am writing this guide as I was unable to find a well-documented thread over XDA (there are just a lot of them). In case there is anything that concerns this guide, feel free to ask in this thread. I expect you to know the basics of Linux, GIT, Android. Please look over some guides in the forum in case you are not familiar with them.

Checking Current CAF Tag of the Kernel:

We will be using best_kernel for this purpose, whose aim is to compare your current kernel source code with different CAF tags and select the best possible match using git diff.

Clone/Download your kernel repo and commit your changes(if not already committed) as best_kernel depends upon git diff to compare changes.
Depending upon your kernel version, add required CAF kernel repo as remote and fetch it. best_kernel will use this fetched data to compare changes.
After fetch is done, run best_kernel. It should run automatically if you have placed dotfiles in $BIN directory and have necessary dependencies installed.
best_kernel will compare changes and will provide results based on that. However, depending on the number of tags, it will take time. A lot of time, so go and grab a cup of coffee till then.


A Dummy Example:

Downloading stock kernel source code from OEM’s website

Code:
wget http://nokiaphones-opensource.azureedge.net/download/phones/Nokia6.1_V2.22J.tar.bz2 && tar xvjf Nokia6.1_V2.22J.tar.bz2 && cd kernel
Adding and committing all files due to lack of a .git dir.

Code:
git init && git add --all && git commit -m "Initial Commit"
As the kernel source code version is 4.4, I will add 4.4 remotes from CAF and fetch it.

Code:
git remote add caf https://source.codeaurora.org/quic/la/kernel/msm-4.4/ && git fetch caf
After fetch, I will check for the current CAF tag using best_kernel. As my device platform is sdm660 and CAF has been releasing sdm660 tags as sdm660.0, I will be using it as an argument in best_kernel. This will ensure that best_kernel doesn’t waste time checking CAF Tags of other platforms and will speed up the process considerably.

Code:
best_kernel "*sdm660.0"
RESULT will be something like this:

Code:
Best match TAG: LA.UM.6.2.r1-06900-sdm660.0 Lines changed: 177924




Creating/Importing GIT History for Kernel Source

A lot of OEM's releases kernel sources in a compressed format excluding the .git dir which results in no git history. Creating or it's better to say to import one is really simple and easy.

Download and check the current CAF tag of your Android kernel source.
Based on that CAF tag, download the respective kernel repository from CAF and checkout for that specific tag.
Copy and paste your downloaded kernel source (with no history) over the CAF one (which has the history of that CAF tag).
Commit the changes.

You have successfully accomplished creating/importing history.


A Dummy Example:

My current CAF tag is LA.UM.6.2.r1-06900-sdm660.0.
Therefore, cloning kernel source from CAF and checking out for this tag while creating a new branch named rebase.

Code:
git clone https://source.codeaurora.org/quic/la/kernel/msm-4.4/
cd msm-4.4/
git checkout tags/LA.UM.6.2.r1-06900-sdm660.0 -b rebase
Now, I will copy paste the kernel source that I downloaded from OEM's website over the CAF one. Assuming the downloaded kernel is in ~/Downloads/kernel and CAF kernel source is in ~/msm-4.4 directories.

Code:
#Renaming the dir so, that it will get merged while copying due to similar names
mv kernel/ msm-4.4/
cp -avr msm-4.4/ ~/msm-4.4
cd ~/msm-4.4
git status
git commit -m "Import Nokia Kernel Source"
Keep in mind that a .gitignore is generated which can and will ignore files during commit which were not getting ignored earlier due to its absence. In case during compilation you encounter any error stating about missing file, add it forcefully and commit again.
The Following 2 Users Say Thank You to TheImpulson For This Useful Post: [ View ] Gift TheImpulson Ad-Free
 
 
11th March 2019, 12:11 PM |#2  
TheImpulson's Avatar
OP Recognized Contributor
Flag Bhilai, India
Thanks Meter: 2,125
 
More
Reserved
The Following User Says Thank You to TheImpulson For This Useful Post: [ View ] Gift TheImpulson Ad-Free
11th March 2019, 12:11 PM |#3  
TheImpulson's Avatar
OP Recognized Contributor
Flag Bhilai, India
Thanks Meter: 2,125
 
More
Reserved (2)
The Following User Says Thank You to TheImpulson For This Useful Post: [ View ] Gift TheImpulson Ad-Free
11th March 2019, 12:50 PM |#4  
SakilMondal's Avatar
Senior Member
Flag Kolkata
Thanks Meter: 153
 
Donate to Me
More
Wew many thanks,
10th May 2019, 10:41 PM |#5  
abhishekr700's Avatar
Senior Member
Flag New Delhi
Thanks Meter: 759
 
Donate to Me
More
Thanks
Have just started exploring xda chef central.
I cam across this guide, really ahlepful Hope you complete it soon.
Thread Closed Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes