Monday, January 12, 2015

Android Booting Sequence Stages Step By Step

Android Booting Sequence Step By Step

In Booting of Android OS from power on

Stage 1 : Power on and boot ROM code execution
Stage 2 : The boot loader loading
Stage 3 : Starting of Linux kernel
Stage 4 : The init process
Stage 5 : Zygote and Dalvik
Stage 6 : The system server initiation

Stage 1 Power on and boot ROM code execution 

At power on the CPU will be in a state where no initializations have been done. Internal clocks are not set up and the only memory available is the internal RAM.
When power supplies are stable the execution will start with the Boot ROM code. The Boot ROM code will detect the boot media using a system register that maps to some physical balls on the ASIC. This is to determine where to find the first stage of the boot loader.
Once the boot media sequence is established the boot ROM will try to load the first stage boot loader to internal RAM. Once the boot loader is in place the boot ROM code will perform a jump and execution continues in the boot loader.

Stage 2 The boot loader loading

The first boot loader stage will detect and set up external RAM.
Once external RAM is available and the system is ready the to run something more significant the first stage will load the main boot loader and place it in external RAM.
The second stage of the boot loader is the first major program that will run. This may contain code to set up file systems, additional memory, network support, loading code for the modem CPU and setting up low level memory protections and security options.
Once the boot loader is done with any special tasks it will look for a Linux kernel to boot. It will load this from the boot media (or some other source depending on system configuration) and place it in the RAM.
Once the boot loader is done it will perform a jump to the Linux kernel, usually some decompression routine, and the kernel assumes system responsibility

Stage 3 Starting of Linux kernel

It will set up everything that is needed for the system to run. Initialize interrupt controllers, set up memory protections, caches and scheduling.
Once the memory management units and caches have been initialized the system will be able to use virtual memory and launch user space processes.
The kernel will look in the root file system for the init process (found under system/core/init in the Android open source tree) and launch it as the initial user space process.

Stage 4 The init process

The init process in Android will look for a file called init.rc. This is a script that describes the system services, file system and other parameters that need to be set up. The init.rc script is placed in system/core/rootdir in the Android open source project.
The init process will parse the init script and launch the system service processes.

Stage 5 Zygote and Dalvik

init runs the C++ program /system/bin/app_process, and gives the resulting process the name "zygote"
app_process executes, and executes a runtime environment for a dalvik class
app_process does a 'runtime.start("", startSystemServer) starts executing
The profiler is started the Zygote socket is registered (for later communication to start apps) classes and resources are preloaded if startSystemServer is set, then the system server is started
Zygote runs in "select loop mode", where a single process spins waiting for communication to start subsequent apps.
Eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking

Stage 6 The system server initiation

The system server is the first java component to run in the system. It will start all the Android services such as telephony manager and bluetooth. Start up of each service is currently written directly into the run method of the system server. source can be found in the file frameworks/base/services/java/com/android/server/ in the open source project. Once the System Server is up and running and the system boot has completed there is a standard broadcast action called ACTION_BOOT_COMPLETED. To start your own service, register an alarm or otherwise make your application perform some action after boot you should register to receive this broadcast intent .

No comments:

Post a Comment