博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android Booting
阅读量:2342 次
发布时间:2019-05-10

本文共 6997 字,大约阅读时间需要 23 分钟。

Bootloader

The first program which runs on any Android system is the bootloader. Technically, thebootloader is outside the realm of Android itself, and is used to do very low-level systeminitialization, before loading the Linux kernel. The kernel then does the bulk of hardware,driver and file system initialization, before starting up the user-space programs and applicationsthat make up Android.

Often, the first-stage bootloader will provide support for loading recovery images to thesystem flash, or performing other recovery, update, or debugging tasks.

The bootloader on the ADP1 detects certain keypresses, which can be used to make it load a 'recovery' image (second instance of the kernel and system), or put the phone intoa mode where the developer can perform development tasks ('fastboot' mode), such asre-writing flash images, directly downloading and executing an alternate kernel image, etc.

'init'

A key component of the Android bootup sequence is the program 'init', which is a specialized program forinitializing elements of the Android system. Unlike other Linux systems (embedded or otherwise), Androiduses its own initialization program. (Linux desktop systems have historically used some combination of/etc/inittab and sysV init levels - e.g. /etc/rc.d/init.d with symlinks in /etc/rc.d/rc.[2345]). Someembedded Linux systems use simplified forms of these -- such as the init program included in busybox, whichprocesses a limited form of /etc/inittab, or a direct invocation of a shell script or small program todo fixed initialization steps.

The Android 'init' program processes two files, executing the commands it finds in them, called'init.rc' and 'init.<machine_name>.rc', where <machine_name> is the name of the hardwarethat Android is running on. (Usually, this is a code word. The name of the HTC1 hardwarefor the ADP1 is 'trout', and the name of the emulator is 'goldfish'.

The 'init.rc' file is intended to provide the generic initializationinstructions, while the 'init.<machine_name>.rc' file is intended to provide themachine-specific initialization instructions.

'init' resources

The syntax for these .rc files is documented in a readme file in the source tree.See the

Or, see also:

See also

Sequence of boot steps on ADP1

firmware

  • first-stage bootloader runs
    • it detects if a special key is held, and can launch the recovery image, or the 'fastboot' bootloader
  • eventually, a kernel is loaded into RAM (usually with an initrd)
    • normally, this will be the kernel from the 'boot' flash partition.

kernel

  • the kernel boots
    • core kernel initialization
      • memory and I/O areas are initialized
      • interrupts are started, and the process table is initialized
    • driver initialization
    • kernel daemons (threads) are started
    • root file system is mounted
    • the first user-space process is started
      • usually /init (note that other Linux systems usually start /sbin/init)

user space

  • the kernel runs /init
    • /init processes /init.rc and /init.<machine_name>.rc
    • dalvik VM is started (zygote). See
    • several daemons are started:
      • rild - radio interface link daemon
      • vold - volume daemon (media volumes, as in file systems - nothing to do with audio volume)
  • the system_server starts, and initializes several core services
    • See
    • initalization is done in 2 steps:
      • 1) a library is loaded to initialize interfaces to native services, then
      • 2) java-based core services are initialized in ServerThread::run() in
  • the activity manager starts core applications (which are themselves dalvik applications)
    • com.android.phone - phone application
    • android.process.acore - home (desktop) and a few core apps.
  • other processes are also started by /init, somewhere in there:
    • adb
    • mediaserver
    • dbus-daemon
    • akmd

Tools for analyzing Android Bootup

  • logcat - see
    • try this command: 'adb logcat -d -b events | grep "boot"
