Turn Android Launch flow

Source: Internet
Author: User

The Android system is powered by three stages:
    1. Bootloader Start
    2. Linux boot
    3. Android Launcher

Startup file:

For the machine from power up to load Linux system generally need three files: bootloader (boot file), kernel (kernel file), Rootfs (root file system can make the operating system normal operation of folders and files of a large collection, in Android is RAMDisk). These files are packaged into ROM in the form of an image when the ROM build is compiled.

The Android system is divided into two main areas. The system partition contains the Android runtime framework, the System app, and the preinstalled third-party app, and the boot partition contains kernel. Two mirrors that are brushed into the system partition and boot partition are called system.img and boot.img

Ramdisk is to simulate a portion of the fixed-size RAM space to the hard disk partition, which is mounted as read-only at boot time. It is not an actual file system, but a mechanism for loading the actual file system into memory and can be used as the root filesystem. put some files that are often accessed without changing ( such as a read-only root file system ) through Ramdisk In memory, it can obviously improve the performance of the system. However, the changes to these files will be lost after power-down, only to modify the IMG and brush.

Ramdisk.img is a read-only image partition that contains the Linux main directory authority, which can be compiled or compiled to the kernel separately. The main is to store Android boot after the first user process init executable files and init.*.rc and other related startup scripts and Sbin directory adbd tools. Directories such as system, Data,dev,proc,sys, and so on are empty and are used to mount the corresponding partitions.

These img files can be brushed into the flash storage of your phone via the brush machine. In general, there are two main types of flash phones:

NOR Flash: The feature is in-Chip execution (XIP, execute in place) so that the application can run directly in Flash flash memory without having to read the code into the system RAM. Nor is highly cost effective in 1~4MB small capacity, but very low write and erase speeds greatly affect its performance, as well as its high transmission efficiency.


NAND Flash

The NAND structure provides very high cell density, high storage density, and fast write and erase speeds.

Start the process:

1. Bootloader start

Bootloader is the boot loader of embedded system, it is the first program to run after power-on system, the main function is to boot the operating system, similar to the BIOS program on PC. Generally divided into BL1 and BL2 two stages, respectively, the initialization of hardware and load operating system. The basic functions are as follows:

A) Hardware Device initialization: Mainly includes shielding all interrupts, setting the CPU speed and clock frequency, shutting down the internal instructions of the processor, data cache, etc.

b) Initialize RAM: Set the CPU register to prepare for loading the kernel;

c) Initialization of the serial port: mainly used for interactive, output debugging information;

d) Check the CPU type: The Linux kernel needs to call the corresponding initialization program according to the CPU type when booting;

e) Set Linux boot parameters: Linux will initialize the corresponding parameters according to the parameter;

f) Call Linux Kernel Image: Load Kernel and RAMDisk to RAM to specify the address and jump to this address to start executing Kernel's first instruction.

To start the bootloader process:

When the machine is powered on, the ARM CPU PC (program counter) register value is 0x0, so the CPU will take instructions from this address, all embedded devices will be related ROM or flash mapped to this address (through the hardware pin level high and low implementation of http:// blog.csdn.net/yapingmcu/article/details/7248890). If the bootloader is stored in nor flash, then 0x0 is the first specified address in Flash, the general BL1 is executed in nor, and BL2 load to ram execution increases speed; if stored in nandflash, you need to load BL1 into RAM execution, Then load and execute BL2, and the process of loading BL1 on different chips is different.

Bootloader also supports interactive start-up, which does not execute BL2 immediately after BL1 completes, but waits for user action, which is called FastBoot.

2. Linux boot

a) kernel image zimage decompression

b) Kernel assembly start: According to the parameters passed in BL, perform the corresponding initialization (related to the hardware platform), the main step is to set up a page table , 4M memory mapping for the kernel

c) Kernel C start: Executes the Start_kernel method in Init/main.c. It mainly completes the remaining initialization operations associated with the hardware platform. Initializes the core process scheduler and interrupt handler functions, creates file and system caches, initializes memory management MMU, initializes memory.

d) rest_init () function, Kernel_thread () starts the first kernel thread execution Kernel_init ()

I. Load system devices and drivers, and initialize them

II. Loading binders, creating/dev/binder device files, and registering as misc devices

III. Mount the RAMDisk as a rootfs to the root directory/

Iv. call Execve () to create the system's first user process Init (/system/core/init/init.c)

V. Parse and execute the init.rc file to start the system service, at which point the thread enters user space to run.

3. Android launcher

