如何编译android kernel参考官方文档:https://source.android.com/source/building-kernels.html
在Ubuntu 14.04上编译android kernel也没有遇到什么很难的问题。主要分以下几个步骤:
首先查看emulator的cpu型号: adb shell
root@generic:/ # cat /proc/cpuinfo
Processor : ARMv7 Processor rev 0 (v7l)
BogoMIPS : 378.47
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc08
CPU revision : 0
Hardware : Goldfish
Revision : 0000
Serial : 0000000000000000
Processor : ARMv7 Processor rev 0 (v7l)
BogoMIPS : 378.47
Features : swp half thumb fastmult vfp edsp neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xc08
CPU revision : 0
Hardware : Goldfish
Revision : 0000
Serial : 0000000000000000
1、下载Android内核源代码:
/data/data/Android$ mkdir kernel
/data/data/Android$ cd kernel
/data/data/Android/kernel$ git clone https://android.googlesource.com/kernel/goldfish.git
/data/data/Android/kernel/goldfish$ git branch -a
/data/data/Android/kernel/goldfish$ git checkout -b android-goldfish-3.4 remotes/origin/android-goldfish-3.4
2、设置环境变量:
/data/data/Android/kernel/goldfish$ export ARCH=arm
/data/data/Android/kernel/goldfish$ export SUBARCH=arm
/data/data/Android/kernel/goldfish$ export CROSS_COMPILE=arm-eabi-
3、将交叉编译工具添加到PATH :
/data/data/Android/kernel/goldfish$ export PATH=$PATH:/data/data/Android/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin
4、修改 硬件配置文件goldfish_defconfig(注:arm v5则为goldfish_defconfig, arm v7则为goldfish_armv7_defconfig):
/data/data/Android/kernel/goldfish$ make goldfish_armv7_defconfig
5、执行编译:
/data/data/Android/kernel/goldfish$ make
6、编译成功:
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
Kernel: arch/arm/boot/zImage is ready
注意:标红的地方特别需要注意两者需要一致,否则会导致启动模拟器时一直黑屏!
如何让模拟器使用编译好的kernel,参考另一片文章:http://www.cnblogs.com/tanlon/p/4279157.html