fuyunwuhen 发表于 2006-10-18 15:37:42

模块的问题

在看linux设备驱动程序上的例子,大家看一下什么问题
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.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);
上面是hello.c程序
下面是Makefile
obj-m := hello.o
KERNELDIR = /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
        rm -f hello.ko hello.mod.c hello.mod.o hello.o
编译通过了
make -C /lib/modules/2.6.9-22.EL/build M=/home/lynn/module modules
make: Entering directory `/usr/src/kernels/2.6.9-22.EL-i686'
Building modules, stage 2.
MODPOST
make: Leaving directory `/usr/src/kernels/2.6.9-22.EL-i686'

可是在:insmod ./hello.ko后没有输出:hello,world
又看书上说在/var/log/message里可能有,我看了也没有

Oct 15 15:02:32 srr00968 syslogd 1.4.1: restart.
Oct 15 15:02:32 srr00968 syslog: syslogd 启动 succeeded
Oct 15 15:02:32 srr00968 kernel: klogd 1.4.1, log source = /proc/kmsg started.
Oct 15 15:02:32 srr00968 kernel: Linux version 2.6.9-22.EL ([email protected]) (gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)) #1 Mon Sep 19 18:20:28 EDT 2005
....................

为什么没有输出啊?请大家帮忙分析一下了

fuyunwuhen 发表于 2006-10-18 15:41:33

make后 的内容应该是下面这样的,上面的是我没有make clean,
make -C /lib/modules/2.6.9-22.EL/build M=/home/lynn/module modules
make: Entering directory `/usr/src/kernels/2.6.9-22.EL-i686'
CC /home/lynn/module/hello.o
Building modules, stage 2.
MODPOST
CC      /home/lynn/module/hello.mod.o
LD /home/lynn/module/hello.ko
make: Leaving directory `/usr/src/kernels/2.6.9-22.EL-i686'

fuyunwuhen 发表于 2006-10-18 15:48:07

Module                  SizeUsed by
hello                   15360
parport_pc             245771
lp                     120770
parport                371292 parport_pc,lp
autofs4                232370
i2c_dev                113290
i2c_core               220811 i2c_dev


lsmod后看到hello模快

xiangleijh 发表于 2006-10-27 09:48:47

HELLO WORLD 模块显示

按ctrl+alt+F1切换到控制台下,然后再插入模块,就可以看到有显示

fuyunwuhen 发表于 2006-10-28 15:27:29

谢谢
页: [1]
查看完整版本: 模块的问题