LDD3在Ubuntu下编译模块

由于实验室需要,要学习Linux下的驱动开发,正好自己也好好学习linux下的驱动开发,但是书本的代码编写碰到一个问题,就是在Ubuntu下不能编译,经过网上的搜索后,找到如下一篇博客,非常不错,如下: 编译LDD3-scull

1、提示scripts/Makefile.build:46:*** CFLAGS was changed in "/home/chenfang/scull/Makefile",Fix it use EXTRA_CFLAGS.Stop.:

由于LDD3使用的是2.6.10内核,很多东西已经发生了变化,这里提示我们修改Makefile中的CFLAGS,用EXTRA_CFLAGS代替,照它说的做就可以。

2、提示找不到文件linux/config.h: 在2.6.19开始的内核中删除了config.h文件,因此只要在mian.c中注释掉#include即可。

3、提示access.c中存在:dereferencing pointer to incomplete type 错误: 在 源码中发现只能是current存在错误,current应该是一个task_struct类型的全局变量,查找task_struct存在于 linux/sched.h中,因此在access.c中加入#include,重新make即可。

顺便看下current这个全局变量是在哪里定义的: 在source ininsight中查找得到的current类似于以下的定义: static inline struct task_struct *get_current(void) __attribute_const__; static inline struct task_struct *get_current(void) { return current_thread_info()->task; } #define current (get_current()) 可 见,current其实是一个“伪全局变量”,是函数get_current()的宏定义。

/home/dengwei/eclipse_workspace/scull/access.c:108: error: ‘struct task_struct’ has no member named ‘uid’

/home/dengwei/eclipse_workspace/scull/access.c:109: error: ‘struct task_struct’ has no member named ‘euid’

/home/dengwei/eclipse_workspace/scull/access.c:116: error: ‘struct task_struct’ has no member named ‘uid’ /home/dengwei/eclipse_workspace/scull/access.c: In function ‘scull_w_available’:

/home/dengwei/eclipse_workspace/scull/access.c:167: error: ‘struct task_struct’ has no member named ‘uid’

/home/dengwei/eclipse_workspace/scull/access.c:168: error: ‘struct task_struct’ has no member named ‘euid’

/home/dengwei/eclipse_workspace/scull/access.c: In function ‘scull_w_open’:

/home/dengwei/eclipse_workspace/scull/access.c:186: error: ‘struct task_struct’ has no member named ‘uid’ 原因: struct task_struct定义在include/linux/sched.h中,原来task_struct结构体定义有所改动,将uid和euid等挪到 cred中,见include/linux/sched.h和include/linux/cred.h。

解决方法: 只需要将报error的代码做如下修改 current->uid 修改为 current->cred->uid current->euid 修改为 current->cred->euid make success

结果: root@dw:/home/dengwei/eclipse_workspace/scull# ls access.c main.o Module.symvers scull.init scull.mod.o access.o Makefile pipe.c scull.ko scull.o _desktop.ini Module.markers pipe.o scull_load scull_unload main.c modules.order scull.h scull.mod.c root@dw:/home/dengwei/eclipse_workspace/scull# insmod scull.ko 按照上面提示,就可以顺利编译成ko文件,其中include/linux在我的Linux中绝对路径名是 /usr/src/linux-headers-2.6.32-21/include/linux

相关推荐