01-01 00:00:08.396 I/boot_progress_start(  754): 1255901-01 00:00:13.716 I/boot_progress_preload_start(  754): 1787901-01 00:00:24.380 I/boot_progress_preload_end(  754): 2854601-01 00:00:25.068 I/boot_progress_system_run(  768): 2923001-01 00:00:25.536 I/boot_progress_pms_start(  768): 2969701-01 00:00:25.958 I/boot_progress_pms_system_scan_start(  768): 3011701-01 00:00:40.005 I/boot_progress_pms_data_scan_start(  768): 4417101-01 00:00:45.841 I/boot_progress_pms_scan_end(  768): 5000601-01 00:00:46.341 I/boot_progress_pms_ready(  768): 5050501-01 00:00:49.005 I/boot_progress_ams_ready(  768): 5316601-01 00:00:52.630 I/boot_progress_enable_screen(  768): 56793
    • or this: 'adb logcat -d | grep preload'
10-15 00:00:17.748 I/Zygote  (  535): ...preloaded 1873 classes in 2438ms.10-15 00:00:17.764 I/Zygote  (  535): ...preloaded 0 resources in 0ms.10-15 00:00:17.772 I/Zygote  (  535): ...preloaded 15 resources in 7ms.
  • Bootchart - see
  • strace is pretty handy also, to see the timings for system calls from a process as it runs
    • You can use strace as a wrapper for a program in init.rc, and save the results to a file
    • Use -f to follow sub-processes
    • Use -tt to get detailed timestamps for syscalls
    • Use -o to output the data to a file

Here is an example of using strace to follow the startup of zygote, and the apps that are forkedfrom it.

Replace:

service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server

with

service zygote /system/xbin/strace -f -tt -o /cache/debug/boot.strace /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server

Here is some sample data:

$ head boot.strace571   00:00:11.389939 execve("/system/bin/app_process", ["/system/bin/app_process", "-Xzygote", "/system/bin", "--zygote", "--start-system-server"], [/* 15 vars */]) = 0571   00:00:11.658878 brk(0)            = 0x804b000571   00:00:11.659048 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x77f9a000571   00:00:11.659169 readlink("/proc/self/exe", "/system/bin/app_process", 4096) = 23571   00:00:11.659339 access("/etc/ld.so.preload", R_OK) = 0571   00:00:11.659440 open("/etc/ld.so.preload", O_RDONLY) = 3571   00:00:11.659548 fstat64(0x3, 0x7fa76650) = 0571   00:00:11.659887 mmap2(NULL, 36, PROT_READ|PROT_WRITE, MAP_PRIVATE, 3, 0) = 0x77f99000571   00:00:11.659970 close(3)          = 0571   00:00:11.660071 open("/lib/libc_sse.so", O_RDONLY) = 3

Please note that writing the strace data takes extra time. For long sequences of very fast syscalls (such as when the timezone file is being read) the overhead of strace itself exaggerates the timings in the trace. Use the timing information with caution.

Notes on the Android startup procedure

Overview

See "Android Initialization Process" at: (this address is not work), using instead.

strace

Interaction of different processes on application initialization

Talking about Android Process -

Improving Bootup Time presentation

See - notes and material for a talk at LinuxCon North America, 2010 by Tim Bird

News

1-second boot of Android

Ubiquitous Corporation has announced boot of ARM-based Android system in 1 second.Actually, it's more like a suspend and resume than a boot.See[March, 2010]

转载地址:http://lqfvb.baihongyu.com/

你可能感兴趣的文章
Spring Boot 整合Filter
查看>>
nginx 安装
查看>>
ngnix 详解
查看>>
IDEA创建spring boot项目
查看>>
IDEA安装插件
查看>>
HttpClient-02连接管理
查看>>
数据库连接池-配置 wallfilter问题解决-UncategorizedSQLException
查看>>
java根据文件流判断文件类型(后缀名)
查看>>
js常用操作事件
查看>>
linux 安装mysql
查看>>
利用SQL语句查询数据库中所有表
查看>>
ActiveMQ 安装
查看>>
java可变参数
查看>>
spring 简述
查看>>
HttpClient-03Http状态管理
查看>>
spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].
查看>>
常用软件下载地址
查看>>
修改spring boot 启动logo
查看>>
spring boot-启动及配置文件
查看>>
HttpsURLConnection 安全传输(HTTPS--Secure Hypertext Transfer Protocol-安全超文本传输协议)...
查看>>