Android起動中init.cファイル分析
8514 ワード
ここにはmain関数の解析のみが貼られています.
Initの主な仕事:1、logシステムを初期化する2、initを解析する.rc init%hardware%.rcなどのファイル3、early-init action in the two files paresed in step 24、デバイス初期化を実行する、/devの下にすべてのデバイスノードを作成し、firmwares 5をダウンロードし、プロパティサーバを初期化し、Actually the property system is working as share memory.Logically it looks like a registry under windows system 6、init actionを実行するin the two files parsed in step 27、属性サービスを開く8、earl-boot and boot actionsを実行するin the two files parsed in step 29、Execute property action in the two files parsed in step 210を実行し、デッドサイクルに入り、to wait for device/property set/child process exit events.たとえば、SDカードが挿入されると、initはデバイス挿入イベントを受信し、そのデバイスにノードを作成します.システムの中で比較的に重要なプロセスはすべてinitからforkに来たので、もし彼らが誰かがクラッシュしたら、initはSIGCHALD信号を受け取って、この信号をサブプロセスの終了イベントに変換して、loopの中で、initはプロセスの終了イベントを操作して実行します*rcファイルで定義されたコマンド
Initの主な仕事:1、logシステムを初期化する2、initを解析する.rc init%hardware%.rcなどのファイル3、early-init action in the two files paresed in step 24、デバイス初期化を実行する、/devの下にすべてのデバイスノードを作成し、firmwares 5をダウンロードし、プロパティサーバを初期化し、Actually the property system is working as share memory.Logically it looks like a registry under windows system 6、init actionを実行するin the two files parsed in step 27、属性サービスを開く8、earl-boot and boot actionsを実行するin the two files parsed in step 29、Execute property action in the two files parsed in step 210を実行し、デッドサイクルに入り、to wait for device/property set/child process exit events.たとえば、SDカードが挿入されると、initはデバイス挿入イベントを受信し、そのデバイスにノードを作成します.システムの中で比較的に重要なプロセスはすべてinitからforkに来たので、もし彼らが誰かがクラッシュしたら、initはSIGCHALD信号を受け取って、この信号をサブプロセスの終了イベントに変換して、loopの中で、initはプロセスの終了イベントを操作して実行します*rcファイルで定義されたコマンド
int main(int argc, char **argv)
{
int fd_count = 0;
struct pollfd ufds[4];
char *tmpdev;
char* debuggable;
char tmp[32];
int property_set_fd_init = 0;
int signal_fd_init = 0;
int keychord_fd_init = 0;
if (!strcmp(basename(argv[0]), "ueventd"))
return ueventd_main(argc, argv);// ?
/* clear the umask */
umask(0);// , 777
/* Get the basic filesystem setup we need put
* together in the initramdisk on / and then we'll
* let the rc file figure out the rest.
*/
// ,tmpfs、proc、sysfs
mkdir("/dev", 0755);
mkdir("/proc", 0755);
mkdir("/sys", 0755);
mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755");
mkdir("/dev/pts", 0755);
mkdir("/dev/socket", 0755);
mount("devpts", "/dev/pts", "devpts", 0, NULL);
mount("proc", "/proc", "proc", 0, NULL);
mount("sysfs", "/sys", "sysfs", 0, NULL);
#ifdef INIT_ENG_BUILD
mount("debugfs", "/sys/kernel/debug", "debugfs", 0, NULL);
#endif
/* We must have some place other than / to create the
* device nodes for kmsg and null, otherwise we won't
* be able to remount / read-only later on.
* Now that tmpfs is mounted on /dev, we can actually
* talk to the outside world.
*/
// /dev/null ,
open_devnull_stdio();
// log /dev/kmsg
log_init();
// JK@MTK, add for AEE {
#ifdef HAVE_AEE_FEATURE
#ifdef AEE_CORE_DUMP
{
extern int aee_enable_core_dump(int);
if (aee_enable_core_dump(1) < 0) {
ERROR("enable core dump fail
");
}
}
#endif
// init.aee.rc
INFO("reading AEE config file
");
init_parse_config_file("/init.aee.rc");
#endif
// JK@MTK, add for AEE }
INFO("reading config file
");
#ifdef USE_BUILT_IN_FACTORY
if (is_factory_boot()) {// factory , init.factory.rc
// init.factory.rc init.rc
if (init_parse_config_file("/init.factory.rc") < 0)
init_parse_config_file("/init.rc");
} else {// init.rc
init_parse_config_file("/init.rc");
}
#else
init_parse_config_file("/init.rc");
#endif
/* pull the kernel commandline and ramdisk properties file in */
// ~
// proc/cmdline , :
// , ,uboot , init
//
import_kernel_cmdline(0);
// , /proc/cpuinfo 。
get_hardware_name(hardware, &revision);
snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware);
init_parse_config_file(tmp);
// early-init actions in the two files parsed in step2
action_for_each_trigger("early-init", action_add_queue_tail);
queue_builtin_action(wait_for_coldboot_done_action, "wait_for_coldboot_done");
queue_builtin_action(property_init_action, "property_init");
queue_builtin_action(keychord_init_action, "keychord_init");
queue_builtin_action(console_init_action, "console_init");
queue_builtin_action(set_init_properties_action, "set_init_properties");
/* execute all the boot actions to get us started */
// init actions in the two files parsed in step2
action_for_each_trigger("init", action_add_queue_tail);
action_for_each_trigger("early-fs", action_add_queue_tail);
action_for_each_trigger("fs", action_add_queue_tail);
action_for_each_trigger("post-fs", action_add_queue_tail);
queue_builtin_action(property_service_init_action, "property_service_init");
queue_builtin_action(signal_init_action, "signal_init");
queue_builtin_action(check_startup_action, "check_startup");
/* execute all the boot actions to get us started */
// early-boot and boot actions in the two files parsed in step2
action_for_each_trigger("early-boot", action_add_queue_tail);
action_for_each_trigger("boot", action_add_queue_tail);
/* run all property triggers based on current state of the properties */
queue_builtin_action(queue_property_triggers_action, "queue_propety_triggers");
#if BOOTCHART
queue_builtin_action(bootchart_init_action, "bootchart_init");
#endif
for(;;) {
int nr, i, timeout = -1;
execute_one_command();
restart_processes();
if (!property_set_fd_init && get_property_set_fd() > 0) {
ufds[fd_count].fd = get_property_set_fd();
ufds[fd_count].events = POLLIN;
ufds[fd_count].revents = 0;
fd_count++;
property_set_fd_init = 1;
}
if (!signal_fd_init && get_signal_fd() > 0) {
ufds[fd_count].fd = get_signal_fd();
ufds[fd_count].events = POLLIN;
ufds[fd_count].revents = 0;
fd_count++;
signal_fd_init = 1;
}
if (!keychord_fd_init && get_keychord_fd() > 0) {
ufds[fd_count].fd = get_keychord_fd();
ufds[fd_count].events = POLLIN;
ufds[fd_count].revents = 0;
fd_count++;
keychord_fd_init = 1;
}
if (process_needs_restart) {
timeout = (process_needs_restart - gettime()) * 1000;
if (timeout < 0)
timeout = 0;
}
if (!action_queue_empty() || cur_action)
timeout = 0;
#if BOOTCHART
if (bootchart_count > 0) {
if (timeout < 0 || timeout > BOOTCHART_POLLING_MS)
timeout = BOOTCHART_POLLING_MS;
if (bootchart_step() < 0 || --bootchart_count == 0) {
bootchart_finish();
bootchart_count = 0;
}
}
#endif
nr = poll(ufds, fd_count, timeout);
if (nr <= 0)
continue;
for (i = 0; i < fd_count; i++) {
if (ufds[i].revents == POLLIN) {
if (ufds[i].fd == get_property_set_fd())
handle_property_set_fd();
else if (ufds[i].fd == get_keychord_fd())
handle_keychord();
else if (ufds[i].fd == get_signal_fd())
handle_signal();
}
}
}
return 0;
}
init解析のスクリプトファイルinit.rcファイルの構造分析は私のブログを参考にすることができます.http://blog.csdn.net/yinwei520/article/details/6598453