歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> scull字符設備驅動編譯在新內核編譯問題解決方案

scull字符設備驅動編譯在新內核編譯問題解決方案

日期:2017/3/1 11:15:28   编辑:Linux編程

最近在看《LINUX設備驅動程序》,給出的字符設備驅動程序scull,在linux 2.6.32-22內核上make編譯時出現了下面的問題:
make -C /lib/modules/2.6.32-22-generic/build M=/home/elite/Desktop/linux設備驅動開發/examples/scull LDDINC=/home/elite/Desktop/linux設備驅動開發/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/elite/Desktop/linux設備驅動開發/examples/scull/Makefile". Fix itto use EXTRA_CFLAGS. Stop.
make[1]: *** [_module_/home/elite/Desktop/linux設備驅動開發/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

打開Makefile,將CFLAGS屏蔽掉:
# CFLAGS += $(DEBFLAGS)
# CFLAGS += -I$(LDDINC)

繼續make,又出現了下面的問題:
make -C /lib/modules/2.6.32-22-generic/build M=/home/elite/Desktop/linux設備驅動開發/examples/scull LDDINC=/home/elite/Desktop/linux設備驅動開發/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
CC [M] /home/elite/Desktop/linux設備驅動開發/examples/scull/main.o
/home/elite/Desktop/linux設備驅動開發/examples/scull/main.c:17:26: error:linux/config.h: No such file or directory
make[2]: *** [/home/elite/Desktop/linux設備驅動開發/examples/scull/main.o] Error 1
make[1]: *** [_module_/home/elite/Desktop/linux設備驅動開發/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

linux/config.h文件找不到,可能時新版內核結構改變了,這個文件被刪除了吧。
打開main.c,把#include <linux/config.h>刪除掉。

繼續make,還有問題:
make -C /lib/modules/2.6.32-22-generic/build M=/home/elite/Desktop/linux設備驅動開發/examples/scull LDDINC=/home/elite/Desktop/linux設備驅動開發/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
CC [M] /home/elite/Desktop/linux設備驅動開發/examples/scull/main.o
CC [M] /home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.o
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c: In function‘scull_p_read’:
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:131: error:‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:131: error: (Eachundeclared identifier is reported only once
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:131: error: foreach function it appears in.)
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:131: error:implicit declaration of function ‘signal_pending’
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:131: error:implicit declaration of function ‘schedule’
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c: In function‘scull_getwritespace’:
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:168: error:‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c: In function‘scull_p_write’:
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:219: error:‘TASK_INTERRUPTIBLE’ undeclared (first use in this function)
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:223: error:‘SIGIO’ undeclared (first use in this function)
/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.c:223: error:‘POLL_IN’ undeclared (first use in this function)
make[2]: *** [/home/elite/Desktop/linux設備驅動開發/examples/scull/pipe.o] Error 1
make[1]: *** [_module_/home/elite/Desktop/linux設備驅動開發/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

TASK_INTERRUPTIBLE找不到,既然前面刪除掉了了一個頭文件,必然有很多變量找不到,
那就到/usr/src/linux-headers-2.6.32-22-generic下grep一下呗:
最終找到頭文件,添加上:
#include <linux/sched.h>

access.c也需要添加上面的頭文件。

然後,還得make,痛苦阿。。。。

make -C /lib/modules/2.6.32-22-generic/build M=/home/elite/Desktop/linux設備驅動開發/examples/scull LDDINC=/home/elite/Desktop/linux設備驅動開發/examples/scull/../include modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-22-generic'
CC [M] /home/elite/Desktop/linux設備驅動開發/examples/scull/access.o
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c: In function‘scull_u_open’:
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c:107: error:‘struct task_struct’ has no member named ‘uid’
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c:108: error:‘struct task_struct’ has no member named ‘euid’
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c:115: error:‘struct task_struct’ has no member named ‘uid’
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c: In function‘scull_w_available’:
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c:166: error:‘struct task_struct’ has no member named ‘uid’
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c:167: error:‘struct task_struct’ has no member named ‘euid’
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c: In function‘scull_w_open’:
/home/elite/Desktop/linux設備驅動開發/examples/scull/access.c:185: error:‘struct task_struct’ has no member named ‘uid’
make[2]: *** [/home/elite/Desktop/linux設備驅動開發/examples/scull/access.o] Error 1
make[1]: *** [_module_/home/elite/Desktop/linux設備驅動開發/examples/scull] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-22-generic'
make: *** [modules] Error 2

說task_struct結構體沒有uid,euid成員變量,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

然後編譯,即可通過。

Copyright © Linux教程網 All Rights Reserved