android 4.4 源码编译--for--nexus5

1.源码获取
    这里不说了。 (一说就伤心,我伟大的和谐政府) 

2.获取硬件驱动

  • Google提供的所有  Nexus系列设备的硬件驱动的二进制文件在以下网址中均可下载   https://developers.google.com/android/nexus
  • 找到(我的是nexus5,你的自己选择,源码是4.4) 

    Nexus 5 (GSM/LTE) binaries for Android 4.4 (KRT16M)

    Hardware Component Company Download MD5 Checksum SHA-1 Checksum
    NFC, Bluetooth, Wi-Fi Broadcom Link bc912bc141f63859e37f59e1bfa1639b 896abf0ba601d261b368e1ac5504dee846447ea1
    Camera, Sensors, Audio LG Link c27922b7aeb0f0f85fdeba160b143368 78d36576ff70fe766144e19e48a22920b8a52afb
    Graphics, GSM, Camera, GPS, Sensors, Media, DSP, USB Qualcomm Link c2a05e15773adebf45955a97a5271dc8
    a5db0602f04ee5991dad387cd602f570a1e5092
    9
  • 下载完成后将三个压缩包解压至Android源码根目录(WORKING_DIRECTORY),

  • 得到三个.sh文件extract-broadcom-hammerhead.shextract-broadcom-hammerhead.shextract-broadcom-hammerhead.sh

  • 分别执行这三个shell脚本(会提示是否接受License之类的,I ACCEPT即 可),会在源码目录下新生成一个/vendor目录,里面就是Nexus5所需的相关硬件驱动二进制文件


  • 一定要在编译Android源码前确保在源码根目录有官方提供的硬件驱动目录vendor,否则编译完成烧录后reboot会因为缺少硬件驱动卡在Google启动画面上






3.编译Android源码

  • 初始化编译环境


执行初始化编译环境的脚本:注(在源码根目录WORKING_DIRECTORY)


kevint@kevintcl:WORKING_DIRECTORY$  source build/envsetup.sh
including device/asus/tilapia/vendorsetup.sh 
including device/asus/grouper/vendorsetup.sh 
including device/asus/deb/vendorsetup.sh 
including device/asus/flo/vendorsetup.sh 
including device/generic/x86/vendorsetup.sh 
including device/generic/armv7-a-neon/vendorsetup.sh 
including device/generic/mips/vendorsetup.sh 
including device/samsung/manta/vendorsetup.sh 
including device/lge/mako/vendorsetup.sh 
including device/lge/hammerhead/vendorsetup.sh 
including sdk/bash_completion/adb.bash 
kevint@kevintcl:WORKING_DIRECTORY$ 

 列出所有可用的Target

kevint@kevintcl:WORKING_DIRECTORY$  lunch 
You're building on Linux 
Lunch menu... pick a combo: 
     1. aosp_arm-eng 
     2. aosp_x86-eng 
     3. aosp_mips-eng 
     4. vbox_x86-eng 
     5. aosp_tilapia-userdebug 
     6. aosp_grouper-userdebug 
     7. aosp_deb-userdebug 
     8. aosp_flo-userdebug 
     9. mini_x86-userdebug 
     10. mini_armv7a_neon-userdebug 
     11. mini_mips-userdebug 
     12. aosp_manta-userdebug 
     13. aosp_mako-userdebug 
       14. aosp_hammerhead-userdebug (这是我需要的) 


  • 选择一个Target


使用lunch指令制定编译的target,具体的配置可以通过参数来指定,例如:


$lunch aosp_arm  -  eng

这行指令用来编译一个完整的模拟器emulator,所有的debug都是开启的。


所有的target形式都是BUILD-BUILDTYPE,其中BUILD是一个特定代码集合的名称,如Nexus5的代码名称就是hammerhead

BUILDTYPE即编译的模式,有一下三种:


eng This is the default flavor(原版). A plain(普通) make is the same as make eng.
  • Installs modules tagged with: engdebuguser, and/or development.
  • Installs non-APK modules that have no tags specified.
  • Installs APKs according to the product definition files, in addition to tagged APKs.
  • ro.secure=0
  • ro.debuggable=1
  • ro.kernel.android.checkjni=1
  • adb is enabled by default.
user make user

This is the flavor intended to be the final release bits.

  • Installs modules tagged with user.
  • Installs non-APK modules that have no tags specified.
  • Installs APKs according to the product definition files; tags are ignored for APK modules.
  • ro.secure=1
  • ro.debuggable=0
  • adb is disabled by default.
