[REFERENCE/TEMPLATE] Marlin Kernel clang template - Google Pixel XL ROMs, Kernels, Recoveries, & Other

Clang Kernel template for Marlin/Sailfish​
What is this?
This is a marlin clang template that can be used to create kernels that compile using clang toolchains. It has all the commits by @nathanchance that optimize clang for the Pixel and XL models
What Does this Mean for me?
The 4.x kernels use clang as a toolchain for compilation. Our kernel is 3.18.x, we do not immediately use clang for compilation. GCC is the key part when compiling a 3.18.x kernel. Using clang adds battery and stability improvements (which I have observed). People are readily adopting clang as a compiler and I just want to ease the workload to cherry pick all the commits required to run clang on a marlin or sailfish device.
Where can I find it?
It is found in my git repository linked here: https://github.com/kingbri1/MarlinClangRef
How Do I use it?
All you do is clone it and look at @nathanchance's guide on how to compile with clang https://github.com/nathanchance/android-kernel-clang
Updates
I will be updating this kernel base to the latest security patches and versions, nothing more, nothing less
Thanks to...
@razorloves -I used his kernel base
@nathanchance for putting the time in to create the commits for clang to be used on Pixels and other devices
Want to collaborate?
Feel free to private message me or email me at [email protected] so we can sort out the details

Related

Request linaro 4.7.1 toolchain CM9

I invite all community members with experience in compilation, testing with Linaro 4.7.1 toolchain,
know that the previous version and instability caused incopatibilidad CM9, but I think the new Linaro 4.7.1 toolchain is compatible,
Here is a link as a reference for a dev to compile your kernel and CM9, and works great.
http://forum.xda-developers.com/showthread.php?t=1630023
I think this may be possible, those who support this project by CM9 rom faster and have the benefits Linaro.​
LINARO INFORMATION​
Kernels can be compiled with Linaro toolchain, really nothing new. CM9 source code needs to be modified to compile with Linaro, IMO it isn't worth it. Also, why in the hell do we need any OpenWRT-related Linaro patch?

[Dev][Kernel][2.04] Stock source + Linux upstream commits

I've seen at least 5 people now apply patches to the kernel source code to bring it up to a more recent version. To save the 6th and subsequent person from doing so, I pushed up a "clean" version of the stock (1.15, of course) kernel source code after merging in all linux mainline commits. FYI, to do so and preserve the history, I do:
git merge --strategy=ours v3.4.10
git merge v3.4.11
..
and resolve the conflicts as I go. There is a readme that explains (without having tested the procedure, so let me know if it needs to be tweaked) how to use to to patch an existing kernel source. This also serves as a good base if you want to start building a completely new kernel or if you want to compare your conflict resolutions to my conflict resolutions.
I plan to continue to update this with upstream patches as they are released as I will be using this to do my own merging of upstream commits.
The source is at http://github.com/crpalmer/dna-kernel-plus-upstream.
The branch "stock" contains the HTC released source code and also includes a commit that restores many of the comments that HTC stripped out of the source code when they released the 2.04 release. This should be much easier to merge with existing commits and make a more easily patched base of a kernel than what HTC released.
crpalmer said:
I've seen at least 5 people now apply patches to the kernel source code to bring it up to a more recent version. To save the 6th and subsequent person from doing so, I pushed up a "clean" version of the stock (1.15, of course) kernel source code after merging in all linux mainline commits. FYI, to do so and preserve the history, I do:
git merge --strategy=ours v3.4.10
git merge v3.4.11
..
and resolve the conflicts as I go. There is a readme that explains (without having tested the procedure, so let me know if it needs to be tweaked) how to use to to patch an existing kernel source. This also serves as a good base if you want to start building a completely new kernel or if you want to compare your conflict resolutions to my conflict resolutions.
I plan to continue to update this with upstream patches as they are released as I will be using this to do my own merging of upstream commits.
The source is at http://github.com/crpalmer/dna-kernel-plus-upstream.
Click to expand...
Click to collapse
this is awesome man thanks
Re: [Dev][Kernel][3.4.38] Stock source + Linux upstream commits
Sweet. Thanks man.
Sent from my HTC Droid DNA
Merged in the 2.04 source drop.
The branch "stock" contains the HTC released source code and also includes a commit that restores many of the comments that HTC stripped out of the source code when they released the 2.04 release. This should be much easier to merge with existing commits and make a more easily patched base of a kernel than what HTC released.
If you've already done your own merge (zarboz), you may want to try cherrypicking this commit:
https://github.com/crpalmer/dna-kernel-plus-upstream/commit/c81741a8337c2342d856ffeac0cc087452729290
Excellent Thanks for this, it's very handy
crpalmer said:
Merged in the 2.04 source drop.
The branch "stock" contains the HTC released source code and also includes a commit that restores many of the comments that HTC stripped out of the source code when they released the 2.04 release. This should be much easier to merge with existing commits and make a more easily patched base of a kernel than what HTC released.
If you've already done your own merge (zarboz), you may want to try cherrypicking this commit:
https://github.com/crpalmer/dna-kernel-plus-upstream/commit/c81741a8337c2342d856ffeac0cc087452729290
Click to expand...
Click to collapse
I looked through all my rej files and they were all comments I personally didn't care about lol
Thanks for the update though

