Linux驱动:动态加载hello world模块

Linux驱动:动态加载hello world模块


本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.


环境:

主机:Ubuntu 10.04


说明:

开始做android驱动开发,所以重新温习linux下驱动编写


注意:

1.Makefile不能写成makefile

2.加载模块命令insmod ./hello.ko,卸载模块命令rmmod hello

3.insmod和rmmod需要管理员权限,如非root账户,在命令前输入sudo

4.printk输出在/var/log/messages中,用dmesg | tail -10命令输出最后10条记录


源码:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include <linux/init.h>  
  2. #include <linux/module.h>  
  3. MODULE_LICENSE("Dual BSD/GPL");  
  4.   
  5. static int hello_init(void)  
  6. {  
  7.     printk(KERN_ALERT "Hello,jdh\n");  
  8.     return 0;  
  9. }  
  10.   
  11. static void hello_exit(void)  
  12. {  
  13.     printk(KERN_ALERT "Goodbye,jdh\n");  
  14. }  
  15.   
  16. module_init(hello_init);  
  17. module_exit(hello_exit);  


Makefile:

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ifneq ($(KERNELRELEASE),)  
  2.     obj-m := hello.o  
  3. else  
  4.     KERNELDIR ?= /lib/modules/$(shell uname -r)/build  
  5.     PWD := $(shell pwd)  
  6. default:  
  7.     $(MAKE) -C $(KERNELDIR) M=$(PWD) modules  
  8.   
  9. endif  


参考:

1.《LINUX设备驱动程序》第三版

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值