OS: Mac OS Mavericks

If you want to flash your Android 5 device with a new system image, you will more than likely need to unlock the bootloader. This is done by enabling the OEM unlock.

You will need the developer’s SDK for the tools needed: https://developer.android.com/sdk/index.html

After you install the SDK, it will make things easier if you add the location of the tools needed to your PATH variable. Note: you will probably need to create the .bash_profile file. One does not exist by default in Mavericks.

$ cat ~/.bash_profile
export PATH=$PATH:/Users/username/Library/Android/sdk/platform-tools

Plug your phone in using the USB cable. Note: I have had some issues with different micro USB cables. I would use the one that came with phone if possible.

You can try the OEM unlock by issuing the following command. This did not work for me with a Nexus 6. Instead, I unlocked it from the Developer options.

$ fastboot oem unlock

Enabling Developer options:

Go to “Settings” and then “About Phone”, and tap the firmware version several times. You will get a countdown for the number of taps to get you into Developer mode. Go back to “Settings” and notice that you now have a “Developers options” option. Select it and turn on OEM unlocking. You might have enter your phone unlock PIN and then confirm to enable.

Turn off the phone. Hold down volume button on the volume rocker and power button at the same time. This will put your phone into transfer mode.

Download the Android M preview system image from: https://developer.android.com/preview/download.html
Other available system images for when you want to switch back: https://developers.google.com/android/nexus/images

Uncompress the downloaded shamu-MPZ44Q-preview-c1d6506a.tgz file by double clicking it in Finder.

Using Terminal go to the location where you saved and uncompressed the download. The directory will be called shamu-MPZ44Q. In that directory, unzip image-shamu-MPZ44Q.zip.

Install Android M:

./flash-base.sh
fastboot flash recovery recovery.img
fastboot flash boot boot.img
fastboot flash system system.img
fastboot flash cache cache.img
fastboot flash userdata userdata.img
fastboot reboot

Here is what the output should look like:

flash_base.sh:

$ ./flash-base.sh
target reported max download size of 536870912 bytes
sending ‘bootloader’ (3807 KB)…
OKAY [ 0.187s]
writing ‘bootloader’…
(bootloader) flashing partition …
(bootloader) This may take a few seconds if a
(bootloader) different partition table is being
(bootloader) flashed since we need to backup
(bootloader) and restore a few partitions
(bootloader) Flashing primary GPT image…
(bootloader) Flashing backup GPT image…
(bootloader) flashing aboot …
(bootloader) flashing sbl1 …
(bootloader) flashing rpm …
(bootloader) flashing tz …
(bootloader) flashing sdi …
(bootloader) flashing logo …
OKAY [ 0.358s]
finished. total time: 0.545s
rebooting into bootloader…
OKAY [ 0.001s]
finished. total time: 0.001s
target reported max download size of 536870912 bytes
sending ‘radio’ (67556 KB)…
OKAY [ 2.965s]
writing ‘radio’…
(bootloader) flashing modem …
(bootloader) flashing mdm1m9kefs1 …
(bootloader) flashing mdm1m9kefs2 …
(bootloader) flashing mdm1m9kefs3 …
(bootloader) flashing versions …
OKAY [ 0.739s]
finished. total time: 3.704s
rebooting into bootloader…
OKAY [ 0.001s]
finished. total time: 0.001s

recovery.img:

$ fastboot flash recovery recovery.img
target reported max download size of 536870912 bytes
sending ‘recovery’ (8877 KB)…
OKAY [ 0.444s]
writing ‘recovery’…
OKAY [ 0.118s]
finished. total time: 0.562s

boot.img:

jimsmac:temp jgz$ fastboot flash boot boot.img
target reported max download size of 536870912 bytes
sending ‘boot’ (8161 KB)…
OKAY [ 0.406s]
writing ‘boot’…
OKAY [ 0.087s]
finished. total time: 0.493s

system.img:

$ fastboot flash system system.img
target reported max download size of 536870912 bytes
sending sparse ‘system’ (517183 KB)…
OKAY [ 31.545s]
writing ‘system’…
OKAY [ 5.282s]
sending sparse ‘system’ (523718 KB)…
OKAY [ 32.352s]
writing ‘system’…
OKAY [ 5.009s]
sending sparse ‘system’ (522246 KB)…
OKAY [ 31.508s]
writing ‘system’…
OKAY [ 4.846s]
sending sparse ‘system’ (370015 KB)…
OKAY [ 23.730s]
writing ‘system’…
OKAY [ 3.407s]
finished. total time: 137.691s

cache.img:

$ fastboot flash cache cache.img
target reported max download size of 536870912 bytes
erasing ‘cache’…
OKAY [ 0.035s]
sending ‘cache’ (6248 KB)…
OKAY [ 0.329s]
writing ‘cache’…
OKAY [ 0.083s]
finished. total time: 0.447s

userdata.img:

$ fastboot flash userdata userdata.img
target reported max download size of 536870912 bytes
erasing ‘userdata’…
OKAY [ 2.290s]
sending ‘userdata’ (138868 KB)…
OKAY [ 6.092s]
writing ‘userdata’…
OKAY [ 2.058s]
finished. total time: 10.440s

reboot:

$ fastboot reboot
rebooting…

finished. total time: 0.022s

You can use the same procedure to downgrade your phone back to Lollipop using one of the downloads at https://developers.google.com/android/nexus/images.