1 page.title=Bring Up 2 pdk.version=1.0 3 doc.type=porting 4 @jd:body 5 6 <p>Once your code is built and you have verified that all necessary directories exist, power on and test your device with basic bring up, as described below. Bring up tests are typically designed to stress certain aspects of your system and allow you to characterize the device's behavior. </p> 7 <p> </p> 8 <h3>1. Confirm a Clean Installation of a Basic Linux Kernel </h3> 9 <p>Before considering Android-specific modifications to the Linux kernel, verify that you can build, deploy, and boot a core Linux kernel on your target hardware. </p> 10 <p> </p> 11 <h3>2. Modify Your Kernel Configuration to Accommodate Android Drivers</h3> 12 <p>Your kernel configuration file should include the following:</p> 13 <pre class="prettyprint"> 14 # 15 # Android 16 # 17 # CONFIG_ANDROID_GADGET is not set 18 # CONFIG_ANDROID_RAM_CONSOLE is not set 19 CONFIG_ANDROID_POWER=y 20 CONFIG_ANDROID_POWER_STAT=y 21 CONFIG_ANDROID_LOGGER=y 22 # CONFIG_ANDROID_TIMED_GPIO is not set 23 CONFIG_ANDROID_BINDER_IPC=y 24 </pre> 25 <h3>3. Write Drivers</h3> 26 <p>Android ships with default drivers for all basic functionality but you'll likely want to write your own drivers (or at least customize the default drivers) for your own device depending on your hardware configuration. See the following topics for examples of how to write your own drivers. </p> 27 <ul> 28 <li><a href="audio_subsystem.html">Audio</a></li> 29 <li><a href="keymaps_keyboard_input.html">Keymaps and Keyboard</a></li> 30 <li><a href="display_drivers.html">Display</a></li> 31 </ul> 32 <p> </p> 33 <h3>4. Burn Images to Flash</h3> 34 <p>An image represents the state of a system or part of a system stored in non-volatile memory. The build process should produce the following system images:</p> 35 <ul> 36 <li><strong>bootloader</strong>: The bootloader is a small program responsible for initiating loading of the operating system. </li> 37 <li><strong>boot</strong>: </li> 38 <li><strong>recovery</strong>: </li> 39 <li><strong>system</strong>: The system image stores a snapshot of the Android operating system.</li> 40 <li><strong>data</strong>: The data image stores user data. Anything not saved to the <code>device/data</code> directory will be lost on reboot.</li> 41 </ul> 42 <ul> 43 <li><strong>kernel</strong>: The kernel represents the most basic element of an operating system. Android's Linux kernel is responsible for managing the system's resources and acts as an abstraction layer between hardware and a system's applications. </li> 44 <li><strong>ramdisk</strong>: RAMdisk defines a portion of Random Access Memory (RAM) that gets used as if it were a hard drive. </li> 45 </ul> 46 <p> </p> 47 <p>Configure the bootloader to load the kernel and RAMdisk into RAM and pass the RAMdisk address to the kernel on startup. </p> 48 <p> </p> 49 <h3>5. Boot the kernel and mount the RAMdisk.</h3> 50 <p> </p> 51 <h3>6. Debug Android-specific init programs on RAMdisk</h3> 52 <p>Android-specific init programs are found in <code>device/system/init</code>. Add LOG messages to help you debug potential problems with the LOG macro defined in <code>device/system/init/init.c</code>.</p> 53 <p> The init program directly mounts all filesystems and devices using either hard-coded file names or device names generated by probing the sysfs filesystem (thereby eliminating the need for a <code>/etc/fstab</code> file in Android). After <code>device/system</code> files are mounted, init reads <code>/etc/init.rc</code> and invokes the programs listed there (one of the first of which is the console shell).</p> 54 <p> </p> 55 <h3>7. Verify that applications have started </h3> 56 <p>Once the shell becomes available, execute <code>% ps</code> to confirm that the following applications are running:</p> 57 <ul> 58 <li><code>/system/bin/logd</code></li> 59 <li><code>/sbin/adbd</code></li> 60 <li><code>/system/bin/usbd</code></li> 61 <li><code>/system/bin/debuggerd</code></li> 62 <li><code>/system/bin/rild</code></li> 63 <li><code>/system/bin/app_process</code></li> 64 <li><code>/system/bin/runtime</code></li> 65 <li><code>/system/bin/dbus-daemon</code></li> 66 <li><code>system_server</code></li> 67 </ul> 68 <p>Each of these applications is embedded Linux C/C++ and you can use any standard Linux debugging tool to troubleshoot applications that aren't running. Execute <code>% make showcommands</code> to determine precise build commands. <code>gdbserver</code> (the GNU debugger) is available in the <code>bin</code> directory of the system partition (please see <a href="http://sourceware.org/gdb/">http://sourceware.org/gdb/</a> for more information). </p> 69 <p> </p> 70 <h3>8. Pulling it all together </h3> 71 <p>If bring up was successful, you should see the following Java applications (with icons) visible on the LCD panel:</p> 72 <ul> 73 <li>com.google.android.phone: The Android contact application. </li> 74 <li>com.google.android.home</li> 75 <li>android.process.google.content</li> 76 </ul> 77 <p>If they are not visible or unresponsive to keypad control, run the <code>framebuffer/keypad</code> tests.</p> 78 79 80 <a name="androidInitLanguage"></a><h1>Android Init Language</h1> 81 82 83 <p>The Android Init Language consists of four broad classes of statements:</p> 84 <ul> 85 <li>Actionn</li> 86 <li>Commands</li> 87 <li>Services</li> 88 <li>Options</li> 89 </ul> 90 <p>The language syntax includes the following conventions: </p> 91 <ul> 92 <li>All classes are line-oriented and consist of tokens separated by whitespace. c-style backslash escapes may be used to insert whitespace into a token. Double quotes may also be used to prevent whitespace from breaking text into multiple tokens. A backslash <br /> 93 appearing as the last character on a line is used for line-folding.</li> 94 <li> Lines that start with a # (leading whitespace allowed) are comments.</li> 95 <li>Actions and Services implicitly declare new sections. All commands 96 or options belong to the section most recently declared. Commands 97 or options before the first section are ignored. </li> 98 <li>Actions and Services have unique names. If a second Action or Service is declared with the same name as an existing one, it is ignored as an error.</li> 99 </ul> 100 <p> Actions</p> 101 <p> Actions are named sequences of commands. Actions have a trigger used to determine when the action should occur. When an event 102 occurs which matches an action's trigger, that action is added to 103 the tail of a to-be-executed queue (unless it is already on the 104 queue).<br /> 105 <br /> 106 Each action in the queue is dequeued in sequence. Each command in 107 an action is executed in sequence. Init handles other activities 108 (such as, device creation/destruction, property setting, process restarting) "between" the execution of the commands in activities. 109 <p>Actions take the form of:</p> 110 <pre class="prettify"> 111 on <trigger> 112 <command> 113 <command> 114 <command> 115 </pre> 116 <p>Services</p> 117 <p>Services are programs that init launches and (optionally) restarts 118 when they exit. </p> 119 <p>Services take the form of:</p> 120 <pre class="prettify"> 121 service <name> <pathname> [ <argument> ]* 122 <option> 123 <option> 124 ... 125 </pre> 126 <p>Options</p> 127 <p> Options are modifiers to services that affect how and when init 128 runs a service. Options are described in the table below:</p> 129 <table> 130 <tr> 131 <th scope="col">Option</th><th scope="col">Description</th></tr> 132 <tr> 133 <td><code>disabled</code></td> 134 <td>This service will not automatically start with its class. It must be explicitly started by name.</td> 135 </tr> 136 <tr> 137 <td><code>socket <type> <name> <perm> [ <user> [ <group> ] ]</code></td> 138 <td> Create a unix domain socket named <code>/dev/socket/<name></code> and pass its fd to the launched process. Valid <code><type></code> values include <code>dgram</code> and <code>stream</code>. <code>user</code> and <code>group</code> default to 0.</td> 139 </tr> 140 <tr> 141 <td><code>user <username></code></td> 142 <td>Change to username before exec'ing this service. Currently defaults to root.</td> 143 </tr> 144 <tr> 145 <td><code>group <groupname> [ <groupname> ]*</code></td> 146 <td> Change to groupname before exec'ing this service. Additional groupnames beyond the first, which is required, are used to set additional groups of the process (with <code>setgroups()</code>). Currently defaults to root.</td> 147 </tr> 148 <tr> 149 <td><code>capability [ <capability> ]+</code></td> 150 <td>Set linux capability before exec'ing this service</td> 151 </tr> 152 <tr> 153 <td><code>oneshot</code></td> 154 <td>Do not restart the service when it exits.</td> 155 </tr> 156 <tr> 157 <td><code>class <name></code></td> 158 <td>Specify a class name for the service. All services in a named class must start and stop together. A service is considered of class "default" if one is not specified via the class option.</td> 159 </tr> 160 </table> 161 <p> Triggers</p> 162 <p>Triggers are strings used to match certain kinds of events that cause an action to occur. </p> 163 <table> 164 <tr> 165 <th scope="col">Trigger</th> 166 <th scope="col">Description</th> 167 </tr> 168 <tr> 169 <td><code>boot</code></td> 170 <td>This is the first trigger that occurs when init starts (after <code>/init.conf</code> is loaded).</td> 171 </tr> 172 <tr> 173 <td><code><name>=<value></code></td> 174 <td>Triggers of this form occur when the property <code><name></code> is set to the specific value <code><value></code>.</td> 175 </tr> 176 <tr> 177 <td><code>device-added-<path><br /> 178 device-removed-<path></code></td> 179 <td>Triggers of these forms occur when a device node is added or removed.</td> 180 </tr> 181 <tr> 182 <td><code> service-exited-<name></code></td> 183 <td>Triggers of this form occur when the specified service exits.</td> 184 </tr> 185 </table> 186 <p><br /> 187 Commands</p> 188 <table> 189 <tr> 190 <th scope="col">Command</th> 191 <th scope="col">Description</th> 192 </tr> 193 <tr> 194 <td><code>exec <path> [ <argument> ]*</code></td> 195 <td>Fork and execute a program (<code><path></code>). This will block until the program completes execution. Try to avoid exec. Unlike the <code>builtin</code> commands, it runs the risk of getting init "stuck".</td> 196 </tr> 197 <tr> 198 <td><code>export <name> <value></code></td> 199 <td>Set the environment variable <code><name></code> equal to <code><value></code> in the global environment (which will be inherited by all processes started after this command is executed).</td> 200 </tr> 201 <tr> 202 <td><code>ifup <interface></code></td> 203 <td>Bring the network interface <code><interface></code> online.</td> 204 </tr> 205 <tr> 206 <td><code>import <filename></code></td> 207 <td> Parse an init config file, extending the current configuration.</td> 208 </tr> 209 <tr> 210 <td><code>hostname <name></code></td> 211 <td>Set the host name.</td> 212 </tr> 213 <tr> 214 <td><code>class_start <serviceclass></code></td> 215 <td>Start all services of the specified class if they are not already running.</td> 216 </tr> 217 <tr> 218 <td><code>class_stop <serviceclass></code></td> 219 <td>Stop all services of the specified class if they are currently running.</td> 220 </tr> 221 <tr> 222 <td><code>domainname <name></code></td> 223 <td>Set the domain name.</td> 224 </tr> 225 <tr> 226 <td><code>insmod <path></code></td> 227 <td>Install the module at <code><path></code>.</td> 228 </tr> 229 <tr> 230 <td><code>mkdir <path></code></td> 231 <td>Make a directory at <code><path></code>.</td> 232 </tr> 233 <tr> 234 <td><code>mount <type> <device> <dir> [ <mountoption> ]*</code></td> 235 <td>Attempt to mount the named device at the directory <code><dir></code> <code><device></code>. This may be of the form mtd@name to specify a mtd block device by name.</td> 236 </tr> 237 <tr> 238 <td><code>setkey</code></td> 239 <td>- currenlty undefined - </td> 240 </tr> 241 <tr> 242 <td><code>setprop <name> <value></code></td> 243 <td>Set system property <code><name></code> to <code><value></code>.</td> 244 </tr> 245 <tr> 246 <td><code> setrlimit <resource> <cur> <max></code></td> 247 <td>Set the rlimit for a resource.</td> 248 </tr> 249 <tr> 250 <td><code>start <service></code></td> 251 <td>Start a service running if it is not already running.</td> 252 </tr> 253 <tr> 254 <td><code> stop <service></code></td> 255 <td>Stop a service from running if it is currently running.</td> 256 </tr> 257 <tr> 258 <td><code>symlink <target> <path></code></td> 259 <td>Create a symbolic link at <code><path></code> with the value <code><target></code>.</td> 260 </tr> 261 <tr> 262 <td><code>write <path> <string> [ <string> ]*</code></td> 263 <td>Open the file at <code><path></code> and write one or more strings to it with write(2).</td> 264 </tr> 265 </table> 266 <p> Properties</p> 267 Init updates some system properties to provide some insight into <br /> 268 what it's doing:</p> 269 <table> 270 <tr> 271 <th scope="col">Property</th> 272 <th scope="col">Description</th> 273 </tr> 274 <tr> 275 <td><code>init.action</code></td> 276 <td>Equal to the name of the action currently being executed or "" if none.</td> 277 </tr> 278 <tr> 279 <td><code>init.command</code></td> 280 <td>Equal to the command being executed or "" if none.</td> 281 </tr> 282 <tr> 283 <td><code>init.svc.<name></code></td> 284 <td>State of a named service ("stopped", "running", or "restarting").</td> 285 </tr> 286 </table> 287 <p>Example init.conf</p> 288 <p>The following snippet is an incomplete example of the <code>init.conf</code> file, simply meant to give you an idea of what a proper configuration resembles.</p> 289 <pre class="prettify"> 290 on boot 291 export PATH /sbin:/system/sbin:/system/bin 292 export LD_LIBRARY_PATH /system/lib 293 294 mkdir /dev 295 mkdir /proc 296 mkdir /sys 297 298 299 mount tmpfs tmpfs /dev 300 mkdir /dev/pts 301 mkdir /dev/socket 302 mount devpts devpts /dev/pts 303 mount proc proc /proc 304 mount sysfs sysfs /sys 305 306 307 write /proc/cpu/alignment 4 308 309 310 ifup lo 311 312 313 hostname localhost 314 domainname localhost 315 316 317 mount yaffs2 mtd@system /system 318 mount yaffs2 mtd@userdata /data 319 320 321 import /system/etc/init.conf 322 323 324 class_start default 325 326 327 service adbd /sbin/adbd 328 user adb 329 group adb 330 331 332 service usbd /system/bin/usbd -r 333 user usbd 334 group usbd 335 socket usbd 666 336 337 338 service zygote /system/bin/app_process -Xzygote /system/bin --zygote 339 socket zygote 666 340 341 342 service runtime /system/bin/runtime 343 user system 344 group system 345 346 347 on device-added-/dev/compass 348 start akmd 349 350 351 on device-removed-/dev/compass 352 stop akmd 353 354 355 service akmd /sbin/akmd 356 disabled 357 user akmd 358 group akmd 359 </pre> 360