• Home
Name Date Size #Lines LOC

..--

parser/03-May-2024-435301

test_service/03-May-2024-154117

.clang-formatD03-May-2024251 1211

Android.bpD03-May-20244.1 KiB172163

Android.mkD03-May-20242 KiB10282

MODULE_LICENSE_APACHE2D03-May-20240

NOTICED03-May-202410.4 KiB191158

README.mdD03-May-202426 KiB686531

action.cppD03-May-202411.1 KiB365269

action.hD03-May-20244.3 KiB13796

bootchart.cppD03-May-20245.9 KiB201140

bootchart.hD03-May-2024868 3210

builtins.cppD03-May-202429.6 KiB952751

builtins.hD03-May-20241.1 KiB4319

capabilities.cppD03-May-20246.3 KiB199145

capabilities.hD03-May-20241.2 KiB4320

compare-bootcharts.pyD03-May-20245.3 KiB14789

descriptors.cppD03-May-20244.4 KiB13583

descriptors.hD03-May-20242.5 KiB8553

devices.cppD03-May-202415.8 KiB439302

devices.hD03-May-20244.1 KiB13990

devices_test.cppD03-May-202412.1 KiB316240

firmware_handler.cppD03-May-20243.9 KiB12781

firmware_handler.hD03-May-2024849 319

grab-bootchart.shD03-May-2024623 2313

import_parser.cppD03-May-20241.7 KiB5934

import_parser.hD03-May-20241.3 KiB4721

init.cppD03-May-202441.4 KiB1,228849

init.hD03-May-20241.5 KiB5320

init_first_stage.cppD03-May-202418.6 KiB518357

init_first_stage.hD03-May-2024832 309

init_parser.cppD03-May-20245.4 KiB169128

init_parser.hD03-May-20244.2 KiB10344

init_parser_test.cppD03-May-20244.7 KiB151113

init_test.cppD03-May-20246.3 KiB194124

keychords.cppD03-May-20243.5 KiB12283

keychords.hD03-May-2024853 3210

keyword_map.hD03-May-20242.8 KiB8955

log.cppD03-May-20241.8 KiB6439

log.hD03-May-2024898 3310

parser.cppD03-May-20242.8 KiB125113

parser.hD03-May-2024952 4118

perfboot.pyD03-May-202415.8 KiB463352

property_service.cppD03-May-202422.2 KiB760584

property_service.hD03-May-20241.2 KiB4621

property_service_test.cppD03-May-20241.8 KiB5527

reboot.cppD03-May-202419.6 KiB537394

reboot.hD03-May-20241.3 KiB4211

service.cppD03-May-202440.7 KiB1,2741,023

service.hD03-May-202410 KiB252186

service_test.cppD03-May-20242.8 KiB7648

signal_handler.cppD03-May-20241.9 KiB7340

signal_handler.hD03-May-2024810 298

uevent.hD03-May-20241,011 4119

uevent_listener.cppD03-May-20246.9 KiB221156

uevent_listener.hD03-May-20241.8 KiB6332

ueventd.cppD03-May-202411 KiB290146

ueventd.hD03-May-2024805 298

ueventd_parser.cppD03-May-20244.5 KiB152107

ueventd_parser.hD03-May-20241.7 KiB5327

ueventd_test.cppD03-May-20244 KiB12387

util.cppD03-May-202412.5 KiB425315

util.hD03-May-20242.5 KiB6935

util_test.cppD03-May-20246.4 KiB196156

watchdogd.cppD03-May-20242.2 KiB8252

watchdogd.hD03-May-2024811 298

README.md

