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
wget http://nokiaphones-opensource.azureedge.net/download/phones/Nokia6.1_V2.22J.tar.bz2 && tar xvjf Nokia6.1_V2.22J.tar.bz2 && cd kernel
git init && git add --all && git commit -m "Initial Commit"
git remote add caf https://source.codeaurora.org/quic/la/kernel/msm-4.4/ && git fetch caf
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.
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
#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"