我正在尝试使用一个有点旧的 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)
最终为真,并返回 -ENODEV。
我越来越接近 - 我想我必须完成并更新 pci 代码以使用更现代的机制......
最佳答案
如果设备出现在/proc/devices 中,并且您确定您在 mknod 中得到了正确的数字,那么驱动程序本身拒绝打开。驱动程序可以从 open() 返回任何错误代码 - 包括“没有这样的设备”,如果它发现初始化硬件有问题,它可能会返回。
关于c - open() 返回 "No such device"错误,但是有这样的设备 (linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/783030/