Init of Android


      2010.12.10


Tetsuyuki Kobayashi

                      1
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
Today's topic

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



                                  3
/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
/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)
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
int main(int argc, char **argv)
{
    /* Boot part   */
 
    for (;;) {

        /* Daemon part */

    }
}
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)
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
device_fd

   Receiving the device status
    notification from kernel and create
    or remove device files under /dev
   In usual Linux system, udevd do
    this.
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)
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.
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
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
Q&A




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

                                     15

Init of Android

  • 1.
    Init of Android 2010.12.10 Tetsuyuki Kobayashi 1
  • 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
  • 15.
    Q&A Thank you forlistening! Any comments to blogs are welcome. 15