在构建内核模块时,为什么需要/lib/modules? [英] while building kernel modules why do we need /lib/modules?

查看:906
本文介绍了在构建内核模块时,为什么需要/lib/modules?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Kbuild树中,当我们编写一个简单的hello.ko程序时,为什么我们需要在构建规则中使用-C/lib/module/.为什么要这样做?可以单独建造吗?它的目的是什么?

In the Kbuild tree, when we are writing a simple hello.ko program then why do we need to use -C /lib/module/ in the build rule. Why this is required? Can it be build solely? What is the purpose of it?

推荐答案

while building kernel modules why do we need /lib/modules?

不一定要提供上述选项,即/lib/modules主要意图是get configured source-code directory.

Its not a compulsory to give above option i.e /lib/modules The main intention is to get configured source-code directory .

您可以设置为直接配置的源代码,或者您可以在上方提供/lib/modules/,其中包含用于构建源代码的软链接.

You can set to directly configured source-code or u can provide above i.e /lib/modules/ which having softlink for built source-code.

KDIR,

您可以设置完整的内核源目录(已配置和编译),也可以仅设置内核头目录(最低要求). 两种解决方案

you can either set full kernel source directory (configured and compiled) or just kernel headers directory (minimum needed). Two solutions

1)Full kernel sources

2)Only kernel headers (linux-headers-* packages in Debian/Ubuntu distributions)

2)Only kernel headers (linux-headers-* packages in Debian/Ubuntu distributions)

在两种情况下,其中的源或标头必须为configured.许多macros or functions depend on the configuration

where in both case The sources or headers must be configured.Many macros or functions depend on the configuration

-C选项调用kernel Makefile,并传递module directory in the M variable ,the kernel Makefile knows how to compile a module.

-C option calls the kernel Makefile, passing the module directory in the M variable ,the kernel Makefile knows how to compile a module.

例如,如果您将内核配置为Arm architecture or machine,则configured kernel Makefile会告诉您如何编译以及应针对哪些体系结构构建模块.

for e.g if you configure your kernel for Arm architecture or machine then configured kernel Makefile will tell how to compile and for which arhitecture your modules should be built.

要编译的是内核模块needs access to the kernel headers, containing the defnitions of functions, types and constants.

To be compiled, a kernel module needs access to the kernel headers, containing the defnitions of functions, types and constants.

Can it be build solely?

不能,您不能完全构建,因为模块应该知道要为哪个内核构建以及需要编译哪个配置,以便在插入模块时 所有相应的符号和配置均应匹配.所有这些都可以通过toplevel Makefile of configured kernel完成.

No you cant build solely since you module should should know for which kernel you want to build it and which configuration it needs to be compiled so that while inserting your module All respective symbols and configuration should be matched. All this can be done through toplevel Makefile of configured kernel.

这篇关于在构建内核模块时,为什么需要/lib/modules?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