linux 驱动初接触

Posted on 2013-04-02 15:36 墨…… 阅读(861) 评论(0)  编辑 收藏 引用
编译 scull

   出现以下错误
 Fix it to use ccflags-y.  Stop.
   将 Makefile 中的 CFLAGS 改为 ccflags-y, 重新 make,又出现错误
main.c:15:26: fatal error: linux/config.h: No such file or directory
   将 main.c 中的 #include <linux/config.h> 删除或注释掉,重新 make,继续编译会遇到如下问题
main.c:634:2: error: unknown field 'ioctl' specified in initializer
   是因为内核中的 file_operations 结构发生了改变,将 main.c 中 scull_fops 声明处的 .ioctl 改为 .unlocked_ioctl  即可,继续编译还会遇到如下问题
main.c:652:3: error: implicit declaration of function ‘init_MUTEX’ [-Werror=implicit-function-declaration]
   可在 main.c 的开始处添加以下代码解决问题
#include <linux/semaphore.h>
#define init_MUTEX(a) sema_init(a,1)
#define init_MUTEX_LOCKED(a) sema_init(a,0)
   到这时还没完,我开始有点烦燥了...继续前进时还出现以下错误
pipe.c: In function ‘scull_p_read’:
pipe.c:131:7: error: ‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
pipe.c:131:7: note: each undeclared identifier is reported only once for each function it appears in
pipe.c:131:3: error: implicit declaration of function ‘signal_pending’ [-Werror=implicit-function-declaration]
pipe.c:131:3: error: implicit declaration of function ‘schedule’ [-Werror=implicit-function-declaration]
   该问题可向 pipe.c 和 access.c 中添加 #include <linux/sched.h> 来解决,但后面还会遇到这样的问题
access.c:101:34: error: ‘SPIN_LOCK_UNLOCKED’ undeclared here (not in a function)
   在access.c文件中用 static DEFINE_SPINLOCK(scull_w_lock);  来代替 static spinlock_t scull_w_lock = SPIN_LOCK_UNLOCKED;
   继续进行,遭遇下面问题
access.c:111:29: error: ‘struct task_struct’ has no member named ‘uid’
access.c:112:29: error: ‘struct task_struct’ has no member named ‘euid’
access.c:119:26: error: ‘struct task_struct’ has no member named ‘uid’
   把 access.c 文件中的 
current->uid 
current->euid
   全部修对应地改为
current->cred->uid
current->cred->euid
   继续重新 make,终于可以生成 scull.ko 了,OMG......

   还要注意的是,上面的错误可能不止发生在一个地方,编译时需要注意看清错误提示,如果有跟上面一样的错误发生,只需参照上面的方法来修改即可。
   驱动不会在虚拟终端上输出,所以如果在终端上没看到驱动的输出,可以看看是不是输出到日志中了:
/var/log/syslog


Contact us

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


posts - 8, comments - 0, trackbacks - 0, articles - 0

Copyright © 墨……