Samsung Firmware Flashing Native for Linux

A clean, correct, and robust implementation of the Thor USB protocol. odin4 provides a reliable alternative for Samsung device maintenance and development workflows on Linux environments.

Why odin4?

Engineered to be the definitive flashing tool for Linux.

๐Ÿง

Native Linux

No Wine, no emulators. Maximum performance and direct kernel compatibility.

๐Ÿ›ก๏ธ

Safety First

Strict partition and integrity validation to prevent device damage.

โšก

Efficiency

Native LZ4 compression support and optimized transfers via libusb.

๐Ÿ”

Transparency

Open-source and auditable code. Detailed logs for precise debugging.

Core Features

๐Ÿ“ก

Auto Detection

Instantly identifies devices in Download Mode via libusb.

๐Ÿ“œ

PIT Management

Automatic retrieval and analysis of the Partition Information Table (PIT).

๐Ÿ’Ž

MD5 Integrity

Cryptographic verification of .tar.md5 files using Crypto++ before flashing.

๐Ÿงช

Dry-run Mode

Validate PIT and archives without performing any writes using --check-only.

๐Ÿ“Š

Real-time Progress

Transfer statistics, speed metrics, and per-file progress reporting.

๐Ÿ”„

Multi-component

Full support for BL, AP, CP, CSC, and UMS firmware components.

โšก

LZ4 Streaming

Native LZ4 compression support for faster firmware transfers.

๐Ÿ“

Logging

Persistent odin4.log file for post-operation debugging and analysis.

๐Ÿ”—

Multi-device

Sequential flashing support for multiple connected devices.

Odin Protocol

Understand the engineering behind Samsung device communication.

What is the Odin Protocol?

The Odin protocol is the proprietary communication protocol used by Samsung devices in Download Mode. It operates over USB bulk transfers and handles session management, partition table delivery, and firmware writing.

Technical Note: odin4 implements this protocol natively, ensuring every packet follows the exact specifications expected by the device bootloader.

Initial Handshake

Before any data transfer, the host sends the ASCII string ODIN (4 bytes) over USB bulk transfer. The device bootloader responds with LOKE (4 bytes) to confirm readiness.

Handshake Flow: Host sends "ODIN" โ†’ Device responds with "LOKE"

PIT Table Extraction

The Partition Information Table (PIT) defines the device's storage layout. odin4 requests this table to validate firmware compatibility using the Odin command protocol (command type 0x65).

The PIT is retrieved in 500-byte blocks: first the device reports the total PIT size, then individual blocks are fetched, and finally the dump is terminated.

PIT Structure: 28-byte header (magic 0x12349876) followed by 132-byte partition entries. Each entry includes partition name, flash filename, binary type, device type, identifier, and block geometry.

Flash Sequence

Flashing uses the Odin command type 0x66 and proceeds in sequences, each divided into packets of the negotiated size (128 KiB or 1 MiB depending on protocol version).

Phase Command Name Description
Init 0x66/0x00 REQUEST_FILE_FLASH Start file transfer session
Begin 0x66/0x02 BEGIN_SEQUENCE Start a sequence with aligned size
Data Bulk write FILE_PART Raw data chunk at packet size
End 0x66/0x03 END_SEQUENCE Complete sequence with partition metadata
Init (LZ4) 0x66/0x05 REQUEST_COMPRESSED Start compressed file transfer
Begin (LZ4) 0x66/0x06 BEGIN_COMPRESSED_SEQUENCE Start a compressed sequence
End (LZ4) 0x66/0x07 END_COMPRESSED_SEQUENCE Complete compressed sequence

Device Information

The device type is queried using command 0x64 with subcommand 0x01. The device responds with a model code which the host formats as SM-<code>.

Note: The device type string is used for firmware compatibility verification โ€” odin4 checks that firmware filenames match the detected device model.

Control Operations

Device control uses command type 0x67 with the following subcommands:

Command Value Description
END_SESSION 0x00 Terminate session gracefully
REBOOT 0x01 Reboot device normally
REDOWNLOAD 0x02 Reboot into Download Mode

Getting Started

Follow the steps below to set up odin4 on your system.

01

Dependencies

Install the required libraries via terminal:

sudo apt-get update sudo apt-get install -y cmake ninja-build zip make pkg-config g++ libusb-1.0-0-dev libcrypto++-dev
02

Compilation

Clone and compile the project using CMake:

git clone https://github.com/Llucs/odin4.git cd odin4 cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build build --parallel $(nproc)
03

USB Permissions

Configure udev rules for non-root access:

sudo cp udev/60-odin4.rules /etc/udev/rules.d/ sudo udevadm control --reload-rules sudo udevadm trigger

Usage Documentation

odin4 --help
Usage: odin4 [options]
Samsung firmware flashing tool for Linux.

Options:
  -h                  Show this help message
  -v                  Show version
  -w                  Show license
  -l                  List detected Download Mode devices
  -d <path>            Select a specific USB device path
  -b <file>           Bootloader archive (.tar or .tar.md5)
  -a <file>           AP archive (.tar or .tar.md5)
  -c <file>           CP archive (.tar or .tar.md5)
  -s <file>           CSC archive (.tar or .tar.md5)
  -u <file>           UMS archive (.tar or .tar.md5)
  --check-only         Validate PIT + archives and exit without flashing
  --allow-unknown      Allow archive entries without a PIT match
  --reboot             Reboot device after flashing
  --redownload         Reboot into download mode if supported
  --efs-clear          Clear EFS partition during flash
  --bl-update          Signal bootloader update to device

Logging:
  --quiet              Only print errors
  --verbose            More detailed logs
  --debug              Debug logs (includes USB packet hexdumps)

USB selection overrides:
  --vid <hex>          Override USB vendor ID
  --pid <hex>          Override USB product ID
  --usb-interface <n>  Force a specific USB interface number
Example: Full Flash
./odin4 -b BL.tar.md5 -a AP.tar.md5 -c CP.tar.md5 -s CSC.tar.md5 -u UMS.tar.md5 --reboot
Example: Specific Device
./odin4 -d /dev/bus/usb/001/002 -a AP.tar.md5 --check-only
Example: Redownload Mode
./odin4 -a AP.tar.md5 --reboot --redownload