Build, patch, and inspect MediaTek-style GPT partition tables from scatter XML files.
Project description
mtk-gpt-tool
Build, patch, inspect, and reverse-engineer MediaTek GPT partition images (PGPT.img / SGPT.img) from scatter XML files or plain partition-table text.
Install
git clone https://github.com/anomalyco/mtk-gpt-tool.git
cd mtk-gpt-tool
pip install -e .
Quick start
# Inspect a real device GPT
mtk-gpt inspect --pgpt PGPT.img --sector-size 4096
# Generate fresh GPT images from a scatter file
mtk-gpt generate --scatter MT6789_Android_scatter.xml --storage ufs \
--disk-size 512GB -o ./out
# Patch existing GPT with new partition boundaries
mtk-gpt patch --scatter MT6789_Android_scatter.xml --storage ufs \
--pgpt PGPT.img --sgpt SGPT.img --disk-size 512GB -o ./out
# Reconstruct scatter XML from a real device GPT
mtk-gpt to-scatter --scatter template.xml --storage ufs \
--pgpt PGPT.img --sector-size 4096 -o ./reconstructed
Subcommands
| Command | Description |
|---|---|
generate |
Build fresh PGPT.img/SGPT.img from scatter XML or partition table |
patch |
Rewrite partition entries in an existing GPT, preserving unique GUIDs |
inspect |
Print the layout found in an existing PGPT.img |
to-scatter |
Reconstruct a scatter XML from a real GPT, using another scatter as a field template |
example |
Run a full end-to-end demo against real firmware in bin/ |
Partition table file (--partitions)
Define partitions in a text file instead of a scatter XML. Two formats are supported and auto-detected.
3-column format
# name first_lba last_lba
boot 174592 190975
system 2717696 124956663
vendor 358400 2717695
Values can be decimal or hex (0x...).
sgdisk format
Paste sgdisk --print output directly — header and footer lines are auto-skipped:
Number Start (sector) End (sector) Size Code Name
1 174592 190975 64.0 MiB 0700 boot_a
2 313856 330239 64.0 MiB 0700 boot_b
3 358400 2717695 9216.0 MiB 0700 super
4 2717696 124956663 477.5 GiB 0700 userdata
Lines starting with # or blank lines are also ignored.
Full workflow
# 1. Dump your device partition table
sgdisk --print /dev/block/sda > partitions.txt
# 2. Generate fresh GPT images
mtk-gpt generate --partitions partitions.txt \
--disk-size 512GB --sector-size 4096 -o ./my_gpt
# 3. Flash
fastboot flash PGPT ./my_gpt/PGPT.img
fastboot flash SGPT ./my_gpt/SGPT.img
Built-in example
If you place firmware files in bin/ (or point MTK_FW_DIR at the directory
containing PGPT.img, SGPT.img, and MT6789_Android_scatter.xml):
# Run the full demo
mtk-gpt example
# Or specify a custom firmware directory
MTK_FW_DIR=/path/to/firmware mtk-gpt example
The example walks through all 7 steps: inspect → generate → verify → partition-table input → exclude → to-scatter round-trip → patch → config file.
Excluding partitions (--exclude)
Place selected partition entries beyond disk capacity so the OS ignores them. Partition names and GUIDs stay in the table (passes preloader checks) but reads to those LBAs fail.
# Disable GenieZone partitions
mtk-gpt generate --scatter scatter.xml --storage ufs \
--disk-size 512GB --exclude gz_a,gz_b -o ./out
# Disable via partition table file
mtk-gpt generate --partitions my_parts.txt \
--disk-size 512GB --sector-size 4096 \
--exclude gz_a,gz_b,gz1,gz2 -o ./out
# Also works with patch
mtk-gpt patch --scatter scatter.xml --storage ufs \
--pgpt PGPT.img --sgpt SGPT.img --disk-size 512GB \
--exclude gz_a -o ./out
TOML config file
Save CLI flags to a .toml file and pass --config:
# mtk-gpt-tool.toml
scatter = "./MT6789_Android_scatter.xml"
storage = "ufs"
sector_size = 4096
disk_size = 511839305728
mtk-gpt generate --config mtk-gpt-tool.toml -o ./out
The tool also auto-discovers ./mtk-gpt-tool.toml and ./.mtk-gpt-tool.toml
without --config.
Options reference
| Flag | Applies to | Description |
|---|---|---|
--scatter <path> |
generate, patch, to-scatter | MTK scatter XML input |
--partitions <path> |
generate, patch | Plain-text partition table (3-col or sgdisk) |
--storage {ufs,emmc} |
all | Storage type (default: ufs → 4096 sector) |
--disk-size <size> |
generate, patch | e.g. 512GB, 476GiB, or raw bytes |
--sector-size <n> |
all | Override sector size (default: 4096 ufs, 512 emmc) |
--num-entries <n> |
generate, patch | GPT entry slot count (default: exact count) |
--first-usable-lba <n> |
generate, patch | Override firstUsableLBA in the GPT header |
--exclude <names> |
generate, patch | Comma-separated partitions to disable |
--pgpt <path> |
inspect, patch, to-scatter | Path to PGPT.img |
--sgpt <path> |
patch | Path to SGPT.img |
-o / --out-dir / --out <dir> |
all | Output directory (default: ./out) |
--out-filename <name> |
to-scatter | Override output scatter filename |
--config <path> |
all | TOML config file with defaults |
Common tasks
| Task | Command |
|---|---|
| Inspect existing GPT | mtk-gpt inspect --pgpt PGPT.img --sector-size 4096 |
| Generate from scatter | mtk-gpt generate --scatter s.xml --storage ufs --disk-size 512GB -o ./out |
| Generate from partition table | mtk-gpt generate --partitions parts.txt --disk-size 512GB --sector-size 4096 -o ./out |
| Patch | mtk-gpt patch --scatter s.xml --pgpt PGPT.img --sgpt SGPT.img --disk-size 512GB -o ./out |
| Disable partitions | Add --exclude gz_a,gz_b to generate or patch |
| Rebuild scatter | mtk-gpt to-scatter --scatter template.xml --pgpt PGPT.img --sector-size 4096 -o ./out |
| With config | mtk-gpt generate --config my.toml -o ./out |
| Full demo | mtk-gpt example (requires firmware in bin/) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mtk_gpt_tool-0.1.0.tar.gz.
File metadata
- Download URL: mtk_gpt_tool-0.1.0.tar.gz
- Upload date:
- Size: 51.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11651db0a3c76a625e03926e062a0ba7c85e3fc2e7e34dc8453a27e764dfc2ae
|
|
| MD5 |
6682e5b998f957d92ce994f7d572e3c9
|
|
| BLAKE2b-256 |
60f21d78c0cfc539f3f6263d526dbac3914a86ec6963d96916243431ac22798e
|
Provenance
The following attestation bundles were made for mtk_gpt_tool-0.1.0.tar.gz:
Publisher:
release.yml on ReCoreShift/mtk-gpt-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mtk_gpt_tool-0.1.0.tar.gz -
Subject digest:
11651db0a3c76a625e03926e062a0ba7c85e3fc2e7e34dc8453a27e764dfc2ae - Sigstore transparency entry: 2168515820
- Sigstore integration time:
-
Permalink:
ReCoreShift/mtk-gpt-tool@ae6107c7a16b571066283af2d426b8a3e83bb750 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ReCoreShift
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ae6107c7a16b571066283af2d426b8a3e83bb750 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mtk_gpt_tool-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mtk_gpt_tool-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a99cdaa6db41c29dd4fd8fd8ff7a9273f4b3af6477daf64b2be69eb7669dbc86
|
|
| MD5 |
48b373e0138c82f017d70d4675073676
|
|
| BLAKE2b-256 |
742c5cc5350f53849409e1aa54180a04364f71ed29aa1fc6326f892ba39bb7b2
|
Provenance
The following attestation bundles were made for mtk_gpt_tool-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ReCoreShift/mtk-gpt-tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mtk_gpt_tool-0.1.0-py3-none-any.whl -
Subject digest:
a99cdaa6db41c29dd4fd8fd8ff7a9273f4b3af6477daf64b2be69eb7669dbc86 - Sigstore transparency entry: 2168515925
- Sigstore integration time:
-
Permalink:
ReCoreShift/mtk-gpt-tool@ae6107c7a16b571066283af2d426b8a3e83bb750 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ReCoreShift
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ae6107c7a16b571066283af2d426b8a3e83bb750 -
Trigger Event:
push
-
Statement type: