Android Deep Exploration (Vol. 1) HAL and Driver Development Sixth Chapter summary

Source: Internet
Author: User

Operating system through a variety of drivers rely on home and hardware devices, it has shielded a variety of devices for users, drive hardware is the most basic function of the operating system, and provide a unified operation. Device drivers are one of the most basic components of the operating system and are more than 60% in the Linux kernel source program, so familiarity with driver writing is important.

The Linux system maps each driver into a single file. These files are referred to as device files or driver files and are present in the/dev directory. Thus, in the application's view, the hardware device is just a device file, and the application can operate the hardware device as if it were a normal file, which greatly facilitates the processing of the device.

Steps to write a driver:

(1) Build Linux driver skeleton (load and unload Linux drivers) any type of program has a basic structure, and Linux drivers are no exception. The Linux kernel needs to load the driver first when it uses the driver. Some initialization work is also required during the loading process.

(2) Registration and cancellation of equipment files

Any Linux driver requires a device file, or the application will not be able to interact with the driver.

(3) Specify driver-related information

The driver is self-describing.

(4) Specifying a callback function

A driver does not necessarily specify all of the callback functions.

(5) Writing business logic

(6) Writing makefile files

(7) Writing Linux drivers

(8) Installing and uninstalling Linux drivers

1. Preparatory work

Create a directory to store Linux drivers

Create a drive source code file

Write a Makefile file

2. Writing the skeleton of the Linux driver (Initialize and exit drivers)

Installing Linux Drivers

See if Word_count is installed successfully

Uninstalling Linux Drivers

View log information from the driver output

3. Specify driver-related information

Module author, module description, module nickname, open Source protocol

4. Registering and unregistering device files

5. Specifying a callback function

6. Algorithm to achieve statistical word count

7. Compiling, installing, and uninstalling Linux drivers

Testing Linux Drivers

Using the Ubuntu Linux test

Test via OST (native) C program on Android simulator

Using the Android NDK test

Directly manipulate device file testing using Java code

Test with the s3c6410 Development Board

Compiling the driver into the Linux kernel for testing

Develop and test Linux drivers with eclipse

1. Building C Project

2. Establish C source code file connection

3. Setting the Include path

4. Compiling Linux Drivers

Testing Linux drivers in eclipse

1. Import the test_word_count.c file

2. Setting the Include path

3. Establish Targe

4.build Engineering

5. Run the test program

It is important to note that the user space and kernel space to complete the same or similar functions, macros and other resources names are not necessarily the same, some names like: malloc and Kmalloc, some different such as: Atoi and Simple_strol, etc. home.cnblogs.com/u/zivjeli/

Android Deep Exploration (Vol. 1) HAL and Driver Development Sixth Chapter summary

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.