静态插入linux内核模块 [英] Insert linux kernel module statically
问题描述
从源代码构建Linux内核时,可以决定是将某种功能静态地内置到内核中还是打包到模块中以通过.config动态插入.
When building the Linux kernel from sources one could decide if a certain functionality is statically built into the kernel or packed into a module for dynamic insertion by .config.
另一方面,如果我有任何第三方模块的源代码,例如打包的设备驱动程序,是否可以通过编程方式将此代码静态地静态集成到内核中?而不是从根文件系统加载内核模块?
If on the other hand I have sources for any 3rd party module, like for example a packaged device driver, is it possible to programmatically integrate this code into the kernel statically instead? And not load the kernel module from the root filesystem?
推荐答案
当然,您只需做一点点改动即可将外部模块移入内核源代码树,对Makefiles/Kconfig进行一些调整,以便代码是内置的,然后构建您的内核映像.例如,假设您将模块源移至drivers/blah
.然后,您应该在drivers/Makefile
的末尾添加一行,例如
Sure, you just need to do a bit of hacking to move the external module into the kernel source tree, tweak the Makefiles/Kconfig a bit so that the code is built-in, and then build your kernel image. For example, let's say you move the module source into drivers/blah
. Then you should add a line to then end of drivers/Makefile
like
obj-y += blah/
,并且应确保设置drivers/blah/Makefile
来内置模块,例如
and you should make sure that drivers/blah/Makefile
is set up to build your module in, with something like
obj-y += mymodule.o
mymodule-objs := src.o other.o
,依此类推,在其中设置了Makefile,但是需要构建您正在处理的特定模块. 注意:您必须使用输出文件名作为mymodule-objs,而不是输入文件名!
and so on, where your Makefile is set up however it needs to be to build the particular module you're working on. Note: You have to use the output file name for mymodule-objs and not the input filename!
这篇关于静态插入linux内核模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!