General steps for writing a Linux:
1th Step: Build Linux driver skeleton (load and unload Linux drivers)
2nd step: Registering and unregistering device files
3rd step: Specify and drive related information
4th step: Specify the callback function
5th step: Writing Business logic
6th step: Writing the Makefile file
7th step: Compiling Linux drivers
8th step: Install and uninstall Linux drivers
When writing a makefile file obj-m means compiling the Linux driver as a module (. ko file), and Obj-y is compiling the Linux driver into the Linux kernel; obj-m or obj-y need to use ": =" assignment. The Make Menuconfig command allows you to configure whether each driver and other kernel programs are allowed to be compiled into the kernel. Linux system memory is divided into user space and kernel space, these two space programs can not be directly accessed. The printf function runs in user space, and the PRINTK function runs in kernel space, so Linux drivers that belong to kernel programs do not have direct access to printf functions, while user-space programs
You cannot call the PRINTK function directly. If you compile the Linux driver using a modular approach, you need to
Use m to specify the directory where the driver is located. For example, the following command is used to view the log information exported by the Linux driver:
# DMESG | grep Word_count | Tail-n 2
Or
# Cat/var/log/syslog | grep Word_count | Tail-n 2
Using Modinfo to view information about a. ko file, the device file is described by the main device number and the secondary device number.
6th. First Linux driver: Count the number of words