sabato 21 marzo 2015

Flashing and running Lollipop 5.0.2 on Samsung S4 stock

I am the owner of a Samsung Galaxy S4 LTE (international version) bought from an italian operator. The phone is still great but the stock ROM (e.g. the Android version originally shipped with the S4, cooked by Samsung) sports a heavy user interface (TouchWiz) and is full of other useless software, which uses the RAM, the CPU, exchange data with remote servers: it uses resources for tasks I'm not interested into and, moreover, prevents me to do significant improvements.
As I run just Linux on my PC since 2008, all that inefficiencies and barriers made me feel frustrated like I was when still ran Windows on my PC. I could not stand the situation anymore and began to look around for a solution that worked.

In this article I will explain how I overwrote the stock Android rom (who was stuck at 4.4.2) flashing a fresh Lollipop 5.0.2 Custom ROM instead, giving a boost to the performance of the S4.

I wont say what's better or worse in absolute terms: I will just introduce what I did, how I did it and why I took one choice and not another. Hoping that that experience can help you in some way.

DISCLAIMER: I will describe MY experience on MY phone: flashing a custom firmware is a risky process and there is NO WARRANTY that following my path you will not brick you device. So any action YOU WILL TAKE on your phone WILL BE YOUR OWN RESPONSIBILITY.

Which distro?

Well, "distro" is how we call linux flavours, but the question is the same: there are several communities and individuals that take the Android source code and produce some kind of Custom ROM. which Custom ROM to choose in order to have a stable Lollipop on my phone? I wanted to break the chains of the proprietary ROM but without compromising the availability and usability of the S4.

After some research I selected the Cyanogenmod ROM, which sports a very  active community of contributors, that release a new build (NIGHTLY in their terms) once a day. The Lollipop version is the CM12, being CM11 the 4.4.4, CM10 the 4.4.2 and so long.

I will not bother you about Cyanogenmod, in this space: you better check directly with them, they run forums and a wiki: I started from this page.

Which steps?

To flash my new CM12 Custom ROM, this is the sequence of actions (that I followed):
  1. download on a PC the Custom ROM and some tools;
  2. make from the S4 a full backup (on a micro sd) of the stock ROM; I also copied some key directories from the S4 to the PC, just in case.
  3. completely wipe the phone;
  4. load & flash on the S4 the custom ROM;
  5. In order to use the Google ecosystem (Play store, Gmail, Gmaps and whatever else) I also ought to add a GApps package (which doesn't come with the Custom ROM for a license infringment constraint);
  6. install again from the Play Store my favourite apps;
  7. recover the app data from the backup.
To achieve the result you will need a PC, directly connected to the S4 with a normal USB and running some sort of software.

As I said I just use Linux machines (Ubuntu), so my description will consider that the companion OS environment running on your PC, for this installation, will be Linux as well. With other OSes, namly Windows, everything gets more complicated and/or "hidden", so I don't recommend anything but Linux for serious tasks.

Action!

Here's how I implemented the steps 1-8 above. Please note that, except for the Cyanogenmod CM12 download page, everywhere else the S4 is code-named jflte.
  1. The CM12 can be downloaded from the Cyanogenmod site: the S4 int'l firmware has codename jfltexx, this is the page and I used the last NIGHTLY (20150320).
    The Custom recovery module is not part of the stock ROM. After reading articles like this I choose to use the recovery module provided by Clockworkmod (named recovery-clockwork-6.0.4.7-jflte.img), that I found at this site.
    To flash this Custom recovery module to the S4 I needed a piece of sw on the PC, called heimdall: in my case I just installed the DEB package (heimdall-flash).
    The last tool I needed was adb (Android Debug Bridge) and here is explained what it does and how to get it.
  2. The full backup can be made from the recovery mode, which first must be installed, so I prepared the S4 to receive the Custom recovery module: with the phone switched off and disconnected from the PC, I pressed volume-down + home + switch-on button and waited for a message to appear with a disclaimer, then pressed volume-up to overcome the disclaimer and went on. Connected the phone to the PC and issued from the PC:

    "$ sudo heimdall flash --RECOVERY recovery-clockwork-6.0.4.7-jflte.img --no-reboot"

    The phone got the recovery module in a few seconds and when the blue bar did stop to grow the process was complete. I switched off the phone and eventually entered the recovery mode pressing volume-up + switch-on. From there I did a complete backup (more than 1 hour).
  3. After completing the backup and keeping the S4 in recovery mode, I then wiped the phone (system, data, cache).
  4. Always in recovery mode, I then navigated the menu to install the Custom ROM from the ZIP that I downloaded previously on the PC. To achieve that, I navigated the menu up to "sideload" and that, on the PC, issued at the terminal prompt the command:

    $ adb install cm-12-20150320-NIGHTLY-jfltexx.zip

    When the upload of the file was complete the S4 immediately started installing the firmware.
    IMPORTANT: in my case the process ended with the following error:

    E:[-] failed to map aboot.
    E:Error loki-ifing the boot image


    This error was constant but didn't affected the installation at all, so I assume that can be ignored. So I just rebooted the S4 and Lollipop firmware was up and running!! 
  5. After checking various solutions, I found here the correct GApps zip file for my CM12 version. Downloaded the file and transferred it in the S4 memory.
    In order to install the GApps one must enter again the S4 in recovery mode but, once the phone run the Cyanogenmod Android, it is very simple: see here. So I reboot the phone in recovery mode and navigated the menu up to install the ZIP from sdcard (the internal memory), choosing the GApps zip file that I just saved. After the installation completed I rebooted and the Google Apps where there. I was able to record my Google account on the S4, enabling then the Play store, the recovery from the cloud of my email, contacts and the full Google ecosystem.
  6. As last step, I installed back my favourite Apps and the upgrade was complete!

Conclusions

Even if it can appear cumbersome, the process is not too much complicated and can be copeted in a few hours, including the initial backup.

After some days of use I see my CM12 very stable, even it's not yet declared such, more responsive then the stock Samsung ROM and with a 15% improvement in battery duration.

There is still pending on the CM12 an old issue on the Camera, who's behaviour is really very weird, especially in poor light conditions. If you are compulsive with selfie, stay far from the NIGHTLY release, at least up the next SNAPSHOT.