自己写了一个USB Power Control的驱动,并杯具的给节点的名字取为 usb_power_control
在Android里面整了半天不出来,自己不能创建 /dev/usb_power_control 这个节点,但是手动创建可以成功
最后只好从文件系统入手,找原因,
Android 的驱动节点创建是由 init 这个进程完成的,
init 这个进程在创建设备节点的时候,会对以“usb”为开头的设置节点进行了过滤,具体代码在:
system/core/init/devices.c
if (!strncmp(uevent->subsystem, "usb", 3)) {
if (!strcmp(uevent->subsystem, "usb")) {
/* 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 */
mkdir("/dev/bus", 0755);
mkdir("/dev/bus/usb", 0755);
snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id);
mkdir(devpath, 0755);
snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id);
devpath_ready = 1;
} else {
/* ignore other USB events */
return;
}
} else if (!strncmp(uevent->subsystem, "graphics", 8)) {
修改这个地方就可以自动创建/dev/usb_power_control 等以usb 开头的设备节点了。
if (!strncmp(uevent->subsystem, "usb", 3)) {
if(!strcmp(!strncmp(name, "usb_power_control", 17)){ //add by tianfeng for usb power control
base = "/dev/";
}else if(!strcmp(!strncmp(name, "hiddev", 6)){ //add by tianfeng for /dev/usb/hiddev0
base = "/dev/usb";
mkdir("/dev/usb", 0755);
}else if (!strcmp(uevent->subsystem, "usb")) {
/* 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 */
mkdir("/dev/bus", 0755);
mkdir("/dev/bus/usb", 0755);
snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id);
mkdir(devpath, 0755);
snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id);
devpath_ready = 1;
} else {
/* ignore other USB events */
return;
}
} else if (!strncmp(uevent->subsystem, "graphics", 8)) {
hiddev 这个节点不能创建也跟这个有关~~