A) parse and execute the init.rc file (\system\core\rootdir\init.rc) (Android system boot process is simpler than PC, init.rc and PC content is not the same, contains 4 different operations called Androidinit Launage is described in System/core/init/readme.txt)

b) Create a directory of Dev, proc, system, data, and mount the corresponding partitions to set the user and permissions for directories and files.

c) Perform action and commands in four operations, and then launch service for native space such as console, ADBD, Vold, netd, Media, Ril-daemon, Surfaceflinger, Ril-daemon and so on.

d) Start the ServiceManager service: is Binder's daemon, mainly responsible for the management of the entire system service, all the services in the system must be registered in the Smgr, access to the service is also required to smgr, through which to obtain remote service binder entity. The IPC of Android consists of client, service, ServiceManager and binder, Binder drives the actual IPC function, while Smgr manages the Service.

(FRAMEWORKS\NATIVE\CMDS\SERVICEMANAGER\SERVICE_MANAGER.C)

e) Start the zygote service: The zygote process is also called the incubation process, and all processes in the Android world are hatched from this process (fork ()), which is responsible for the creation and initiation of other processes in the application's framework layer.

(Frameworks/base/cmds/app_process/app_main.cpp) (The script that launches zygote in Android L is not in the Init.rc file but has a separate init.zygote_xx.rc file to boot to support 64-bit operating systems)

I. Zygote create Appruntime and start, call STARTVM, inside will call JNI_CREATEJAVAVM to start Davlik virtual machine. and load the required libraries and jar packages so that every time you fork out a new process you don't need to load the VM.

II. Call Startreg () to register the Jni method of Android

III. Invoking the main function of the Java layer's Com.android.internal.os.ZygoteInit class from the native layer through JNI, this function mainly does the following 3 things:

    1. Zygote register a socket for process communication, when we need to launch an Android application, AMS will create a new process for the application via the socket notification zygote.
    2. Zygote Process fork out a systemserver process, the systemserver process is responsible for starting the system's key services, such as package management Service Packagemanagerservice and application component Management Service Activitymanagerservice. For specific operating procedures see F
    3. Zygote execute runselectloopmode into loop to listen for socket requests

f) Run Systemserver: will run Handlesystemserverprocess () after it is created, this process will be responsible for starting other Android services

(Frameworks\base\services\java\com\android\server\systemserver.java)

I. Close the socket in the process because it is forked from the zygote process, but it does not need to be used.

II. Loading libandroid_servers.so

III. NATIVEINIT () Start the sensor Service in the native space and register to ServiceManager (frameworks/base/services/core/jni/com_android _server_systemserver.cpp)

Iv. execute Serverthread.initandloop () to start the service for Java Space and register to Servicemanage (mainly including ams/wms/connectivityservice/inputmanage Rservice, etc.)

V. Invoke the Systemready method of each service to notify the service that the system has started to complete

Vi. calling Looper.loop () to start the message loop on the main thread

PS: I see the KitKat code and the old version of the online introduction is not quite the same, the old version using Init1 () and Init2 () two functions to start the native and Java service, and Init1 started a lot of service, mainly including: sensor/ Audioflinger/mediaplayer/camera/audiopolicy, and only the sensor service is activated here. There is no knowing where other services are starting up.

g) Start Home:

I. The Systemready method of AMS is called, which invokes resumetopactivitylocked ()

II. The final call to the resumetopactivitylocked in Activitystack.java

III. Find no other activity, call activitystacksupervisor.resumehomeactivity

Iv. gethomeintent Get Intent, Intent CATEGORY is Intent.CATEGORY.HOME, then call ams.starthomeactivitylocked Pass Intent

V. Call Activitystacksupervisor. Starthomeactivity, call startactivitylocked ()

Vi. using the Resolveactivityinfo function to query the Packagemanagerservice category type for HOME applications

Vii. Finally, AMS will notify Zygote to start a new process.

h) Complete the Android system boot process

Reference:

The difference between ROM, PROM, EPROM, EEPROM, Flash ROM

Linux fork and Exec use

Http://www.cnblogs.com/hicjiajia/archive/2011/01/20/1940154.html

ARM Linux Start-Up process Analysis

Http://www.go-gddq.com/html/QianRuShiXiTong-JiShu/2012-08/1042290p2.htm

Android armlinux Kernel START Process

http://blog.csdn.net/yili_xie/article/details/5716837

Android of the Init process Details (i)

Http://www.cnblogs.com/nokiaguy/archive/2013/04/14/3020774.html

Android of the Init procedure (ii): initialization language ( init.rc ) parsing

Http://www.cnblogs.com/nokiaguy/p/3164799.html

Turn Android Launch flow

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.