userdebug make userdebug

The same as user, except:

  • Also installs modules tagged with debug.
  • ro.debuggable=1
  • adb is enabled by default.
 如果你编译了某种特殊(flavor)的版本,然后要编译其它特殊版本,你必须在两次执行  make  之间执行   make installclean  来担保(guarantee)你不会使用前一个特殊版本安装的文件。


make clean 同样可以满足要求(suffice),但是将会消耗更多的时间。


注:由于我的编译的类型中没有eng  , 我又想使ro.secure=0. 我做了如下修改
kevint@kevintcl:core$ pwd 
/home/kevint/WORKING_DIRECTORY/build/core 
kevint@kevintcl:core$ vi main.mk  
在如下位子
ifneq (,$(user_variant)) 
  # Target is secure in user builds. 
  #ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1 在行被注释,添加了下行 
  ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=  0 




Which would you like? [aosp_arm-eng] ^C 
kevint@kevintcl:WORKING_DIRECTORY$ clear
选择一个  Target  (我的源码中只能用这个选项)
kevint@kevintcl:WORKING_DIRECTORY$  lunch aosp_hammerhead-userdebug

============================================ 
PLATFORM_VERSION_CODENAME=REL 
PLATFORM_VERSION=4.4 
TARGET_PRODUCT=aosp_hammerhead 
TARGET_BUILD_VARIANT=userdebug 
TARGET_BUILD_TYPE=release 
TARGET_BUILD_APPS= 
TARGET_ARCH=arm 
TARGET_ARCH_VARIANT=armv7-a-neon 
TARGET_CPU_VARIANT=krait 
HOST_ARCH=x86 
HOST_OS=linux 
HOST_OS_EXTRA=Linux-3.11.0-12-generic-x86_64-with-Ubuntu-13.10-saucy 
HOST_BUILD_TYPE=release 
BUILD_ID=KRT16S 
OUT_DIR=out 
============================================ 


kevint@kevintcl:WORKING_DIRECTORY$  
开始编译
如果你编译了某种特殊(flavor)的版本,然后要编译其它特殊版本,你必须在两次执行  make  之间执行   make installclean  来担保(guarantee)你不会使用前一个特殊版本安装的文件。


make clean 同样可以满足要求(suffice),但是将会消耗更多的时间。


kevint@kevintcl:WORKING_DIRECTORY$  make -j4 
============================================ 
PLATFORM_VERSION_CODENAME=REL 
PLATFORM_VERSION=4.4 
TARGET_PRODUCT=aosp_hammerhead 
TARGET_BUILD_VARIANT=userdebug 
TARGET_BUILD_TYPE=release 
TARGET_BUILD_APPS= 
TARGET_ARCH=arm 
TARGET_ARCH_VARIANT=armv7-a-neon 
TARGET_CPU_VARIANT=krait 
HOST_ARCH=x86 
HOST_OS=linux 
HOST_OS_EXTRA=Linux-3.11.0-12-generic-x86_64-with-Ubuntu-13.10-saucy 
HOST_BUILD_TYPE=release 
BUILD_ID=KRT16S 
OUT_DIR=out 
============================================

编译完成后生成的文件
kevint@kevintcl:hammerhead$ pwd 
/home/kevint/WORKING_DIRECTORY/out/target/product/hammerhead
kevint@kevintcl:hammerhead$ ls 
android-info.txt  data                 previous_build_config.mk  root 
boot.img          fake_packages          ramdisk.img               symbols 
cache             installed-files.txt  ramdisk-recovery.img      system 
cache.img         kernel               recovery                   system.img 
clean_steps.mk    obj                   recovery.img               userdata.img 
kevint@kevintcl:hammerhead$ 

编译完了就刷机了哟:

解锁Bootloader

  • 只有在Bootloaderunlock模式下才可能烧录定制的系统,Nexus5设备默认的Bootloader都是locked的,需要解锁。

  • 先把Nexus5关机,然后同时按住音量的2个键和power,进入fastbootmode,执行下面命令解锁:


$fastboot oem unlock  (刷机完成后执行fastboot oem lock  加锁)

官方推荐在烧录系统前格式化  cache    userdate  ,注意在执行下面命令前做好手机数据的备份:

