SlideShare a Scribd company logo
1 of 60
Download to read offline
Android for
Embedded Linux Developers

      AnDevCon – March 9th 2011

   Karim Yaghmour / @karimyaghmour
About ...
●   Author of:




●   Introduced Linux Trace Toolkit in 1999
●   Originated Adeos and relayfs (kernel/relay.c)
1. Motivation
2. Stack Comparison
3. Android-Specific Concepts
4. Useful Embedded Linux Tricks
5. Pros and Cons
1. Motivation
●   Embedded Linux developers:
    ●   Developing Android apps
    ●   Porting apps
    ●   Creating custom Android device
●   Android developers:
    ●   Leverage Linux heritage
    ●   Learn embedded Linux tricks
    ●   Understand relation to embedded Linux
2. Stack Comparison
●   Starting point
●   Architecture
●   Requirements
●   Development approach
●   Development tools
●   Development environment
●   Bootloader
●   Kernel
●   Root filesystem
●   Startup
●   Default applications
●   Application development
2.1. Starting point - EL
●   Usually:
    ●   Bare/custom hardware
    ●   Create/building custom stack components
    ●   Lots of low-level work ahead (drivers, etc.)
    ●   No tools to start with
2.1. Starting point - Android
●   Usually – App dev:
    ●   Functional consumer-ready device
    ●   Fully-functional development environment
    ●   Distribution system for your app: Market
●   Exceptionally – Device dev:
    ●   Bare/custom hardware
    ●   Create/building custom stack components
    ●   Lots of low-level work ahead (drivers, etc.)
    ●   Fewer tools to start with
2.2. Architecture - EL
2.2. Architecture - Android
2.3. Requirements - EL
●   Minimal:
    ●   Linux workstation
    ●   GNU cross-development toolchain
    ●   Internet connection – download packages
●   Extras:
    ●   Distribution (free or $)
    ●   JTAG debugger
2.3. Requirements - Android
●   Minimal:
    ●   Windows / Mac / Linux workstation
    ●   JDK
    ●   Android SDK
    ●   Eclipse
●   Extras:
    ●   Android NDK
    ●   Android Open Source Project
2.4. Development approach - EL
1.Get a functional toolchain
2.Generate and β€œinstall” bootloader
3.Generate and β€œinstall” kernel
4.Create a basic functional root filesystem
5.Configure target to boot over NFS
6. ... Develop ...
7.Write root filesystem to flash
8.Ship
2.4. Development approach - Android
1.Create new project in Eclipse
2.Write application
3.Use emulator to debug
4.Test application on real device(S)
5.Ship
2.5. Development tools - EL
●   GNU cross-development toolchain:
    ●   gcc - compiler
    ●   as - assembler
    ●   ld - linker
    ●   gdb/gdbserver - debugger
    ●   etc.
●   C library: uClibc, eglibc or glibc
●   JTAG debugger
2.5. Development tools - Android
●   SDK:
    ●   android – manage AVDs and SDK components
    ●   apkbuilder – creating .apk packages
    ●   dx – converting .jar to .dex
    ●   adb – debug bridge
    ●   emulator – QEMU-based ARM emulator
    ●   ...
●   Eclipse w/ ADT plugin
●   NDK: GNU toolchain for native binaries
2.6. Development environment - EL
●   Editor/IDE:
    ●   vi
    ●   emacs
    ●   Eclipse
    ●   K Develop
●   CLI
●   Serial port emulator: minicom, C-Kermit, ...
2.6. Development env. - Android
●   Mainly:
    ●   Eclipse
    ●   Emulator
●   Maybe:
    ●   Favourite editor
    ●   CLI
    ●   adb
2.7. Bootloader - EL
●   U-Boot: PPC, ARM, x86, MIPS, SuperH, ...
    ●   CLI interface, serial-based
    ●   Environment variables, including built-in scripts
    ●   Evolved from forks and merges (8xxrom / PPCBoot / ARMBoot)
    ●   Very versatile and flexible bootloader
    ●   Actively maintained
    ●   Very mature
    ●   Supports a wide range of boot methods: TFTP, DHCP, IDE, SCSI,
        DOC, JFFS2, ...
    ●   Fairly well documented
    ●   Distributed under the terms of the GPL
2.7. Bootloader - Android
●   aosp/bootable/bootloader
    ●   Custom bootloader for Android
    ●   USB-based
    ●   Implements the β€œfastboot” protocol
    ●   Controlled via β€œfastboot” cli tool on host
●   aosp/bootable/recovery
    ●   UI-based recovery boot program
    ●   Accessed through magic key sequence at boot
    ●   Usually manufacturer specific variant
2.8. Kernel – EL
●   Stock kernel from kernel.org
●   May require porting to custom hardware
2.8. Kernel - Android
●   Android-specific patches:
    ●   Wakelocks
    ●   lowmem handler
    ●   Binder
    ●   Ashmem – anynoymous shared memory
    ●   RAM console
    ●   Logger
    ●   ...
2.9. Root filesystem - EL
●   /bin    =>   Essential user binaries
●   /boot   =>   Bootloader and kernel images
●   /dev    =>   Device files
●   /etc    =>   System configuration
●   /home =>     User home directories
●   /lib    =>   Essential shared libs and kernel modules
●   /mnt    =>   Temporary mount point
●   /opt    =>   Add-on software packages
●   /proc   =>   Virtual filesystem for kernel information
●   /sbin   =>   Essential system binaries
●   /sys    =>   Virtual filesystem for device access and information
●   /tmp    =>   Temporary files
●   /usr    =>   Secondary hierarchy (mostly user apps)
●   /var    =>   Variable data generated by daemons
2.9. Root filesystem - Android
●   Mainly
    ●   /data    => User data
    ●   /system => System components
●   Also found:
    ●   /cache
    ●   /mnt
    ●   /sbin
    ●   Etc.
2.10. Startup - EL
●   Software taking part in the system's startup:
    ●   Bootloader
    ●   Kernel
    ●   Init process
