ubuntu12.04 character device driver and provide source code parsing

Source: Internet
Author: User

The previous two articles documented the initial implementation of a driver module and its parameters on ubuntu12.04:

HelloWorld

Module parameters

The following record, in the ubuntu12.04 above the implementation of the character-driven process, in the See LDD3 (Linux Device driver 3rd) Chapter Three, explained the character device driver implementation, naturally found the source code to view and compile, but, The official source code contains the third chapter to the sixth chapter of the content, for the novice, may feel very distressed, because the knowledge will not be back, and the code mixed together is not conducive to the knowledge of this chapter, the following record my source separation process, as well as in ubuntu12.04 (kernel Version 3.2.0-23-generic) The process of compiling, loading, testing, and unloading the above.

First, the source resources that can be run: http://download.csdn.net/detail/jiguangcanhen/8314973

-------------------------------------------------------------------------------------------

The final source contains the following files:

MAIN.C Makefile scull.h scull.init scull_load scull_unload

Say it separately:

MAIN.C: Of course, the main content of the module.

Makefile: is a compilation script

Scull.h: A custom header file, which is referenced in Main.c, declares a number of variables, and so on.

Scull.init: Initializes the script, creates the device node when the module is loaded, deletes the device node when the module is unloaded, and so on.

Scull_load: module load script.

Scull_unload: module unload script.

--------------------------------------------------------------------------------------------

First of all, the Main.c script source code parsing, this is a reference to this blog, the explanation is very detailed: http://blog.csdn.net/liuhaoyutz/article/details/7383313

--------------------------------------------------------------------------------------------

followed by the Makefile script parsing, this is also reference to this blog: http://blog.csdn.net/liuhaoyutz/article/details/7382956

Here, let me just say something that needs to be changed:

1. Put SCULL-OBJS: = MAIN.O pipe.o ACCESS.O modified to SCULL-OBJS: = MAIN.O

The reason is also very simple, we now have no pipe.c and ACCESS.C, these are the contents of the later chapters, but also we need to remove the part.

2. There is also an error in make, which is left behind.

--------------------------------------------------------------------------------------------

For Scull.init and Scull_load and Scull_unload is three shell scripts, for here, if you do not understand, please read the shell Introduction and development guide

Here is also a place to change:

1.files= "0 0 1 1 2 2 3 3 priv 16
PIPE0 pipe1 pipe2 Pipe3 35
Single-UID 80 "wuid

Modified to:

files= "0 0 1 1 2 2 3 3"

The reason is also very simple, that is the character device behind, we do not need to.

As for Scull_load and scull_unload can not be modified.

In concrete, we will be more than the source code and the official source of the difference on it.

-------------------------------------------------------------------------------------------

The following is the make process:

Issue 1:makefile.build:12: * * * CFLAGS WA changed in ' Yourpath '. Fix it to use ccflags-y. Stop.

Problem solving: also very simple, is to find the corresponding problem in the makefile, to replace it.

Issue 2:main.c:1:0:error:linux/config.h:no such file or directory.

Problem solving: comment out the words "include <linux/config.h>".

Issue 3:error:implicit declaration of function ' Init_mutex '

Problem solving: You can quote main.c in the place where the initialization is used to Init_mutex, or you can use Sema_init (sem,1) to replace it.

--------------------------------------------------------------------------------------------

After that, make is passed, LS look at the current file directory.


Because we haven't loaded the module yet, we can't see the device node we created, and we need root permission to load the module.


Once the module has been loaded, we can see our module in/proc/modules.


You can see our devices in/dev.


We can see the device main number is 249, this number is: 0, 1, 2, 3, the name is resolved to Scull0, Scull1, Scull2, Scull3. and C, it means that our device is a character device. And the main number is generally associated with the driver, it can be explained that our driver number is 249.


Test our character device as well as the driver, display the contents of the view scull0, find nothing, and then input the current login account information into the scull0, again see can see our previous input information.


Then the module uninstall, you can find that the corresponding device has been deleted, and the module has been successfully uninstalled.

ubuntu12.04 character device driver and provide source code parsing

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.