Moderator

Rank: 7Rank: 7Rank: 7

Credits
49803
Device
Mi 4i
MIUI Version
V9.2.2.0.LXIMIEK
Online time
3111 Hours
Send PM

Mi HeadphonesMi BandMi Band 2Mi HomeMijia Story TellerMi WiFi RouterMi VRMi In-Ear HeadphonesMi BoxXiaomi 7th AnniversaryMIUI 2015I Love MIUIMIUI 7MIUI Devices ContestFantastic!Awesome!FlashholicMIUI 2016MIUI 6Mi PadMi 4iXiaomi Mi 4Mi 3Mi 1Redmi4 Million Forum Members2014 ChristmasMIUI English Forum 2013Ringolicious MedalRocket to FutureThanksgiving DayMIUI 30 Million UsersMIUI Fan From IndonesiaMIUI 4th AnniversarySuper SundayFan Of  MIUI AzerbaijanMIUI Forum AppHappy Singles' DayAtaturk MourningMIUI 20 Million Users90000 Forum Members1st AnniversaryDiwali MIUI Fan From PhilippinesMIUI 9100k Forum MembersMIUI 3rd AnniversaryMIUI 7th Anniversary300K Forum Members500K Forum MembersMIUI 100 Million UsersMIUI Fan From Singapore1 Million Forum App InstallsFan Of MIUI Ex-Yu 800K Forum MembersXiaomi 5th Anniversary1 Million Forum MembersHappy Diwali2100K Forum MembersFan Of MIUI BangladeshI Love 2016MIUI 50 Million UsersHappy Valentine's DayMIUI Lucky FridayFan Of MIUI IndiaSuper Saturday600K Forum MembersMIUI Fan From Brazil3500K Forum MembersSuper Monday700K Forum MembersSuper ThursdayMIUI 5th AnniversaryI Love Mi BunnyGamer Mi BunnySummer Mi BunnyAlpaca Mi Bunny MIUI Beta TeamMIUI Beta Team VIPMIUI ReviewMi TalentMIUI Translation ContributorDebate MasterMIUI G+ FollowerMIUI Twitter FollowerAndroid ElfMIUI FB FollowerMIUI Android 4.4 KitKatAndroid GuruMIUI Ice Bucket ChallengeMi Bunny Game Master Most Active MIUIerMi Story TellerMIUI KingMi Lover MedalStar Of TechnologyMIUI Global Forum 2014MIUI Medals CollectorDie-hard MIUI FanOTA FeedbackSuper ModeratorPioneer of MIUI English Forum MIUI FollowerBest ArticleStar Of  MIUI Beta TeamSenior Beta TesterMIUI Community VIPStar Of IconsForum Contest LoverStar Bug FinderMr. DependableYouth PledgeMIUI ExpertUpdates Lover

