2015年8月30日 星期日

Android - Make signed ota update file

經過修改Release key的步驟及漫長的build流程,我們可以開始製作OTA更新檔。

A. 製作signed-target_files.zip

make_ota_target_file 或 make_ota_package
在out/target/product/fiber-3g/obj/PACKAGING/target_files_intermediates目錄底下生成fiber_3g-target_files-xxx.zip
使用sign_target_files_apks製作signed-target_files.zip
編譯過程會遇到下面的錯誤,原因是由於有些apk程序已經簽過名了或者找不到對應的key,我們僅需將列出來的apk檔加入排除項目即可。
clip_image002
./build/tools/releasetools/sign_target_files_apks \
-d ./build/target/product/security \
-k ./build/target/product/security=./build/target/product/security \
-o \
out/target/product/fiber-3g/obj/PACKAGING/target_files_intermediates/*-target_files-*.zip \
signed-target_files.zip

在android4.4目錄底下生成signed-target_files.zip

B. 製作signed-img.zip

使用img_from_target_files製作signed-img.zip
./build/tools/releasetools/img_from_target_files \
signed-target_files.zip \
signed-img.zip

在android4.4目錄底下生成signed-img.zip

C. 製作完整升級包signed-ota_update.zip

使用ota_from_target_files製作signed-ota_update.zip
./build/tools/releasetools/ota_from_target_files \
-k ./build/target/product/security/releasekey \
signed-target_files.zip \
signed-ota_update.zip

在android4.4目錄底下生成signed-ota_update.zip

D. 製作差異升級包signed-ota-inc.zip

差異升級包,簡稱差分包,它僅使用於兩個版本之間,升級必要的內容而非全部內容,體積小是它最大的優點。要生成差分包,必須提供前一版本的target-file檔,也將是比較文件。
在對應out目錄下out/target/product/xxx/obj/PACKAGING/target_files_intermediates/,生成命名為xxx-target_files-xxx.zip的target-file檔,將其保存起來。
將比較版本的target-file檔拷貝到Android的根目錄下,注意,必須保證Android根目錄下只有一個zip格式的檔。
make_ota_package_inc

在android4.4/out/target/product/xxx目錄底下生成xxx_xxx-ota-xxx-inc.zip
注意:該差分包僅對指定的前一版本固件有效
unsigned-target_files.zip 僅能生成unsigned-ota-inc.zip
signed-target_files.zip僅能生成signed-ota-inc.zip
這邊得留意提供的target_files.zip有無簽章過,否則更新時會驗證失敗。
 

刷機更新系統

A. 透過fastboot tool

輸入指令進入bootloader mode
adb reboot bootloader

輸入指令檢查devices是否已連接
fastboot devices

輸入指令開始更新
fastboot update signed-img.zip

clip_image002[5]
目前Windows上fastboot devices安裝完驅動抓不到機器,不知是什麼原因。

B. 透過Recovery Mode

1. 完整包升級
將signed-ota_update.zip複製到internal storage
adb reboot recovery

選擇apply update from internal storage
再選擇signed-ota_update.zip更新
clip_image004
2. 差分包升級
將fiber_3g-ota-xxx-inc.zip複製到internal storage
adb reboot recovery

選擇apply update from internal storage
再選擇fiber_3g-ota-xxx-inc.zip更新

2015年8月29日 星期六

Setup android release key and Device product name

I. About key

A. 簽名類型

android的標準簽名key有:
testkey
media
platform
shared
以上的四種,可以在源碼的/build/target/product/security/裡面看到對應的金鑰,其中shared.pk8代表私密金鑰,shared.x509.pem公開金鑰,一定是成對出現的。
其中testkey是作為android編譯的時候默認的簽名key,如果系統中的apk的android.mk中沒有設置LOCAL_CERTIFICATE的值,就默認使用testkey。
而如果設置成:
LOCAL_CERTIFICATE := platform
就代表使用platform來簽名,這樣的話這個apk就擁有了和system相同的簽名,因為系統級別的簽名也是使用的platform來簽名,此時使用android:sharedUserId="android.uid.system"才有用!
最後我們需要將testkey置換成releasekey。

B. 製作Release key

subject='/C=US/ST=California/L=Mountain View/O=Android/OU=Android/CN=Android/emailAddress=android@android.com'
mkdir ~/.android-certs
for x in releasekey platform shared media; do \
./development/tools/make_key ~/.android-certs/$x "$subject"; \
done
C ---> Country Name (2 letter code)
ST ---> State or Province Name (full name)
L ---> Locality Name (eg, city)
O ---> Organization Name (eg, company)
OU ---> Organizational Unit Name (eg, section)
CN ---> Common Name (eg, your name or your server’s hostname)
emailAddress ---> Contact email address
另外在使用上面的make_key腳本生成key的過程中會提示輸入password,直接enter,不要密碼!否則build的過程因為多執行緒會build失敗。
將生成的key複製到android4.4/build/target/product/security/ 底下,testkey可以不留。
僅需一個人產生即可,其他人複製同一份security key使用,避免使用不同簽章而在燒錄過程驗證不過。

C. 修改系統默認簽名key

若LOCAL_CERTIFICATE沒有設定的話,系統預設會直接使用testkey為APK簽章。
修改預設使用的testkey為releasekey
android4.4/build/core/config.mk
修正前:
DEFAULT_SYSTEM_DEV_CERTIFICATE := build/target/product/security/testkey
修正後:
DEFAULT_SYSTEM_DEV_CERTIFICATE := build/target/product/security/releasekey

android4.4/build/core/makefile
修正前:
ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/testkey)
BUILD_VERSION_TAGS += test-keys
修正後:
ifeq ($(DEFAULT_SYSTEM_DEV_CERTIFICATE),build/target/product/security/releasekey)
BUILD_VERSION_TAGS += release-keys

II.修改Device Product名稱

lichee/brandy/u-boot-2011.09/usb_sunxi/usb_fastboot.h
修正前:
#define SUNXI_FASTBOOT_DEVICE_PRODUCT "Android Fastboot" /*產品資訊*/
修正後:
#define SUNXI_FASTBOOT_DEVICE_PRODUCT "exdroid" /*產品資訊*/

