自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
管理启动时间
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
启动过程涉及一系列操作,首先是启动 ROM,接着是引导加载程序、内核、init、Zygote 和系统服务器(粗体表示 Android 特有启动过程)。在汽车特有的启动过程中,后视摄像头 (RVC) 等早期服务必须在内核启动期间启动。
顺序 |
组件 |
Android |
Android Automotive |
1 |
启动 ROM |
将引导加载程序的第一个阶段加载到内部 RAM 中。 |
2 |
引导加载程序 |
初始化内存、验证安全性并加载内核。 |
3 |
内核 |
设置中断控制器、内存保护、缓存和调度,并启动用户空间进程。 |
后视摄像头 (RVC) 进程在内核启动早期启动。该进程启动后,VMCU 的 GPIO 会触发 RVC 画面在显示屏上显示。 |
4 |
init 进程 |
解析 init.rc 脚本、装载文件系统、启动 Zygote、启动系统进程。 |
车载 HAL (VHAL) 作为核心服务的一部分在 init 阶段启动。可移至早前状态,具体取决于 ServiceManager;需要移除共享库的依赖项(例如 init)。 |
5 |
Zygote |
为 Android 对象设置 Java 运行时和 init 内存。 |
6 |
系统服务器 |
系统中的第一个 Java 组件,用于启动核心 Android 服务。 |
CarService 在所有系统服务启动后启动。 |
优化启动时间
如需缩短系统启动时间,请遵循以下准则:
如需获取优化方面的帮助,Google 提供了以下工具:
提前启动服务
在启动序列中,某些服务可能会在 Android 开始启动之前启动。
后视摄像头
后视摄像头 (RVC) 应在内核中进行处理。当汽车转换到倒车档位时,VMCU 会向原生内核进程发出通知,然后原生内核进程会在显示屏上显示 RVC 画面。车载 HAL 可以使用 hardware/libhardware/include/hardware/vehicle_camera.h
控制 RVC。
车载 HAL (VHAL)
一些系统可能需要在启动序列的早期阶段读取和缓冲 CAN 数据(例如车辆速度、挡位状态),同时等待用户空间服务启动(该操作发生在启动序列后期)。VNS 以及 HAL 和 CAN 控制器需要在早期启动(通常在几秒钟内),这样才会出现这种情况。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Manage boot time\n\nThe boot process is a chain of actions starting from the boot ROM, followed by the bootloader,\nkernel, **Init** , **Zygote** , and **system server** (bold\nindicates Android-specific boot process). In the automotive-specific boot process, early services\nsuch as rearview camera (RVC) must start during the kernel boot.\n\n| Order | Component | Android | Android Automotive |\n|-------|---------------|----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| 1 | Boot ROM | Loads the first stage of the boot loader into internal RAM. ||\n| 2 | Bootloader | Inits memories, verifies for security, and loads kernel. ||\n| 3 | Kernel | Sets up interrupt controllers, memory protection, caches, and scheduling; launches user space processes. | **Rearview camera (RVC)** process starts early in kernel boot. After the process is up, GPIO from VMCU triggers RVC to show on display. |\n| 4 | Init process | Parses `init.rc` scripts, mounts file systems, launches Zygote, launches system process. | **Vehicle HAL (VHAL)** starts during init phase as part of core services. Can be moved to earlier states depending on ServiceManager; requires removing dependencies on shared libraries (such as init). |\n| 5 | Zygote | Sets up Java Runtime and init memory for Android objects. ||\n| 6 | System server | First Java component in the system, starts core Android services. | **CarService** starts after all system services are started. |\n\nOptimize boot time\n------------------\n\nTo improve boot time in your system, use the following guidelines:\n\n- **Kernel.** Load only the modules in use and initialize only the hardware\n components in use.\n\n- `init.rc`\n\n - Watch for blocking operations (service compared to command invocation).\n - Start only what is used.\n - Setting correct priority for services.\n- **Zygote.** Class preloading optimization (specify the list of classes to\n load).\n\n- **Package Manager**\n\n - Optimize product image to include only APKs in use.\n\n - [Enable DEX\n preoptimization](/docs/core/runtime/configure#compilation_options).\n\n- **System server.** Start only the system services that are used.\n\nFor help with optimization, Google provides the following tools:\n\n- Use `packages/services/Car/tools/bootanalyze/bootanalyze.py` to analyze logcat and\n dmesg logs.\n\n- Use `packages/services/Car/tools/bootio/` to record I/O for processes during the\n boot. You must compile the kernel with specific flags (refer to the `README.md`\n file).\n\nStart services early\n--------------------\n\nIn the boot sequence, some services might start before Android starts to boot.\n\n### Rearview camera\n\nThe rearview camera (RVC) should be handled in the kernel. The VMCU notifies the native kernel\nprocess when the vehicle shifts into Reverse, after which the native kernel process displays the\nRVC image onto the display. The vehicle HAL can control the RVC using\n`hardware/libhardware/include/hardware/vehicle_camera.h`.\n\n### Vehicle HAL (VHAL)\n\nSome systems might need to read and buffer CAN data (for example, vehicle speed, gear status)\nduring the early stages of the boot sequence while waiting for the user-space service to start\n(which occurs later in the boot sequence). This scenario requires VNS and the HAL and CAN\ncontrollers to start very early, typically within a few seconds.\n\n- Systems that can quickly mount `/system` can simply launch service manager then\n VNS early.\n\n- System that can't quickly mount `/system` must move both service manager and VNS\n to the kernel boot image and link all dependent libraries statically."]]