Saturday, November 22, 2014

Man vs. Android - The Road To Victory

It took way too long to see this...
I have something of a love-hate relationship with Android. On the one hand, as backed up by Coyote Blog, among several others, there's really no way to describe the difference between the Google ecosystem and any of the other ones. Since I work in IT, having a small, portable computing Swiss Army knife is really useful, and, for various security reasons, you can't get anything like Wifi Analyzer or Terminal for iPhone or Windows Mobile. Which is really a shame, because, like clockwork, after I keep whatever Android phone I have for about a year or so, it slowly but inexorably does its best imitation of a long-suffering Windows 98 install. It runs slower. It randomly reboots. It freezes.

I kid you not - it even bluescreens.

My current phone, a Motorola RAZR HD (XT956, for those keeping track at home), started acting up about a year or so ago after an OTA update ("Over-The-Air" - one provided by my cell phone provider). Ever since then, it just hasn't been the same. For a while, I was willing to just sort of deal with it - sure, it was slower after the update, and yeah, it wasn't as stable as before, but maybe the next update will clean some of that up. Sure enough, about a month or so later, another update came to my phone and I tried to install it.

Tried and failed.

Okay - no problem. Maybe I can install my own updates - maybe, if I'm feeling really bold, I can install my own version of Android, one without all the random apps that Verizon likes to toss on to all of their phones. Unfortunately, the first update I installed locked the door (though only temporarily, it seems) on unlocking the bootloader[1]. Once I learned that, I decided to hold off, suffer a little longer, and see if things improved over time. Perhaps someone would find a way to unlock my phone, perhaps some of the applications on the phone would get updated, or perhaps my upgrade period would come around and I'd decide whether I'd rather have a flexible but unstable Swiss Army knife or instead opt for something more stable but a little less usable in certain circumstances.

Time passed. Things did not improve.

After suffering for a while, I decided that I was close enough to my upgrade window to roll the dice - if I failed and ended up with a brick, I could always go to the store over the weekend and do a little phone shopping. So, I decided it was time to have some fun. I had recently read about Safestrap and thought that it might let me in far enough to get off of Jelly Bean and install KitKat - an upgrade, by the way, that would've been available to my phone if my phone could install updates. To install Safestrap, I needed root access - no problem, plenty of walkthroughs for that. The first step was to grab the DROID RAZR HD Utility, a handy pile of scripts and files that included a factory firmware for my phone.

Perfect - the first step was to literally wipe and reload my phone. I was pretty happy at this point.

Eventually, I successfully installed root, gained the access I thought I wanted, installed Safestrap, and... learned that Safestrap will only let you install ROMs based on the stock version of the kernel you have installed. That was a problem for me since one of the problems I wanted to solve was the lousy memory management in my phone's kernel - despite having 1 GB of RAM and consistently having over 100 MB free, it would keep trying to page from the much slower flash memory. Since one of the big benefits of KitKat was "Project Svelte", Google's focus on a leaner, meaner kernel, I was really interested in getting off of the one my phone was equipped with somehow.

After growing disillusioned with Safestrap, I began to explore my recently wiped phone and discovered that it was requesting an OTA update. Just for kicks, I went ahead and tried to install it.

It was successful.

Ah! Now we're getting somewhere. Do this a few more times and I'll finally be on KitKat yet! I installed the next one... then the next one... and then there it was, all 400+ MB of it - KitKat. The end goal was in sight.

The install failed.

I tried it again. It failed again.

Now I was desperate. I was this close to pulling this off. It was past midnight, I was tired, I was close... I made a desperate and nearly catastrophic move.

While poking around through some of the utilities that I was using to gain root, I noticed that the DROID RAZR HD Utility just had a bunch of Android system files lying around and a shell script that called some Motorola programming utilities to push the files on to the phone. "Well," I thought to myself, "what if I just download the KitKat update, replace the files in the HD Utility, and call it a night? Maybe I can force the phone to take the update!"

Oh, it took it, all right. It took it good and hard, which is why I'm finishing this blog post at 3:15 in the morning.

It turns out that the script only updates some of the files, not all of them, which is a problem since many of the files in the update deal with radio updates, changing the file structure of the phone itself, and a whole host of other changes that are far beyond the scope of a tool that's designed to get a RAZR HD back to where it was when it was first removed from the box. Consequently, when I attempted to boot off of my "updated" system, I was attempting to boot off of what was, at best, a half updated system.

The phone really didn't like that.

Thankfully, after a considerable amount of patience, holding down the power button and the down volume button for 30 seconds, then quickly flicking the volume finger to the up volume button over and over and over again, some trial and error, and an absolutely fantastic tutorial (Mr. Bluecoat, whoever you are, thank you!), I was able to get my phone back up and running with KitKat installed.

Chocolate-flavored kernel victory is mine!


1. On a computer - and, these days, modern smartphones qualify - getting from "powered off" to "usable" is a two (okay, three if you want to get really technical) stage process. In the first stage, the computer looks for what's called a bootloader, a small piece of software. The bootloader then tells the computer where to find the rest of the operating system (in Android parlance, a ROM) - this is where everything else is located. On most PCs, the bootloader is very small and limited, though that's changing somewhat; on cell phones, however, the bootloader is considerably more involved and is usually baked into the operating system directly. This is done to keep cell phones more or less secure - when a bootloader gets compromised, it can literally tell the computer which operating system to load and in what way so that whatever compromised the bootloader becomes virtually undetected. On a home computer, this is incredibly annoying; on a cell phone, it can lead to rather expensive phone bills that customers refuse to pay. Consequently, cell phone providers are rather insistent that phone bootloaders remain inviolate, save for the occasional well-heeled developer willing to spring for a developer edition phone. Even then, Android is the only platform to openly offer such an edition; Apple and Microsoft are considerably more protective of their platforms.

No comments:

Post a Comment