lecture 11 - inuesc.inu.ac.kr/~chung/epc6071_2017/lecture_11.pdf · 2017. 5. 24. · lecture 11....

29
Jaeyong Chung Systems-on-Chips (SoC) Laboratory Incheon National University Embedded System Design Lecture 11

Upload: others

Post on 03-Oct-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Jaeyong Chung

Systems-on-Chips (SoC) Laboratory

Incheon National University

Embedded System Design

Lecture 11

Page 2: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Android

An operating system based on the Linux kernel

Java is the first-class citizen in Android

Chung EPC6071 2

Page 3: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Java

Java is a computer programming language

Objective-oriented language like C++

Intended to let application developer “write once, run

anywhere (WORA)”

Code that runs on one platform does not need to be recompiled

to run on another

Java applications are compiled to bytecode (class file)

that can run on any Java virtual machine (JVM)

regardless of computer architecture

Java Standard Libraries: Java ME, Java SE, Java EE

Chung EPC6071 3

Page 4: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Java

JNI (Java Native Interface) is a programming framework

that enables Java code running in a Java Virtual

Machine to call and be called by native applications

Chung EPC6071 4

Page 5: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Porting android to your embedded system

Let’s say you create a novel ES and you want to run

android on your ES

As of January 2014, current Android versions are built

upon Linux Kernel 3.4 or later

Chung EPC6071 5

Page 6: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Porting android to your embedded system

Download the kernel source

