我对 Linux 内核编程非常陌生。我通过阅读Greg 的代码创建了一个简单的 USB 驱动程序;如果需要,可以查看我的完整代码。
据我所知,这段代码可以从 USB 设备读取数据和写入数据。但是当我连接我的 pendrive 时,我看到了dmesg
踪迹,我发现一切正常,但无法在lsblk
.
由于它不在那里,我无法安装它,因此无法测试我的驱动程序。这是dmesg
痕迹
[20073.437683] [SIMUSB]:Module Loaded
[20073.437730] [SIMUSB] USB Detected
[20073.437734] [SIMUSB] USB Vendor ID=1008 and Product ID=22023
[20073.437737] [SIMUSB] endpoint->bEndpointAddress=1
[20073.437740] [SIMUSB] Result of endpoint->bEndpointAddress & USB_DIR_OUT is 0
[20073.437743] [SIMUSB] ENDPOINT WITH OUT DIRECTION FOUND
[20073.437746] [SIMUSB] Result of endpoint->bmAddress & USB_ENDPOINT_XFERTYPE_MASK is 2
[20073.437749] [SIMUSB] OUT ENDPOINT adress set
[20073.437752] [SIMUSB] endpoint->bEndpointAddress=130
[20073.437755] [SIMUSB] Result of endpoint->bEndpointAddress & USB_DIR_IN is 128
[20073.437757] [SIMUSB] ENDPOINT WITH IN DIRECTION FOUND
[20073.437760] [SIMUSB] Result of endpoint->bmAddress & USB_ENDPOINT_XFERTYPE_MASK is 2
[20073.437763] [SIMUSB] IN ENDPOINT adress set
[20073.437910] [SIMUSB] status=0
[20073.437914] [SIMUSB] USB Registered Successfully
usb_register_dev()
只是在in之后添加了一行sim_prob
printk(KERN_INFO "[SIMUSB] retval=%d",retval);
我得到以下命令输出demsg|grep SIMUSB
root@anandlinux:/lin_dev/kprogs/usb_rough# dmesg|grep SIMUSB
[7803.843992] [SIMUSB]:Module Loaded
[7803.844055] [SIMUSB] USB Detected
[7803.844060] [SIMUSB] USB Vendor ID=2385 and Product ID=5699
[7803.844064] [SIMUSB] endpoint->bEndpointAddress=129
[7803.844069] [SIMUSB] Result of endpoint->bEndpointAddress & USB_DIR_IN is 128
[7803.844073] [SIMUSB] ENDPOINT WITH IN DIRECTION FOUND
[7803.844077] [SIMUSB] Result of endpoint->bmAddress & USB_ENDPOINT_XFERTYPE_MASK is 2
[7803.844080] [SIMUSB] IN ENDPOINT adress set
[7803.844085] [SIMUSB] endpoint->bEndpointAddress=2
[7803.844089] [SIMUSB] OUT ENDPOINT adress set
[7803.844156] [SIMUSB] retval=0
[7803.844186] [SIMUSB] status=0
[7803.844188] [SIMUSB] USB Registered Successfully
root@anandlinux:/lin_dev/kprogs/usb_rough#