Porting Android to new Platforms
Amit Pundir
Android Engineer, Linaro
Android Software Stack
Applications
Application
Frameworks
Libraries &
Runtime
Linux
Kernel Audio Display
Hardware
Abstraction
Layers
Firmware Binaries
WiFi BinderCamera Logger ...
GPSRadio (RIL)Camera
Media
NFSSensorsAudio ...
Skia
Core Libraries
Dalvik VM...
SQlite
ALSA
Freetype
Input
Webkit
System Services
Power Manager Activity Manager Package Manager
Content Manager Battery Service Window Manager
Location Manager Audio Service Alarm Manager
Network Manager Media Server ...
Home SettingsMedia PlayerCameraDialer ...
Android Open Source Project
● AOSP is not a single project.
● Hundreds of independent projects having own Git repositories.
● Don't need to pull the projects one by one. Repo tool for the
rescue.
● AOSP manifest file to download a snapshot.
● Android Documentation: Downloading the source tree
http://source.android.com/source/downloading.html
AOSP Code Structure
bionic Android's C library.
bootable Legacy Bootloader/Recovery code for reference
build AOSP Build framework
cts Android's Compatibility Test Suit
dalvik Dalvik Virtual Machine
development Development tools #tutorials #monkey
device Vendor specific configuration files
external External projects used in AOSP
frameworks Android core application framework
hardware Hardware specific libraries/modules #HAL
kernel Linux Kernel
libcore Apache Harmony. Fee Java implementation. Used by
Dalvik.
ndk Native Development Kit
packages AOSP's stock applications
prebuilt Prebuilt binaries such as Toolchain
sdk Android's Software Development Kit
system Android's core system libraries/binaries #init #toolbox #adb
Android Kernel
● Android patches are not available mainline.
● android-common project
→ Android patches on top of Linus's base tree.
● Extract patches and apply them to your Target specific
kernel.
Android Kernel Features
● Binder
→ Android's IPC mechanism. Inspired from Open Binder project.
● Ashmem or Anonymous Shared Memory
→ Shared memory allocator. Discards shared units under memory pressure.
● Logger
→ Android's driver which logs data from user space.
● Wakelocks
→ Prevents a system to enter suspend or low power states.
● Out Of Memory handler
→ Aggressive OOM handler. Triggers before Kernel's default
implementation.
● Alarm
→ Android's alarm timer implementation on top of Kernel's RTC
implementation.
● RAM console
→ Logs last Kernel log. Accessible through /proc/last_kmsg
● Paranoid network
→ Network administration through uid/pid e.g AID_NET_*
Common Android Hardware
Abstraction Layers
libaudio.so AudioHardwareInterface implementation.
libgralloc.so Graphics Buffer Allocator
“hardware/libhardware/modules/gralloc/”
libsensor.so Sensor modules.
libcamera.so CameraHardwareInterface implementation.
libgps.so GPS module.
libstagefrighthw.so Stagefright implementation for h/w codecs.
libril.so Radio interface layer module
... ...
HAL Module/Library loaders
● Run time loading
● hw_get_module()
● libgps, liblights, libgralloc, libsensors,
liboverlays etc
● dlopen()
● libstagefrighthw, libril etc
● Build time linking
● libaudio, libcamera etc
● Linux standard sysfs and /dev nodes
● Power management, Input devices etc
Device/Vendor specific
configuration files
● Build config files
● Target build requirements are set by build/core/{main.mk,
config.mk, product.mk, product_config.mk}
● Build process looks for target specific config file
BoardConfig.mk at device/*/$(TARGET_DEVICE) or vendor/*/$
(TARGET_DEVICE)
● TARGET_PRODUCT = TARGET_DEVICE =
PRODUCT_DEVICE, where PRODUCT_DEVICE is defined in
AndroidProducts.mk
● Android Run time config files init.rc, init.TARGET_PRODUCT.rc,
ueventd.rc, ueventd.TARGET_PRODUCT.rc, vold.fstab etc
● Set optional PRODUCT_PACKAGES for Pre-loaded applications.
● Generate Project manifest file. It is different from an Android
Application Manifest file.
AOSP Build Process
● Android Documentation: Building the system
http://source.android.com/source/building.html
● $ . build/envsetup.sh
→ Setting up build environment
● $ lunch
→ Choose correct TARGET_PRODUCT
● $ export USE_CCACHE = 1
→ will cache object files generated by the C/C++ compiler which can
be used to speed up next build.
● $ make -jX
→ where X = “the number of CPU cores in your build machine” + 1.
OR
● $ mm
→ make alias which is handy while building AOSP projects
independently.
Android Boot Process
Kernel
Init
Service
Manager
system
server
Zygote... ...
binder
System Services
Activity Manager Power Manager Package Manager
Content Manager Battery Service Window Manager
Location Manager Audio Service Alarm Manager
Network Manager Media Server ...
System
Server
Android
Application
Android Debugging
● Increase loglevel in init.rc
● dmesg
→ Dump Kernel logs
● logcat
→ Dump System logs
● adb and ddms
→ Android debug bridge and tool for remote debugging.
● dumpsys and dumpstate
→ Dump system services meminfo
● /proc/last_kmsg
→ Last dmesg or kernel log to debug random crashes.
● Traceview ?
→ http://android-developers.blogspot.com/2010/10/traceview-
war-story.html
Thank You

