This page details how to build only the kernel. The following instructions assume you have not downloaded all of AOSP; if you have already done so, you can skip the git clone steps except the step that downloads the kernel sources.

All examples in this section use the hikey kernel.

Selecting a kernel

This table lists the name and locations of the kernel sources and binaries:
Device Binary location Source location Build configuration
marlin device/google/marlin-kernel kernel/msm marlin_defconfig
sailfish device/google/marlin-kernel kernel/msm marlin_defconfig
hikey device/linaro/hikey-kernel kernel/hikey-linaro hikey_defconfig
angler device/huawei/angler-kernel kernel/msm angler_defconfig
bullhead device/lge/bullhead-kernel kernel/msm bullhead_defconfig
shamu device/moto/shamu-kernel kernel/msm shamu_defconfig
fugu device/asus/fugu-kernel kernel/x86_64 fugu_defconfig
volantis device/htc/flounder-kernel kernel/tegra flounder_defconfig
hammerhead device/lge/hammerhead-kernel kernel/msm hammerhead_defconfig
flo device/asus/flo-kernel/kernel kernel/msm flo_defconfig
deb device/asus/flo-kernel/kernel kernel/msm flo_defconfig
manta device/samsung/manta/kernel kernel/exynos manta_defconfig
mako device/lge/mako-kernel/kernel kernel/msm mako_defconfig
grouper device/asus/grouper/kernel kernel/tegra tegra3_android_defconfig
tilapia device/asus/grouper/kernel kernel/tegra tegra3_android_defconfig
maguro device/samsung/tuna/kernel kernel/omap tuna_defconfig
toro device/samsung/tuna/kernel kernel/omap tuna_defconfig
panda device/ti/panda/kernel kernel/omap panda_defconfig
stingray device/moto/wingray/kernel kernel/tegra stingray_defconfig
wingray device/moto/wingray/kernel kernel/tegra stingray_defconfig
crespo device/samsung/crespo/kernel kernel/samsung herring_defconfig
crespo4g device/samsung/crespo/kernel kernel/samsung herring_defconfig

After determining the device project you want to work with, view the git log for the kernel binary. Device projects use the form device/VENDOR/NAME.

git clone https://android.googlesource.com/kernel/hikey-linaro
cd hikey-linaro
git log --max-count=1 kernel

The commit message for the kernel binary contains a partial git log of the kernel sources used to build the binary. The first entry in the log is the most recent (the one used to build the kernel). Make a note of the commit message as you will need it in a later step.

Identifying kernel version

To determine the kernel version used in a system image, run the following command against the kernel file:

dd if=kernel bs=1 skip=$(LC_ALL=C grep -a -b -o $'\x1f\x8b\x08\x00\x00\x00\x00\x00' kernel | cut -d ':' -f 1) | zgrep -a 'Linux version'

For Nexus 5 (hammerhead), the command is:

dd if=zImage-dtb bs=1 skip=$(LC_ALL=C od -Ad -x -w2 zImage-dtb | grep 8b1f | cut -d ' ' -f1 | head -1) | zgrep -a 'Linux version'

Downloading sources

Download the source for the kernel you want to build using the appropriate git clone command. For example, the following command clones the common kernel, a generic, customizable kernel:

git clone https://android.googlesource.com/kernel/common

A full list of the kernel projects can be found in the Kernel directory. Below are some of the commonly used kernels and their respective git clone commands.

The exynos project has the kernel sources for Nexus 10, and can be used as a starting point for work on Samsung Exynos chipsets.

git clone https://android.googlesource.com/kernel/exynos

The goldfish project contains the kernel sources for the emulated platforms.

git clone https://android.googlesource.com/kernel/goldfish

The hikey-linaro project is used for HiKey reference boards, and can be used as a starting point for work on HiSilicon 620 chipsets.

git clone https://android.googlesource.com/kernel/hikey-linaro

The msm project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6, Nexus 5X, Nexus 6P, Nexus 7 (2013), Pixel, and Pixel XL, and can be used as a starting point for work on Qualcomm MSM chipsets.

git clone https://android.googlesource.com/kernel/msm

The omap project is used for PandaBoard and Galaxy Nexus, and can be used as a starting point for work on TI OMAP chipsets.

git clone https://android.googlesource.com/kernel/omap

The samsung project is used for Nexus S, and can be used as a starting point for work on Samsung Hummingbird chipsets.

git clone https://android.googlesource.com/kernel/samsung

The tegra project is for Xoom, Nexus 7 (2012), Nexus 9, and can be used as a starting point for work on NVIDIA Tegra chipsets.

git clone https://android.googlesource.com/kernel/tegra

The x86_64 project has the kernel sources for Nexus Player, and can be used as a starting point for work on Intel x86_64 chipsets.

git clone https://android.googlesource.com/kernel/x86_64

Building the kernel

When you know the last commit message for a kernel and have successfully downloaded the kernel source and prebuilt gcc, you are ready to build the kernel. The following build commands use the hikey kernel:

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-android-
cd hikey-linaro
git checkout -b android-hikey-linaro-4.1 origin/android-hikey-linaro-4.1
make hikey_defconfig
make

To build a different kernel, simply replace hikey-linaro with the name of the kernel you want to build.

The image outputs to the arch/arm64/boot/Image directory; the kernel binary outputs to the arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb fle. Copy the Image directory and the hi6220-hikey.dtb file to the hikey-kernel directory.

Alternatively, you can include the TARGET_PREBUILT_KERNEL variable while using make bootimage (or any other make command line that builds a boot image). This variable is supported by all devices as it is set up via device/common/populate-new-device.sh. For example:

export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage-dtb

Note: Kernel names differ by device. To locate the correct filename for your kernel, refer to device/VENDOR/NAME in the kernel source.