[Nexus 6P Android Development] nathanchance:
How to compile the kernel for yourself

1. Configure your environment

In order to compile this kernel, I'd recommend using Linux (OS X should be acceptable but this guide will be tailored for Linux). To get the environment configured, either use Google's own guide here or my guide (only section 1) here.

2. Grab the source

Grab my AK source

mkdir ~/Android
cd ~/Android
git clone https://github.com/nathanchance/AK-Angler.git AK

Explanation:

First command makes a directory named Android in your home folder (mkdir = make directory). You can change the location if you want but keep it consistent throughout the guide.

Second command moves into that directory (change directory)

Third command pulls the source from my Github into a directory named AK (git clone <url> <folder_to_clone_in_to> is the format of the command).

Grab my AnyKernel source

cd ~/Android
git clone https://github.com/nathanchance/AK-Angler-AnyKernel2 AK-AK2

Explanation:

First command moves into the Android directory we made above (change directory)

Third command pulls the source from my Github into a directory named AK-AK2 (git clone <url> <folder_to_clone_in_to> is the format of the command).

Grab the toolchain you want to use to compile the kernel

cd ~/Android
git clone <kernel_url>

Explanation:

In order to compile the kernel, we need to grab a toolchain (bunch of compilation tools). I currently compile 11 options, you'll only be doing one. Below are the list of possible URLs to clone; copy and paste it after the words git clone above:

AOSP: https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9

Uber 4.9: https://bitbucket.org/DespairFactor/aarch64-linux-android-4.9-kernel.git

Uber 5.4: https://bitbucket.org/DespairFactor/aarch64-linux-android-5.x-kernel.git

Uber 6.1: https://bitbucket.org/DespairFactor/aarch64-linux-android-6.x-kernel.git

Uber 7.0: https://bitbucket.org/DespairFactor/aarch64-linux-android-7.0-kernel.git

Linaro 4.9: https://android-git.linaro.org/git/.../aarch64/aarch64-linux-android-4.9-linaro.git

Linaro 5.4: https://android-git.linaro.org/git/.../aarch64/aarch64-linux-android-5.4-linaro.git

Linaro 6.1: https://android-git.linaro.org/git/.../aarch64/aarch64-linux-android-6.1-linaro.git

DF-Linaro 4.9: https://bitbucket.org/DespairFactor/aarch64-linux-android-4.9-kernel-linaro.git

DF-Linaro 5.4: https://bitbucket.org/DespairFactor/aarch64-linux-android-5.x-kernel-linaro.git

DF-Linaro 6.1: https://bitbucket.org/DespairFactor/aarch64-linux-android-6.x-kernel-linaro.git

3. Setup the build

Make sure everything looks right

After following the above steps, type:

ls

You should see something like this:

aarch64-linux-android-6.x-kernel-linaro AK AK-AK2

The toolchain directory make be different depending on what you cloned above. If it looks different, delete the Android folder and do step 2 again.

Select the correct kernel branch

cd ~/Android/AK
git checkout <branch>

Example:

cd ~/Android/AK
git checkout m-eas

Explanation

First command will move you into the AK source directory we cloned above.

Second command will checkout the branch you want to compile for. A git repo can have multiple branches. For mine, these are the possible options:

m-standard (for the M Normal branch)

m-eas (for the M EAS branch)

m-nethunter (for the M NetHunter branch)

n-testing (for the N Normal branch)

Select the correct AnyKernel branch

cd ~/Android/AK-AK2
git checkout ak-angler-anykernel

Explanation

First command will move you into the AK AnyKernel directory we cloned above. This is what allows you to flash the kernel (thank you very much [MENTION=4544860]osm0sis[/MENTION] for all the work you do).

Second command will checkout the correct branch (in this case, ak-angler-anykernel)

4. Make the kernel

Tell the makefile what toolchain and architecture you are building for

Figure out the full path of your toolchain folder

Assuming you have done this whole process correctly, you can move into your toolchain directory and type:

cd ~/Android/<toolchain_folder>
pwd

