Building Android OS Topics Building Android and Kernel

  • Slides: 31
Download presentation
Building Android OS Topics: Building Android and Kernel Date: 11/7/2017

Building Android OS Topics: Building Android and Kernel Date: 11/7/2017

References (study these) • https: //source. android. com/source/index. html • https: //source. android. com/source/requirements.

References (study these) • https: //source. android. com/source/index. html • https: //source. android. com/source/requirements. html • https: //source. android. com/source/building-kernels. html#building • https: //source. android. com/devices/index. html

Android OS Architecture

Android OS Architecture

Android Binary Component 1. Application Processor Images Bootloader Image Kernel Image 2. Communication Processor

Android Binary Component 1. Application Processor Images Bootloader Image Kernel Image 2. Communication Processor Image Platform Image

Android OS Image Component • Bootloader Image • Initialize system and launch Linux kernel

Android OS Image Component • Bootloader Image • Initialize system and launch Linux kernel • Kernel Image • Include Linux Kernel (bz. Image) • Basic Linux OS system and device drivers • “kernel” or other names • Platform Image • Include Android Framework, Native Libraries, Android Runtime, HAL • The core of Android OS except kernel image • “system. img” • Other Images • CP(Communication Processor) Image, User Data, …

Android Boot Sequence 1. Kernel Booting - Initialization - Call init process 2. Init

Android Boot Sequence 1. Kernel Booting - Initialization - Call init process 2. Init Process - Launch daemons - Start Zygote 3. Start Zygote and Dalvik - Virtual machine - Initial process 4. System Server - Start Java Service

Android Boot Sequence 1. Power On and System Startup • Starts when we press

Android Boot Sequence 1. Power On and System Startup • Starts when we press the power button. • The Boot ROM code starts executing from a pre-defined location which is hardwired in ROM. • It loads the Bootloader into RAM and starts executing.

Android Boot Sequence 2. Bootloader • The bootloader is a small program which runs

Android Boot Sequence 2. Bootloader • The bootloader is a small program which runs before Android does. • Bootloader is NOT part of the Android operating system. • The bootloader executes in two stages. • In the first stage it detects external RAM and loads a program which helps in the second stage. • In the second stage, the bootloader setups the network, memory, etc, which requires to run kernel.

Android Boot Sequence 3. Kernel • The Android kernel starts in a similar way

Android Boot Sequence 3. Kernel • The Android kernel starts in a similar way as the Linux kernel. • Setup cache, protected memory, scheduling and loads drivers. • binder, ashmem, logger, wakelocks, oom, … • When the kernel finishes the system setup, it looks for “init” in the system files.

Android Boot Sequence 4. init process • Init is the very first process •

Android Boot Sequence 4. init process • Init is the very first process • It is a root process, or the grandfather of all processes. • The init process has two responsibilities. • 1 - Mounts directories like /sys , /dev or /proc • 2 - Runs init. rc script • At this stage, you can finally see the Android logo in your screen.

Android Boot Sequence 5. Zygote and Dalvik • Start Davlik Virtual Machine - an

Android Boot Sequence 5. Zygote and Dalvik • Start Davlik Virtual Machine - an interpreter for the Java programming language. • It’s written for CPU utilization and to minimize memory usage • Starts a process called “Zygote”. • The Zygote enables code sharing across the Dalvik VM, achieving a lower memory footprint and minimal startup time. • The Zygote preloads and initializes core library classes. • At this time, you can see the boot animation.

Android Boot Sequence 6. System Services • After the above steps are completed, Zygote

Android Boot Sequence 6. System Services • After the above steps are completed, Zygote launches the system services. • The Zygote forks a new process to launch the system services. • • • Core services: Starting power manager Creating the Activity Manager Starting context manager Starting system contact providers Starting battery service Starting alarm manager Starting sensor service …

Android Source Tree • • art - Android Run. Time bionic - libc library,

Android Source Tree • • art - Android Run. Time bionic - libc library, math library, (dynamic) linker dalvik – Dalvik virtual machine device – configurations for various smartphone models external - not Android original code(sqlite, open. CV) docs - documentation frameworks • • hardware – hardware vendor specific code(Intel, ARM…) kernel – kernel source tree out – build output files are located prebuilt – toolchain(gcc), other pre-built image or program • The heart of Android source code • Built-in application, Java framework, C++ Native code, Android service

Android Platform Build

Android Platform Build

Android OS Build • Basic hardware requirements: • • 64 bit machine for Gingerbread

Android OS Build • Basic hardware requirements: • • 64 bit machine for Gingerbread or higher version 100 GB hard disk for source code 200 GB hard disk for build Multi-core server is strongly recommended!! • Basic software requirements: • • • Linux (Ubuntu 12. 04) for Gingerbread or higher version Java Development Kit (1. 8 or higher version) Python 2. 6 GNU Make and GCC https: //source. android. com/source/initializing

