标题: usb_register_dev 沒有在/dev底下新增裝置節點 [打印本页] 作者: rockwalking 时间: 2015-1-12 09:58 标题: usb_register_dev 沒有在/dev底下新增裝置節點 Dear Firefly:
I encountered a problem for USB drivers that usb_register_dev do not create device under /dev
Here is the code
Static int flv_probe(struct usb_interface dev_if, …)
{
usb_set_intfdata(dev_if, &flv_class_driver);
retval = usb_register_dev(dev_if, &flv_class_driver);
if (retval != 0) {
/* something prevented us from registering this driver */
printk(KERN_INFO "%s() unable to get a minor for this device.\n", __func__);
usb_set_intfdata(dev_if, NULL);
goto _safe_exit;
}
}
The function usb_register_dev should create file not only under /sys/class/usbmisc/flv0, but under /dev/flv0.
However, I cannot see the device file under /dev.
I also refer to snd_register_device(), which successfully create device under /dev/snd, but can not find the key place.
Could you give me some suggestions? Thank you very much.
Thanks, 作者: rockwalking 时间: 2015-1-13 14:48
Android init process will ignore usb uevent, so please modified ~/$proj/system/core/init/device.c
...
if (!strncmp(uevent->subsystem, "usb", 3)) {
if (!strcmp(uevent->subsystem, "usb")) {
if (uevent->device_name) {
/*
* create device node provided by kernel if present
* see drivers/base/core.c
*/
char *p = devpath;
snprintf(devpath, sizeof(devpath), "/dev/%s", uevent->device_name);
/* skip leading /dev/ */
p += 5;
/* build directories */
while (*p) {
if (*p == '/') {
*p = 0;
make_dir(devpath, 0755);
*p = '/';
}
p++;
}
}
else {
/* This imitates the file system that would be created
* if we were using devfs instead.
* Minors are broken up into groups of 128, starting at "001"
*/
int bus_id = uevent->minor / 128 + 1;
int device_id = uevent->minor % 128 + 1;
/* build directories */
make_dir("/dev/bus", 0755);
make_dir("/dev/bus/usb", 0755);
snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id);
make_dir(devpath, 0755);
snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id);
}
} else {
/* ignore other USB events */ if(!strncmp(name, "flv",3)){
base = "/dev/";
}
else
return;
}
...作者: zhansb 时间: 2015-1-13 19:08
{:3_48:}nice作者: huoooooo 时间: 2017-1-18 11:05