Original: Http://blog.csdn.net/lxmky/archive/2010/06/17/5675706.aspx
Under the Linux driver development, writing encountered a problem, that is, in Ubuntu can not compile, after the search on the Internet, find the following blog, very good, as follows: Compile Ldd3-scull
1, prompted scripts/makefile.build:46:*** Cflags was changed in "/home/chenfang/scull/makefile", Fix it use Extra_cflags. Stop.:
Because LDD3 uses the 2.6.10 kernel, a lot of things have changed, here prompted us to modify the cflags in makefile, with Extra_cflags instead, as it said to do it.
2, the hint can not find the file linux/config.h: In the 2.6.19 start of the kernel deleted config.h file, so as long as in Mian.c comment out #include.
3, hint ACCESS.C exist: dereferencing pointer to incomplete type error: In the source found only the current error, current should be a task_struct type of global variables, Find task_struct exists in linux/sched.h, so add #include to access.c and make it again.
By the way, the current global variable is defined where: the current found in source Ininsight is similar to the following definition: 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_curre NT ()) is visible, current is actually a "pseudo global variable", is the macro definition of function get_current ().
When Current->uid is used in ACCESS.C, the get_current () function is invoked to return the task of the TASK_STRUCT structure, so current->uid is equivalent to Task->uid. Prior to compiling scull in Ubuntu there are errors, but fortunately there are users to provide a solution, that is, delete config.h files and add #include two header files: Capability.h and Sched.h Having recently upgraded Ubuntu to version 9.10, the 2.6.31 Kernel tree was regenerated, and it was not thought that a new version of the Scull module would appear when it was compiled
/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 ' Reason: struct task _struct defined in Include/linux/sched.h, the original task_struct structure definition has changed, the UID and euid, etc. moved to cred, see Include/linux/sched.h and Include/linux /cred.h.
WORKAROUND: Simply make the code for the error as follows modify Current->uid to Current->cred->uid Current->euid modified to Current->cred->euid Make success
Results: root@dw:/home/dengwei/eclipse_workspace/scull# ls access.c main.o module.symvers scull.init SCULL.MOD.O Makefile pipe.c Scull.ko scull.o _desktop.ini module.markers pipe.o scull_load scull_unload main.c modules.order scull.h s CULL.MOD.C root@dw:/home/dengwei/eclipse_workspace/scull# Insmod Scull.ko Follow the above prompts, you can successfully compile into Ko file, which include/ Linux in my Linux absolute path name is/usr/src/linux-headers-2.6.32-21/include/linux
Communicating with hardware
#include <linux/ioctl.h>/* needed for the _IOW etc stuff used later * *
#include <mach/hardware.h>
#include <asm/io.h>
#include <linux/ioport.h>
#include <mach/regs-gpio.h>
#include <mach/regs-gpioj.h>
Header file