`
daojin
  • 浏览: 690355 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Android启动过程

 
阅读更多

init is the first process after kernel started. The corresponding source code lies in: device/system/init. It does the following tasks step by step:

1.       Initialize log system.

2.       Parse /init.rc and /init.%hardware%.rc.

3.       Execute early-init action in the two files parsed in step 2.

4.       Device specific initialize. For example, make all device node in /dev and download firmwares.

5.       Initialize property system. Actually the property system is working as a share memory. Logically it looks like a registry under Windows system.

6.       Execute init action in the two files parsed in step 2.

7.       Start property service.

8.       Execute early-boot and boot actions in the two files parsed in step 2.

9.       Execute property action in the two files parsed in step 2.

10.   Enter into an indefinite loop to wait for device/property set/child process exit events. For example, if an SD card is plugined, init will receive a device add event, so it can make node for the device. Most of the important process is forked in init, so if any of them crashed, init will receive a SIGCHLD then translate it into a child process exit event, so in the loop init can handle the process exit event and execute the commands defined in *.rc(it will run command onrestart).

The .rc file is a script file defined by Android. The default is device/system/rootdir/init.rc. We can take a loot at the file format(device/system/init/readme.txt is a good overall introduction of the script). Basically the script file contains actions and services.

Actions

-------

Actions are named sequences of commands. Actions have a trigger which is used to determine when the action should occur.  When an event occurs which matches an action's trigger, that action is added to the tail of a to-be-executed queue (unless it is already on the queue).

Each action in the queue is dequeued in sequence and each command in that action is executed in sequence.  Init handles other activities (device creation/destruction, property setting, process restarting) "between" the execution of the commands in activities.

Actions take the form of:

on <trigger>

   <command>

   <command>

   <command>

...

Services

--------

Services are programs which init launches and (optionally) restarts when they exit.  Services take the form of:

service <name> <pathname> [ <argument> ]*

   <option>

   <option>

   ...

Options

-------

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

Triggers

--------

Triggers are strings which can be used to match certain kinds of events and used to cause an action to occur.

The builtin supported commands are defined in device/system/init/keywords.h. Commands are implementd in device/system/init/bultins.c.

The init program only executes five kinds of triggers: “early-init”, “init”, “early-boot”, “boot”, “property:*”. Take a look at the following line in default init.rc.

class_start default

This line is a command for the action corresponding to “boot” trigger. It will start all services whose class name equals to “default”. By default, if no class option is defined for a service, the service’s class name is “default”. So this line will start all the services in the order of position in the file by default. (BTW, you can start any service using start commands, if you like.) Any service is run as a forked process of init, take a look at the source code of service_start in device/system/init.c.

So according to the default init.rc, the following services will be executed step by step:

console: star a shell. The source is in device/system/bin/ash.

adbd: start adb daemon. The source is in device/tools/adbd. By default is disabled.

servicemanager: start binder system. The source is in device/commands/binder.

mountd: mount all fs defined in /system/etc/mountd.conf if started, receive commands through local socket to mount any fs. The source is in device/system/bin/mountd.

debuggerd: start debug system. The source is in device/system/bin/debuggerd.

rild: start radio interface layer daemon. The source is in device/commands/rind.

zygote: start Android Java Runtime and start system server. It’s the most important service. The source is in device/servers/app.

media: start AudioFlinger, MediaPlayerService and CameraService. The source is in device/commands/mediaserver.

bootsound: play the default boot sound /system/media/audio/ui/boot.mp3. The source is in device/commands/playmp3.

dbus: start dbus daemon, it’s only used by BlueZ. The source is in device/system/Bluetooth/dbus-daemon.

hcid: redirect hcid’s stdout and stderr to the Android logging system. The source is in device/system/bin/logwrapper. By default is disabled.

hfag: start Bluetooth handsfree audio gateway, it’s only used by BlueZ. The source is in device/system/Bluetooth/bluez-utils. By default is disabled.

hsag: start Bluetooth headset audio gateway, it’s only used by BlueZ. The source is in device/system/Bluetooth/bluez-utils. By default is disabled.

installd: start install package daemon. The source is in device/servers/installd.

flash_recovery: load /system/recovery.img. The source is in device/commands/recovery/mtdutils.

Zygote service does the following tasks step by step:

1.       Create JAVA VM.

2.       Register android native function for JAVA VM.

3.       Call the main function in the JAVA class named com.android.internal.os.ZygoteInit whose source is device/java/android/com/android/internal/os/ZygoteInit.java.

a)         Load ZygoteInit class

b)        Register zygote socket

c)        Load preload classes(the default file is device/java/android/preloaded-classes)

d)        Load preload resources

e)         Call Zygote::forkSystemServer (implemented in device/dalvik/vm/InternalNative.c) to fork a new process. In the new process, call the main function in the JAVA class named com.android.server.SystemServer, whose source is in device/java/services/com/android/server.

                         i.              Load libandroid_servers.so

                       ii.              Call JNI native init1 function implemented in device/libs/android_servers/com_android_server_SystemServers. It only calls system_init implemented in device/servers/system/library/system_init.cpp.

l         If running on simulator, instantiate AudioFlinger, MediaPlayerService and CameraService here.

l         Call init2 function in JAVA class named com.android.server.SystemServer, whose source is in device/java/services/com/android/server. This function is very critical for Android because it start all of Android JAVA services.

l         If not running on simulator, call IPCThreadState::self()->joinThreadPool() to enter into service dispatcher.

SystemServer::init2 will start a new thread to start all JAVA services as follows:

Core Services:

分享到:
评论

相关推荐

    Android 启动过程详解

    ### Android启动过程详解 #### 一、概述 Android操作系统启动过程是一个复杂且精细的过程,它涉及到从硬件层面的初始化到最终用户界面的呈现。整个启动流程可以大致分为以下几个阶段: 1. **init进程启动** 2. **...

    Android 启动过程相关资料

    Android启动过程是一个复杂而有序的系统初始化阶段,涵盖了操作系统内核加载、系统服务启动、用户界面呈现等多个步骤。在这个过程中,Makefile起着至关重要的作用,它是构建Android系统的基石之一。 首先,Android...

    Android启动过程分析

    ### Android启动过程深入解析 Android启动过程是操作系统与硬件初始化、系统服务启动及应用程序环境建立的复杂流程。本文将从Init进程的启动入手,详细解析Android设备如何从电源开启到用户界面呈现的整个过程。 #...

    Android启动过程详解[借鉴].pdf

    Android 启动过程详解 Android 启动过程可以分为四个步骤:init 进程启动、Native 服务启动、System Server 启动和 Home 启动。 第一步:init 进程启动 init 进程是 Android 启动的第一个进程,由内核启动的用户...

    android 核心分析之------Android 启动过程详解

    ### Android核心分析之Android启动过程详解 Android启动过程是一个复杂且有序的流程,涉及多个关键阶段,从硬件初始化到最终的用户界面呈现。这一过程可以分为四大步骤:init进程启动、Native服务启动、...

    android核心分析之------Android启动过程详解.pdf

    Android启动过程详解主要分为四个关键步骤,这四个步骤构建了Android系统的基石。下面将详细阐述这些步骤以及涉及的重要组件。 第一步:初始化init进程 init进程是Android系统启动的第一个用户级进程,由Linux内核...

    android启动流程

    android启动流程,以uml图的方式显示了android的启动流程

    Android_启动过程分析

    下面是详细的Android启动过程分析: 1. **Bootloader阶段**: Bootloader是设备启动时运行的第一段软件,通常由制造商定制,负责加载Linux内核。Bootloader如uboot,会检查设备状态,加载必要的固件,然后将控制权...

    Android 启动过程分析

    此文档是根据sundy讲解的android启动视频而进行整理的,主要是跟踪andoird的系统开机过程,

    浅谈android性能优化之启动过程(冷启动和热启动)

    Android 应用程序启动优化之冷启动和热启动详解 一、应用程序启动方式 ...了解 Android 应用程序的启动过程对于优化应用程序的性能非常重要,可以根据应用程序的启动方式和启动过程来进行相应的优化处理。

    android启动优化.pdf

    ### Android启动过程优化详解 #### 一、Android启动过程概览 Android的启动过程是一个复杂且有序的过程,涉及多个核心组件和服务的初始化。下面将详细解释Android启动过程的关键步骤。 ##### 1. Init进程的启动 ...

    android启动源代码分析(init.c)

    Android启动源代码分析是一个深入探讨Android系统启动机制的重要途径,本文将重点分析Android启动过程中的关键源代码文件init.c,该文件位于system/core/init目录下,主要负责启动和管理系统进程,以及解析init.rc...

    Android_开机启动流程

    - [Android启动过程详解](http://blog.csdn.net/basonjiang_sz/category/648399.aspx) Android从Linux系统启动的过程大致分为以下几个步骤: 1. `init`进程启动 2. Native服务启动 3. `SystemServer`启动 4. 应用...

Global site tag (gtag.js) - Google Analytics