eclipse 编译内核模块_单独编译某个内核模块

本文介绍了在SUSE Linux系统中如何使用Eclipse编译内核模块,特别是对于内核自带模块的编译过程。首先需要安装kernel-source和kernel-devel包,然后根据README.SUSE文档进行编译。在编译过程中遇到了ocfs2模块未被默认启用的问题,通过运行make menuconfig选择ocfs2并重新编译解决了问题。
摘要由CSDN通过智能技术生成

对开发内核驱动和文件系统的人来说,经常需要编译某个内核模块。 当然从编译角度,有built-in kernel module和external kernel module之分。 怎么编译一个外部内核模块,google一下“hello world kernel module Makefile”吧。 这里我说下编译内核自带模块的坑... 我用的是SUSE Linux

安装源代码包和开发包 #zypper in kernel-source kernel-devel

开发包里面放的是头文件和Makefile文件,用RPM命令来查看下: # rpm -qa|grep kernel-devel

kernel-devel-4.1.27-27.1.noarch

# rpm -ql kernel-devel-4.1.27-24.1.noarch|more

/usr/share/doc/packages/kernel-source-4.1.27-24

/usr/share/doc/packages/kernel-source-4.1.27-24/README.SUSE

/usr/share/doc/packages/kernel-source-4.1.27-24/config-options.changes.txt

/usr/src/linux

/usr/src/linux-4.1.27-24

/usr/src/linux-4.1.27-24/Documentation

/usr/src/linux-4.1.27-24/Documentation/DocBook

/usr/src/linux-4.1.27-24/Documentation/DocBook/Makefile

....

重要参考文件

#ls -l /usr/src/linux/README.SUSE

lrwxrwxrwx 1 root root 61 Dec 31 10:41 /usr/src/linux/README.SUSE -> ../../share/doc/packages/kernel-source-3.12.49-11/README.SUSE

这个文档介绍编译内核以及模块所需的软件包,概念,方法和步骤。 基本上也适用于其他Linux发型版。

贴出相关的一段:

The second method involves the following steps:

(1)  Install the kernel-devel package.

(2)  Install the kernel-$FLAVOR-devel package. This is necessary for

symbol version information (CONFIG_MODVERSIONS).

(3)  Compile the module(s) by changing into the module source directory

and typing ``make -C /usr/src/linux-obj/$ARCH/$FLAVOR M=$(pwd)''.

Substitute $ARCH and $FLAVOR with the architecture and flavor

for which to build the module(s).

If the installed kernel sources match the running kernel, you

can build modules for the running kernel by using the path

/lib/modules/$(uname -r)/build as the -C option in the above

command. (build is a symlink to /usr/src/linux-obj/$ARCH/$FLAVOR).

(4)  Install the module(s) with

``make -C /usr/src/linux-obj/$ARCH/$FLAVOR M=$(pwd) modules_install''.

3.坑

但是按照上面的步骤总是编译不出来.ko内核模块, 原因是当前的发行版默认没有打开ocfs2模块编译选项:

eric1211:/usr/src/linux/fs/ocfs2 # make -C /lib/modules/3.12.49-11-default/build M=`pwd` modules

make: Entering directory '/usr/src/linux-3.12.49-11-obj/x86_64/default'

make[1]: Entering directory `/usr/src/linux-3.12.49-11-obj/x86_64/default'

Building modules, stage 2.

MODPOST 0 modules

make: Leaving directory '/usr/src/linux-3.12.49-11-obj/x86_64/default'

原因是配置文件默认没有选择OCFS2,所以要手动make menuconfig,把ocfs2选上, 再试就可以了。具体步骤:

cd /usr/src/linux

make menuconfig 选择ocfs2

cd /usr/src/linux/fs/ocfs2

make -C /lib/modules/`uname -r`/build M=`pwd` modules

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值