免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5895 | 回复: 3
打印 上一主题 下一主题

linux设备驱动程序的hello world例子 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-08-14 23:29 |只看该作者 |倒序浏览

------------------------------hello.c文件内容------------------------------------
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk(KERN_ALERT "hello, world\n");
        return 0;
}

static void hello_exit(void)
{
        printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);

---------------------------Makefile文件内容------------------------------------------
ifneq ($(KERNELRELEASE),)
        obj-m := hello.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif


[root@yang-centos hello]# make
make -C /lib/modules/2.6.32-358.14.1.el6.i686/build M=/root/exam_drive/hello modules
make[1]: Entering directory `/usr/src/kernels/2.6.32-358.14.1.el6.i686'
  CC [M]  /root/exam_drive/hello/hello.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /root/exam_drive/hello/hello.mod.o
LD [M]  /root/exam_drive/hello/hello.ko.unsigned
  NO SIGN [M] /root/exam_drive/hello/hello.ko

make[1]: Leaving directory `/usr/src/kernels/2.6.32-358.14.1.el6.i686'
[root@yang-centos hello]# ls
hello.c   hello.ko.unsigned  hello.mod.o  Makefile       Module.symvers
hello.ko  hello.mod.c        hello.o      modules.order
[root@yang-centos hello]# insmod ./hello.ko
[root@yang-centos hello]# rmmod hello
[root@yang-centos hello]#

make时上面红色的与书上的结果不一样,insmod也没有打印hello word,请问怎么回事?

论坛徽章:
0
2 [报告]
发表于 2013-08-15 10:58 |只看该作者
本帖最后由 wwxxxxll 于 2013-08-15 11:10 编辑

dmesg就有了
你的输出级别太低
printk(KERN_ALERT "hello, world\n");
改成
printk(KERN_ERR "hello, world\n");
就有了

有什么问题,可以加入我们群,问题会更快得到回复!
群号:163617970

论坛徽章:
0
3 [报告]
发表于 2013-08-25 16:07 |只看该作者
谢谢,呵呵

论坛徽章:
0
4 [报告]
发表于 2013-08-25 16:07 |只看该作者
谢谢,呵呵
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP