Android uses the Linux kernel, generally running on the ARM architecture, Android device startup process, the application layer is basically equivalent to Linux, from the application layer of the first program Init began to differ, the following begins to introduce.
Step1, the boot ROM main function is to load boot loader into memory and execute, boot ROM is generally cured on the chip, the device starts after the power-on self-test from a fixed address start execution
Step2,boot Loader in 2 steps, the boot ROM only loads the first part of the bootloader code into memory, this part of the code loads the second part of the bootloader code, and the second part is the core, which completes the necessary environment preparation and begins loading the kernel.
bootloader is small program which runs before Android operating System running. Bootloader is first program to run so It's specific for board and processor. Device manufacturer either use popular bootloaders like Redboot,uboot, Qi bootloader or they develop own bootloaders, It ' s Not part of Android Operating System. Bootloader is the place where OEMs and Carriers put there locks and restrictions.
Bootloader perform execution in the stages, first stage It to detect external RAM and load program which helps in Second stage, in second stage bootloader setup network, memory, etc. which requires to run kernel, bootloader are able to p Rovide configuration parameters or inputs to the kernel for specific purpose.
Android bootloader can be found at <android source>\bootable\bootloader\legacy\usbloaderlegacy loader contain, important files, need to Address Here.1. Init.s-initializes stacks, zeros the BSS segments, call _main () in MAIN.C
2. Main.c-initializes Hardware (clocks, Board, keypad, console), creates Linux tags
Refer this link to know more about Android bootloader:
Https://motorola-global-portal.custhelp.com/app/answers/detail/a_id/86208/~/bootloader-frequently-asked-questions
Step3, the Android kernel boot process is similar to standard Linux, completing the initialization of the memory subsystem, protection mode, task scheduling system, drive subsystem, device system, file system, etc., and finally running the first application init. Unlike the standard system, the Android kernel adds some drivers and patches,
What isThe difference between the Linux and Android kernels?, here's A list of changes/addons that the Android Project made to the Linux kernel: Binder: It isAn Android specific interprocess communication mechanism and remote method invocation System.ashmem:"Android Shared Memory". It isANewShared memory allocator, similar to POSIX SHM but with a different behavior and sporting a simpler file-based API.PMEM:"Process Memory Allocator": It isUsed to manage large (1- -+MB) Physically contigous regions of memory shared between userspace and kernel drivers.logger:This isThe kernel support forThe logcat command.wakelocks:It isUsed forPower management files. It holds the machine awake on a per-EventBasis until Wakelock isreleased.oom handling:it kills processes asavailable memory becomes Low.alarm manager:it lets user space tell the kernel when It would like to wake up. Ram_console:allows to save kernel PRINTK messages to a bufferinchRAM, so the after a kernel panic they can is viewedinchThe next kernel invocation. USB Gadget driver forADBYAFFS2 Flash filesystem
STEP4, init process, starting from this step, Android startup and other Linux distributions (such as Redhat,gentoo,ubuntu) is not the same, the implementation of the INIT program, init.rc file format, are not the same. The main function of the INIT process is to mount the disk partitions and then parse and execute according to the INIT.RC configuration
Init isThe very first process, we can say it isa root process, or the grandfather of all processes. The INIT process has both responsibilities. 1-Mounts directories Like/sys,/dev orproc2-Runs init.rc Script-The INIT process can be found At/init:: <android source>/system/core/Init-init.rc file can found at:: <android source>/system/core/rootdir/Android has specific format and rules forinit.rc files. More information about ThisRules can be foundinch: what isInside the init.rc and what isIt used for. at ThisStage, you canfinallySee the Android logoinchYour screen.
Init.rc main configuration items are as follows:
After Init executes, the interface starts to appear Android logo, adb shell PS View, backstage already appeared a bunch of daemons, such as:
/system/bin/logd
/sbin/adbd
/system/bin/usbd
/system/bin/debuggerd
/system/bin/rild
/system/bin/runtime
/system/bin/dbus-daemon
system_server
- Zygote
These processes are the fork+execve of the init process.
STEP5, from this step, the Android system enters the Java world from the world of native (ie C + +) (that is, the code runs inside the Java Virtual machine). The source of the Java world is the zygote process that was launched in the previous step. When this process starts, it initializes the Java Virtual Machine environment (in fact, it loads dvm.so or art.so, gets some APIs for the virtual machine dynamic library, such as jnienv, and then registers a bunch of JNI functions to the virtual machine). All newly created app processes on Android are made by the zygote process clone, which allows you to share the code of the virtual machine's dynamic library and improve efficiency. Zygote also has a very important function, which is to create the system_server process, which will load and launch all the service threads (Java threads) of the Android app framework, the so-called Android framework, From the perspective of native, it is the two processes of zygote and system_server. STEP6, System_server started the service thread, as follows
After the above steps is completed, Zygote launches the system services. The Zygote forks ANewprocess to launch the system services. Core services:starting Power managercreating the Activity managerstarting Telephony registrystarting Package Managerset A Ctivity Manager Service asSystem processstarting Context managerstarting system contact Providersstarting Battery servicestarting Alarm Manage Rstarting Sensor servicestarting window managerstarting Bluetooth servicestarting Mount service other services:starting s Tatus bar servicestarting Hardware servicestarting NetStat servicestarting connectivity servicestarting Notification Managerstarting devicestoragemonitor servicestarting location managerstarting Search servicestarting Clipboard servicestarting checkin servicestarting Wallpaper servicestarting Audio servicestarting headsetobserverstarting Adbsettingsobserver Now we havefinallyCompleted the booting process (system service is up and runninginchMemory).
Reference: the Android booting process
Android Boot sequence
Android System Boot Process detailed