【发布时间】:2009-04-23 18:48:42
【问题描述】:
我正在尝试使用一个有点旧的 DAQ,并且不得不跳过几个环节来获得一个旧的(大约 2004 年)设备驱动程序来编译它 (DTI-DT340 Linux-DAQ-PCI)。
我已经到了编译的地步,我可以加载内核模块,它找到卡,我可以使用 mknod 创建字符设备。
但是当我尝试打开这些设备时,我似乎无法打开这些设备并不断收到errno 19 (ENODEV) 'No such device'
open("/dev/dt340/0",O_RDWR);
但是 mknod 对制作它没有任何抱怨,而且它就在那里:
# ls -l /dev/dt340/
total 0
crw-rw-r-- 1 root staff 250, 0 2009-04-23 11:02 0
crw-rw-r-- 1 root staff 250, 1 2009-04-23 11:02 1
crw-rw-r-- 1 root staff 250, 2 2009-04-23 11:02 2
crw-rw-r-- 1 root staff 250, 3 2009-04-23 11:02 3
有什么我忽略的事情吗?打开失败的原因可能是什么?
这是我用来加载驱动程序和制作设备的脚本。
#!/bin/bash
module="dt340"
device="dt340"
mode="664"
# invoke modprobe with all arguments we were passed
#/sbin/modprobe -t misc -lroot -f -s $module.o $* || exit 1
insmod $module.ko
# remove stale nodes
rm -f /dev/${device}/[0-3]
major=`awk "\\$2==\"$module\" {print \\$1}" /proc/devices`
mkdir -p /dev/${device}
mknod /dev/${device}/0 c $major 0
mknod /dev/${device}/1 c $major 1
mknod /dev/${device}/2 c $major 2
mknod /dev/${device}/3 c $major 3
# give appropriate group/permissions, and change the group
# not all distributions have staff; some have "users" instead
group="staff"
grep '^staff:' /etc/group > /dev/null || group="users"
chgrp $group /dev/${device}/[0-3]
chmod $mode /dev/${device}/[0-3]
一些附加信息:
#grep dt340 /proc/devices
250 dt340
# lsmod | grep dt340
dt340 21516 0
# tail /var/log/messages
Apr 23 11:59:26 ve kernel: [ 412.862139] dt340 0000:03:01.0: PCI INT A -> GSI 22 (level, low) -> IRQ 22
Apr 23 11:59:26 ve kernel: [ 412.862362] dt340: In function dt340_init_one:
Apr 23 11:59:26 ve kernel: [ 412.862363] Device DT340 Rev 0x0 detected at address 0xfebf0000
#lspci | grep 340
03:01.0 Multimedia controller: Data Translation DT340
回答:printk 确认 -ENODEV 是从 open() 内部抛出的。遵循旧式
while ((pdev = pci_find_device(PCI_VENDOR_ID_DTI, PCI_ANY_ID, pdev)))
(已弃用),if(!pdev) 最终为 true,并返回 -ENODEV。
我越来越近了——我想我必须努力更新 pci 代码以使用更现代的机制...
【问题讨论】:
-
你用的是udev还是老式的dev?这也会产生影响......
-
唯一的影响是提示进一步的问题“你为什么要手动创建设备节点?”;否则,没有区别。
-
驱动使用的是老式开发——这是我第一次深入研究设备驱动,所以我只是想尽可能多地使用已有的驱动
标签: c linux linux-kernel linux-device-driver kernel-module