Android Fuse文件系统-2:vold启动之rc文件

648 阅读1分钟

1. 回到噩梦开始的地方----init解析rc时启动vold进程

system/core/init/init.cpp

int SecondStageMain(int argc, char** argv) {
    .....
	// Trigger all the boot actions to get us started.
    am.QueueEventTrigger("init");

    // Repeat mix_hwrng_into_linux_rng in case /dev/hw_random or /dev/random
    // wasn't ready immediately after wait_for_coldboot_done
    am.QueueBuiltinAction(MixHwrngIntoLinuxRngAction, "MixHwrngIntoLinuxRng");

    // Don't mount filesystems or start core system services in charger mode.
    std::string bootmode = GetProperty("ro.bootmode", "");
    if (bootmode == "charger") {
        am.QueueEventTrigger("charger");
    } else {
        am.QueueEventTrigger("late-init");//------ 触发 late-init ------重要代码!!!!!!
    }
    ....
}

/system/core/rootdir/init.rc

对应的手机目录为 /system/etc/init/hw/init.rc

# Mount filesystems and start core system services.
on late-init
    trigger early-fs  #// 触发 early-fs 触发器,early-fs 会启动 vold 服务。vold在zygote之前启动,zygote 启动system_server,system_server启动mount服务。
    
    # 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 factory-fs
    trigger fs
    trigger post-fs

    # 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   ### -----------------------// 挂载 data

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

    # Should be before netd, but after apex, properties and logging is available.
    trigger load_bpf_programs

    # Now we can start zygote for devices with file based encryption
    trigger zygote-start    #####----------------触发  zygote-start !!所以 vold服务 在mount 服务之前启动

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

    trigger early-boot
    trigger boot
    trigger mmi


on early-fs   ################# 触发 early-fs 时,启动 vold 服务
    # Once metadata has been mounted, we'll need vold to deal with userdata checkpointing
    start vold
    
# start命令 启动某个服务
system/vold/vold.rc (对应的手机目录 /system/etc/init/vold.rc)
service vold /system/bin/vold \
        --blkid_context=u:r:blkid:s0 --blkid_untrusted_context=u:r:blkid_untrusted:s0 \
        --fsck_context=u:r:fsck:s0 --fsck_untrusted_context=u:r:fsck_untrusted:s0
    class core  #// core 类型
    ioprio be 2
    writepid /dev/cpuset/foreground/tasks
    shutdown critical
    group root reserved_disk