Android7.0 init.rc流程分析

在http://blog.csdn.net/kc58236582/article/details/52247547这篇博客中,我们分析了init进程的流程,现在我们结合代码主要分析init.rc脚本的流程。


首先我们会加载原生的init.rc,然后我们自己的一些内容放在自己的init.rc中。然后会在原生的init.rc中import。

而原生会通过ro.hardware这个属性,来获取我们设备自己的init.rc文件的名字,然后加载。

import /init.${ro.hardware}.rc
而这个ro.hardware是在proc/cmdline中获取其中关于androidboot的内容,来设置相关的ro属性。比如ro.boot.hardware(这个就是用来引入自己的init.rc) ro.boot.mode(开机模式)。


然后android init进程会触发几个关键的触发器,early-init init  后面会根据ro.boot.mode来加载是charge 还是late-init

我们下面来看看early-init init late-init这个三个触发器主要做了什么。


early-init主要是启动了ueventd,这个进程会做设备节点。然后在init进程加载这个trigger之后,会去等一个/dev/.coldboot_done文件,这个文件当ueventd设备节点都做好了会去写这个文件。


后面是init,这里面主要是创建一些目录,chown chmod操作


后面就是late-init,我们看下面late-init中又分了多个trigger,并且每一个做什么都写好了。

fs对应有mount_all命令,挂载fstab文件中对应的文件系统

post-fs会启动logd

load_system_props_action加载系统属性

post-fs-data创建data下面的目录

load_persist_props_action加载永久属性

boot中启动core服务,core服务有ueventd、logd、healthd、sh、adbd、servicemanager、vold、SurfaceFlinger、bootanimation。

on late-init
    trigger early-fs

    # Mount fstab in init.{$device}.rc by mount_all command. Optional parameter
    # '--early' can be specified to skip entries with 'latemount'.
    # /system and /vendor must be mounted by the end of the fs stage,
    # while /data is optional.
    trigger fs
    trigger post-fs

    # Load properties from /system/ + /factory after fs mount. Place
    # this in another action so that the load will be scheduled after the prior
    # issued fs triggers have completed.
    trigger load_system_props_action

    # Mount fstab in init.{$device}.rc by mount_all with '--late' parameter
    # to only mount entries with 'latemount'. This is needed if '--early' is
    # specified in the previous mount_all command on the fs stage.
    # With /system mounted and properties form /system + /factory available,
    # some services can be started.
    trigger late-fs

    # Now we can mount /data. File encryption requires keymaster to decrypt
    # /data, which in turn can only be loaded when system properties are present.
    trigger post-fs-data

    # Load persist properties and override properties (if enabled) from /data.
    trigger load_persist_props_action

    # Remove a file to wake up anything waiting for firmware.
    trigger firmware_mounts_complete

    trigger early-boot
    trigger boot
而main服务会在下面这个trigger中启动,而这个trigger会在mount_all函数中,把它加入执行trigger。

on nonencrypted
    class_start main
    class_start late_start
后面会启动main和late_start服务。

main服务有netd,debuggerd,rild,mediaserver,installd,zygote

late_start服务有logcat




猜你喜欢

转载自blog.csdn.net/kc58236582/article/details/78364759