#111
#112 if (qemu[0])
#113 import_kernel_cmdline(1);
這段代碼是用來判斷是否使用模擬器運行,如果時,就加載內核命令行參數。
#114
#115 if (!strcmp(bootmode,”factory”))
#116 property_set(“ro.factorytest”, “1”);
#117 else if (!strcmp(bootmode,”factory2″))
#118 property_set(“ro.factorytest”, “2”);
#119 else
#120 property_set(“ro.factorytest”, “0”);
這段代碼是根據內核命令行參數來設置工廠模式測試,比如在工廠生產手機過程裡需要自動化演示功能,就可以根據這個標志來進行特別處理。
#121
#122 property_set(“ro.serialno”, serialno[0] ? serialno : “”);
這段代碼是設置手機序列號到屬性裡保存,以便上層應用程序可以識別這臺手機。
#123 property_set(“ro.bootmode”, bootmode[0] ? bootmode : “unknown”);
這段代碼是保存啟動模式到屬性裡。
#124 property_set(“ro.baseband”, baseband[0] ? baseband : “unknown”);
這段代碼是保存手機基帶頻率到屬性裡。
#125 property_set(“ro.carrier”, carrier[0] ? carrier : “unknown”);
這段代碼是保存手機硬件載波的方式到屬性裡。
#126 property_set(“ro.bootloader”, bootloader[0] ? bootloader : “unknown”);
這裡是保存引導程序的版本號到屬性裡,以便系統知道引導程序有什麼特性。
#127
#128 property_set(“ro.hardware”, hardware);
這裡是保存硬件信息到屬性裡,其實就是獲取CPU的信息。
#129 snprintf(tmp, PROP_VALUE_MAX, “%d”, revision);
#130 property_set(“ro.revision”, tmp);
這裡是保存硬件修訂的版本號到屬性裡,這樣可以方便應用程序區分不同的硬件版本。
#131
#132 /* execute all the boot actions to get us started */
#133 action_for_each_trigger(“init”, action_add_queue_tail);
#134 drain_action_queue();
這段代碼是先把所有init命令添加隊列,然後再執行。
#135
#136 /* read any property files on system or data and
#137 * fire up the property service. This must happen
#138 * after the ro.foo properties are set above so
#139 * that /data/local.prop cannot interfere with them.
#140 */
#141 property_set_fd = start_property_service();
這段代碼是加載system和data目錄下的屬性,並啟動屬性監聽服務。
#142
#143 /* create a signalling mechanism for the sigchld handler */
#144 if (socketpair(AF_UNIX, SOCK_STREAM, 0, s) == 0) {
#145 signal_fd = s[0];
#146 signal_recv_fd = s[1];
#147 fcntl(s[0], F_SETFD, FD_CLOEXEC);
#148 fcntl(s[0], F_SETFL, O_NONBLOCK);
#149 fcntl(s[1], F_SETFD, FD_CLOEXEC);
#150 fcntl(s[1], F_SETFL, O_NONBLOCK);
#151 }
這段代碼是創建一個全雙工的通訊機制的兩個SOCKET,信號可以在signal_fd和signal_recv_fd雙向通訊,從而建立起溝通的管道。其實這個信號管理,就是用來讓init進程與它的子進程進行溝通的,子進程從signal_fd寫入信息,init進程從signal_recv_fd收到信息,然後再做處理。
#152
#153 /* make sure we actually have all the pieces we need */
#154 if ((device_fd < 0) ||
#155 (property_set_fd < 0) ||
#156 (signal_recv_fd < 0)) {
#157 ERROR(“init startup failure
“);
#158 return 1;
#159 }
這段代碼是判斷關鍵的幾個組件是否成功初始化,主要就是設備文件系統是否成功初始化,屬性服務是否成功初始化,信號通訊機制是否成功初始化。
#160
#161 /* execute all the boot actions to get us started */
#162 action_for_each_trigger(“early-boot”, action_add_queue_tail);
#163 action_for_each_trigger(“boot”, action_add_queue_tail);
#164 drain_action_queue();
這段代碼是執行early-boot和boot屬性的命令。
#165
#166 /* run all property triggers based on current state of the properties */
#167 queue_all_property_triggers();
#168 drain_action_queue();
這段代碼是根據當前屬性,運行屬性命令。
#169
#170 /* enable property triggers */
#171 property_triggers_enabled = 1;
這段代碼是標明屬性觸發器已經初始化完成。
#172
#173 ufds[0].fd = device_fd;
#174 ufds[0].events = POLLIN;
#175 ufds[1].fd = property_set_fd;
#176 ufds[1].events = POLLIN;
#177 ufds[2].fd = signal_recv_fd;
#178 ufds[2].events = POLLIN;
#179 fd_count = 3;
這段代碼是保存三個重要的服務socket,以便後面輪詢使用。
#180
#181 if (keychord_fd > 0) {
#182 ufds[3].fd = keychord_fd;
#183 ufds[3].events = POLLIN;
#184 fd_count++;
#185 } else {
#186 ufds[3].events = 0;
#187 ufds[3].revents = 0;
#188 }
這段代碼是判斷是否處理組合鍵輪詢。
#189
#190 #if BOOTCHART
#191 bootchart_count = bootchart_init();
#192 if (bootchart_count < 0) {
#193 &nbs