配套系列教学视频链接:
说明
系统:AOSP Android10.0
设备:RK3399 开发板
前言
在Android源码编译完成的out目录下, 有out/target/product/产品名/root/, 该目录是作为Android系统运行启动是的根目录, 包含了整个Android根文件系统的目录架构以及system, vendor等分区的挂载点,本章节重点讲解Android的根目录下的子目录是如何在编译的时候创建出来的,并可以将之前学习的知识点综合应用到这个章节来。起到温故知新的作用。
一, Android根目录的来源
在Android源码编译完成的out目录下, 有out/target/product/产品名/root/, 该目录是作为Android系统运行启动是的根目录, 包含了整个Android根文件系统的目录架构以及system, vendor等分区的挂载点,而out/target/product/产品名/root/目录中的大部分文件都是由源码中的system/core/rootdir/生成的。

最终生成的root目录如下,以rk3399 Android10举例
ls out/target/product/rk3399_roc_pc_plus/root/

二,rootdir目录Android.mk分析
LOCAL_PATH:= $(call my-dir)
#######################################
# init.rc
include $(CLEAR_VARS)
LOCAL_MODULE := init.rc
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
LOCAL_REQUIRED_MODULES := fsverity_init
# The init symlink must be a post install command of a file that is to TARGET_ROOT_OUT.
# Since init.rc is required for init and satisfies that requirement, we hijack it to create the symlink.
LOCAL_POST_INSTALL_CMD := ln -sf /system/bin/init $(TARGET_ROOT_OUT)/init
include $(BUILD_PREBUILT)
#######################################
# init-debug.rc
include $(CLEAR_VARS)
LOCAL_MODULE := init-debug.rc
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/init
include $(BUILD_PREBUILT)
以上部分主要是进行预编译init.rc和init-debug.rc,分别编译到out/target/product/产品名/root/init.rc和out/target/product/产品名/root/init/init-debug.rc, rc脚本文件是Android启动非常重要的脚本文件,后期会单独分析
#######################################
# fsverity_init
include $(CLEAR_VARS)
LOCAL_MODULE:= fsverity_init
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_SRC_FILES := fsverity_init.sh
include $(BUILD_PREBUILT)
#######################################
# init.environ.rc
include $(CLEAR_VARS)
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE := init.environ.rc
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
EXPORT_GLOBAL_ASAN_OPTIONS :=
ifneq ($(filter address,$(SANITIZE_TARGET)),)
EXPORT_GLOBAL_ASAN_OPTIONS := export ASAN_OPTIONS include=/system/asan.options
&nb

本文详细分析了Android源码编译完成后根目录的生成过程,特别是out/target/product/产品名/root/目录的结构。内容包括init.rc和相关rc脚本的预编译、软链接的创建、VNDK模块的配置等,揭示了Android启动时根文件系统的构建原理。


被折叠的 条评论
为什么被折叠?