1Android Init Language
2---------------------
3
4The Android Init Language consists of five broad classes of statements:
5Actions, Commands, Services, Options, and Imports.
6
7All of these are line-oriented, consisting of tokens separated by
8whitespace.  The c-style backslash escapes may be used to insert
9whitespace into a token.  Double quotes may also be used to prevent
10whitespace from breaking text into multiple tokens.  The backslash,
11when it is the last character on a line, may be used for line-folding.
12
13Lines which start with a # (leading whitespace allowed) are comments.
14
15Actions and Services implicitly declare a new section.  All commands
16or options belong to the section most recently declared.  Commands
17or options before the first section are ignored.
18
19Services have unique names.  If a second Service is defined
20with the same name as an existing one, it is ignored and an error
21message is logged.
22
23
24Init .rc Files
25--------------
26The init language is used in plain text files that take the .rc file
27extension.  There are typically multiple of these in multiple
28locations on the system, described below.
29
30/init.rc is the primary .rc file and is loaded by the init executable
31at the beginning of its execution.  It is responsible for the initial
32set up of the system.
33
34Devices that mount /system, /vendor through the first stage mount mechanism
35load all of the files contained within the
36/{system,vendor,odm}/etc/init/ directories immediately after loading
37the primary /init.rc.  This is explained in more details in the
38Imports section of this file.
39
40Legacy devices without the first stage mount mechanism do the following:
411. /init.rc imports /init.${ro.hardware}.rc which is the primary
42   vendor supplied .rc file.
432. During the mount\_all command, the init executable loads all of the
44   files contained within the /{system,vendor,odm}/etc/init/ directories.
45   These directories are intended for all Actions and Services used after
46   file system mounting.
47
48One may specify paths in the mount\_all command line to have it import
49.rc files at the specified paths instead of the default ones listed above.
50This is primarily for supporting factory mode and other non-standard boot
51modes.  The three default paths should be used for the normal boot process.
52
53The intention of these directories is:
54
55   1. /system/etc/init/ is for core system items such as
56      SurfaceFlinger, MediaService, and logcatd.
57   2. /vendor/etc/init/ is for SoC vendor items such as actions or
58      daemons needed for core SoC functionality.
59   3. /odm/etc/init/ is for device manufacturer items such as
60      actions or daemons needed for motion sensor or other peripheral
61      functionality.
62
63All services whose binaries reside on the system, vendor, or odm
64partitions should have their service entries placed into a
65corresponding init .rc file, located in the /etc/init/
66directory of the partition where they reside.  There is a build
67system macro, LOCAL\_INIT\_RC, that handles this for developers.  Each
68init .rc file should additionally contain any actions associated with
69its service.
70
71An example is the logcatd.rc and Android.mk files located in the
72system/core/logcat directory.  The LOCAL\_INIT\_RC macro in the
73Android.mk file places logcatd.rc in /system/etc/init/ during the
74build process.  Init loads logcatd.rc during the mount\_all command and
75allows the service to be run and the action to be queued when
76appropriate.
77
78This break up of init .rc files according to their daemon is preferred
79to the previously used monolithic init .rc files.  This approach
80ensures that the only service entries that init reads and the only
81actions that init performs correspond to services whose binaries are in
82fact present on the file system, which was not the case with the
83monolithic init .rc files.  This additionally will aid in merge
84conflict resolution when multiple services are added to the system, as
85each one will go into a separate file.
86
87There are two options "early" and "late" in mount\_all command
88which can be set after optional paths. With "--early" set, the
89init executable will skip mounting entries with "latemount" flag
90and triggering fs encryption state event. With "--late" set,
91init executable will only mount entries with "latemount" flag but skip
92importing rc files. By default, no option is set, and mount\_all will
93process all entries in the given fstab.
94
95Actions
96-------
97Actions are named sequences of commands.  Actions have a trigger which
98is used to determine when the action is executed.  When an event
99occurs which matches an action's trigger, that action is added to
100the tail of a to-be-executed queue (unless it is already on the
101queue).
102
103Each action in the queue is dequeued in sequence and each command in
104that action is executed in sequence.  Init handles other activities
105(device creation/destruction, property setting, process restarting)
106"between" the execution of the commands in activities.
107
108Actions take the form of:
109
110    on <trigger> [&& <trigger>]*
111       <command>
112       <command>
113       <command>
114
115Actions are added to the queue and executed based on the order that
116the file that contains them was parsed (see the Imports section), then
117sequentially within an individual file.
118
119For example if a file contains:
120
121    on boot
122       setprop a 1
123       setprop b 2
124
125    on boot && property:true=true
126       setprop c 1
127       setprop d 2
128
129    on boot
130       setprop e 1
131       setprop f 2
132
133Then when the `boot` trigger occurs and assuming the property `true`
134equals `true`, then the order of the commands executed will be:
135
136    setprop a 1
137    setprop b 2
138    setprop c 1
139    setprop d 2
140    setprop e 1
141    setprop f 2
142
143
144Services
145--------
146Services are programs which init launches and (optionally) restarts
147when they exit.  Services take the form of:
148
149    service <name> <pathname> [ <argument> ]*
150       <option>
151       <option>
152       ...
153
154
155Options
156-------
157Options are modifiers to services.  They affect how and when init
158runs the service.
159
160`console [<console>]`
161> This service needs a console. The optional second parameter chooses a
162  specific console instead of the default. The default "/dev/console" can
163  be changed by setting the "androidboot.console" kernel parameter. In
164  all cases the leading "/dev/" should be omitted, so "/dev/tty0" would be
165  specified as just "console tty0".
166
167`critical`
168> This is a device-critical service. If it exits more than four times in
169  four minutes, the device will reboot into recovery mode.
170
171`disabled`
172> This service will not automatically start with its class.
173  It must be explicitly started by name.
174
175`setenv <name> <value>`
176> Set the environment variable _name_ to _value_ in the launched process.
177
178`socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]`
179> Create a unix domain socket named /dev/socket/_name_ and pass its fd to the
180  launched process.  _type_ must be "dgram", "stream" or "seqpacket".  User and
181  group default to 0.  'seclabel' is the SELinux security context for the
182  socket.  It defaults to the service security context, as specified by
183  seclabel or computed based on the service executable file security context.
184  For native executables see libcutils android\_get\_control\_socket().
185
186`file <path> <type>`
187> Open a file path and pass its fd to the launched process. _type_ must be
188  "r", "w" or "rw".  For native executables see libcutils
189  android\_get\_control\_file().
190
191`user <username>`
192> Change to 'username' before exec'ing this service.
193  Currently defaults to root.  (??? probably should default to nobody)
194  As of Android M, processes should use this option even if they
195  require Linux capabilities.  Previously, to acquire Linux
196  capabilities, a process would need to run as root, request the
197  capabilities, then drop to its desired uid.  There is a new
198  mechanism through fs\_config that allows device manufacturers to add
199  Linux capabilities to specific binaries on a file system that should
200  be used instead. This mechanism is described on
201  <http://source.android.com/devices/tech/config/filesystem.html>.  When
202  using this new mechanism, processes can use the user option to
203  select their desired uid without ever running as root.
204  As of Android O, processes can also request capabilities directly in their .rc
205  files. See the "capabilities" option below.
206
207`group <groupname> [ <groupname>\* ]`
208> Change to 'groupname' before exec'ing this service.  Additional
209  groupnames beyond the (required) first one are used to set the
210  supplemental groups of the process (via setgroups()).
211  Currently defaults to root.  (??? probably should default to nobody)
212
213`capabilities <capability> [ <capability>\* ]`
214> Set capabilities when exec'ing this service. 'capability' should be a Linux
215  capability without the "CAP\_" prefix, like "NET\_ADMIN" or "SETPCAP". See
216  http://man7.org/linux/man-pages/man7/capabilities.7.html for a list of Linux
217  capabilities.
218
219`seclabel <seclabel>`
220> Change to 'seclabel' before exec'ing this service.
221  Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
222  Services on the system partition can instead use policy-defined transitions
223  based on their file security context.
224  If not specified and no transition is defined in policy, defaults to the init context.
225
226`oneshot`
227> Do not restart the service when it exits.
228
229`class <name> [ <name>\* ]`
230> Specify class names for the service.  All services in a
231  named class may be started or stopped together.  A service
232  is in the class "default" if one is not specified via the
233  class option. Additional classnames beyond the (required) first
234  one are used to group services.
235`animation class`
236> 'animation' class should include all services necessary for both
237  boot animation and shutdown animation. As these services can be
238  launched very early during bootup and can run until the last stage
239  of shutdown, access to /data partition is not guaranteed. These
240  services can check files under /data but it should not keep files opened
241  and should work when /data is not available.
242
243`onrestart`
244> Execute a Command (see below) when service restarts.
245
246`writepid <file> [ <file>\* ]`
247> Write the child's pid to the given files when it forks. Meant for
248  cgroup/cpuset usage. If no files under /dev/cpuset/ are specified, but the
249  system property 'ro.cpuset.default' is set to a non-empty cpuset name (e.g.
250  '/foreground'), then the pid is written to file /dev/cpuset/_cpuset\_name_/tasks.
251
252`priority <priority>`
253> Scheduling priority of the service process. This value has to be in range
254  -20 to 19. Default priority is 0. Priority is set via setpriority().
255
256`namespace <pid|mnt>`
257> Enter a new PID or mount namespace when forking the service.
258
259`oom_score_adjust <value>`
260> Sets the child's /proc/self/oom\_score\_adj to the specified value,
261  which must range from -1000 to 1000.
262
263`memcg.swappiness <value>`
264> Sets the child's memory.swappiness to the specified value (only if memcg is mounted),
265  which must be equal or greater than 0.
266
267`memcg.soft_limit_in_bytes <value>`
268> Sets the child's memory.soft_limit_in_bytes to the specified value (only if memcg is mounted),
269  which must be equal or greater than 0.
270
271`memcg.limit_in_bytes <value>`
272> Sets the child's memory.limit_in_bytes to the specified value (only if memcg is mounted),
273  which must be equal or greater than 0.
274
275`shutdown <shutdown_behavior>`
276> Set shutdown behavior of the service process. When this is not specified,
277  the service is killed during shutdown process by using SIGTERM and SIGKILL.
278  The service with shutdown_behavior of "critical" is not killed during shutdown
279  until shutdown times out. When shutdown times out, even services tagged with
280  "shutdown critical" will be killed. When the service tagged with "shutdown critical"
281  is not running when shut down starts, it will be started.
282
283
284Triggers
285--------
286Triggers are strings which can be used to match certain kinds of
287events and used to cause an action to occur.
288
289Triggers are subdivided into event triggers and property triggers.
290
291Event triggers are strings triggered by the 'trigger' command or by
292the QueueEventTrigger() function within the init executable.  These
293take the form of a simple string such as 'boot' or 'late-init'.
294
295Property triggers are strings triggered when a named property changes
296value to a given new value or when a named property changes value to
297any new value.  These take the form of 'property:<name>=<value>' and
298'property:<name>=\*' respectively.  Property triggers are additionally
299evaluated and triggered accordingly during the initial boot phase of
300init.
301
302An Action can have multiple property triggers but may only have one
303event trigger.
304
305For example:
306`on boot && property:a=b` defines an action that is only executed when
307the 'boot' event trigger happens and the property a equals b.
308
309`on property:a=b && property:c=d` defines an action that is executed
310at three times:
311
312   1. During initial boot if property a=b and property c=d.
313   2. Any time that property a transitions to value b, while property c already equals d.
314   3. Any time that property c transitions to value d, while property a already equals b.
315
316
317Commands
318--------
319
320`bootchart [start|stop]`
321> Start/stop bootcharting. These are present in the default init.rc files,
322  but bootcharting is only active if the file /data/bootchart/enabled exists;
323  otherwise bootchart start/stop are no-ops.
324
325`chmod <octal-mode> <path>`
326> Change file access permissions.
327
328`chown <owner> <group> <path>`
329> Change file owner and group.
330
331`class_start <serviceclass>`
332> Start all services of the specified class if they are
333  not already running.  See the start entry for more information on
334  starting services.
335
336`class_stop <serviceclass>`
337> Stop and disable all services of the specified class if they are
338  currently running.
339
340`class_reset <serviceclass>`
341> Stop all services of the specified class if they are
342  currently running, without disabling them. They can be restarted
343  later using `class_start`.
344
345`class_restart <serviceclass>`
346> Restarts all services of the specified class.
347
348`copy <src> <dst>`
349> Copies a file. Similar to write, but useful for binary/large
350  amounts of data.
351  Regarding to the src file, copying from symbolic link file and world-writable
352  or group-writable files are not allowed.
353  Regarding to the dst file, the default mode created is 0600 if it does not
354  exist. And it will be truncated if dst file is a normal regular file and
355  already exists.
356
357`domainname <name>`
358> Set the domain name.
359
360`enable <servicename>`
361> Turns a disabled service into an enabled one as if the service did not
362  specify disabled.
363  If the service is supposed to be running, it will be started now.
364  Typically used when the bootloader sets a variable that indicates a specific
365  service should be started when needed. E.g.
366
367    on property:ro.boot.myfancyhardware=1
368        enable my_fancy_service_for_my_fancy_hardware
369
370`exec [ <seclabel> [ <user> [ <group>\* ] ] ] -- <command> [ <argument>\* ]`
371> Fork and execute command with the given arguments. The command starts
372  after "--" so that an optional security context, user, and supplementary
373  groups can be provided. No other commands will be run until this one
374  finishes. _seclabel_ can be a - to denote default. Properties are expanded
375  within _argument_.
376  Init halts executing commands until the forked process exits.
377
378`exec_start <service>`
379> Start a given service and halt the processing of additional init commands
380  until it returns.  The command functions similarly to the `exec` command,
381  but uses an existing service definition in place of the exec argument vector.
382
383`export <name> <value>`
384> Set the environment variable _name_ equal to _value_ in the
385  global environment (which will be inherited by all processes
386  started after this command is executed)
387
388`hostname <name>`
389> Set the host name.
390
391`ifup <interface>`
392> Bring the network interface _interface_ online.
393
394`insmod [-f] <path> [<options>]`
395> Install the module at _path_ with the specified options.
396  -f: force installation of the module even if the version of the running kernel
397  and the version of the kernel for which the module was compiled do not match.
398
399`load_all_props`
400> Loads properties from /system, /vendor, et cetera.
401  This is included in the default init.rc.
402
403`load_persist_props`
404> Loads persistent properties when /data has been decrypted.
405  This is included in the default init.rc.
406
407`loglevel <level>`
408> Sets the kernel log level to level. Properties are expanded within _level_.
409
410`mkdir <path> [mode] [owner] [group]`
411> Create a directory at _path_, optionally with the given mode, owner, and
412  group. If not provided, the directory is created with permissions 755 and
413  owned by the root user and root group. If provided, the mode, owner and group
414  will be updated if the directory exists already.
415
416`mount_all <fstab> [ <path> ]\* [--<option>]`
417> Calls fs\_mgr\_mount\_all on the given fs\_mgr-format fstab and imports .rc files
418  at the specified paths (e.g., on the partitions just mounted) with optional
419  options "early" and "late".
420  Refer to the section of "Init .rc Files" for detail.
421
422`mount <type> <device> <dir> [ <flag>\* ] [<options>]`
423> Attempt to mount the named device at the directory _dir_
424  _flag_s include "ro", "rw", "remount", "noatime", ...
425  _options_ include "barrier=1", "noauto\_da\_alloc", "discard", ... as
426  a comma separated string, eg: barrier=1,noauto\_da\_alloc
427
428`restart <service>`
429> Stops and restarts a running service, does nothing if the service is currently
430  restarting, otherwise, it just starts the service.
431
432`restorecon <path> [ <path>\* ]`
433> Restore the file named by _path_ to the security context specified
434  in the file\_contexts configuration.
435  Not required for directories created by the init.rc as these are
436  automatically labeled correctly by init.
437
438`restorecon_recursive <path> [ <path>\* ]`
439> Recursively restore the directory tree named by _path_ to the
440  security contexts specified in the file\_contexts configuration.
441
442`rm <path>`
443> Calls unlink(2) on the given path. You might want to
444  use "exec -- rm ..." instead (provided the system partition is
445  already mounted).
446
447`rmdir <path>`
448> Calls rmdir(2) on the given path.
449
450`setprop <name> <value>`
451> Set system property _name_ to _value_. Properties are expanded
452  within _value_.
453
454`setrlimit <resource> <cur> <max>`
455> Set the rlimit for a resource.
456
457`start <service>`
458> Start a service running if it is not already running.
459  Note that this is _not_ synchronous, and even if it were, there is
460  no guarantee that the operating system's scheduler will execute the
461  service sufficiently to guarantee anything about the service's status.
462
463> This creates an important consequence that if the service offers
464  functionality to other services, such as providing a
465  communication channel, simply starting this service before those
466  services is _not_ sufficient to guarantee that the channel has
467  been set up before those services ask for it.  There must be a
468  separate mechanism to make any such guarantees.
469
470`stop <service>`
471> Stop a service from running if it is currently running.
472
473`swapon_all <fstab>`
474> Calls fs\_mgr\_swapon\_all on the given fstab file.
475
476`symlink <target> <path>`
477> Create a symbolic link at _path_ with the value _target_
478
479`sysclktz <mins_west_of_gmt>`
480> Set the system clock base (0 if system clock ticks in GMT)
481
482`trigger <event>`
483> Trigger an event.  Used to queue an action from another
484  action.
485
486`umount <path>`
487> Unmount the filesystem mounted at that path.
488
489`verity_load_state`
490> Internal implementation detail used to load dm-verity state.
491
492`verity_update_state <mount-point>`
493> Internal implementation detail used to update dm-verity state and
494  set the partition._mount-point_.verified properties used by adb remount
495  because fs\_mgr can't set them directly itself.
496
497`wait <path> [ <timeout> ]`
498> Poll for the existence of the given file and return when found,
499  or the timeout has been reached. If timeout is not specified it
500  currently defaults to five seconds.
501
502`wait_for_prop <name> <value>`
503> Wait for system property _name_ to be _value_. Properties are expanded
504  within _value_. If property _name_ is already set to _value_, continue
505  immediately.
506
507`write <path> <content>`
508> Open the file at _path_ and write a string to it with write(2).
509  If the file does not exist, it will be created. If it does exist,
510  it will be truncated. Properties are expanded within _content_.
511
512
513Imports
514-------
515`import <path>`
516> Parse an init config file, extending the current configuration.
517  If _path_ is a directory, each file in the directory is parsed as
518  a config file. It is not recursive, nested directories will
519  not be parsed.
520
521The import keyword is not a command, but rather its own section,
522meaning that it does not happen as part of an Action, but rather,
523imports are handled as a file is being parsed and follow the below logic.
524
525There are only three times where the init executable imports .rc files:
526
527   1. When it imports /init.rc or the script indicated by the property
528      `ro.boot.init_rc` during initial boot.
529   2. When it imports /{system,vendor,odm}/etc/init/ for first stage mount
530      devices immediately after importing /init.rc.
531   3. When it imports /{system,vendor,odm}/etc/init/ or .rc files at specified
532      paths during mount_all.
533
534The order that files are imported is a bit complex for legacy reasons
535and to keep backwards compatibility.  It is not strictly guaranteed.
536
537The only correct way to guarantee that a command has been run before a
538different command is to either 1) place it in an Action with an
539earlier executed trigger, or 2) place it in an Action with the same
540trigger within the same file at an earlier line.
541
542Nonetheless, the defacto order for first stage mount devices is:
5431. /init.rc is parsed then recursively each of its imports are
544   parsed.
5452. The contents of /system/etc/init/ are alphabetized and parsed
546   sequentially, with imports happening recursively after each file is
547   parsed.
5483. Step 2 is repeated for /vendor/etc/init then /odm/etc/init
549
550The below pseudocode may explain this more clearly:
551
552    fn Import(file)
553      Parse(file)
554      for (import : file.imports)
555        Import(import)
556
557    Import(/init.rc)
558    Directories = [/system/etc/init, /vendor/etc/init, /odm/etc/init]
559    for (directory : Directories)
560      files = <Alphabetical order of directory's contents>
561      for (file : files)
562        Import(file)
563
564
565Properties
566----------
567Init provides information about the services that it is responsible
568for via the below properties.
569
570`init.svc.<name>`
571> State of a named service ("stopped", "stopping", "running", "restarting")
572
573
574Boot timing
575-----------
576Init records some boot timing information in system properties.
577
578`ro.boottime.init`
579> Time after boot in ns (via the CLOCK\_BOOTTIME clock) at which the first
580  stage of init started.
581
582`ro.boottime.init.selinux`
583> How long it took the first stage to initialize SELinux.
584
585`ro.boottime.init.cold_boot_wait`
586> How long init waited for ueventd's coldboot phase to end.
587
588`ro.boottime.<service-name>`
589> Time after boot in ns (via the CLOCK\_BOOTTIME clock) that the service was
590  first started.
591
592
593Bootcharting
594------------
595This version of init contains code to perform "bootcharting": generating log
596files that can be later processed by the tools provided by <http://www.bootchart.org/>.
597
598On the emulator, use the -bootchart _timeout_ option to boot with bootcharting
599activated for _timeout_ seconds.
600
601On a device:
602
603    adb shell 'touch /data/bootchart/enabled'
604
605Don't forget to delete this file when you're done collecting data!
606
607The log files are written to /data/bootchart/. A script is provided to
608retrieve them and create a bootchart.tgz file that can be used with the
609bootchart command-line utility:
610
611    sudo apt-get install pybootchartgui
612    # grab-bootchart.sh uses $ANDROID_SERIAL.
613    $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh
614
615One thing to watch for is that the bootchart will show init as if it started
616running at 0s. You'll have to look at dmesg to work out when the kernel
617actually started init.
618
619
620Comparing two bootcharts
621------------------------
622A handy script named compare-bootcharts.py can be used to compare the
623start/end time of selected processes. The aforementioned grab-bootchart.sh
624will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart.
625If two such barballs are preserved on the host machine under different
626directories, the script can list the timestamps differences. For example:
627
628Usage: system/core/init/compare-bootcharts.py _base-bootchart-dir_ _exp-bootchart-dir_
629
630    process: baseline experiment (delta) - Unit is ms (a jiffy is 10 ms on the system)
631    ------------------------------------
632    /init: 50 40 (-10)
633    /system/bin/surfaceflinger: 4320 4470 (+150)
634    /system/bin/bootanimation: 6980 6990 (+10)
635    zygote64: 10410 10640 (+230)
636    zygote: 10410 10640 (+230)
637    system_server: 15350 15150 (-200)
638    bootanimation ends at: 33790 31230 (-2560)
639
640
641Systrace
642--------
643Systrace (<http://developer.android.com/tools/help/systrace.html>) can be
644used for obtaining performance analysis reports during boot
645time on userdebug or eng builds.
646
647Here is an example of trace events of "wm" and "am" categories:
648
649    $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py \
650          wm am --boot
651
652This command will cause the device to reboot. After the device is rebooted and
653the boot sequence has finished, the trace report is obtained from the device
654and written as trace.html on the host by hitting Ctrl+C.
655
656Limitation: recording trace events is started after persistent properties are loaded, so
657the trace events that are emitted before that are not recorded. Several
658services such as vold, surfaceflinger, and servicemanager are affected by this
659limitation since they are started before persistent properties are loaded.
660Zygote initialization and the processes that are forked from the zygote are not
661affected.
662
663
664Debugging init
665--------------
666By default, programs executed by init will drop stdout and stderr into
667/dev/null. To help with debugging, you can execute your program via the
668Android program logwrapper. This will redirect stdout/stderr into the
669Android logging system (accessed via logcat).
670
671For example
672service akmd /system/bin/logwrapper /sbin/akmd
673
674For quicker turnaround when working on init itself, use:
675
676    mm -j &&
677    m ramdisk-nodeps &&
678    m bootimage-nodeps &&
679    adb reboot bootloader &&
680    fastboot boot $ANDROID_PRODUCT_OUT/boot.img
681
682Alternatively, use the emulator:
683
684    emulator -partition-size 1024 \
685        -verbose -show-kernel -no-window
686