设为首页 加入收藏

TOP

在Ubuntu 11.04下编写驱动程序
2014-11-24 11:07:46 来源: 作者: 【 】 浏览:0
Tags:Ubuntu 11.04 编写 驱动程序

___________________________________________________________________


hello.c


#include "linux/init.h"
#include "linux/module.h"


static int hello_init(void)
{
printk(KERN_INFO "Hello World linux_driver_module\n");
return 0;
}


static void hello_exit(void)
{
printk(KERN_INFO "Goodbey linux_driver_module\n");
}


module_init(hello_init);
module_exit(hello_exit);



_____________________________________________________________________________________


Makefile:


#Makefile 2.6
ifneq ($(KERNELRELEASE),)
#kbuild syntax dependency relationship of files and target modules are listed here.
mymodule-objs:=hello.o
obj-m:=hello.o
else
PWD:=$(shell pwd)
KVER =$(shell uname -r)
KDIR:=/lib/modules/$(KVER)/build
all:



$(MAKE) -C $(KDIR) M=$(PWD)


clean:



rm -rf .*.com *.o *.mod.c *.ko .tmp_versions


endif



_______________________________________________________________


步骤:


1.sudo make all;


2.生成hello.ko文件


3.insmod hello.ko


4.lsmod,可以看到hello模块


5.rmmod hello.ko


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android软件开发之获取通讯录联系.. 下一篇Linux下OpenSSL-1.0.0 c编写OpenS..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·定义一个类模板并实 (2025-12-27 06:52:28)
·一文搞懂怎么用C语言 (2025-12-27 06:52:25)
·常用C模板范文_百度 (2025-12-27 06:52:21)
·【C语言】动态内存管 (2025-12-27 06:23:20)
·C语言中的内存管理 - (2025-12-27 06:23:16)