kevint@kevintcl:hammerhead-krt16m$ fastboot format cache 
erasing 'cache'... 
OKAY [  0.646s] 
formatting 'cache' partition... 
Creating filesystem with parameters: 
    Size: 734003200 
    Block size: 4096 
    Blocks per group: 32768 
    Inodes per group: 7472 
    Inode size: 256 
    Journal blocks: 2800 
    Label:  
    Blocks: 179200 
    Block groups: 6 
    Reserved block group size: 47 
Created filesystem with 11/44832 inodes and 5813/179200 blocks 
sending 'cache' (13348 KB)... 
writing 'cache'... 
OKAY [  2.007s] 
finished. total time: 2.653s 

kevint@kevintcl:hammerhead-krt16m$ 

kevint@kevintcl:hammerhead-krt16m$  fastboot format userdata
erasing 'userdata'...
OKAY [ 12.327s]
formatting 'userdata' partition...
Creating filesystem with parameters:
    Size: 13725835264
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8144
    Inode size: 256
    Journal blocks: 32768
    Label: 
    Blocks: 3351034
    Block groups: 103
    Reserved block group size: 823
Created filesystem with 11/838832 inodes and 93654/3351034 blocks
sending 'userdata' (137318 KB)...
writing 'userdata'...
OKAY [ 14.931s]
finished. total time: 27.258s
kevint@kevintcl:hammerhead-krt16m$ 


.刷入Android4.4 适配的Bootloader和基带版本

  • 从官方提供的出厂镜像中可以找到合适的Bootloaderradio信息,如果不执行这步,查看Settings->"Aboutphone”->"Baseband version"为“unknown”,更简单的说,打不了电话....


google factory image: https://developers.google.com/android/nexus/images

选择对应版本


"hammerhead" for Nexus 5 (GSM/LTE)

Version Download MD5 Checksum SHA-1 Checksum
4.4 (KRT16M) Link 36aa82ab2d7d05ee144d18546565cd5f bd9c39ded5dc0ac80c4e96d24db060a660266033
4.4.2 (KOT49H) Link fa3bdfbef24c25b48d4969e0925bc600 02006b9917ae3f470d29644023b7c843ec96aa03
4.4.3 (KTU84M) Link 34a201b32259aadcc8c4879e45c1575c 53ff95bf3912814b745e65cab6bc111bde987537
4.4.4 (KTU84P) Link d450411b40a6e60884c8e419bd50db2b 35ea0277bd6a8fc928b47256bfa97b2eed60746b
4.4.4 Release 2 (For 2Degrees/NZ, Telstra/AUS and India ONLY) (KTU84Q) Link b079669398b128dfed4cab3d0471241f ae4752935beebeeffdba4937c8a729bb57f87b32
5.0 (LRX21O) Link 761667f1ddaf4e38d4792136df4ab927 01315e08c7f282452b5eba0606dd5a2d5274edde
5.0.1 (LRX22C) Link f769bb85b7a82c1b4f7cc88f0d42129d 0f9eda1b8c801bec45f762c96121e7ae905976c0
5.1.0 (LMY47D) Link 021fa0ed4946e0c7e70e39da301e5a34 6c1ad81eb8b90b329da5ed534af6ef18dea9921c
5.1.0 (LMY47I) Link d78c50bc06fe37a19536cbca0a17394a df127988e25758e683d53df9767cc799ee113935



我下的是4.4 (KRT16M)下载文件解压后的文件信息如下:

bootloader-hammerhead-HHZ11d.img  (Nexus 5 bootloader镜像)

flash-base.sh
flash-all.bat                     

image-hammerhead-krt16m.zip (出厂镜像)
flash-all.sh                      

radio-hammerhead-M8974A-1.0.25.0.17.img (Nexus 5的基带镜像)


  • bootloaderradio刷入Nexus5,我使用了自己的路径,注意要替换成你的路径:


    kevint@kevintcl:hammerhead$ fastboot flash bootloader ~/nexus5/4-4-KRT16M/hammerhead-krt16m/bootloader-hammerhead-HHZ11d.img  


刷好bootloader后重启进入bootloader用最新的bootloader进行烧录radio和编译好的rom:


kevint@kevintcl:hammerhead$ fastboot reboot-bootloader 


刷入基带radio:


kevint@kevintcl:hammerhead$ fastboot flash radio ~/nexus5/4-4-KRT16M/hammerhead-krt16m/radio-hammerhead-M8974A-1.0.25.0.17.img 


