A simple tourial for Linux 2.6.24 kernel module

Source: Internet
Author: User

Author: Charles Yang <chio.yang@gmail.com>

Linux Dist: Ubuntu 8.04 hard

1. Preparation

1.1 download source code with apporiate version

Usually, the Linux release distribution have no full kernel source code tree. So you shoshould get a copy of kernel source fromWww.kernel.org. For convience, you had better download the same version as you running Linux kernel.

You can typeUname-RIn you X-term, for example:

Charles @ Charles - Laptop ~ > Uname - R
2.6 . 24 - 16 - Generic

1.2 learn the document for Linux kernel module (lkm)

Once you plan to do modules development, you should refer:$ Srcdir/document/kbuild/modules.txt

In my Ubuntu 8.04, I can find it in // Usr/src/linux-headers-2.6.24-16/documentation/kbuild

Now let read the document for module development ..

1). How to Build external Module

From modules.txt, we know the simplest make command:

Make - C < Path - To - Kernel > M = 'Pwd'

The <path-to-kernel> means the kernel source path.

For the running kernel use:

Make - C / Lib / Modules / 'Uname - R' / Build m = 'Pwd'

The-C option: change to the directory before execute the make command.

actually, that will result in search the makefile in / lib / modules / 2.6 . 24 - 16 - generic / build in my OS.

notice: Most of files in / lib / modules / 2.6 . 24 - 16 - generic / build actually link to /usr/src/linux-headers-2.6.24-16/

The M = 'pwd': Define a macro required by makefile in/Lib/Modules/2.6.24-16-Generic/Build, which can tell the directory of current exernal module code.

Therefore youNeedn'tWrite your own makefile for build your modules, that's completedKbuild-A good machism for kernel modules.

2. Make target

Make - C $ kdir m = 'Pwd'
Make - C $ kdir m = 'Pwd' all
Make - C $ kdir m = 'Pwd' modules
Make - C $ kdir m = 'Pwd' modules_install
Make - C $ kdir m = 'Pwd' clean
Make - C $ kdir m = 'Pwd' help

The first 3 commands are absolutely same. For more details, you can referModules.txt

 

 

 

 

 

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.