init of android

15

Click here to load reader

Upload: tetsuyuki-kobayashi

Post on 20-May-2015

5.599 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Init of Android

1

Init of Android

Tetsuyuki Kobayashi

2010.12.10

Page 2: Init of Android

2

Who am I?

20+ years involved in embedded systems 10 years in real time OS, such as iTRON 10 years in embedded Java Virtual Machine Now GCC, Linux, QEMU, Android, …

Blogs http://d.hatena.ne.jp/embedded/ (Personal) http://blog.kmckk.com/ (Corporate)

Twitter @tetsu_koba

Page 3: Init of Android

3

Today's topic

/init Boot part of init Daemon part of init Check it out using debugger

Page 4: Init of Android

/init

Quite different from usual Linux system

Add ”init=/init” in kernel boot parameter. Kernel searches only the following init /sbin/init /etc/init /bin/init /bin/sh

Page 5: Init of Android

/init

Android init is static linked. So it can run standalone (Linux /sbin/init is dynamically

linked. If some trouble in dynamic link system, the whole system won't work)

Page 6: Init of Android

Component of init

See the source code of init system/core/init

Init is made of 2 parts: boot part and daemon part At first, boot part is executed once

After that daemon part executed repeatedly

Page 7: Init of Android

int main(int argc, char **argv){ /* Boot part  */  for (;;) {

/* Daemon part */ }}

Page 8: Init of Android

Boot part

Setup the directories /dev /proc /sys

Parse /init.rc and execute it Yokohama Android Platform club

has a lot of information for this topic (written in Japanese)

Page 9: Init of Android

Daemon part

Waiting for 4 fds by poll system call and handle these in forever loop device_fd property_set_fd signal_recv_fd keychord_fd

Page 10: Init of Android

device_fd

Receiving the device status notification from kernel and create or remove device files under /dev

In usual Linux system, udevd do this.

Page 11: Init of Android

property_set_fd

Waiting for write request for system property

Init process maintains master data of system property. The other processes share it in read only mode by android ashmem mechanism.

(Let's talk this in other session)

Page 12: Init of Android

signal_recv_fd

Waiting for exiting child process and finish them by waitpid system call

If the child process is registered as service, restart it as registered info.

Page 13: Init of Android

keychord_fd

Monitoring special key comination and start the associated service

Effective only if system property ”ro.debuggable” == ”1” || “init.svc.adbd” == “running”

No services use this in default init.rc

Page 14: Init of Android

See also

KMC blog ”init of Android” http://blog.kmckk.com/archives/3137191.html This page have links of Yokohama Android

Platform club, too. Written in Japanese

Page 15: Init of Android

15

Q & A

Thank you for listening!Any comments to blogs are welcome.