下面是具体步骤


kevint@kevintcl:hammerhead$ which fastboot
/home/kevint/WORKING_DIRECTORY/out/host/linux-x86/bin/fastboot    (fastboot 是编译完源码生成的,路径WORKING_DIRECTORY/out/host/linux-x86/bin/fastboot  )

kevint@kevintcl:hammerhead$  fastboot devices  检测手机是否链接好 
04d6bfad010adbd0  fastboot 
kevint@kevintcl:hammerhead$  fastboot flash bootloader ~/nexus5/4-4-KRT16M/hammerhead-krt16m/bootloader-hammerhead-HHZ11d.img  
sending 'bootloader' (2506 KB)... 
OKAY [  0.270s] 
writing 'bootloader'... 
OKAY [  0.502s] 
finished. total time: 0.772s 
kevint@kevintcl:hammerhead$  fastboot reboot-bootloader 
rebooting into bootloader... 
OKAY [  0.001s] 
finished. total time: 0.001s 
kevint@kevintcl:hammerhead$  fastboot flash radio ~/nexus5/4-4-KRT16M/hammerhead-krt16m/radio-hammerhead-M8974A-1.0.25.0.17.img  
sending 'radio' (42033 KB)... 
OKAY [  1.627s] 
writing 'radio'... 
OKAY [  2.901s] 
finished. total time: 4.529s 
kevint@kevintcl:hammerhead$ ls 
android-info.txt  data                 previous_build_config.mk  root 
boot.img          fake_packages        ramdisk.img               symbols 
cache             installed-files.txt  ramdisk-recovery.img      system 
cache.img         kernel               recovery                  system.img 
clean_steps.mk    obj                  recovery.img              userdata.img 
kevint@kevintcl:hammerhead$ fastboot reboot-bootloaderrebooting into bootloader... 
OKAY [  0.001s] 
finished. total time: 0.001s 


烧录到设备  (Nexus5)

完整的Android 4.4 可以通过一行简单的命令刷入Nexus 5

它在检测bootloaderradio版本和编译好的Android版本匹配后把bootrecoverysystem文件分区烧录到设备中,

命令里的“-w”参数是wipe,就是把所有的user data格式化,如果有要保留的数据注意备份:



kevint@kevintcl:hammerhead$  fastboot -w flashall
-------------------------------------------- 
Bootloader Version...: HHZ11d 
Baseband Version.....: M8974A-1.0.25.0.17 
Serial Number........: 04d6bfad010adbd0 
-------------------------------------------- 
checking product... 
OKAY [  0.100s] 
sending 'boot' (8620 KB)... 
OKAY [  0.515s] 
writing '   boot'   ..
OKAY [  0.760s] 
sending 'recovery' (9202 KB)... 
OKAY [  0.570s] 
writing 'recovery'...  
OKAY [  0.782s] 
erasing 'system'... 
OKAY [  1.018s] 
sending 'system' (294108 KB)... 
OKAY [ 10.932s] 
writing 'system'..
OKAY [ 21.399s] 
erasing 'userdata'... 
OKAY [  7.391s] 
formatting 'userdata' partition... 
Creating filesystem with parameters: 
    Size: 13725835264 
    Block size: 4096 
    Blocks per group: 32768 
    Inodes per group: 8144 
    Inode size: 256 
    Journal blocks: 32768 
    Label:  
    Blocks: 3351034 
    Block groups: 103 
    Reserved block group size: 823 
Created filesystem with 11/838832 inodes and 93654/3351034 blocks 
sending 'userdata' (137318 KB)... 
writing 'userdata'..
OKAY [ 14.700s] 
erasing 'cache'... 
OKAY [  0.554s] 
formatting 'cache' partition... 
Creating filesystem with parameters: 
    Size: 734003200 
    Block size: 4096 
    Blocks per group: 32768 
    Inodes per group: 7472 
    Inode size: 256 
    Journal blocks: 2800 
    Label:  
    Blocks: 179200 
    Block groups: 6 
    Reserved block group size: 47 
Created filesystem with 11/44832 inodes and 5813/179200 blocks 
sending 'cache' (13348 KB)... 
writing 'cache'... 
OKAY [  1.995s] 
rebooting... 


finished. total time: 61.249s 
kevint@kevintcl:hammerhead$ 

最后机子自己重启了。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值