[RESOURCE][TOOLCHAINS] Repo friendly Toolchains.

I've been following all the wonderful guides for building and compiling; but I've been having trouble finding the exact locations of the toolchains.
So I'd like to share my manifest for the same.
The repo tool can be used for getting all the toolchains [that I know] in one go for ease of development,
https://github.com/HaoZeke/Android-ToolChains
The instructions are given there.
All credits to the actual developers.
Currently Synced
Uber ToolChains [48, 4.9, 5.1, 5.2, 6.0*]
Hyper-Toolchains {SaberNaro 4.8**, LinaroMod 4.8**, LinaroMod 4.9**} (Linaormod 4.9*, SaberNaro 4.9*)
Linaro [4.8, 4.9, 5.1, 5.2]
Archidroid [5.2]
Sabermod [4.8**, 4.9**]
* --> Kernel Only
** --> Rom Only
Use a local_manifests/del.xml to remove unecessary toolchains.
Click to expand...
Click to collapse
Please feel free to push changes & additions!!

M Kernel reference (3.10.92, Interactive, Wireless branches)

Hi.
Just sharing this for reference for them who wants to:
- Build a linux mainline up-to-date kernel (3.10.y). Builds fine with some reverts and no other kernel commits. Updated straight on M kernel (3.10.40). (branch 'mainline'). Easy to maintain and update yourself when linux mainline is updated.
- Build with interactive governor from 3.18 kernel. (branch 'interactive')
- Build with an up to date wireless driver from: https://android.googlesource.com/kernel/common/+log/bcmdhd-3.10. (branch 'wireless')
All three sorted in respective branches at https://github.com/PerLycke/kernel_moto_shamu
And all of those branches are independent, all applied on pure M (r26) source, so merge away!
Master branch is the branch I'm using personally, so that's not a reference. Or sort off. If you like what I like (very stockish).
Cheers
pemell
@pemell
This is great! Thanks for sharing your work! I too tried to merge all the way to .96 and ended up with no sound lol. Regardless, I will be working on basing my new Shamu kernel off of your work. It looks great! Thanks again!

[GUIDE]Working with Android Kernel from Scratch

