Ldd3 compilation module in Ubuntu

Source: Internet
Author: User

As required by the lab, we need to learn the driver development in Linux, and we should also study the driver development in Linux. However, a problem occurs when writing the book code, that is, it cannot be compiled in Ubuntu, after searching on the internet, find the next blog, which is very good, as shown below:

 

Compile LDD3-scull

1. The following message is displayed: scripts/makefile. Build: 46: *** cflags was changed in "/home/chenfang/scull/makefile", fix it use extra_cflags.stop .:

Ldd3 uses the 2.6.10 kernel, and many things have changed. Here we are prompted to modify the cflags in makefile and replace them with extra_cflags. Just do what it says.

2. The system prompts that the file Linux/config. h cannot be found:

The config. h file is deleted in the kernel starting with 2.6.19. Therefore, you only need to comment out # include <Linux/config. h> in Mian. C.

3. The error message "dereferencing pointer to incomplete type" is displayed in access. C:

In the source code, it is found that only current has an error. Current should be a global variable of the task_struct type. Find that task_struct exists in Linux/sched. h, so in access. add # include <Linux/sched. h>, make again.

By the way, let's see where the current global variable is defined:

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_current ())

As you can see, current is actually a "pseudo global variable", which is the macro definition of the function get_current. When access. c uses current-> uid, The get_current () function is called to return tasks in the task_struct structure. Therefore, current-> uid is equivalent to task-> uid.

An error occurred while compiling scull In ubuntu. Fortunately, some netizens provided a solution to delete the config. h file and add the # include header files capability. h and sched. h.

After upgrading Ubuntu to version 9.10 recently, the kernel tree of version 2.6.31 was regenerated.
/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'
Cause:
Struct task_struct is defined in include/Linux/sched. in H, the definition of the original task_struct struct has been changed, and UID and EUID are moved to cred. See include/Linux/sched. H and include/Linux/cred. h.
Solution:
You only need to modify the Error Code as follows:
Current-> uid changed to current-> cred-> uid
Modify current-> EUID to current-> cred-> EUID

Make success
Result:
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

 

Follow the prompts above to compile the Ko file. The include/Linux absolute path name in my Linux is

/Usr/src/linux-headers-2.6.32-21/include/Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.