【Android源码 栏目提醒】:网学会员,鉴于大家对Android源码 十分关注,论文会员在此为大家搜集整理了“android系统开发--HAL层开发基础 - 操作系统”一文,供大家参考学习!
android系统开发--HAL层开发基础 Android HAL层即硬件抽象层是Google响应厂家“希望不公开源码”的要求推出的新概念 1源代码和目标位置 源代码 /hardware/libhardware目录该目录的目录结构如下 /hardware/libhardware/hardware.c编译成libhardware.so目标位置为/system/lib目录 /hardware/libhardware/include/hardware目录下包含如下头文件 hardware.h 通用硬件模块头文件 copybit.h copybit模块头文件 gralloc.h gralloc模块头文件 lights.h 背光模块头文件 overlay.h overlay模块头文件 qemud.h qemud模块头文件 sensors.h 传感器模块头文件 /hardware/libhardware/modules目录下定义了很多硬件模块 这些硬件模块都编译成xxx.xxx.so目标位置为/system/lib/hw目录 2HAL层的实现方式 JNI-通用硬件模块-硬件模块-内核驱动接口 具体一点JNI-libhardware.so-xxx.xxx.so-kernel 具体来说android frameworks中JNI调用/hardware/libhardware/hardware.c中定义的hw_get_module函数来获取硬件模块 然后调用硬件模块中的方法硬件模块中的方法直接调用内核接口完成相关功能 3通用硬件模块libhardware.so 1头文件为/hardware/libhardware/include/hardware/hardware.h 头文件中主要定义了通用硬件模块结构体hw_module_t声明了JNI调用的接口函数hw_get_module hw_module_t定义如下 typedef struct hw_module_t / tag must be initialized to HARDWARE_MODULE_TAG / uint32_t tag / major version number for the module / uint16_t version_major / minor version number of the module / uint16_t version_minor / Identifier of module / const char id / Name of this module / const char name / Author/owner/implementor of the module / const char author / Modules methods / struct hw_module_methods_t methods //硬件模块的方法 / modules dso / void dso / padding to 128 bytes reserved for future use / uint32_t reserved32-7 hw_module_t 硬件模块方法结构体hw_module_methods_t定义如下 typedef struct hw_module_methods_t / Open a specific device / int openconst struct hw_module_t module const char id struct hw_device_t device hw_module_methods_t 只定义了一个open方法其中调用的设备结构体参数hw_device_t定义如下 typedef struct hw_device_t / tag must be initialized to HARDWARE_DEVICE_TAG / uint32_t tag / version number for hw_device_t / uint32_t version / reference to the module this device belongs to / struct hw_module_t module / padding reserved for future use / uint32_t reserved12 / Close this device / int closestruct hw_device_t device hw_device_t hw_get_module函数声明如下 int hw_get_moduleconst char id const struct hw_module_t module 参数id为模块标识定义在/hardware/libhardware/include/hardware目录下的硬件模块头文件中 参数module是硬件模块地址定义了/hardware/libhardware/include/hardware/hardware.h中 2hardware.c中主要是定义了hw_get_module函数如下 define HAL_LIBRARY_PATH /system/lib/hw static const char variant_keys ro.hardware ro.product.board ro.board.platform ro.arch static const int HAL_VARIANT_KEYS_COUNT sizeofvariant_keys/sizeofvariant_keys0 int hw_get_moduleconst char id const struct hw_module_t module int status int i const struct hw_module_t hmi NULL char propPATH_MAX char pathPATH_MAX for i0 i上一篇:Android网络程序设计