Linux development module, the method of viewing debugging information on this machine has gone through. Current version 2.6.32-32-generic
Uname–r
can query
Take Module_param () as an example here.
the macro is defined in the Include/linux/moduleparam.h file and is defined as follows:
#define MODULE_PARAM (name, type, perm)
Module_param_named (name, name, type, perm)
3 parameters are used: The parameter variable name to pass, the data type of the variable, and the permission to access the parameter.
hello.c
#include <linux/init.h> #include <linux/module.h> #include <linux/moduleparam.h>module_license (" Dual BSD/GPL "); static char *flag=" world "; static int times = 5;module_param (TIMES,INT,S_IRUSR), Module_param (FLAG,CHARP,S_IRUSR), static int hello_init (void) { int I;for (i=0;i<=times;i++) {PRINTK ("(%d) Hello,%s\n", I,flag); Kern_debug}return 0;} static void Hello_exit (void) {PRINTK ("goodbye,%s\n", Flag),//kern_debug}module_init (Hello_init); Module_exit (Hello_ Exit);
This file needs to be compiled into a module, using
Makefile
obj-m:= Hello.okerneldir: =/lib/modules/$ (Shell uname-r)/buildpwd : = $ (shell pwd) default:$ (make)-C $ (Kerneldir) m =$ (PWD) MODULESCLEAN:RM-RF *.o *~ core depend. *.cmd *.ko *.mod.c. tmp_versions
$ (make)-C $ (Kerneldir) m=$ (PWD) modules
1),-C $ (Kerneldir)
Represents the Execute make command in the $ (kerneldir) directory.
2), m=$ (PWD)
Represents a makefile file that contains $ (PWD).
3), modules
Represents a module compilation
In the terminal
Make
Generating the Hello.ko module
Insmod Hello.ko flag= "Daniu" times=5
[Email protected]:/mnt/hgfs/test_curl/core# dmesg-c
[9057.070444] Goodbye,\xffffffe2\xffffff80\xffffff9d\xffffff80\xffffff9ddaniu\xffffffe2\xffffff80\xffffff9d\ xffffff80\xffffff9d
[9059.357777] (0) Hello, daniu
[9059.357781] (1) Hello, daniu
[9059.357783] (2) Hello, Daniu
[9059.357784] (3) Hello, Daniu
[9059.357785] (4) Hello, Daniu
[9059.357786] (5) Hello, Daniu
Rmmod Hello.ko
HELLO.C Kernel module Compilation--Linux kernel