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.