Linux kernel module learning notes ########## Makefile ########## obj-m: modname. o modname will be generated after compilation. ko must have modname in the current directory. [c/s/S] the Object obj-m value *. o *. ko ++...
Linux kernel module learning notes ########## Makefile ########## obj-m: = modname. o modname will be generated after compilation. ko must have modname in the current directory. [c/s/S] the Object obj-m value *. o *. ko ++ multiple files: obj-m: = modname. omodname-objs: = 1.o 2.o... compiled modname. o by modname-objs *. o generate *** will not compile the modname in the current directory. [c/s/S] file ########## module command ######### insmod modname. ko or modprobe modname to use the modprobe command to install the module to the file system lsmod [modname] or cat/proc/modulesrmmod module_name or modprobe-r modnamemodinfo modname. ko ########## basic module structure ########## include Include Static int _ init test_init (void) {printk ("hello test init !!! \ N "); return 0;} static void _ exit test_exit (void) {printk (" hello test exit !!! \ N ");} module_init (test_init); module_exit (test_exit); MODULE_LICENSE (" GPL "); MODULE_AUTHOR ("... "); MODULE_DESCRIPTION ("... "); www.2cto.com ########## module parameters ########## type var_name; module_param (var_name, type, perm ); insmod modname. ko var_name = value ++ ++ int num = SIZE; type var_name [SIZE]; module_param_array (var_name, type, & num, perm); insmod modname. ko var_name = val0, val1, val2 ,..., valSIZE ++ ++ var_name: variable (must be global) type: byte short ushort int uint long ulong charp bool invboolperm: Specify/sys/module/$ (modname)/parameters/$ (param_name) file permissions (the content of this file is the value of var_name) ---> kernel/include/linux/stat. h: 50 0 ---> (no corresponding file exists) S_IRWXUGO S_IALLUGO S_IRUGO S_IWUGO S_IXUGO & num: parameter length pointer (must be global) www.2cto.com ########## symbol export ######### EXPORT_SYMBOL (symbol_name ); kernel ----> kernel or module A ----> module A does not need to export the symbol module ----> kernel or module A ----> module B can only use the exported symbol kernel ----> module no matter the module symbol cannot be used for export or not ######### printk ########## level: include/linux/printk. h: 9cat/proc/sys/kernel/printkecho a [B]>/proc/sys/kernel/printk a: messages with a lower level than a will be printed to console B: default level
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.