Skip to content

Instantly share code, notes, and snippets.

@eyecatchup
Created November 13, 2014 11:40
Show Gist options
  • Save eyecatchup/06b28233efecfed63e3b to your computer and use it in GitHub Desktop.
Save eyecatchup/06b28233efecfed63e3b to your computer and use it in GitHub Desktop.
The safest way to flash factory images - This is a manual step-by-step procedure to flash Android 5.0 (LRX21O) factory images onto the Nexus 5 (aka hammerhead).
# Create a new working directory and cd into it
~$ mkdir -p /path/n5update && cd /path/n5update
# Download all files you need
/path/n5update$ wget --no-check-certificates https://dl.google.com/dl/android/aosp/hammerhead-lrx21o-factory-01315e08.tgz
/path/n5update$ wget --no-check-certificates https://copy.com/pV8d7OdciGi2EUQu/openrecovery-twrp-2.8.1.0-hammerhead.img
# @chainfire: I really hope it's not too cheeky, I just so wanted a hotlink for this one. :| As soon as you ask, it's gone.
/path/n5update$ wget --no-check-certificates https://copy.com/spuYd3VhHiAULMCL/CF-Auto-Root-hammerhead-hammerhead-nexus5.zip
# Extract downloaded file archives
/path/n5update$ mkdir -p ./images && tar zxvf hammerhead-lrx21o-factory-01315e08.tgz -C ./images
/path/n5update$ unzip -jXVK ./images/hammerhead-lrx21o/image-hammerhead-lrx21o.zip -d ./images/hammerhead-lrx21o
/path/n5update$ unzip -XVK CF-Auto-Root-hammerhead-hammerhead-nexus5.zip -d ./cf
# Remove unneeded archive files
/path/n5update$ rm CF-Auto-Root-hammerhead-hammerhead-nexus5.zip
/path/n5update$ rm hammerhead-lrx21o-factory-01315e08.tgz
/path/n5update$ rm ./images/hammerhead-lrx21o/image-hammerhead-lrx21o.zip
# Update required flashing utility tools via SDK manager's command line options
/path/n5update$ android.[bat|sh] update sdk -u -t platform-tools,tools
/path/n5update$ android.[bat|sh] update adb
# Boot into bootloader mode
/path/n5update$ adb reboot bootloader
# In bootloader mode, make sure the device is recognized
/path/n5update$ fastboot devices
# Erase old boot, cache, system & userdata partitions
/path/n5update$ fastboot erase boot
/path/n5update$ fastboot erase cache
/path/n5update$ fastboot erase system
/path/n5update$ fastboot erase userdata
# IGNORE THIS COMMAND, IF YOU HAVE A CUSTOM RECOVERY INSTALLED AND WANT TO KEEP IT.
# IF YOU HAVE THE STOCK RECOVERY, DO NOT IGNORE THE NEXT LINE.
/path/n5update$ fastboot erase recovery
# Flash new bootloader & reboot into
/path/n5update$ fastboot flash bootloader ./images/hammerhead-lrx21o/bootloader-hammerhead-hhz12d.img
/path/n5update$ fastboot reboot-bootloader
# Flash new radio & reboot bootloader
/path/n5update$ fastboot flash radio ./images/hammerhead-lrx21o/radio-hammerhead-m8974a-2.0.50.2.21.img
/path/n5update$ fastboot reboot-bootloader
# Do wipe again.
/path/n5update$ fastboot -w
# Flash new boot, cache, system & userdata partitions
/path/n5update$ fastboot flash system ./images/hammerhead-lrx21o/system.img
/path/n5update$ fastboot flash userdata ./images/hammerhead-lrx21o/userdata.img
/path/n5update$ fastboot flash cache ./images/hammerhead-lrx21o/cache.img
/path/n5update$ fastboot flash boot ./images/hammerhead-lrx21o/boot.img
# ONLY REQUIRED, IF YOU ERASED THE RECOVERY PARTITION BEFORE.
# USE ONLY ONE OF THE FOLLOWING TWO LINES (1. Stock, 2. TWRP)!
/path/n5update$ fastboot flash recovery ./images/hammerhead-lrx21o/recovery.img
/path/n5update$ fastboot flash recovery ./openrecovery-twrp-2.8.1.0-hammerhead.img
# Reboot the system using the CF-Auto-Root boot image
/path/n5update$ fastboot boot ./cf/image/CF-Auto-Root-hammerhead-hammerhead-nexus5.img
# Device will reboot when CF-Auto-Root finished its job.
# Done.
# Bye
@khesayed
Copy link

khesayed commented Dec 5, 2014

You can run flash-all file:

  • Windows OS: Run the flash-all.bat file.
  • MAC OS: Run the flash-all.sh using the Terminal.
  • Linux OS: Run the flash-all.sh file.

@eyecatchup
Copy link
Author

@khesayed REALLY!?!? ;-) Well, sure you can. This is, as the description says, the safest not the fastest way to do pretty much the same thing. Internal processing of flash-all is, however, a bit different. For me, at least, that bit matters. Because, from my experience, which dates back to GRF39K for the Nexus One and includes several hundred flashes per device, there're way less bad flashes when you do it manually - as outlined in the gist - compared to running flash-all. That being said, it may not be required for the random user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment