Building Kernels

来自: http://source.android.com/source/building-kernels.html

 

Building Kernels 

 

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 configuration
hikeydevice/linaro/hikey-kernelkernel/hikey-linarohikey_defconfig
anglerdevice/huawei/angler-kernelkernel/msmangler_defconfig
bullheaddevice/lge/bullhead-kernelkernel/msmbullhead_defconfig
shamudevice/moto/shamu-kernelkernel/msmshamu_defconfig
fugudevice/asus/fugu-kernelkernel/x86_64fugu_defconfig
volantisdevice/htc/flounder-kernelkernel/tegraflounder_defconfig
hammerheaddevice/lge/hammerhead-kernelkernel/msmhammerhead_defconfig
flodevice/asus/flo-kernel/kernelkernel/msmflo_defconfig
debdevice/asus/flo-kernel/kernelkernel/msmflo_defconfig
mantadevice/samsung/manta/kernelkernel/exynosmanta_defconfig
makodevice/lge/mako-kernel/kernelkernel/msmmako_defconfig
grouperdevice/asus/grouper/kernelkernel/tegrategra3_android_defconfig
tilapiadevice/asus/grouper/kernelkernel/tegrategra3_android_defconfig
magurodevice/samsung/tuna/kernelkernel/omaptuna_defconfig
torodevice/samsung/tuna/kernelkernel/omaptuna_defconfig
pandadevice/ti/panda/kernelkernel/omappanda_defconfig
stingraydevice/moto/wingray/kernelkernel/tegrastingray_defconfig
wingraydevice/moto/wingray/kernelkernel/tegrastingray_defconfig
crespodevice/samsung/crespo/kernelkernel/samsungherring_defconfig
crespo4gdevice/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=aach64-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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值