[AT&T Samsung Galaxy S 5] LucN31:
MASTER CAUTION: This will wipe ALL data on the device!! Backup your stuff before proceeding. I nor XDA is responsible for loss of your memes!

Flashing last LineageOS microG rom (18.1), I lost data on french laposte (SFR) network. Telephon calls remains, but data don't. I decided to flash last stock ROM using heimdall to avoid Windows VM on my computer.

To succeed you need some information about ROM structure and process.

Firmware version​

Some versions of stock ROM are just for upgrade and it doesn't contains all files nedeed. For example, I choose French XEF firmware for SM-G900F on sammobile.com

Last version 6.0.1 G900FXXS1CQD1 (2017-05-03) doesn't contain files as hidden.img.ext4, modem.bin... I nedeed.

I chose first 6.0.1 firmware witch contains all files : G900FXXU1CPE9 (2016-05-22)

Firmware content​

For SM-G900F, firmware ZIP file contains another archive file with .tar.md5 extension. This file is a normal tar file (I don't know why .md5 is added) which contains files to be flashed as PIT partitions

Structure is as below :

View attachment 5445141

Firmware extraction​

We need to extract 2 levels of archive to obtain files to be flashed.

unzip firmware archive (zip file) to obtain contained archive file (.tar.md5)

untar file to obtain files to be flashed.

Spoiler content hidden.

Convert sparses files​

Some files with ".img.ext4" extension are not a dump of ext4 partition. System can't mount these file at boot if we flash them as this.

These file are "Android sparse image, version: 1.0". We need to convert il in raw ext4 image file with de command simg2img.

Under Debian this command is obtained from the package "android-sdk-libsparse-utils"

Spoiler content hidden.

Use command "simg2img" to convert each file with ".img.ext4" extension.

Spoiler content hidden.

We are now ready to flash files into the device.

Flashing the files​

Obtain PIT files​

We need to know in which partition we must flash each file. print-pit operation in heimdall command allow to obtain all information.

To reduce output lines we use grep command as below :

heimdall print-pit --no-reboot | grep -A1 "Partition Name"

Spoiler content hidden.

With this result we can now construct heimdall flash command.

Flash command​

We need pass each file extracted from tar archive as parameter in flash command associated to its partition name.

CAUTION : Each sparse file (.ext4) must be replaced by associated converted file (.raw)

Here, my command, but you should verify that is correct in your case.

heimdall flash --SBL1 sbl1.mbn --DBI sdi.mbn --TZ tz.mbn --RPM rpm.mbn --ABOOT aboot.mbn --BOOT boot.img --RECOVERY recovery.img --APNHLOS NON-HLOS.bin --SYSTEM system.img.raw --HIDDEN hidden.img.raw --CACHE cache.img.raw --MODEM modem.bin --no-reboot

Note : --no-reboot option allows to verify and chain another command to re-flash a part (if errors or incomplete flash), but in my case device must be detected before each command. This is done unplugging and re-plugging USB device cable.

Reboot​

To reboot pass last command without --no-reboot option. For example :

heimdall print-pit

Firmware upgrade​

All upgrade needed to obtain last version can be applied using similar method or by OTA upgrade.