環(huán)境
1.Host:MacBook Air (13 英寸,2015 年初)
外置128G硬盤 區(qū)分大小寫
Xcode 7.3
image.png
2.樹莓派:樹莓派3B 16GB存儲卡 讀卡器
步驟
1.下載源碼
Refer to http://source.android.com/source/downloading.html
repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r19
為了避免被墻歧匈,加快速度织阳,repo init的步驟可以參考(實測1速度更快):
1.https://lug.ustc.edu.cn/wiki/mirrors/help/aosp
2.https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
git clone https://github.com/android-rpi/local_manifests .repo/local_manifests
repo sync
漫長的等待诉瓦,源碼較大仿贬,60G以上,如果repo sync的時候 kernel_rpi external_mesa3d這兩項同
步不下來的話,先在.repo/local_manifests/default.xml中把這兩項注釋掉奕坟,然后執(zhí)行repo
sync遍搞,最后在github上下載zip包罗侯,解壓至源碼對應(yīng)路徑。
源碼下載完成后溪猿,需要對源碼做一些簡單的修改可參見:
https://github.com/android-rpi/device_brcm_rpi3/wiki#use-hal_pixel_format_bgra_8888
2.安裝gcc-linaro-arm-linux-gnueabihf钩杰,下載地址:
http://download.csdn.net/download/u010955001/10148489
3.安裝gnu-sed
由于mac自帶的sed與gnu-sed有區(qū)別,編譯過程中需要使用到gnu-sed再愈,所以我們要安裝gnu-sed榜苫。
你可以選擇brew 或者port來安裝。
我選擇的是brew:brew install gnu-sed --with-default-names
安裝完成以后:
sudo rm /usr/local/bin/sed
sudo ln -s /usr/local/Cellar/gnu-sed/4.4/bin/sed /usr/local/bin/sed
這樣會將mac自帶的sed刪除翎冲,并使用gnu-sed垂睬,你也可以保留自帶的sed,只需將gnu-sed的路徑
export至系統(tǒng)環(huán)境變量前即可抗悍。
4.編寫編譯腳本驹饺,以下是我已經(jīng)寫好的腳本,將以下內(nèi)容保存到源碼根路徑下缴渊,命名為build_rpi.sh赏壹,然后chmod a+x build_rpi.sh 增加可執(zhí)行權(quán)限。
#!/bin/bash
if [[ $1 = all ]]; then
cd kernel/rpi
ARCH=arm scripts/kconfig/merge_config.sh arch/arm/configs/bcm2709_defconfig android/configs/android-base.cfg android/configs/android-recommended.cfg
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make zImage
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make dtbs
cd ../..
source build/envsetup.sh
lunch rpi3-eng
make ramdisk systemimage
fi
if [[ $1 = kernel ]]; then
cd kernel/rpi
ARCH=arm scripts/kconfig/merge_config.sh arch/arm/configs/bcm2709_defconfig android/configs/android-base.cfg android/configs/android-recommended.cfg
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make zImage
ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make dtbs
cd ../..
fi
if [[ $1 = android ]]; then
source build/envsetup.sh
lunch rpi3-eng
make ramdisk systemimage
fi
5.有了上一步的腳本后衔沼,在源碼根路徑下執(zhí)行腳本即可
./build_rpi.sh all //編譯內(nèi)核和安卓代碼
./build_rpi.sh kernel //編譯內(nèi)核
./build_rpi.sh android //編譯安卓
6.燒寫系統(tǒng)
準(zhǔn)備一張8G以上SD蝌借,為SD卡創(chuàng)建分區(qū)(因為需要創(chuàng)建ext4文件系統(tǒng)最好使用Linux昔瞧,我使用Mac分區(qū)失
敗了,才安裝了Ubuntu的虛擬機(jī)為SD卡分區(qū)),分區(qū)結(jié)構(gòu)如下圖(注意system分區(qū)大小為1G):
image.png
p1 512MB for BOOT : Do fdisk : W95 FAT32(LBA) & Bootable, mkfs.vfat
p2 1024MB for /system : Do fdisk, new primary partition
p3 512MB for /cache : Do fdisk, mkfs.ext4
p4 remainings for /data : Do fdisk, mkfs.ext4
Set volume label for each partition - system, cache, userdata
: use -L option of mkfs.ext4, e2label command, or -n option of mkfs.vfat
# Write system partition
$ cd out/target/product/rpi3
$ sudo dd if=system.img of=/dev/<p2> bs=1M
# Copy kernel & ramdisk to BOOT partition
device/brcm/rpi3/boot/* to p1:/
kernel/rpi/arch/arm/boot/zImage to p1:/
kernel/rpi/arch/arm/boot/dts/bcm2710-rpi-3-b.dtb to p1:/
kernel/rpi/arch/arm/boot/dts/overlays/vc4-kms-v3d.dtbo to p1:/overlays/vc4-kms-v3d.dtbo
out/target/product/rpi3/ramdisk.img to p1:/
7.SD卡插入樹莓派菩佑,使用USB-TTL連接樹莓派的串口和電腦的USB自晰。
8.樹莓派開始啟動,在minicom中即可進(jìn)入樹莓派終端稍坯,也能看到啟動消息
錯誤
1.scripts/mod/mk_elfconfig.c:4:10: fatal error: 'elf.h' file not found
解決辦法
到這個路徑 https://www.rockbox.org/tracker/9006?getfile=16683 找到elf.h的源碼酬荞,
放在 scripts/mod下,并修改報錯部分的include<elf.h>為 include "elf.h" 再次編譯瞧哟,如果
遇到這個類似的報錯混巧,也修改include<elf.h> 即可,注意路徑勤揩。
2.編譯內(nèi)核的時候提示needed by `net/netfilter/built-in.o'
解決辦法
因為同步kernel_rpi的時候失敗了咧党,所以是下載的zip包解壓,實際是解壓后復(fù)制過來的文件不完整陨亡,
所以凿傅,先刪除復(fù)制過來的kernel/rpi文件夾,直接將zip復(fù)制過來数苫,然后解壓,修改解壓后的文件夾名
稱為rpi
3.curl不兼容報錯
Unsupported curl, please use a curl not based on SecureTransport
Jack server installation not found
Unsupported curl, please use a curl not based on SecureTransport
Unsupported curl, please use a curl not based on SecureTransport
解決辦法:
brew install curl --with-openssl
編輯環(huán)境變量辨液,增加以下內(nèi)容:
export PATH=$(brew --prefix curl)/bin:$PATH
4.Out of memory error (version 1.2-rc4 'Carnac' (298900 f95d7bdecfceb327f9d201a1348397ed8a843843 by android-jack-team@google.com)).
修改Jack的配置文件prebuilts/sdk/tools/jack-admin
將:
JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -cp $LAUNCHER_JAR $LAUNCHER_NAME"
更改為:
JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -Xmx4096m -cp $LAUNCHER_JAR $LAUNCHER_NAME"
先停止服務(wù)
./prebuilts/sdk/tools/jack-admin stop-server
重新開始服務(wù)
./prebuilts/sdk/tools/jack-admin start-server
5./bin/bash: xgettext: command not found
解決辦法:
brew install gettext
編輯環(huán)境變量虐急,增加以下內(nèi)容:
export PATH=$(brew --prefix gettext)/bin:$PATH
6.燒錄系統(tǒng)完成后,無法啟動看到以下消息:
[ 3.621274] init: Starting service 'healthd'...
[ 3.626646] init: Starting service 'adbd'...
[ 3.628913] binder: 111:111 transaction failed 29189, size 0-0
[ 3.637741] init: cannot find '/system/bin/sh' (No such file or directory), disabling 'console'
[ 4.629075] binder: 111:111 transaction failed 29189, size 0-0
解決辦法:
檢查system.img燒錄是否正常滔迈,system分區(qū)大小是否正確止吁。我的是因為分區(qū)508M太小導(dǎo)致的,修改分區(qū)
大小為1G以后正常