嵌入式Linux简单字符设备驱动程序---helloworld

2019-07-13 00:19发布

/* **$ gcc -DMODULE -D__KERNEL__ -I /usr/src/linux-2.4.20/include -c hello.c **$ insmod hello.o 如果成功加载到内核将在终端上显示:Hello world, Linux Driver! **$ rmmod hello.o 卸载成功的话将终端显示: Goodbye, Linux Driver! */ #include #include /* Tell the kernel I can do what */ static int __init hello_init(void) { printk(KERN_ALERT"Hello world, Linux Driver! "); return 0; } /* Tell the kernel stop me doing */ static void __exit hello_exit(void) { printk(KERN_ALERT"Goodbye, Linux Driver! "); } module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("Dual BSD/GPL"); /* All modules need to define the LICENCE */