Kernel moduleCodeFile
File YYYY. C (yyyy can have the same name or different name as module XXXX)
(Something similar to a template)
# Ifndef _ KERNEL __
# DEFINE _ KERNEL __
# Endif
# Ifndef module // removed when added directly to the kernel. It is retained when the module is generated.
# Define Module
# Endif
# Include <*. h>
...
Module_license ("GPL"); // license declaration, used to inform the kernel that this module has a license
Module_author ("You name"); // the author's statement (optional)
Module_description ("aaaa"); // module description (optional)
Module_version ("V1.0"); // module version (optional)
Module_alias ("a bbbb module"); // module alias (optional)
Static int _ Inti xxxx_init (void)
{
}
Static void _ Inti xxxx_exit (void)
{
}
... // Other functions
...
Module_init (xxxx_init );
Module_exit (xxxx_exit );
Kernel-compiled makefile
Makefile
(Something similar to a template)
Ifneq ($ (kernelrelease ),)
OBJ-M: = XXXX. o
XXXX-objs: = YYYY. O (if there are other source files to continue adding zzzz. O...) (for example, if yyyy = XXXX and there is only one source file, this row can be removed)
Else
Kdir: =/lib/module/2.6.28.6/build
ALL:
Make-C $ (kdir) M = $ (PWD) Modules
Clean:
Rm-f *. Ko *. O *. Mod. O *. Mod. C *. symvers
Endif
Here,/lib/module/2.6.28.6/build is the directory generated by the kernel code tree, and the number of kernel codes is created:
Http://blog.csdn.net/leaglave_jyan/article/details/6652444
After editing the source file and makefile, run make in the directory to compile and generate the XXXX. Ko file of the module.
Use insmod XXXX. Ko to add