clip_image002
在刷機的時候會去檢查Device Product是否與Update requires相同,若未修改則會遇到上面的狀況而刷機失敗。目前不曉得Update requires的名稱在哪邊可以設定。

Setup Ubuntu virtual memory

在build android 時後發現電腦會整個卡住,發現其實Ubuntu 的swap功能沒被啟動,有兩個原因:1.沒有分割linux-swap磁區。2.設定的UUID不同。
Screenshot from 2015-08-15 17%3A59%3A20
打開terminal
  • 輸入free 查看記憶體使用狀況,若swap大小為0 則是沒有啟動swap功能。
    free
  • 輸入 blkid 查詢磁碟分割狀況。
    blkid
  • 自行指定要掛載哪個磁區,輸入swapon /dev/sda5 ,Type="swap"的那個磁區。
    swap
  • 自動掛載,輸入swapon –a
    swapon
  • 若自動掛載發生找不到磁碟UUID的錯誤,請自行修改/etc/fstab裡頭的swap的UUID,每個人都會不同,請勿照抄。
    sudo vim /etc/fstab
    fstab
    這樣設定好在每次開機的時候就會自動掛載swap磁區啦!
設定好swap功能後接著再build android就不會卡住死當,看得出來記憶體快用光了就會使用虛擬記憶體,雖然很多人說虛擬記憶體會拖垮linux速度,但為了保險不卡死還是設定一下保命。
Screenshot from 2015-08-17 11%3A44%3A48
若需要調教swap使用效率的話可以參考官方文件。連結
如何分割磁區可以參考阿舍

2015年8月17日 星期一

Ubuntu 14.04 編譯 Android4.4 SDK A31

