By learning Android Deep Exploration (Volume one) HAL and Driver Development Nineth Chapter Let me know the HAL hardware abstraction layer, why to add Hal and Android Hal Architecture in Android.
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, the main purpose of which is to avoid direct access to the Linux driver, but also the important reason is to protect "private property."
Linux drivers in traditional Linux systems typically have two types of code: Access to hardware register code and business logic code. So the main reason to join HAL is: 1, unified hardware call interface, because HAL has a standard call interface, so you can use Hal Shield Linux Drive complex, non-uniform interface; 2, solve the GPL copyright issue, because the Linux kernel based on the GPL protocol, While Android is based on the Apache licence2.0 protocol, and Hal has a layer of sensitive code that was originally in Linux drivers, 3, for some special requirements, for some hardware, may need to access some user's space resources, Or work that is inconvenient in the kernel space, and special requirements, in which case the HAL code located in the user space can be used to assist the Linux driver in doing some work.
The basic principle of the HAL architecture is to use the library in the Android system to invoke Linux drivers located in kernel space, and then the Android application can access the libraries in the HAL through the NDK program, or access the libraries in the HAL directly in the Android application.
Android Deep Explore (Volume one) HAL and Driver Development Chapter Nineth