Coscup2011: porting android to brand-new cpu architecture
1. PORTING ANDROID TO
BRAND-NEW CPU ARCHITECTURE
新規CPUアーキテクチャにアンドロイドの移植
Luse Cheng <lusecheng@gmail.com>
August 21, 2011 @ COSCUP
2. 自我介紹
Experience
Compiler Lead at An Embedded CPU IP Company
Compiler Engineer at An Embedded CPU IP Company
Quick summary
Full-time Open-Source Developer
Part-time Open-Source Contributor
國民革命軍軍人(DIRDS:國四無雙)
專長: 屠龍之技 (Compiler)
3. An Embedded CPU IP Company
Andes Technology Corporation
32-bit Embedded CPU IP Company
Brand-new 32/16 mixed ISA
本土 32-bit 嵌入式處理系智財
簡單的說就是台灣的 ARM
或者說 ARM 就是英國 Andes (笑)
EEtimes 的 scouting report
Taiwan nurtures the next ARM
4. About This Session
Android = Armdroid
Android is arm-awareness product
Porting to non-ARM platform
x86 in not included: Android-x86 is very good project
x86 is a faster CPU than ARM
It’s good reference for us
Reference platform at this session
Andes architecture
5. Agenda
Brand new CPU architecture?
Platform quick-review
OK, let go !
Pre-requirement, bring up
Life is not fair, get used to it
Android porting guideline
How do you do your best?
Optimization
6. Brand new CPU architecture?
Andes ADP-AG102
N1233-F * 2 (533 MHz)
With Single/Double FPU
With SW cache-coherence
RAM: DDR-II 512 MB
GPU: XG22 2D-Only GPU
Output: D-SUB
800x600
ROOTFS: SDCARD
USB Keyboard, Mouse
7. Target Android Version
We use Froyo with tag 2.2.1
Why Froyo?
Andes BSP: Linux kernel 2.6.32
ADP-AG102 lack of 3D GPU
Can use over 80% Android AP
Version API level Distribution
Why tag 2.2.1? 3.x.x Honeycomb 11-13 0.9%
2.3.x Gingerbread 9-10 18.6%
Can use 32-bit host 2.2.x Froyo
2.0.x /2.1.x Eclair
8
5-7
59.4%
17.5%
1.6 Donut 4 2.2%
1.5 Cupcake 3 1.4%
From: Wikipedia (Android)
8. Agenda
Brand new CPU architecture?
Platform quick-review
OK, let go !
Pre-requirement, bring up
Life is not fair, get used to it
Android porting guideline
How do you do your best?
Optimization
9. OK, let go !
bring up 的最高指導原則: 先求有再求好
Pre-requirement
1. A Workable Environment (Real-Board or Virtual-Board)
至少要有開發板或模擬器
2. A Workable GNU-Toolchain
Froyo need : GCC 4.4 + Binutils 2.19
如果沒有怎麼辦?
如果有別的版本 (like GCC-4.2), 就使用別的版本
3. A Workable BSP (Board support package)
最好的情況: BSP 也是使用 2.6.32 系列的 Linux Kernel
事實上能找到一個動得很好的 BSP 其實不是簡單的事
10. A Workable BSP
Make sure BSP is workable on Linux environment
From Linux to Android-Linux
We must think then as two similar platform, but different
Reference change
Linux kernel
TLS system call
Integrate Android driver (No-ASM)
Linux kernel Bug Fix
Deadlock in page fault handling
arch/<arch-name>/kernel/time.c
Add function save_time_delta to support android wakelock
Make sure Android-Linux BSP is workable
11. Porting Android Build System
Folder <ROOT>/build
Arm-awareness !!
EX: core/binary.mk
Reference change
Add TARGET_linux-<arch>.mk
Add Linker scirpt <arch>elf.x and <arch>elf.xsc
Toolchain path in core/envsetup.mk
MISC Change:
Fix build message with hard-coding “ARM” or “Thumb”
Add TARGET_ARCH variable
Use <Vendor-board>.mk
13. Porting Dalvik VM
非常幸運, 如果只是要能動, 幾乎不用 Porting
Dalvik VM 已經包含了一個 generic 用 c 寫的直譯器
非得需要 Porting 的部分 : JNI
使用組合語言來實作
需要再寫一個 Hint 的產生方式
Alternative: Porting libffi (foreign function interface library)
以上兩種方法其實都需要寫組合語言
DVM Optimization
Fast Interpreter: 使用組語來處理 Dalvik 指令
JITTER: 使用動態編譯器來最佳化熱區 (快取機制)
14. Porting External Package
<ROOT>/external
其實不太需要 Porting
Fix misc compilation error and makefile change
Like external/webkit
Elfutils :
Sync EM number and RELOC type of Architecture
15. Build Whole Android Image
make TARGET_ARCH=nds32 -j4
Waiting for build complete ….
Finding NOTICE files: out/target/product/generic/obj/NOTICE_FILES/hash-timestamp
Combining NOTICE files: out/target/product/generic/obj/NOTICE.html
Target system fs image:
out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Installed file list: out/target/product/generic/installed-files.txt
OK, We can compile whole android for brand-new
CPU Architecture now
16. Configuration !
Configuration! You can porting android to
brand-new CPU architecture now!
不過如果你是工程師, 就會知道這一切才剛開始
If you are an engineer, you know that everything is
just beginning
あなたがエンジニアである場合, すべてはただ今始
まったばかりです
17. Agenda
Brand new CPU architecture?
Platform quick-review
OK, let go !
Pre-requirement, bring up
Life is not fair, get used to it
Android porting guideline
How do you do your best?
Optimization
19. Life is not fair, get used to it
Battery Problem
基本上是一個 Porting 到 non-Phone 的platform 最容易
遇到也必須要解決的一個問題
Google 上答案很多, 挑一個喜歡的帶回家 (!?)
10 秒鐘的幸福
Android Activity Manager Service 預設的 Timeout
很可惜台灣的CPU 不能享受這個奢華的幸福
20. Life is not fair, get used to it
電源管理
一看就知道很手機, 不改就會死人
Hack 掉一些很手機的 code
我很低調, 我不愛GPS !
老是喜歡讓大家使用beta產品的某公司首頁改版後, 沒
有GPS 的Android上某公司首頁後瀏覽器會 crash!
只好使用 那家公司唯一不是 beta 的產品 : Search
改 framework/base 的
location/java/android/location/LocationManager.java
22. Agenda
Brand new CPU architecture?
Platform quick-review
OK, let go !
Pre-requirement, bring up
Life is not fair, get used to it
Android porting guideline
How do you do your best?
Optimization
23. Why Don't You Do Your Best?
Source: http://yoake-kibo.jugem.jp/?eid=1671
24. How do you do your best?
Q:Why Don't You Do Your Best?
A: Life is not fair, get used to it
Era of Time-to-Market
能不能做到最好還要問有沒有時間做到最好
所以我們在這邊探討不探討”為何不”,只探討”如何”
身為產品洪流下, 工程師的宿命