Android源码编译(8)---编译内核

来源:互联网 发布:金税盘开票数据导出 编辑:程序博客网 时间:2024/05/19 05:04

Building Kernels

IN THIS DOCUMENT

  1. Selecting a kernel
  2. Identifying kernel version
  3. Downloading sources
  4. Downloading a prebuilt gcc
  5. Building the kernel

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:

DeviceBinary locationSource locationBuild configurationhikeydevice/linaro/hikey-kernelkernel/hikey-linarohikey_defconfiganglerdevice/huawei/angler-kernelkernel/msmangler_defconfigbullheaddevice/lge/bullhead-kernelkernel/msmbullhead_defconfigshamudevice/moto/shamu-kernelkernel/msmshamu_defconfigfugudevice/asus/fugu-kernelkernel/x86_64fugu_defconfigvolantisdevice/htc/flounder-kernelkernel/tegraflounder_defconfighammerheaddevice/lge/hammerhead-kernelkernel/msmhammerhead_defconfigflodevice/asus/flo-kernel/kernelkernel/msmflo_defconfigdebdevice/asus/flo-kernel/kernelkernel/msmflo_defconfigmantadevice/samsung/manta/kernelkernel/exynosmanta_defconfigmakodevice/lge/mako-kernel/kernelkernel/msmmako_defconfiggrouperdevice/asus/grouper/kernelkernel/tegrategra3_android_defconfigtilapiadevice/asus/grouper/kernelkernel/tegrategra3_android_defconfigmagurodevice/samsung/tuna/kernelkernel/omaptuna_defconfigtorodevice/samsung/tuna/kernelkernel/omaptuna_defconfigpandadevice/ti/panda/kernelkernel/omappanda_defconfigstingraydevice/moto/wingray/kernelkernel/tegrastingray_defconfigwingraydevice/moto/wingray/kernelkernel/tegrastingray_defconfigcrespodevice/samsung/crespo/kernelkernel/samsungherring_defconfigcrespo4gdevice/samsung/crespo/kernelkernel/samsungherring_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:

$ git clone https://android.googlesource.com/kernel/common.git$ git clone https://android.googlesource.com/kernel/hikey-linaro$ 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
  • The goldfish project contains the kernel sources for the emulated platforms.
  • The msm project has the sources for ADP1, ADP2, Nexus One, Nexus 4, Nexus 5, Nexus 6, Nexus 5X, Nexus 6P, Nexus 7 (2013), and can be used as a starting point for work on Qualcomm MSM chipsets.
  • The omap project is used for PandaBoard and Galaxy Nexus, and can be used as a starting point for work on TI OMAP chipsets.
  • The samsung project is used for Nexus S, and can be used as a starting point for work on Samsung Hummingbird chipsets.
  • 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.
  • The exynos project has the kernel sources for Nexus 10, and can be used as a starting point for work on Samsung Exynos chipsets.
  • 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.
  • The hikey-linaro project is used for HiKey reference boards, and can be used as a starting point for work on HiSilicon 620 chipsets.

Downloading a prebuilt gcc


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

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 thearch/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 makecommand line that builds a boot image). This variable is supported by all devices as it is set up viadevice/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 todevice/<vendor>/<name> in the kernel source.

0 0