Android bottom driver analysis and porting

honggarae 03/10/2021 1049

Introduction

The content of this book is divided into 3 parts, a total of 22 chapters, which explain the typical driver knowledge in the Android underlying system step by step. This book starts from obtaining the source code and analyzing the source code structure, and then explains the basic knowledge of the basic knowledge, the Android proprietary driver, and the typical driver transplantation. When explaining each driver, start with the architecture of the Android system, from the kernel analysis to the specific driver implementation, then from the JNI layer architecture analysis to the interface application of the Java application layer, and finally to the transplantation and development of the typical drive system, and thoroughly analyze it. The complete implementation process of each typical drive system is described. This book covers almost all the content of Android underlying driver, the explanation method is easy to understand, and the content is informative. It is not only suitable for the learning of application masters, but also particularly conducive to the learning and digestion of beginners.

This book is suitable as a learning book for Android driver developers, Linux developers, Android low-level learners, Android enthusiasts, Android source code analysts, and Android application developers, as well as related training schools and colleges. Teaching books for related majors in colleges and universities.

Book Catalog

The first basic knowledge article

Chapter 1 Android underlying development foundation.............. ......... 2

1.1 Introduction to Android system............................. ......... 2

1.2 Introduction to Android system architecture............ .. 2

1.3 Get the Android source code... . 5

1.5 Compile the source code...................................... ............ 20

Chapter 2 Basics of Android Driver Development........ 28< /p>

2.1 Driver Basics........................................ .. 28

2.2 Basics of Linux Development... .... 30

2.3 Linux kernel structure........................ ...... 35

2.4 Analyze the Linux kernel source code............................... 40

2.5 How to learn Linux kernel...........................50

2.6 Type 3 drivers in Linux...54

2.7 Basics of Android system transplantation... ...65

2.8 The interface between kernel space and user space.......... 67

2.9 Writing JNI method...................................... .... 72

Chapter 3 Mainstream Kernel System Analysis............76

p>

3.1 Goldfish kernel and driver analysis... ... 76

3.2 MSM kernel and driver architecture............ 85

Part 2 Android Proprietary Drivers

Chapter 4 Analyze the Hardware Abstraction Layer......................... ...... 98

4.1 HAL basics....................... ................98

4.2 Analysis of HAL module architecture..................... .... 101

4.3 Analyze the file hardware.c ........................ 103< /p>

4.4 Analyze the loading process of the hardware abstraction layer...106

4.5 Analyze the hardware access service... .........................109

4.6 Analyze the Mokoid example............. ..................... 111

4.7 HAL and system migration...... .... 120

4.8 Develop your own HAL driver ... .. 126

Chapter 5 Detailed explanation of Binder communication driver...130

5.1 Analysis of Binder Driver........................ 130

5.2 Binder package library driver........ ........................ 153

5.3 Initialize the Java layer Binder framework............ ... 160

5.4 The driver of the entity object binder_node.............. 163

5.5 The local object BBinder driver... ......................167

5.6 Reference object binder_ref driver............... ....... 177

5.7 Proxy object BpBinder driver........ ............... 180

Chapter 6 Detailed Explanation of Logger Drive Architecture............. 185

6.1 Analyze the Logger driver............ 185

6.2 Log Library Liblog driver ...201

6.3 Log writing interface driver. ...............206

Chapter 7 Ashmem driver detailed explanation..... ..... 217

7.1 Analysis of Ashmem driver ... ....... 217

7.2 C++ access interface layer.............................. ....... 231

7.3 Interface layer that implements Java access....................... 243

7.4 Actual combat exercise-reading data in kernel space...247

Chapter 8 Setting up a test environment... ... 250

8.1 Setting up the S3C6410 development environment..................... .. 250

8.2 Introduction to other development environments......................257

p>

8.3 The method of test drive............ 259

Chapter 9 Low Memory Management Driver............. 266

9.1 OOM Mechanism..............................................266 p>

9.2 Low Memory Killer architecture mechanism of Android system....... 273

9.3 Detailed explanation of Low Memory Killer driver............... 274

9.4 Actual combat exercise-Obtaining objects from the memory pool... 280

9.5 Actual combat exercise- —Use the user program to read the data in the kernel space....... 282

Chapter 3 Typical Driver Porting

Chapter 10 Power Management Driver..... ..........286

10.1 Power Management Architecture Foundation............ . 286

10.2 Analysis of the Framework layer.............. 287

10.3 Analysis of JNI layer structure............ 309

10.4 Analysis of Kernel layer architecture...... 311

10.5 wakelock and early_suspend............ ... 319

10.6 Battery system architecture and management..............323

10.7 JobScheduler energy-saving scheduling mechanism..... ...........331

Chapter 11 PMEM memory driver architecture............339

