Skip to contentSkip to conversation

How to check if driver is in-built or module?

DISCUSSION [email protected] 5 participants 12 messages Mar 3, 2006 – Apr 1, 2006

lore
Share & tools
lore
#0 lore raw

Hello. This is my first post on this list, and I hope I'm not asking something that's already been dealt with. (I searched the docs and this list before posting.)

How can I tell udev to modprobe <module> only if <module> exists and hasn't been compiled in the kernel? In my experience modules are visible to udev only when and after they are loaded, which makes finding a solution to my problem a bit of a paradox.

I need this feature for those modules that aren't autoloaded, such as rtc. The idea would not be to modprobe all modules that exist, but to add conditional that would run modprobe only if necessary.

The rule I use for autoloading is:
SYSFS{modalias}="?*", ACTION="add", RUN+="/sbin/modprobe $env{MODALIAS}

Thank you. Sincerelly,
Juuso Alasuutari

----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 2 lines · On Mar 03, [email protected] wrote:

How can I tell udev to modprobe <module> only if <module> exists and hasn't been compiled in the kernel? In my experience modules are visible to udev only when

# check if the device has already been claimed by a driver
ENV{PHYSDEVDRIVER}="?*", GOTO="hotplug_driver_loaded"

ENV{MODALIAS}="?*", RUN+="/sbin/modprobe $env{MODALIAS}"

LABEL="hotplug_driver_loaded"

Look at the Debian rules files for details.

Quoted 3 lines

I need this feature for those modules that aren't autoloaded, such as rtc. The idea would not be to modprobe all modules that exist, but to add conditional that would run modprobe only if necessary.

I doubt that this buys you much anyway.

Signature · 13 lines
ciao,
Marco


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#2 lore raw
In reply to [email protected]
Quoted 5 lines · Marco d'Itri
Quoted 2 lines · On Mar 03, [email protected] wrote:

How can I tell udev to modprobe <module> only if <module> exists and hasn't been compiled in the kernel? In my experience modules are visible to udev only when

Quoted 7 lines
# check if the device has already been claimed by a driver
ENV{PHYSDEVDRIVER}=="?*", GOTO="hotplug_driver_loaded"

ENV{MODALIAS}=="?*", RUN+="/sbin/modprobe $env{MODALIAS}"

LABEL="hotplug_driver_loaded"

This breaks drivers like joydev which augment an existing loaded driver. PHYSDEVDRIVER contains usbhid, so you never load joydev (which is expanded by the MODALIAS).

Scott

Signature · 2 lines
Scott James Remnant
[email protected]
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Fri, Mar 03, 2006 at 10:35:50PM +0200, [email protected]…

Hello. This is my first post on this list, and I hope I'm not asking something that's already been dealt with. (I searched the docs and this list before posting.)

How can I tell udev to modprobe <module> only if <module> exists and hasn't been compiled in the kernel? In my experience modules are visible to udev only when and after they are loaded, which makes finding a solution to my problem a bit of a paradox.

Look in /sys/module/ That will have the module name if the module is loaded _or_ if the module is built into the kernel.

If it's not there, then it should be safe to load it.

Or you can always just try to load the thing, as if it's already in the kernel built in, it will not be present in the tree as a module.

Hope this helps,

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to [email protected]
Quoted 4 lines
Quoted 1 line

How can I tell udev to modprobe <module> only if <module> exists and hasn't

been

Quoted 1 line

compiled in the kernel? In my experience modules are visible to udev only

when

Quoted 8 lines
Quoted 1 line

and after they are loaded, which makes finding a solution to my problem a

bit

Quoted 1 line

of a paradox.

Look in /sys/module/ That will have the module name if the module is loaded _or_ if the module is built into the kernel.

If it's not there, then it should be safe to load it.

Thanks, that helped a lot. I wrote the following rules for snd_pcm_oss and rtc based on your hint:

# Load ALSA OSS emulation sound module if not already loaded. KERNEL!="snd_pcm_oss", SUBSYSTEM!="module", ACTION="add", RUN+="/sbin/modprobe snd_pcm_oss"

# Load real time clock module if not already loaded. KERNEL!="rtc", SUBSYSTEM!="module", RUN+="/sbin/modprobe rtc"

They work at least when running udevstart in console, haven't yet rebooted. One thing bugs me, though. I tried to be smart and make it so that snd_pcm_oss wouldn't try to load unless snd_pcm was loaded, but snd_pcm_oss refused to load altogether. Here's what I wrote:

KERNEL!="snd_pcm", SUBSYSTEM!="module", GOTO="bypass_oss" KERNEL!="snd_pcm_oss", SUBSYSTEM!="module", ACTION="add", RUN+="/sbin/modprobe snd_pcm_oss"
LABEL="bypass_oss"

What might be wrong with it?

Juuso

----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to [email protected]
Quoted 16 lines · On Sat, Mar 04, 2006 at 04:49:43AM +0200, [email protected]…
Quoted 4 lines
Quoted 1 line

How can I tell udev to modprobe <module> only if <module> exists and hasn't

been

Quoted 1 line

compiled in the kernel? In my experience modules are visible to udev only

when

Quoted 8 lines
Quoted 1 line

and after they are loaded, which makes finding a solution to my problem a

bit

Quoted 1 line

of a paradox.

Look in /sys/module/ That will have the module name if the module is loaded _or_ if the module is built into the kernel.

If it's not there, then it should be safe to load it.

Thanks, that helped a lot. I wrote the following rules for snd_pcm_oss and rtc based on your hint:

Quoted 6 lines

# Load ALSA OSS emulation sound module if not already loaded. KERNEL!="snd_pcm_oss", SUBSYSTEM!="module", ACTION="add", RUN+="/sbin/modprobe snd_pcm_oss"

# Load real time clock module if not already loaded. KERNEL!="rtc", SUBSYSTEM!="module", RUN+="/sbin/modprobe rtc"

No, this kind of thing belongs in your distro's "load these modules at boot time" list. Everyone has this, it's just in different locations (/etc/sysconfig/modules in SuSE, /etc/modules.autoload/kernel-2.6/ for Gentoo, etc.)

Don't mess with udev rules for things like this, it's just not worth it. Use the infrastructure that is already present and solves this today.

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to [email protected]

Quoting Greg KH <[email protected]>:

Quoted 13 lines
Quoted 2 lines

# Load ALSA OSS emulation sound module if not already loaded. KERNEL!="snd_pcm_oss", SUBSYSTEM!="module", ACTION="add",

RUN+="/sbin/modprobe

Quoted 4 lines

snd_pcm_oss"

# Load real time clock module if not already loaded. KERNEL!="rtc", SUBSYSTEM!="module", RUN+="/sbin/modprobe rtc"

No, this kind of thing belongs in your distro's "load these modules at boot time" list. Everyone has this, it's just in different locations (/etc/sysconfig/modules in SuSE, /etc/modules.autoload/kernel-2.6/ for Gentoo, etc.)

Quoted 7 lines

Don't mess with udev rules for things like this, it's just not worth it. Use the infrastructure that is already present and solves this today.

thanks,

greg k-h

OK. I'm using Source Mage, and there indeed exists a file /etc/modules.

The reason I wanted a udev rule for rtc (among many) is because the udev autoload rule isn't doing everything that hotplug was. rtc is one example of modules that were loaded by hotplug before but not by udev now. Same goes for the irda modules. Obviously I didn't have entries for them in /etc/modules back then, so I am hoping to figure out why they aren't loading and if there's anything I can do about that with udev.

Any thoughts on this?

Sincerelly,
Juuso

PS: As I really enjoy messing with udev stuff and also contribute to Source Mage's development, I would like to know if there are any dangers in loading these modules with udev. If so, I'll just use the approach pointed out to me. But if it's possible to use udev, why not edit Source Mage's own udev rules to load those modules that are all-around useful, and leave it to the user to put others in /etc/modules?
(I have to admit that right now I don't have a clear image of which modules really are "all-around useful", so I'm just assuming that all modules which were loaded by hotplug are such, rtc being one example.)

----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to [email protected]
Quoted 1 line · On Mar 04, [email protected] wrote:

Any thoughts on this?

These modules are not being loaded automatically because they lack the needed aliases. I added these to the debian package:

alias pnp:dPNP0510 irtty-sir
alias pnp:dPNP0511 irtty-sir
alias pnp:dPNP0700 floppy
alias pnp:dPNP0800 pcspkr
alias pnp:dPNP0b00 rtc
alias pnp:dPNP0303 atkbd
alias pnp:dPNP0f13 psmouse
alias pnp:dPNPb02f analog

And then I use this rule:

SUBSYSTEM="pnp", ENV{MODALIAS}!="?*", RUN+="/bin/sh -c 'while read id; do /sbin/modprobe pnp:d$$id; done < /sys$devpath/id'"

It's still not perfect, drivers which have card PNP aliases do not export them to sysfs.

Signature · 13 lines
ciao,
Marco


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#8 lore raw
In reply to [email protected]

Quoting Marco d'Itri <[email protected]>:

Quoted 12 lines

These modules are not being loaded automatically because they lack the needed aliases. I added these to the debian package:

alias pnp:dPNP0510 irtty-sir
alias pnp:dPNP0511 irtty-sir
alias pnp:dPNP0700 floppy
alias pnp:dPNP0800 pcspkr
alias pnp:dPNP0b00 rtc
alias pnp:dPNP0303 atkbd
alias pnp:dPNP0f13 psmouse
alias pnp:dPNPb02f analog

Quoted 7 lines

And then I use this rule:

SUBSYSTEM="pnp", ENV{MODALIAS}!="?*", RUN+="/bin/sh -c 'while read
id; do /sbin/modprobe pnp:d$$id; done < /sys$devpath/id'"

It's still not perfect, drivers which have card PNP aliases do not export them to sysfs.

Where do those "alias ..." lines go exactly?

How did hotplug manage to load these modules without them having aliases, by the way? And are there any tools for finding out what modules lack this necessary info, except hands-on experimentation?

What would it take to make these kind of special arrangements unnecessary? On what level would the changes have to happen? In udev, or in the kernel perhaps? In whose court is the ball on this matter?

Juuso

----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#9 lore raw
In reply to [email protected]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 15 lines · On Tuesday 07 March 2006 02:45, [email protected] wrote:

Quoting Marco d'Itri <[email protected]>:

Quoted 14 lines

These modules are not being loaded automatically because they lack the needed aliases. I added these to the debian package:

alias pnp:dPNP0510 irtty-sir
alias pnp:dPNP0511 irtty-sir
alias pnp:dPNP0700 floppy
alias pnp:dPNP0800 pcspkr
alias pnp:dPNP0b00 rtc
alias pnp:dPNP0303 atkbd
alias pnp:dPNP0f13 psmouse
alias pnp:dPNPb02f analog

And then I use this rule:

Quoted 8 lines
Quoted 5 lines

SUBSYSTEM="pnp", ENV{MODALIAS}!="?*", RUN+="/bin/sh -c 'while
read id; do /sbin/modprobe pnp:d$$id; done < /sys$devpath/id'"

It's still not perfect, drivers which have card PNP aliases do not export them to sysfs.

Where do those "alias ..." lines go exactly?

/etc/modprobe.conf I assume

Quoted 2 lines

How did hotplug manage to load these modules without them having aliases, by the way?

It could have some built-in list of modules.

Quoted 3 lines

And are there any tools for finding out what modules lack this necessary info, except hands-on experimentation?

I doubt it. If you know that device has PNP id and know its driver, check for existence of MODULE_DEVICE_TABLE(pnp,...). If it is missing, driver does not export PNP IDs it supports and no module aliases are created.

Quoted 4 lines

What would it take to make these kind of special arrangements unnecessary? On what level would the changes have to happen? In udev, or in the kernel perhaps? In whose court is the ball on this matter?

This is kernel issue. And adding ID table is not enough because PNP subsystem does not support modalias (at least here, 2.6.15.6, it is missing). So you still need the above hack even if module properly defines aliases.

- -andrey
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (GNU/Linux)

iD8DBQFEDqYlR6LMutpd94wRAmGtAJwOZ8pUaeKvOOYotAoearVIKHsRSwCfTO+I lZ8gkVdgM5hN8H3NCpUXu60=Sa0X
-----END PGP SIGNATURE-----

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#10 lore raw
In reply to [email protected]

Returning again to the module autoloading issue.

First of all, thank you very much for the help! :) I've managed to exile hotplug from my system.

I still have a question, though: Does autoloading modules & firmware with udev also work with kernels older than 2.6.15?

Sincerelly,
Juuso Alasuutari

----------------------------------------------------------------
This mail sent through L-secure: http://www.l-secure.net/

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#11 lore raw
In reply to [email protected]
Quoted 7 lines · On Fri, Mar 31, 2006 at 11:52:25PM +0300, [email protected]…

Returning again to the module autoloading issue.

First of all, thank you very much for the help! :) I've managed to exile hotplug from my system.

I still have a question, though: Does autoloading modules & firmware with udev also work with kernels older than 2.6.15?

Yes, it should.

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel