0

Is it possible to dynamically load (via MOD_ALIAS() maybe?) a module that requires another module to first be loaded?

Background: I have a USB->I2C bridge on my system, and attached to the i2c end is a touchscreen. The kernel module that brings up the i2c automatically loads/unloads whenever the USB cable is connected/disconnected. I'm looking for a way to also load/unload the touchscreen driver on the same events.

2 Answers 2

1

You're talking about module dependencies, generated by depmod -A. The actual dependency information is stored in /lib/modules/version/modules.dep.

If /lib/modules/2.6.29/kernel/a.ko depends on b.ko (in the same directory) you could add the line:

/lib/modules/2.6.29/kernel/a.ko: /lib/modules/2.6.29/kernel/b.ko

To create the dependency.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't know that this helps me. foo.ko is loaded/unloaded dynamically based on usb plug events, and is unaware of the other module, bar.ko. bar.ko needs to be loaded after foo.ko is loaded. If I created a dependency from foo.ko to bar.ko, bar.ko will fail in its init function because it needs foo.ko to be loaded first
Ah I see. I believe you're into udev rulesets then. There's a way of doing them for USB so that when you hotplug in a USB device, you can do pretty much anything, including running a script. Unfortunately I don't know much about udevadm, sorry...
1

What you want is modprobe.d

Add a <module>.conf file where <module> is the name of your kernel module that is dynamically loaded.

Define the install and remove options within the above conf file to run the relevant commands instead of the modprobe (in the required order).

If you want to automatically load the module bob after loading the module alice,

# /etc/modprobe.d/alice.conf
install alice /sbin/modprobe --ignore-install alice;  /sbin/modprobe bob;

The --ignore-install, stops the modprobe from running the same install command again.

Similarly define the remove section within the same conf file.
For more details, checkout the man page of modprobe.d.

2 Comments

How do we do this with built-in drivers which are loaded at the beginnning
Is the double quote (") at the end a mistake?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.