How to use modprobe to load your own module and it dependencies automatically

In our previous post of module stacking, we developed two modules:

  • One module exporting a symbol
  • Other module using that symbol
We used insmod to load the first module which exported the symbol and then the second module.

In this post we will see how we can use modprobe on the second module and the first module should get automatically loaded.

Step 1: As modprobe reads only modules present in /lib/modules/$(uname -r), create symbolic link of your modules to /lib/modules/$(uname -r). Note, we need to pass full path of the module

$ sudo ln -s /home/jamal/ldd/module_stacking/module1.ko /lib/modules/$(uname -r)/kernel/drivers/misc

$ sudo ln -s /home/jamal/ldd/module_stacking/module2.ko /lib/modules/$(uname -r)/kernel/drivers/misc

Step2: Update modules.dep and map files
$ sudo depmod -a

Step3: Run modprobe on the module which has dependencies
$sudo modprobe module2


You can see when we did modprobe module2, module1 was also loaded automatically and when we did modprobe -r module2, module1 was also removed.

Comments

Popular posts from this blog

bb.utils.contains yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig

PR, PN and PV Variable in Yocto