您的位置:首页 > 移动开发 > Android开发

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

2015-04-06 17:01 453 查看
1.源码获取    这里不说了。 (一说就伤心,我伟大的和谐政府) ​2.获取硬件驱动Google提供的所有 Nexus系列设备的硬件驱动的二进制文件在以下网址中均可下载  https://developers.google.com/android/nexus找到(我的是nexus5,你的自己选择,源码是4.4) 

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

Hardware ComponentCompanyDownloadMD5 ChecksumSHA-1 Checksum
NFC, Bluetooth, Wi-FiBroadcomLinkbc912bc141f63859e37f59e1bfa1639b896abf0ba601d261b368e1ac5504dee846447ea1
Camera, Sensors, AudioLGLinkc27922b7aeb0f0f85fdeba160b14336878d36576ff70fe766144e19e48a22920b8a52afb
Graphics, GSM, Camera, GPS, Sensors, Media, DSP, USBQualcommLinkc2a05e15773adebf45955a97a5271dc8a5db0602f04ee5991dad387cd602f570a1e50929
下载完成后将三个压缩包解压至Android源码根目录(WORKING_DIRECTORY),得到三个.sh文件extract-broadcom-hammerhead.sh、extract-broadcom-hammerhead.sh、extract-broadcom-hammerhead.sh,分别执行这三个shell脚本(会提示是否接受License之类的,IACCEPT即 可),会在源码目录下新生成一个/vendor目录,里面就是Nexus5所需的相关硬件驱动二进制文件(一定要在编译Android源码前确保在源码根目录有官方提供的硬件驱动目录vendor,否则编译完成烧录后reboot会因为缺少硬件驱动卡在Google启动画面上)3.编译Android源码初始化编译环境执行初始化编译环境的脚本:注(在源码根目录WORKING_DIRECTORY)kevint@kevintcl:WORKING_DIRECTORY$ source build/envsetup.shincluding 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$  列出所有可用的Targetkevint@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(普通) [code]make is the same as 
make eng
.Installs modules tagged with: 
eng
debug
user
,
 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
[code]make userThis 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
[code]make userdebugThe same as 
user
, except:Also installs modules tagged with 
debug
.
ro.debuggable=1
adb
 is enabled by default.
 如果你编译了某种特殊(flavor)的版本,然后要编译其它特殊版本,你必须在两次执行 make 之间执行  makeinstallclean 来担保(guarantee)你不会使用前一个特殊版本安装的文件。makeclean 同样可以满足要求(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 之间执行  makeinstallclean 来担保(guarantee)你不会使用前一个特殊版本安装的文件。makeclean 同样可以满足要求(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/hammerheadkevint@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只有在Bootloader是unlock模式下才可能烧录定制的系统,Nexus5设备默认的Bootloader都是locked的,需要解锁。先把Nexus5关机,然后同时按住音量的2个键和power,进入fastbootmode,执行下面命令解锁:
$fastbootoem 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 userdataerasing '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: 823Created filesystem with 11/838832 inodes and 93654/3351034 blockssending 'userdata' (137318 KB)...writing 'userdata'...OKAY [ 14.931s]finished. total time: 27.258skevint@kevintcl:hammerhead-krt16m$ .刷入Android4.4 适配的Bootloader和基带版本从官方提供的出厂镜像中可以找到合适的Bootloader和radio信息,如果不执行这步,查看“Settings->"Aboutphone”->"Basebandversion"为“unknown”,更简单的说,打不了电话....google factory image: https://developers.google.com/android/nexus/images选择对应版本

"hammerhead" for Nexus 5 (GSM/LTE)

VersionDownloadMD5 ChecksumSHA-1 Checksum
4.4 (KRT16M)Link36aa82ab2d7d05ee144d18546565cd5fbd9c39ded5dc0ac80c4e96d24db060a660266033
4.4.2 (KOT49H)Linkfa3bdfbef24c25b48d4969e0925bc60002006b9917ae3f470d29644023b7c843ec96aa03
4.4.3 (KTU84M)Link34a201b32259aadcc8c4879e45c1575c53ff95bf3912814b745e65cab6bc111bde987537
4.4.4 (KTU84P)Linkd450411b40a6e60884c8e419bd50db2b35ea0277bd6a8fc928b47256bfa97b2eed60746b
4.4.4 Release 2 (For 2Degrees/NZ, Telstra/AUS and India ONLY) (KTU84Q)Linkb079669398b128dfed4cab3d0471241fae4752935beebeeffdba4937c8a729bb57f87b32
5.0 (LRX21O)Link761667f1ddaf4e38d4792136df4ab92701315e08c7f282452b5eba0606dd5a2d5274edde
5.0.1 (LRX22C)Linkf769bb85b7a82c1b4f7cc88f0d42129d0f9eda1b8c801bec45f762c96121e7ae905976c0
5.1.0 (LMY47D)Link021fa0ed4946e0c7e70e39da301e5a346c1ad81eb8b90b329da5ed534af6ef18dea9921c
5.1.0 (LMY47I)Linkd78c50bc06fe37a19536cbca0a17394adf127988e25758e683d53df9767cc799ee113935
我下的是4.4(KRT16M),下载文件解压后的文件信息如下:bootloader-hammerhead-HHZ11d.img  (Nexus5 的bootloader镜像)flash-base.shflash-all.bat                     image-hammerhead-krt16m.zip (出厂镜像)flash-all.sh                      radio-hammerhead-M8974A-1.0.25.0.17.img (Nexus5的基带镜像)把bootloader和radio刷入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$ fastbootreboot-bootloader 
刷入基带radio:
kevint@kevintcl:hammerhead$ fastbootflash 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 可以通过一行简单的命令刷入Nexus5,它在检测bootloader和radio版本和编译好的Android版本匹配后把boot、recovery、system文件分区烧录到设备中,命令里的“-w”参数是wipe,就是把所有的userdata格式化,如果有要保留的数据注意备份: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$ 最后机子自己重启了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 源码 nexus