Building Android's Kernel

Linux Kernel

For the most part, developing your device drivers is the same as developing a typical Linux device driver. Android uses a specialized version of the Linux kernel with a few special additions such as wakelocks, a memory management system that is more aggressive in preserving memory, the Binder IPC driver, and other features that are important for a mobile embedded platform like Android. These additions have less to do with driver development than with the system's functionality. You can use any version of the kernel that you want as long as it supports the required features, such as the binder driver. However, we recommend using the latest version of the Android kernel. For the latest Android kernel, see Building Kernels.


Figuring out which kernel to build

This table lists the name and locations of the kernel sources and binaries:
DeviceBinary locationSource locationBuild configuration
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
You will want to look at the git log for the kernel binary in the device project that you are interested in.
Device projects are of the form device//.
$ 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 that were used to build the binary in question. 

Identifying kernel version


$ 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'

$ bzgrep -a 'Linux version' vmlinux.bz2

Downloading sources


Depending on which kernel you want,
$ git clone https://android.googlesource.com/kernel/common.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, 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 and Nexus 7, 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.

Downloading a prebuilt gcc


Ensure that the prebuilt toolchain is in your path.
$ export PATH=$(pwd)/prebuilts/gcc/linux-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


As an example, we would build the panda kernel using the following commands:
$ export ARCH=arm
$ export SUBARCH=arm
$ export CROSS_COMPILE=arm-eabi-
$ cd omap
$ git checkout 
$ make panda_defconfig
$ make
To build the tuna kernel, you may run the previous commands replacing all instances of "panda" with "tuna".
The kernel binary is output as: `arch/arm/boot/zImage` It can be copied into the Android source tree in order to build the matching boot image.
Or you can include the TARGET_PREBUILT_KERNEL variable while using make bootimage or any other make command line that builds a boot image.

$ export TARGET_PREBUILT_KERNEL=$your_kernel_path/arch/arm/boot/zImage
That variable is supported by all devices as it is set up via device/common/populate-new-device.sh

Creating Your Own Androidized Kernel (http://www.linaro.org/linaro-blog/2012/03/20/androidization-of-linux-kernel/)

To add the Android patches to 3.2 Linux kernel for Vexpress-rtsm.
How to create an Androidized kernel using the git rebase command. Androidization process was just 4 step process:
1. Clone the Linux kernel and create a branch for androidization :
    To clone the repository then work on the remote branch "arm/vexpressdt-rtsm" locally:
git clone http://git.linaro.org/git/people/dmart/linux-3-arm.git   -b   arm/vexpressdt-rtsm

    Create an switch to the local branch android:
git   checkout   -b   android

2. Add the remote topic branch:
    To add the remote server repository "androidization":
git   remote   add   androidization   git://git.linaro.org/landing-teams/working/ti/kernel.git
3. Fetch and rebase the kernel:
    To fetch everything the remote server "androidization"  has:
git fetch androidization
    To rebase
git   rebase   remotes/androidization/linaro-androidization-tracking
4. Add the necessary configs to the board-defconfig file to enable Android components in the kernel:
CONFIG_ASHMEM=y
CONFIG_STAGING=y
CONFIG_ANDROID=y
CONFIG_ANDROID_BINDER_IPC=y
CONFIG_ANDROID_LOGGER=y
CONFIG_ANDROID_RAM_CONSOLE=y
CONFIG_ANDROID_LOW_MEMORY_KILLER=y
Additionally I had to set “CONFIG_VMSPLIT_3G=y” for Android to boot on vexpress RTSM/Fastmodel.
The androidization patches are usually provided by Google but was not available for 3.2 kernel. For people working on 3.3 kernel, androidization patches are available from Google at:
https://android.googlesource.com/kernel/common.git for the Android-3.3 branch.

留言

熱門文章