Flashing a Samsung Galaxy S5 from Ubuntu

Unfortunately, it's a little more involved to flash a Samsung S5 using the Heimdall software suite on Ubuntu than it should, so I've compiled a list of necessary steps to get it all working together.

The general process should normally looks like the following, as per Cyanogenmod's flashing guide:

  • Install Heimdall
  • Flash a custom recovery partition to your phone
  • Copy the image you want to flash to your phone's SD card
  • Copy the google applications package to your phone's SD card
  • Flash both the new ROM and the google apps package to your device.
  • Reboot the phone

I found that the first step is actually a little more involved than it should because the Heimdall version packaged with Ubuntu is old, so I had to compile Heimdall from source and add some custom udev rules so that I could flash successfully.

Compiling Heimdall from sources (from git master)

First of all, let's get the latest sources on our machine:

sudo apt-get install git
git clone https://gitlab.com/BenjaminDobell/Heimdall.git
cd Heimdall

Of course, we'll need a few build dependencies before we can actually build:

sudo apt-get install build-essential cmake zlib1g-dev qt5-default libusb-1.0-0-dev libgl1-mesa-glx libgl1-mesa-dev

I'm not sure why the openGL dependencies are needed, but I followed the HOWTO to the letter and it worked.

The build step itself is a standard cmake workflow, no surprises:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make

That will create a set of heimdall binaries in the current directory's bin/ subfolder.

Let's check that everything worked OK with a quick test:

bin/heimdall version  # That should return whatever is the current version

Adding custom (temporary) udev rules

Before we can actually flash anything we need to tell udev not to use the USB modem driver with our phone. To do this, we simply add a custom udev rule in /etc/udev/rules.d:

sudo su -
cat > /etc/udev/rules.d/90-temp-samsung.rules <<EOF
ATTRS{idVendor}=="04e8", ENV{ID_MM_DEVICE_IGNORE}="1"
EOF

This bit is a bit cryptic, especially the vendor magic number. But take my word for it, "04e8" is actually whatever a Samsung Galaxy S5 advertises as vendorId.

You need to restart udev and re-plug your phone in for this to work:

sudo service udev restart

Actually flashing!

Hurray! We should now be able to flash the downloaded recovery file to our phone with:

bin/heimdall flash --RECOVERY /path/to/the/recovery.img --no-reboot

Put the custom image you intend to flash on the SD card. I didn't manage to workaround adb not being able to adb push to teamwin's recovery image, maybe my udev rule up there interferes with it somehow, I got stuck with adb complaining about a lack of permissions. No worries. I'll put the file on the actual SD card (like, plugging it in another computer, physically).

You can now reboot into recovery mode (volume up + home + power) and use the recovery UI to flash your new system and the google apps bundle you downloaded previously.

Remove the custom udev rule

It's now time for our custom udev rule to be removed (or commented out), since that will otherwise prevent the system from detecting the phone as a USB modem.

If you can live without the functionality feel free to leave the rule as-is, but I personally love to be able to just plug the phone in and let it serve as and extra line to the world.

That's all folks! As usual, if you have questions or comments feel free to tweet or email me.