Tip: The installation will wipe all data on your phone. Take necessary backups of your data if required.

This guide covers two ways to flash the stock OS: with Odin on Windows and with Heimdall on Linux. Both flash the same Samsung firmware package.

Assumptions

  • The user has a working samsung device with /e/OS on it.
  • The user wishes to revert their Samsung device to Stock OS

Stock OS here refers to the OS that is provided by the vendor.

Tip: The installation with Odin was tested on the S9 and S9+, the one with Heimdall on the S8. It should work on all Samsung devices.

Samsung stock OS

Whatever your operating system, download the Samsung stock OS first.

We downloaded the stock OS from the Samfw site

Search for your exact model number (for example SM-G960F for an S9), then pick the firmware for your region (CSC). The model number is shown in Download mode and under Settings > About phone.

Warning: Ensure you download the latest stock OS build specific to your country or location.

On Windows with Odin

Downloads

  1. ODIN

The version we used for this test was 3.14.4

  1. Samsung USB drivers, available from the same Samfw page

Pre Requisites

  • Windows 11 PC

We tested this on a Windows 11 PC.

  • Odin installed and working on the PC

We tested with ODIN version 3.14

  • Internet connection on the PC

Required to download any device specific drivers to make it run on the PC

  • Working data cable

There are cables which are used only for charging. Ensure the cable you use allows data and file transfer

IMPORTANT

  • Keep the phone fully charged before starting the installation process
  • Disable Samsung Kies if installed on your Windows PC
  • Disable any anti virus programs running on the Windows PC. This includes the default

Steps

    • Searching your model number on the Samfw site to download the Samsung stock OS will show a long list of downloads.
    • Choose the download specific to your country
  1. This is how your Samsung smartphone would appear at this moment.

    • You have not yet started the installation
    • In this screenshot we have a /e/OS oreo build already installed on a s9
    • Remove any passwords or PIN you may have set to unlock your device.

      You can always set these up later after the installation

  2. Disconnect the phone if attached by the device cable from the PC

  3. Create a folder and unzip the downloaded Stock OS inside this folder

    • You should see files in the folder similar to the screenshot below

  4. Extract ODIN from the zip file.

  5. Browse to the folder where you have extracted ODIN and run Odin.exe

  6. Power off your phone.

  7. Power on the phone into Download mode.

    For example if it is the S9 then press Bixby + Power + Volume down. The Bixby button is the one below the volume button on the s9

  8. On the blue screen you will be asked to Confirm by clicking the Volume + button

  9. Connect the phone to the PC using the data cable

  10. ODIN should detect your device and assign a COM Port to it. In the screen shot below you can see COM5 assigned to the attached s9

    The port number may change from PC to PC and on individual USB ports.

  11. In the ODIN UI you would see buttons with the text BL, AP, CP, CSC, USERDATA

    • Select the AP tab from the Odin and import AP file
    • Select the BL tab and import BL file.
    • Select CP tab and import CP file there.
    • Click on the CSC tab and import the Home_CSC file that is already in the firmware folder.
  12. In Odin, tick on Auto Reboot and F.Reset.Time options for your Odin options

    Now that you have set up ODIN to install you need to start the installation

  13. Click on Start button

    Your phone screen will look like this while the installation is running. Notice a thin white line marking the completion of the download and installation

  14. ODIN will also mark the progress and completion with a PASS showing up as visible in the screenshot below

  15. This marks the completion of the installation.

  16. Wait for a few minutes as your phone will now reboot and you should be at this screen which marks the start of the Stock OS Set wizard on the Samsung smartphone

Tip: On some devices if you are stuck at the boot screen, you can try to do a factory reset from within the recovery to get the phone to boot.
  1. You can remove the cable at this point as there is no further requirement for the PC or ODIN. You can start setting up your smartphone.

On Linux with Heimdall

Odin only runs on Windows. On Linux, the open source Heimdall flashes the same firmware. A Samsung firmware package is made of .tar.md5 archives (AP, BL, CP, CSC) that Heimdall cannot read directly: the script below prepares them and prints the Heimdall command to run.

Warning: The script below does not flash anything by itself: always read the command it prints before running it.

Pre Requisites

  • A Linux PC with bash, tar, md5sum (coreutils), lz4 and heimdall installed
    • On Debian or Ubuntu: sudo apt install heimdall-flash lz4
    • On Fedora: sudo dnf install heimdall lz4
    • See Install Heimdall for other systems
  • The Samsung stock OS, downloaded as explained above
  • Working data cable

There are cables which are used only for charging. Ensure the cable you use allows data and file transfer

IMPORTANT

  • Keep the phone fully charged before starting the installation process
  • Remove any passwords or PIN you may have set to unlock your device

The preparation script

Download samsung-heimdall-prepare.sh and save it in the folder where you will unzip the stock OS. It:

  1. verifies the MD5 checksum appended to each .tar.md5 archive
  2. extracts the images into an extracted folder, decompressing the .lz4 ones
  3. reads the partition table (PIT) shipped in the CSC archive
  4. prints the heimdall flash command that writes each extracted file to its partition, with the factory USERDATA image last (it is left out with --keep-data) and without the HIDDEN image

The script does not talk to the phone: the printed command is the only one that does, in a single session, and the phone reboots on its own when it ends.

You can also download it from a terminal, from inside the firmware folder:

curl -O https://doc.e.foundation/scripts/devices/guides/revert-samsung-stock-windows/samsung-heimdall-prepare.sh

Like any script downloaded from the internet, open it in a text editor and read it before running it.

Steps

  1. Create a folder and unzip the downloaded stock OS inside it. You should see files named AP_...tar.md5, BL_...tar.md5, CP_...tar.md5, CSC_...tar.md5 and HOME_CSC_...tar.md5.

  2. Download the script above into the same folder, then make it executable:

    chmod +x samsung-heimdall-prepare.sh
    
  3. From the firmware folder, run the script:

    ./samsung-heimdall-prepare.sh
    

    By default the script uses the CSC file, which wipes all data on the phone. Add --keep-data to use the HOME_CSC file instead, which keeps user data.

  4. Check that every archive is marked OK and that the PIT was read.

  5. Power off your phone.

  6. Power on the phone into Download mode.

    For example if it is the S9 then press Bixby + Power + Volume down. The Bixby button is the one below the volume button on the s9

  7. On the blue screen you will be asked to Confirm by clicking the Volume + button

  8. Connect the phone to the PC using the data cable

  9. Copy the heimdall flash ... command printed at the end of the script and run it.

    If it fails with Protocol initialisation failed or similar, power-cycle the phone into Download mode and run the same command again.

    If Heimdall reports libusb error: -3, your user is not allowed to access the phone: run the command with sudo.

    If Heimdall ends with Failed to receive session end confirmation and the phone asks to use the Emergency recovery function, the phone refused the flash but is not damaged: hold Volume down + Power until the screen goes off, immediately hold Volume down + Bixby + Power to go back into Download mode, and run the printed command again as is. Do not add partitions to it, such as HIDDEN or MISC: writing them is what triggers this error.

  10. Once Heimdall reports that the upload is complete, the phone reboots on its own. On this first boot the recovery finishes the factory reset (the screen shows the installation progress): do not interrupt it.

    The reset comes from the factory USERDATA image, which replaces the data on the phone, and from the CSC file, which makes the recovery adapt it to the phone on first boot. With --keep-data, the script does not flash USERDATA.

    USERDATA is flashed last. If Heimdall fails on it (for example with Failed to confirm end of file transfer sequence), everything else is already written: put the phone back into Download mode, run the command again, and if it fails again do a factory reset from the stock recovery (hold Volume up + Bixby + Power from a powered-off phone, then select Wipe data/factory reset).

    The script does not flash the HIDDEN image. That partition only holds optional preloaded content (such as a sample song), and on some phones it is smaller than the firmware’s image: writing it makes the phone ask to use the Emergency recovery function.

  11. Wait for a few minutes: the phone boots to the Stock OS setup wizard.

Tip: On some devices if you are stuck at the boot screen, you can try to do a factory reset from within the recovery to get the phone to boot.
  1. You can remove the cable at this point as there is no further requirement for the PC. You can start setting up your smartphone.