Nexus5 内核编译烧录过程记录

一、下载nexus5 对应的内核源码python

     Android系统使用的是Linux内核,但与主线分枝的Linux内核又有一些差别,各个不一样的厂商又有本身的修改。内核源码位于谷歌境外服务器,不FQ没法访问,这给同步源码形成很大的不便。幸亏清华大学的开源服务器上也同步了AOSP内核的源码,使得咱们无须FQ就能够同步源码。linux

   映射关系以下:android

复制代码

名称     Google GIT地址     清华服务器地址
common     https://android.googlesource.com/kernel/common.git     https://aosp.tuna.tsinghua.edu.cn/kernel/common.gitexynos     https://android.googlesource.com/kernel/exynos.git     https://aosp.tuna.tsinghua.edu.cn/kernel/exynos.gitgoldfish     https://android.googlesource.com/kernel/goldfish.git     https://aosp.tuna.tsinghua.edu.cn/kernel/goldfish.githikey-linaro     https://android.googlesource.com/kernel/hikey-linaro     https://aosp.tuna.tsinghua.edu.cn/kernel/hikey-linaro.gitlk         https://aosp.tuna.tsinghua.edu.cn/kernel/lk.gitmsm     https://android.googlesource.com/kernel/msm.git     https://aosp.tuna.tsinghua.edu.cn/kernel/msm.gitomap     https://android.googlesource.com/kernel/omap.git     https://aosp.tuna.tsinghua.edu.cn/kernel/omap.gitsamsung     https://android.googlesource.com/kernel/samsung.git     https://aosp.tuna.tsinghua.edu.cn/kernel/samsung.gittegra     https://android.googlesource.com/kernel/tegra.git     https://aosp.tuna.tsinghua.edu.cn/kernel/tegra.gitx86_64     https://android.googlesource.com/kernel/x86_64.git     https://aosp.tuna.tsinghua.edu.cn/kernel/x86_64.git

复制代码

因为nexus5使用的是高通处理器,因此直接同步msm的连接git

ninjame@ubuntu1604:~/aosp$ mkdir kernel
ninjame@ubuntu1604:~/aosp$ cd kernel
ninjame@ubuntu1604:~/aosp/kernel$ git clone https://aosp.tuna.tsinghua.edu.cn/kernel/msm.git

git branch 查看Android内核源码的代码版本分支ubuntu

 

复制代码

ninjame@ubuntu1604:~/aosp/kernel/msm$ git branch -a* (头指针分离于 7717f76)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-4.4
  remotes/origin/android-4.4.y
……
  remotes/origin/android-msm-hammerhead-3.4-kitkat-mr1
  remotes/origin/android-msm-hammerhead-3.4-kitkat-mr2
  remotes/origin/android-msm-hammerhead-3.4-kk-fr1
  remotes/origin/android-msm-hammerhead-3.4-kk-fr2
  remotes/origin/android-msm-hammerhead-3.4-kk-r1
  remotes/origin/android-msm-hammerhead-3.4-l-preview
  remotes/origin/android-msm-hammerhead-3.4-lollipop-mr1
  remotes/origin/android-msm-hammerhead-3.4-lollipop-mr1.1
  remotes/origin/android-msm-hammerhead-3.4-lollipop-release
  remotes/origin/android-msm-hammerhead-3.4-m-preview
  remotes/origin/android-msm-hammerhead-3.4-marshmallow
  remotes/origin/android-msm-hammerhead-3.4-marshmallow-mr1
  remotes/origin/android-msm-hammerhead-3.4-marshmallow-mr2
  remotes/origin/android-msm-hammerhead-3.4-marshmallow-mr3
……

复制代码

 

和nexus5 相关的且是adnoid6.0 版本的内核分支共有4个,到底checkout哪一个分支呢?对于Android的源码与Android内核源码版本的对应关系,很难说得清楚。通过摸索,找到一种比较讨巧的方法,直接进入手机设置,查看关于手机服务器

 

内核版本是3.4.0-g7717f76架构

ninjame@ubuntu1604:~/aosp/kernel/msm$ git checkout 3.4.0-g7717f76

当发现真的把相应分支源码的源码给同步过来,居然有种意外的惊喜,这是怎么回事呢?ide

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节点拉出来的,那么每个节点均可以看作一个分支,固然某些分支中只包含它本身)ui

3.4.0-g7717f76  就能够解读为该内核版本大的分支为linux3.4.0,具体的源码对应于commit节点为7717f76 那一次提交代码对应的快照。google

下载部分参考博客:

http://blog.csdn.net/sunao2002002/article/details/53057374

http://blog.csdn.net/qq1084283172/article/details/54880488

 

二、配置编译环境

因为是在 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

 三、编译

开始编译以前,不要着急开始,先使用 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'.
编译碰到的问题;

 

复制代码

, line , m.group(  /usr/bin/  -s /usr/bin/python2. /usr/bin/python,默认设置成python2.
其实,提示的错误信息已经明确告诉你了,你应该省略defined() 。打开 kernel/timeconst.pl

复制代码

四、刷新内核

进入到了 Android 源代码目录,设置环境变量,告知已编译好的新内核地址

ninjame@ubuntu1604:~/aosp/kernel/msm$ cd arch/arm/boot/ninjame@ubuntu1604:~/aosp/kernel/msm/arch/arm/boot$ ls -l zImage-dtb-rw-rw-r-- 1 ninjame ninjame 8441144 5月  23 00:27 zImage-dtb
ninjame@ubuntu1604:~/aosp/kernel/msm/arch/arm/boot$ pwd/home/ninjame/aosp/kernel/msm/arch/arm/boot

export TARGET_PREBUILT_KERNEL=/home/ninjame/aosp/kernel/msm/arch/arm/boot/zImage-dtb

从新编译bootp_w_picpath

make bootp_w_picpath

成功后,如有相似以下的输出:

Copy: out/target/product/hammerhead/kernel
Target boot p_w_picpath: out/target/product/hammerhead/boot.img
out/target/product/hammerhead/boot.img maxsize=23519232 blocksize=135168 total=9369600 reserve=270336#### make completed successfully (03:29 (mm:ss)) ####

重启手机进入bootloader模式

adb reboot bootloader

刷入内核

fastboot flash boot boot.img

重启手机

fastboot reboot

~晒图,换上本身的签名了,哈哈~   ,不过g4ad03fa 打脸了。。。

相关文章
相关标签/搜索