Android from pressing the power on key to booting what happened

Source: Internet
Author: User

As an Android developer, it is necessary to understand the entire system architecture, so this article summarizes what happens to the Android phone from pressing the power-on button to starting the process.

To learn about the Android phone startup process, let's start by understanding what happens to a Linux-based computer from the moment the power button is pressed, so that the analogy can better understand the startup process of the Android phone.

Linux-based PC startup process

We all know that all the program software including the operating system is running in memory, but our operating system is generally stored on the hard disk, when we press the power-on button, at this time what the memory program is not, so need some way to load the operating system into memory, and the completion of this task is BIOS.

The person who has installed the system must know what the BIOS is, so what is it?
The Bios:basic input/output system (basic input and output system) is an industry-standard firmware interface (from Wikipedia) on an IBM PC-compatible system. A bit difficult to understand, in fact, the BIOS is the first time we load the computer startup program, this program is not written in the Java language is not written in C language, is generally compiled program. The BIOS program is cured on the motherboard of a chip, is connected to the computer hardware and operating system bridge, it holds the computer's most important basic input and output programs, post-boot self-test program and system self-start program.

So the question is, how did the BIOS program start? BIOS boot is done by hardware, Intel 80x86
Series of CPU hardware are designed to power up (that is, the boot moment) into the 16-bit real mode state operation, at this time the CPU hardware logic is designed to force the value of CS to set to 0xffff,ip value set to 0x0000, so Cs:ip point to 0xffff0 this position, This location is the entry address of the BIOS program. So this is a hardware vendor agreement, all the BIOS program entry address is 0xffff0, so that when the boot, we find this address, if the address and there is no code snippet, then the computer will crash, if there is a code snippet at this address, will execute this code snippet, and thus execute, That is, the BIOS program starts.
Add:
CS: The code segment register, which exists in the CPU, points to the region where the CPU is currently executing code in memory.
IP: The instruction register, which exists in the CPU, records the offset address of the instruction to be executed within the code snippet, and the CS combination is the memory address of the instruction that will be executed.

When the BIOS program starts, it detects hardware devices such as our graphics card, memory, and so on. The BIOS establishes the interrupt vector table and the interrupt service program in memory. There are 256 interrupt vectors in the interrupt vector table, 4 bytes per interrupt vector, and each interrupt vector points to an interrupt service program that completes the task of loading the operating system from the hard disk into memory.

Linux-based operating systems, the computer will be divided into three batches of the operating system code, the first batch of the BIOS interrupt int 0x19 The first sector bootsect content into memory, the second and third batches under the command of Bootsect, respectively, loading the contents of the back sector into memory.

After executing a series of BIOS code, the computer completes the self-test and so on, the computer hardware system will operate in conjunction with the BIOS, so that the CPU receives an int 0x19 interrupt, and after the CPU receives the interrupt, the int 0x19 interrupt vector is found in the interrupt vector table immediately. The corresponding interrupt service program is found, and the boot program for the first sector of the hard disk is added to the specified location in memory by the interrupt service program. Subsequently, under the role of the bootloader, the operating system will be loaded into memory, the real mode to the protection mode of transformation, for the implementation of the operating system entry function main preparation, followed by the operating system of the initial chemical industry, the final completion of computer startup.

Android phone start-up process

Android is a Linux-based system, but because Android belongs to embedded devices, there is no BIOS program like PC. Instead, the bootloader--system boot loader. It is similar to the BIOS, which is used to initialize the hardware device before the system is loaded, to create an image of the memory space, and to prepare the environment for the final call to the system kernel. There is no hard drive in Android, but ROM, it is similar to hard disk storage operating system, user program, etc. Rom, like a hard disk, will also be divided into different areas for placing different programs, mainly divided into several partitions on Android:

    • /boot: Store the boot program, including kernel and memory operating procedures
    • /system: equivalent to computer C drive, storing Android system and system application
    • /recovery: Recovery partition, can enter this partition for system recovery
    • /data: User data area containing user's data: Contacts, SMS, settings, user-installed programs
    • /cache: Android system cache, saving the most frequently accessed data and applications in the system
    • /misc: Contains some miscellaneous content, such as system settings and system features enable disable settings
    • /sdcard: User's own storage area, can store photos, music, videos and other files

So how did the bootloader get loaded? We can think of, should be like a PC, when power-on, the CPU will be from the CPU manufacturer preset address to take instructions, this address is the manufacturer agreed to commonly known, similar to the above 80x86 architecture 0xffff0 address, Therefore, the Android phone will pre-map the solid-state storage device ROM to the address, when power-on, the CPU will be executed from the address of the/boot partition bootloader program, loaded into the Linux kernel into RAM.

When the Linux kernel starts, it initializes various hardware and software environments, loads the drivers, mounts the root filesystem, and starts the Init program of the root file system, the most important core program in the Android boot process.

The INIT process is the originator of the user process in the Android system. The INIT process launches various system-local services, such as Media Server, service Manager, Bootanim (boot animation), and so on. The init process will fork out the zygote after parsing the init.rc file, and Zygote is the parent of all Java processes, and our app is the zygote fork.

The zygote process mainly includes:

    • Load Zygoteinit class, register zygote socket server socket;
    • Load the virtual machine;
    • Pre-loaded Android core class
    • Pre-load system resources

The zygote process then fork out the system server process, and the system server process is responsible for starting and managing the entire framework, including services such as activity Manager,powermanager.

When system server is ready, it notifies Activitymanager to start the first Android program home, which is the desktop program we see.

At this point, from the Android phone boot to see the desktop program all the process analysis finished.

Finally, a whole flowchart is attached to help you understand it better (the source is in the reference link below)

Reference:
Http://blog.chinaunix.net/uid-26569496-id-3891554.html
http://ticktick.blog.51cto.com/823160/1659473
http://gityuan.com/2016/01/30/android-boot/

Android from pressing the power on key to booting what happened

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.