This chapter mainly introduces the first Linux driver: Count the number of words. The Linux system maps each driver into a single file, which is called a device file or driver file, and is stored in the/dev directory. Most Linux drivers have their corresponding device files, so exchanging data with Linux drives becomes the exchange of data with files, that is, file operations.
Steps to write a Linux driver
First step: Build Linux driver skeleton (load and unload Linux drivers)
Step two: Register and unregister the device files
Step three: Specify driver-related information
Fourth step: Specify the callback function
Fifth step: Writing business logic
Sixth step: Writing the Makefile file
Seventh step: Compiling Linux drivers
Eighth Step: Install and uninstall Linux drivers
Install Linux drivers:
Insmod (driver name, typically a file with a. ko suffix)
To see if Word_count installed successfully:
Lsmod | grep word_count
(Unload L Inux Drive: Rmmod word_count, this step is uninstalled when you don't need it)
To view log information from Linux-driven output:
DMESG | grep Word_count | Tail–n
Compiling the driver into the Linux kernel for testing (using the Word_count driver example)
First step: Put the word_count.c file into the Linux kernel source code
Step Two: Modify the Kconfig file
Step three: Modify the Makefile file (follow the makefile edit rule)
Fourth step: Set the. config file (menu configuration)
Fifth step: Compile the Linux kernel (enter the directory with the makefile file, execute the Make command)
To add the Word_count directory to the Linux kernel source tree
First step: Create a new Kcinfig file (This step is the drag of the file)
Step Two: Modify the makefile file
Step three: Modify the Kconfig file of the upper directory
Fourth step: Modify the Makefile file of the upper directory
Android Deep Exploration-Volume 1 sixth chapter experience