Code
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL"); static char *book_name = "dissecting Linux Device Driver"; static int num = 4000; static int param[8] = {1, 2, 3, 4, 5, 6, 7, 8}; static int param_len = 8; static int book_init(void) {
int i;
printk(KERN_ALERT " book name: %s\n", book_name);
printk(KERN_ALERT " book num: %d\n", num);
for(i = 0; i < 8; i++)
{
printk(KERN_ALERT "param[%d] = %d \n", i, param[i]);
}
return 0; }
static void book_exit(void) {
printk(KERN_ALERT " Book module exit\n"); }
module_init(book_init);
module_exit(book_exit);
module_param(num, int, S_IRUGO);
module_param(book_name, charp, S_IRUGO);
module_param_array(param, int, ¶m_len, S_IRUGO);
MODULE_AUTHOR("Jimmy, fightingjimmy@gmail.com");
MODULE_DESCRIPTION("A simple Module for testing module params");
MODULE_VERSION("v1.0");
Compile
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
|
V
make -C /lib/modules/3.8.0-33-generic/build M=`pwd` test.ko
insmod
sudo insmod test.ko book_name='GoodBook' num=5000
Result
Jul 3 07:48:16 happy-Desktop kernel: [10874.385886] book num: 5000
Jul 3 07:48:16 happy-Desktop kernel: [10874.385891] param[0] = 1 Jul 3 07:48:16 happy-Desktop kernel: [10874.385897] param[1] = 2 Jul 3 07:48:16 happy-Desktop kernel: [10874.385901] param[2] = 3 Jul 3 07:48:16 happy-Desktop kernel: [10874.385933] param[3] = 4 Jul 3 07:48:16 happy-Desktop kernel: [10874.385938] param[4] = 5 Jul 3 07:48:16 happy-Desktop kernel: [10874.385943] param[5] = 6 Jul 3 07:48:16 happy-Desktop kernel: [10874.385947] param[6] = 7 Jul 3 07:48:16 happy-Desktop kernel: [10874.385951] param[7] = 8
Reference
- linux 模块层叠技术和多个ko的编译
0 意見:
張貼留言