[英]Compiling out-of-tree kernel module against any kernel source tree on the filesystem
I am trying to compile a module against any source tree on the file system but I am having trouble with the Makefile.我正在尝试针对文件系统上的任何源代码树编译模块,但是我在 Makefile 上遇到了问题。 This was the original Makefile I had against the kernel specified:
这是我针对内核指定的原始 Makefile:
obj-m += new-mod.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
This Makefile would compile correctly, but goal is to have it compile against any source tree.这个 Makefile 可以正确编译,但目标是让它针对任何源代码树进行编译。 I have tried just:
我试过:
obj-m += new-mod.o
I thought that "all:" is assumed but I get error:我认为“所有:”是假设的,但我收到错误:
make: *** No targets. Stop.
I have also added:我还补充道:
all:
to the Makefile with no difference except for error message:到 Makefile 除了错误消息外没有区别:
make: Nothing to be done for `all'
I have tried a lot of documentation but no luck.我已经尝试了很多文档,但没有运气。 I would greatly appreciate any help.
我将不胜感激任何帮助。
goal is to have it compile against any source tree
ya you can do it providing a compiled source-code path
是的,您可以提供
compiled source-code path
just replace make -C /lib/modules/$(shell uname -r)/build M=$PWD modules
只需替换
make -C /lib/modules/$(shell uname -r)/build M=$PWD modules
with this有了这个
make -C <path-to-compiled-src-code> M=$PWD modules
make -C /home/vinay/linux-3.9 M=$PWD modules
try below makefile试试下面的makefile
Makefile –生成文件 –
# if KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq (${KERNELRELEASE},)
obj-m := new-mod.o
# Otherwise we were called directly from the command line.
# Invoke the kernel build system.
else
KERNEL_SOURCE := /usr/src/linux
PWD := $(shell pwd)
default:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules
clean:
${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
endif
In above you can change KERNEL_SOURCE := /usr/src/linux
-->to.--> your sr-code KERNEL_SOURCE := <path to compiled-src-code>
在上面你可以改变
KERNEL_SOURCE := /usr/src/linux
-->to.--> 你的 sr-code KERNEL_SOURCE := <path to compiled-src-code>
for further info find below liks有关更多信息,请在下面找到喜欢
while building kernel modules why do we need /lib/modules? 在构建内核模块时,为什么我们需要 /lib/modules?
A simple program on linux device driver 一个简单的linux设备驱动程序
How to make a built-in device driver in linux 如何在linux中制作内置设备驱动程序
Build against your custom kernel source ( not the one that is installed), You can use following steps.针对您的自定义内核源代码(不是已安装的内核源代码)构建,您可以使用以下步骤。
1.download kernel from kernel.org (tar) 1.从 kernel.org (tar) 下载内核
2.Extract 2.提取
3.make x86_64_defconfig 3.make x86_64_defconfig
4.make prepare 4.做好准备
5.make modules_prepare 5.make modules_prepare
Now you have to change Makefile to point to kernel source you had downloaded and extracted.现在您必须更改 Makefile 以指向您下载和解压缩的内核源代码。 Something similar mentioned in example by Vinay Answer.
Vinay Answer 的示例中提到的类似内容。
Just remember you cannot insmod this module as kernel running and module built is for different kernel.请记住,您不能插入此模块,因为内核正在运行,并且构建的模块是针对不同内核的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.