Android Platform Build 1. Download Repo • $ mkdir ~/bin • $ PATH=~/bin: $PATH

Android Platform Build 1. Download Repo • $ mkdir ~/bin • $ PATH=~/bin: $PATH • $ curl https: //storage. googleapis. com/git-repodownloads/repo > ~/bin/repo • $ chmod a+x ~/bin/repo

Android Platform Build 2. Repo init • $ repo init -u https: //android. googlesource.

Android Platform Build 2. Repo init • $ repo init -u https: //android. googlesource. com/platform/manifest

Android Platform Build 3. Repo sync (downloading source files) • $ repo sync

Android Platform Build 3. Repo sync (downloading source files) • $ repo sync

Android Platform Build 4. Build setting • $ source build/envsetup. sh • $ lunch

Android Platform Build 4. Build setting • $ source build/envsetup. sh • $ lunch

Android Platform Build 5. Make • We build platform image for emulator • Select

Android Platform Build 5. Make • We build platform image for emulator • Select building setting (1) in the lunch menu • $ make

Android Platform Build 6. Output files • After a few hours later, build finishes

Android Platform Build 6. Output files • After a few hours later, build finishes • “android/out/target/product/mini-emulator-x 86_64/” • “ramdisk. img”, “system. img”, “userdata. img”

Android Kernel Build

Android Kernel Build

Android Kernel Build 1. Download source files • $ git clone https: //android. googlesource.

Android Kernel Build 1. Download source files • $ git clone https: //android. googlesource. com/kernel/goldfish. git • Reference for Android Kernel list • https: //source. android. com/source/building-kernels

Android Kernel Build 1. Download source files • No files downloaded, we need to

Android Kernel Build 1. Download source files • No files downloaded, we need to checkout branch • $ cd goldfish • $ git branch -a

Android Kernel Build 1. Download source files • $ git checkout -t origin/android-goldfish-3. 10

Android Kernel Build 1. Download source files • $ git checkout -t origin/android-goldfish-3. 10 -b goldfish • $ ls

Android Kernel Build 2. Build kernel for Emulator • We build kernel image for

Android Kernel Build 2. Build kernel for Emulator • We build kernel image for Android emulator • $ /home/seulki/android/prebuilts/qemu-kernel/buildkernel. sh --arch=x 86

Android Kernel Build 3. Output kernel image • “goldfish/arch/x 86/boot/bz. Image”

Android Kernel Build 3. Output kernel image • “goldfish/arch/x 86/boot/bz. Image”

Loading kernel to Emulator 1. Copy “bz. Image” to the Android emulator folder •

Loading kernel to Emulator 1. Copy “bz. Image” to the Android emulator folder • “C: UsersSeulkiApp. DataLocalAndroidSdksystemimagesandroid-23google_apisx 86” 2. Change filename from “kernel-qemu” to “kernel-qemu 2” 3. Change filename from “bz. Image” to “kernel-qemu” 4. Launch Android Emulator

Flashing images into real device 1. Your custom images can be flashed to real

Flashing images into real device 1. Your custom images can be flashed to real devices • “fastboot” tool in Android SDK 2. Entering to the download mode • Turn off the phone. • Press and hold the volume down and power buttons simultaneously, and keep holding them for about 10 seconds. 3. Flashing • flash-all • fastboot flash bootloader <bootloader image file name>. img • fastboot flash boot <boot image file name>. img • fastboot flash system <system file name>. img • fastboot flash radio <radio image file name>. img DO NOT FLASH IMAGES IF YOU’RE NOT SURE!

Make-up Assignment Part 1 - Kernel Android uses many input devices such as touchscreen,

Make-up Assignment Part 1 - Kernel Android uses many input devices such as touchscreen, touch key and hardware key. But for an emulator, it cannot use physical input devices mentioned above. Instead, a mouse pointer connected to your laptop is used as a touchscreen pointer for an emulator screen. • Find the location of pointer device driver in Kernel source. • Print a log message for pointer every time your laptop-mouse clicks on the emulator screen like the below picture (you need to load your modified kernel to the emulator).

Make-up Assignment Part 2 Platform Sensor data from sensor devices in your phone travel

Make-up Assignment Part 2 Platform Sensor data from sensor devices in your phone travel though multiple Android software layers to arrive at a sensor application. It starts from a physical sensor device and travels though kernel device driver, sensor HAL(Hardware Abstraction Layer), sensor service, sensor framework(Sensor. Manger) and finally arrives at an application. In this assignment, we are going to look at sensor HAL in detail. • Where is the location of sensor HAL source files? • What is the difference between sensor HAL code for real device and emulator? • Add one sensor to the HAL that is not currently supported for emulator. You don’t need to add the new sensor to other layers(sensor service, sensor framework) and kernel. • Build your own sensor HAL with the sensor you have newly added (make sure it does not make any compile errors).