page.title=Building Kernels @jd:body
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 panda kernel.
This table lists the name and locations of the kernel sources and binaries:
| Device | Binary location | Source location | Build configuration |
|---|---|---|---|
| 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/device/ti/panda
$ cd panda
$ 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.
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'
Download the source for the kernel you want to build using the appropriate
git clone command:
$ git clone https://android.googlesource.com/kernel/common.git
$ git clone https://android.googlesource.com/kernel/x86_64.git
$ git clone https://android.googlesource.com/kernel/exynos.git
$ git clone https://android.googlesource.com/kernel/goldfish.git
$ git clone https://android.googlesource.com/kernel/msm.git
$ git clone https://android.googlesource.com/kernel/omap.git
$ git clone https://android.googlesource.com/kernel/samsung.git
$ git clone https://android.googlesource.com/kernel/tegra.git
goldfish project contains the kernel sources for the emulated
platforms.msm project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6,
Nexus 5X, Nexus 6P,
and can be used as a starting point for work on Qualcomm MSM chipsets.omap project is used for PandaBoard and Galaxy Nexus,
and can be used as a starting point for work on TI OMAP chipsets.samsung project is used for Nexus S,
and can be used as a starting point for work on Samsung Hummingbird chipsets.tegra project is for Xoom, Nexus 7, Nexus 9,
and can be used as a starting point for work on NVIDIA Tegra chipsets.exynos project has the kernel sources for Nexus 10,
and can be used as a starting point for work on Samsung Exynos chipsets.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.Ensure the prebuilt toolchain is in your path:
$ export PATH=$(pwd)/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
or
$ export PATH=$(pwd)/prebuilts/gcc/darwin-x86/arm/arm-eabi-4.6/bin:$PATH
On a Linux host, if you don't have an Android source tree, you can download the prebuilt toolchain from:
$ git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6
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 panda kernel:
$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-
$ cd omap
$ git checkout <commit_from_first_step>
$ make panda_defconfig
$ make
To build a different kernel, simply replace panda with the name
of the kernel you want to build.
The kernel binary is output as arch/arm/boot/<kernel_name>
and can be copied into the Android source tree to build the matching boot image.
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.