Can't Restore Samsung Galaxy S3 To Factory Firmware I installed CyanogenMod on my Samsung Galaxy S3 (SGH i747), and now I need to re-install factory firmware to network unlock my phone. Heimdall seems to be able to successfully image the firmware package onto the device, but after imaging, it won't boot. I can still get to recovery mode and download mode, but nothing else. This is the command I'm using to image:

heimdall flash --SYSTEM I747UCDLK3_I747ATTDLK3_I747UCDLK3_HOME.tar.md5 


This is the output:

Heimdall v1.4.1

Copyright (c) 2010-2014 Benjamin Dobell, Glass Echidna
http://www.glassechidna.com.au/

This software is provided free of charge. Copying and redistribution is
encouraged.

If you appreciate this software and you would like to support future
development please consider donating:
http://www.glassechidna.com.au/donate/

Initialising connection...
Detecting device...
Claiming interface...
Setting up interface...

Initialising protocol...
Protocol initialisation successful.

Beginning session...

Some devices may take up to 2 minutes to respond.
Please be patient!

Session begun.

Downloading device's PIT file...
PIT file download successful.

Uploading SYSTEM
100%
SYSTEM upload successful

Ending session...
Rebooting device...
Releasing device interface...


I tried factory resetting before and after imaging the ROM via ClockworkMod, but it didn't help.

How do I fix this?



NOTE: I am using Linux.
.tar.md5 file is used by Odin (another firmware flashing tool), but AFAIK it cannot be used by Heimdall. Please make a backup of this file.

Remove md5sum

Run md5sum on any file to see what is it's output like. Something similar will be appended to original .tar file. Assuming you can open the .tar.md5 file in a text editor, remove the md5 sum from the end of file (and probably you'll have to remove last new line character). Then rename this file to I747UCDLK3_I747ATTDLK3_I747UCDLK3_HOME.tar.

Extract partitions

You should be able to run tar -xf I747UCDLK3_I747ATTDLK3_I747UCDLK3_HOME.tar. It should create a new directory with similar name and this directory will contain images of boot, cache, fat, hidden, recovery and system partitions (and maybe more):


boot.img
cache.img.ext4
hidden.img.ext4
system.img.ext4


Flashing

You should make sure that partitions on your device have the same names as I've written below (APPS, CACHE, HIDDEN, SYSTEM). You can do it be running heimdall download-pit --output &lt;filename&gt; and then heimdall print-pit --file &lt;filename&gt;. Finally, here's the actual flashing (you may want to add --no-reboot to the first command):

# heimdall flash --APPS boot.img --verbose
# heimdall flash --SYSTEM system.img.ext4 --CACHE cache.img.ext4 --HIDDEN hidden.img.ext4 --verbose


Re-flash recovery (added later)

In case your phone boots to recovery instead of system, you should flash your recovery (doesn't have to be stock) image again.