One, kernel module function: Let the kernel file (zimage or bzimage) does not contain a component itself, but in the
When components need to be used, they are dynamically added to the running kernel
Second, kernel module installation and uninstallation
Loading: Insmod (Insmod Hello.ko)
Uninstall: rmmod (rmmod Hello)
View: Lsmod
Loading: modprobe (modprobe Hello)
Modprobe, like Insmod, also loads a module into the kernel. It differs in that it is based on the file
/lib/modules/< $version >/MODULES.DEP
To view the module to be loaded and see if it also relies on other modules, if so, Modprobe will first find
These modules, load them into the kernel first.
Third, module optional information:
1. License Statement
The macro module_license is used to inform the kernel that the module has a license, without such a description, the loading mode
Block when the kernel will complain. Valid licenses are "GPL", "GPL v2", "GPL and
Additionalrights "," Dual BSD/GPL "," Dual MPL/GPL "and" proprietary ".
2. The author affirms (optional)
Module_author ("Simon Li");
3. Module description (optional)
Module_description ("Hello World Module");
4. Module version (optional)
Module_version ("V1.0");
5. Module alias (optional)
Module_alias ("A simple module");
6. Module parameters
The module parameters are specified by the macro Module_param, which is used to pass parameters to the module when the module is loaded.
Module_param (Name,type,perm)
Name is the type of the parameter for the module, and Perm is the access to the module parameter.
Permissions.
Type common values:
BOOL: Boolean int: Integral type charp: String type
Perm Common values:
S_irugo: Any user has read access to the parameter that appears in/sys/module
S_IWUSR: Allows the root user to modify the parameter that appears in/sys/module
/**************param**************************/
#include <linux/init.h>
#include <linux/module.h>
Module_license ("GPL");
static char *name = "Daniel Guo";
static int age = 30;
Module_param (age, int, s_irugo);
Module_param (name, Charp, S_irugo);
static int __init Hello_init ()
{
PRINTK (Kern_emerg "name:%s\n", Name);
PRINTK (Kern_emerg "age:%d\n", age);
return 0;
}
static void __exit Hello_exit ()
{
PRINTK (kern_info "Module exit\n");
}
Module_init (Hello_init);
Module_exit (Hello_exit);
/***************************************************/
Command:
Make
Insmod Param.ko
Rmmod param
Insmod Param.ko age=12
/****************************************************/
Quad, kernel symbol export
/proc/kallsyms records the names and addresses of all exported symbols in the kernel.
Export_symbol (func); /*func is the function name for use by other modules */
Export of kernel symbols using:
Export_symbol (symbol name)
EXPORT_SYMBOL_GPL (symbol name)
Where EXPORT_SYMBOL_GPL can only be used for modules that contain GPL licenses.
Http://www.cnblogs.com/FORFISH/p/5188421.html
Linux kernel module Development