[Tips & Tutorials] [Mod's Insight] Understanding Android Boot Process

[ Promote]
12065 23 |
14:34, Mar-01-2014 | From PC
|
|
Go to reply no.
This post was edited by Iyengar 07:12,Mar-01-2014

Folks,
Introduction

WNow that Android is universally accepted operating system throughout & the Smart Phone/Device market is flooded with android devices. The initial impact was "Cheap device & price". Not to ignore the fact that it has given the user not just control over the device but the best part of it is the complete control of it core and explicitly user now able to choose what he wants and what does not.

Purpose of this Topic

Unless the Porter/User does not understand what Andoid is and how it operates/function, I am sure you would would not have see something unique like MIUI. The very ver resson we are in this forum and this topic explains it.

Warning, Entering Geek World

That being said, a sneak peak at the partitions and boot sequence of a android device.

Mainly there are 6 partitions in Android phones, tablets and any other Android devices. Below is the list of partition for Android File System.
  • /boot
  • /system
  • /recovery
  • /data
  • /cache
  • /misc

Note from author: There might be some other partitions available & may also differs from Model to Model. But baseline partitions mention above do not change in any Android devices.


Partition.jpg

Note to User(s):Boot.img, System.img, & recovery.img are all flashable partitions with a unlocked boot loader.



For SD Card Fie System Partitions.
  • /sdcard
  • /sd-ext


Note to User(s):Only /sdcard partition can be found in all Android devices and SD-Ext is present only in select devices.

Now that we know the partitions avalable of our device, we can see what can be changed or wiped or erased. To illustrate: Wiping stock recovery and install TWRP recovery means just changing the recovery partition is all.

Now Let us start with the brief intro for each partition. I would be dwelling much on each of these but just brief intro to each for wider audience.

/boot

Boot partition of your Android device, as the name suggests. It includes the android kernel and the ramdisk.  The device will not boot without this partition. Wiping this partition from recovery should only be done if absolutely required and once done, the device must NOT be rebooted before installing a new one, which can be done by installing a ROM that includes a /boot partition.

/system

As the name suggests, this partition contains the entire Android OS, other than the kernel and the ramdisk. This includes the Android GUI and all the system applications that come pre-installed on the device. Wiping this partition will remove Android from the device without rendering it unbootable, and you will still be able to put the phone into recovery or bootloader mode to install a new ROM.

/recovery

This is specially designed for backup. The recovery partition can be considered as an alternative boot partition, that lets the device boot into a recovery console for performing advanced recovery and maintenance operations on it.

/data

As the name suggest, it is userdata partition. This partition contains the user’s data like your contacts, sms, settings and all android applications that you have installed. While you are doing factory reset on your device, this partition will wipe out, Then your device will be in the state, when you use for he first time, or the way it was after the last official or custom ROM installation.

/cache

I hope you have some idea about cache, as you are expert on internet browsing. This is the partition where Android stores frequently accessed data and app components. Wiping the cache doesn’t effect your personal data but simply gets rid of the existing data there, which gets automatically rebuilt as you continue using the device.

/misc

This partition contains miscellaneous system settings in form of on/off switches. These settings may include CID (Carrier or Region ID), USB configuration and certain hardware settings etc. This is an important partition and if it is corrupt or missing, several of the device’s features will will not function normally.

Android device execute following steps when you press power switch


Process.jpg
Android Boot Sequence / Process

Step 1 : Power On and System Startup

When power start Boot ROM code start execution from pre defined location which is hardwired on ROM. It load Bootloader into RAM and start execution

Step 2 : Bootloader

Bootloader is small program which runs before Android operating system running. Bootloader is first program to run so It is 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 two 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 is able to provide configuration parameters or inputs to the kernel for specific purpose.  

Android bootloader can be found at

<Android Source>\bootable\bootloader\legacy\usbloaderlegacy loader contain two important files that need to address here.

  • init.s - Initializes stacks, zeros the BSS segments, call _main() in main.c
  • main.c - Initializes hardware (clocks, board, keypad, console), creates Linux tags


If you are interested in more info, you can refer to Android 101: What Is A Bootloader?

Step 3: Kernel

Android kernel start similar way as desktop linux kernel starts, as kernel launch it start setup cache, protected memory, scheduling, loads drivers. When kernel finish system setup first thing it look for “init” in system files and launch root process or first process of system.  

Step 4: init process

init it very first process, we can say it is root process or BOSS of all processes. init process has two responsibilities

  • mount directories like /sys, /dev, /proc
  • run init.rc script.

init process can be found at init : <android source>/system/core/init
init.rc file can be found in source tree at <android source>/system/core/rootdir/init.rc
readme.txt file can be found in source tree at <andorid source>/system/core/init/readme.txt

Android has specific format and rules for init.rc files. In Android we call it as “Android Init Language

The Android Init Language consists of four broad classes of statements,which are Actions, Commands, Services, and Options.
Action : Actions are named sequences of commands.  Actions have a trigger which is used to determine when the action should occur.
Syntax
on <trigger>
   <command>
   <command>
   <command>

Service :  Services are programs which init launches and (optionally) restarts when they exit.  Syntax
service <name> <pathname> [ <argument> ]*
   <option>
   <option>
   ...

Options : Options are modifiers to services.  They affect how and when init runs the service.

Looking @ default init.rc file; listed are some major events and services.

  
Action  / Service
  
Description
on  early-init
Set  init and its forked children's oom_adj.
  Set  the security context for the init process.
on  init
setup  the global environment
  Create  cgroup mount point for cpu accounting
  and  many
on  fs
mount  mtd partitions
on  post-fs
change  permissions of system directories
on  post-fs-data
change  permission of /data folders and sub folders
on  boot
basic  network init ,Memory Management ,etc
service  servicemanager
start  system manager to manage all native services like location, audio, shared  preference etc..
service  zygote
start  zygote as app_process

At this stage you can see “Android/OEM” logo on device screen.

Step 5: Zygote and Dalvik

In a Java, We know that separate Virtual Machine(VMs) instance will popup in memory for separate per app, In case of Android app should launch as quick as possible, If Android os launch different instance of Dalvik VM for every app then it consume lots of memory and time. so, to overcome this problem Android OS as system named “Zygote”. Zygote enable shared code across Dalvik VM, lower memory footprint and minimal startup time. Zygote is a VM process that starts at system boot time as we know in previous step. Zygote preloads and initialize core library classes.  Normally there core classes are read-only and part of Android SDK or Core frameworks. In Java VM each instance has it’s own copy of core library class files and heap objects.

Zygote loading process

Source Code :<Android Source> /frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
  • registerZygoteSocket() -  Registers a server socket for zygote command connections
  • preloadClasses() - “preloaded-classes” is simple text file contains list of classes that need to be preloaded, you cna find “preloaded-classes” file at <Android Source>/frameworks/base
  • preloadResources() - preloadReaources means native themes and layouts, everything that include android.R file will be load using this method.


At this time you can see bootanimation

Step 6: System  Service or Services

After complete above steps, runtime request Zygote to launch system servers. System Servers are written in native and java both, System servers we can consider as process, The same system server is available as System Services in Android SDK. System server contain all system services.

Zygote fork new process to launch system services. You can find source code in ZygoteInit class and “startSystemServer” method.

Core Services which gets started along with the boot process
  • Starting Power Manager
  • Creating Activity Manager
  • Starting Telephony Registry
  • Starting Package Manager
  • Set Activity Manager Service as System Process
  • Starting Context Manager
  • Starting System Context Providers
  • Starting Battery Service
  • Starting Alarm Manager
  • Starting Sensor Service
  • Starting Window Manager
  • Starting Bluetooth Service
  • Starting Mount Service


Other services after booting process are
  • Starting Status Bar Service
  • Starting Hardware Service
  • Starting NetStat Service
  • Starting Connectivity Service
  • Starting Notification Manager
  • Starting DeviceStorageMonitor Service
  • Starting Location Manager
  • Starting Search Service
  • Starting Clipboard Service
  • Starting Checkin Service
  • Starting Wallpaper Service
  • Starting Audio Service
  • Starting HeadsetObserver
  • Starting AdbSettingsObserver


Step 7 : Boot Completed

Once System Services up and running in memory, Android has completed booting process, At this time “ACTION_BOOT_COMPLETED” standard broadcast action will fire.
You Smart Phone is now at your disposal.

Source & Image

Favorite1 Share

Rated by 16 people   Experience Prestige Reason  

discodave + 4 Fantastic!
_polimorph_ + 1 Great!
12dyl1983 + 5 Great!
meredithhan + 10 Great!
ilovepunkmusic + 2 Great!
AndroidFuchs + 5 Great!
chongjc + 5 Thanks!
alialmabhouh + 10 Your posts are very cool and useful .. t
narm5 + 10 + 3 Fantastic!
ygorigor + 2 Great!
ATP:RedRice + 1 Thanks!
Daconi + 10 + 3 Thanks!
helloansuman + 5 Great!
manu33xtro.ep + 5 Thanks!
Roussinov + 10 + 3 Thanks!
plasma.d00d + 2 Great!

Experience +87  Prestige +9  View Rating Log

Retired

Elite Member

Rank: 6Rank: 6

Credits
6299
Device
Mi 5 Pro
MIUI Version
5.8.20
Online time
400 Hours
Send PM

Awesome!I Love MIUIMIUI 6Mi 3Fan Of MIUI UKMIUI Fan From SingaporeMIUI V5 ReviewFan Of MIUI IndiaFan Of MIUI Ex-Yu MIUI Fan from IndiaMIUI 4th AnniversaryMIUI 50 Million UsersHilal Ramadan MIUI Fan From PhilippinesMIUI Fan from MalaysiaI Love Mi BunnyApp StarMIUI Android 4.4 KitKatMIUI ExpertMIUI Medals CollectorAndroid GuruOTA FeedbackPioneer of MIUI English Forum MIUI Follower

15:22, Mar-01-2014 | From PC
|
Superb post and very informative , thank you

MIUI Beta Team - Global

Cooool

Rank: 6Rank: 6

Credits
12153
Device
Mi Max 64GB
MIUI Version
8.2.1
Online time
514 Hours
Send PM

Mi Plastic In-ear PhonesYeelight Bedside LampMi Power StripMi BandMijia Qi CycleMi Bluetooth SpeakerMi Power Bank 10000MAH Xiaomi 6 LaunchUnlock MedalMi MIXMi Band 2Mijia VR Play 2Mi  BunnyMi HomeMijia Smart PTZ CameraMi HeadphonesMi Selfie StickMi Kids WatchXiaomi 7th AnniversaryFlashholicFantastic!MIUI Devices ContestMIUI 8Awesome!MIUI 2016MIUI 6I Love MIUIMIUI 7Redmi Note 24 Million Forum MembersMIUI 2017Happy New YearFan Of MIUI PolandMIUI Fan From SingaporeHappy Valentine's DayRooster Year of 2017I Love 20161500K Forum MembersMIUI Lucky FridayMIUI Weekly PollMIUI World TourMIUI 6th AnniversaryMIUI 5th AnniversaryMerry Christmas5 Million Forum PostsMIUI English Forum 2013Fan Of MIUI FranceMIUI 3rd Anniversary90000 Forum Members1300K Forum MembersUEFA EURO MedalMi Live MedalMIUI Forum AppMid-Autumn FestivalMIUI 300 WeeksPokemon Master MedalOlympics Medal1400K Forum Members3 Million Forum App Installs100k Forum MembersMIUI 9500K Forum MembersMIUI Happy MedalFan Of MIUI AustraliaRocket to FutureSuper Tuesday3500K Forum MembersMIUI 7th AnniversaryPuzzle MasterCamera Filter Guru MedalFan Of MIUI SpainMIUI PHappy DiwaliFan Of MIUI IndiaFan Of MIUI BangladeshSuper Monday300K Forum MembersMIUI 100 Million UsersSuper Saturday3 Million Forum MembersHappy Holi MedalSurge S1Super ThursdayRingolicious MedalSuper SundayMIUI Font LoverI Love Mi BunnyMiPopAlpaca Mi Bunny MIUI Beta TeamStar WarsAndroid GuruRingtone ExpertMaster Of TechnologyMIUI FB FollowerScroll Of WisdomDebate MasterMIUI FollowerDie-hard MIUI FanUpdates LoverMIUI G+ FollowerMr. DependableMIUI Halloween 2017Pioneer of MIUI English Forum OTA FeedbackMi Bunny Game Master Mi Story TellerAndroid ElfStar Of TechnologyMIUI Medals CollectorMost Active MIUIerMIUI SuperstarMIUI ExpertTheme TalentMIUI Android 4.4 KitKatForum Contest LoverHumor MasterInbox ZeroMIUI KingMIUI Ice Bucket ChallengeMi Lover MedalTechnology GuruMi TalentYouth Pledge

17:00, Mar-01-2014 | From PC
|
Iyengar,

Wow it is very informative.
Thank you bro.
MIUI, what's the best ? ...
Thanks Xiaomi

Supreme Member

www.lucrativephotography.com

Rank: 7Rank: 7Rank: 7

Credits
44060
Device
Mi 6
MIUI Version
8.1.18
Online time
2922 Hours
Send PM

Mi KeyMi Portable WiFiMi BoxMi BandMi In-Ear HeadphonesMi Power BankMi Power Bank 10000MAH Xiaomi 7th AnniversaryFantastic!MIUI 2015FlashholicI Love MIUIMIUI 6Awesome!MIUI 8Mi TVRedmiRedmi 1SMi 3Redmi NoteXiaomi Mi 4Mi 5MIUI 50 Million Users1400K Forum MembersMIUI Fan From Singapore1700K Forum MembersMIUI Fan from MalaysiaMIUI V5 ReviewMIUI 30 Million Users100k Forum MembersMIUI English Forum 2013MIUI Fan From IndonesiaFan Of MIUI India1st AnniversaryMi Live MedalFan Of MIUI Ex-Yu 300K Forum MembersMIUI Fan From PhilippinesMid-Autumn FestivalHilal Ramadan MIUI Fan from IndiaSingapore BirthdayMIUI Fan from TurkeyFan Of MIUI BangladeshFan Of  MIUI AzerbaijanMIUI 4th AnniversaryHappy Valentine's DayThanksgiving DayOlympics MedalAtaturk MourningMIUI 300 WeeksPokemon Master MedalDiwali MIUI 100 Million UsersHappy DiwaliHappy Singles' DaySummer Mi BunnyGamer Mi BunnyAlpaca Mi Bunny I Love Mi BunnyMIUI Porting TeamMIUI Device TeamMIUI Android 4.4 KitKatAndroid GuruMost Active MIUIerMIUI Ice Bucket ChallengeForum Contest LoverMIUI FB FollowerInbox ZeroYouth PledgeDie-hard MIUI FanOTA FeedbackMIUI Global Forum 2014Most Productive Porting DeveloperRedmi Note 3 ExplorerMi Lover MedalAndroid ElfSuper MIUI ThemeMost Popular Porting DeveloperMIUI Medals CollectorRingtone Star Technology GuruMaster Of TechnologyStar Of IconsMIUI ExpertListed in Official Download PageStar Of TechnologyMIUI Community VIPRecognized MIUI Porting DevPioneer of MIUI English Forum Humor MasterUpdates LoverMIUI Follower

17:04, Mar-01-2014 | From PC
|
Very helpful...

Gold Member

Rank: 3Rank: 3

Credits
213
Device
Galaxy S4
MIUI Version
5.6.27
Online time
32 Hours
Send PM

Awesome!I Love MIUIMIUI FollowerPioneer of MIUI English Forum

20:48, Mar-01-2014 | From PC
|
great info

thnaks

Platinum Member

Rank: 4

Credits
4795
Device
Redmi 1
MIUI Version
6.6.16
Online time
210 Hours
Send PM

Mi BandMIUI 2015Fantastic!I Love MIUIAwesome!MIUI 6FlashholicMIUI 7MIUI 2016Xiaomi Mi 4RedmiRedmi 2Mi Note800K Forum Members300K Forum MembersMIUI 4th Anniversary500K Forum Members1 Million Forum MembersMIUI 100 Million UsersMIUI English Forum 2013Summer Mi BunnyI Love Mi BunnyAlpaca Mi Bunny Class A Beta TeamMIUI FollowerAndroid GuruHumor MasterUpdates LoverMIUI Medals CollectorForum Contest LoverMIUI Global Forum 2014MIUI Android 4.4 KitKatOTA FeedbackDie-hard MIUI FanPioneer of MIUI English Forum

21:30, Mar-01-2014 | From PC
|
Thanks for this explains.
I translate in french, in MIUI-France : http://miui-france.org/threads/13300/

;-)
ATP: MiTu: I'm alive! ~ Xiaomi Redmi WCDMA
----
Redmi 1: FAQs,...
Linux: access by USB Cable, QQ

