android 使用 linux 内核,一般运行在 ARM 体系架构上,android 设备启动的过程,应用层之下基本等同于linux, 从应用层第一个程序init开始有所区别,下面开始介绍。

 

step1, boot rom 主要作用是加载 boot loader 进入内存并执行,boot rom 一般固化在芯片上,设备启动加电自检后从固定的地址开始执行

step2,boot loader 分2步执行,boot rom只加载了第一部分bootloader代码进入内存,这部分代码随即加载第二部分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 
\bootable\bootloader\legacy\usbloaderlegacy loader contain two important files that 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, android 内核启动过程与标准linux类似,完成内存子系统、保护模式、任务调度系统、驱动子系统、设备系统、文件系统等的初始化,最后运行第一个应用程序init. 与标准系统有所不同的是,android的内核增加了部分驱动及补丁,

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: Binder: It is an Android specific interprocess communication mechanism and remote method invocation system.ashmem:  "Android Shared Memory". It is a new shared memory allocator, similar to POSIX SHM but with a different behavior and sporting a simpler file-based API.pmem: "Process memory allocator": It is used to manage large (1-16+ MB) physically contigous regions of memory shared between userspace and kernel drivers.logger:  This is the kernel support for the logcat command.wakelocks: It is used for power management files. It holds the machine awake on a per-event basis until wakelock is released.oom handling: It kills processes as available 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 buffer in RAM, so that after a kernel panic they can be viewed in the next kernel invocation.USB gadget driver for ADByaffs2 flash filesystem

step4, init 进程,从这一步开始,android的启动跟其他linux发行版(如redhat,gentoo,ubuntu)就不一样了,init程序的实现、init.rc文件的格式,都是不一样的。init 进程主要功能是挂载磁盘分区,然后根据init.rc的配置解析并执行

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 - The init process can be found at /init :: /system/core/init- Init.rc file can be found at :: /system/core/rootdir/ 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.

init.rc主要配置项如下:

init 执行完后,界面开始出现android logo, adb shell ps 查看,后台已经出现一堆守护进程,如:
  • /system/bin/logd
  • /sbin/adbd
  • /system/bin/usbd
  • /system/bin/debuggerd
  • /system/bin/rild
  • /system/bin/runtime
  • /system/bin/dbus-daemon
  • system_server
  • zygote

这些进程都是 init 进程 fork+execve 出来的子进程

 

step5, 从这一步开始,android系统从native(即c/c++)世界进入java世界(即代码跑在java 虚拟机内部)。 java世界的源头是上一步启动的 zygote 进程。这个进程启动后会初始化java虚拟机环境(其实就是加载 dvm.so或 art.so, 获取虚拟机动态库的一些api,如 jniEnv ,然后注册一堆jni函数给虚拟机)。 所有android上新创建的app 进程都是由 zygote 进程 clone 出来的,这样可以共享虚拟机动态库的代码,提高了效率。zygote 还有一个非常重要的功能,就是创建 system_server 进程,后者会加载并启动android app framework 的所有 service 线程(java线程),所谓android framework, 从native 视界看,就是 zygote 和 system_server 这两个进程。     step6, system_server 启动的服务线程,如下
After the above steps are completed,  Zygote launches the system services.  The Zygote forks a new process to launch the system services.Core services:Starting power managerCreating the Activity ManagerStarting telephony registryStarting package managerSet activity manager service as system processStarting context managerStarting system contact providersStarting battery serviceStarting alarm managerStarting sensor serviceStarting window managerStarting Bluetooth serviceStarting mount service Other services: Starting status 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 have finally completed the booting process (system service are up and running in memory).

 

 

参考: The Android Booting process

      android boot sequence

转载于:https://www.cnblogs.com/jiayy/p/4301049.html

更多相关文章

  1. Android:Service:AIDL实现进程通信
  2. Android(安卓)进程状态的概念
  3. android 实现listview动态加载列表项
  4. Android(安卓)启动流程
  5. 深入理解zygote——1(代码源于GooGle)
  6. Android(安卓)进程保活招式大全
  7. Android中ActivityManagerService与应用程序(客户端)通信模型分
  8. Android入门进阶教程(14)-Binder进程通信介绍
  9. Android(安卓)Loader的使用以及手机通讯录的获取方法

随机推荐

  1. android studio接入微信支付
  2. Android中获取设备的各种信息总结
  3. Android Retrofit 2.0的基本使用
  4. Android(安卓)framework系统默认设置修改
  5. Android控件布局属性全解
  6. Android EditText和TextView图文混排
  7. android adb 抓包
  8. 帮助你快速使用 Android 的 LiveData 与
  9. 在Android studio中保存keystore
  10. [置顶] Android中资源文件的详解和androi