The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | |
| 2 | Android Init Language |
| 3 | --------------------- |
| 4 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 5 | The Android Init Language consists of five broad classes of statements, |
| 6 | which are Actions, Commands, Services, Options, and Imports. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 7 | |
| 8 | All of these are line-oriented, consisting of tokens separated by |
| 9 | whitespace. The c-style backslash escapes may be used to insert |
| 10 | whitespace into a token. Double quotes may also be used to prevent |
| 11 | whitespace from breaking text into multiple tokens. The backslash, |
| 12 | when it is the last character on a line, may be used for line-folding. |
| 13 | |
| 14 | Lines which start with a # (leading whitespace allowed) are comments. |
| 15 | |
| 16 | Actions and Services implicitly declare a new section. All commands |
| 17 | or options belong to the section most recently declared. Commands |
| 18 | or options before the first section are ignored. |
| 19 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 20 | Actions and Services have unique names. If a second Action is defined |
| 21 | with the same name as an existing one, its commands are appended to |
| 22 | the commands of the existing action. If a second Service is defined |
| 23 | with the same name as an existing one, it is ignored and an error |
| 24 | message is logged. |
| 25 | |
| 26 | |
| 27 | Init .rc Files |
| 28 | -------------- |
| 29 | The init language is used in plaintext files that take the .rc file |
| 30 | extension. These are typically multiple of these in multiple |
| 31 | locations on the system, described below. |
| 32 | |
| 33 | /init.rc is the primary .rc file and is loaded by the init executable |
| 34 | at the beginning of its execution. It is responsible for the initial |
| 35 | set up of the system. It imports /init.${ro.hardware}.rc which is the |
| 36 | primary vendor supplied .rc file. |
| 37 | |
| 38 | During the mount_all command, the init executable loads all of the |
| 39 | files contained within the /{system,vendor,odm}/etc/init/ directories. |
| 40 | These directories are intended for all Actions and Services used after |
| 41 | file system mounting. |
| 42 | |
| 43 | The intention of these directories is as follows |
| 44 | 1) /system/etc/init/ is for core system items such as |
| 45 | SurfaceFlinger and MediaService. |
| 46 | 2) /vendor/etc/init/ is for SoC vendor items such as actions or |
| 47 | daemons needed for core SoC functionality. |
| 48 | 3) /odm/etc/init/ is for device manufacturer items such as |
| 49 | actions or daemons needed for motion sensor or other peripheral |
| 50 | functionality. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 51 | |
| 52 | |
| 53 | Actions |
| 54 | ------- |
| 55 | Actions are named sequences of commands. Actions have a trigger which |
| 56 | is used to determine when the action should occur. When an event |
| 57 | occurs which matches an action's trigger, that action is added to |
| 58 | the tail of a to-be-executed queue (unless it is already on the |
| 59 | queue). |
| 60 | |
| 61 | Each action in the queue is dequeued in sequence and each command in |
| 62 | that action is executed in sequence. Init handles other activities |
| 63 | (device creation/destruction, property setting, process restarting) |
| 64 | "between" the execution of the commands in activities. |
| 65 | |
| 66 | Actions take the form of: |
| 67 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 68 | on <trigger> [&& <trigger>]* |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 69 | <command> |
| 70 | <command> |
| 71 | <command> |
| 72 | |
| 73 | |
| 74 | Services |
| 75 | -------- |
| 76 | Services are programs which init launches and (optionally) restarts |
| 77 | when they exit. Services take the form of: |
| 78 | |
| 79 | service <name> <pathname> [ <argument> ]* |
| 80 | <option> |
| 81 | <option> |
| 82 | ... |
| 83 | |
| 84 | |
| 85 | Options |
| 86 | ------- |
| 87 | Options are modifiers to services. They affect how and when init |
| 88 | runs the service. |
| 89 | |
| 90 | critical |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 91 | This is a device-critical service. If it exits more than four times in |
| 92 | four minutes, the device will reboot into recovery mode. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 93 | |
| 94 | disabled |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 95 | This service will not automatically start with its class. |
| 96 | It must be explicitly started by name. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 97 | |
| 98 | setenv <name> <value> |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 99 | Set the environment variable <name> to <value> in the launched process. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 100 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 101 | socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ] |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 102 | Create a unix domain socket named /dev/socket/<name> and pass |
| 103 | its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket". |
| 104 | User and group default to 0. |
| 105 | 'seclabel' is the SELinux security context for the socket. |
| 106 | It defaults to the service security context, as specified by seclabel or |
| 107 | computed based on the service executable file security context. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 108 | |
| 109 | user <username> |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 110 | Change to username before exec'ing this service. |
| 111 | Currently defaults to root. (??? probably should default to nobody) |
Tom Cherry | dbddb40 | 2015-12-11 12:54:50 -0800 | [diff] [blame] | 112 | As of Android M, processes should use this option even if they |
| 113 | require linux capabilities. Previously, to acquire linux |
| 114 | capabilities, a process would need to run as root, request the |
| 115 | capabilities, then drop to its desired uid. There is a new |
| 116 | mechanism through fs_config that allows device manufacturers to add |
| 117 | linux capabilities to specific binaries on a file system that should |
| 118 | be used instead. This mechanism is described on |
| 119 | http://source.android.com/devices/tech/config/filesystem.html. When |
| 120 | using this new mechanism, processes can use the user option to |
| 121 | select their desired uid without ever running as root. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | |
| 123 | group <groupname> [ <groupname> ]* |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 124 | Change to groupname before exec'ing this service. Additional |
| 125 | groupnames beyond the (required) first one are used to set the |
| 126 | supplemental groups of the process (via setgroups()). |
| 127 | Currently defaults to root. (??? probably should default to nobody) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 128 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 129 | seclabel <seclabel> |
| 130 | Change to 'seclabel' before exec'ing this service. |
Stephen Smalley | 3fb6110 | 2012-11-02 15:22:34 -0400 | [diff] [blame] | 131 | Primarily for use by services run from the rootfs, e.g. ueventd, adbd. |
| 132 | Services on the system partition can instead use policy-defined transitions |
| 133 | based on their file security context. |
| 134 | If not specified and no transition is defined in policy, defaults to the init context. |
| 135 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 136 | oneshot |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 137 | Do not restart the service when it exits. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 138 | |
| 139 | class <name> |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 140 | Specify a class name for the service. All services in a |
| 141 | named class may be started or stopped together. A service |
| 142 | is in the class "default" if one is not specified via the |
| 143 | class option. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 144 | |
| 145 | onrestart |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 146 | Execute a Command (see below) when service restarts. |
| 147 | |
| 148 | writepid <file...> |
| 149 | Write the child's pid to the given files when it forks. Meant for |
| 150 | cgroup/cpuset usage. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 151 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 152 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 153 | Triggers |
| 154 | -------- |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 155 | Triggers are strings which can be used to match certain kinds of |
| 156 | events and used to cause an action to occur. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 157 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 158 | Triggers are subdivided into event triggers and property triggers. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 159 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 160 | Event triggers are strings triggered by the 'trigger' command or by |
| 161 | the QueueEventTrigger() function within the init executable. These |
| 162 | take the form of a simple string such as 'boot' or 'late-init'. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 163 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 164 | Property triggers are strings triggered when a named property changes |
| 165 | value to a given new value or when a named property changes value to |
| 166 | any new value. These take the form of 'property:<name>=<value>' and |
| 167 | 'property:<name>=*' respectively. Property triggers are additionally |
| 168 | evaluated and triggered accordingly during the initial boot phase of |
| 169 | init. |
Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 170 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 171 | An Action can have multiple property triggers but may only have one |
| 172 | event trigger. |
Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 173 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 174 | For example: |
| 175 | 'on boot && property:a=b' defines an action that is only executed when |
| 176 | the 'boot' event trigger happens and the property a equals b. |
| 177 | |
| 178 | 'on property:a=b && property:c=d' defines an action that is executed |
| 179 | at three times, |
| 180 | 1) During initial boot if property a=b and property c=d |
| 181 | 2) Any time that property a transitions to value b, while property |
| 182 | c already equals d. |
| 183 | 3) Any time that property c transitions to value d, while property |
| 184 | a already equals b. |
Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 185 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 186 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 187 | Commands |
| 188 | -------- |
| 189 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 190 | bootchart_init |
| 191 | Start bootcharting if configured (see below). |
| 192 | This is included in the default init.rc. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 193 | |
| 194 | chmod <octal-mode> <path> |
| 195 | Change file access permissions. |
| 196 | |
| 197 | chown <owner> <group> <path> |
| 198 | Change file owner and group. |
| 199 | |
| 200 | class_start <serviceclass> |
| 201 | Start all services of the specified class if they are |
| 202 | not already running. |
| 203 | |
| 204 | class_stop <serviceclass> |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 205 | Stop and disable all services of the specified class if they are |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 206 | currently running. |
| 207 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 208 | class_reset <serviceclass> |
| 209 | Stop all services of the specified class if they are |
| 210 | currently running, without disabling them. They can be restarted |
| 211 | later using class_start. |
| 212 | |
| 213 | copy <src> <dst> |
| 214 | Copies a file. Similar to write, but useful for binary/large |
| 215 | amounts of data. |
| 216 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 217 | domainname <name> |
| 218 | Set the domain name. |
| 219 | |
JP Abgrall | 3beec7e | 2014-05-02 21:14:29 -0700 | [diff] [blame] | 220 | enable <servicename> |
| 221 | Turns a disabled service into an enabled one as if the service did not |
| 222 | specify disabled. |
| 223 | If the service is supposed to be running, it will be started now. |
| 224 | Typically used when the bootloader sets a variable that indicates a specific |
| 225 | service should be started when needed. E.g. |
| 226 | on property:ro.boot.myfancyhardware=1 |
| 227 | enable my_fancy_service_for_my_fancy_hardware |
| 228 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 229 | exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]* |
| 230 | Fork and execute command with the given arguments. The command starts |
| 231 | after "--" so that an optional security context, user, and supplementary |
| 232 | groups can be provided. No other commands will be run until this one |
Mark Salyzyn | 17fff89 | 2015-06-02 11:11:02 -0700 | [diff] [blame] | 233 | finishes. <seclabel> can be a - to denote default. |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 234 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 235 | export <name> <value> |
| 236 | Set the environment variable <name> equal to <value> in the |
| 237 | global environment (which will be inherited by all processes |
| 238 | started after this command is executed) |
| 239 | |
| 240 | hostname <name> |
| 241 | Set the host name. |
| 242 | |
| 243 | ifup <interface> |
| 244 | Bring the network interface <interface> online. |
| 245 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 246 | insmod <path> |
| 247 | Install the module at <path> |
| 248 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 249 | load_all_props |
| 250 | Loads properties from /system, /vendor, et cetera. |
| 251 | This is included in the default init.rc. |
| 252 | |
| 253 | load_persist_props |
| 254 | Loads persistent properties when /data has been decrypted. |
| 255 | This is included in the default init.rc. |
| 256 | |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 257 | loglevel <level> |
| 258 | Sets the kernel log level to level. Properties are expanded within <level>. |
| 259 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 260 | mkdir <path> [mode] [owner] [group] |
| 261 | Create a directory at <path>, optionally with the given mode, owner, and |
| 262 | group. If not provided, the directory is created with permissions 755 and |
Johan Redestig | 0b42ba2 | 2015-03-15 17:39:41 +0100 | [diff] [blame] | 263 | owned by the root user and root group. If provided, the mode, owner and group |
| 264 | will be updated if the directory exists already. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 265 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 266 | mount_all <fstab> |
| 267 | Calls fs_mgr_mount_all on the given fs_mgr-format fstab. |
| 268 | |
Niklas Tibbling | bc3f69f | 2012-08-01 13:15:38 +0200 | [diff] [blame] | 269 | mount <type> <device> <dir> [ <flag> ]* [<options>] |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 270 | Attempt to mount the named device at the directory <dir> |
| 271 | <device> may be of the form mtd@name to specify a mtd block |
| 272 | device by name. |
Niklas Tibbling | bc3f69f | 2012-08-01 13:15:38 +0200 | [diff] [blame] | 273 | <flag>s include "ro", "rw", "remount", "noatime", ... |
| 274 | <options> include "barrier=1", "noauto_da_alloc", "discard", ... as |
| 275 | a comma separated string, eg: barrier=1,noauto_da_alloc |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 276 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 277 | powerctl |
| 278 | Internal implementation detail used to respond to changes to the |
| 279 | "sys.powerctl" system property, used to implement rebooting. |
| 280 | |
| 281 | restart <service> |
| 282 | Like stop, but doesn't disable the service. |
| 283 | |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 284 | restorecon <path> [ <path> ]* |
Stephen Smalley | 3fb6110 | 2012-11-02 15:22:34 -0400 | [diff] [blame] | 285 | Restore the file named by <path> to the security context specified |
| 286 | in the file_contexts configuration. |
| 287 | Not required for directories created by the init.rc as these are |
| 288 | automatically labeled correctly by init. |
| 289 | |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 290 | restorecon_recursive <path> [ <path> ]* |
| 291 | Recursively restore the directory tree named by <path> to the |
| 292 | security contexts specified in the file_contexts configuration. |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 293 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 294 | rm <path> |
| 295 | Calls unlink(2) on the given path. You might want to |
| 296 | use "exec -- rm ..." instead (provided the system partition is |
| 297 | already mounted). |
| 298 | |
| 299 | rmdir <path> |
| 300 | Calls rmdir(2) on the given path. |
| 301 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 302 | setprop <name> <value> |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 303 | Set system property <name> to <value>. Properties are expanded |
| 304 | within <value>. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 305 | |
| 306 | setrlimit <resource> <cur> <max> |
| 307 | Set the rlimit for a resource. |
| 308 | |
| 309 | start <service> |
| 310 | Start a service running if it is not already running. |
| 311 | |
| 312 | stop <service> |
| 313 | Stop a service from running if it is currently running. |
| 314 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 315 | swapon_all <fstab> |
| 316 | Calls fs_mgr_swapon_all on the given fstab file. |
| 317 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 318 | symlink <target> <path> |
| 319 | Create a symbolic link at <path> with the value <target> |
| 320 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 321 | sysclktz <mins_west_of_gmt> |
| 322 | Set the system clock base (0 if system clock ticks in GMT) |
| 323 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 324 | trigger <event> |
| 325 | Trigger an event. Used to queue an action from another |
| 326 | action. |
| 327 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 328 | verity_load_state |
| 329 | Internal implementation detail used to load dm-verity state. |
| 330 | |
| 331 | verity_update_state <mount_point> |
| 332 | Internal implementation detail used to update dm-verity state and |
| 333 | set the partition.<mount_point>.verified properties used by adb remount |
| 334 | because fs_mgr can't set them directly itself. |
| 335 | |
Patrick McCormick | 96d0a4d | 2011-02-04 10:51:39 -0800 | [diff] [blame] | 336 | wait <path> [ <timeout> ] |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 337 | Poll for the existence of the given file and return when found, |
| 338 | or the timeout has been reached. If timeout is not specified it |
| 339 | currently defaults to five seconds. |
Patrick McCormick | 96d0a4d | 2011-02-04 10:51:39 -0800 | [diff] [blame] | 340 | |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 341 | write <path> <content> |
| 342 | Open the file at <path> and write a string to it with write(2). |
| 343 | If the file does not exist, it will be created. If it does exist, |
| 344 | it will be truncated. Properties are expanded within <content>. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 345 | |
| 346 | |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 347 | Imports |
| 348 | ------- |
| 349 | The import keyword is not a command, but rather its own section and is |
| 350 | handled immediately after the .rc file that contains it has finished |
| 351 | being parsed. It takes the below form: |
| 352 | |
| 353 | import <path> |
| 354 | Parse an init config file, extending the current configuration. |
| 355 | If <path> is a directory, each file in the directory is parsed as |
| 356 | a config file. It is not recursive, nested directories will |
| 357 | not be parsed. |
| 358 | |
| 359 | There are only two times where the init executable imports .rc files, |
| 360 | 1) When it imports /init.rc during initial boot |
| 361 | 2) When it imports /{system,vendor,odm}/etc/init/ during mount_all |
| 362 | |
| 363 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 364 | Properties |
| 365 | ---------- |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 366 | Init provides information about the services that it is responsible |
| 367 | for via the below properties. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 368 | |
| 369 | init.svc.<name> |
Tom Cherry | 3be66ed | 2015-09-01 14:49:38 -0700 | [diff] [blame] | 370 | State of a named service ("stopped", "stopping", "running", "restarting") |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 371 | |
| 372 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 373 | Bootcharting |
| 374 | ------------ |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 375 | This version of init contains code to perform "bootcharting": generating log |
| 376 | files that can be later processed by the tools provided by www.bootchart.org. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 377 | |
Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 378 | On the emulator, use the -bootchart <timeout> option to boot with bootcharting |
| 379 | activated for <timeout> seconds. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 380 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 381 | On a device, create /data/bootchart/start with a command like the following: |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 382 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 383 | adb shell 'echo $TIMEOUT > /data/bootchart/start' |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 384 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 385 | Where the value of $TIMEOUT corresponds to the desired bootcharted period in |
| 386 | seconds. Bootcharting will stop after that many seconds have elapsed. |
| 387 | You can also stop the bootcharting at any moment by doing the following: |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 388 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 389 | adb shell 'echo 1 > /data/bootchart/stop' |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 390 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 391 | Note that /data/bootchart/stop is deleted automatically by init at the end of |
| 392 | the bootcharting. This is not the case with /data/bootchart/start, so don't |
| 393 | forget to delete it when you're done collecting data. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 394 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 395 | The log files are written to /data/bootchart/. A script is provided to |
| 396 | retrieve them and create a bootchart.tgz file that can be used with the |
| 397 | bootchart command-line utility: |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 398 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 399 | sudo apt-get install pybootchartgui |
Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 400 | # grab-bootchart.sh uses $ANDROID_SERIAL. |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 401 | $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 402 | |
Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 403 | One thing to watch for is that the bootchart will show init as if it started |
| 404 | running at 0s. You'll have to look at dmesg to work out when the kernel |
| 405 | actually started init. |
| 406 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 407 | |
Ben Cheng | 50bbde0 | 2015-06-09 17:04:36 +0800 | [diff] [blame] | 408 | Comparing two bootcharts |
| 409 | ------------------------ |
| 410 | A handy script named compare-bootcharts.py can be used to compare the |
| 411 | start/end time of selected processes. The aforementioned grab-bootchart.sh |
| 412 | will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart. |
| 413 | If two such barballs are preserved on the host machine under different |
| 414 | directories, the script can list the timestamps differences. For example: |
| 415 | |
| 416 | Usage: system/core/init/compare-bootcharts.py base_bootchart_dir |
| 417 | exp_bootchart_dir |
| 418 | |
| 419 | process: baseline experiment (delta) |
| 420 | - Unit is ms (a jiffy is 10 ms on the system) |
| 421 | ------------------------------------ |
| 422 | /init: 50 40 (-10) |
| 423 | /system/bin/surfaceflinger: 4320 4470 (+150) |
| 424 | /system/bin/bootanimation: 6980 6990 (+10) |
| 425 | zygote64: 10410 10640 (+230) |
| 426 | zygote: 10410 10640 (+230) |
| 427 | system_server: 15350 15150 (-200) |
| 428 | bootanimation ends at: 33790 31230 (-2560) |
| 429 | |
| 430 | |
Yasuhiro Matsuda | f93db4b | 2015-06-15 18:49:35 +0900 | [diff] [blame] | 431 | Systrace |
| 432 | -------- |
| 433 | Systrace [1] can be used for obtaining performance analysis reports during boot |
| 434 | time on userdebug or eng builds. |
| 435 | Here is an example of trace events of "wm" and "am" categories: |
| 436 | |
| 437 | $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py wm am --boot |
| 438 | |
| 439 | This command will cause the device to reboot. After the device is rebooted and |
| 440 | the boot sequence has finished, the trace report is obtained from the device |
| 441 | and written as trace.html on the host by hitting Ctrl+C. |
| 442 | |
| 443 | LIMITATION |
| 444 | Recording trace events is started after persistent properties are loaded, so |
| 445 | the trace events that are emitted before that are not recorded. Several |
| 446 | services such as vold, surfaceflinger, and servicemanager are affected by this |
| 447 | limitation since they are started before persistent properties are loaded. |
| 448 | Zygote initialization and the processes that are forked from the zygote are not |
| 449 | affected. |
| 450 | |
| 451 | [1] http://developer.android.com/tools/help/systrace.html |
| 452 | |
| 453 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 454 | Debugging init |
| 455 | -------------- |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 456 | By default, programs executed by init will drop stdout and stderr into |
| 457 | /dev/null. To help with debugging, you can execute your program via the |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 458 | Android program logwrapper. This will redirect stdout/stderr into the |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 459 | Android logging system (accessed via logcat). |
| 460 | |
| 461 | For example |
| 462 | service akmd /system/bin/logwrapper /sbin/akmd |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 463 | |
| 464 | For quicker turnaround when working on init itself, use: |
| 465 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 466 | mm -j |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 467 | m ramdisk-nodeps |
| 468 | m bootimage-nodeps |
| 469 | adb reboot bootloader |
| 470 | fastboot boot $ANDROID_PRODUCT_OUT/boot.img |
| 471 | |
| 472 | Alternatively, use the emulator: |
| 473 | |
| 474 | emulator -partition-size 1024 -verbose -show-kernel -no-window |
| 475 | |
| 476 | You might want to call klog_set_level(6) after the klog_init() call |
| 477 | so you see the kernel logging in dmesg (or the emulator output). |