Init of Android
The /init process in Android is different than a typical Linux system. It has two main parts - a boot part and a daemon part. The boot part sets up directories and parses the /init.rc file. The daemon part runs in a forever loop handling events from four file descriptors for devices, properties, signals, and keychords. It is responsible for device management, property updates, restarting services, and special key combinations. The /init process is statically linked so it can run independently of the system.
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
2
3. Today's topic
/init
Boot part of init
Daemon part of init
Check it out using debugger
3
4. /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
5. /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)
6. 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
7. int main(int argc, char **argv)
{
/* Boot part */
for (;;) {
/* Daemon part */
}
}
8. 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)
9. 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
10. device_fd
Receiving the device status
notification from kernel and create
or remove device files under /dev
In usual Linux system, udevd do
this.
11. 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)
12. 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.
13. 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
14. 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