(http://source.android.com/source/building-kernels.html)

$ git clone https://android.googlesource.com/kernel/exynos.git

The exynos project has the kernel sources for Nexus 10, and can be

used as a starting point for work on Samsung Exynos chipsets

Download the toolchain

$ git clone

https://android.googlesource.com/platform/prebuilts/gcc/linux-

x86/arm/arm-eabi-4.6

Make

Chung EPC6071 6

Page 7: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Android 4.0 ICS on Raspberry PI

Chung EPC6071 7

Page 8: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

System Architecture

An application framework consists of a software

framework used by software developers to implement the

standard structure of an application

Chung EPC6071 8

Page 9: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Typical Directory Tree of Android

Chung EPC6071 9

Page 10: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Inter-process Communication

In GNU/ Linux Signal

Pipe

Socket

Semaphore

Message Queue

Shared memory

In Android Binder: lightweight Remote Procedure Call (RPC)

mechanism

Chung EPC6071 10

Page 11: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Binder IPC

Driver to facilitate inter-process communication

High performance through shared memory

Synchronous calls between processes

“In the Android platform, the binder is used for nearly

everything that happens across processes in the

core platform” – Dianne Hackborn

Chung EPC6071 11

Page 12: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Low-level System Architecture

If you have a new IO device

Develop a linux device driver

Develop hardware abstraction layer

Linux Kernel

For the most part, developing your

device drivers is the same as

developing a typical Linux device

driver

Hardware abstraction layer (HAL)

Hides the lower-level implementations

of your drivers and hardware

Built into shared library modules (.so

files)

Chung EPC6071 12

Page 13: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Bluetooth Example

Chung EPC6071 13

Page 14: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Sensor Example

If you have a new type of sensor in your ES, you need to

implement the following the HAL interface in addition to

your device driver:

Chung EPC6071 14

Page 15: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Developing Android Applications

Android applications are written in Java

Download SDK

(http://developer.android.com/sdk/index.html)

Includes Android API and tools

Eclipse is a java-based integrated development

environment (IDE)

Android Develop Tools (ADT) is an Eclipse plugin

Android applications are usually developed using Eclipse

+ ADT plugin

ADT bundle includes

A version of Eclipse

ADT plugin

Chung EPC6071 15

Page 16: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Dalvik VM

Dalvik is a java virtual machine in Google’s android

operating system

Takes .dex (Dalvi Excutable) and odex (Optimized Dalvik

Exectuable) files instead of .class (Java bytecodes)

A tool called dx is used to convert some Java .class files into the

.dex format

Unlike Java VMs, which are stack machines, the Dalvik

VM uses a register-based architecture

/system/bin/dalvikvm

Similar to usual ‘java’ command

Try ‘dalvikvm –h’ to show command line help

Chung EPC6071 16

Page 17: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

App Component: Activity

An application component that provides a screen with

which users can interact in order to do something, such

as dial the phone, take a photo, send an email, or view a

map.

An activity can start other activities, including activities that live

in separate applications.

Unlike other programming paradigms in which apps are

launched with a main() method, android applications

should be implemented using an application framework

called activity

Chung EPC6071 17

Page 18: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

App Component: Service

A Service is an application component that can perform

long-running operations in the background without a user

interface. For example, a service can handle network

transactions, play music, or work with a content provider

without the user being aware of the work going on

Chung EPC6071 18

Page 19: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Developing Android Applications in C or C++

Native Development Kit (NDK)

Allows you to implement parts of your app using native-code

languages such as C and C++

The purpose is to create native libraries, not programs

The native libraries are called from Java via JNI

Even if you really want an app to be in C or C++ entirely,

you need to write at least a tiny Java class that will call

your native library immediately

Google already made a generic java class like that

which is NativeActivity

Chung EPC6071 19

Page 20: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Developing Android Applications in C or C++

Porting existing applications into android platform using

NDK would be a fun project

Although it is not recommended by Google

http://blog.stuff-o-matic.com/

Chung EPC6071 20

Page 21: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Boot Sequence

Daemon is a computer program that runs as a background process

Chung EPC6071 21

Page 22: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

System Services

Chung EPC6071 22

Page 23: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Zygote

Chung EPC6071 23

Page 24: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Zygote

Zygote process preloads typical (approx. 1800) classes

and dynamic libraries so that children start quickly

Copy-on-write

Only when new process writes page, new page is allocated

All pages not be written are shared among all zygote children

Exec system call is not used in zygote

Exec wipes the page mapping table of the process

It means exec discards zygote cache

Chung EPC6071 24

Page 25: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Bionic

Standard C/C++ library

Libc, libm, ptrhead, dynamic linker

BSD license is a non-copyleft license and Google wished

to isolate Android applications from the effects of both

the GPL and the LGPL

The most widespread standard C libraries for the Linux kernel

are the GNU C Library and uClibc, which are both subject to the

GNU Lesser General Public License (LGPL); in contrast to the

GPL, the LGPL explicitly allows for dynamic linking but it does

not allow static linking of proprietary software

Smaller size than GNU C library

Bonic is designed for CPUs at relatively low clock frequencies

Chung EPC6071 25

Page 26: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

UID, GID of applications

UID(user id) and GID (group id) is used for managing

multi-user in usual Linux system

Android use this mechanism to isolate applications

Each application has UID

Can not read/write other application’s files

Zygote is running as UID=0 (root)

After forking child process, its UID is changed by setuid system

call

Chung EPC6071 26

Page 27: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

adb

Android Debug Bridge (adb) is a versatile command line tool

that lets you communicate with an emulator instance or

connected Android-powered device

A client-server program that includes three components

A client, which runs on your development machine. You can invoke a

client from a shell by issuing an adb command.

A server, which runs as a background process on your development

machine. The server manages communication between the client and

the adb daemon running on an emulator or device

A daemon, which runs as a background process on each emulator or

device instance

Adb is usually used over USB. However, it is also possible to

use over Wi-FI

After forking child process, its UID is changed by setuid system call

Chung EPC6071 27

Page 28: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

adb

Data

$ adb install <path-to-apk>

$ adb pull <remote> <local>

$ adb push <local> <remote>

Debug

$ adb logcat [option] [filter-specs]

Shell

$ adb shell

$ adb shell [shellCommand]

Chung EPC6071 28

Page 29: Lecture 11 - INUesc.inu.ac.kr/~chung/epc6071_2017/Lecture_11.pdf · 2017. 5. 24. · Lecture 11. Android ... Chung EPC6071 11. Low-level System Architecture

Android Logging System

Chung EPC6071 29