●   Bootloader:
    ●   First to run
    ●   Initializes hardware to a known state
    ●   Places kernel parameters for the kernel to find
    ●   Loads kernel and jumps to it
●   Kernel:
    ●   Early startup code is very hardware dependent
    ●   Initializes environment for the running of C code
    ●   Jumps to the architecture-independent start_kernel()
        function.
    ●   Initializes high-level kernel subsystems
    ●   Mounts root filesystem
    ●   Starts the init process
●   The init process takes care of loading all the user
    applications and starting the various daemons.
2.10. Startup - Android
●   Components involved
    ●   Bootloader
    ●   Kernel
    ●   Init
    ●   Zygote
    ●   System Server
    ●   Activity Manager
    ●   Launcher (Home)
●   Flash layout:
       0x000003860000Β­0x000003900000Β :Β "misc"
       0x000003900000Β­0x000003e00000Β :Β "recovery"
       0x000003e00000Β­0x000004300000Β :Β "boot"        Kernel
       0x000004300000Β­0x00000c300000Β :Β "system"      /system
       0x00000c300000Β­0x0000183c0000Β :Β "userdata"    /data
       0x0000183c0000Β­0x00001dd20000Β :Β "cache"       /cache
       0x00001dd20000Β­0x00001df20000Β :Β "kpanic"
       0x00001df20000Β­0x00001df60000Β :Β "dinfo"
       0x00001df60000Β­0x00001dfc0000Β :Β "setupdata"
       0x00001dfc0000Β­0x00001e040000Β :Β "splash1"
       0x000000300000Β­0x000001680000Β :Β "modem"
                      From Acer Liquid-E
●   Android's init - opens, parses, and runs /init.rc:
    ●   Create mountpoints and mount filesystems
    ●   Set up filesystem permissions
    ●   Set OOM adjustments properties
    ●   Start daemons:
        –   adbd
        –   servicemanager (binder)
        –   vold
        –   netd
        –   rild
        –   app_process -Xzygote (Zygote)
        –   mediaserver
        –   ...
