简体   繁体   English

Linux内核模块

[英]Linux kernel modules

I've not clear what is the difference between drivers that can be "embedded" inside a monolithic kernel and drivers available only as external modules. 我尚不清楚可以“嵌入”在单片内核中的驱动程序与只能作为外部模块使用的驱动程序之间的区别是什么。

What kind of effort is requested to "port" some driver (provided as "external module" only) to a monolithic kernel? 为了将某些驱动程序(仅提供为“外部模块”)“移植”到单片内核,需要采取何种努力?

I would like to be able to run Vmware Tools disabling loadable modules support and getting rid of the initrd bazaar. 我希望能够运行Vmware Tools来禁用可加载模块支持,并摆脱initrd集市。

Though the driver more or less remains the same(in both cases),there are definitely benefits for using "drivers" embedded in monolithic kernel. 尽管驱动程序或多或少保持不变(在两种情况下),但使用嵌入在单片内核中的“驱动程序”绝对有好处。

I'll try to explain the "effort in porting" the driver part which you've asked. 我将尝试解释您要求的“移植端口”的驱动程序部分。

Depending on the kind of driver you've, essentially you've to figure out how it will fit in the current kernel source tree, its compilation(include your .ko in the uImage) and loading of it while kernel booting. 根据您所使用的驱动程序类型,从本质上讲,您必须弄清楚它如何适合当前的内核源代码树,其编译(在uImage中包括.ko)并在内核引导时加载它。 Let's illustrate each step a bit: 让我们稍微说明一下每个步骤:

a.) Locate the folder (in the kernel source tree) where you think it is best suited to keep your driver code. a。)找到您认为最适合保留驱动程序代码的文件夹(在内核源代码树中)。

b.) Work on to make sure your driver code is getting compiled.[ie ultimately it will be part of monolithic kernel image(uImage or whatever you call it)]. b。)继续确保您的驱动程序代码已被编译。[即最终它将成为单片内核映像(uImage或您所称的映像)的一部分]。 In this context, You've to work on your Makefile for your driver. 在这种情况下,您必须为驱动程序处理Makefile。 You might have to introduce some CONFIG flags to compile your driver code. 您可能必须引入一些CONFIG标志来编译驱动程序代码。 There are tons of Makefiles' and driver code lying in the source tree. 源代码树中有大量的Makefile和驱动程序代码。 Roam around and you will get a good reference of how it is being done. 到处漫游,您将很好地了解它是如何完成的。

c.) Make sure that your driver code is independent of any other loadable kernel module(ie such modules which are not part of the "monolithic" kernel image). c。)确保您的驱动程序代码独立于任何其他可加载的内核模块(即,这些模块都不属于“整体”内核映像的一部分)。 Because if you invoke your driver code(which is monolithic now and is in memory) which depends on loadable module code then it may cause some kernel panic/segmentation fault kind of error. 因为如果您调用依赖于可加载模块代码的驱动程序代码(现在是单片且在内存中),则可能会导致某些内核崩溃/分段错误。

d.) Make sure that your driver is registered with a higher level of subsystem which will be initializing all the registered drivers during boot-up time.(for example: an i2c driver once registered with i2c driver framework will be loaded automatically when i2c subsystem is initialized during system startup). d。)确保您的驱动程序已在更高级别的子系统中注册,该子系统将在启动时初始化所有已注册的驱动程序。(例如:在i2c驱动程序框架中注册的i2c驱动程序将在i2c子系统自动加载)在系统启动期间初始化)。 This step might not be really required if you can figure out another way of invoking your driver's __init and __exit functions. 如果您可以找到另一种调用驱动程序的__init和__exit函数的方法,则可能不一定需要执行此步骤。

e.) Now, Your Driver _ init and ( _exit sections) "should" be called if it is getting loaded by any device driver framework or directly(ie while kernel is booting up ). e。)现在,如果驱动程序_ init和( _exit部分)被任何设备驱动程序框架加载或直接加载(即在内核启动时),则应“调用”。

f.) In case of h/w drivers, we have .probe implementation in driver which will be invoked once the kernel finds a corresponding device. f。)对于硬件驱动程序,我们在驱动程序中具有.probe实现,一旦内核找到相应的设备,该实现就会被调用。 In case of s/w drivers, I guess __init and __exit is all you have. 如果是s / w驱动程序,我想您拥有__init和__exit。

g.) Once it is loaded, you can use it like you were using it earlier as a loadable kernel module g。)一旦加载,就可以像之前将其用作可加载内核模块一样使用它

h.) I'll recommend reading source code of similar device drivers in the linux kernel tree and see how they are operating. h。)我建议您在linux内核树中阅读类似设备驱动程序的源代码,并查看它们如何运行。

Hope this helps. 希望这可以帮助。

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

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