Sideloading Nexus Devices with the Android SDK

Android 5.0 "Lollipop" was released yesterday and I wanted to check it out on my Nexus 7 2013 WiFi tablet without having to wait for the update to be pushed. I've done this several times with various Nexus devices now, but so infrequently that I always have to look up how to do it. So this time I'm taking some notes. It should be noted that most of this information is just scraped from the flash-all.{bat,sh} included in the factory image.

First off, Nexus factory images are listed here. Start off by pulling the proper one down, verifying the integrity, and then extracting the tarball:

~ $ mkdir tmp && cd tmp && wget -q https://dl.google.com/dl/android/aosp/razor-lrx21p-factory-ba55c6ab.tgz
~/tmp $ md5sum razor-lrx21p-factory-ba55c6ab.tgz 
fd868b03bd00074dd7f70e31ad73b25a  razor-lrx21p-factory-ba55c6ab.tgz
~/tmp $ tar xf razor-lrx21p-factory-ba55c6ab.tgz 
~/tmp $ ls razor-lrx21p
bootloader-flo-flo-04.04.img  flash-all.bat  flash-all.sh  flash-base.sh  image-razor-lrx21p.zip

To start the bootloader will need to be unlocked. This will wipe the data on the device, but once unlocked this is no longer an issue when flashing in the future. Sideloading the image requires the Android SDK platform tools.

First thing's first: get into the bootloader. Begin by plugging the tablet into the PC and verifying that it's connected.

~/android-studio/sdk/platform-tools $ ./adb devices -l
List of devices attached 
0a16e983               device usb:1-1.2 product:razor model:Nexus_7 device:flo

Now reboot into the bootloader:

~/android-studio/sdk/platform-tools $ ./adb reboot bootloader

Once in the bootloader make sure the device is connected/detected:

~/android-studio/sdk/platform-tools $ sudo ./fastboot devices -l
0a16e983               fastboot usb:1-1.2

If the bootloader is not already unlocked this will need to be done first (note: this wipes the device, so be sure to back things up beforehand). Unlock the bootloader with the following command (follow the prompts on the device; it'll warn about wiping the device clean):

~/android-studio/sdk/platform-tools $ sudo ./fastboot oem unlock
...
(bootloader) Unlocking bootloader...
(bootloader) erasing userdata...
(bootloader) erasing userdata done
(bootloader) erasing cache...
(bootloader) erasing cache done
(bootloader) Unlocking bootloader done!
OKAY [ 65.559s]
finished. total time: 65.559s

Now flash the bootloader image downloaded earlier:

~/android-studio/sdk/platform-tools $ sudo ./fastboot  flash bootloader ~/tmp/razor-lrx21p/bootloader-flo-flo-04.04.img 
sending 'bootloader' (3911 KB)...
OKAY [  0.192s]
writing 'bootloader'...
OKAY [  1.936s]
finished. total time: 2.128s

And reboot into the bootloader again:

~/android-studio/sdk/platform-tools $ sudo ./fastboot reboot-bootloader
rebooting into bootloader...
OKAY [  0.006s]
finished. total time: 0.006s

Next flash the zip image:

~/android-studio/sdk/platform-tools $ sudo ./fastboot -w update ~/tmp/razor-lrx21p/image-razor-lrx21p.zip 
archive does not contain 'boot.sig'
archive does not contain 'recovery.sig'
archive does not contain 'system.sig'
--------------------------------------------
Bootloader Version...: FLO-04.04
Baseband Version.....: none
Serial Number........: 0a16e983
--------------------------------------------
checking product...
OKAY [  0.003s]
checking version-bootloader...
OKAY [  0.004s]
sending 'boot' (7154 KB)...
OKAY [  0.347s]
writing 'boot'...
OKAY [  0.420s]
sending 'recovery' (7740 KB)...
OKAY [  0.369s]
writing 'recovery'...
OKAY [  0.297s]
erasing 'system'...
OKAY [  1.510s]
sending 'system' (799121 KB)...
OKAY [ 37.893s]
writing 'system'...
OKAY [ 35.392s]
erasing 'userdata'...
OKAY [ 23.679s]
formatting 'userdata' partition...
Creating filesystem with parameters:
    Size: 28856791040
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 8192
    Inode size: 256
    Journal blocks: 32768
    Label: 
    Blocks: 7045115
    Block groups: 215
    Reserved block group size: 1024
Created filesystem with 11/1761280 inodes and 154578/7045115 blocks
sending 'userdata' (139085 KB)...
writing 'userdata'...
OKAY [ 13.485s]
erasing 'cache'...
OKAY [  0.406s]
formatting 'cache' partition...
Creating filesystem with parameters:
    Size: 587202560
    Block size: 4096
    Blocks per group: 32768
    Inodes per group: 7168
    Inode size: 256
    Journal blocks: 2240
    Label: 
    Blocks: 143360
    Block groups: 5
    Reserved block group size: 39
Created filesystem with 11/35840 inodes and 4616/143360 blocks
sending 'cache' (10984 KB)...
writing 'cache'...
OKAY [  1.033s]
rebooting...

finished. total time: 114.857s

And now it's finished. If the bootloader was already locked previously, then you can remove the -w flag in the last command to avoid wiping the device (note: I've not tried this yet).