1. Each hardware abstraction Layer module corresponds to a driver in the kernel, and the Hardware Abstraction Layer module then accesses the hardware device through these drivers, which communicate by reading and writing device files.
The module interface source files in the hardware abstraction layer are generally saved in the Hardware/libhardware directory, for convenience, we define the module name of the virtual hardware device Freg in the hardware abstraction layer as Freg, and the directory structure is as follows:
Hardware/libhardware/include/hardware/freg.h
Hardware/libhardware/modules/freg/android.mk
Hardware/libhardware/modules/freg/freg.cpp
The above three files correspond to the module's header file, makefile file, and source file respectively.
Steps for compiling 2.HAL layers
The first thing to do is modify the Android.mk file below Hardware/libhardware/modules, as follows:
Hardware_modules:=Gralloc Hwcomposer Audio NFC NFC-NCI local_time \ Power usbaudio audio_remote_submix camera consumerir sensors Vibrator \ tv_ Input fingerprint Freginclude $(call all -named-subdir-makefiles, $(hardware_modules))
Modify point: Add Freg to the Hardware_modules variable
Compilation: MMM./hardware/libhardware/modules
Result: A dynamic library of the HAL layer is generated, such as freg.default.so
3. View Freg.default.so
Use the Linux NM tool to view the symbol table for the dynamic library, we view OUT/TARGET/PRODUCT/XXXX/SYMBOLS/SYSTEM/LIB/HW
Directory below the freg.default.so dynamic library file, the command is as follows:
nm freg.default.so
Output:
00000549 T _zl12freg_get_valp13freg_device_tpi0000059d< Span class= "PLN" > T _zl12freg_set_valp13freg_ Device_ti000004b9 T _zl16freg_device_openpk11hw_module_tpkcpp11hw_device_t 000004ad T _ Zl17freg_device_closep11hw_device_t00002084 D _zl19freg_module_methods
We can see that a function with HAL layer is actually programmed.
4. Loading the hardware Abstraction Layer module
Above we generate a hardware abstraction layer corresponding to the. So file, then how to load. So? The hardware abstraction layer in the Android system is loaded by the system uniformly, and when the caller needs to load these modules, as long as the ID is specified, in the Android hardware abstraction layer, the function that is responsible for loading the hardware abstraction layer is the Hw_get_module function, the prototype is as follows:
int hw_get_module(const char *id, const struct hw_module_t **module);
For example, we pass in the parameter freg_hardware_module_id, i.e. "Freg", find the corresponding. So file inside the function, and then finally call load load.
Adding HAL modules to Android (GO)