Book Image

Instant Android Systems Development How-to

By : Earlence Fernandes
Book Image

Instant Android Systems Development How-to

By: Earlence Fernandes

Overview of this book

<p>Android is by far the most popular open source mobile operating system. Learning to write high quality code at the platform level and learning how the systems works internally is a vital skill. This book teaches you these skills with clear and concise explanations and code examples.</p> <p>Instant Android Systems Development How-to provides a gentle introduction to the platform internals without sacrificing depth. Source code examples are designed to be meaningful, but at the same time, do not disguise their real purpose, which is to illustrate systems development techniques and common design patterns in android systems programming. Readers will be guided through several examples that give a hands-on experience.</p> <p>Readers begin by downloading the android source code, which is a topic of much discussion on android forums. They are then guided through the android boot process, and later on learn various common android systems development paradigms. More importantly, the book provides advice on when to use certain techniques which is often a mystery for the novice developer. Readers who complete the book will have high confidence in developing good systems code for Android.</p> <p>The book discusses how to setup a development machine and how to obtain the android source code and kernel code. It describes the source code organization and how the system boots up with precise references to various points in the source code. It highlights the common systems design patterns followed and how to create a custom system service. It then covers the all important flashing of phones. This is a topic of much confusion and the book provides direct steps to achieve safe flashing of developer phones. It describes the user application library mechanism and the platform library mechanism. Native code is needed for certain operations and an example service utilizing native code is explained. Modification of core system applications is explained and useful tips are provided on how to speed up the build-test cycle. The book concludes with a case study of two real world android platform extensions which give the user a reference while developing their own extensions.</p> <p>Instant Android Systems Development How-to is a well rounded book on platform internals that provides simple explanations without sacrificing depth and rigor.</p>
Table of Contents (7 chapters)
Instant Android Systems Development How-to
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Instant Android Systems Development How-to

Flashing with Fastboot (Must know)


Fastboot is a tool and a protocol used to communicate with bootloaders. It exists as a binary and gets included in your path when you work with the Android sources. Fastboot is also a part of the standard SDK (under platform-tools).

Getting ready

Before you can flash any software, you need to boot the device into fastboot mode. There are two ways of doing this:

  1. Using key combinations:

    • First, power off the phone completely

    • (Nexus One) Passion: Press and hold the trackball, then press Power

    • (Nexus S) Crespo: Press and hold Volume Up, then press and hold Power

    • (Galaxy Nexus) Maguro: Press and hold both Volume Up and Volume Down, then press and hold Power

  2. Using ADB commands: The following command reboots the device into recovery mode. This has the same effect as the key combinations.

    adb reboot-bootloader
    

    Unlock the bootloader: You can flash software only if the bootloader allows it. We need to unlock the bootloader with the following command once the device is in fastboot mode.

    fastboot oem unlock
    

    Note

    Be sure to back up whatever files/data you need from the device, since this operation erases all device memory.

    And follow the onscreen instructions.

    Note

    On the Nexus One, this operation voids the warranty.

    For the Galaxy Nexus and Nexus S devices, you can lock the bootloader via the following command:

    fastboot oem lock

How to do it…

  1. To flash, you need to ensure you are connected to the device in fastboot mode. The following command will display the device's serial number on the terminal:

    fastboot devices
    
  2. Then, execute the following in order:

    fastboot erase userdata
    fastboot erase cache
    fastboot flash boot boot.img
    fastboot flash recovery recovery.img
    fastboot flash system system.img
    fastboot reboot
    

    The device will boot into the custom operation system. For additional information on different fastboot commands and the flashing process in general, refer to http://source.android.com/source/building-devices.html.

    Note

    After a successful build, the required system images will be available at ANDROID_SRC/target/out/product/<NAME>/.

    Here, <NAME> refers to the target. For the emulator, it is generic, similarly, for the Nexus S, it will be crespo. The available images will be system.img, boot.img, and recovery.img.

How it works…

Fastboot is a protocol to communicate with device bootloaders. This was designed such that flashing can be independent of the underlying bootloader. The process of unlocking the bootloader is available on developer devices. This is a recent feature starting with Nexus S. Relocking bootloaders allows you to lock the bootloader preventing the installation of new firmware.

Google developer phones can be loaded with custom software that we have been building in the previous recipes (Google developer phones are special devices designed for platform developers and not for the typical consumer). Firmware can be written to these devices' flash memory as the bootloader is unlocked. Consumer devices normally lock their bootloaders and flashing is not possible. The workflow for all three of the developer phones (Nexus One, Nexus S, and Galaxy Nexus) is, for the most part, identical. Fastboot is a protocol and a flashing tool used to write new software images to the device.

For more details on the fastboot protocol, refer ANDROID_SRC/bootable/bootloader/legacy/fastboot_protocol.txt.