Nineth Hardware Abstraction Layer: HAL
The Nineth chapter mainly introduces a set of library HAL (Hardware abstraction Layer) built on Linux driver. This library is not part of the Linux kernel, but rather belongs to the application layer on top of the Linux kernel layer.
Google's main purpose of adding Hal to Android is to protect "private property" in addition to avoiding direct access to Linux drivers. HAL is the gospel for businesses or individuals who want to publish Android-based Linux drivers without exposing their core logic.
Why do I add HAL to Android in the first section?
Linux is only a "data setter" for Linux driver authors who don't want to open the source. In other words, the Linux driver should not keep any business logic code that you do not want to expose (the code is in the HAL), but only the code that interacts with the register, and the access register can only be done by the relevant functions of the Linux kernel. If this is the case, the Linux driver has only one shell left, and the only function is to receive the data sent by the HAL, write the data to the specified register, or read the data from the register and return it to the HAL. From this point of view, the Linux driver with HAL is equivalent to uploading data from the HAL to the sensor, or from the register to the HAL's "Data Setter".
Section II Android HAL Architecture
The core code in the HAL module does not change, just add some new HAL schema required entry code, so that these libraries can be automatically recognized by the Android system. The code that calls the HAL module does not need to load the. So file directly, but only requires an ID to locate the corresponding. So file (this is called stub). There is also a layer of service libraries between stubs and JNI, which uses the mechanism provided by the Android system to call the HAL to access the service library in the HAL. Then the Android app calls the service library again.
Section III for LED driver add HAL
Steps:
Writing Linux Drivers
Writing the HAL Library
Write Service Library
Nineth Hardware Abstraction Layer: HAL