android captronic

Upload: xitrumch

Post on 13-Oct-2015

74 views

Category:

Documents


0 download

DESCRIPTION

Android

TRANSCRIPT

  • Introduction to Android and Bring Up

    Introduction toAndroid and BringUpMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 1/255

  • Maxime Ripard

    I Embedded Linux engineer and trainer at Free Electrons since2011

    I Embedded Linux development: kernel and driver development,system integration, boot time and power consumptionoptimization, consulting, etc.

    I Embedded Linux training, Linux driver development trainingand Android system development training, with materialsfreely available under a Creative Commons license.

    I http://www.free-electrons.com

    I Contributor to various open-source projects: Barebox, Linux,Buildroot

    I Living in Toulouse, south west of France

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 2/255

  • Free Electrons

    I Free Electrons, specialized in Embedded Linux, since 2005

    I Strong emphasis on community relationI Training

    I Embedded Linux system developmentI Linux kernel and device driver developmentI Upcoming public sessions in Avignon, Lyon and Toulouse, or

    sessions at customer locationI All training materials freely available under a Creative

    Commons license.

    I Development and consultingI Board Support Package development or improvementI Kernel and driver developmentI Embedded Linux system integrationI Power-management, boot-time, performance audits and

    improvementI Embedded Linux application development

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 3/255

  • Free Electrons customers

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 4/255

  • Free Electrons training

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 5/255

  • Introduction to Android

    Introduction toAndroidMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 6/255

  • Introduction to Android

    Features

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 7/255

  • Features

    I All you can expect from a modern mobile OS:I Application ecosystem, allowing to easily add and remove

    applications and publish new features across the entire systemI Support for all the web technologies, with a browser built on

    top of the well-established WebKit rendering engineI Support for hardware accelerated graphics through OpenGL ESI Support for all the common wireless mechanisms: GSM,

    CDMA, UMTS, LTE, Bluetooth, WiFi.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 8/255

  • Introduction to Android

    History

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 9/255

  • Early Years

    I Began as a start-up in Palo Alto, CA, USA in 2003I Focused from the start on software for mobile devicesI Very secretive at the time, even though founders achieved a

    lot in the targeted area before founding itI Finally bought by Google in 2005I Andy Rubin, founder of Android, Inc was also CEO of Danger,

    Inc, a company producing one of the early smartphones, theSidekick

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 10/255

  • Opening Up

    I Google announced the Open Handset Alliance in 2007, aconsortium of major actors in the mobile area built aroundAndroid

    I Hardware vendors: Intel, Texas Instruments, Qualcomm,Nvidia, etc.

    I Software companies: Google, eBay, etc.I Hardware manufacturers: Motorola, HTC, Sony Ericsson,

    Samsung, etc.I Mobile operators: T-Mobile, Telefonica, Vodafone, etc.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 11/255

  • Android Open Source Project (AOSP)

    I At every new version, Google releases its source code throughthis project so that community and vendors can work with it.

    I One major exception: Honeycomb has not been releasedbecause Google stated that its source code was not cleanenough to release it.

    I One can fetch the source code and contribute to it, eventhough the development process is very locked by Google

    I Only a few devices are supported through AOSP though, onlythe two most recent Android development phones, the Pandaboard and the Motorola Xoom.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 12/255

  • Android Releases

    I Each new version is given a dessert name

    I Released in alphabetical orderI Last releases:

    I Android 3.X HoneycombI Android 4.0 Ice Cream SandwichI Android 4.1/4.2 Jelly Bean

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 13/255

  • Android Versions

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 14/255

  • Introduction to Android

    Architecture

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 15/255

  • Architecture

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 16/255

  • The Linux Kernel

    I Used as the foundation of the Android system

    I Numerous additions from the stock Linux, including new IPC(Inter-Process Communication) mechanisms, alternativepower management mechanism, new drivers and variousadditions across the kernel

    I These changes are beginning to go into the staging/ area ofthe kernel, as of 3.3, after being a complete fork for a longtime

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 17/255

  • Android Libraries

    I Gather a lot of Android-specific libraries to interact at alow-level with the system, but third-parties libraries as well

    I Bionic is the C library, SurfaceManager is used for drawingsurfaces on the screen, etc.

    I But also WebKit, SQLite, OpenSSL coming from the freesoftware world

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 18/255

  • Android Runtime

    Handles the execution of Android applications

    I Almost entirely written from scratch by Google

    I Contains Dalvik, the virtual machine that executes everyapplication that you run on Android, and the core library forthe Java runtime, coming from Apache Harmony project

    I Also contains system daemons, init executable, basic binaries,etc.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 19/255

  • Android Framework

    I Provides an API for developers to create applications

    I Exposes all the needed subsystems by providing an abstraction

    I Allows to easily use databases, create services, expose data toother applications, receive system events, etc.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 20/255

  • Android Applications

    I AOSP also comes with a set of applications such as the phoneapplication, a browser, a contact management application, anemail client, etc.

    I However, the Google apps and the Android Market app arentfree software, so they are not available in AOSP. To obtainthem, you must contact Google and pass a compatibility test.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 21/255

  • Introduction to Android

    Hardware Requirements for Linux

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 22/255

  • Processor architecture

    I The Linux kernel and most other architecture-dependentcomponent support a wide range of 32 and 64 bitsarchitectures

    I x86 and x86 64, as found on PC platforms, but also embeddedsystems (multimedia, industrial)

    I ARM, with hundreds of different SoC (multimedia, industrial)I PowerPC (mainly real-time, industrial applications)I MIPS (mainly networking applications)I SuperH (mainly set top box and multimedia applications)I Blackfin (DSP architecture)I Microblaze (soft-core for Xilinx FPGA)I Coldfire, SCore, Tile, Xtensa, Cris, FRV, AVR32, M32R

    I Both MMU and no-MMU architectures are supported,even though no-MMU architectures have a few limitations.

    I Linux is not designed for small microcontrollers.I Besides the toolchain, the bootloader and the kernel, all other

    components are generally architecture-independent

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 23/255

  • RAM and storage

    I RAM: a very basic Linux system can work within 8 MB ofRAM, but a more realistic system will usually require at least32 MB of RAM. Depends on the type and size of applications.

    I Storage: a very basic Linux system can work within 4 MB ofstorage, but usually more is needed.

    I flash storage is supported, both NAND and NOR flash, withspecific filesystems

    I Block storage including SD/MMC cards and eMMC issupported

    I Not necessarily interesting to be too restrictive on the amountof RAM/storage: having flexibility at this level allows tore-use as many existing components as possible.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 24/255

  • Communication

    I The Linux kernel has support for many commoncommunication buses

    I I2CI SPII CANI 1-wireI SDIOI USB

    I And also extensive networking supportI Ethernet, WiFi, Bluetooth, CAN, etc.I IPv4, IPv6, TCP, UDP, SCTP, DCCP, etc.I Firewalling, advanced routing, multicast

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 25/255

  • ARM and System-on-Chip

    I ARM is one of the most popular architectures used inembedded Linux systems

    I ARM designs CPU cores (instruction sets, caches, MMU,etc.) and sells the design to licensees

    I The licensees are founders (Texas Instruments, Freescale, STEricsson, Atmel, etc.), they integrate an ARM core with manyperipherals, into a chip called a SoC, for System-on-chip

    I Each founder provides different models of SoC, with differentcombination of peripherals, power, power consumption, etc.

    I The concept of SoC allows to reduce the number ofperipherals needed on the board, and therefore the cost ofdesigning and building the board.

    I Linux supports SoCs from most vendors, but not all, andnot with the same level of functionality.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 26/255

  • ARM and System-on-Chip

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 27/255

  • Atmel AT91SAM9263

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 28/255

  • Texas Instruments OMAP3430

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 29/255

  • Type of hardware platforms

    I Evaluation platforms from the SoC vendor. Usuallyexpensive, but many peripherals are built-in. Generallyunsuitable for real products.

    I Component on Module, a small board with onlyCPU/RAM/flash and a few other core components, withconnectors to access all other peripherals. Can be used tobuild end products for small to medium quantities.

    I Community development platforms, a new trend to make aparticular SoC popular and easily available. Those areready-to-use and low cost, but usually have less peripheralsthan evaluation platforms. To some extent, can also be usedfor real products.

    I Custom platform. Schematics for evaluation boards ordevelopment platforms are more and more commonly freelyavailable, making it easier to develop custom platforms.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 30/255

  • Gumstix

    I TI OMAP3530 (600 MHz, ARMCortex-A8, PowerVR SGX, DSP)

    I Component on Module

    I 256 MB RAM

    I 256 MB NAND (optional)

    I Bluetooth, WiFi (optional)

    I uSD

    I $115-229

    I Development boards available at $49-229, with many peripherals: LCD,Ethernet, UART, SPI, I2C, etc.

    I http://www.gumstix.com

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 31/255

  • Pandaboard ES

    I TI OMAP 4460(Dual-Core 1.2 GHz,cortex A9, PowerVRGPU, DSP)

    I Community developmentplatform

    I 1 GiB RAM

    I SD slot, Ethernet, WiFi,Bluetooth, USB OTG

    I HDMI, S-Video, Camera,audio

    I $ 149

    I http://pandaboard.org

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 32/255

  • Snowball

    I ST Ericsson AP9500 (dualcortex A9, MALI GPU)

    I Community developmentplatform

    I 1 GB RAM

    I 4-8 GB eMMC, microSD

    I HDMI, S-Video, audio

    I WiFi, Bluetooth, Ethernet

    I Accelerometer, Magnetometer,Gyrometer, GPS

    I Expansion: USB, I2C, SPI,LCD, UART, GPIO, etc.

    I 169 e to 244 e

    I http://igloocommunity.orgFree Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 33/255

  • Freescale Quick Start

    I Freescale I.MX53 (1 GHzCortex A8)

    I Community developmentplatform

    I 1 GB RAM

    I 4-8 GB eMMC, microSD

    I LVDS, LCD, VGA, HDMI,audio

    I Accelerometer, SD/MMC,microSD, SATA, Ethernet,USB

    I Expansion: I2C, SPI, SSI, LCD,Camera

    I 149 e

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 34/255

  • Criteria for choosing the hardware

    I Make sure the hardware you plan to use is already supportedby the Linux kernel, and has an open-source bootloader,especially the SoC youre targeting.

    I Having support in the official versions of the projects (kernel,bootloader) is a lot better: quality is better, and newversions are available.

    I Some SoC vendors and/or board vendors do not contributetheir changes back to the Linux kernel. Ask them to do so, oruse another product if you can. A good measurement is to seethe delta between their kernel and the official one.

    I Between properly supported hardware in the official Linuxkernel and poorly-supported hardware, there will be hugedifferences in development time and cost.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 35/255

  • Introduction to Android

    Embedded Systems using Linux

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 36/255

  • Consumer device: Internet box

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 37/255

  • Consumer device: Television

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 38/255

  • Professional device: point of sale terminal

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 39/255

  • Industrial system: laser cutter

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 40/255

  • Industrial system: wind turbine

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 41/255

  • Industrial system: cow milking

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 42/255

  • Industrial system: sea pollution detection system

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 43/255

  • Industrial system: viticulture machine

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 44/255

  • Critical Systems: Nuclear Reactor

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 45/255

  • Critical Systems: Rockets

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 46/255

  • Introduction to Android

    Hardware Requirements for Android

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 47/255

  • SoC requirements

    I Since Android in itself is quite huge, the hardware required isquite different.

    I First, the only architecture officially supported by Google isARMv7 (basically, all the SoCs based on the Cortex-A). TheCPU has to be powerful enough as well (the typical setup onrecent releases is a dual-core CPUs running at more than1GHz

    I Other architectures like x86 and MIPS are supported bythird-party ports

    I You also need to have a powerful enough GPU with OpenGLES support. Latest versions of Android require the 3Dhardware acceleration

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 48/255

  • Storage and RAM needed

    I The required RAM size is also quite huge, 340MB are requiredfor the kernel and userspace memory

    I Required storage is quite huge as well. An image of thesystem is around 200-300MB, and you must have 350MB ofdata space for the user plus 1GB of shared storage for theapplications. Google recommends to use block devices forstorage and not flash devices.

    I The shared space has to be accessible from a host computerby some way, like NFS, USB Mass Storage, MTP, etc.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 49/255

  • External Peripherals 1/2

    I No form of communication supported is mandatory, but youneed at least one form of data networking with a throughputof at least 200 kbit per second.

    I You will also need obviously a rather large screen with apointer device, presumably a touchscreen.

    I Screens supported must have a screen size of at least 2.5inches, with a minimal resolution of 426x320, with a ratiobetween 4:3 and 16:9 and with a color depth of at least 16bits.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 50/255

  • External Peripherals 2/2

    I Sensors are not mandatory, but depending of the class ofsensors, they are:

    I RecommendedI AccelerometerI MagnetometerI GPSI Gyroscope

    I OptionalI BarometerI PhotometerI Proximity Sensor

    I DeprecatedI Thermometer (and only to measure CPU temperature)

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 51/255

  • Unusual Android Devices: Nook E-Book Reader

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 52/255

  • Unusual Android Devices: Watch

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 53/255

  • Unusual Android Devices: Portable Console

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 54/255

  • Unusual Android Devices: Microwave Oven

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 55/255

  • Unusual Android Devices: Treadmill

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 56/255

  • When to choose Android

    I All of the requirements listed above are only if you want to beeligible to the Android Play Store

    I If you dont want to get the store, you can obviously ignorethese

    I However, Android really makes sense in a system that has atleast:

    I A large screenI A powerful SoC, with plenty of RAM, storage space (around

    512MB) and a decent GPU

    I This is not an advisable choice when you want to build aheadless system, or a cheap system with limited resources

    I In this case, a regular Linux system is definitely moreappropriate. It will save you engineering costs, reduce theprice of your hardware, and bring the same set of features youcould expect from a headless Android

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 57/255

  • Android Source Code and Compilation

    Android SourceCode andCompilationMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 58/255

  • Android Source Code and Compilation

    How to get the source code

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 59/255

  • Source Code Location

    I The AOSP project is available athttp://source.android.com

    I On this site, along with the code, you will find some resourcessuch as technical details, how to setup a machine to buildAndroid, etc.

    I The source code is split into several Git repositories forversion control. But as there is a lot of source code, a singleGit repository would have been really slow

    I Google split the source code into a one Git repository percomponent

    I You can easily browse these git repositories usinghttps://code.google.com/p/android-source-

    browsing/source/browse/

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 60/255

  • Repo

    I This makes hundreds of Git repositories

    I To avoid making it too painful, Google also created a tool:repo

    I Repo aggregates these Git repositories into a single folderfrom a manifest file describing how to find these and how toput them together

    I Also aggregates some common Git commands such as diff orstatus that are run across all the Git repositories

    I You can also execute a shell command in each repositorymanaged by Repo using the repo forall command

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 61/255

  • Source code licenses

    I Mostly two kind of licenses:I GPL/LGPL Code: Linux, D-Bus, BlueZI Apache/BSD: All the restI In the external folder, it depends on the component, but

    mostly GPL

    I While you might expect Googles apps for Android, like theAndroid Market (now called Google Play Store), to be in theAOSP as well, these are actually proprietary and you need tobe approved by Google to get them.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 62/255

  • Android Source Code and Compilation

    Compilation

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 63/255

  • Android Compilation Process

    I Androids build system relies on the well-tried GNU/Makesoftware

    I Android is using a product notion which corresponds to thespecifications of a shipping product, i.e. crespo for the GoogleNexus S vs crespo4g for the Sprints Nexus S with LTEsupport

    I To start using the build system, you need to include the filebuild/envsetup.sh that defines some useful macros forAndroid development or sets the PATH variable to include theAndroid-specific commands

    I source build/envsetup.sh

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 64/255

  • Prepare the process

    I Now, we can get a list of all the products available and selectthem with to the lunch command

    I lunch will also ask for a build variant, to choose betweeneng, user and userdebug, which corresponds to which kindof build we want, and which packages it will add

    I You can also select variants by passing directly the comboproduct-variant as argument to lunch

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 65/255

  • Compilation

    I You can now start the compilation just by running make

    I This will run a full build for the current selected product

    I There are lots of other build commands:

    make Builds only the package, instead of goingthrough the entire build

    make clean Cleans all the files generated by previouscompilations

    make clean- Removes all the files generated bythe compilation of the given package

    mm Builds all the modules in the current directorymmm builds all the modules in the given

    directory

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 66/255

  • Android Source Code and Compilation

    Contribute

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 67/255

  • Gerrit

    I Google also developed for the Android development process atool to manage projects and ease code reviews.

    I It once again uses Git to do so and Repo is also built aroundit so that you can easily contribute to Android

    I To do so, start a new branch withrepo start

    I Do your usual commits with Git

    I When you are done, upload to Gerrit using repo upload

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 68/255

  • Linux kernel introduction

    Linux kernelintroductionMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 69/255

  • Linux kernel in the system

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 70/255

  • History

    I The Linux kernel is one component of a system, which alsorequires libraries and applications to provide features to endusers.

    I The Linux kernel was created as a hobby in 1991 by a Finnishstudent, Linus Torvalds.

    I Linux quickly started to be used as the kernel for free softwareoperating systems

    I Linus Torvalds has been able to create a large and dynamicdeveloper and user community around Linux.

    I Nowadays, hundreds of people contribute to each kernelrelease, individuals or companies big and small.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 71/255

  • Linux license

    I The whole Linux sources are Free Software released under theGNU General Public License version 2 (GPL v2).

    I For the Linux kernel, this basically implies that:I When you receive or buy a device with Linux on it, you should

    receive the Linux sources, with the right to study, modify andredistribute them.

    I When you produce Linux based devices, you must release thesources to the recipient, with the same rights, with norestriction..

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 72/255

  • Linux kernel key features

    I Portability and hardwaresupport. Runs on mostarchitectures.

    I Scalability. Can run onsuper computers as well ason tiny devices (4 MB ofRAM is enough).

    I Compliance to standardsand interoperability.

    I Exhaustive networkingsupport.

    I Security. It cant hide itsflaws. Its code is reviewedby many experts.

    I Stability and reliability.

    I Modularity. Can includeonly what a system needseven at run time.

    I Easy to program. You canlearn from existing code.Many useful resources onthe net.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 73/255

  • Supported hardware architectures

    I See the arch/ directory in the kernel sources

    I Minimum: 32 bit processors, with or without MMU, and gccsupport

    I 32 bit architectures (arch/ subdirectories)Examples: arm, avr32, blackfin, m68k, microblaze,mips, score, sparc, um

    I 64 bit architectures:Examples: alpha, arm64, ia64, sparc64, tile

    I 32/64 bit architecturesExamples: powerpc, x86, sh

    I Find details in kernel sources: arch//Kconfig,arch//README, or Documentation//

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 74/255

  • System calls

    I The main interface between the kernel and userspace is theset of system calls

    I About 300 system calls that provide the main kernel servicesI File and device operations, networking operations,

    inter-process communication, process management, memorymapping, timers, threads, synchronization primitives, etc.

    I This interface is stable over time: only new system calls canbe added by the kernel developers

    I This system call interface is wrapped by the C library, anduserspace applications usually never make a system calldirectly but rather use the corresponding C library function

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 75/255

  • Virtual filesystems

    I Linux makes system and kernel information available inuser-space through virtual filesystems.

    I Virtual filesystems allow applications to see directories andfiles that do not exist on any real storage: they are created onthe fly by the kernel

    I The two most important virtual filesystems areI proc, usually mounted on /proc:

    Operating system related information (processes, memorymanagement parameters...)

    I sysfs, usually mounted on /sys:Representation of the system as a set of devices and buses.Information about these devices.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 76/255

  • The Android Kernel

    Changesintroduced in theAndroid KernelMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 77/255

  • The Android Kernel

    Wakelocks

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 78/255

  • Power management basics

    I Every CPU has a few states of power consumption, frombeing almost completely off, to working at full capacity.

    I These different states are used by the Linux kernel to savepower when the system is run

    I For example, when the lid is closed on a laptop, it goes intosuspend, which is the most power conservative mode of adevice, where almost nothing but the RAM is kept awake

    I While this is a good strategy for a laptop, it is not necessarilygood for mobile devices

    I For example, you dont want your music to be turned offwhen the screen is

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 79/255

  • Wakelocks

    I Androids answer to these power management constraints iswakelocks

    I One of the most famous Android changes, because of theflame wars it spawned

    I The main idea is instead of letting the user decide when thedevices need to go to sleep, the kernel is set to suspend assoon and as often as possible.

    I In the same time, Android allows applications and kerneldrivers to voluntarily prevent the system from going tosuspend, keeping it awake (thus the name wakelock)

    I This implies to write the applications and drivers to use thewakelock API.

    I Applications do so through the abstraction provided by the APII Drivers must do it themselves, which prevents to directly

    submit them to the vanilla kernel

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 80/255

  • Wakelocks API

    I Kernel Space API#include

    void wake_lock_init(struct wakelock *lock,

    int type,

    const char *name);

    void wake_lock(struct wake_lock *lock);

    void wake_unlock(struct wake_lock *lock);

    void wake_lock_timeout(struct wake_lock *lock, long timeout);

    void wake_lock_destroy(struct wake_lock *lock);

    I User-Space API$ echo foobar > /sys/power/wake_lock

    $ echo foobar > /sys/power/wake_unlock

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 81/255

  • The Android Kernel

    Binder

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 82/255

  • Binder

    I RPC/IPC mechanism

    I Takes its roots from BeOS and the OpenBinder project, whichsome of the current Android engineers worked on

    I Adds remote object invocation capabilities to the Linux Kernel

    I One of the very basic functionalities of Android. Without it,Android cannot work.

    I Every call to the system servers go through Binder, just likeevery communication between applications, and evencommunication between the components of a singleapplication.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 83/255

  • Binder

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 84/255

  • The Android Kernel

    klogger

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 85/255

  • Logging

    I Logs are very important to debug a system, either live or aftera fault occurred

    I In a regular Linux distribution, two components are involvedin the systems logging:

    I Linux internal mechanism, accessible with the dmesgcommand and holding the output of all the calls to printk()from various parts of the kernel.

    I A syslog daemon, which handles the userspace logs and usuallystores them in the /var/log directory

    I From Android developers point of view, this approach hastwo flaws:

    I As the calls to syslog() go through as socket, they generateexpensive task switches

    I Every call writes to a file, which probably writes to a slowstorage device or to a storage device where writes are expensive

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 86/255

  • Logger

    I Android addresses these issues with logger, which is a kerneldriver, that uses 4 circular buffers in the kernel memory area.

    I The buffers are exposed in the /dev/log directory and youcan access them through the liblog library, which is in turn,used by the Android system and applications to write tologger, and by the logcat command to access them.

    I This allows to have an extensive level of logging across theentire AOSP

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 87/255

  • The Android Kernel

    Anonymous Shared Memory(ashmem)

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 88/255

  • Shared memory mechanism in Linux

    I Shared memory is one of the standard IPC mechanismspresent in most OSes

    I Under Linux, they are usually provided by the POSIX SHMmechanism, which is part of the System V IPCs

    I ndk/docs/system/libc/SYSV-IPC.html illustrates all thelove Android developers have for these

    I The bottom line is that they are flawed by design in Linux,and lead to code leaking resources, be it maliciously or not

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 89/255

  • Ashmem

    I Ashmem is the response to these flawsI Notable differences are:

    I Reference counting so that the kernel can reclaim resourceswhich are no longer in use

    I There is also a mechanism in place to allow the kernel toshrink shared memory regions when the system is undermemory pressure.

    I The standard use of Ashmem in Android is that a processopens a shared memory region and share the obtained filedescriptor through Binder.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 90/255

  • The Android Kernel

    Alarm Timers

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 91/255

  • The alarm driver

    I Once again, the timer mechanisms available in Linux were notsufficient for the power management policy that Android wastrying to set up

    I High Resolution Timers can wake up a process, but dont firewhen the system is suspended, while the Real Time Clock canwake up the system if it is suspended, but cannot wake up aparticular process.

    I Developed the alarm timers on top of the Real Time Clockand High Resolution Timers already available in the kernel

    I These timers will be fired even if the system is suspended,waking up the device to do so

    I Obviously, to let the application do its job, when theapplication is woken up, a wakelock is grabbed

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 92/255

  • The Android Kernel

    Network Security

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 93/255

  • Paranoid Network

    I In the standard Linux kernel, every application can opensockets and communicate over the Network

    I However, Google was willing to apply a more strict policy withregard to network access

    I Access to the network is a permission, with a per applicationgranularity

    I Filtered with the GID

    I You need it to access IP, Bluetooth, raw sockets or RFCOMM

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 94/255

  • The Android Kernel

    Low Memory Killer

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 95/255

  • Low Memory Killer

    I When the system goes out of memory, Linux throws the OOMKiller to cleanup memory greedy processes

    I However, this behavior is not predictable at all, and can killvery important components of a phone (Telephony stack,Graphic subsystem, etc) instead of low priority processes(Angry Birds)

    I The main idea is to have another process killer, that kicks inbefore the OOM Killer and takes into account the time sincethe application was last used and the priority of thecomponent for the system

    I It uses various thresholds, so that it first notifies applicationsso that they can save their state, then begins to killnon-critical background processes, and then the foregroundapplications

    I As it is run to free memory before the OOM Killer, the latterwill never be run, as the system will never run out of memory

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 96/255

  • The Android Kernel

    Various Drivers and Fixes

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 97/255

  • Various additions

    I Android also has a lot of minor features added to the Linuxkernel:

    I RAM Console, a RAM-based console that survives a reboot tohold kernel logs

    I pmem, a physically contiguous memory allocator, writtenspecifically for the HTC G1, to allocate heaps used for 2Dhardware acceleration

    I ADBI YAFFS2I Timed GPIOs

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 98/255

  • Android Filesystem

    AndroidFilesystemMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 99/255

  • Android Filesystem

    Principle and solutions

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 100/255

  • Filesystems

    I Filesystems are used to organize data in directories and fileson storage devices or on the network. The directories and filesare organized as a hierarchy

    I In Unix systems, applications and users see a single globalhierarchy of files and directories, which can be composed ofseveral filesystems.

    I Filesystems are mounted in a specific location in thishierarchy of directories

    I When a filesystem is mounted in a directory (called mountpoint), the contents of this directory reflects the contents ofthe storage device

    I When the filesystem is unmounted, the mount point is emptyagain.

    I This allows applications to access files and directories easily,regardless of their exact storage location

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 101/255

  • Filesystems (2)

    I Create a mount point, which is just a directory$ mkdir /mnt/usbkey

    I It is empty$ ls /mnt/usbkey

    $

    I Mount a storage device in this mount point$ mount -t vfat /dev/sda1 /mnt/usbkey

    $

    I You can access the contents of the USB key$ ls /mnt/usbkey

    docs prog.c picture.png movie.avi

    $

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 102/255

  • mount / umount

    I mount allows to mount filesystemsI mount -t type device mountpointI type is the type of filesystemI device is the storage device, or network location to mountI mountpoint is the directory where files of the storage device

    or network location will be accessibleI mount with no arguments shows the currently mounted

    filesystems

    I umount allows to unmount filesystemsI This is needed before rebooting, or before unplugging a USB

    key, because the Linux kernel caches writes in memory toincrease performances. umount makes sure that those writesare committed to the storage.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 103/255

  • Root filesystem

    I A particular filesystem is mounted at the root of the hierarchy,identified by /

    I This filesystem is called the root filesystemI As mount and umount are programs, they are files inside a

    filesystem.I They are not accessible before mounting at least one

    filesystem.

    I As the root filesystem is the first mounted filesystem, itcannot be mounted with the normal mount command

    I It is mounted directly by the kernel, according to the root=kernel option

    I When no root filesystem is available, the kernel panicsPlease append a correct "root=" boot option

    Kernel panic - not syncing: VFS: Unable to mount root fs on unknown block(0,0)

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 104/255

  • Location of the root filesystem

    I It can be mounted from different locationsI From the partition of a hard diskI From the partition of a USB keyI From the partition of an SD cardI From the partition of a NAND flash chip or similar type of

    storage deviceI From the network, using the NFS protocolI From memory, using a pre-loaded filesystem (by the

    bootloader)I etc.

    I It is up to the system designer to choose the configuration forthe system, and configure the kernel behavior with root=

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 105/255

  • Mounting rootfs from storage devices

    I Partitions of a hard disk or USB keyI root=/dev/sdXY, where X is a letter indicating the device,

    and Y a number indicating the partitionI /dev/sdb2 is the second partition of the second disk drive

    (either USB key or ATA hard drive)

    I Partitions of an SD cardI root=/dev/mmcblkXpY, where X is a number indicating the

    device and Y a number indicating the partitionI /dev/mmcblk0p2 is the second partition of the first device

    I Partitions of flash storageI root=/dev/mtdblockX, where X is the partition numberI /dev/mtdblock3 is the fourth partition of a NAND flash chip

    (if only one NAND flash chip is present)

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 106/255

  • rootfs in memory: initramfs (1)

    I It is also possible to have the root filesystem integrated intothe kernel image

    I It is therefore loaded into memory together with the kernelI This mechanism is called initramfs

    I It integrates a compressed archive of the filesystem into thekernel image

    I It is useful for two casesI Fast booting of very small root filesystems. As the filesystem is

    completely loaded at boot time, application startup is very fast.I As an intermediate step before switching to a real root

    filesystem, located on devices for which drivers not part of thekernel image are needed (storage drivers, filesystem drivers,network drivers). This is always used on the kernel ofdesktop/server distributions to keep the kernel image sizereasonable.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 107/255

  • rootfs in memory: initramfs (2)

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 108/255

  • rootfs in memory: initramfs (3)

    I The contents of an initramfs are defined at the kernelconfiguration level, with the CONFIG_INITRAMFS_SOURCEoption

    I Can be the path to a directory containing the root filesystemcontents

    I Can be the path to a cpio archiveI Can be a text file describing the contents of the initramfs (see

    documentation for details)

    I The kernel build process will automatically take the contentsof the CONFIG_INITRAMFS_SOURCE option and integrate theroot filesystem into the kernel image

    I filesystems/ramfs-rootfs-initramfs.txt andearly-userspace/README

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 109/255

  • Android Filesystem

    Contents

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 110/255

  • Filesystem organization on GNU/Linux

    I On most Linux based distributions, the filesystem layout isdefined by the Filesystem Hierarchy Standard

    I The FHS defines the main directories and their contents

    /bin Essential command binaries/boot Bootloader files, i.e. kernel images and related

    stuff/etc Host-specific system-wide configuration files.

    I Android follows an orthogonal path, storing its files in foldersnot present in the FHS, or following it when it uses a definedfolder

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 111/255

  • Filesystem organization on Android

    I Instead, the two main directories used by Android are

    /system Immutable directory coming from the originalbuild. It contains native binaries and libraries,framework jar files, configuration files, standardapps, etc.

    /data is where all the changing content of the systemare put: apps, data added by the user, datagenerated by all the apps at runtime, etc.

    I These two directories are usually mounted on separatepartitions, from the root filesystem originating from a kernelRAM disk.

    I Android also uses some usual suspects: /proc, /dev, /sys,/etc, sbin, /mnt where they serve the same function theyusually do

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 112/255

  • /system

    ./app All the pre-installed apps

    ./bin Binaries installed on the system (toolbox, vold,surfaceflinger)

    ./etc Configuration files

    ./fonts Fonts installed on the system

    ./framework Jar files for the framework

    ./lib Shared objects for the system libraries

    ./modules Kernel modules

    ./xbin External binaries

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 113/255

  • Other directories

    I Like we said earlier, Android most of the time either usesdirectories not in the FHS, or directories with the exact samepurpose as in standard Linux distributions (/dev, /proc),therefore avoiding collisions. /sys)

    I There is some collision though, for /etc and /sbin, whichare hopefully trimmed down

    I This allows to have a full Linux distribution side by side withAndroid with only minor tweaks

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 114/255

  • android filesystem config.h

    I Located in system/core/include/private/I Contains the full filesystem setup, and is written as a C

    headerI UID/GIDI Permissions for system directoriesI Permissions for system files

    I Processed at compilation time to enforce the permissionsthroughout the filesystem

    I Useful in other parts of the framework as well, such as ADB

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 115/255

  • Android Filesystem

    Virtual Filesystems

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 116/255

  • proc virtual filesystem

    I The proc virtual filesystem exists since the beginning of LinuxI It allows

    I The kernel to expose statistics about running processes in thesystem

    I The user to adjust at runtime various system parameters aboutprocess management, memory management, etc.

    I The proc filesystem is used by many standard userspaceapplications, and they expect it to be mounted in /proc

    I Applications such as ps or top would not work without theproc filesystem

    I Command to mount /proc:mount -t proc nodev /proc

    I filesystems/proc.txt in the kernel sources

    I man proc

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 117/255

  • proc contents

    I One directory for each running process in the systemI /proc/I cat /proc/3840/cmdlineI It contains details about the files opened by the process, the

    CPU and memory usage, etc.

    I /proc/interrupts, /proc/devices, /proc/iomem,/proc/ioports contain general device-related information

    I /proc/cmdline contains the kernel command lineI /proc/sys contains many files that can be written to to

    adjust kernel parametersI They are called sysctl. See /latest/sysctl/ in kernel

    sources.I Example

    echo 3 > /proc/sys/vm/drop_caches

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 118/255

  • sysfs filesystem

    I The sysfs filesystem is a feature integrated in the 2.6 Linuxkernel

    I It allows to represent in userspace the vision that the kernelhas of the buses, devices and drivers in the system

    I It is useful for various userspace applications that need to listand query the available hardware, for example udev or mdev

    I All applications using sysfs expect it to be mounted in the/sys directory

    I Command to mount /sys:mount -t sysfs nodev /sys

    I $ ls /sys/block bus class dev devices firmware

    fs kernel modulepower

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 119/255

  • Android Filesystem

    Minimal filesystem

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 120/255

  • Basic applications

    I In order to work, a Linux system needs at least a fewapplications

    I An init application, which is the first userspace applicationstarted by the kernel after mounting the root filesystem

    I The kernel tries to run /sbin/init, /bin/init, /etc/initand /bin/sh.

    I If none of them are found, the kernel panics and the bootprocess is stopped.

    I The init application is responsible for starting all otheruserspace applications and services

    I Usually a shell, to allow a user to interact with the system

    I Basic Unix applications, to copy files, move files, list files(commands like mv, cp, mkdir, cat, etc.)

    I Those basic components have to be integrated into the rootfilesystem to make it usable

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 121/255

  • Overall booting process

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 122/255

  • Android Build System

    Android BuildSystemMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 123/255

  • Android Build System

    Basics

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 124/255

  • Build Systems

    I Build systems are designed to meet several goals:I Integrate all the software components, both third-party and

    in-house into a working imageI Be able to easily reproduce a given build

    I Usually, they build software using the existing building systemshipped with each component

    I Several solutions: Yocto, Buildroot, ptxdist.I Google came up with its own solution for Android, that never

    relies on other build systems, except for GNU/MakeI It allows to rely on very few tools, and to control every

    software component in a consistent way.I But it also means that when you have to import a new

    component, you have to rewrite the whole Makefile to build it

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 125/255

  • First compilation

    $ source build/envsetup.sh

    $ lunch

    Youre building on Linux

    Lunch menu... pick a combo:

    1. generic-eng

    2. simulator

    3. full_passion-userdebug

    4. full_crespo-userdebug

    Which would you like? [generic-eng]

    $ make

    $ make showcommands

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 126/255

  • Output

    I All the output is generated in the out/ directory, outside ofthe source code directory

    I This directory contains mostly two subdirectories: host/ andtarget/

    I These directories contain all the objects files compiled duringthe build process: .o files for C/C++ code, .jar files forJava libraries, etc

    I It is an interesting feature, since it keeps all the generatedstuff separate from the source code, and we can easily cleanwithout side effects

    I It also generates the system images in theout/target/product// directory

    I make clean only deletes that out directory

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 127/255

  • Android Build System

    Add a New Module

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 128/255

  • Modules

    I Every component in Android is called a module

    I Modules are defined across the entire tree through theAndroid.mk files

    I The build system abstracts many details to make the creationof a modules Makefile as trivial as possible

    I Of course, building a module that will be an Androidapplication and building a static library will not require thesame instructions, but these builds dont differ that mucheither.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 129/255

  • Hello World

    LOCAL_PATH = $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_SRC_FILES = hello_world.c

    LOCAL_MODULE = HelloWorld

    LOCAL_MODULE_TAGS = optional

    include $(BUILD_EXECUTABLE)

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 130/255

  • Hello World

    I Every module variable is prefixed by LOCAL_*

    I LOCAL_PATH tells the build system where the current moduleis

    I include $(CLEAR_VARS) cleans the previously declaredLOCAL_* variables. This way, we make sure we wont haveanything weird coming from other modules. The list of thevariables cleared is in build/core/clear_vars.mk

    I LOCAL_SRC_FILES contains a list of all source files to becompiled

    I LOCAL_MODULE sets the module name

    I LOCAL_MODULE_TAGS defines the set of modules this moduleshould belong to

    I include $(BUILD_EXECUTABLE) tells the build system tobuild this module as a binary

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 131/255

  • Tags

    I Tags are used to define several sets of modules to be builtthrough the build variant selected by lunch

    I We have 3 build variants:I user

    I Installs modules tagged with userI Installs non-packaged modules that have no tags specifiedI ADB is disabled by default

    I userdebug is user plusI Installs modules tagged with debugI ADB is enabled by default

    I eng is userdebug, plusI Installs modules tagged as eng and developmentI ro.kernel.android.checkjni = 1

    I Finally, we have a fourth tag, optional, that will never bedirectly integrated by a build variant, but deprecates user

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 132/255

  • Make and clean a module

    I To build a module from the top directory, just domake ModuleName

    I However, building a simple module wont regenerate a newimage. This is just useful to make sure that the modulebuilds. You will have to do a full make to have an image thatcontains your module

    I Actually, a full make will build your module at some point, butyou wont find it in your generated image if it is tagged asoptional

    I If you want to enable it for all builds, add its name to thePRODUCT_PACKAGES variables in thebuild/target/product/core.mk file.

    I You can also get the list of the modules to be built with themake modules target

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 133/255

  • Android Build System

    Add a New Product

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 134/255

  • Defining new products

    I Devices are well supported by the Android build system. Itallows to build multiple devices with the same source tree, tohave a per-device configuration, etc.

    I All the product definitions should be put indevice//

    I The entry point is the AndroidProducts.mk file, whichshould define the PRODUCT_MAKEFILES variable

    I This variable defines where the actual product definitions arelocated.

    I It follows such an architecture because you can have severalproducts using the same device

    I If you want your product to appear in the lunch menu, youneed to create a vendorsetup.sh file in the devicedirectory, with the right calls to add_lunch_combo

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 135/255

  • Product, devices and boards

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 136/255

  • Minimal Product Declaration

    $(call inherit-product, build/target/product/generic.mk)

    PRODUCT_NAME := full_MyDevice

    PRODUCT_DEVICE := MyDevice

    PRODUCT_MODEL := Full flavor of My Brand New Device

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 137/255

  • Copy files to the target

    $(call inherit-product, build/target/product/generic.mk)

    PRODUCT_COPY_FILES += \

    device/mybrand/mydevice/vold.fstab:system/etc/vold.fstab

    PRODUCT_NAME := full_MyDevice

    PRODUCT_DEVICE := MyDevice

    PRODUCT_MODEL := Full flavor of My Brand New Device

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 138/255

  • Add a package to the build for this product

    $(call inherit-product, build/target/product/generic.mk)

    PRODUCT_PACKAGES += FooBar

    PRODUCT_COPY_FILES += \

    device/mybrand/mydevice/vold.fstab:system/etc/vold.fstab

    PRODUCT_NAME := full_mydevice

    PRODUCT_DEVICE := mydevice

    PRODUCT_MODEL := Full flavor of My Brand New Device

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 139/255

  • Overlays

    I This is a mechanism used by products to override resourcesalready defined in the source tree, without modifying theoriginal code

    I This is used for example to change the wallpaper for oneparticular device

    I Use the DEVICE_PACKAGE_OVERLAYS orPRODUCT_PACKAGE_OVERLAYS variables that you set to a pathto a directory in your device folder

    I This directory should contain a structure similar to the sourcetree one, with only the files that you want to override

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 140/255

  • Add a package to the build for this product

    $(call inherit-product, build/target/product/generic.mk)

    PRODUCT_PACKAGES += FooBar

    PRODUCT_COPY_FILES += \

    device/mybrand/mydevice/vold.fstab:system/etc/vold.fstab

    DEVICE_PACKAGE_OVERLAYS := device/mybrand/mydevice/overlay

    PRODUCT_NAME := full_mydevice

    PRODUCT_DEVICE := mydevice

    PRODUCT_MODEL := Full flavor of My Brand New Device

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 141/255

  • Board Definition

    I You will also need a BoardConfig.mk file along with theproduct definition

    I While the product definition was mostly about the buildsystem in itself, the board definition is more about thehardware

    I You can have a full working example indevice/samsung/crespo/BoardConfigCommon.mk

    I However, this is poorly documented and sometimesambiguous so you will probably have to dig into thebuild/core/Makefile at some point to see what a givenvariable does

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 142/255

  • Minimal Board Definition

    TARGET_NO_BOOTLOADER := true

    TARGET_NO_KERNEL := true

    TARGET_CPU_ABI := armeabi

    HAVE_HTC_AUDIO_DRIVER := true

    BOARD_USES_GENERIC_AUDIO := true

    USE_CAMERA_STUB := true

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 143/255

  • Android Native Layer

    Android NativeLayerMaxime RipardFree Electrons

    c Copyright 2004-2013, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 144/255

  • Android Native Layer

    Bionic

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 145/255

  • Bionic

    I Google developed another C library for Android: Bionic.They didnt start from scratch however, they based their workon the BSD standard C library.

    I The most remarkable thing about Bionic is that it doesnthave full support for the POSIX API, so it might be a hurdlewhen porting an already developed program to Android.

    I However, Bionic has been created this way for a number ofreasons

    I Keep the libc implementation as simple as possible, so that itcan be fast and lightweight (Bionic is a bit smaller than uClibc)

    I Keep the (L)GPL code out of the userspace. Bionic is underthe BSD license

    I And it implements some Android-specifics functions as well:I Access to system propertiesI Logging events in the system logs

    I In the prebuilt/ directory, Google provides a prebuilttoolchain that uses Bionic

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 146/255

  • Android Native Layer

    Toolbox

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 147/255

  • Why Toolbox?

    I A Linux system needs a basic set of programs to workI An init programI A shellI Various basic utilities for file manipulation and system

    configuration

    I In normal Linux systems, those programs are provided bydifferent projects

    I coreutils, bash, grep, sed, tar, wget, modutils, etc. areall different projects

    I Many different components to integrateI Components not designed with embedded systems constraints

    in mind: they are not very configurable and have a wide rangeof features

    I BusyBox is an alternative solution, extremely common onembedded systems

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 148/255

  • General purpose toolbox: BusyBox

    I Rewrite of many useful Unix command line utilitiesI Integrated into a single project, which makes it easy to work

    withI Designed with embedded systems in mind: highly configurable,

    no unnecessary features

    I All the utilities are compiled into a single executable,/bin/busybox

    I Symbolic links to /bin/busybox are created for eachapplication integrated into BusyBox

    I For a fairly featureful configuration, less than 500 KB(statically compiled with uClibc) or less than 1 MB (staticallycompiled with glibc).

    I http://www.busybox.net/

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 149/255

  • BusyBox commands!

    Commands available in BusyBox 1.13[, [[ , addgroup, adduser, adjtimex, ar, arp, arping, ash, awk, basename, bbconfig, bbsh,brctl, bunzip2, busybox, bzcat, bzip2, cal, cat, catv, chat, chattr, chcon, 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, devfsd, df,dhcprelay, diff, dirname, dmesg, dnsd, dos2unix, dpkg, dpkg_deb, du, dumpkmap, dumpleases,e2fsck, echo, ed, egrep, eject, env, envdir, envuidgid, ether_wake, expand, expr, fakeidentd,false, fbset, fbsplash, fdflush, fdformat, fdisk, fetchmail, fgrep, find, findfs, fold, free,freeramdisk, fsck, fsck_minix, ftpget, ftpput, fuser, getenforce, getopt, getsebool, getty,grep, gunzip, gzip, halt, hd, hdparm, head, hexdump, hostid, hostname, httpd, hush, hwclock,id, ifconfig, ifdown, ifenslave, ifup, inetd, init, inotifyd, insmod, install, ip, ipaddr,ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill, killall, killall5,klogd, lash, last, length, less, linux32, linux64, linuxrc, ln, load_policy, loadfont,loadkmap, logger, login, logname, logread, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lzmacat,makedevs, man, matchpathcon, md5sum, mdev, mesg, microcom, mkdir, mke2fs, mkfifo, mkfs_minix,mknod, mkswap, mktemp, modprobe, more, mount, mountpoint, msh, mt, mv, nameif, nc, netstat,nice, nmeter, nohup, nslookup, od, openvt, parse, passwd, patch, pgrep, pidof, ping, ping6,pipe_progress, pivot_root, pkill, poweroff, printenv, printf, ps, pscan, pwd, raidautorun,rdate, rdev, readahead, readlink, readprofile, realpath, reboot, renice, reset, resize,restorecon, rm, rmdir, rmmod, route, rpm, rpm2cpio, rtcwake, run_parts, runcon, runlevel,runsv, runsvdir, rx, script, sed, selinuxenabled, sendmail, seq, sestatus, setarch,setconsole, setenforce, setfiles, setfont, setkeycodes, setlogcons, setsebool, setsid,setuidgid, sh, sha1sum, showkey, slattach, sleep, softlimit, sort, split, start_stop_daemon,stat, strings, stty, su, sulogin, sum, sv, svlogd, swapoff, swapon, switch_root, sync, sysctl,syslogd, tac, tail, tar, taskset, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time, top,touch, tr, traceroute, true, tty, ttysize, tune2fs, udhcpc, udhcpd, udpsvd, umount, uname,uncompress, unexpand, uniq, unix2dos, unlzma, unzip, uptime, usleep, uudecode, uuencode,vconfig, vi, vlock, watch, watchdog, wc, wget, which, who, whoami, xargs, yes, zcat, zcip

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 150/255

  • Toolbox

    I As Busybox is under the GPL, Google developed an equivalenttool, under the BSD license

    I Much fewer UNIX commands implemented than Busybox, butother commands to use the Android-specifics mechanism,such as alarm, getprop or a modified log

    Commands available in Toolbox in Gingerbreadalarm, cat, chmod, chown, cmp, date, dd, df, dmesg, exists, getevent, getprop, hd, id,ifconfig, iftop, insmod, ioctl, ionice, kill, ln, log, ls, lsmod, lsof, mkdir, mount, mv,nandread, netstat, newfs_msdos, notify, powerd, printenv, ps, r, readtty, reboot, renice, rm,rmdir, rmmod, rotatefb, route, schedtop, sendevent, setconsole, setkey, setprop, sleep, smd,start, stop, sync, syren, top, umount, uptime, vmstat, watchprops, wipe

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 151/255

  • Android Native Layer

    Init

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 152/255

  • Init

    I init is the name of the first userspace program

    I It is up to the kernel to start it, with PID 1, and the programshould never exit during system life

    I The kernel will look for init at /sbin/init, /bin/init,/etc/init and /bin/sh. You can tweak that with the init=kernel parameter

    I The role of init is usually to start other applications at boottime, a shell, mount the various filesystems, etc.

    I Init also manages the shutdown of the system by undoing allit has done at boot time

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 153/255

  • Androids init

    I Once again, Google has developed his own instead of relyingon an existing one.

    I However, it has some interesting features, as it can also beseen as a daemon on the system

    I it manages device hotplugging, with basic permissions rules fordevice files, and actions at device plugging and unplugging

    I it monitors the services it started, so that if they crash, it canrestart them

    I it monitors system properties so that you can take actionswhen a particular one is modified

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 154/255

  • Init part

    I For the initialization part, init mounts the various filesystems(/proc, /sys, data, etc.)

    I This allows to have an already setup environment beforetaking further actions

    I Once this is done, it reads the init.rc file and executes it

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 155/255

  • init.rc file interpretation

    I Uses a unique syntax, based on events

    I There usually are several init configuration files, init.rcitself, and init..rc

    I While init.rc is always taken into account,init..rc is only interpreted if theplatform currently running the system reports the same name

    I This name is either obtained by reading the file/proc/cpuinfo or from the androidboot.hardware kernelparameter

    I Most of the customizations should therefore go to theplatform-specific configuration file rather than to the genericone

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 156/255

  • Uevent

    I Init also manages the runtime events generated by the kernelwhen hardware is plugged in or removed, like udev does on astandard Linux distribution

    I This way, it dynamically creates the devices nodes under /dev

    I You can also tweak its behavior to add specific permissions tothe files associated to a new event.

    I The associated configuration files are /ueventd.rc and/ueventd..rc

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 157/255

  • Properties

    I Init also manages the system properties

    I Properties are a way used by Android to share values acrossthe system that are not changing quite often

    I Quite similar to the Windows RegistryI These properties are split into several files:

    I /system/build.prop which contains the properties generatedby the build system, such as the date of compilation

    I /default.prop which contains the default values for certainkey properties, mostly related to the security and permissionsfor ADB.

    I /data/local.prop which contains various properties specificto the device

    I /data/property is a folder which purpose is to be able toedit properties at run-time and still have them at the nextreboot. This folder is storing every properties prefixed bypersist. in separate files containing the values.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 158/255

  • Modifying Properties

    I You can add or modify properties in the build system by usingeither the PRODUCT_PROPERTY_OVERRIDES makefile variable,or by defining your own system.prop file in the devicedirectory. Their content will be appended to/system/build.prop at compilation time

    I Modify the init.rc file so that at boot time it exports theseproperties using the setprop command

    I Using the API functions such as the Java functionSystemProperties.set

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 159/255

  • Permissions on the Properties

    I Android, by default, only allows any given process to read theproperties.

    I You can set write permissions on a particular property or agroup of them using the filesystem/core/init/property_service.c

    /* White list of permissions for setting property services. */

    struct {

    const char *prefix;

    unsigned int uid;

    unsigned int gid;

    } property_perms[] = {

    { "net.rmnet0.", AID_RADIO, 0 },

    { "net.dns", AID_RADIO, 0 },

    { "net.", AID_SYSTEM, 0 },

    { "dhcp.", AID_SYSTEM, 0 },

    { "log.", AID_SHELL, 0 },

    { "service.adb.root", AID_SHELL, 0 },

    { "persist.security.", AID_SYSTEM, 0 },

    { NULL, 0, 0 }

    };Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 160/255

  • Special Properties

    I ro.* properties are read-only. They can be set only once inthe system life-time. You can only change their value bymodifying the property files and reboot.

    I persist.* properties are stored on persistent storage eachtime they are set.

    I ctl.start and ctl.stop properties used instead of storingproperties to start or stop the service name passed as the newvalue

    I net.change property holds the name of the last net.*property changed.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 161/255

  • Android Native Layer

    Various daemons

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 162/255

  • Vold

    I The VOLume Daemon

    I Just like init does, monitors new device events

    I While init was only creating device files and taking someconfigured options, vold actually only cares about storagedevices

    I Its roles are to:I Auto-mount the volumesI Format the partitions on the device

    I There is no /etc/fstab in Android, but/system/etc/vold.fstab has a somewhat similar role

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 163/255

  • rild

    I rild is the Radio Interface Layer Daemon

    I This daemon drives the telephony stack, both voice and datacommunication

    I When using the voice mode, talks directly to the baseband,but when issuing data transfers, relies on the kernel networkstack

    I It can handle two types of commands:I Solicited commands: commands that originate from the user:

    dial a number, send an SMS, etc.I Unsolicited commands: commands that come from the

    baseband: receiving an SMS, a call, signal strength changed,etc.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 164/255

  • Others

    I netdI netd manages the various network connections: Bluetooth,

    Wifi, USBI Also takes any associated actions: detect new connections, set

    up the tethering, etc.I It really is an equivalent to NetworkManagerI On a security perspective, it also allows to isolate

    network-related privileges in a single process

    I installdI Handles package installation and removalI Also checks package integrity, installs the native libraries on

    the system, etc.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 165/255

  • Android Native Layer

    SurfaceFlinger and PixelFlinger

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 166/255

  • Introduction to graphical stacks

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 167/255

  • Compositing window managers

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 168/255

  • SurfaceFlinger

    I This difference in design adds some interesting features:I Effects are easy to implement, as its up to the window

    manager to mangle the various surfaces at will to display themon the screen. Thus, you can add transparency, 3d effects, etc.

    I Improved stability. With a regular window manager, a messageis sent to every window to redraw its part of the screen, forexample when a window has been moved. But if an applicationfails to redraw, the windows will become glitchy. This will nothappen with a compositing WM, as it will still display theuntouched surface.

    I SurfaceFlinger is the compositing window manager inAndroid, providing surfaces to applications and rendering allof them with hardware acceleration.

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 169/255

  • SurfaceFlinger and PixelFlinger

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 170/255

  • Android Native Layer

    Stagefright

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 171/255

  • Stagefright

    I StageFright is the multimedia playback engine in Androidsince Eclair

    I In its goals, it is quite similar to Gstreamer: Provide anabstraction on top of codecs and libraries to easily playmultimedia files

    I It uses a plugin system, to easily extend the number offormats supported, either software or hardware decoded

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 172/255

  • StageFright Architecture

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 173/255

  • StageFright plugins

    I To add support for a new format, you need to:I Develop a new Extractor class, if the container is not

    supported yet.I Develop a new Decoder class, that implements the interface

    needed by the StageFright core to read the data.I Associate the mime-type of the files to read to your new

    Decoder in the OMXCodec.cpp file, in the kDecoderInfoarray.

    I No runtime extension of the decoders, this is done atcompilation time.

    static const CodecInfo kDecoderInfo[] = {

    { MEDIA_MIMETYPE_AUDIO_AAC, "OMX.TI.AAC.decode" },

    { MEDIA_MIMETYPE_AUDIO_AAC, "AACDecoder" },

    };

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 174/255

  • Android Native Layer

    Dalvik and Zygote

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 175/255

  • Dalvik

    I Dalvik is the virtual machine, executing Android applications

    I It is an interpreter written in C/C++, and is designed to beportable, lightweight and run well on mobile devices

    I It is also designed to allow several instances of it to be run atthe same time while consuming as little memory as possible

    I Two execution modesI portable: the interpreter is written in C, quite slow, but

    should work on all platformsI fast: Uses the mterp mechanism, to define routines either in

    assembly or in C optimized for a specific platform. Instructiondispatching is also done by computing the handler addressfrom the opcode number

    I It uses the Apache Harmony Java framework for its corelibraries

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 176/255

  • Zygote

    I Dalvik is started by Zygote

    I frameworks/base/cmds/app_processI At boot, Zygote is started by init, it then

    I Initializes a virtual machine in its address spaceI Loads all the basic Java classes in memoryI Starts the system serverI Waits for connections on a UNIX socket

    I When a new application should be started:I Android connects to Zygote through the socket to request the

    start of a new applicationI Zygote forksI The child process loads the new application and start

    executing it

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 177/255

  • Android Native Layer

    Hardware Abstraction Layer

    Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 178/255

  • Hardware Abstraction Layers