A simple tourial for Linux 2.6.24 kernel module

來源:互聯網
上載者:User

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

Linux Dist: Ubuntu 8.04 Hardy

1. Preparation

1.1 Download source code with apporiate version

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

You can type uname -r  in 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 to:  $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 you needn't  write your own Makefile for build your modules, that's completed by kbuild - 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 refer to modules.txt

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.