ninjame@ubuntu1604:~/aosp/kernel/msm$ git branch -r --contains 7717f769b2d0bf26db19598d8826a01b82ab6540 origin/android-msm-hammerhead-3.4-marshmallow-mr1 origin/android-msm-hammerhead-3.4-marshmallow-mr2 origin/android-msm-hammerhead-3.4-marshmallow-mr3
7717f76对应着源码中的一个commit节点,可以看做是git库上最小的分支(分支都是从commit节点拉出来的,那么每一个节点都可以看做一个分支,当然某些分支中只包含它自己)
3.4.0-g7717f76 就可以解读为该内核版本大的分支为linux3.4.0,具体的源码对应于commit节点为7717f76 那一次提交代码对应的快照。
2、配置编译环境
由于是在 Linux / Mac OS X 上进行编译,所以交叉编译的环境变量是必须要设置的,一共涉及到三个。
首先设定 ARCH,–注意,由于 Nexus 5 是32位架构,所以取值为 arm,如果是64位,则要取值为 arm64
export ARCH=arm
然后设定 CROSS_COMPILE,同上,64位要取值 aach64-linux-android-
export CROSS_COMPILE=arm-eabi-
对应地,告诉编译系统到哪里寻找编译器
export PATH=$PATH:/home/ninjame/aosp/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin
3、编译
开始编译之前,不要着急开始,先使用 help 看有哪些预定义好的配置
make help
从上面可以找到 hammerhead_defconfig,这正是 Nexus 5 的默认配置
make hammerhead_defconfig
上述就是生成配置,如果需要调整,则可以继续执行
make menuconfig
最后执行编译吧
make
成功编译后,可以看到类似如下的输出:
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
DTC arch/arm/boot/msm8974-hammerhead-rev-11.dtb
DTC arch/arm/boot/msm8974-hammerhead-rev-11j.dtb
DTC arch/arm/boot/msm8974-hammerhead-rev-10.dtb
DTC arch/arm/boot/msm8974-hammerhead-rev-c.dtb
DTC arch/arm/boot/msm8974-hammerhead-rev-b.dtb
DTC arch/arm/boot/msm8974-hammerhead-rev-bn.dtb
DTC arch/arm/boot/msm8974-hammerhead-rev-a.dtb
DTC arch/arm/boot/msm8974-hammerhead-rev-f.dtb
CAT arch/arm/boot/zImage-dtb
Kernel: arch/arm/boot/zImage-dtb is ready
make[1]: Nothing to be done for 'arch/arm/boot/dtbs'.
编译碰到的问题;
问题1:
File "/home/ninjame/aosp/kernel/msm/scripts/gcc-wrapper.py", line 55
print "error, forbidden warning:", m.group(2)
解决:由于本人把机器上的python给改成3.5了,不支持这种print语法
sudo rm /usr/bin/python,删除
sudo ln -s /usr/bin/python2.7 /usr/bin/python,默认设置成python2.7
这样在终端中输入python默认就是 2.7版本了
问题2:
CHK include/linux/version.h
CHK include/generated/utsrelease.h
make[1]: 'include/generated/mach-types.h' is up to date.
CC kernel/bounds.s
arm-eabi-gcc: No such file or directory
Is your PATH set correctly?
/home/ninjame/aosp/kernel/msm/./Kbuild:35: recipe for target 'kernel/bounds.s' failed
make[1]: *** [kernel/bounds.s] Error 2
Makefile:993: recipe for target 'prepare0' failed
make: *** [prepare0] Error 2
解决:环境变量没设置好,最开始设置成了
export PATH=$PATH:/home/ninjame/aosp/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/arm-eabi/bin
提示再明显不过了
ninjame@ubuntu1604:~/aosp/prebuilts$ find -name "arm-eabi-gcc"
./gcc/darwin-x86/arm/arm-eabi-4.8/bin/arm-eabi-gcc
./gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-gcc
问题3:
Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at kernel/timeconst.pl line 373.
/home/ninjame/aosp/kernel/msm/kernel/Makefile:129: recipe for target 'kernel/timeconst.h' failed
make[1]: *** [kernel/timeconst.h] Error 255
Makefile:953: recipe for target 'kernel' failed
make: *** [kernel] Error 2
解决:其实,提示的错误信息已经明确告诉你了,你应该省略defined() 。打开 kernel/timeconst.pl
将if (defined(@val)) 改为if (@val),再次编译就可以通过
4、刷新内核
进入到了 Android 源代码目录,设置环境变量,告知已编译好的新内核地址