Article Title: How to dynamically add driver modules. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Note: The original test keyboard driver is used as the experiment material and must be dynamically loaded into the system through insmod. Think: to dynamically load, you must first put test in the file system. ko file ,. how to generate ko files when they are loaded by a dedicated module. what about ko files? The method is generated during compilation. Of course, you cannot compile the test file in the arm-linux-gcc-o test. ko test. c syntax. What should you do? The analysis is as follows:
1. set test. put the c file in the root directory of YLP2440 (the same kernel version as the kernel used in the board). YLP2440 is the file directory 2 in the PC after the kernel. modify the Makefile file in the root directory of YLP2440 and add the following code in the header:
Obj-m: = test. o
KERNELDIR: =/root/test/YLP2440
PWD: = $ (shell pwd)
Modules:
$ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules
Modules_install:
$ (MAKE)-C $ (KERNELDIR) M = $ (PWD) modules_install
3. make 4. generate test. ko file, and then put it in the file system, create a new cramfs file system, download to the Board 5. start the board, and then in test. input: insmod test. ko 6. complete
In the above code, I do not know why modules and modules_install should be named. Another code is written like this:
Obj-m: = test. o
KERNELDIR: =/root/test/YLP2440
PWD: = $ (shell pwd)
Default:
$ (MAKE)-C $ (KDIR) SUBDIRS = $ (PWD) modules
This statement does not prompt that the modulles is overwritten.