Example:

cd ~/Android/aarch64-linux-android-6.x-kernel-linaro
pwd

You should get something like this:

/home/nathanchance/Android/aarch64-linux-android-6.x-kernel-linaro

Tell the compiler where that toolchain is

Copy and paste that file location above into this command:

export CROSS_COMPILE=<toolchain_dir>/bin/aarch64-linux-android-

Example:

export CROSS_COMPILE=/home/nathanchance/Android/aarch64-linux-android-6.x-kernel-linaro/bin/aarch64-linux-android-

Set the architecture

Angler is a 64-bit device so we need arm64

export ARCH=arm64
export SUBARCH=arm64

Clean up from a previous compilation and update the source

cd ~/Android/AK-AK2
git reset --hard origin/ak-angler-anykernel
git clean -f -d -x > /dev/null 2>&1
git pull > /dev/null 2>&1

cd ~/Android/AK
git reset --hard origin/<kernel_branch>
git clean -f -d -x > /dev/null 2>&1
make clean && make mrproper

Example:

cd ~/Android/AK-AK2
git reset --hard origin/ak-angler-anykernel
git clean -f -d -x > /dev/null 2>&1
git pull > /dev/null 2>&1

cd ~/Android/AK
git reset --hard origin/m-standard
git clean -f -d -x > /dev/null 2>&1
make clean && make mrproper
git pull

Explanation:

First set:

The first command moves you into the AK AnyKernel directory.

The second command will undo any local commits you have done and align your source with the most recent commit from me.

The third command will clean any untracked or compiled files (this is send to /dev/null so you do not see it happen).

The fourth command will pull any new AnyKernel changes from me into the source.

Second set:

The first command moves you into the AK source directory.

The second command will undo any local commits you have done and align your source with the most recent commit from me.

The third command will clean any untracked or compiled files (this is send to /dev/null so you do not see it happen).

The fourth and fifth command (strung together with &&) will remove you

The sixth command will pull any new kernel changes from me into the source.

Set up the defconfig

A defconfig tells the compiler which features you want in the kernel. This is already set up by me. To set up the defconfig, type the following:

cd ~/Android/AK
make ak_angler_defconfig

Name the kernel

If you notice in About Phone > Kernel Version, it shows 3.10.102-AK.066-9.UBER4.9 (or something similar). You can customize this like so:

export LOCALVERSION=-"kernel name"

Example:

export LOCALVERSION=-"AK-Nathan-Personal"

Make the kernel!

make -j#

Example:

make -j4

Explanation:

The # after the "j" is how many simultaneous threads are run. Traditionally, this is the number of cores you have plus one. So a quad-core CPU would be -j5.

5. Zip it up and flash!

Copy the zImage to the AnyKernel directory

cd ~/Android/AK/arch/arm64/boot
cp -v Image.gz ~/Android/AK-AK2/zImage

Explanation:

We need to copy the newly compiled kernel (which resides in the arch/arm64/boot folder) to the AnyKernel directory, while changing its name to zImage.

cp = copy

-v = verbose (prints the copying)

Image.gz = file to be copied

~/Android/AK-AK2/zImage = destination and name

Make a current dtb file

cd ~/Android/AK-AK2
tools/dtbToolCM -v2 -o dtb -s 2048 -p ~/Android/AK/scripts/dtc/ ~/Android/AK/arch/arm64/boot/dts/

Explanation:

No explanation, just do it :silly:

Zip it up!

cd ~/Android/AK-AK2
zip -x@zipexclude -r9 ak-kernel.zip *

Using the above commands, your newly completed kernel will be located at ~/Android/AK-AK2/ak-kernel.zip

If you followed all of the above steps successfully, congratulations, you built the kernel!! Once you have done all five steps, you will just need to follow steps 4 and 5 to update in the future. Below, I have linked a script that will do all of this for you (with some variable edits at the top); however, please do it manually first so you know exactly what you are doing :) enjoy!

https://raw.githubusercontent.com/nathanchance/Android-Tools/master/ak.sh