Diamond Member

Rank: 5Rank: 5

Credits
1277
Device
Others
MIUI Version
4.2.18
Online time
84 Hours
Send PM

I Love MIUIMi 3Mi 2I Love Mi BunnyMIUI FollowerPioneer of MIUI English Forum OTA FeedbackMIUI Android 4.4 KitKat

02:30, Mar-02-2014 | From PC
|
More of these. Quite informative.

Diamond Member

Rank: 5Rank: 5

Credits
1419
Device
Mi 6
MIUI Version
7.8.8
Online time
248 Hours
Send PM

Mi BoxMi In-Ear HeadphonesUnlock MedalMi Power StripMi KeyMi BandMi HomeMi Power BankXiaomi 7th AnniversaryMIUI 8MIUI 2016MIUI 7MarshmallowMIUI 2015FlashholicI Love MIUIMIUI Devices ContestMIUI 6Awesome!Fantastic!Redmi Note 2Redmi NoteMi 5Redmi 2Mi TVXiaomi Mi 6Hilal Ramadan Happy Singles' DayRocket to FutureMIUI 4th Anniversary300K Forum MembersMIUI 50 Million UsersMIUI 9Surge S1MIUI Font LoverMIUI V5 ReviewHappy Valentine's Day1500K Forum MembersI Love 20161400K Forum MembersHappy New Year90000 Forum MembersThanksgiving Day1 Million Forum MembersMIUI 20 Million UsersUEFA EURO MedalMIUI 3rd Anniversary800K Forum MembersMIUI 6th AnniversaryMIUI 300 WeeksMIUI Fan From Indonesia900K Forum MembersAlpaca Mi Bunny Gamer Mi BunnySummer Mi BunnyI Love Mi BunnyMIUI Medals CollectorMIUI FollowerOTA FeedbackPioneer of MIUI English Forum Android GuruMi Bunny Game Master Youth PledgeRingtone Star Indonesia Independence DayMIUI Global Forum 2014Humor MasterAndroid ElfMIUI FB FollowerTechnology GuruMost Active MIUIerMi Lover MedalForum Contest LoverStar Of IconsUpdates LoverInbox ZeroDie-hard MIUI FanMIUI ExpertMIUI Android 4.4 KitKat

03:24, Mar-02-2014 | From PC
|
this is what we all need to know
thanks.....

Junior Member

Rank: 1

Credits
0
Device
Others
MIUI Version
4.8.8
Online time
33 Hours
Send PM

I Love MIUIMIUI 50 Million UsersI Love Mi BunnyPioneer of MIUI English Forum MIUI FollowerMIUI Global Forum 2014Android Guru

04:17, Mar-02-2014 | From PC
|
Great post with many info... I will try to translate it in Greek for the Greek miui forums

Senior Member

Rank: 2

Credits
41
Device
Others
MIUI Version
4.4.25
Online time
7 Hours
Send PM

I Love MIUIFan Of MIUI Ex-Yu I Love Mi Bunny

09:18, Mar-02-2014 | From PC
|
Thanks... Nice info

Credits Management

Quick Reply Top Return to the list