How one can define a dependency for modules in kernel,
Example:
got module1 and module2.
How do I say say kernel module2
should be loaded after module1
or module2
is dependent of module1
?
Note : module2 is not using any symbol from module1, but still order is important in my use case. so don't relate with moddep in kernel.
As of the linux 4.4 kernel (and maybe earlier) soft dependencies can be used to specify that a kernel module be loaded before or after a module is requested to be loaded. Those soft dependencies can be setup in a configuration file as described in the modprobe.d (5) manpage, or they can be specified directly in the code for the kernel module directly using the MODULE_SOFTDEP
macro.
To accomplish loading module2
after module1
by modifying the code of module2
, add this line outside of a function to the module2
code:
MODULE_SOFTDEP("pre: module1")
To accomplish the same by modifying the module1
code, you would use this line:
MODULE_SOFTDEP("post: module2")
Quote from man page of 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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With