Ldd3 Study Notes 2-simple

Source: Internet
Author: User
Tags gz file

I read ldd3 in the cloud. Fortunately, I have the source code. I can find the source code, compile it, and learn about ldd3. Find a source code and run it. Whether it's a white cat or a black cat, catch a mouse. You have to run it for me first, haha!

The following subdirectories are decompressed to the ldd3,examples.tar.gz file.

include  Makefile      pci    scullc  scullv      simple  ttylddbus   misc-modules  sbull  sculld  short       skull   usbLICENSE  misc-progs    scull  scullp  shortprint  snull

CD to the simple directory with the following files

Makefile  simple.c  simple_load  simple_unload

Makefile, simple_load, and simple_unload are described in detail. I don't know du Niang or Google, but I don't understand some of them.

1) cflags Error

Bory @ Chong :~ /Ldd3/test/simple $ Makemake-C/lib/modules/2.6.32-37-generic/build M =/home/Fang/ldd3/test/simple lddincdir =/home/Fang /ldd3/test/simple /.. /include modulesmake [1]: Entering the directory '/usr/src/linux-headers-2.6.32-37-generic' scripts/makefile. build: 49: *** cflags was changed in "/home/Fang/ldd3/test/simple/makefile ". fix it to use extra_cflags. Stop. Make [1]: *** [_ module _/home/Fang/ldd3/test/simple] Error 2 make [1]: leaving directory '/usr/src/linux-headers-2.6.32-37-generic' Make: *** [Default] Error 2

Because the source code is for Linux kernel 2.6.10 or earlier, both Bory and your version are later than 2.6.10. Therefore, many version-related errors may occur during source code compilation. The above error

Solution:

Replace "cflags" in the makefile with "extra_cflags"

Save and continue compilation.

2) Linux/config. h: the file or directory does not exist.

Bory @ Chong :~ /Ldd3/test/simple $ Makemake-C/lib/modules/2.6.32-37-generic/build M =/home/Fang/ldd3/test/simple lddincdir =/home/Fang /ldd3/test/simple /.. /include modulesmake [1]: Entering the directory '/usr/src/linux-headers-2.6.32-37-generic' CC [m]/home/Fang/ldd3/test/simple. o/home/Fang/ldd3/test/simple. c: 18: 26: Error: Linux/config. h: there is no such file or directory/home/Fang/ldd3/test/simple. c: In function 'simple _ vma_nopage ':/home/Fang/ldd3/test/simple. c: 115: Error: 'nopage _ sigbus' undeclared (first use in this function)/home/Fang/ldd3/test/simple. c: 115: Error: (each undeclared identifier is reported only once/home/Fang/ldd3/test/simple. c: 115: Error: for each function it appears in .) /home/Fang/ldd3/test/simple. c: at top level:/home/Fang/ldd3/test/simple. c: 128: Error: Unknown field 'nopage' specified in initializer/home/Fang/ldd3/test/simple. c: 128: Warning: initialization from incompatible pointer typemake [2]: *** [/home/Fang/ldd3/test/simple. o] Error 1 make [1]: *** [_ module _/home/Fang/ldd3/test/simple] Error 2 make [1]: leaving directory '/usr/src/linux-headers-2.6.32-37-generic' Make: *** [Default] Error 2

The file Linux/config. h does not exist. This is because the config. h file has been removed in the new version.

Solution:

Unregister the config. h header file of simple. C.

//#include <linux/config.h>

3) 'nopage _ sigbus' undeclared (first use in this function) and unknown field 'nopage' specified in initializer

Continue Compilation

Bory @ Chong :~ /Ldd3/test/simple $ Makemake-C/lib/modules/2.6.32-37-generic/build M =/home/Fang/ldd3/test/simple lddincdir =/home/Fang /ldd3/test/simple /.. /include modulesmake [1]: Entering the directory '/usr/src/linux-headers-2.6.32-37-generic' CC [m]/home/Fang/ldd3/test/simple. o/home/Fang/ldd3/test/simple. c: In function 'simple _ vma_nopage ':/home/Fang/ldd3/test/simple. c: 115: Error: 'nopage _ sigbus' undeclared (first use in this function)/home/Fang/ldd3/test/simple. c: 115: Error: (each undeclared identifier is reported only once/home/Fang/ldd3/test/simple. c: 115: Error: for each function it appears in .) /home/Fang/ldd3/test/simple. c: at top level:/home/Fang/ldd3/test/simple. c: 128: Error: Unknown field 'nopage' specified in initializer/home/Fang/ldd3/test/simple. c: 128: Warning: initialization from incompatible pointer typemake [2]: *** [/home/Fang/ldd3/test/simple. o] Error 1 make [1]: *** [_ module _/home/Fang/ldd3/test/simple] Error 2 make [1]: leaving directory '/usr/src/linux-headers-2.6.32-37-generic' Make: *** [Default] Error 2

It is also an error. It seems that kernel versions do not match, causing a lot of trouble. Nopage_sigbus and nopage are not defined. Because the new version vm_operations_struct removes the nopage member. We also remove her here.

Solution:

Edit simple. C and find return nopage_sigbus. (Because this method is not used, it does not matter if null is returned)

                //return NOPAGE_SIGBUS;                return NULL;

Find. nopage = simple_vma_nopage, and change the line as follows:

//.nopage = simple_vma_nopage,

Because the nopage member is removed from vm_operations_struct in the new kernel version

4) load the driver

Save and continue compilation. This is a success. After compiling this simple character driver, how can I load it?

Simple_load is the shell script and simple_unload is the unload script. First, change the permission.

Bory @ Chong :~ /Ldd3/test/simple $ chmod 755 simple_load
Bory @ Chong :~ /Ldd3/test/simple $ chmod 755 simple_unload

Continue

Bory @ Chong :~ /Ldd3/test/simple $ sudo./simple_load

After loading, how can I check whether the load is successful?

Bory @ Chong :~ /Ldd3/test/simple $ lsmod
Module size used
Simple 3868 0
Binfmt_misc 7960 1
Ppdev 6375 0

Joydev 11104 0

...

The simple character driver we just loaded in the list indicates that our operation was successful. If we print logs in the driver, how can we view these logs?

Find the file/var/log/syslog and you will be able to view your printed log.

In case of any errors, please point out, thank you for your advice!

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.