Android Startup process In-depth analysis

Source: Internet
Author: User
Keywords Can boot program kernel nbsp;

The article by Bole Online-the top of the Sea of clouds translated from Kpbird. Welcome to the Android team. Please refer to the request at the end of the article.

What happens when you press the power button on the Android device? What is the startup process for Android? What is the Linux kernel? What is the difference between the Linux kernel of the desktop system and the Linux kernel of the Android system? What is a bootstrap loader? What is Zygote? What is X86 and arm Linux? What is init.rc? What is a system service?

When we think of the Android startup process, there is always a lot of doubt in our minds. This article will introduce the Android startup process, hoping to help you find answers to these questions.

Android is a Linux based open source operating system. x86 (x86 is a series of Intel 8086 CPU based computer microprocessor instruction set architecture) is the most common system for Linux kernel deployment. However, all Android devices are running on the ARM processor (arm originates from the advanced compact instruction set machine, originating from the ARM architecture), except for Intel's Xolo device (http://xolo.in/xolo-x900-features). Xolo source from the 1.6GHz x86 processor. The startup process of an Android device or an embedded device or a linux-based arm device is slightly different than a desktop version. In this article, I'll explain the startup process for Android devices. Going into the Linux startup process is a good article on the desktop Linux startup process.

When you press the POWER switch, the Android device performs the following steps.

First step: Power Up and system boot

When the power is pressed, the boot chip code begins to execute from the predefined place (curing in ROM). Load the bootstrapper into RAM, and then execute.

Step two: Bootstrapper

The bootstrapper is a small program before the Android operating system begins to run. The bootstrapper is the first program to run, so it is specific to the motherboard and chip. Device manufacturers either use popular boot programs such as Redboot, Uboot, Qi bootloader, or develop their own bootstrapper, which is not part of the Android operating system. The boot program is where the OEM manufacturer or operator locks and restricts it.

The bootstrapper executes in two phases. The first phase detects external RAM and loads programs that are useful for the second phase, and the second stage, the boot program sets up the network, memory, and so on. These are necessary for running the kernel, and in order to achieve a specific goal, the bootstrapper can set the kernel based on configuration parameters or input data.

The Android bootstrapper can be found in \bootable\bootloader\legacy\usbloader.
The traditional loader contains a file that needs to be described here:

Init.s Initialize Stack, clear 0 BBS segment, call MAIN.C _main () function, MAIN.C Initialize hardware (alarm clock, motherboard, keyboard, console), create Linux label.

More about Android Bootstrapper can be learned here.

Third step: Kernel

The Android kernel starts with the desktop Linux kernel in much the same way. When the kernel is started, set the cache, Protected Storage, schedule list, load driver. When the kernel completes the system setup, it first looks for the "init" file in the system file and then starts the root process or the first process of the system.

Step Fourth: Init process

Init is the first process, which we can say is the root process or the parent process of the process. The INIT process has two responsibilities, one is to mount the directory, such as/sys,/dev,/proc, and the second is to run the init.rc script.

The

init process can be found in/system/core/init. init.rc files can be found in/system/core/rootdir/init.rc. Readme.txt can be found in/system/core/init/readme.txt.

For init.rc files, there are specific formats and rules for Android. In Android, we call the Android initialization language.
The Android initialization language consists of four types of declarations, actions, Commands (commands), services (services), and options.
Action: The action is named after the command process, and a trigger determines whether the action occurs.
Syntax

1234on <trigger> <command> <command> <command>

Service (Service): Services are programs that are started by the Init process, and the INIT process restarts services as appropriate when the service exits.
Syntax

1234service <name> <pathname> [<argument>]* <option> <option> ...

Options (option)
option is a description of the service. They affect how and when the init process starts the service.
Let's take a look at the default init.rc file. Here I only list the main events and services.
Table

Action/service describes the precedence of the on Early-init setting up the init process and the subprocess it creates, setting the security environment for the INIT process on INIT setting the global environment, creating Cgroup for CPU Accounting (resource control) Mount point on FS Mount MTD partition on Post-fs Change access to system directory on Post-fs-data change/data directory and its subdirectories access rights on boot basic network initialization, memory management, etc. service ServiceManager start the System Manager to manage the local services, such as location, audio, Shared preference, and so on ... service zygote start zygote as application process

At this stage you can see the "Android" logo on the device screen.

Fifth Step

In Java, we know that different virtual machine instances allocate different memory for different applications. If Android apps should start as quickly as possible, if the Android system starts a different Dalvik virtual machine instance for each application, it consumes a lot of memory and time. Therefore, to overcome this problem, the Android system created "Zygote". Zygote makes it possible for Dalvik virtual machines to share code, low memory footprint, and minimal startup time. Zygote is a VM process, as we said in the previous step when the system boots. Zygote preload and initializes the core library class. Typically, these core classes are generally read-only and are part of the Android SDK or core framework. In a Java virtual machine, each instance has its own copy of its core library class files and heap objects.

Zygote Loading process

Loading Zygoteinit class, source code:/frameworks/base/core/java/com/android/internal/os/zygoteinit.javaregisterzygotesocket () Registers a server socket for the zygote command connection. Preloadclassed "Preloaded-classes" is a simple text file containing a series of preload classes you can find in <android source>/frameworks/base Preloaded-classes file. Preloadresources () Preloadresources also means local themes, layouts, and Android. Everything contained in the R file will be loaded in this way.

At this stage, you can see the startup animation.

Step Sixth: System services or Services

After completing the previous steps, the running environment requests Zygote to run the system service. System services use both native and Java authoring, and system services can be considered a process. The same system service can be obtained in the Android SDK as system services. The system service contains all the systems services.

Zygote Create a new process to start the system service. You can find the source code in the "Startsystemserver" Method of the Zygoteinit class.

Core Services:

starts the Power Manager, creates the activity manager, initiates the phone registration, launches the Package Manager, sets the activity Management Service as the system process, launches the context Manager, starts the system contexts Providers; starts the battery service; Starts the timer manager ; Start the sensor service; start the window manager; start the Bluetooth service; start the Mount service.

Other services:

Start the status bar service, start the hardware service, start the Network State service, start the Network connection service, start the Notification Manager, start the device Storage monitoring service, start the Location manager, start the Search service, start the Clipboard service, start the registration service, start the wallpaper service; start the audio service; ; start adbsettingsobserver (Process adb command). Seventh Step: Boot completion

Once the system service runs in memory, Android completes the boot process. At this time "action_boot_completed" boot up the broadcast will be sent out.

Original link: Kpbird translation: Bole online-the top of the sea of clouds
Link: http://blog.jobbole.com/67931/
[Reprint must be marked in the text and retain the original link, translation links and translators and other information. ]

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.