編譯Android source code,依照Installing required packages (Ubuntu 14.04)需安裝相關的套件。

Android Build

Once you have unpacked the SDK (the lichee directory in particular)

Configuring the Build

The SDK can build android or linux flavor images, and may target different boards. Running ./build.sh will list the options.
先至lichee下build linex kernel 產品所要選定的chip版本
lichee$ ./build.sh -p sun6i_fiber
I found that this failed silently when generating the rootfs(see gen_rootfs_log.txt). The reason for this was that the treat warning as errors flag was set in makedevs.mk. By removing this then everything worked as expected. Running build.sh will produce binaries and images underout/<platform>/{linux,android}.

Building Android

android4.4$ source build/envsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including device/asus/deb/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/lge/mako/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/softwinner/fiber-common/vendorsetup.sh
including device/softwinner/fiber-a31st512m/vendorsetup.sh
including device/softwinner/fiber-w02/vendorsetup.sh
including device/softwinner/fiber-a31st/vendorsetup.sh
including device/softwinner/fiber-3g/vendorsetup.sh
including device/softwinner/fiber-a31stm/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including sdk/bash_completion/adb.bash

android4.4$ 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_flo-userdebug
     8. aosp_deb-userdebug
     9. aosp_hammerhead-userdebug
     10. aosp_mako-userdebug
     11. aosp_manta-userdebug
     12. fiber_a31st512m-eng
     13. fiber_a31st512m-user
     14. fiber_w02-eng
     15. fiber_w02-user
     16. fiber_a31st-eng
     17. fiber_a31st-user
     18. fiber_3g-eng
     19. fiber_3g-user
     20. fiber_a31stm-eng
     21. fiber_a31stm-user
     22. mini_armv7a_neon-userdebug
     23. mini_mips-userdebug
     24. mini_x86-userdebug

Which would you like? [aosp_arm-eng] 18

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.4.2
TARGET_PRODUCT=fiber_3g
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=cortex-a7
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-3.13.0-61-generic-x86_64-with-Ubuntu-14.04-trusty
HOST_BUILD_TYPE=release
BUILD_ID=KOT49H
OUT_DIR=out
============================================

android4.4$ extract-bsp 
android4.4/device/*/fiber-3g/bImage copied!
android4.4/device/*/fiber-3g/modules copied

android4.4$ make –j4
This should create the image files that are needed for packing.

Packing the Image

經過漫長的等待,在android4.4/out/target/product/fiber-3g/產生這些檔案
boot.img
ramdisk.img
ramdisk-recovery.img
recovery.img
system.img
將build好的檔案打包成一個image(.img)檔
lichee$ ./build.sh pack
pack 完的image會輸出至 lichee/tools/pack_brandy/sun6i_android_fiber-3g.img,檔名會依照當初lunch選擇的項目稍有變動。

Notes

在build linux kernel與android4.4 一定要分兩個Terminal,不然在build的過程中會有一些warning而進入了Werror的錯誤。目前猜測應該是
lichee$ ./build.sh -p sun6i_fiber
android4.4$ source build/envsetup.sh
這兩個個別執行時會有些環境變數,或include path 互相影響了。

Ref:
http://linux-sunxi.org/SDK_build_howto_A31

2015年4月30日 星期四

在Xcode 6 中建立不使用Storyboard 的project

不想要使用龐大的Storyboard框架設計iOS app,於是找到可以建立一個簡單的乾淨專案的方法。
  1. Create an Single View Application with XCode6
  2. Remove Main.storyboard and LaunchScreen.xib (select them, right-click, and choose to either remove them from the project, or delete them completely).
  3. Remove "Main storyboard file base name" and "Launch screen interface file base name" entries in Info.plist file.
  4. Open AppDelegate.m, and edit application didFinishLaunchingWithOptions so that it looks like this: 

Ref: http://stackoverflow.com/questions/25783282/how-to-create-an-empty-application-in-xcode-6-without-storyboard