Android system transplantation and driver development-Chapter 6-use instances to understand Linux driver development and experiences, and android driver development

Source: Internet
Author: User

Android system transplantation and driver development-Chapter 6-use instances to understand Linux driver development and experiences, and android driver development

The operating method of the Linux driver is interaction. For example, if you want to send a print command to the Linux printer driver, you can directly use the C language function open to open the device file, and then use the C language function ioctl to send a print command to the driver's device file. The most important thing to write a Linux driver is to write a callback function. Otherwise, the data that interacts with the device file cannot be processed.

Two functions are used to create the Linux driver SKELETON: module_init and module_exit. Macro definition is required.

Use misc_register and misc_deregister to create and remove device files.

A callback function is generated by itself. A driver does not have to specify all callback functions.

The specific business logic is related to the driver function. It may consist of multiple functions, multiple files, or even multiple Linux driver modules.

The program can be directly compiled into the kernel or used separately as a module.

Printk is used for output, so you may wonder why you don't need printf, because in Linux, it is divided into user space and kernel space, while printf can only run in user space. In addition, the device files used for interaction between them.

To understand the source file, GPL protocol, LGPL protocol, BSD Protocol, MIT protocol, and Apache License2.0 protocol.

When writing and destroying a device file, note that misc_register can only set this device number.

You can use cat/proc/devices to obtain the information about the main Device and Its ID in the current system.

You can use the file_operation.read and file_operation.write member variables to specify the pointers of the callback functions to be called by the read/write device.

After the driver program is compiled, the driver is compiled multiple times. The drivers in the read/write directory are the same as those in build. sh and related script files.

The Cat command does not restore four bytes to int type values.

By default, the goldfish kernel for Android simulators does not allow dynamic loading of Linux driver modules. Therefore, cd ~ /Kernel/goldfish, make menuconfig. Select the correct sub-menu in the Configuration box. Otherwise, the kernel may fail to be loaded.

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.