SP Flash Tool is a command-line utility for flashing firmware images to supported MediaTek-based devices from a Windows x64 host. It handles scatter-file parsing, download-agent handoff, and partition-level write operations through a single scriptable interface. The tool targets technicians and developers working in offline or air-gapped environments; it does not perform device unlocking, bypass security controls, or modify firmware beyond what the provided image files specify. Scope is limited to the flashing workflow described here, and behavior against unsupported chipsets or malformed scatter files is not guaranteed.
- OS: Windows 10 / 11
- Shell: PowerShell 5.1+ or PowerShell 7+
- Network: internet access to download the script
- Privileges: standard user
Operates as a single-binary CLI with no runtime dependencies beyond the host OS; all functionality is exposed through subcommands and flags documented in the Usage and Flags sections.
- Accepts device configuration and flash-operation descriptors from local files; the tool reads and writes only paths you specify and performs no network calls during execution.
- Reports deterministic exit codes for every terminal condition, allowing reliable scripting and CI integration; the full mapping is defined in the Exit codes section.
- Emits structured, line-oriented output suitable for log capture and parsing, with verbosity controlled by explicit flags rather than environment inference.
- Supports batch execution of sequential operations defined in a single descriptor file, stopping or continuing on error according to a declared policy.
- Scope is limited to the operations enumerated in the Flags reference; device-specific protocols, vendor signing, and firmware validation are outside the current implementation and are not implied by any flag.
- Validates descriptor syntax before any device interaction and fails fast with a diagnostic identifying the offending line and field.
- Performs no privilege escalation and requires the caller to supply whatever access the target interface demands; permission failures are surfaced verbatim rather than retried silently.
- Cross-platform builds share the same argument grammar and exit-code contract, though hardware access paths differ by OS and are documented per platform in the Recipes section.
- All processing occurs locally against user-provided inputs; no telemetry, remote logging, or configuration upload is performed.
Invoke the tool from a terminal with the target device descriptor and, optionally, a flash plan file. At minimum, a single argument identifying the connected device or a plan is required; the tool enumerates attached hardware and refuses to proceed if more than one candidate matches without an explicit selector.
sp-flash-tool <device-id> [options]
By default the tool performs a read-only inventory of the device, prints the detected chipset and partition map, and exits without writing. Writing is opt-in and must be requested with the appropriate operation flag. Dry-run output is identical to a real run except that no data is committed.
Operational scope is limited to devices the tool can enumerate over the supported transport. It does not manage firmware for arbitrary hardware and will report an unsupported target rather than attempt a generic write. If a device is not recognized, the tool exits non-zero and produces no partial state.
Configuration precedence, from highest to lowest: command-line arguments, the plan file, the profile config in the working directory, and built-in defaults. Values resolved from a lower-priority source are overridden silently unless -verbose is set, in which case each resolution is logged to stderr.
Standard streams behave predictably: progress and human-readable status go to stderr, machine-readable output goes to stdout. This allows piping stdout to a file or another process without progress noise. Exit status follows the codes documented in the Exit codes section; callers should branch on the code rather than parsing messages.
For repeatable workflows, capture an explicit plan with -plan-out and re-run it later with -plan. Plans are plain text and can be reviewed and edited before execution. The tool never reads a plan from an implicit location and never executes one found next to the binary.
Advanced operation overrides are available under the -modifier namespace for device-specific tuning. These are documented individually under Flags and are intended for cases where defaults do not match a particular hardware revision. They are not required for standard use and can produce inconsistent results if applied without understanding the target's expected sequence; the tool will not prevent you from using them, but it logs a notice when one is set.
-p, -port <number> — Binds the local service to the specified TCP port. Defaults to 8080. Values outside 1–65535 are rejected at startup.
-
-d,-device <id>— Selects the target device by identifier. Only the first matching device is used; if none matches, the process exits with a non-zero status. -
-o,-output <path>— Writes results to the given file path instead of standard output. Parent directories must already exist; they are not created implicitly. -
-dry-run— Performs validation and resolves all inputs without transmitting data or modifying any device state. Useful for verifying configuration before a real run. -
-verbose— Emits extended diagnostic logging to standard error. Log volume is significantly higher and may impact timing on slow terminals. -
-timeout <seconds>— Sets the per-operation timeout. Defaults to30. A value of0disables the timeout entirely; this is not recommended for unattended runs. -
-no-color— Disables ANSI color sequences in output. Applied automatically when output is not attached to a TTY. -
-v,-version— Prints the version string and exits. No other flags are processed. -
-h,-help— Prints a usage summary and exits.
Flag parsing accepts -flag=value and -flag value forms. Short flags may be combined only when none of the combined flags takes an argument. Unknown flags cause an immediate error with exit status 2; they are not silently ignored. Options are processed in order, and a later occurrence of the same flag overrides an earlier one.
Exit status is a single unsigned integer in the range 0–255. Values are grouped by origin: 0 indicates success, 1–63 are reserved for tool-level conditions, 64–127 for platform and device interaction, and values above 127 are passed through unchanged from the underlying operating system or terminated child process.
0— Operation completed and all requested actions succeeded.1— General failure not covered by a more specific code; inspect stderr for the originating subsystem.2— Invalid command-line usage: unknown flag, malformed value, or mutually exclusive options supplied together.3— Configuration file missing, unreadable, or syntactically invalid.4— Requested operation not supported on the detected platform or transport.5— Permission denied while accessing a required resource (device node, configuration path, or working directory).64— No compatible device detected within the default timeout.65— Device detected but failed handshake or identification; verify cable, port, and driver state.66— Device entered an unexpected state during the operation and the sequence was aborted.67— Timeout while waiting for a device response; the operation may be retried.68— I/O error during read or write; partial transfer state is not preserved.69— Image or payload integrity check failed before flashing began.70— Operation interrupted by a signal; cleanup was attempted but not guaranteed.
Exit codes report only the terminal outcome of the invoked command. They do not encode per-stage detail, partial progress, or advisory warnings; those are written to stderr and are not reflected in the exit status. Scripts that need stage-level granularity should parse stderr output rather than infer it from the exit code.
When the tool wraps an external process, that process's exit code is propagated verbatim when it falls outside the reserved ranges, so downstream consumers should not assume any value above 127 maps to a documented condition.
Use -verify-only with -firmware <file> to validate an image against the tool's partition table before writing anything; the exit code reflects integrity, not device state.
For scripted batch work, pass -device-model and -dry-run together to preview which partitions would be touched. -dry-run performs full parsing and compatibility checks but issues no writes.
Erase and format operations require -confirm; omitting it aborts with a non-zero code and a message naming the missing flag. This is deliberate and cannot be disabled.
When generating reproducible builds, combine -log-format json log-level info and redirect stderr to a file. The JSON log records resolved flag values, detected device identifiers, and the exact partition map applied.
For repeated runs against identical hardware, -config <path> loads a saved flag profile. Profiles are strict: unknown keys cause a parse error rather than being ignored.
To exercise error paths without hardware attached, -simulate substitutes a deterministic stub backend. -simulate does not model timing or USB errors and is intended for flag and config validation only.
Use -list-devices to enumerate attached targets; it exits without modifying anything. If no device is detected, the exit code distinguishes "none found" from "enumeration failed."
-no-reboot suppresses the automatic restart after a write completes; pair it with -wait to hold the session until the device is manually detached.
SP Flash Tool is distributed under the MIT License. The full license text is provided in the LICENSE file at the root of the source tree and governs all use, modification, and redistribution of the project's source code.
The license permits use, copying, modification, merger, publication, distribution, sublicensing, and sale of copies of the software, subject to inclusion of the copyright notice and permission notice in all copies or substantial portions of the software. The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement.
Scope clarification: the MIT License applies only to the source code contained in this repository. It does not extend to third-party dependencies, which remain under their respective licenses, nor to any proprietary firmware images, vendor binaries, or device-specific payloads that users may supply when operating the tool. Users are responsible for ensuring they have the necessary rights to any firmware or device images they process with SP Flash Tool.
No warranty is made regarding fitness for device recovery, flashing, or repair workflows. Operation of the tool against physical hardware is undertaken at the user's own risk, and the maintainers accept no liability for device damage, data loss, or bricked hardware arising from use of the software.
Contributions submitted to the project are accepted under the same MIT License terms unless explicitly stated otherwise at the time of submission.

