Android Developer Tools – Fastboot

Fastboot is a protocol used to update the flash filesystem in Android devices from a host via USB. It is part of the Android Debug Bridge library (adb). The materialization of this protocol is the fastboot command, which we can make use of, to easily interface with the protocol. Since it is part of the adb library, before using it, we need to install the Android SDK and configure our environment to work from the command line. This post, will guide you through this process.

As fastboot will allow us to flash a device using a USB interface, we need both -the host machine and the device to be flashed- to be aware that we are using the fastboot protocol. For this, we need to enable the protocol in the device itself so that commands arriving from the USB port in the host machine are accepted. Fastboot, as we can imagine, given its nature of “flashing protocol”, does not require a OS to run on the device, but it does need at least, a basic shell to run on top of – just like the one provided in a common boot loader such us u-boot. (Please follow this link to read more about The Bootloader). In order to access this shell, power on your device and press any key before the kernel is loaded (around 5 seconds). You will get a console that looks like the one in the picture below. Type help in order to see which commands are available.

Newer versions of u-boot (one of the most popular boot loaders) integrate with fastboot, and make it easier to use – avoiding for example having to create the .img of any image prior flashing it to the device. If you cannot find fastboot listed in your available commands in the console provided by the boot loader, maybe it is time to update :)

(Get the latest u-boot from DENX‘s git repository – Type in your console git clone git://git.denx.de/u-boot.git)

Once you have got a boot loader with fastboot just type fastboot in the console provided by u-boot. You should see something like this (Please notice the underlined line):

Now, you should insert your OTG cable (mine is MicroUSB(male) – USB(male) ) and connect it to your host machine. You should see that when you plug the cable in, you get a “OTG cable Connected!” in your serial terminal. This means that now the device is waiting to get commands over the USB port.

Now we are going to comment the different actions you can carry out with fastboot. We type fastboot help and we get:

Most of the fastboot options are -as we can see- self-explanatory. In order to make it easier to understand, we are going to put ourselves in the scenario where we have a device (board,phone, tablet,etc) with a recently flashed boot loader and a well-formed MBR and partition table (use fdisk for this). Our intention is to flash a kernel and and Android as our OS. Also we want a clean start, in case some “dirty” data is still in our boot device. See this post for more information regarding flash devices -SDCards or USBs) wiping - Coming soon. (Please notice that these commands should be typed in the host machine side):

  • fastboot devices // Check, in case we have more than one device connected
  • fastboot format kernel
  • fastboot format system
  • fastboot format ramdisk
  • fastboot flash kernel $KERNELDIR/arch/armboot/zImage
  • fastboot flash system $ANDROIDDIR/out/target/product/$BOARD/system.img
  • fastboot flash ramdisk $ANDROIDDIR/out/target/product/$BOARD/ramdisk-uboot.img
  • fastboot -w
  • fastboot reboot

The board should restart and successfully complete the boot sequence, allowing us to handle the device as any other Android device we have used before.

Fastboot is extremely useful for flashing boot devices. Here, we have seen an example on how to “flash” images as such. However, we can use it for many other things when we are developing:

  • Format partitions - fastboot format <partition>
  • Erase partitions - fastboot erase <partition>
  • Debug the boot loader and see its configuration and boot/operation modes (variables) - fastboot getvar <variable>
  • Download a kernel and boot it - fastboot boot <kernel> [ <ramdisk> ]
  • Create a boot image from a kernel (and flash it) - fastboot flash:raw boot <kernel> [ <ramdisk> ]

Also, it allow us to play with some more advance features such as modify base address for the kernel (fastboot -b <base_address>) or the page size (fastboot -n <page_size>).

Indeed, a very useful tool for facilitation the process of flashing images when developing for embedded systems ;)

-javier