This article is the sixth article in the Android Kernel Development series, and the previous articles cover the basics of Android kernel development, including: Download of Android source code, introduction of versions and branches, compilation and burning, etc. Starting from this article, we will start to really do the Android kernel learning and actual combat.
Learn any hardware and software systems, research system startup process is a very effective way to start, to engage in Android kernel development is no exception. There are many articles on the Internet for Android launch related code analysis and the daytime, we can first search to read, I personally prefer a more intuitive way to understand the unknown, including graphs, tables, system output log information, and so on, This article is going to explore the Android startup process with some flowchart and log information.
First of all, give a picture, the image from here, I think it draws very well, it is quoted, to help you understand and analyze.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/1C/wKioL1V0NLqz5WkHAAFZtLWnJvI406.jpg "title=" 1.png " alt= "Wkiol1v0nlqz5wkhaafztlwnjvi406.jpg"/>
First stage: After the Android device is powered on, the first boot code starts from the processor ROM, and the on-chip ROM looks for the bootloader code and loads it into memory. (This step is designed and implemented by "chip manufacturers " )
Phase two: Bootloader begins execution, first responsible for completing the initialization of the hardware, then locating the Linux kernel code and loading it into memory. (This step is designed and implemented by the "equipment Manufacturer")
Phase III: The Linux kernel starts, initializes various hardware and software environments, loads the driver, mounts the root filesystem, and executes the INIT program, which opens up the Android world. (This step is where the Android kernel needs to be involved in the development process)
Android and Major Linux distributions, their Linux kernel part of the boot process is similar, the biggest difference between them is the INIT program is different, because the INIT program determines the system during the boot process, which daemons and services will start, And how a user UI interface is presented.
Therefore, the INIT program is the most core program in analyzing the Android startup process.
The corresponding code is located at: system/core/init/init.c, the work content (picture from "Embedded Android" this book):
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/20/wKiom1V0M1eT5QMVAAGjy48aLpE827.jpg "title=" 2.png " alt= "Wkiom1v0m1et5qmvaagjy48alpe827.jpg"/>
The core work of the INIT program is mainly 3 points:
(1) Create and mount some system directories/device nodes, set permissions such as:/dev,/proc, And/sys
(2) Parse init.rc and init.
(3) Display boot logo, the default is "Android" word
The most important step is the second step, when a series of Android services are started, in fact, the most important process of booting the Android system is the start of each system service, because all the functions of the system depend on these services to complete , such as launching applications, making calls, using WiFi or Bluetooth, playing audio and video, and so on, as long as these services can start normally and work properly, the entire Android system has completed its own boot.
These services include 2 parts, part of the local service, and the Android service, all of which will want to ServiceManager process registration, which is managed by it, and the startup process of these services is described as follows:
(1) Local Service
Local service refers to the system daemon running on the C + + layer, and part of the local service is initiated directly by the Init process, which is defined in init.rc scripts and init.
We can find out exactly what local services were started directly by the INIT process by looking at the init.rc and init.
Note that each local service initiated directly by Init is a standalone Linux process , and after the system is booted, after we enter the phone through the adb shell command, enter the top command to see the presence of these local processes:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6E/20/wKiom1V0M3mRuBOAAAiGldvIXg0202.jpg "title=" 3.png " alt= "Wkiom1v0m3mruboaaaigldvixg0202.jpg"/>
(2) Android service
Android services are services that run in the Dalvik virtual machine process, and the creation process of these services is described as follows:
The INIT process executes the app_process program, creating the zygote process, which is the most important process for the Android system, and all subsequent Android applications are forked out.
The zygote process will first fork out the "systemserver" process, and the full task of the "Systemserver" process is to start up all Android core Services, including:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6E/20/wKiom1V0M6KDKc28AAUZgS6gxZ0002.jpg "title=" 4.png " alt= "Wkiom1v0m6kdkc28aauzgs6gxz0002.jpg"/>
When all services are started, Systemserver prints out "Making services Ready" and then launches the home interface via Activitymanager and sends a "action_boot_completed" broadcast message.
Note that these Android services do not run in separate processes, they are created as threads by Systemserver, so they all run in the same process , that is, in the Systemserver process .
(3) Summary
Some of the above pictures I always feel not enough to enjoy, so the article finally, give a picture to help you deepen understanding, this picture from the improving the Boot time of the Android OS this paper.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6E/1C/wKioL1V0NWmiHTYHAAJuMBfXId4365.jpg "title=" 123. PNG "alt=" wkiol1v0nwmihtyhaajumbfxid4365.jpg "/>
About the start-up process of the graphical Android system is introduced here, have any questions or suggestions welcome message or letter [email protected] exchange, or follow my Sina Weibo @ Lu _ June to get the latest articles and information.
This article is from the "Shadow Three People" blog, please be sure to keep this source http://ticktick.blog.51cto.com/823160/1659473
Android Kernel development: Diagram of the Android system startup process