Usage of uvent,bind and unbind interface in /sys
2012-07-31 17:11
204 查看
In /sys, there are many kobject which have the attribute of uevent. Mainly thay are used as the interface for communication between kenel and udev. To udev and the netlink protocol, they doesn’t have to access uevent file. But via the interface of the uevent
file, udevmonitor can send message from kernel to udevd, and it also can be used to check the environment variable of netlink messages which are support by this device. This attribute can be used by developer to debug udev script, and udevtrigger is also implemented
based on this interface.
These uevent file usually are writable, In /sys/device, there are many of them. In the latest version kernel, these files are also readable.
#find /sys –type f –name uevent -ls
11 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/uevent
1471 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/pcspkr/uevent
3075 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/vesafb.0/uevent
3915 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/serial8250/uevent
3941 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/serial8250/tty/ttyS2/uevent
3950 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/serial8250/tty/ttyS3/uevent 5204 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/i8042/uevent[...]
912 0 -rw-r–r– 1 root root 4096 Jan 12 21:17 /sys/devices/pci0000:00/0000:00:02.5/uevent
All these uevent file are writable and readable. The last item is uevent file of SCSI controller. The parameter which can be written are “add”, “remove”, “change”, “move”, “online” and “offline”.By writing “add”, it can sent a netlink message to udevd and
let udevd refresh the udev script file. This is very helpfult for developer to debug the udev script file.
# echo add > /sys/devices/pci0000:00/0000:00:02.5/uevent
In the /sys, there are many bind, unbind and new_id file for PCI device. Every device driver specified in the program which hardware this driver for, for example in the source code of driver, the MODULE_DEVICE_TABLE specifies the PCI hardware
PCI device id. If the hardware which is designed in future still can work in the mode of backward comptiable, then it still can use current driver. But before the interface of bind and unbind were implemented, we have to modify the DEVICE_TABLE of the source
code and recompile it. Besides this, there is no other solution. After the bind and unbind were added to kernel 2.6, we can bind the device driver and the hardware manually without the recompilation of the code.
In addition, to some hardware, there are several device drivers available, but at any certain time, there is only one driver running. We can use bind and unbind to decide which driver is running or not( For the choose of multiple drivers,the better way is
use modprobe.conf. It needs to be effective after reboot, but bind/unbind provide a temporary method witheout reboot). Via the interface of bind and unbind we can forcefully decide a device use certain driver or not.
#find /sys/-type f ( -name bind -or -name unbind -or -name new_id ) -ls
69 0 -rw-r–r– 1 root root 4096 Jan 12 22:12
/sys/devices/virtual/vtconsole/vtcon0/bind
3072 0 –w——- 1 root root 4096 Jan 12 22:15
/sys/bus/platform/drivers/vesafb/unbind
[...]
6489 0 –w——- 1 root root 4096 Jan 12 22:09
/sys/bus/pci/drivers/8139too/unbind
6490 0 –w——- 1 root root 4096 Jan 12 22:09
/sys/bus/pci/drivers/8139too/bind
6491 0 –w——- 1 root root 4096 Jan 12 22:15
/sys/bus/pci/drivers/8139too/new_id
# find /sys/bus/pci/drivers/8139too/ -ls
6435 0 drwxr-xr-x 2 root root 0 Jan 12 22:08
/sys/bus/pci/drivers/8139too/
6436 0 lrwxrwxrwx 1 root root 0 Jan 12 22:08
/sys/bus/pci/drivers/8139too/0000:00:0e.0 -> ../../../../devices/pci0000:00/0000:00:0e.0
6485 0 lrwxrwxrwx 1 root root 0 Jan 12 22:08
/sys/bus/pci/drivers/8139too/module -> ../../../../module/8139too
6488 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/uevent
6489 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/unbind
6490 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/bind
6491 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/new_id
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state
UNKNOWN qlen 1000
link/ether 00:14:2a:d1:16:72 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.102/24 brd 192.168.1.255 scope global eth0
3: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
# echo -n 0000:00:0e.0 > /sys/bus/pci/drivers/8139too/unbind
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
3: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
# echo -n 0000:00:0e.0 > /sys/bus/pci/drivers/8139too/bind
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
3: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state
DOWN qlen 1000
link/ether 00:14:2a:d1:16:72 brd ff:ff:ff:ff:ff:ff
This example shows how to bind and unbind the driver 8139too to device “0000:00:0e.0″ forcefully.
Write bus_id to unbind to cancal binding.
Write bus_id to bind to implement binding
Notes: Bus id is used for writing, for PCI Device, it meets following rules and it can be retrieved from the kobject node. To device of other kinds bus, it meets the rules of this kind of bus.
file, udevmonitor can send message from kernel to udevd, and it also can be used to check the environment variable of netlink messages which are support by this device. This attribute can be used by developer to debug udev script, and udevtrigger is also implemented
based on this interface.
These uevent file usually are writable, In /sys/device, there are many of them. In the latest version kernel, these files are also readable.
#find /sys –type f –name uevent -ls
11 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/uevent
1471 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/pcspkr/uevent
3075 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/vesafb.0/uevent
3915 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/serial8250/uevent
3941 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/serial8250/tty/ttyS2/uevent
3950 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/serial8250/tty/ttyS3/uevent 5204 0 -rw-r–r– 1 root root 4096 Jan 12 21:10 /sys/devices/platform/i8042/uevent[...]
912 0 -rw-r–r– 1 root root 4096 Jan 12 21:17 /sys/devices/pci0000:00/0000:00:02.5/uevent
All these uevent file are writable and readable. The last item is uevent file of SCSI controller. The parameter which can be written are “add”, “remove”, “change”, “move”, “online” and “offline”.By writing “add”, it can sent a netlink message to udevd and
let udevd refresh the udev script file. This is very helpfult for developer to debug the udev script file.
# echo add > /sys/devices/pci0000:00/0000:00:02.5/uevent
In the /sys, there are many bind, unbind and new_id file for PCI device. Every device driver specified in the program which hardware this driver for, for example in the source code of driver, the MODULE_DEVICE_TABLE specifies the PCI hardware
PCI device id. If the hardware which is designed in future still can work in the mode of backward comptiable, then it still can use current driver. But before the interface of bind and unbind were implemented, we have to modify the DEVICE_TABLE of the source
code and recompile it. Besides this, there is no other solution. After the bind and unbind were added to kernel 2.6, we can bind the device driver and the hardware manually without the recompilation of the code.
In addition, to some hardware, there are several device drivers available, but at any certain time, there is only one driver running. We can use bind and unbind to decide which driver is running or not( For the choose of multiple drivers,the better way is
use modprobe.conf. It needs to be effective after reboot, but bind/unbind provide a temporary method witheout reboot). Via the interface of bind and unbind we can forcefully decide a device use certain driver or not.
#find /sys/-type f ( -name bind -or -name unbind -or -name new_id ) -ls
69 0 -rw-r–r– 1 root root 4096 Jan 12 22:12
/sys/devices/virtual/vtconsole/vtcon0/bind
3072 0 –w——- 1 root root 4096 Jan 12 22:15
/sys/bus/platform/drivers/vesafb/unbind
[...]
6489 0 –w——- 1 root root 4096 Jan 12 22:09
/sys/bus/pci/drivers/8139too/unbind
6490 0 –w——- 1 root root 4096 Jan 12 22:09
/sys/bus/pci/drivers/8139too/bind
6491 0 –w——- 1 root root 4096 Jan 12 22:15
/sys/bus/pci/drivers/8139too/new_id
# find /sys/bus/pci/drivers/8139too/ -ls
6435 0 drwxr-xr-x 2 root root 0 Jan 12 22:08
/sys/bus/pci/drivers/8139too/
6436 0 lrwxrwxrwx 1 root root 0 Jan 12 22:08
/sys/bus/pci/drivers/8139too/0000:00:0e.0 -> ../../../../devices/pci0000:00/0000:00:0e.0
6485 0 lrwxrwxrwx 1 root root 0 Jan 12 22:08
/sys/bus/pci/drivers/8139too/module -> ../../../../module/8139too
6488 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/uevent
6489 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/unbind
6490 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/bind
6491 0 –w——- 1 root root 4096 Jan 12 22:08
/sys/bus/pci/drivers/8139too/new_id
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_fast state
UNKNOWN qlen 1000
link/ether 00:14:2a:d1:16:72 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.102/24 brd 192.168.1.255 scope global eth0
3: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
# echo -n 0000:00:0e.0 > /sys/bus/pci/drivers/8139too/unbind
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
3: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
# echo -n 0000:00:0e.0 > /sys/bus/pci/drivers/8139too/bind
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
3: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state
DOWN qlen 1000
link/ether 00:14:2a:d1:16:72 brd ff:ff:ff:ff:ff:ff
This example shows how to bind and unbind the driver 8139too to device “0000:00:0e.0″ forcefully.
Write bus_id to unbind to cancal binding.
Write bus_id to bind to implement binding
Notes: Bus id is used for writing, for PCI Device, it meets following rules and it can be retrieved from the kobject node. To device of other kinds bus, it meets the rules of this kind of bus.
相关文章推荐
- About the Rebase and Bind operation in the production of software
- Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
- The Usage of Lambda and Heap in the C++ STL
- usage of fscanf and other read functions in C/C++
- 【DataStructure】Descriptioin and usage of List
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary
- mysql 5.7 [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonag
- python inconsistent use of tabs and spaces in indentation
- [转]Sorting, Filtering, and Paging with the Entity Framework in an ASP.NET MVC Application (3 of 10)
- Daily paper -Science 2006: Experimental Study of Inequality and Unpredictability in an Artificial Cultural Market (探究群体行为对商品销量的影响)
- Ubuntu Touch Emulator: Installation And Usage In Ubuntu 14.04, 13.10 And 12.04
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- About the Usage of fseek and ftell
- The Default Methods And Static Methods In Java Interface
- Difference of px, dp, dip and sp in android
- [Android 問題] How to Add a Button in ListView, and Make the Event of onClick and onItemClick Coexist?
- inbound and outbound interface of COM
- Note: Time clocks and the ordering of events in a distributed system
- Change the Foreground and Background Colour of Staic Text Control in VC++
- Ray-ban Sunglasses: The Ultimate Name in the World of Sunglasses and Eyewear