[Nexus 6P Original Android Development] nathanchance:
How to build ElementalX MM with the Dirty Cow fix and the SafetyNet bypass patches

Hey guys, a lot of people have been asking for a Marshmallow update even though flar2 has said that he won't update further (as Google is no longer supporting Marshmallow). However, that doesn't mean you have to be left in the dark! You yourself can update the kernel yourself with the help of this guide and a computer.

Prerequisites: A computer with Linux (you can use VirtualBox if you cannot dual boot - use this guide to get the packages you need)

GUIDE:

Download the ElementalX source

git clone https://github.com/flar2/angler ElementalX
cd ElementalX
git checkout ElementalX-1.00

Explanation:

The first command clones the ElementalX source from Github onto your computer into a folder named ElementalX

The second command moves you into this folder

The third command puts you onto the Marshmallow branch (since the Nougat branch is the default)

Download the toolchain

cd .. && git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9
cd aarch64-linux-android-4.9
export CROSS_COMPILE=$(pwd)/bin/aarch64-linux-android-
export ARCH=arm64 && export SUBARCH=arm64

Explanation:

The first command clones the toolchain (a set of compilers) into a folder named aarch64-linux-android-4.9

The second command moves you into that folder

The third command points the Makefile of the kernel to your compiler (as we cannot compile an arm64 kernel using an x86 gcc, which is mostly what your computer will use)

The fourth and fifth command tell the compiler which architecture we are compiling for (arm64)

NOTE: if you want to compile with another toolchain like Linaro or Uber, you must use 4.9; the kernel does not include support for gcc 5, 6, or 7 (although it can be added with some commits)

Download the AnyKernel source (optional)

If you want Aroma support, you can unzip the last MM kernel and replace the elex.Image in the boot folder with your own that we are about to compile. Otherwise, follow the steps below to clone my AnyKernel source.

cd .. && git clone https://github.com/Flash-Kernel/AnyKernel2
cd AnyKernel2
git checkout angler-decrypt

Explanation:

The second command clones the AnyKernel2 repo onto your computer

The second command moves you into that folder

The third command checks out the basic Angler branch (if you don't want force encryption or dm-verity disabled, use the angler-stock branch instead)

Fetch the SafetyNet and Dirty Cow patches

cd ../ElementalX
git fetch https://github.com/sultanxda/android_kernel_oneplus_msm8996 cm-13.0-sultan
git cherry-pick abc05b16bbd33521c2fffaf491c5657a94bfcfc5
git fetch git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux-3.10.y
git cherry-pick 9691eac5593ff1e2f82391ad327f21d90322aec1

Explanation:

The first command moves us into the ElementalX source folder

The second and fourth commands fetch the repo containing the patches that we want; the format for this command is git fetch <repo_url> <branch_containing_patch>

The third and fifth commands merge the commit into our source; the format for this command is git cherry-pick <commit_hash>

If you ever mess something up, you can go back to the base repo state by running the following command: git reset --hard origin/ElementalX-1.00; this will reset the repo back to its state at the origin (Github).

Make the kernel!

If you want to edit the kernel version to show that it is updated, you can open the arch/arm64/configs/elementalx_defconfig in the ElementalX source folder and modify the LOCALVERSION line.

make clean && make mrproper
make elementalx_defconfig
make -j$(grep -c ^processor /proc/cpuinfo)

Explanation:

The first and second commands make sure there are no lingering files (which can sometimes be committed to Github)

The third command tells the kernel what modules and features we want (predefined in the elementalx_defconfig file)

The fourth command makes the kernel; the command after the j flag tells the compiler to use all available threads to make the kernel

Package the kernel

If you are using my AnyKernel2 source:

mv -v arch/arm64/boot/Image.gz-dtb ../AnyKernel2/zImage-dtb
cd ../AnyKernel2
zip -r9 [i]whatevernameyouwant[/i].zip * -x README [i]whatevernameyouwant[/i].zip

If you are using the Aroma zip:

mv -v arch/arm64/boot/Image.gz-dtb [i]aroma_zip_location[/i]/boot/elex.Image
cd [i]aroma_zip_location[/i]
zip -r9 [i]whatevernameyouwant[/i].zip *

Explanation:

The first command moves the completed kernel image into the zip with the proper name and location

The second command moves you into the zip folder

The third command zips up the kernel with the proper name and files

If you have any questions or issues with this, please private message me instead of posting here (the one time I will offer technical support) as this is not something flar2 will support or help with. This is purely to cut down on the number of Marshmallow update requests.