惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
V
V2EX
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
A
About on SuperTechFans
博客园_首页
L
LangChain Blog
量子位
雷峰网
雷峰网
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Jina AI
Jina AI
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium

博客园 - 中土

strcpy和memcpy的标准实现 Linux 命令缩写部分解释 Eclipse RCP 的一些有用的资源及应用案例 分析Linux和windows动态库 C/C++中的函数参数传递机制(zz) LDD3 笔记: 第3章 字符设备的驱动 2008年看书计划 H.264学习建议(zz) - 中土 - 博客园 几种常用的视频接口(端子) U-boot 移植到FS2410 NandFlash和NorFlash的区别 Linux basic use Kernel resource list Linux2.6 驱动设计―从 2.4.x 到 2.6.x Linux 2.6.x 内核模块入门(LKM) C++中无处不在的临时变量 类中引用成员的初始化 C++初始化与赋值 C异常处理实现: setjmp和longjmp
A simple tourial for Linux 2.6.24 kernel module
中土 · 2008-10-11 · via 博客园 - 中土

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 -<path-to-kernel> M=`pwd`

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

For the running kernel use:

make -/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