If I have two modules which are being statically linked in. One modules' module_init function depends on another module's module_init function having already run. Is there a way to force one module to load before the other?
Also, is the first module's init function guaranteed to finish before the second one is invoked?
Lastly, if the answer to the above is NO, what is the recommended way of synchronizing the two module init calls to make sure I don't run into issues?
Linux provides a utility known as “insmod”. This is the utility which can be used to load the kernel module at the running kernel. To load the kernel module, just execute the command as insmod followed by the module file name.
Run the command lsmod to see if driver is loaded. (look for the driver name that was listed in the output of lshw, "configuration" line). If you did not see the driver module in the list then use the modprobe command to load it.
The Linux loadable modules have two important characteristics: Dynamic linking: A kernel module can be loaded and linked into the kernel while the kernel is already in memory and executing. A module can also be un- linked and removed from memory at any time. Stackable modules: The modules are arranged in a hierarchy.
To load a kernel module, use the /sbin/modprobe command followed by the kernel module name.
Is there a way to force one module to load before the other?
Answer is surprisingly simple, make sure first module is first in Makefile:
obj-y += mod1.o
obj-y += mod2.o
is the first module's init function guaranteed to finish before the second one is invoked?
Yes, initcalls (module_init
hook) in your case are called one-by-one. See init/main.c
,
do_one_initcall()
callers.
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