如何利用udev为自己的驱动分配/dev下面的节点?
我使用了<<linux设备驱动>>的scull.ko, #insmod scull.ko后, 会有一个"/sys/module/scull"出现,
想利用udev的自动机制来生成/dev的节点, 编辑udev的规则,放入/etc/udev/rules.d/01-scull.rules,该文件内容为:
KERNEL=="scull", NAME="%k0", SYMLINK+="usbhd0"
但是当我insmod scull.ko时,在/dev目录下并没有生成/dev/scull0 节点,好像该机制没用,我不知道是不是哪里没有设置好,请教大家的解答!
谢谢!
用udevinfo得到的信息:
# udevinfo -a -p /sys/module/scull/
Udevinfo starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/module/scull':
KERNEL=="scull"
SUBSYSTEM=="module"
DRIVER==""
ATTR{initstate}=="live"
ATTR{refcnt}=="0"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
偶已经找到原因,但是是邮件的,懒得翻译了,各位见谅。
还有几个link给大家参考:http://www.chinaunix.net/jh/4/892777.html
http://www.deansys.com/doc/ldd3/ch14s05.html
http://www.deansys.com/doc/ldd3/ch14s07.html
I have found the reason. After editing udev rules, there is still some work to do in modules. It is mentioned in Linux Device Driver Chapter14. There should be a file "dev" in /sys/class for udev to make /dev entity. Like below:[email=root@freescale]root@[/email] /sys/class$ ll /sys/class/scull/scull1/
-r--r--r-- 1 root root 4096 Jan 1 05:12 dev
lrwxrwxrwx 1 root root 0 Jan 1 05:12 subsystem -> ../../../class/scull
--w------- 1 root root 4096 Jan 1 05:12 uevent
[email=root@freescale]root@[/email] /sys/class/scull/scull1$ cat dev
244:1
This "dev" file determine udev to create the major and minor number of a /dev node. And now there is a /dev node.[email=root@freescale]root@[/email] /sys/class/scull/scull1$ ll /dev/scull1
crw-rw---- 1 root root 244, 1 Jan 1 05:12 /dev/scull1
To make sure there is "dev" info. The main work is:1) In module init function,static struct class *scull_class; //globalint scull_init_module(void){.......... scull_class = class_create(THIS_MODULE, "scull");
if(IS_ERR(scull_class)){
printk(KERN_ERR "error creating scull class .\n");
goto fail;
}
class_device_create(scull_class, NULL, MKDEV(scull_major, 1), NULL, "scull%d", 1);
.............}The code will create a dir /sys/class/scull, then udev can use it to make a /dev node.2) In module cleanup function,
void scull_cleanup_module(void){
...
class_device_destroy(scull_class, MKDEV(scull_major, 1));
class_destroy(scull_class);
...
}
This work can replace "mknod" manually.
不好意思,这个只是在驱动代码里面就把dev node创建好了,udev rules还没有起作用
KERNEL=="scull", NAME="%k0", SYMLINK+="usbhd0"
本来应该创建scull0这个节点,但实际上/dev 下面只有scull1这个节点,因为是由这行代码创建的:
class_device_create(scull_class, NULL, MKDEV(scull_major, 1), NULL, "scull%d", 1);
为什么scull0不能创建出来,就算scull0因为和scull1冲突不能创建,为什么符号链接usbhd0也创建不了?