preface

For the system start-up process of the thematic research has been almost a week, although the progress is slow, but also have some reading source code experience, and a little understanding of the source code

Because the system startup process involves relatively more source code, so decided to divide several articles to write, this is mainly to start the process for a simple overview, and talk about my personal method of reading the source code

Welfare activities

The book donation activity jointly sponsored by Android Institute and China Machine Press is in progress. Please click the link to participate

The body of the

Startup Process Overview

The startup process refers to the startup process of the Android system

Let’s recall how we “booted up” a brand new unopened Android phone:

  1. Press the power button
  2. Enter boot animation
  3. After a long wait (maybe a few minutes? Ha ha)
  4. End of boot animation
  5. Officially boot, enter the setting screen
  6. Enter the system desktop Launcher.

Does it feel like a lot of steps? In fact, we mainly do or only responsible for pressing the power button OK, we want to analyze, is from the steps of 1-5, the system has done what, I simply draw a graph (PS: this is also called the graph?) :

  1. loader

As you probably know, Android can use a combination of buttons to access the BootLoader page, which is the bottom layer of the image above. It is a BootLoader that decompresses and initializes Kenel before the Android system, even its kernel, is loaded

  1. Idle process

The kernel is 0, the idle process, started by the kernel, and always perform in kernel mode, by the kernel mode of open we often mention 1 idle process, init (corresponding to the source code, the system/core/init/init. CPP)

  1. The init process

This process is also referred to in Deng’s book as the “Tianzihao” process, but after our analysis above, it is not the originator of the creation of heaven and earth

CPP does more than just start the init process, which will be discussed later in the source code

The init process is responsible for parsing the system startup script file init.rc (loadBootScripts()), after parsing the architect-specific script file ro.zygote to step 4

  1. The zygote process

I’ve been looking for the entry to the Zygote process for a long time, but the script in zygote. Rc makes it very clear

The corresponding source location is framework/base/ CMDS /app_process/app_main

app_process
app_main
process_name
ps
zygote
native
zygoteInit.java
main
Java
SystemServer

  1. SystemServer

This part of the source code has not read, here is just a brief mention…

  1. Launcher

Launcher is already our specific App, and this is a process fork from zygote

At this point, after all these steps, the system is finally up and interacting with the user

How to read source code

As the saying goes, it is better to give someone a fish than to be given a fish, so LET me briefly mention how I read the source code

I have discussed this issue with my friends and consulted with my predecessors. At present, I follow this approach

Aimed at system startup process related to the source code, for example, if they are a complete stranger, no idea, that I need to go to the reading books, such as deng teachers understand the Android, or to find some related articles, for the first piece is a general concept, specifically involves which classes, which processes involved

And then for these specific classes, or processes, put forward their own questions, or, to their own to ask some questions, and then with these specific problems, and then to in-depth source research

And most importantly, be clear about the purpose of reading the source code and the related issues. Don’t get bogged down in details. For example, I spent a lot of time trying to figure out how idle in the kernel starts the init process in the system, but it’s not that important.

The next article will cover the source code of the init startup process in detail

Write in the last

Think so? Why don’t you just like it and follow it?