日期:2014-05-16  浏览次数:20734 次

Linux设备驱动程序3 的hello,world!
我用的是2.6.15的内核,并且在2.6.15的内核源码中编译的hello程序
使用insmod   ./hello.ko装载成功(lsmod可以看到生成了这个模块)
使用rmmod   hello也成功(同样用lsmod看到)

但是在装载和卸载的时候,在终端上没有任何输出??
请大侠指点一下??

真是举步唯艰啊~~~~~~~~~

------解决方案--------------------
ALT+F1 ~ ALT+F6 ,切换.

我这里有一个不用切换到文本模式也能打印消息的方法,像用printk一样使用logmsg就行了。

#include <linux/tty.h> /*for the tty declarations*/
#include <linux/version.h>
#include <linux/sched.h> /*for current macro*/
#include "logmsg.h "
MODULE_LICENSE( "GPL ");

static int print_string(char *str)
{
struct tty_struct *current_tty;

#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,5))
current_tty = current-> tty;
#else
current_tty = current-> signal-> tty;
#endif

if (NULL == current_tty)
{
return -1;
}
(current_tty-> driver)-> write(current_tty,
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,9))
0,
#endif
str,
strlen(str));

return 0;
}

int logmsg(char *fmt, ...)
{
int ret;
char msgbuf[1024];
va_list ap;
va_start(ap, fmt);
ret = vsprintf(msgbuf, fmt, ap);
print_string(msgbuf);
va_end(ap);

return ret;
}

EXPORT_SYMBOL(logmsg);