Hal is a set of libraries built on Linux drivers. This library is not part of the Linux kernel but is the application layer on top of the Linux kernel layer.
Google's main purpose for adding Hal to Android is as follows:
1, the unified hardware call interface.
2, solve the GPL copyright issue.
3, for a number of special requirements.
To write a Linux driver that supports HAL:
1. Write Linux drivers
2. Writing Hal Library
3. Write Service Library
Steps and principles for writing HAL modules:
1. Define structure and macro
2. Write the HAL module's Open function
3. Define HW_MODULE_METHODS_T structure variables
4. Define HAL_MODULE_INFO_SYM variables
5. Write the close function of the HAL module
6, write the function of the control LED
There are two ways to use Linux drivers in an Android system. One is to interact directly with Linux drivers in a traditional way. For example, directly read and write data from a device file. The other is Android-specific, which is through the HAL module. The HAL module essentially interacts with the Linux driver through a Linux shared library, and then the application accesses the Linux shared library. Early HAL modules have applications that are called directly by accessing the Linux shared library. The higher version of the Android system adds a stub to HAL. In other words, specify an ID for each HAL shared library, and then use that ID to match a certain rule to find the Linux shared library. So the Linux shared library to replace the file name, mobile location is very convenient. Google also recommends using stubs to write HAL modules.
Android Deep Explore Nineth Chapter