Android root file system startup process (detailed analysis of INIT process)

Source: Internet
Author: User

Start analyzing Android today
Root file system startup process.

When the Android system is started, "init =/init" is usually set in the kernel boot parameters. In this way, if the kernel is successfully mounted to the file system, the INIT program in the root directory is run first. What does this program do? We only have rfsc (readthe fucking source code )!!
The INIT program source code is in the android official source code system/CORE/INIT (my name is android2.3), and main is in init. C. Our analysis starts from main.

Init:

(1) install the sigchld signal. (If the parent process does not wait for the child process to end, the child process will become a zombie process, occupying system resources. Therefore, the sigchld signal must be processed to recycle the resources of the zombie process to avoid unnecessary waste of resources.

(2) reset umask.
What is umask, please see http://www.szstudy.cn/showArticle/53978.shtml

(3) create necessary folders for rootfs and mount appropriate partitions.
/Dev (tmpfs)
/Dev/PTS (devpts)
/Dev/socket
/Proc (Proc)
/Sys (sysfs)

(4) Create/dev/null and/dev/kmsg nodes.

(5) Parse/init. RC and add all service and operation information to the linked list.

(6) extract information kernel startup parameters from/proc/cmdline and save them to global variables.

(7) obtain the information hardware information and version number from the global variables obtained in the previous step. If not, extract the information from/proc/cpuinfo and save the information to the global variables.

(8) Select/init. (hardware). RC Based on the hardware information, parse and add the service and operation information to the linked list.

The author's root directory contains two/init. (hardware). RC: init. Goldfish. RC and init. ok6410.rc. The INIT program selects a resolution based on the hardware information obtained in the previous step.

(9) execute the command triggered by "early-init" in the linked list.

(10) traverse the/sys folder, which is a device addition event generated by the kernel (to automatically generate a device node ).

(11) initialize the property system and import the initialization property file.

(12) Obtain Ro. debuggable from the property system. If the value is 1, The keychord listener is initialized.

(13) Open the console. If the console is not specified in the cmdline, open the/dev/console.

(14) retrieve/initlogo. RLE (a memory of 565 RLE memory segments). If it succeeds, the logo is displayed in/dev/graphics/fb0, if the parameter is missing, set/dev/tty0 to text mode and enable/dev/tty0. Then, the text "android" is displayed.

(15) determine the number of rows in the Parameter Line and set the parameters in the attribute system:
1. If bootmode is
-Factory, set Ro. factorytest to 1
-Factory2: Set Ro. factorytest to 2.
-The value of other preset Ro. factorytest is 0.
2. If the serialno parameter exists, set Ro. serialno ""
3. If you have the bootmod parameter, set Ro. bootmod. Otherwise, it is "unknown"
4. If the baseband parameter is set, set Ro. baseband. Otherwise, set it to "unknown"
5. If the carrier parameter exists, set Ro. Carrier. Otherwise, it is "unknown"
6. If the bootloader parameter exists, set Ro. bootloader to "unknown"
7. Set Ro. Hardware and Ro. version through global variables (extracted from/proc/cpuinfo.

(16) all the actions that are triggered as init in the response line.

(17) Start the property service and fetch some property files. This action must be performed in the previous Ro. set Foo to/data/local. prop cannot commit to them.
-/System/build. Prop
-/System/Default. Prop
-/Data/local. Prop
-Obtain the presistent propertie after the primary node obtains the default property, in/data/property.

(18) create a messaging mechanism for the sigchld handler.

(19) confirm that all initialization is completed:
Device_fd (device init completed)
Property_set_fd (property Server start is complete)
Signal_recv_fd)

(20) all the actions that are triggered by the startup line as early-boot

(21) All the boot-triggered actions in the reboot line

(22) based on the previous Property Operation identifier, all the actions that are triggered as property in the response row

(23) Note:
-Device_fd
-Property_set_fd
-Signal_recv_fd
-If keychord exists, add keychord_fd.

(24) If bootchart is supported, the bootchart is initialized.

(25) Import progress cycle:
-Reset the acceptance of the zookeeper event. The revents value is 0.
-Query and execute the action details column.
-Services that require heavy failover
-Zookeeper: indicates the event of callback.
-If the revents of signal_recv_fd is Pollin, a message is obtained and processed.
-If the revents of device_fd is Pollin, the handler uses handle_device_fd.
-If the revents of property_fd is Pollin, the handler uses handle_property_set_fd.
-If the keychord_fd revents is Pollin, the handler uses handle_keychord.


This is android
Root file system startup process.

The author carefully analyzed what the INIT process has done, and understanding this is of great help for Android porting and custom products. Although it is traditional Chinese, I believe that everyone will read the meaning of the article, recommend it to Android Developers, and repost the linkHttp://crazier9527.javaeye.com/blog/454635

Source: http://blog.csdn.net/yimiyangguang1314/article/details/6281117

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.