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