按照《linux设备驱动开发详解》一书中的步骤实现经典例子"hello,world!"的例子。具体步骤如下: 1.编写代码: /* * hello.c -- the example of printf "hello world!" in the screen of driver program */ #include #include
MODULE_LICENSE("Dual BSD/GPL");/* declare the license of the module ,it is necessary */
static int hello_init(void) { printk(KERN_ALERT "Hello World enter!\n"); return 0; }
static int hello_exit(void) { printk(KERN_ALERT "Hello world exit!\n"); }
module_init(hello_init); /* load the module */ module_exit(hello_exit); /* unload the module */
/* before is some decription of the model,not necessary */ MODULE_AUTHOR("YJ Hou"); MODULE_DESCRIPTION("This is an example of programming driver!"); MODULE_ALIAS(a simplest module);