Friday, November 16, 2018

fix Nexus 6p bootloop, the right way, you bastard

If your 6p is bootlooping, you have a two options - either (1) search the internet for hours, reading multiple conflicting guides and trying solutions that put your phone deeper in the hole, or (2) read this.

(The 6p bootloop (aka "Bootloop of Death", or BLOD), in case your search is just starting out and you aren't quite sure how to refer to your phone's problem, is when the phone shuts down randomly, then shows the early-boot "Google" logo on a black background for ~10 seconds, then you get one second of black screen, and then "Google" comes back, and this repeats endlessly.  You can't shut it down, you can't do shit but watch it cycle as it drains your device of life.)

The overview of what's below: find the bootloader that your phone needs, manually modify the files so that the performance cores (4-7) are disabled, only leaving you with the lightweight cores (0-3), and upload the new bootloader files to your phone.  Idk if this keeps working through an OTA update or not, but it's a pretty easy process once you get the hang of it.

Also, this guide is for a linux host - everything should be almost the same for windows and mac, but the commands are slightly different and you have to download different versions of host tools.

Here's the future-proof-ish way to fix your goddam phone:
  1. Get the latest "platform-tools".  Or at least get this one, it worked for me.
  2. Unzip that shit and cd into the new dir it created, hereafter referred to as ~/Downloads/platform-tools.
  3. Boot your piece of shit brickphone into the recovery menu by holding the power and "volume down" buttons for what feels like an eternity.  Seriously, when the 6p is bootlooping, it can take like 20 seconds.  Don't let up until you get into a strange and magical menu you've either (1) never seen before, or (2) you have seen before and can identify as the fucking recovery menu.

    Or, if the handset can still boot to android, and it has, and you're in ~/Downloads/platform-tools, you can run:

    ./adb reboot bootloader

    This adb command will only work if, on your phone, you've previously gone into Settings -> System -> About Phone, scrolled to the bottom, and tapped "Build number" about a thousand times, and then gone into Settings -> System -> Developer options and enabled "USB debugging".

    But the fucking point is to get to the recovery menu. 
  4. Make sure your PC can talk to your phone.  Plug the phone into the PC.  On your linux PC, with pwd inside the unzipped platform-tools dir, run this:

    ./fastboot devices

    If that spits out nothing, then either your phone is totally fucked or you've done something dumb and you need to go back to step 3 and actually make sure you're booted into the recovery menu.  If it spits out one (or more! who knows what the future holds for ./fastboot devices!) line of stuff, then proceed.
  5. Unlock the bootloader.  THIS WILL WIPE ALL YOUR DATA, but you have to fucking do it man.  Just do it, c'mon.

    ./fastboot flashing unlock

    Now your user data is toast - hope you backed up all the important shit, like the photos of your cat and the food you ate.  You'll have to factory reset at some point after this, though I'm skipping the pain steps I went through here for your fucking benefit so I don't know when that reset will be forced upon you exactly.

    (Whenever your pattern or unlock code or whatever doesn't work, that's when you need to start googling how to do the factory data reset.  It doesn't affect anything else, in this guide we're modifying the boot partitions.  If you've read this far you can branch off and figure out that one discrete step whenever it's time.  Sorry.)
  6. Now you need to get the most recent bootloader for this ancient handset.  This is the site where they're all available, and this is the direct link to the current one that worked for my Project Fi 6p as of 2018/11/16.  Stay frosty yokels, this is a ~1GB download.

    You aren't sure which one is the right one to download!  So if you're reading this too long after publication, you should probably scroll to the bottom of the 6p downloads in that first link and grab the most recent, if your phone is up to date.  If you're on the cutting edge of sarcastic linux blogging and you read this soon after I wrote it, or if there aren't any more updates for the 6p at all after this point, then you might be good with the second link above.  Otherwise, who knows!  Any of those downloads could be the right one!  You'll just have to try flashing a bunch and figure out which one allows your phone to boot!  (Or find some way to determine which you need, which sadly is outside the scope of this "article".)  Sorry I'm such a shit.  But don't worry, if you follow these instructions and your phone won't boot, all you have to do is flash the right bootloader to fix it.

    Note also that you'll have to unzip the inner zipfile (something like inside the downloaded angler zipfile to get to the actual file you're really after here, which in this case is boot.img.  
  7. We're going to be manually patching this pile of garbage, so we need a utility that can unpack and repack android boot images.  It's called AIK (Android Image Kitchen), get the version I used here.  Untar it, blah blah blah, sorry again.  Something like tar xvf AIK-Linux-whatever.tar.gz.  The place where all this lives is hereafter referred to as ~/Downloads/AIK-Linuxcd into it now.
  8. Ok, the scallops are minced and the lettuce is browned and we have a fresh liter of chili powder on standby - time to cook!
  9. We need to cp the boot.img into the local dir and unpack it so we can do some surgery.  From ~/Downloads/AIK-Linux:

    cp -v ../angler-whatever-do-I-look-like-I-fish/boot.img .
    ./ boot.img

    (You'll be sudo prompted, for some reason.  So if you're getting the five-finger discount on clock cycles from your university's timeshare system, look out!)
  10. This unpacks into two dirs, ramdisk and split_img.  You need to make the same modifications as in the following github changesets.  (Sorry, this would have been super easy to script, but so much more fun to write about.  This is our cycle of violence, fellow nerds.)

    Adding "maxcpus=4" to the end of the line. (in split_img/boot.img-cmdline)
    Changing everything to use CPUs 0-3 only. (in ramdisk/init.angler.rc)
  11. Then you have to repack that turd so it'll fit back into your phone:

  12. The output file of the script is boot-new.img.  Make sure your phone is still in recovery (see step 3) and run the following to flash the new bootloader:

    cd ~/Downloads/platform-tools
    ./fastboot flash boot ../AIK-Linux/boot-new.img
  13. Then reboot:

    ./fastboot reboot
  14. And I expect you should be booted into a device that you can't unlock and you'll have to google how to factory reset it!  But once you do, the failed big cores will be disabled, and your 6p will become a family heirloom passed down to your great-great grandkids.  And honestly, to me, so far the device's performance actually seems a lot better without those failed big cores - I thought the phone would be horribly sluggish, but I was wrong (imagine that!).  The responsiveness is better than before the fix on my handset, at any rate.
Thanks for reading this far, and sorry I was so angry.  I fucking hate fixing phones, and hope that this may help someone to not have to feel the frustration I've felt, but instead get to laugh at me and have a functional phone again in a shorter time than it took me.  Thanks to all those insane motherfuckers on XDA, youtube, etc who actually figured this shit out - I would call you out by name but I cobbled this together from like 15 different guides.