jump to navigation

new way to manage your devices on Linux (udev-083+) (2) February 2, 2007

Posted by TSAI HONG-BIN in Linux.

There are two things about udev lie in userspace

1. device nodes

that’s the job udev used to work on. it helps create device nodes, according to rules defined in /etc/udev/rule.d/*.rule, under /dev.
for example:
KERNEL==”controlC[0-9]”, NAME=”snd/%k”
will create sound card device node under /dev/snd/, the file name will follow what kernel names it.

2. modules

udev now helps automatically load module, again, according to the rules. So if you’re a lazy bone, just write
ACTION==”add”, SUBSYSTEM==”?*”, ENV{MODALIAS}==”?*”, RUN+=”/sbin/modprobe $env{MODALIAS}”
and this should do the trick of coldplug (used to be dealt with by hotplug).
IMPORTANT: udev relies on modules.alias to load modules that match to the pci venderID, deviceID, instead of modules.pcmap, it should be faster because modalias is matched through wildcard. By the way, you should check the file modalias under somewhere like /sys/devices/pci0000:00/0000:00:10.0/modalias. your /sbin/modprobe should support probing module in the form of :

modprobe pci:v00001000d00000030sv00000000sd00000000bc01sc00i00

That’s how udev load modules, again, according to the rule. So if you define your rule in a strict way, you should be aware of the potential risk that  not all devices scanned will be driven (by udev).

And two things about udev lie in kernel

1. uevent

check kernel source ~/lib/kobject_uevent.c and you’ll find that it accepts hardawre signals “add, remove, mount ..blah.” That’s exactly what kernel’s uevent meant to do: throwing events by hardware change at run time. It places a file “uevent” under each device kernel sees under sysfs, and that’s the key to hotplug/coldplug. uevent is sent in netlink_socket fashion, that is, udev opens a socket to accept uevents, and then its job. All device nodes created, modules loaded by udev are triggered by udev, whether hotplugged or coldplugged. Note that there is still a difference, coldplug is invoked by triggering uevents (udevtrigger) after kernel stage.

2. kernel config

Since uevents communicates with userspace application, udev, through socket. [Unix domain socket] should be selected (UNIX=y), for hotplug you’ll need CONFIG_HOTPLUG=y, sysfs, procfs … as well. you can find the config how-to in detail from my former post.



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: