Android 啟動分析-init進程&init.rc[轉]
本文轉自: http://h1372865100.blog.163.com/blog/static/210429103201292911399594/
首先是 init 進程啟動
(一些 native 服務啟動)
如: servicemanager 啟動
Zygote 啟動
SysytemServer 啟動,在
init1
init2 函數中啟動 Android 服務
init 進程起來後,解析 init.rc 和 init.xxx.rc 建立基本的服務
之後進入迴圈,並沒有退出
分析 init.c@/system/core/init 的 main 函數主要實現過程
...
mkdir("/dev", 0755) // 建立具有可讀寫的目錄 ” /dev “
。。。
log_init(); // 初始化 log 系統
。。。
parse_config_file("/init.rc"); /* 解析 init.rc 檔案, parse_config_file 這個 函數是在 /system/core/init/parse.c 這個類中實現的,講解析得到的 service 資訊儲存到
service_list 這個資料解構中 */
get_hardware_name();
snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware);
parse_config_file(tmp); /* 解析 init.xxx.rc ,和硬體相關 */
action_for_each_trigger("early-init", action_add_queue_tail);
drain_action_queue(); /* 執行解析得到的” early-init ”的 action*/
INFO("device init/n");
device_fd = device_init(); /* 裝置的初始化。掛載結點倒 /dev 下還有下載
firmwares*/
property_init();
。。。 /*property 初始化 */
/* 讀取 /initlogo.rle (一張位元影像),如果成功則在 /dev/graphics/fb0 顯示 Logo, 如果失敗則將 /dev/tty0, 設為 TEXT 模式並開啟 /dev/tty0, 輸出文本 ANDROID 。具體實現可看
/system/core/init/log.c
*/
if( load_565rle_image(INIT_IMAGE_FILE) ) {
fd = open("/dev/tty0", O_WRONLY);
if (fd >= 0) {
。。。
。。。
}
/* 判斷 cmdline 中的參數,並設定屬性系統中的參數 :
* 1 、 如果 bootmode 為
* - factory, 設定 ro.factorytest 值為 1
* - factory2, 設定 ro.factorytest 值為 2
* - 其他的設 ro.factorytest 值為 0
* 2 、如果有 serialno 參數,則設定 ro.serialno ,否則為 ""
* 3 、如果有 bootmod 參數,則設定 ro.bootmod ,否則為 "unknown"
* 4 、如果有 baseband 參數,則設定 ro.baseband ,否則為 "unknown"
* 5 、如果有 carrier 參數,則設定 ro.carrier ,否則為 "unknown"
* 6 、如果有 bootloader 參數,則設定 ro.bootloader ,否則為 "unknown"
* 7 、通過全域變數(前面從 /proc/cpuinfo 中提取的)設定 ro.hardware 和 ro.version 。
*/
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);
action_for_each_trigger("init", action_add_queue_tail);
drain_action_queue(); /* 執行解析得到的 init action */