Introduction
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. In case you want to contribute to this, feel free to do so. I welcome everyone's contribution to be it fixing my derp, pointing a mistake or adding a new section.
Links to some nice documentations:
Git Documentation
Linux Kernel Newbies
How to take logs in Android
How to get an Android kernel up to date with linux-stable
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 the $BIN directory and have the 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
What is CAF/Code Aurora | CodeAurora Android Releases Page | CAF Kernel Sources​
Creating/Importing GIT History for Kernel Source
A lot of OEMs release 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 simple and easy.
Download and check the current CAF tag of your Android kernel source.
Note: If your chipset is not Qualcomm, you should visit Linux Kernel Source or AOSP's Kernel Common and use that as a base while checking out to the specific version of your kernel source you are going to copy-paste. Qualcomm devices can also use that as a ref but I will recommend them to use CAF 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 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.
Remember, its always good to split that one big commit into small parts. It's helpful when you start rebasing your kernel usually when new CAF Tag for new android versions come out. Solving a few conflicts ina lot of commit is much better than solving a load of them in one. It also gives you a chance to easily diff on websites like GitHub so that you can figure what's a particular line is doing.
Doing that is also easy. Just reset head for a particular folder like driver/touchscreen and commit them separately. Check git rebase documentation which will help you with this.
Upstreaming your Kernel
Merging upstream versions is a really good thing. It brings in security patches, stability, new features and much more. The usual and best way is to visit Linux Kernel Source and check if there are upstream updates available. If yes, start merging them in your kernel source one by one.
Note: If your chipset is not Qualcomm, you should visit Linux Kernel Source or AOSP's Kernel Common and use that as a base. Qualcomm devices can also use that as a ref but I will recommend them to use CAF source.
A Dummy Example:
Assuming my current kernel version is v4.4.205, I will fetch v4.4.206 from Linux Kernel Source and merge that. I can also fetch and merge different branches from CAF Source which are usually upstreamed with Linux-stable (for example, aosp/upstream-linux-4.4.y branch)
Code:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git v4.4.206
git merge FETCH_HEAD
Fix conflicts if you get some. What to keep and what not is a question that depends upon the device to device. Usually, you should compare local changes and upstream and try to figure out what could be the best way to fix it. I will advise to check the history of that file in upstream and see which commit caused that conflict and why. You can also check similar merges by other same kernel versions to see if they had the same conflict and how they fixed it.
I will also advise merging AOSP's kernel/common and new CAF upstream tags (Only QCOM devices should merge new CAF tags) regularly when available. The reason is pretty simple. There are commits that get merged in AOSP like which improves performance or other stuff which doesn't get merged in Linux Kernel Source. This way you can get the benefit from all sources. This, however, is not pretty easy and might result in a huge number of conflicts considering if OEM has modified the source a lot from upstream.
CAF also hosts f2fs and other file system changes on their servers. Merge it if you want and use it.
Compiling Standalone Kernel
Compiling a kernel standalone requires you to have a compatible toolchain like GCC or Clang. The best way to figure out which one suits your need is testing and debugging. The standard AOSP GCC toolchains are recommended for devices with old kernels, to begin with, while newer ones can use clang with backports or upstream merges. In case you want to compile with clang, checking out android-kernel-clang is a good way, to begin with.
Compiling standalone kernels can give a lot of missing headers errors/warnings. This is due to not compiling it in a ROM environment. This can be easily fixed either by correcting paths of those header files being included or creating an out dir manually and using it as output. You can also use this commit to do that automatically.
Clone your kernel source and desired toolchain(s). Export arch and cross compiler arguments. Choose the desired defconfig to make and compile.
A Dummy Example:
I will clone the kernel source and toolchain in the same dir and export the following arguments in kernel source root dir.
Code:
export ARCH=arm64
export CROSS_COMPILE=/media/hdd/aayush/kernel/aarch64-elf-gcc/bin/aarch64-elf-
make nokia_defconfig
make -j$(nproc --all)
Kernel conflicts might occur. You can search on GitHub to check if someone has fixed that already, otherwise fix the issues yourself. Comparing code with upstream repositories is also a way to figure out the differences. Choosing defconfig can be a bit tricky if you are doing bringups. I recommend pulling the current defconfig from your device itself. Its usually by the name of config.gz in /proc/ of your device.
Links to some cross compiler
GNU Toolchain by ARM
DragonTC
GNU and Linaro
Working with TWRP from Scratch
This post is supposed to help you with building TWRP from scratch for the first time if you are a newbie. There are some good resources already available for that over the web, specially XDA. I am linking some good ones below that you can read for more info on it.
How to compile TWRP Touch Recovery
The aim of a device tree is to contain the device-specific code for the build you are doing. In this case, as we are building TWRP which is a custom recovery, only flags relating to building TWRP and a normal recovery are enough to build it. Adding system specific codes like partition sizes for the system, vendor, boot and other doesn't contribute anything. An example tree can be begonia's tree hosted on TeamWin's org maintained by me.
Now coming to the device you want to build TWRP for, you will the following :
- A working kernel
- Device-specific binaries/libraries etc required for features like encryption which heavily differs on OEM implementation
AB devices need an extra commit in their kernel to make 'fastboot boot' command work: init: initramfs: disable do_skip_initramfs . Additionally if your device ships a separate DTBO image you will also need the following flag and the DTBO image: begonia: Build DTBO image into recovery
Newer devices are nowadays coming with 'fastboot boot' command disabled. Nokia 8.1 is an example of it. To make it work again, you might need to tweak bootloader which can prove to be risky.
Now coming to creating a device tree for TWRP. The very first step is to look out if someone else has booted TWRP on a similar SOC, OEM or same device. It can be used as a reference to fix similar/OEM related bugs and hacks quickly. In case, one doesn't exist, just pick a latest one from Teamwin's Github org for the android version you are compiling for.
Reserved (2)
Wew many thanks,
Thanks
Have just started exploring xda chef central.
I cam across this guide, really ahlepful Hope you complete it soon.
Updated the thread. Fixed formatting, links and added a new section.
How To Unofficially Unlock Bootloader For LG G8
We all know LG G8 is a android device. It's open source. But I recently bought a LG G8 only but it's locked to sprint sim . No any sim work. I can't unlock bootloader. I can't root. I can't flag firmware or install custom recovery. Anyone know here , how to totally remove firmware and but another firmware ? Why we can't build a method to do that?
TheImpulson said:
Updated the thread. Fixed formatting, links and added a new section.
Click to expand...
Click to collapse
Can you create a guide for, "How to Rebase an Android Kernel". Like from Android 9 to Android 10?
thanks for this guide bro
While using best caf kernel, Prefix of the caf tag should start with a -
For example, "*- sdm660.0"
@theimpulson
Hey there,
Am getting this error del.dog/megupebinu.txt
While trying execute best_kernel script
This is helpful, thanks mate
@theimpulson I had a question: (Before reading this guide) I had already downloaded stock Samsung sources and git init push the thing to my Github. So will anything bad happen if I did it this way or do I have to rebase it with CAF?
Also what are the benefits of these so-called CAF based kernels everywhere? Improved performance? Cuz I really wanted to compile my own kernel specifically for performance with WSL-2 (shameless plug)
Thanks in advance and sorry if the @ bothered you,
Ishaq
NullCode said:
@theimpulson I had a question: (Before reading this guide) I had already downloaded stock Samsung sources and git init push the thing to my Github. So will anything bad happen if I did it this way or do I have to rebase it with CAF?
Also what are the benefits of these so-called CAF based kernels everywhere? Improved performance? Cuz I really wanted to compile my own kernel specifically for performance with WSL-2 (shameless plug)
Thanks in advance and sorry if the @ bothered you,
Ishaq
Click to expand...
Click to collapse
The existing sources are fine, no issues if you are fine without any git history.
SOC specific optimizations, bug fixes etc. Nothing more. So, yeah, if you want SOC specific optimizations, performance improvements, you will want to merge latest CAF tags for your kernel.
theimpulson said:
The existing sources are fine, no issues if you are fine without any git history.
SOC specific optimizations, bug fixes etc. Nothing more. So, yeah, if you want SOC specific optimizations, performance improvements, you will want to merge latest CAF tags for your kernel.
Click to expand...
Click to collapse
thanks a lot for the reply! Another thing, because of your suggestion I tried to Import the git history (and i succeeded). Then I wanted to upload these sources to my own Github, which I can't figure out how to do. It only gives Github repo for the place where it came from (msm-3.18). Help me please
Edit: The guides which I found for merging CAF tags say that my base also has to be CAF (which it isn't) and this guide here basically does not work

Categories

Resources