Some questions arise when we think about the Android boot sequence. What is the Zygote, init.rc, what is the difference between the linux kernel and the android linux kernel?.
This document is intended to explain how the booting process runs.
Consider the following graph:
Step 1: Power On and System Startup
When we press the power button, the Boot ROM code starts executing from a pre-defined location which is hardwired in ROM. It loads the Bootloader into RAM and starts executing.
Step 2: Bootloader
The bootloader is a small program which runs before Android does. This is NOT part of the Android operating system. The bootloader is the place where manufacturer puts their locks and restrictions.
The bootloader executes in two stages. In the first stage it detects external RAM and loads a program which helps in the second stage.
In the second stage, the bootloader setups the network, memory, etc, which requires to run kernel. The bootloader is able to provide configuration parameters or inputs to the kernel for specific purposes.
The bootloader can be found at:
This legacy loader contains 2 important files:
Step 3: Kernel
The Android kernel starts in a similar way as the linux kernel. As the kernel launches, is starts to setup cache, protected memory, scheduling and loads drivers. When the kernel finishes the system setup, it looks for “init” in the system files.
What is the difference between the linux and android kernels?, here's a list of changes/addons that the Android Project made to the Linux kernel:
Step 4: init process
Init is the very first process, we can say it is a root process, or the grandfather of all processes. The init process has two responsibilities.
1- Mounts directories like /sys , /dev or /proc
2- Runs init.rc script
Android has specific format and rules for init.rc files. More information about this rules can be found in: What is inside the init.rc and what is it used for.
At this stage, you can finally see the Android logo in your screen.
Step 5: Zygote and Dalvik
In Java, we know that a separate Virtual Machine instance will popup in memory for separate per app, but in the case of Android, the VM should run as quick as possible for an app. But what happens if you have several apps thus launching several instances of the Dalvik (VM)?, it would consume an immense amount of memory.
To overcome this problem, the Android OS has a system called “Zygote”. The Zygote enables code sharing across the Dalvik VM, achieving a lower memory footprint and minimal startup time. Zygote is a virtual machine process that starts at system boot. The Zygote preloads and initializes core library classes.
The Zygote loading process:
At this time, you can see the boot animation.
Step 6: System service
After the above steps are completed, Zygote launches the system services. The Zygote forks a new process to launch the system services.
Now we have finally completed the booting process (system service are up and running in memory).
Need to analyze the Android Bootup?
The logcat :: Use adb to get the booting process events from the logcat.
‘adb logcat –d –b events | grep “boot”
‘adb logcat –d | grep preload’
More information about ADB can be found here: Using ADB with your Sabre Board