Skip to main content

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:

  1. OPP table modification — Scale frequencies in g_default_gpu table
  2. AVS freq check bypass — NOP the efuse frequency mismatch abort
  3. Apply_adjust bypass (probe) — NOP the BL that overwrites OPPs during probe
  4. Apply_adjust bypass (AVS) — NOP the BL in the AVS adjustment path
  5. 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 notes
  • docs/patch-model.md — Voltage model and patch plan details
  • docs/legacy-script-analysis.md — Original script reconstruction

License

Mozilla Public License 2.0. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mtk_gpu_oc-0.1.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mtk_gpu_oc-0.1.0-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

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

Hashes for mtk_gpu_oc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 10b2f901b5172875b9e7827fa14a9d762578d5dafb319464d239687c285340e3
MD5 80408f4379028714815cd3c7627f5dc6
BLAKE2b-256 bd9f9fb84fa29e196f005897f6c5b6a410a11f12257e989245f3a2cf2bd7806b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mtk_gpu_oc-0.1.0.tar.gz:

Publisher: release.yml on ReCoreShift/mtk-gpu-oc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for mtk_gpu_oc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e11a0b661d120f7068b90431a50739d17272bc2b1aee209524716112fe185cc
MD5 33808a6223f2cde1d6e374d44244f314
BLAKE2b-256 e7a69b7ce44189e39b3d80110a28fe662c4a50a9bcf541377fcb4f7e7a626aeb

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page