Revert Samsung Device to stock OS
EditThis 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.
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-G960Ffor an S9), then pick the firmware for your region (CSC). The model number is shown in Download mode and underSettings>About phone.
On Windows with Odin
Downloads
The version we used for this test was 3.14.4
- 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
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

Disconnect the phone if attached by the device cable from the PC
Create a folder and unzip the downloaded Stock OS inside this folder
- You should see files in the folder similar to the screenshot below

Extract ODIN from the zip file.
Browse to the folder where you have extracted ODIN and run Odin.exe
Power off your phone.
Power on the phone into Download mode.
For example if it is the S9 then press
Bixby+Power+Volume down. TheBixbybutton is the one below the volume button on the s9On the blue screen you will be asked to
Confirmby clicking theVolume +buttonConnect the phone to the PC using the data cable
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.

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.
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
Click on
StartbuttonYour phone screen will look like this while the installation is running. Notice a thin white line marking the completion of the download and installation

ODIN will also mark the progress and completion with a
PASSshowing up as visible in the screenshot below
This marks the completion of the installation.
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

- 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.
Pre Requisites
- A Linux PC with
bash,tar,md5sum(coreutils),lz4andheimdallinstalled- On Debian or Ubuntu:
sudo apt install heimdall-flash lz4 - On Fedora:
sudo dnf install heimdall lz4 - See Install Heimdall for other systems
- On Debian or Ubuntu:
- 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:
- verifies the MD5 checksum appended to each
.tar.md5archive - extracts the images into an
extractedfolder, decompressing the.lz4ones - reads the partition table (PIT) shipped in the
CSCarchive - prints the
heimdall flashcommand that writes each extracted file to its partition, with the factoryUSERDATAimage last (it is left out with--keep-data) and without theHIDDENimage
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
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.md5andHOME_CSC_...tar.md5.Download the script above into the same folder, then make it executable:
chmod +x samsung-heimdall-prepare.shFrom the firmware folder, run the script:
./samsung-heimdall-prepare.shBy default the script uses the
CSCfile, which wipes all data on the phone. Add--keep-datato use theHOME_CSCfile instead, which keeps user data.Check that every archive is marked
OKand that the PIT was read.Power off your phone.
Power on the phone into Download mode.
For example if it is the S9 then press
Bixby+Power+Volume down. TheBixbybutton is the one below the volume button on the s9On the blue screen you will be asked to
Confirmby clicking theVolume +buttonConnect the phone to the PC using the data cable
Copy the
heimdall flash ...command printed at the end of the script and run it.If it fails with
Protocol initialisation failedor 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 withsudo.If Heimdall ends with
Failed to receive session end confirmationand the phone asks to use the Emergency recovery function, the phone refused the flash but is not damaged: holdVolume down+Poweruntil the screen goes off, immediately holdVolume down+Bixby+Powerto go back into Download mode, and run the printed command again as is. Do not add partitions to it, such asHIDDENorMISC: writing them is what triggers this error.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
USERDATAimage, which replaces the data on the phone, and from theCSCfile, which makes the recovery adapt it to the phone on first boot. With--keep-data, the script does not flashUSERDATA.USERDATAis flashed last. If Heimdall fails on it (for example withFailed 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 (holdVolume up+Bixby+Powerfrom a powered-off phone, then selectWipe data/factory reset).The script does not flash the
HIDDENimage. 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.Wait for a few minutes: the phone boots to the Stock OS setup wizard.
- You can remove the cable at this point as there is no further requirement for the PC. You can start setting up your smartphone.