转自:http://blog.chinaunix.net/uid-20564848-id-186359.html
android如何在init.rc中添加/dev/字符设备节点创建权限
system/core/init/init.c
system/core/init/keywords.h:77: KEYWORD(device, COMMAND, 4, do_device)
do_device
add_devperms_partners
/init.rc中我们可以为/dev/下具体设备节点的当被创建时,控制信息
on early-init
device /dev/gpio 644 system wifi
device /dev/snd* 664 system audio
其中*表示prefix为1,没有*表示prefix为0[luther.gliethttp]
上面的device关键字后面的system和wifi字符串描述对应的id为
static struct android_id_info android_ids[] = {
{ "root", AID_ROOT, },
{ "system", AID_SYSTEM, },
{ "radio", AID_RADIO, },
{ "bluetooth", AID_BLUETOOTH, },
{ "graphics", AID_GRAPHICS, },
{ "input", AID_INPUT, },
{ "audio", AID_AUDIO, },
{ "camera", AID_CAMERA, },
{ "log", AID_LOG, },
{ "compass", AID_COMPASS, },
{ "mount", AID_MOUNT, },
{ "wifi", AID_WIFI, },
{ "dhcp", AID_DHCP, },
{ "adb", AID_ADB, },
{ "install", AID_INSTALL, },
{ "media", AID_MEDIA, },
{ "shell", AID_SHELL, },
{ "cache", AID_CACHE, },
{ "diag", AID_DIAG, },
{ "net_bt_admin", AID_NET_BT_ADMIN, },
{ "net_bt", AID_NET_BT, },
{ "sdcard_rw", AID_SDCARD_RW, },
{ "", AID_VPN, },
{ "keystore", AID_KEYSTORE, },
{ "inet", AID_INET, },
{ "net_raw", AID_NET_RAW, },
{ "net_admin", AID_NET_ADMIN, },
{ "misc", AID_MISC, },
{ "nobody", AID_NOBODY, },
};
// =======================================
system/core/init/init.c
int main(int argc, char **argv)
{
......
INFO("reading config file\n");
parse_config_file("/init.rc");
/* pull the kernel commandline and ramdisk properties file in */
qemu_init();
import_kernel_cmdline(0);
get_hardware_name();
snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware);
parse_config_file(tmp);
// 需要在on early-init加入device
// 这样下面的device_init();创建节点动作
// 才会根据这里的对device设备的描述创建出相应权限的节点[luther.gliethttp]
action_for_each_trigger("early-init", action_add_queue_tail);
drain_action_queue();
// 因为device_init()将依赖sysfs文件系统提供的uevent机制
// 对builtin到kernel中的所有char,block,net等设备,
// 在/dev/目录下动态创建出对应的节点,此时会使用到
// init.rc中device添加的内容device信息,
// 因此device命令必须添加到early-init字段中
// 即[luther.gliethttp]
// on early-init
// device /dev/gpio 644 system wifi
// device /dev/snd* 644system audio
INFO("device init\n");
device_fd = device_init();
......
}
当需要修改,添加,删除系统的启动项时,可以通过修改根目录下的init.rc解决。如添加新设备的系统权限chmod 755 dev/video3等。
直接修改会有主要的2个问题,一是没有vi编辑器,二是权限不够。但可按一下步骤修改:
1:将init.rc文件pull出来
2:修改
3:在android的shell下执行mount -o rw -o remount /dev/block/actb /
4:将修改好的init.rc文件push到根目录下
相关链接:http://blog.csdn.net/yiyaaixuexi/article/details/6803593