Article reprinted to CSDN community Luo Shenyang's Android tour, original address: http://blog.csdn.net/luoshengyang/article/details/6567257
The hardware abstraction layer of Android, simply, is the encapsulation of the Linux kernel driver, providing an interface upward, shielding the implementation details of the lower level. That is, the support for the hardware is divided into two layers, one layer in user space, one layer in the kernel space (Kernel spaces), where the hardware abstraction layer runs in user space, and the Linux kernel driver runs in kernel space. Why do we have to do this? Is it not OK to combine the hardware abstraction layer with the kernel driver and put it in the kernel space? From a technical implementation point of view, it is possible, but from a commercial point of view, the hardware support logic is placed in the kernel space, may harm the interests of manufacturers. We know that the Linux kernel source code copyright complies with the GNU License, while the Android source code copyright complies with Apache License, the former must publish the source code when publishing the product, while the latter does not need to publish the source code. If the hardware support for all the code is placed on the Linux driver, it means that the release of the source code to expose the driver, and open source code means that the hardware parameters and implementation are open, in the mobile phone market competition today, which for manufacturers, the damage is very large. Therefore, Android will think of hardware support into the hardware abstraction layer and the kernel driver layer, the kernel driver layer only provides simple access to hardware logic, such as read and write hardware registers of the channel, as to what value from the hardware or write what value to the hardware logic, are placed in the hardware abstraction layer, This will hide the business secrets. It is also because of this layering that Android is kicked out of the Linux kernel mainline code tree. As you can imagine, the hardware support for Android's driver in kernel space is incomplete, and when the Linux kernel is ported to another machine, the hardware is completely useless due to lack of support from the hardware abstraction layer, which is why Android is an open system rather than an open source system.
Aside from these arguments, learning about the Android hardware abstraction layer is extremely useful for understanding the entire Android system, as it involves the hardware drive layer of the Android system, the hardware abstraction layer, the runtime library, the application framework layer, and so on. The following diagram illustrates the location of the hardware abstraction layer in the Android system and its relationship to other layers:
In the process of learning the Android hardware abstraction layer, we will learn how to write hardware drivers in kernel space, how to add interfaces in the hardware abstraction layer to support access to hardware, how to provide hardware access services at system startup, and how to write JNI so that hardware can be accessed through the Java interface. And as an episode in the middle, we'll also learn how to add a C executable program to the Android system to access the hardware driver. As this is a systematic learning process, the author will be divided into six articles to describe each learning process, including:
One. Write the hardware driver in the Android kernel source code project.
Two. Add the C executable program to the Android system to access the hardware driver.
Three. Add the interface module to access the hardware driver in the Android hardware abstraction layer.
Four. Write the Jni method on the Android system to provide Java interface access to the hardware at the application framework level.
Five. Add the hardware service interface to the application framework layer of the Android system.
Six. Write apps on Android to access hardware services through the application framework layer.
After studying these six articles, I believe that you will have a deeper understanding of the Android system, so stay tuned.
Lao Luo's Sina Weibo: Http://weibo.com/shengyangluo, welcome attention!
Android hardware Abstraction Layer (HAL) Overview and Learning Plan