Linux kernel 如何定义内核模块之间的依赖关系?
如何定义内核中模块的依赖关系 例如:Linux kernel 如何定义内核模块之间的依赖关系?,linux-kernel,linux-device-driver,Linux Kernel,Linux Device Driver,如何定义内核中模块的依赖关系 例如: got module1 and module2. 我怎么说内核module2应该在module1之后加载,或者module2依赖于module1 注意:module2没有使用module1中的任何符号,但在我的用例中顺序仍然很重要。所以不要在内核中与moddep联系起来。引用depmod手册页: Linux kernel modules can provide services (called "symbols") for other modu
got module1 and module2.
我怎么说内核module2
应该在module1
之后加载,或者module2
依赖于module1
注意:module2没有使用module1中的任何符号,但在我的用例中顺序仍然很重要。所以不要在内核中与moddep联系起来。引用depmod手册页:
Linux kernel modules can provide services (called "symbols") for other
modules to use (using one of the EXPORT_SYMBOL variants in the code).
If a second module uses this symbol, that second module clearly depends
on the first module. These dependencies can get quite complex.
depmod creates a list of module dependencies by reading each module
under /lib/modules/version and determining what symbols it exports and
what symbols it needs. By default, this list is written to modules.dep,
and a binary hashed version named modules.dep.bin, in the same
directory. If filenames are given on the command line, only those
modules are examined (which is rarely useful unless all modules are
listed). depmod also creates a list of symbols provided by modules in
the file named modules.symbols and its binary hashed version,
modules.symbols.bin. Finally, depmod will output a file named
modules.devname if modules supply special device names (devname) that
should be populated in /dev on boot (by a utility such as udev).
为了便于解决,您可以在第一个模块中添加符号,并在第二个模块init中检查该符号。如果未使用导出符号
EXPORT_SYMBOL
您可以从第二个模块初始化本身返回
有关详细信息,请参阅页眉
Linux kernel modules can provide services (called "symbols") for other
modules to use (using one of the EXPORT_SYMBOL variants in the code).
If a second module uses this symbol, that second module clearly depends
on the first module. These dependencies can get quite complex.
depmod creates a list of module dependencies by reading each module
under /lib/modules/version and determining what symbols it exports and
what symbols it needs. By default, this list is written to modules.dep,
and a binary hashed version named modules.dep.bin, in the same
directory. If filenames are given on the command line, only those
modules are examined (which is rarely useful unless all modules are
listed). depmod also creates a list of symbols provided by modules in
the file named modules.symbols and its binary hashed version,
modules.symbols.bin. Finally, depmod will output a file named
modules.devname if modules supply special device names (devname) that
should be populated in /dev on boot (by a utility such as udev).
从Linux4.4内核(可能更早)开始,可以使用软依赖项来指定在请求加载模块之前或之后加载内核模块。这些软依赖项可以按照modprobe.d(5)手册页中的描述在配置文件中设置,也可以直接使用
module\u SOFTDEP
宏在内核模块的代码中指定
要通过修改module2
的代码在module1
之后完成加载module2
,请在module2
代码的函数外添加此行:
MODULE\u SOFTDEP(“pre:module1”)
要通过修改模块1
代码来实现这一点,可以使用以下行:
MODULE\u SOFTDEP(“post:module2”)
我们不能手动执行吗?@srinivasth您能提供有关您试图解决的问题的更多信息吗?可能重复您所说的是外部模块(aka文件)还是内置模块?