I. Manual Loading Test
1. insmod./key_test.ko load the driver module to the kernel.
2. Run cat/proc/modules | grep key_test to check the address of the key_test module in the kernel. If no filter is added, all loaded modules are displayed.
3. lsmod: display the module. The module names are displayed, followed by the main device number and secondary device number.
4. rmmod key_test uninstalls the module from the kernel.
Ii. Dynamic Loading
1. Put the key_test.c source code under/drives/char/of the kernel source code, because this is a compaction-type driver, which is compiled to zImage.
2. In this case, the key_test option is not displayed when we make menuconfig to compile the kernel. We can only write this option into the menu. There is a Kconfig file under/drives/char/in the kernel source code to open
(1) Add several lines to vi Kconfig:
Config ConFig_key_test
Bool "key test" // switch the previous bool to tristate to support modular compilation.
In the above sentence, the key test option will appear in make menuconfig under the drive/char sub-menu, and the TAB key is in front of bool.
------ Help ---------- this sentence appears under the menu options
This key test help. This is your driver description that will appear in help.
(2) Add the following sentence to the Makefile file in the/drivers/char directory:
Obj-$ (CONFIG_key_test) + = key_test.o
The above sentence is to compile key_test into the kernel during Make.
(3) make menuconfig select the key_test Option
(4) make zImage
Generate the zImage file and restart and load the new kernel.
3. lsmod will be able to see key_test, but it is not available yet. There is no interface, that is, there is no
4. mknod/dev/key_test c 121 0. This is the master device number defined in the source code that can be called by the common program after the device is created under/dev, 0 indicates the next device number.
5. cat/dev/key_test is equivalent to the open device, or write a program to directly call functions such as open and write.
Fd = ("/dev/key_test", ORW );