免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3498 | 回复: 2
打印 上一主题 下一主题

如何利用udev为自己的驱动分配/dev下面的节点? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-05 15:28 |只看该作者 |倒序浏览
我使用了<<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"

论坛徽章:
0
2 [报告]
发表于 2008-06-05 19:06 |只看该作者
偶已经找到原因,但是是邮件的,懒得翻译了,各位见谅。
还有几个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; //global
int 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.

论坛徽章:
0
3 [报告]
发表于 2008-06-12 14:28 |只看该作者
不好意思,这个只是在驱动代码里面就把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也创建不了?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP