1. 程式人生 > 其它 >【開發指南】如何為nexus 5編譯韌體

【開發指南】如何為nexus 5編譯韌體

nexus 5是谷歌的親兒子,而android的原始碼是開源的,那如果我有一個nexus 5手機,為何不自己為nexus 5編譯軟體呢?

開搞,本文假定已經有android 5.1的原始碼並已經配置好開發環境,如果沒有則參考google官方文件下載原始碼並配置開發環境。參考https://source.android.com/source/initializing.html以及https://source.android.com/source/downloading.html。注意,這個過程可能需要訪問外國網站,作為程式設計師的我們,訪問外國網站不是小菜一碟。

另外你需要知道AOSP,AOSP即Android Open Source Project 漢語意思是:谷歌開放原始碼專案。我們通過Google官方下載的原始碼,就是AOSP的程式碼,其中是不包含Google開發的那些個應用的,各個廠商拿到的也是這個版本,在這個版本的基礎上進行修改。而Google釋出的工廠韌體則是包含全套Google服務的。廠商如果想安裝Google服務,就需要過Google的那一套認證,比較麻煩,而且價格不菲,鑑於Google在國內的尷尬地位,國內很多廠商都沒有過這個認證。所以,我們自己編譯的出來的軟體和nexus 5官方放出來的刷機包還是有區別的。

1. 初始化編譯環境

. build/envsetup.sh

2. 載入機型

lunch

3. 選擇要編譯的機器

You're building on Linux
Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. aosp_shamu-userdebug
     8. aosp_manta-userdebug
     9. full_fugu-userdebug
     10. aosp_fugu-userdebug
     11. aosp_grouper-userdebug
     12. aosp_tilapia-userdebug
     13. aosp_deb-userdebug
     14. aosp_flo-userdebug
     15. aosp_mako-userdebug
     16. aosp_hammerhead-userdebug
     17. aosp_flounder-userdebug
     18. mini_emulator_x86_64-userdebug
     19. mini_emulator_arm-userdebug
     20. mini_emulator_x86-userdebug
     21. mini_emulator_mips-userdebug
     22. mini_emulator_arm64-userdebug

3.1 機型對照表

Device

Code name

Build configuration

Nexus 6

shamu

aosp_shamu-userdebug

Nexus Player

fugu

aosp_fugu-userdebug

Nexus 9

volantis (flounder)

aosp_flounder-userdebug

Nexus 5 (GSM/LTE)

hammerhead

aosp_hammerhead-userdebug

Nexus 7 (Wi-Fi)

razor (flo)

aosp_flo-userdebug

Nexus 7 (Mobile)

razorg (deb)

aosp_deb-userdebug

Nexus 10

mantaray (manta)

full_manta-userdebug

Nexus 4

occam (mako)

full_mako-userdebug

Nexus 7 (Wi-Fi)

nakasi (grouper)

full_grouper-userdebug

Nexus 7 (Mobile)

nakasig (tilapia)

full_tilapia-userdebug

Galaxy Nexus (GSM/HSPA+)

yakju (maguro)

full_maguro-userdebug

Galaxy Nexus (Verizon)

mysid (toro)

aosp_toro-userdebug

Galaxy Nexus (Experimental)

mysidspr (toroplus)

aosp_toroplus-userdebug

PandaBoard (Archived)

panda

aosp_panda-userdebug

Motorola Xoom (U.S. Wi-Fi)

wingray

full_wingray-userdebug

Nexus S

soju (crespo)

full_crespo-userdebug

Nexus S 4G

sojus (crespo4g)

full_crespo4g-userdebug

3.2 三個版本說明版本

user

limited access; suited for production

userdebug

like “user” but with root access and debuggability; preferred for debugging

eng

development configuration with additional debugging tools

選擇aosp_hammerhead-userdebug之後,會有下面的確認資訊:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=5.0.50.50.50.50
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
TARGET_2ND_ARCH=
TARGET_2ND_ARCH_VARIANT=
TARGET_2ND_CPU_VARIANT=
HOST_ARCH=x86_64
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-37-generic-x86_64-with-Ubuntu-14.10-utopic
HOST_BUILD_TYPE=release
BUILD_ID=AOSP
OUT_DIR=out
============================================

4.生成驅動目錄

接下來需要在Android官網下載 Nexus5所需要的驅動:https://developers.google.com/android/nexus/drivers#hammerheadlrx22c

下載完成後,解壓出來是三個.sh檔案,放到Android原始碼目錄下面,然後執行.會將相關驅動放到vender目錄下面.

5. 執行編譯命令

make -j8

如果沒有出錯的話,在經過漫長的時間之後,編譯成功:

6. 刷機命令

Nexus5關機狀態下,長按音量下+電源,即可進入recovery模式, 然後在原始碼根目錄下執行下面命令:

fastboot -w flashall

刷機成功後會自動重啟

~/ fastboot -w flashall
target reported max download size of 1073741824 bytes
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
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
--------------------------------------------
Bootloader Version...: HHZ12d
Baseband Version.....: M8974A-2.0.50.2.22
Serial Number........: 08ade1a513dc087b
--------------------------------------------
checking product...
OKAY [  0.100s]
sending 'boot' (8950 KB)...
OKAY [  0.500s]
writing 'boot'...
OKAY [  0.784s]
sending 'recovery' (9672 KB)...
OKAY [  0.556s]
writing 'recovery'...
OKAY [  0.814s]
erasing 'system'...
OKAY [  1.166s]
sending 'system' (328187 KB)...
OKAY [ 10.501s]
writing 'system'...
OKAY [ 23.623s]
erasing 'userdata'...
OKAY [ 14.657s]
sending 'userdata' (137318 KB)...
OKAY [  4.520s]
writing 'userdata'...
OKAY [  9.776s]
erasing 'cache'...
OKAY [  0.618s]
sending 'cache' (13348 KB)...
OKAY [  0.630s]
writing 'cache'...
OKAY [  1.070s]
rebooting...
finished. total time: 70.095s