Linux drivers: Count the number of words
I. Steps to write a Linux driver
1. Build Linux driver skeleton (load and unload Linux drivers)
The Linux driver needs to provide two functions to handle the work of driving initialization and exit separately, specified with Module_init and module_exit macros.
The driver's header file typically includes linux/module.h,linux/init.h,linux/kernel.h,linux/fs.h,linux/miscdevice.h and asm/uaccess.h.
The difference between printf and PRINTK: printf runs in user space, PRINTK runs in kernel space
2. Registration and destruction of equipment files
Use Misc_register to create device files and use Misc_deregister to remove device files.
3. Specify driver-related information
The driver is self-describing and needs to be specified in the driver source code.
Module_author Specify author name
Module_license Specify the open source protocol used
Module_alias specifying the driver alias
Module_description description of the specified driver
View. ko file information: modinfo. ko file
4. Specifying a callback function
A driver does not necessarily specify all of the callback functions, and the callback function is registered by the relevant mechanism.
5. Writing business logic
Business logic may consist of multiple functions, multiple files, or even multiple Linux driver modules
6. Writing the makefile file
7. Install and uninstall Linux drivers
Linux drivers exist as modules, need to load Linux driver modules with Insmod or modprobe commands, uninstall Linux drivers using the Rmmod command
Install driver: insmod. ko file
Unload driver: Rmmod module name
View log information for driver output: DMESG | grep Module Name | Tail-n 2
Two. Open Source Agreement
1.GPL Protocol 2.LGPL Protocol 3.BSD protocol 4.Apache Licence2.0 Protocol 5.MIT Protocol
Android Deep Explore sixth chapter