Android system porting and Platform Development (vii)-Initial knowledge HAL

Source: Internet
Author: User

1. Hal's module and stub

HAL (Hardware abstractlayer) Hardware abstraction layer is a Google-developed Android system in the upper layer of the application of the underlying hardware to shield a software level, plainly, is that the upper layer of the application does not care about how the underlying hardware specifically how to work, As long as a unified interface is provided to the upper layer, this design idea is widely present in the current software architecture design.

Strictly speaking, the Android system can not be completely without the HAL hardware abstraction layer, the upper layer of application can be called through the API to the underlying hardware, but android from the beginning has been playing the banner of Open source, and some hardware manufacturers because of commercial factors, do not want their core code open source, And just provide binary code. In addition, some of the hardware device interfaces used in the Android system may not be used as a unified interface for Linux kernel, and there are GPL copyright reasons, so Google is not self-interested, in the Android architecture, the concept of HAL is proposed, This HAL is actually hardware independent meaning, the Android system does not rely on a specific hardware driver, but relies on the HAL code, so that third-party vendors can be their own non-open source code in the HAL layer, only provide binary.

The HAL architecture is divided into two types:

Ø Old Architecture Module

Ø New Architecture Modulestub

1.1 Module Architecture

The old architecture is better understood, the Android user application or the framework layer code is implemented by Java, Java runs in the Dalvik virtual machine, there is no way to directly access the underlying hardware, only by invoking so local library code implementation, in so local library code has the underlying hardware operation code, as shown in:

That is, the application layer or the framework layer Java code, through the JNI technology call C or C + + written so library code, in so library code calls the underlying driver, implementation of the upper application of the proposed hardware request operation. The so library that implements hardware operations is: module.

The implementation process is as follows:

Thus, Java code to access hardware efficiency is actually very low, no C code efficiency is high, but the Android system in the software framework and hardware processors are in the reduction and C code execution efficiency gap, according to the results of foreign testing, basically can achieve C code efficiency of about 95%.

Although this design architecture satisfies the need of Java application to access hardware, however, the coupling between the upper and lower levels of our code is too high, the user program or framework code must be loaded module library, if the underlying hardware changes, moudle to recompile, the upper layer to do the corresponding changes, in addition, If more than one application accesses the hardware at the same time, it loads the module, and the same module is mapped multiple times by more than one process, and there is a problem with code re-entry. As a result, Google proposes a new HAL architecture.

1.2 New HAL Schema

The new schema uses the module stub method. Stub is the meaning of a stub or pile, in fact, the meaning of an object represents. From the above schema, the upper application layer or the framework layer code load so library code, so library code we called module, in the HAL layer registers each hardware object stub stub, when the upper layer needs to access the hardware, from the current registered hardware object stub lookup, When the stub is found, the operations Interface (operator interface) of the hardware object is provided to the upper module, which is stored in the module and the upper application or framework accesses the hardware through the module operator interface. For example, in the case of LEDs:

Led app for Android app, the LED app Java code can not operate the hardware, the hardware operation to the local module library led_runtime.so, it from the current system to find the LED Stub, found after the LED When the stub returns a hardware-driven operation to the Module,led app operating hardware, it accesses the underlying hardware indirectly through the operator interface saved in the module.

Here's the problem:

O Trouble, feel more complicated than module mode

Ø How do hardware objects register as stubs?

Ø How to find the stub of hardware object in upper layer?

"Trouble" is certain, but Google's smart company is unlikely to be a hassle-making company, and it must be a way of thinking about other advantages.

1.3Module architecture vs. stub architecture

In the module schema, the local code is implemented by the so library, and the top layer directly maps the so library into the process space, with the problem of code re-entry and multiple device opening. Although the new stub framework also loads the module library, the module does not include the ability to operate the underlying hardware driver, it only holds the operating interface provided by the underlying stub, and the underlying stub acts as the "interface provider," which is loaded into memory when the stub is first used. Subsequent reuse only returns the hardware object operation interface, there is no device multiple open problem, and because the multi-process access is only the function pointer returned, the code does not re-enter the problem.

Android system porting and Platform Development (vii)-Initial knowledge HAL

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.