Android Deep explore HAL and Driver Development-—— 9th Chapter

Source: Internet
Author: User

This chapter mainly studies the hardware abstraction layer: HAL.

The hardware abstraction layer of Android, simply, is the encapsulation of the Linux kernel driver, providing an interface upward, shielding the implementation details of the lower level. That is, the support for the hardware is divided into two layers, one layer in user space, one layer in the kernel space (Kernel spaces), where the hardware abstraction layer runs in user space, and the Linux kernel driver runs in kernel space. Why do we have to do this? Is it not OK to combine the hardware abstraction layer with the kernel driver and put it in the kernel space? From a technical implementation point of view, it is possible, but from a commercial point of view, the hardware support logic is placed in the kernel space, may harm the interests of manufacturers. We know that the Linux kernel source code copyright complies with the GNU License, while the Android source code copyright complies with Apache License, the former must publish the source code when publishing the product, while the latter does not need to publish the source code. If the hardware support for all the code is placed on the Linux driver, it means that the release of the source code to expose the driver, and open source code means that the hardware parameters and implementation are open, in the mobile phone market competition today, which for manufacturers, the damage is very large. Therefore, Android will think of hardware support into the hardware abstraction layer and the kernel driver layer, the kernel driver layer only provides simple access to hardware logic, such as read and write hardware registers of the channel, as to what value from the hardware or write what value to the hardware logic, are placed in the hardware abstraction layer, This will hide the business secrets. It is also because of this layering that Android is kicked out of the Linux kernel mainline code tree. As you can imagine, the hardware support for Android's driver in kernel space is incomplete, and when the Linux kernel is ported to another machine, the hardware is completely useless due to lack of support from the hardware abstraction layer, which is why Android is an open system rather than an open source system.

The general steps for writing a Linux driver that supports HAL are: The first step: writing Linux drivers, and when adding HAL for Linux drivers to protect sensitive data, the Linux code needs to be concise to put the business logic into the HAL Library. Step two: Write the HAL Library, which is the normal Linux library file, and the Service Library locates the HAL by the ID defined in the interface. Step three: Write the service Library. ServiceManager calls the service library,apk program to call the Servicemanger class to access the service Library. Each part of the program should be tested in the process of writing Linux drivers and driver-related programs.
Writing HAL module steps and principles: First step: Define struct and macro, step two: Write Hal module Open function, step three: Define hw_module_methods_t struct variable, fourth step: Define HAL_MODULE_INFO_SYM variable, Fifth step: Write the HAL module close function, step sixth: write the control led function.

Android Deep explore HAL and Driver Development-—— 9th Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.