Android Boot Process
In computing, booting is starting up a computer or computer appliance until it can be used. It can be initiated by hardware such as a button press, or by software command. After the power is switched on the computer is relatively dumb, and can read only part of its storage called Read-only memory. There a small program is stored called firmware. It does power-on self-tests, and most importantly, allows accessing other types of memory, like hard disk and main memory. The firmware loads bigger programs into the computer’s main memory and runs it. In general purpose computers, but as well in smart phones, tablets, optionally a boot manager is run.
Android Boot Process
Android Boot Process includes the following six steps:
- Boot ROM: This Step is known as power ON and system startup. This means that whenever we press the power button, the Boot ROM code starts executing from a pre-defined location which is hardwired in ROM. Boot ROM loads the BootLoader into RAM and starts executing.
- BootLoader: Bootloaders is a low-level code contains the instructions that tell a device how to start up and find the system kernel. A Bootloader is a place where manufacturers put their locks and restrictions.
The bootloader is a code that is executed before any Operating System starts to run. The BootLoader executes in 2 Stages:
a) In the first stage, it detects external RAM and loads a program which helps in the second stage.
b) In the second stage, the bootloader setups the network, memory etc which requires to run Kernel.
- Kernel: Once kernel boots, it starts setup cache, protected memory, scheduling, loads drivers, starts kernel daemons, mounts root file system, initializing Input/Output, starts interrupts, initializes process table. A Kernel is the lowest level of easily replaceable software that interfaces with the hardware in our device. When kernel finish system setup first thing it looks for “init” in system files and launch root process or first process of a system.
- Init: Init is the very first process or we can say that it is the grandfather of all the processes.
The Init process has 2 responsibilities:
- Mounts directories like /sys, /dev or/proc
- Runs /init.rc script. The init.rc is responsible for the initial set up of the system.
The init process is what will set up all native services and this is similar to a regular Linux system boot.
- Zygote and Dalvik VM: The Zygote is a VM process that starts as the system boots. When app_process launces Zygote, it first creates the Dalvik VM and then calls Zygote’s main() method. Zygote receives a request to launch an App through/dev/socket/zygote. Once it happens, it triggers a fork() call.
When a process is a fork, it creates a clone to itself. It replicates itself in another memory space. This is done pretty efficiently. When this happens to Zygote, it creates an exact and clean new Dalvik VM as a thread, preloaded with all necessary classes and resources that any App will need. This makes the process of creating a VM and load resources pretty efficiently.
It enables code sharing across the Dalvik VM which helps in the achievement of minimal startup time.
- System Servers: After zygote preloads all necessary Java Classes and resources, it starts System Server. The System server is the core of the Android system. The first thing that happens is that the server will load a native library called android_servers that provides interfaces to native functionalities.
Then the native init method that will setup native services called. After setting up the native services it creates the server thread. This thread will start the remaining services in the system according to the necessary start order.
Each service is running in a separate Dalvik thread in the SystemServer.
Once system Services up and running in memory, Android has completed boot process, At this time “ACTION_BOOT_COMPLETED” standard broadcast action will fire.