2.11. Default applications - EL
●   Busybox
     [, [[, acpid, add-shell, addgroup, adduser, adjtimex, arp, arping, ash, awk, base64, basename, beep, blkid,
     blockdev, bootchartd, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpasswd,
     chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cryptpw, cttyhack, cut, date, dc, dd,
     deallocvt, delgroup, deluser, depmod, devmem, df, dhcprelay, diff, dirname, dmesg, dnsd, dnsdomainname,
     dos2unix, du, dumpkmap, dumpleases, echo, ed, egrep, eject, env, envdir, envuidgid, ether-wake, expand, expr,
     fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flock, fold, free, freeramdisk,
     fsck, fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, getty, grep, gunzip, gzip, halt, hd, hdparm, head, hexdump,
     hostid, hostname, httpd, hush, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd, init, insmod, install,
     ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, last,
     length, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, logger, login, logname, logread, losetup, lpd, lpq, lpr,
     ls, lsattr, lsmod, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg,
     microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.minix, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp,
     modinfo, modprobe, more, mount, mountpoint, mpstat, mt, mv, nameif, nbd-client, nc, netstat, nice, nmeter, nohup,
     nslookup, ntpd, od, openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap,
     popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pwd, raidautorun, rdate, rdev, readahead, readlink,
     readprofile, realpath, reboot, reformime, remove-shell, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm,
     rpm2cpio, rtcwake, run-parts, runlevel, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setarch,
     setconsole, setfont, setkeycodes, setlogcons, setsid, setuidgid, sh, sha1sum, sha256sum, sha512sum, showkey,
     slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, su, sulogin, sum, sv, svlogd,
     swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time,
     timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize, tunctl, udhcpc, udhcpd, udpsvd, umount, uname,
     unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, vlock,
     volname, wall, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat, zcip
2.11. Default applications - Android
    ● System Server
    ● Toolbox

    ● Native daemons

    ● Stock Android apps


/packages/apps                           /packages/providers      /packages/inputmethods

AccountsAndSettings   Launcher2          ApplicationProvider      LatinIME
AlarmClock            Mms                CalendarProvider         OpenWnn
Bluetooth             Music              ContactsProvider         PinyinIME
Browser               PackageInstaller   DownloadProvider
Calculator            Protips            DrmProvider
Calendar              Provision          GoogleContactsProvider
Camera                QuickSearchBox     MediaProvider
CertInstaller         Settings           TelephonyProvider
Contacts              SoundRecorder      UserDictionaryProvider
DeskClock             SpeechRecorder
Email                 Stk
Gallery               VoiceDialer
HTMLViewer
2.12. Application development - EL
●   Most apps:
    ●   C library
    ●   Unix systems programming
●   Window-based apps:
    ●   X window
    ●   Toolkits:
         –   Qt / GTK
    ●   Windowing systems:
         –   Qt Framework (formerly Qtopia)
         –   Gnome / KDE / Unity / etc.
2.12. Application dev. - Android
●   Android API
2.13. Application debugging - EL
●   gdb
●   strace
●   IDE integration
2.13. Application debugging - Android
●   adb
●   ddms
●   monkeyrunner
●   traceview
●   logcat
●   Eclipse integration
3. Android-specific Concepts
●   App fundamentals
●   Framework components
●   Native development
3.1. App fundamentals
●   Components
●   Intents
●   Component lifecycle
●   Manifest file
●   Processes and threads
●   Remote procedure calls
3.1.1. Components
●   1 App = N Components
●   Apps can use components of other applications
●   App processes are automagically started whenever any part
    is needed
●   Ergo: N entry points, !1, and !main()
●   Components:
    ●   Activities
    ●   Services
    ●   Broadcast Receivers
    ●   Content Providers
3.1.2. Intents
●   Intent = asynchronous message w/ or w/o
    designated target
●   Like a polymorphic Unix signal, but w/o
    required target
●   Intents β€œpayload” held in Intent Object
●   Intent Filters specified in Manifest file
3.1.3. Component lifecycle
●   System automagically starts/stops/kills
    processes:
    ●   Entire system behaviour predicated on low memory
●   System triggers Lifecycle callbacks when
    relevant
●   Ergo: Must manage Component Lifecycle
●   Some Components are more complex to
    manage than others
3.1.4. Manifest file
●   Informs system about app’s components
●   XML format
●   Always called AndroidManifest.xml
●   Activity = <activity> ... static
●   Service = <service> ... static
●   Broadcast Receiver:
    ●   Static = <receiver>
    ●   Dynamic = Context.registerReceiver()
●   Content Provider = <provider> ... static
3.1.5. Processes and threads
●   Processes
    ●   Default: all callbacks to any app Component are issued to the main process thread
    ●   <activity>β€”<service>β€”<recipient>β€”<provider> have process attribute to override
        default
    ●   Do NOT perform blocking/long operations in main process thread:
        –   Spawn threads instead
    ●   Process termination/restart is at system’s discretion
    ●   Therefore:
        –   Must manage Component Lifecycle
●   Threads:
    ●   Create using the regular Java Thread Object
    ●   Android API provides thread helper classes:
        –   Looper: for running a message loop with a thread
        –   Handler: for processing messages
        –   HandlerThread: for setting up a thread with a message loop
3.1.6. Remote procedure calls
●   Apparently System V IPC is evil ...
●   Android RPCs = Binder mechanism
●   Binder is a low-level functionality, not used as-is
●   Instead: must define interface using Interface
    Definition Language (IDL)
●   IDL fed to aidl Tool to generate Java interface
    definitions
3.2. Framework components
●   UI
●   Data storage
●   Security/Permissions
●   ... and much more ... :
    ●    Graphics
    ●    Audio and Video
    ●    Location and Maps
    ●    Bluetooth
    ●    NFC
3.2.1. UI
●   Everything based on hierarchy of Views and
    ViewGroups (layouts)
●   Declared in XML or dynamically through Java
●   UI components:
    ●   Widgets
    ●   Event handlers
    ●   Menus
    ●   Dialogs
    ●   Notifications
    ●   ...
3.2.2. Data storage
●   Shared preferences
    ●   Private primitive key-pair values
●   Internal storage
    ●   Private data on device memory
●   External storage
    ●   Public data on shared external device (SD)
●   SQLite DB
    ●   Private DB
●   Network connection
    ●   Web-based storage (REST)
3.2.3. Security/Permissions
●   Most security enforced at process level: UID, GID
●   Permissions enforce restrictions on:
    ●   Per-process operations
    ●   Per-URI access
●   Applications are sandboxed
●   Specific permissions required to β€œexit” sandbox
●   Decision to grant access based on:
    ●   Certificates
    ●   User prompts
●   All permissions must be declared statically
3.3. Native development
●   What it can and cannot do
●   Getting and installing the NDK
●   Using the NDK
●   Implementing fully native apps
3.3.1. What it can and cannot do
●   Useful for:
    ●   Porting existing body of code to Android
    ●   Developing optimized native apps, especially for gaming
●   Provides:
    ●   Tools and build files to generate native code libraries from C/C++
    ●   Way to embed native libs into .apk
    ●   Set of stable (forward-compatible) native libs
    ●   Documentation, samples and tutorials
●   Enables:
    ●   Calling native code from Java using JNI
    ●   Implementing fully native apps (since 2.3)
●   Doesn't allow you to:
    ●   Compile traditional Linux/Unix apps as-is
3.3.2. Getting and installing the NDK
●   What’s in the NDK?
    ●   Development tools
    ●   Stable native APIs system headers
    ●   Documentation - IMPORTANT
    ●   Samples
●   Getting the NDK
    ●   http://developer.android.com/sdk/ndk/index.html
●   Prerequisites
    ●   Windows, Mac or Linux
    ●   Complete SDK
    ●   make (GNU’s) and awk
    ●   For Windows, Cygwin 1.7 or higher
●   NDK set up:
    ●   Make sure prerequisites are installed
    ●   Download and install NDK
3.3.3. Using the NDK
1.Place native code under <project>/jni/...
2.Create <project>/jni/Android.mk to describe native code
  to NDK
3.Optional: create <project>/jni/Application.mk for
  describing which natives sources are required by app
4.Build native code:
  β€’   cd <project>
  β€’   <ndk>/ndk-build
5.Compile app with SDK. Native code will be shared lib
  in .apk file.
3.3.4. Implementing fully native apps
●   Android 2.3 and up
●   Native lifecycle management
●   Still runs within context of dedicated Dalvik VM
●   Can use JNI to call on Java functions
●   Limited API:
    ●   Activity lifecycle management
    ●   Input events and sensors
    ●   Window management
    ●   Direct access to assets
●   Make sure your activity is called: β€œandroid.app.NativeActivity”
4. Useful Embedded Linux Tricks
●   crosstool-ng
●   Busybox
●   uClibc
4.1. crosstool-ng
●   Cross-development toolchain generator
●   Successor to crosstool
●   Available at:
     http://ymorin.is-a-geek.org/projects/crosstool
●   Downloads, patches, builds, installs, etc.
●   Comprises 23 steps
●   Menuconfig-based
●   Supports uClibc, glibc and eglibc
●   Supports ARM, Blackfin, MIPS, PowerPC, SH, …
●   Fairly well maintained
4.2. Busybox
●   Replicate Linux CLI experience
     [, [[, acpid, add-shell, addgroup, adduser, adjtimex, arp, arping, ash, awk, base64, basename, beep, blkid,
     blockdev, bootchartd, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpasswd,
     chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cryptpw, cttyhack, cut, date, dc, dd,
     deallocvt, delgroup, deluser, depmod, devmem, df, dhcprelay, diff, dirname, dmesg, dnsd, dnsdomainname,
     dos2unix, du, dumpkmap, dumpleases, echo, ed, egrep, eject, env, envdir, envuidgid, ether-wake, expand, expr,
     fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flock, fold, free, freeramdisk,
     fsck, fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, getty, grep, gunzip, gzip, halt, hd, hdparm, head, hexdump,
     hostid, hostname, httpd, hush, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd, init, insmod, install,
     ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, last,
     length, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, logger, login, logname, logread, losetup, lpd, lpq, lpr,
     ls, lsattr, lsmod, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg,
     microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.minix, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp,
     modinfo, modprobe, more, mount, mountpoint, mpstat, mt, mv, nameif, nbd-client, nc, netstat, nice, nmeter, nohup,
     nslookup, ntpd, od, openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap,
     popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pwd, raidautorun, rdate, rdev, readahead, readlink,
     readprofile, realpath, reboot, reformime, remove-shell, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm,
     rpm2cpio, rtcwake, run-parts, runlevel, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setarch,
     setconsole, setfont, setkeycodes, setlogcons, setsid, setuidgid, sh, sha1sum, sha256sum, sha512sum, showkey,
     slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, su, sulogin, sum, sv, svlogd,
     swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time,
     timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize, tunctl, udhcpc, udhcpd, udpsvd, umount, uname,
     unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, vlock,
     volname, wall, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat, zcip
●   Some features of interest:
    ●   color-coded file lists
    ●   tab completion
    ●   "home", "end"
    ●   grep, sed, wc, more, less
    ●   vi
    ●   ifconfig
    ●   httpd
    ●   sendmail
    ●   tftp
    ●   top
    ●   ...
●   Download BusyBox (1.18.3)
●   Move to the directory for the rest of the setup:
    $ cd busybox-1.18.3

●   Configuration of BusyBox's options:
    $ make menuconfig

●   Options that must be set:
    ●   β€œBuild Options” -> β€œDo you want to build BusyBox with a Cross Compiler?”
    ●   Cross-compiler prefix: arm-unknown-linux-gnueabi-
    ●   β€œInstallation Options” -> β€œDon't use /usr”
    ●   Installation prefix: ${PRJROOT}/rootfs
●   Build:
    $ make

●   Install:
    $ make install
●   Cheat sheet:
       Commands to get the new Busybox onto the rootfs:
       adb shell mount -o remount,rw rootfs /
       adb shell mkdir /bin
       adb push busybox /bin/
       adb shell /bin/busybox --install /bin
       adb shell

       To do after going into the shell:
       /bin/ash
       export PATH=/bin:$PATH
4.3. uClibc
●   Originates from uClinux effort
●   Support both CPUs that have and those that
    lack an MMU and/or an FPU.
●   Allows both static and dynamic linking
●   Most applications that build with glibc will build
    and work the same with uClibc.
●   Available from: http://uclibc.org/
5. Pros and Cons
●   Target application type:
    ●   Stock Android vs. Custom Android
●   Development language
●   Licensing
●   Branding:
    ●   Do you care about the CTS?
Thank you ...



karim.yaghmour@opersys.com




     www.opersys.com

More Related Content

What's hot

Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Opersys inc.
Β 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
Utkarsh Mankad
Β 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
Β 

What's hot (20)

Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
Β 
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Using and Customizing the Android Framework / part 4 of Embedded Android Work...
Β 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
Β 
Android Internals
Android InternalsAndroid Internals
Android Internals
Β 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
Β 
Deep Dive into the AOSP
Deep Dive into the AOSPDeep Dive into the AOSP
Deep Dive into the AOSP
Β 
Android Internals
Android InternalsAndroid Internals
Android Internals
Β 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
Β 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
Β 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
Β 
Building aosp
Building aospBuilding aosp
Building aosp
Β 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
Β 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
Β 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Β 
Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)
Β 
Porting Android
Porting AndroidPorting Android
Porting Android
Β 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with Pie
Β 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
Β 
Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)Using the Android Native Development Kit (NDK)
Using the Android Native Development Kit (NDK)
Β 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
Β 

Viewers also liked

Play With Android
Play With AndroidPlay With Android
Play With Android
Champ Yen
Β 
Bootloader and bootloading
Bootloader and bootloadingBootloader and bootloading
Bootloader and bootloading
Arpita Gupta
Β 
Android Radio Layer Interface
Android Radio Layer InterfaceAndroid Radio Layer Interface
Android Radio Layer Interface
Chun-Yu Wang
Β 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
Lihan Chen
Β 

Viewers also liked (20)

Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
Β 
Play With Android
Play With AndroidPlay With Android
Play With Android
Β 
Bootloader and bootloading
Bootloader and bootloadingBootloader and bootloading
Bootloader and bootloading
Β 
Android Architecture
Android ArchitectureAndroid Architecture
Android Architecture
Β 
Accessing Hardware on Android
Accessing Hardware on AndroidAccessing Hardware on Android
Accessing Hardware on Android
Β 
How To Build Android for ARM Chip boards
How To Build Android for ARM Chip boardsHow To Build Android for ARM Chip boards
How To Build Android for ARM Chip boards
Β 
Hacking Android OS
Hacking Android OSHacking Android OS
Hacking Android OS
Β 
Fuzzing the Media Framework in Android
Fuzzing the Media Framework in AndroidFuzzing the Media Framework in Android
Fuzzing the Media Framework in Android
Β 
How to reverse engineer Android applicationsβ€”using a popular word game as an ...
How to reverse engineer Android applicationsβ€”using a popular word game as an ...How to reverse engineer Android applicationsβ€”using a popular word game as an ...
How to reverse engineer Android applicationsβ€”using a popular word game as an ...
Β 
Android Booting Scenarios
Android Booting ScenariosAndroid Booting Scenarios
Android Booting Scenarios
Β 
08 android multimedia_framework_overview
08 android multimedia_framework_overview08 android multimedia_framework_overview
08 android multimedia_framework_overview
Β 
Udev
UdevUdev
Udev
Β 
OpenGL ES 2.x Programming Introduction
OpenGL ES 2.x Programming IntroductionOpenGL ES 2.x Programming Introduction
OpenGL ES 2.x Programming Introduction
Β 
RIL and Android Telephony
RIL and Android TelephonyRIL and Android Telephony
RIL and Android Telephony
Β 
Linux Kernel Tour
Linux Kernel TourLinux Kernel Tour
Linux Kernel Tour
Β 
Learning by hacking - android application hacking tutorial
Learning by hacking - android application hacking tutorialLearning by hacking - android application hacking tutorial
Learning by hacking - android application hacking tutorial
Β 
Android Radio Layer Interface
Android Radio Layer InterfaceAndroid Radio Layer Interface
Android Radio Layer Interface
Β 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
Β 
System Booting Process overview
System Booting Process overviewSystem Booting Process overview
System Booting Process overview
Β 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overview
Β 

Similar to Android for Embedded Linux Developers

Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
Opersys inc.
Β 
Leveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IVLeveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IV
Opersys inc.
Β 
Android Variants, Hacks, Tricks and Resources presented at AnDevConII
Android Variants, Hacks, Tricks and Resources presented at AnDevConIIAndroid Variants, Hacks, Tricks and Resources presented at AnDevConII
Android Variants, Hacks, Tricks and Resources presented at AnDevConII
Opersys inc.
Β 
Leveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VILeveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VI
Opersys inc.
Β 
Leveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon VLeveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon V
Opersys inc.
Β 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Docker, Inc.
Β 
EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...
EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...
EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...
melbats
Β 

Similar to Android for Embedded Linux Developers (20)

Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
Β 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
Β 
Leveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IVLeveraging Android's Linux Heritage at AnDevCon IV
Leveraging Android's Linux Heritage at AnDevCon IV
Β 
Android Variants, Hacks, Tricks and Resources presented at AnDevConII
Android Variants, Hacks, Tricks and Resources presented at AnDevConIIAndroid Variants, Hacks, Tricks and Resources presented at AnDevConII
Android Variants, Hacks, Tricks and Resources presented at AnDevConII
Β 
Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3Leveraging Android's Linux Heritage at AnDevCon3
Leveraging Android's Linux Heritage at AnDevCon3
Β 
Porting Android
Porting AndroidPorting Android
Porting Android
Β 
Porting Android ABS 2011
Porting Android ABS 2011Porting Android ABS 2011
Porting Android ABS 2011
Β 
Leveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VILeveraging Android's Linux Heritage at AnDevCon VI
Leveraging Android's Linux Heritage at AnDevCon VI
Β 
Leveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon VLeveraging Android's Linux Heritage at AnDevCon V
Leveraging Android's Linux Heritage at AnDevCon V
Β 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Β 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Β 
Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UI
Β 
Grub and dracut ii
Grub and dracut iiGrub and dracut ii
Grub and dracut ii
Β 
Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013
Β 
embedded-linux-120203.pdf
embedded-linux-120203.pdfembedded-linux-120203.pdf
embedded-linux-120203.pdf
Β 
Android Hacks, Variants, Tricks and Resources ESC SV 2012
Android Hacks, Variants, Tricks and Resources ESC SV 2012Android Hacks, Variants, Tricks and Resources ESC SV 2012
Android Hacks, Variants, Tricks and Resources ESC SV 2012
Β 
Android Variants, Hacks, Tricks and Resources
Android Variants, Hacks, Tricks and ResourcesAndroid Variants, Hacks, Tricks and Resources
Android Variants, Hacks, Tricks and Resources
Β 
Leveraging Android's Linux Heritage
Leveraging Android's Linux HeritageLeveraging Android's Linux Heritage
Leveraging Android's Linux Heritage
Β 
The Deck by Phil Polstra GrrCON2012
The Deck by Phil Polstra GrrCON2012The Deck by Phil Polstra GrrCON2012
The Deck by Phil Polstra GrrCON2012
Β 
EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...
EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...
EclipseCon Eu 2012 - Buildroot Eclipse Bundle : A powerful IDE for Embedded L...
Β 

More from Opersys inc.

More from Opersys inc. (20)

Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
Β 
Android 10 Internals Update
Android 10 Internals UpdateAndroid 10 Internals Update
Android 10 Internals Update
Β 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
Β 
Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?
Β 
Embedded Android Workshop with Oreo
Embedded Android Workshop with OreoEmbedded Android Workshop with Oreo
Embedded Android Workshop with Oreo
Β 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
Β 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
Β 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
Β 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
Β 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
Β 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoT
Β 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
Β 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
Β 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave Internals
Β 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
Β 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
Β 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
Β 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave Internals
Β 
Project Ara
Project AraProject Ara
Project Ara
Β 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
Β 

Recently uploaded

Recently uploaded (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Β 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
Β 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Β 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Β 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Β 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Β 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
Β 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Β 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Β 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Β 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Β 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Β 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
Β 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Β 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Β 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Β 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Β 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Β 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Β 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Β 

Android for Embedded Linux Developers

  • 1. Android for Embedded Linux Developers AnDevCon – March 9th 2011 Karim Yaghmour / @karimyaghmour
  • 2. About ... ● Author of: ● Introduced Linux Trace Toolkit in 1999 ● Originated Adeos and relayfs (kernel/relay.c)
  • 3. 1. Motivation 2. Stack Comparison 3. Android-Specific Concepts 4. Useful Embedded Linux Tricks 5. Pros and Cons
  • 4. 1. Motivation ● Embedded Linux developers: ● Developing Android apps ● Porting apps ● Creating custom Android device ● Android developers: ● Leverage Linux heritage ● Learn embedded Linux tricks ● Understand relation to embedded Linux
  • 5. 2. Stack Comparison ● Starting point ● Architecture ● Requirements ● Development approach ● Development tools ● Development environment ● Bootloader ● Kernel ● Root filesystem ● Startup ● Default applications ● Application development
  • 6. 2.1. Starting point - EL ● Usually: ● Bare/custom hardware ● Create/building custom stack components ● Lots of low-level work ahead (drivers, etc.) ● No tools to start with
  • 7. 2.1. Starting point - Android ● Usually – App dev: ● Functional consumer-ready device ● Fully-functional development environment ● Distribution system for your app: Market ● Exceptionally – Device dev: ● Bare/custom hardware ● Create/building custom stack components ● Lots of low-level work ahead (drivers, etc.) ● Fewer tools to start with
  • 10. 2.3. Requirements - EL ● Minimal: ● Linux workstation ● GNU cross-development toolchain ● Internet connection – download packages ● Extras: ● Distribution (free or $) ● JTAG debugger
  • 11. 2.3. Requirements - Android ● Minimal: ● Windows / Mac / Linux workstation ● JDK ● Android SDK ● Eclipse ● Extras: ● Android NDK ● Android Open Source Project
  • 12. 2.4. Development approach - EL 1.Get a functional toolchain 2.Generate and β€œinstall” bootloader 3.Generate and β€œinstall” kernel 4.Create a basic functional root filesystem 5.Configure target to boot over NFS 6. ... Develop ... 7.Write root filesystem to flash 8.Ship
  • 13. 2.4. Development approach - Android 1.Create new project in Eclipse 2.Write application 3.Use emulator to debug 4.Test application on real device(S) 5.Ship
  • 14. 2.5. Development tools - EL ● GNU cross-development toolchain: ● gcc - compiler ● as - assembler ● ld - linker ● gdb/gdbserver - debugger ● etc. ● C library: uClibc, eglibc or glibc ● JTAG debugger
  • 15. 2.5. Development tools - Android ● SDK: ● android – manage AVDs and SDK components ● apkbuilder – creating .apk packages ● dx – converting .jar to .dex ● adb – debug bridge ● emulator – QEMU-based ARM emulator ● ... ● Eclipse w/ ADT plugin ● NDK: GNU toolchain for native binaries
  • 16. 2.6. Development environment - EL ● Editor/IDE: ● vi ● emacs ● Eclipse ● K Develop ● CLI ● Serial port emulator: minicom, C-Kermit, ...
  • 17. 2.6. Development env. - Android ● Mainly: ● Eclipse ● Emulator ● Maybe: ● Favourite editor ● CLI ● adb
  • 18. 2.7. Bootloader - EL ● U-Boot: PPC, ARM, x86, MIPS, SuperH, ... ● CLI interface, serial-based ● Environment variables, including built-in scripts ● Evolved from forks and merges (8xxrom / PPCBoot / ARMBoot) ● Very versatile and flexible bootloader ● Actively maintained ● Very mature ● Supports a wide range of boot methods: TFTP, DHCP, IDE, SCSI, DOC, JFFS2, ... ● Fairly well documented ● Distributed under the terms of the GPL
  • 19. 2.7. Bootloader - Android ● aosp/bootable/bootloader ● Custom bootloader for Android ● USB-based ● Implements the β€œfastboot” protocol ● Controlled via β€œfastboot” cli tool on host ● aosp/bootable/recovery ● UI-based recovery boot program ● Accessed through magic key sequence at boot ● Usually manufacturer specific variant
  • 20. 2.8. Kernel – EL ● Stock kernel from kernel.org ● May require porting to custom hardware
  • 21. 2.8. Kernel - Android ● Android-specific patches: ● Wakelocks ● lowmem handler ● Binder ● Ashmem – anynoymous shared memory ● RAM console ● Logger ● ...
  • 22. 2.9. Root filesystem - EL ● /bin => Essential user binaries ● /boot => Bootloader and kernel images ● /dev => Device files ● /etc => System configuration ● /home => User home directories ● /lib => Essential shared libs and kernel modules ● /mnt => Temporary mount point ● /opt => Add-on software packages ● /proc => Virtual filesystem for kernel information ● /sbin => Essential system binaries ● /sys => Virtual filesystem for device access and information ● /tmp => Temporary files ● /usr => Secondary hierarchy (mostly user apps) ● /var => Variable data generated by daemons
  • 23. 2.9. Root filesystem - Android ● Mainly ● /data => User data ● /system => System components ● Also found: ● /cache ● /mnt ● /sbin ● Etc.
  • 24. 2.10. Startup - EL ● Software taking part in the system's startup: ● Bootloader ● Kernel ● Init process ● Bootloader: ● First to run ● Initializes hardware to a known state ● Places kernel parameters for the kernel to find ● Loads kernel and jumps to it
  • 25. ● Kernel: ● Early startup code is very hardware dependent ● Initializes environment for the running of C code ● Jumps to the architecture-independent start_kernel() function. ● Initializes high-level kernel subsystems ● Mounts root filesystem ● Starts the init process ● The init process takes care of loading all the user applications and starting the various daemons.
  • 26. 2.10. Startup - Android ● Components involved ● Bootloader ● Kernel ● Init ● Zygote ● System Server ● Activity Manager ● Launcher (Home)
  • 27. ● Flash layout: 0x000003860000Β­0x000003900000Β :Β "misc" 0x000003900000Β­0x000003e00000Β :Β "recovery" 0x000003e00000Β­0x000004300000Β :Β "boot" Kernel 0x000004300000Β­0x00000c300000Β :Β "system" /system 0x00000c300000Β­0x0000183c0000Β :Β "userdata" /data 0x0000183c0000Β­0x00001dd20000Β :Β "cache" /cache 0x00001dd20000Β­0x00001df20000Β :Β "kpanic" 0x00001df20000Β­0x00001df60000Β :Β "dinfo" 0x00001df60000Β­0x00001dfc0000Β :Β "setupdata" 0x00001dfc0000Β­0x00001e040000Β :Β "splash1" 0x000000300000Β­0x000001680000Β :Β "modem" From Acer Liquid-E
  • 28. ● Android's init - opens, parses, and runs /init.rc: ● Create mountpoints and mount filesystems ● Set up filesystem permissions ● Set OOM adjustments properties ● Start daemons: – adbd – servicemanager (binder) – vold – netd – rild – app_process -Xzygote (Zygote) – mediaserver – ...
  • 29. 2.11. Default applications - EL ● Busybox [, [[, acpid, add-shell, addgroup, adduser, adjtimex, arp, arping, ash, awk, base64, basename, beep, blkid, blockdev, bootchartd, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpasswd, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cryptpw, cttyhack, cut, date, dc, dd, deallocvt, delgroup, deluser, depmod, devmem, df, dhcprelay, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, du, dumpkmap, dumpleases, echo, ed, egrep, eject, env, envdir, envuidgid, ether-wake, expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flock, fold, free, freeramdisk, fsck, fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, getty, grep, gunzip, gzip, halt, hd, hdparm, head, hexdump, hostid, hostname, httpd, hush, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd, init, insmod, install, ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, last, length, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, logger, login, logname, logread, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.minix, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp, modinfo, modprobe, more, mount, mountpoint, mpstat, mt, mv, nameif, nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, ntpd, od, openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pwd, raidautorun, rdate, rdev, readahead, readlink, readprofile, realpath, reboot, reformime, remove-shell, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm, rpm2cpio, rtcwake, run-parts, runlevel, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setarch, setconsole, setfont, setkeycodes, setlogcons, setsid, setuidgid, sh, sha1sum, sha256sum, sha512sum, showkey, slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, su, sulogin, sum, sv, svlogd, swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time, timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize, tunctl, udhcpc, udhcpd, udpsvd, umount, uname, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, vlock, volname, wall, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat, zcip
  • 30. 2.11. Default applications - Android ● System Server ● Toolbox ● Native daemons ● Stock Android apps /packages/apps /packages/providers /packages/inputmethods AccountsAndSettings Launcher2 ApplicationProvider LatinIME AlarmClock Mms CalendarProvider OpenWnn Bluetooth Music ContactsProvider PinyinIME Browser PackageInstaller DownloadProvider Calculator Protips DrmProvider Calendar Provision GoogleContactsProvider Camera QuickSearchBox MediaProvider CertInstaller Settings TelephonyProvider Contacts SoundRecorder UserDictionaryProvider DeskClock SpeechRecorder Email Stk Gallery VoiceDialer HTMLViewer
  • 31. 2.12. Application development - EL ● Most apps: ● C library ● Unix systems programming ● Window-based apps: ● X window ● Toolkits: – Qt / GTK ● Windowing systems: – Qt Framework (formerly Qtopia) – Gnome / KDE / Unity / etc.
  • 32. 2.12. Application dev. - Android ● Android API
  • 33. 2.13. Application debugging - EL ● gdb ● strace ● IDE integration
  • 34. 2.13. Application debugging - Android ● adb ● ddms ● monkeyrunner ● traceview ● logcat ● Eclipse integration
  • 35. 3. Android-specific Concepts ● App fundamentals ● Framework components ● Native development
  • 36. 3.1. App fundamentals ● Components ● Intents ● Component lifecycle ● Manifest file ● Processes and threads ● Remote procedure calls
  • 37. 3.1.1. Components ● 1 App = N Components ● Apps can use components of other applications ● App processes are automagically started whenever any part is needed ● Ergo: N entry points, !1, and !main() ● Components: ● Activities ● Services ● Broadcast Receivers ● Content Providers
  • 38. 3.1.2. Intents ● Intent = asynchronous message w/ or w/o designated target ● Like a polymorphic Unix signal, but w/o required target ● Intents β€œpayload” held in Intent Object ● Intent Filters specified in Manifest file
  • 39. 3.1.3. Component lifecycle ● System automagically starts/stops/kills processes: ● Entire system behaviour predicated on low memory ● System triggers Lifecycle callbacks when relevant ● Ergo: Must manage Component Lifecycle ● Some Components are more complex to manage than others
  • 40. 3.1.4. Manifest file ● Informs system about app’s components ● XML format ● Always called AndroidManifest.xml ● Activity = <activity> ... static ● Service = <service> ... static ● Broadcast Receiver: ● Static = <receiver> ● Dynamic = Context.registerReceiver() ● Content Provider = <provider> ... static
  • 41. 3.1.5. Processes and threads ● Processes ● Default: all callbacks to any app Component are issued to the main process thread ● <activity>β€”<service>β€”<recipient>β€”<provider> have process attribute to override default ● Do NOT perform blocking/long operations in main process thread: – Spawn threads instead ● Process termination/restart is at system’s discretion ● Therefore: – Must manage Component Lifecycle ● Threads: ● Create using the regular Java Thread Object ● Android API provides thread helper classes: – Looper: for running a message loop with a thread – Handler: for processing messages – HandlerThread: for setting up a thread with a message loop
  • 42. 3.1.6. Remote procedure calls ● Apparently System V IPC is evil ... ● Android RPCs = Binder mechanism ● Binder is a low-level functionality, not used as-is ● Instead: must define interface using Interface Definition Language (IDL) ● IDL fed to aidl Tool to generate Java interface definitions
  • 43. 3.2. Framework components ● UI ● Data storage ● Security/Permissions ● ... and much more ... : ● Graphics ● Audio and Video ● Location and Maps ● Bluetooth ● NFC
  • 44. 3.2.1. UI ● Everything based on hierarchy of Views and ViewGroups (layouts) ● Declared in XML or dynamically through Java ● UI components: ● Widgets ● Event handlers ● Menus ● Dialogs ● Notifications ● ...
  • 45. 3.2.2. Data storage ● Shared preferences ● Private primitive key-pair values ● Internal storage ● Private data on device memory ● External storage ● Public data on shared external device (SD) ● SQLite DB ● Private DB ● Network connection ● Web-based storage (REST)
  • 46. 3.2.3. Security/Permissions ● Most security enforced at process level: UID, GID ● Permissions enforce restrictions on: ● Per-process operations ● Per-URI access ● Applications are sandboxed ● Specific permissions required to β€œexit” sandbox ● Decision to grant access based on: ● Certificates ● User prompts ● All permissions must be declared statically
  • 47. 3.3. Native development ● What it can and cannot do ● Getting and installing the NDK ● Using the NDK ● Implementing fully native apps
  • 48. 3.3.1. What it can and cannot do ● Useful for: ● Porting existing body of code to Android ● Developing optimized native apps, especially for gaming ● Provides: ● Tools and build files to generate native code libraries from C/C++ ● Way to embed native libs into .apk ● Set of stable (forward-compatible) native libs ● Documentation, samples and tutorials ● Enables: ● Calling native code from Java using JNI ● Implementing fully native apps (since 2.3) ● Doesn't allow you to: ● Compile traditional Linux/Unix apps as-is
  • 49. 3.3.2. Getting and installing the NDK ● What’s in the NDK? ● Development tools ● Stable native APIs system headers ● Documentation - IMPORTANT ● Samples ● Getting the NDK ● http://developer.android.com/sdk/ndk/index.html ● Prerequisites ● Windows, Mac or Linux ● Complete SDK ● make (GNU’s) and awk ● For Windows, Cygwin 1.7 or higher ● NDK set up: ● Make sure prerequisites are installed ● Download and install NDK
  • 50. 3.3.3. Using the NDK 1.Place native code under <project>/jni/... 2.Create <project>/jni/Android.mk to describe native code to NDK 3.Optional: create <project>/jni/Application.mk for describing which natives sources are required by app 4.Build native code: β€’ cd <project> β€’ <ndk>/ndk-build 5.Compile app with SDK. Native code will be shared lib in .apk file.
  • 51. 3.3.4. Implementing fully native apps ● Android 2.3 and up ● Native lifecycle management ● Still runs within context of dedicated Dalvik VM ● Can use JNI to call on Java functions ● Limited API: ● Activity lifecycle management ● Input events and sensors ● Window management ● Direct access to assets ● Make sure your activity is called: β€œandroid.app.NativeActivity”
  • 52. 4. Useful Embedded Linux Tricks ● crosstool-ng ● Busybox ● uClibc
  • 53. 4.1. crosstool-ng ● Cross-development toolchain generator ● Successor to crosstool ● Available at: http://ymorin.is-a-geek.org/projects/crosstool ● Downloads, patches, builds, installs, etc. ● Comprises 23 steps ● Menuconfig-based ● Supports uClibc, glibc and eglibc ● Supports ARM, Blackfin, MIPS, PowerPC, SH, … ● Fairly well maintained
  • 54. 4.2. Busybox ● Replicate Linux CLI experience [, [[, acpid, add-shell, addgroup, adduser, adjtimex, arp, arping, ash, awk, base64, basename, beep, blkid, blockdev, bootchartd, brctl, bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpasswd, chpst, chroot, chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cryptpw, cttyhack, cut, date, dc, dd, deallocvt, delgroup, deluser, depmod, devmem, df, dhcprelay, diff, dirname, dmesg, dnsd, dnsdomainname, dos2unix, du, dumpkmap, dumpleases, echo, ed, egrep, eject, env, envdir, envuidgid, ether-wake, expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgconsole, fgrep, find, findfs, flock, fold, free, freeramdisk, fsck, fsck.minix, fsync, ftpd, ftpget, ftpput, fuser, getopt, getty, grep, gunzip, gzip, halt, hd, hdparm, head, hexdump, hostid, hostname, httpd, hush, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd, init, insmod, install, ionice, iostat, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5, klogd, last, length, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap, logger, login, logname, logread, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lspci, lsusb, lzcat, lzma, lzop, lzopcat, makedevs, makemime, man, md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mke2fs, mkfifo, mkfs.ext2, mkfs.minix, mkfs.vfat, mknod, mkpasswd, mkswap, mktemp, modinfo, modprobe, more, mount, mountpoint, mpstat, mt, mv, nameif, nbd-client, nc, netstat, nice, nmeter, nohup, nslookup, ntpd, od, openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_root, pkill, pmap, popmaildir, poweroff, powertop, printenv, printf, ps, pscan, pwd, raidautorun, rdate, rdev, readahead, readlink, readprofile, realpath, reboot, reformime, remove-shell, renice, reset, resize, rev, rm, rmdir, rmmod, route, rpm, rpm2cpio, rtcwake, run-parts, runlevel, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq, setarch, setconsole, setfont, setkeycodes, setlogcons, setsid, setuidgid, sh, sha1sum, sha256sum, sha512sum, showkey, slattach, sleep, smemcap, softlimit, sort, split, start-stop-daemon, stat, strings, stty, su, sulogin, sum, sv, svlogd, swapoff, swapon, switch_root, sync, sysctl, syslogd, tac, tail, tar, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time, timeout, top, touch, tr, traceroute, traceroute6, true, tty, ttysize, tunctl, udhcpc, udhcpd, udpsvd, umount, uname, unexpand, uniq, unix2dos, unlzma, unlzop, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig, vi, vlock, volname, wall, watch, watchdog, wc, wget, which, who, whoami, xargs, xz, xzcat, yes, zcat, zcip
  • 55. ● Some features of interest: ● color-coded file lists ● tab completion ● "home", "end" ● grep, sed, wc, more, less ● vi ● ifconfig ● httpd ● sendmail ● tftp ● top ● ...
  • 56. ● Download BusyBox (1.18.3) ● Move to the directory for the rest of the setup: $ cd busybox-1.18.3 ● Configuration of BusyBox's options: $ make menuconfig ● Options that must be set: ● β€œBuild Options” -> β€œDo you want to build BusyBox with a Cross Compiler?” ● Cross-compiler prefix: arm-unknown-linux-gnueabi- ● β€œInstallation Options” -> β€œDon't use /usr” ● Installation prefix: ${PRJROOT}/rootfs ● Build: $ make ● Install: $ make install
  • 57. ● Cheat sheet: Commands to get the new Busybox onto the rootfs: adb shell mount -o remount,rw rootfs / adb shell mkdir /bin adb push busybox /bin/ adb shell /bin/busybox --install /bin adb shell To do after going into the shell: /bin/ash export PATH=/bin:$PATH
  • 58. 4.3. uClibc ● Originates from uClinux effort ● Support both CPUs that have and those that lack an MMU and/or an FPU. ● Allows both static and dynamic linking ● Most applications that build with glibc will build and work the same with uClibc. ● Available from: http://uclibc.org/
  • 59. 5. Pros and Cons ● Target application type: ● Stock Android vs. Custom Android ● Development language ● Licensing ● Branding: ● Do you care about the CTS?