Booting (Android)

The booting process of Android devices starts at the power-on of the SoC (system on a chip) and ends at the visibility of the home screen, or special modes like recovery and fastboot. The boot process of devices that run Android is influenced by the firmware design of the SoC manufacturers.
== Background ==
As of 2018, 90% of the SoCs of the Android market are supplied by either Qualcomm, Samsung or MediaTek. 
== History ==
Verified boot, a booting security measure, was introduced with Android KitKat.
== Stages ==
=== Primary Bootloader ===
The Primary Bootloader (PBL), which is stored in the Boot ROM is the first stage of the boot process. This code is written by the chipset manufacturer.
The PBL verifies the authenticity of the next stage.
On Samsung smartphones, the Samsung Secure Boot Key (SSBK) is used by the boot ROM to verify the next stages.
On SoCs from Qualcomm, it is possible to enter the Qualcomm Emergency Download Mode from the primary bootloader.
If the verification of the secondary bootloader fails, it will enter EDL.[
=== Secondary Bootloader ===
Because the space in the boot ROM is limited, a secondary bootloader on the eMMC or eUFS is used. The secondary bootloader initializes TrustZone.
On the Qualcomm MSM8960 for example, the Secondary Bootloader 1 loads the Secondary Bootloader 2. The Secondary Bootloader 2 loads TrustZone and the Secondary Bootloader 3.
The SBL is now called XBL by Qualcomm and uses UEFI to be cross compatible for booting operating systems other than Android in the second stage.
=== Aboot (ABL) ===
Qualcomm uses Little Kernel, MediaTek uses Das U-Boot. Little Kernel is a microkernel for embedded devices, which has been modified by Qualcomm to use it as an Android bootloader. The Android Bootloader (Aboot), which implements the fastboot interface (which is absent in Samsung devices). Aboot verifies the authenticity of the boot and recovery partitions. By pressing a specific key combination, devices can also boot in recovery mode. Aboot then transfers control to the Linux kernel.
=== Kernel and initramfs ===
See also: Booting process of Linux
The initramfs is a gzip'ed cpio archive that contains a small root file system. It contains init, which is executed. The Android kernel is a modified version of the Linux kernel. Init does mount the partitions. dm-verity verifies the integrity of the partitions that are specified in the fstab file. dm-verity is a Linux kernel module that was introduced by Google in Android since version 4.4. The stock implementation only supports block based verification, but Samsung has added support for files.
=== Zygote ===
See also: Bionic (software) § Components
Zygote is spawned by the init process, which is responsible for starting Android applications and service processes. It loads and initializes classes that are supposed to be used very often into the heap. For example, dex data structures of libraries. After Zygote has started, it listens for commands on a socket. When a new application is to be started, a command is sent to Zygote which executes a fork() system call.[citation needed]
== Partition layout ==
The Android system is divided across different partitions.
The Qualcomm platform makes use of GPT. This specification is part of the UEFI specification, but does not depend on UEFI firmware.
== Every stage of the boot processes for Android, recovery, fastboot, or EDL in simple wording ==
=== General Android ===
# PMIC responds to power on command by pressing the power button
# PBL starts executing and verifying the XBL
# XBL starts. Any key combo here would set the device in fastboot
# ABL verification (if any errors are detected, it would not start)
# Verification error messages (if your bootloader is unlocked, loading a different OS or can't be trusted by a dm-verity error)
# ABL loads the Linux kernel (if key combo is detected, it automatically loads the recovery kernel and sets the androidboot.mode= string to recovery)
# Ramdisk unpacked, init is started
# Zygote executes a ()fork system call
# Your lock screen is shown
# Boot done
== Android Recovery's stages of booting ==
It's like normal Android, but it has to manage the screen and the Android subsystem is not present.
# PMIC responds to power on command by pressing the power button
# PBL starts executing and verifying the XBL
# XBL starts
# ABL verification (if any errors are detected, it would not start)
# Kay combo is detected, forcing the ABL to start Android Recovery
# ABL loads the recovery kernel
# Recovery ramdisk is loaded and unpacked
# Recovery Init is loaded, along with the recovery daemon
# If there is nothing written about the recovery GUI in the /misc partition, it displays the lovely No command screen if it's not cooperating.
# The recovery GUI is loaded, allowing the user to press the volume keys to navigate
== Fastboot's boot stages ==
# PMIC responds to power on command by pressing the power button
# PBL starts executing and verifying the XBL
# XBL starts
# Key combo forces the XBL to load fastboot
# Fastboot is loaded. Flashing can now be done here 
== EDL boot stages (Qualcomm only) ==
# PMIC responds to power on command by pressing the power button
# PBL detects the keycombo, starting EDL.
# EDL loaded
This can also load if the XBL verification fails.