More Related Content Similar to Android+init+process Similar to Android+init+process (20) Android+init+process3. 안드로이드init은 루트에 위치하기때문에 반드시 커널 부팅옵션에서 “init=/init”옵션이 주어져야 한다.< kernel/init/main.c > static intnoinlineinit_post(void) { ... if (execute_command) { run_init_process(execute_command); printk(KERN_WARNING "Failed to execute %s. Attempting " "defaults...", execute_command); } run_init_process("/sbin/init"); run_init_process("/etc/init"); run_init_process("/bin/init"); run_init_process("/bin/sh"); panic("No init found. Try passing init= option to kernel."); } 22. 정적 디바이스 파일 생성 flow< init.c > device_fd = device_init(); main() < devices.c > device_init() coldboot() do_coldboot() devperms구조체를 참조하여 uevent강제발생 Hot Plug handle_device_fd() handle_device_event() make_device() 27. import_kernel_cmdline에서 읽어온값 설정< android/system/core/init/init.c > int main(intargc, char **argv) { … if (qemu[0]) import_kernel_cmdline(1); if (!strcmp(bootmode,"factory")) property_set("ro.factorytest", "1"); else if (!strcmp(bootmode,"factory2")) property_set("ro.factorytest", "2"); else property_set("ro.factorytest", "0"); property_set("ro.serialno", serialno[0] ? serialno : ""); property_set("ro.bootmode", bootmode[0] ? bootmode : "unknown"); property_set("ro.baseband", baseband[0] ? baseband : "unknown"); property_set("ro.carrier", carrier[0] ? carrier : "unknown"); property_set("ro.bootloader", bootloader[0] ? bootloader : "unknown"); property_set("ro.hardware", hardware); snprintf(tmp, PROP_VALUE_MAX, "%d", revision); property_set("ro.revision", tmp); … } 31. early-boot, boot섹션을 실행큐에 담고 수행한다.< android/system/core/init/init.c > int main(intargc, char **argv) { … /* make sure we actually have all the pieces we need */ if ((device_fd < 0) || (property_set_fd < 0) || (signal_recv_fd < 0)) { ERROR("init startup failure"); return 1; } /* execute all the boot actions to get us started */ action_for_each_trigger("early-boot", action_add_queue_tail); action_for_each_trigger("boot", action_add_queue_tail); drain_action_queue(); … } 35. early-boot, boot섹션을 실행큐에 담고 수행한다.< android/system/core/init/init.c > int main(intargc, char **argv) { … structpollfdufds[4]; … ufds[0].fd = device_fd; ufds[0].events = POLLIN; ufds[1].fd = property_set_fd; ufds[1].events = POLLIN; ufds[2].fd = signal_recv_fd; ufds[2].events = POLLIN; fd_count = 3; if (keychord_fd > 0) { ufds[3].fd = keychord_fd; ufds[3].events = POLLIN; fd_count++; } else { ufds[3].events = 0; ufds[3].revents = 0; } … } 37. 안드로이드boot process 분석을위해 관련 데이터들을 수집한다.< android/system/core/init/init.c > int main(intargc, char **argv) { … i#f BOOTCHART bootchart_count = bootchart_init(); if (bootchart_count < 0) { ERROR("bootcharting init failure"); } else if (bootchart_count > 0) { NOTICE("bootcharting started (period=%d ms)", bootchart_count*BOOTCHART_POLLING_MS); } else { NOTICE("bootcharting ignored"); } #endif … for(;;) { #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 … } … }