MediaTek GPUfreq kernel module analysis and patching tool
Project description
mtk-gpu-oc
Structural analysis and patching tool for MediaTek GPUfreq kernel modules. Overclock your MediaTek GPU by modifying the OPP frequency–voltage table and bypassing runtime calibration overwrites.
Supported platforms: MT6789 (initial). Designed for extensibility.
Installation
pip install mtk-gpu-oc
Or from source:
git clone https://github.com/ReCoreShift/mtk-gpu-oc.git
cd mtk-gpu-oc
pip install -e .
Quick start
# Inspect a kernel module
mtk-gpu-oc inspect mtk_gpufreq_mt6789.ko
# Generate an overclocked module (1200 MHz ceiling, auto voltage)
mtk-gpu-oc patch stock.ko --max-freq 1200 -o patched.ko
# Generate with explicit voltage
mtk-gpu-oc patch stock.ko --max-freq 1200 --volt 800 -o patched.ko
# Compare stock and modified modules
mtk-gpu-oc compare stock.ko patched.ko
# Verify a patched module
mtk-gpu-oc verify stock.ko patched.ko
# Dry-run (show plan without writing)
mtk-gpu-oc patch stock.ko --max-freq 1200 --dry-run
Commands
| Command | Description |
|---|---|
inspect |
Display ELF identity, OPP table, patch sites |
patch |
Apply overclock patches (bypass + OPP table) |
compare |
Semantic diff between two modules |
verify |
Validate patched module integrity |
How it works
Overclocking a MediaTek GPU requires five coordinated changes:
- OPP table modification — Scale frequencies in
g_default_gputable - AVS freq check bypass — NOP the efuse frequency mismatch abort
- Apply_adjust bypass (probe) — NOP the BL that overwrites OPPs during probe
- Apply_adjust bypass (AVS) — NOP the BL in the AVS adjustment path
- Segment ceiling removal — Zero
g_segment_adj[0]to remove the OPP cap
Plus relocation entry nullification to pass kernel module loader checks.
Voltage estimation
Default model: top-two-OPP slope extrapolation. The voltage slope between the two highest OPP entries is used to estimate the voltage at the target frequency. Fallback models handle degenerate tables:
| Model | When used |
|---|---|
| top-two | Two distinct top frequencies/volts |
| endpoint | Top-two have identical voltage |
| constant | Single entry or degenerate table |
| explicit | User provides --volt |
A mathematically estimated voltage is not a proven safe voltage. Always test patched modules on device and have a recovery path (e.g., backup the original module, have flashing tools ready).
Architecture
src/mtk_gpu_oc/
elf.py Generic ELF64 parsing (platform-independent)
opp.py OPP entry types, encoding, detection, invariants
gpufreq.py MediaTek GPUFreq structural analysis
profiles.py Platform-specific profiles (MT6789)
analysis.py Module analysis orchestration
compare.py Semantic stock-vs-modified comparison
patch.py Patch plan generation, validation, application
verify.py Independent patch verification
voltage.py Voltage estimation abstraction
config.py TOML config file loading
cli.py CLI argument parsing
Limitations
- Only MT6789 is currently supported
- Voltage curve is linear interpolation (not per-entry hand-tuned)
- No device-side stability validation
- Module signature verification not implemented
- Mali GPU driver interaction not analyzed
Development
# Run tests
python3 -m pytest tests/ -v
# Run integration tests with stock module
MTK_STOCK_MODULE=research/stock/mtk_gpufreq_mt6789.ko python3 -m pytest tests/ -v
Documentation
docs/mt6789-gpufreq-analysis.md— Reverse engineering notesdocs/patch-model.md— Voltage model and patch plan detailsdocs/legacy-script-analysis.md— Original script reconstruction
License
Mozilla Public License 2.0. See LICENSE.
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_gpu_oc-0.1.0.tar.gz.
File metadata
- Download URL: mtk_gpu_oc-0.1.0.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10b2f901b5172875b9e7827fa14a9d762578d5dafb319464d239687c285340e3
|
|
| MD5 |
80408f4379028714815cd3c7627f5dc6
|
|
| BLAKE2b-256 |
bd9f9fb84fa29e196f005897f6c5b6a410a11f12257e989245f3a2cf2bd7806b
|
Provenance
The following attestation bundles were made for mtk_gpu_oc-0.1.0.tar.gz:
Publisher:
release.yml on ReCoreShift/mtk-gpu-oc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mtk_gpu_oc-0.1.0.tar.gz -
Subject digest:
10b2f901b5172875b9e7827fa14a9d762578d5dafb319464d239687c285340e3 - Sigstore transparency entry: 2172974897
- Sigstore integration time:
-
Permalink:
ReCoreShift/mtk-gpu-oc@632a1d099a0fbef8938f90fc5eca9a23bec77d4d -
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@632a1d099a0fbef8938f90fc5eca9a23bec77d4d -
Trigger Event:
push
-
Statement type:
File details
Details for the file mtk_gpu_oc-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mtk_gpu_oc-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.3 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 |
8e11a0b661d120f7068b90431a50739d17272bc2b1aee209524716112fe185cc
|
|
| MD5 |
33808a6223f2cde1d6e374d44244f314
|
|
| BLAKE2b-256 |
e7a69b7ce44189e39b3d80110a28fe662c4a50a9bcf541377fcb4f7e7a626aeb
|
Provenance
The following attestation bundles were made for mtk_gpu_oc-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ReCoreShift/mtk-gpu-oc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mtk_gpu_oc-0.1.0-py3-none-any.whl -
Subject digest:
8e11a0b661d120f7068b90431a50739d17272bc2b1aee209524716112fe185cc - Sigstore transparency entry: 2172974904
- Sigstore integration time:
-
Permalink:
ReCoreShift/mtk-gpu-oc@632a1d099a0fbef8938f90fc5eca9a23bec77d4d -
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@632a1d099a0fbef8938f90fc5eca9a23bec77d4d -
Trigger Event:
push
-
Statement type: