1. The overall structure of the Linux kernel is very large and contains many components, using these components in two ways:
① directly into the kernel file, either Zimage or bzimage (problem: excessive memory consumption)
② Dynamic Additions
* The module itself is not compiled into the kernel file
* Dynamically install or uninstall during kernel runtime, as required
2. Dynamic installation and uninstallation of kernel modules
① installation Insmod
Example: Insmod/home/dnw_usb.ko
② Uninstalling Rmmod
Example: Rmmod dnw_usb
③ View Lsmod
Example: Lsmod
3. Module declaration
①module_license ()
②module_author ()
③module_description ()
④module_version ()
4. Module parameters
The ① module parameter is used to pass parameters to the module when the module is loaded
② specifying variables to save module parameters via macro Module_param
Module_param (name, type, perm)
* Name: Names of variables
* Type: Variable type. BOOL: boolean, int: integer, Charp: String
* Perm is access rights. S_irugo: Read permission, s_iwusr: Write permission
③ Simple Example
int 3 int, sirugo);
Command line: insmod Xxx.ko a = 10
5. Symbol Export
① if a function or global variable in a kernel module wants to be used by another module, it must be exported
② kernel symbol export using macros
Export_symbol (symbol name)
EXPORT_SYMBOL_GPL (symbol name)
Note: Where EXPORT_SYMBOL_GPL can only be used for modules that contain GPL licenses
6. Kernel Module Simple Example
① Module Code:
#include <linux/init.h><linux/module.h>staticint hello_init () { PRINTK (kern_warning"Hello World initlizing\n"); return 0 ; } Static void Hello_exit () { printk (kern_warning"Hello World exiting\n"); } Module_init (Hello_init); Module_exit (hello_exit);
②makefile:
Obj-m: = helloworld.okdir:=/home/linux/kernal/linux-2.6. in All : -C $ (Kdir) m=$ (PWD) modules cross_compile=arm-linux-arch=arm clean : -F *.o *.ko *.order *. symvers
A simple example of a Linux kernel module