11.1 Preliminary PMEM.........................................339 p>

11.2 PMEM driver architecture........................341

11.3 User space interface......................................367

11.4 Actual combat exercise-adding PMEM to the kernel... 370

11.5 Actual combat exercise-adding PMEM to the kernel... ......372

11.6 Actual combat exercise-PMEM application in Camera...... 373

11.7 Actual combat exercise-PMEM transplantation and testing. .. 375

Chapter 12 Debugging Mechanism Drives Ram Console ........ 378

12.1 Introduction to Ram Console............ .................... 378

12.2 Actual Now Ram Console................................378

Chapter 13 USB Gadget driver. .......................389

13.1 Analyze the USB driver of the Linux kernel.....389

< p>13.2 Detailed explanation of USB Gadget driver architecture...401

13.3 Practical drill-USB driver routine analysis... 437

13.4 Actual combat drill... ...450

Chapter 14 Time Device Driver........................453

< p>14.1 Timed Output drive architecture........ 453

Practical exercise-to realize the read and write operations of the device.. ........460

14.2 Timed Gpio driver architecture..........................461

p>

Chapter 15 Alarm System Drive Alarm .......467

15.1 Basics of Alarm System........ ............... 467

15.2 RTC driver architecture.......... ..... 468

15.3 Alarm drive architecture........ ................. 469

15.4 JNI layer detailed explanation... ...... 491

15.5 Java layer detailed explanation...... ............... 493

15.6 The concrete realization of the simulator environment......... .............503

15.7 Actual combat drills.......................... ..... 504

Chapter 16 Vibrator Drive Architecture and Migration ...512

16.1 Vibrator system architecture ... .............512

16.2 Hardware abstraction layer architecture........................ .......... 513

16.3 JNI layer architecture............................ ...............514

16.4 Java layer architecture....................... .........515

16.5 Actual Combat Drill-Transplanting Vibrator System...519

p>

16.6 Actual combat exercise-Vibrator drive on the MSM platform...........520

16.7 Actual combat exercise-Vibrator drive on the MTK platform.. .......... 523

16.8 Actual combat exercise-transplanting the vibrator driver...........526

Chapter 17 Input System driver............................ 527

17.1 Input system architecture analysis... ..........................527

17.2 The method of transplanting input system driver......... ......... 528

17.3 Input system driver detailed explanation.............. 529

17.4 Hardware abstraction Detailed explanation of layers........ 551

17.5 Actual combat drill... ........................................... 561

Chapter 18 LCD Display Driver...573

18.1 LCD system introduction. ....................................573

18.2 Detailed explanation of the FrameBuffer core layer. ..... 573

18.3 Detailed Explanation of Hardware Abstraction Layer... ................. 6 00

18.4 Detailed explanation of FrameBuffer driver in Goldfish...........607

18.5 Driver using Gralloc module........ .... 610

18.6 MSM display driver in Qualcomm processor........ 620

18.7 Detailed explanation of Gralloc driver in MSM..... . 623

The realization of the display driver in the 18.8 OMAP processor...630

18.9 Actual combat drill............... ...............633

Chapter 19 Audio System Driver..... ..........664

19.1 Audio system architecture basis............ ........ 664

19.2 Detailed audio system hierarchy......... ...........668

19.3 Porting Audio system........................... ....... 672

19.4 Practical drill——Realize Audio driver on MSM platform..........680

19.5 Practical drill——in OSS platform realizes Audio driver.............684

19.6 Practical drill——Realize Audio system on ALSA platform...........692< /p>

Chapter 20 Detailed Explanation of Overlay System Driver...710

20.1 Video output system structure...... ........................710

20.2 Transplant Overlay System.............. ...711

20.3 Detailed hardware abstraction layer... ..............711

20.4 Implementation of Overlay hardware abstraction layer......715

p>

20.5 Actual Combat Exercise-Realizing Overlay System on OMAP Platform.........717

< p>20.6 Actual Combat Exercise-Calling Overlay HAL at the System Layer...724

Chapter 21 Camera Driver... ........................ 729

21.1 The structure of the Camera system....... ......729

21.2 Porting Camera System...... ......737

21.3 Actual Combat Drill-Realizing Camera Driver on MSM Platform....... 747

21.4 Actual Combat Exercise-Implementing Camera Driver on OMAP Platform.........750

21.5 Android Implementing S5PV210 FIMC Driver............. 751

Chapter 22 Bluetooth System Driver...764

< p>22.1 Bluetooth module in Android system......764

22.3 Detailed explanation of Bluetooth low energy protocol stack......... .............767

22.4 BlueDroid in Android ......................769< /p>

22.5 Operation process of Android Bluetooth module............783

Latest: BREW (English word)

Next: Low-level development