Building and booting Nexus 5 kernel

1. Downloading toolchain and setup.

git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/

2. Downloading kernel source code :

$git clone https://android.googlesource.com/kernel/msm.git
looking into kernel version : 3.4.0-gd59db4e
$git checkout -b android-msm-hammerhead-3.4-kitkat-mr1 origin/android-msm-hammerhead-3.4-kitkat-mr1

switch to this branch; otherwise doesn't compile yet.
$make ARCH=arm SUBARCH=arm hammerhead_defconfig
$make -j16 ARCH=arm SUBARCH=arm CROSS_COMPILE=arm-eabi- 2>&1 | tee build.out
alias makenexus5="make -j16 ARCH=arm KCFLAGS=-ggdb3 CROSS_COMPILE=arm-eabi-"

```
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
CAT     arch/arm/boot/zImage-dtb
Kernel: arch/arm/boot/zImage-dtb is ready 
```
    copy arch/arm/boot/zImage-dtb being the kernel for boot.img.

3. Repacking Android image:

https://github.com/xiaolu/mkbootimg_tools.git
please read the readme.md by youself.

4. Flashing the custom kernel

let's try and check if it works or not.
Connect your phone using USB cable to your PC, 
be sure that you have USB debugging enabled.

$ adb start-server
	* daemon not running. starting it now on port 5037 *
	* daemon started successfully *
$ adb reboot bootloader ; fastboot flash boot boot.img

ref :

http://marcin.jabrzyk.eu/posts/2014/05/building-and-booting-nexus-5-kernel
http://pete.akeo.ie/2013/10/compiling-and-running-your-own-android.html

原文地址:https://www.cnblogs.com/bittorrent/p/8117174.html