Q4.11: Porting Android to new Platforms

  • 1.
    Porting Android tonew Platforms Amit Pundir Android Engineer, Linaro
  • 2.
  • 3.
    Applications Application Frameworks Libraries & Runtime Linux Kernel AudioDisplay Hardware Abstraction Layers Firmware Binaries WiFi BinderCamera Logger ... GPSRadio (RIL)Camera Media NFSSensorsAudio ... Skia Core Libraries Dalvik VM... SQlite ALSA Freetype Input Webkit System Services Power Manager Activity Manager Package Manager Content Manager Battery Service Window Manager Location Manager Audio Service Alarm Manager Network Manager Media Server ... Home SettingsMedia PlayerCameraDialer ...
  • 4.
  • 5.
    ● AOSP isnot a single project. ● Hundreds of independent projects having own Git repositories. ● Don't need to pull the projects one by one. Repo tool for the rescue. ● AOSP manifest file to download a snapshot. ● Android Documentation: Downloading the source tree http://source.android.com/source/downloading.html
  • 6.
  • 7.
    bionic Android's Clibrary. bootable Legacy Bootloader/Recovery code for reference build AOSP Build framework cts Android's Compatibility Test Suit dalvik Dalvik Virtual Machine development Development tools #tutorials #monkey device Vendor specific configuration files external External projects used in AOSP frameworks Android core application framework hardware Hardware specific libraries/modules #HAL kernel Linux Kernel libcore Apache Harmony. Fee Java implementation. Used by Dalvik. ndk Native Development Kit packages AOSP's stock applications prebuilt Prebuilt binaries such as Toolchain sdk Android's Software Development Kit system Android's core system libraries/binaries #init #toolbox #adb
  • 8.
  • 9.
    ● Android patchesare not available mainline. ● android-common project → Android patches on top of Linus's base tree. ● Extract patches and apply them to your Target specific kernel.
  • 10.
  • 11.
    ● Binder → Android'sIPC mechanism. Inspired from Open Binder project. ● Ashmem or Anonymous Shared Memory → Shared memory allocator. Discards shared units under memory pressure. ● Logger → Android's driver which logs data from user space. ● Wakelocks → Prevents a system to enter suspend or low power states. ● Out Of Memory handler → Aggressive OOM handler. Triggers before Kernel's default implementation. ● Alarm → Android's alarm timer implementation on top of Kernel's RTC implementation. ● RAM console → Logs last Kernel log. Accessible through /proc/last_kmsg ● Paranoid network → Network administration through uid/pid e.g AID_NET_*
  • 12.
  • 13.
    libaudio.so AudioHardwareInterface implementation. libgralloc.soGraphics Buffer Allocator “hardware/libhardware/modules/gralloc/” libsensor.so Sensor modules. libcamera.so CameraHardwareInterface implementation. libgps.so GPS module. libstagefrighthw.so Stagefright implementation for h/w codecs. libril.so Radio interface layer module ... ...
  • 14.
  • 15.
    ● Run timeloading ● hw_get_module() ● libgps, liblights, libgralloc, libsensors, liboverlays etc ● dlopen() ● libstagefrighthw, libril etc ● Build time linking ● libaudio, libcamera etc ● Linux standard sysfs and /dev nodes ● Power management, Input devices etc
  • 16.
  • 17.
    ● Build configfiles ● Target build requirements are set by build/core/{main.mk, config.mk, product.mk, product_config.mk} ● Build process looks for target specific config file BoardConfig.mk at device/*/$(TARGET_DEVICE) or vendor/*/$ (TARGET_DEVICE) ● TARGET_PRODUCT = TARGET_DEVICE = PRODUCT_DEVICE, where PRODUCT_DEVICE is defined in AndroidProducts.mk ● Android Run time config files init.rc, init.TARGET_PRODUCT.rc, ueventd.rc, ueventd.TARGET_PRODUCT.rc, vold.fstab etc ● Set optional PRODUCT_PACKAGES for Pre-loaded applications. ● Generate Project manifest file. It is different from an Android Application Manifest file.
  • 18.
  • 19.
    ● Android Documentation:Building the system http://source.android.com/source/building.html ● $ . build/envsetup.sh → Setting up build environment ● $ lunch → Choose correct TARGET_PRODUCT ● $ export USE_CCACHE = 1 → will cache object files generated by the C/C++ compiler which can be used to speed up next build. ● $ make -jX → where X = “the number of CPU cores in your build machine” + 1. OR ● $ mm → make alias which is handy while building AOSP projects independently.
  • 20.
  • 21.
    Kernel Init Service Manager system server Zygote... ... binder System Services ActivityManager Power Manager Package Manager Content Manager Battery Service Window Manager Location Manager Audio Service Alarm Manager Network Manager Media Server ... System Server Android Application
  • 22.
  • 23.
    ● Increase loglevelin init.rc ● dmesg → Dump Kernel logs ● logcat → Dump System logs ● adb and ddms → Android debug bridge and tool for remote debugging. ● dumpsys and dumpstate → Dump system services meminfo ● /proc/last_kmsg → Last dmesg or kernel log to debug random crashes. ● Traceview ? → http://android-developers.blogspot.com/2010/10/traceview- war-story.html
  • 24.