27
1 和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。 Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved. NTU CSIE 2017.01.16 The key issues for teaching or learning Android and Linux Kernel 梁文耀, CTO 和沛移動股份有限公司

The key issues for teaching or learning Android and Linux Kernel

Embed Size (px)

Citation preview

1和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

NTU CSIE 2017.01.16The key issues for teaching or learning

Android and Linux Kernel梁文耀, CTO

和沛移動股份有限公司

2和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

■ Android: http://www.slideshare.net/williamwyliang/an-introduction-to-the-android-framework-a-core-architecture-view-from-apps-to-the-kernel

■ Linux Kernel: http://www.slideshare.net/williamwyliang/an-introduction-to-the-linux-kernel-and-device-drives-ntu-201603-59718004

■ Android Device Drivers: http://www.slideshare.net/williamwyliang/android-device-driver-structure-introduction

■ Design Pricinple for H/W Drivers: http://www.slideshare.net/williamwyliang/operating-systems-and-software-design-for-hardware-components

References

3和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Basic Topics for Kernel 1/2

■ Device file concept■ File operations■ System calls■ Dynamic loadable kernel module■ Kernel memory management■ Concurrency control■ Synchronizations■ Performance issues

4和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Basic Topics for Kernel 2/2

■ Interrupt handling and ISR■ Process control■ Waiting queues■ Blocking accesses■ Bottom half■ Atomic context■ Linux device model and sysfs■ Other types of device drivers

5和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Basic Topics for Android 1/2

■ Android framework integration overview■ Apps and framework programming■ Kernel vs. user space device drivers■ Native shared libraries■ Android NDK■ Java native interface■ Device control flow for Android and Linux■ Framework and hardware services

6和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

■ Android device control model and service-oriented device management

■ Binder IPC and AIDL■ Android booting flow■ System services and service

management■ Android HAL and interfaces■ HAL Stub and HAL Module

Basic Topics for Android 1/2

7和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

in 15 minutes

A Brief Introduction for Android and LInux Kernel

8和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Android vs. Linux

■ Android differs from the typical GNU/Linux in that Android adopts only the Linux kernel, not everything.

■ The first process ‘init’ transfers to Android’s own application environment.

■ The Bionic libc is used instead of glibc or uClibc.

■ As a result, it is called Android/Linux, not GNU/Linux.

9和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Android Architecture

10和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

The Linux Kernel

• Android relies on Linux version 2.6 and later for core system services such as security, memory management, process management, network stack, and driver model.

• The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.

Why Linux?

• Great memory and process management

• Permissions-based security model

• Proven driver model

• Support for shared libraries

• It’s already open source!

11和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

About the Linux Kernel

• An implementation of UNIX• Multitasking• File systems• Distributions• Device Management• System Interface• Threading• IPC

12和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Android Framework

• Mixed Language/Layer Design• Application Framework• Services• Native Shared Library• Dalvik Virtual Machine

13和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

An Overview: from Apps to H/W

• User level (user mode)• Write a user program• Compile & Link• Execution

• Kernel (kernel mode)• Load the program• System call• Device driver

• Hardware manipulation

14和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Linux Kernel and the Drivers

15和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

OS for I/O

• Provide protection to shared I/O resources• Provides abstraction for accessing devices• Handles the interrupts generated by I/O devices• Provide equitable access to the shared I/O

resources• Schedule accesses in order to enhance system

throughput

© Computer Organization and Design: The Hardware/Software Interface, David Patterson and John Hennessy

16和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Role of the Device Drivers

• Device drivers are usually treated as black boxes for the application developers.

• They resemble as a software layer lying between the applications and the actual devices.

• A device driver performs user requests in a standardized manner.

17和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

How Linux Treats Devices

• Unix/Linux see devices as special files•Device files

• Enable users to employ familiar commands and functions such as open, read, write, and close

•File Operations vs. Device Accesses

18和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

• Android Application

• Android Application Framework• Android Java/C/C++ Interface• Android/Linux Native Layers• Linux System Calls• Linux Device Driver• Hardware and Control

Android/Linux Integration

19和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

The Android HAL

20和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

System Integration Flow

• Implement the device driver• Implement the HAL Module• Implement the Native Stub• Implement the Hardware Service• Implement the Software Management

Component• Implement Applications

21和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Kernel Module (.ko)

Kernel Module(C Code)

Implement Device Driver

File Operations

22和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Shared Library (.so)

Kernel Module(C Code)

HAL Module(Native Code)

Implement HAL Module

System call Kernel Module (.ko)

HAL DeviceInterface

File Operations

23和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Shared Library (.so)

HAL Stub(JNI Native Code)

Kernel Module(C Code)

HAL Module(Native Code)

Implement Native Stub

hw_get_module

System callKernel Module (.ko)

Shared Library (.so)

HAL DeviceInterface

File Operations

NativeFunctions

24和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

HAL Stub(JNI Native Code)

Kernel Module(C Code)

HAL Module(Native Code)

Implement Hardware Service

hw_get_module

System callKernel Module (.ko)

Shared Library (.so)

Android Service (APK+.so)

Hardware Service(Java Code)

JNI

BinderInterfac

e

HAL DeviceInterface

NativeFunctions

File Operations

25和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Hardware Service(Java Code)

HAL Stub(JNI Native Code)

External Library (JAR)

Kernel Module(C Code)

HAL Module(Native Code)

Device Manager(Java Code)

Implement Mgmt. Component

hw_get_module

JNI

System call

Android Service (APK+.so)

Shared Library (.so)

Kernel Module (.ko)

Binder IPC

BinderInterfac

e

HAL DeviceInterface

NativeFunctions

File Operations

26和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

for the rest time of the talk, if still available :p

Let’s go back and review the contents of the reference

pages.

27和沛移動股份有限公司機密資料,非經許可不得重製、轉載、或散播。

Copyright © 2016 和沛科技 Hope Bay Mobile, Inc. All rights reserved.

Q&A