简体   繁体   English

针对内核源代码树构建Linux内核模块?

[英]Building Linux Kernel Module against kernel source tree?

What does it mean to build a module against any kernel source tree present on file system and not just those happened to be install in /lib/ at sometime? 针对文件系统上存在的任何内核源代码树构建模块,而不仅仅是有时偶然在/ lib /中安装的模块,这意味着什么? Concretely, I have come across these two examples 1. and 2. but both of them are largely vague. 具体来说,我遇到了这两个示例1.2.,但是它们在很大程度上都是模糊的。 The second has some code but it fails to say what the code is actually doing. 第二个有一些代码,但是它无法说出代码的实际作用。

/lib/modules/$(shell uname -r)/build refers to a directory that should contain the source tree; /lib/modules/$(shell uname -r)/build指向应包含源树的目录; it's usually a symlink to a folder in /usr/src . 它通常是/usr/src文件夹的符号链接。 If the source tree is not installed, it's a dangling symlink or an empty directory. 如果未安装源代码树,则它是悬挂的符号链接或空目录。

uname -r gives the release string for the running kernel (try it). uname -r给出正在运行的内核的发布字符串(尝试)。 This is used to label a subdirectory of /lib/modules , where the modules for that kernel are stored. 这用于标记/lib/modules的子目录,该目录用于存储该内核的模块。 By default, the kernel will not load a module that was compiled for a different version (eg, 3.13.5 vs 3.13.4), so if you are writing you own module, you must compile it every version you want to use it with. 默认情况下,内核不会加载针对其他版本(例如3.13.5与3.13.4)编译的模块,因此,如果您正在编写自己的模块,则必须将每个要使用的版本编译该模块。 。

Since the makefile in your first link uses uname -r , it will only work for the currently running kernel; 由于第一个链接中的makefile使用uname -r ,因此它仅适用于当前正在运行的内核。 if you want to use it unchanged for a different version, you'd have to reboot with that version. 如果您想不更改版本地使用它,则必须重新启动该版本。 The questioner is asking for a simple way to modify the makefile such that it could be used to compile a module for any kernel version, not just the one that is running. 发问者正在寻求一种简单的方法来修改Makefile,以便可以将其用于编译适用于任何内核版本的模块,而不仅仅是正在运行的模块。 If you are reading the second link, which is an introduction to writing kernel modules, you do not have to be concerned with this issue. 如果您正在阅读第二个链接,它是编写内核模块的入门,则不必担心此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM