Re: automatic driver loading functionality in Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ozan Türkyılmaz wrote:
26.01.2010 17:42, Greg KH yazmış:
On Sun, Jan 24, 2010 at 10:49:24AM +0530, Joel Fernandes wrote:
Hi Peter,

Thanks for your message.
Actually I'm interested in how modprobe autoloads modules based on the
modalias files in sysfs. I read this in Greg KH's great book - Linux Kernel in a Nutshell and I've been wondering how the modules would get loaded if they had to be loaded in the first place to have the device->module list to
exist.

modprobe is "smart" and knows what modules support what devices based on
the cache it creates when you run 'depmod' when a new kernel is
installed.


is it possible to get that information (what module determines what
driver) from modprobe.

(sorry for the problem Greg KH. i hit the wrong button)
Hi,
modinfo should give you all the information you need.

For example:
- modinfo my_module

filename:       ./my_module.ko
license:        GPL
srcversion:     00C7B5EE66E00EC3C91D3D9
alias:          usb:v0EA0p2168d*dc*dsc*dp*ic*isc*ip*
depends:        usbcore
vermagic:       2.6.24-19-generic SMP mod_unload 586

alias field indicate alias for this module (based on usb_device_id table in source file).

When you execute "depmod -a" the following line is added to /lib/modules/<kernel name>/modules.alias:
alias usb:v0EA0p2168d*dc*dsc*dp*ic*isc*ip* my_module

where:
v     idVendor
p     idProduct
d     bcdDevice
dc    bDeviceClass
dsc   bDeviceSubClass
dp    bDeviceProtocol
ic    bInterfaceClass
isc   bInterfaceSubClass
ip    bInterfaceProtocol


This line says that if I do:
modprobe usb:v0EA0p2168[remaining fields filled with whatever we like]
so in practice I can do:
modprobe usb:v0EA0p2168d0200dc00dsc00dp00ic08isc06ip50
to load my_module.

NOTE: in this example I used USB sub-system but all this applies to other sub-systems(PCI, PCMCIA, ...),
vendor and product id are fictitious.

All this stuff is here to allow udev do the right thing.
For example you can add the following line to /etc/udev/rules.d/90-modprobe.rules:
ENV{MODALIAS}=="?*", RUN+="/sbin/modprobe -Q $env{MODALIAS}"
so udev load the right module when you plug in the device.

You can check it by issuing the following command:

udevmonitor -e | grep MODALIAS

then when you plug the device you get:

MODALIAS=usb:v0EA0p2168d0200dc00dsc00dp00ic08isc06ip50

hope this helps
regards
Luca

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux