Mode-l ((better)) - Smartphone Flash Tool -runtime Trace

Unlocking the Depths of Firmware Logging: A Masterclass on Smartphone Flash Tool -runtime Trace Mode-l

In the competitive world of smartphone repair, custom ROM development, and embedded systems engineering, the Smartphone Flash Tool (SP Flash Tool) is a legendary utility. Primarily known for flashing MediaTek (MTK) based devices, this tool is the bridge between a bricked device and a functional operating system.

However, beneath the surface of the "Download" and "Format" buttons lies a diagnostic powerhouse often overlooked by beginners: Runtime Trace Mode, specifically dialed in with the -l (log level) parameter.

If you have ever faced a STATUS_BROM_CMD_SEND_DA_FAIL error, a boot loop after a custom kernel flash, or a mysterious S_BROM_CMD_STARTCMD_FAIL, you are not looking for a flashing tutorial—you are looking for runtime trace data. This article dives deep into how to leverage the -runtime Trace Mode-l to turn your flashing tool into a real-time debugger.

Advanced Flags: Combining -runtime Trace with Other Arguments

To become a true power user, combine the trace mode with other runtime arguments:

| Command | Effect | | :--- | :--- | | -runtime Trace Mode -l 5 -s COM5 | Traces only over physical COM port 5 (bypasses USB stack issues). | | -runtime Trace Mode -l 5 -b 921600 | Sets baud rate for trace to 921600 (faster logging for large RAM dumps). | | -runtime Trace Mode -l 5 -o C:\traces\debug.log | Outputs the runtime trace directly to a persistent log file. | Smartphone Flash Tool -runtime Trace Mode-l

Complementary Tools and Workflows

For maximum effectiveness, combine -runtime Trace Mode-l with:

Limitations and Risks

No tool is without its drawbacks. Be aware of these when working with -runtime Trace Mode-l:

  1. Only for Engineering Builds: Consumer versions of SP Flash Tool (like those from generic ROM sites) often have this functionality stripped out. You need the real engineering release from MediaTek’s partner portal or reputable developer archives.

  2. Slower Flashing: Enabling Mode-l tracing introduces overhead. The USB pipe must carry both image data and trace logs simultaneously, which can slow down the flashing process by 30-50%. Unlocking the Depths of Firmware Logging: A Masterclass

  3. Potential for Overflows: If the device’s buffer fills with trace messages, it may crash the pre-loader. Some devices require a special “trace DA” (Download Agent) to handle the load.

  4. Secure Boot Complications: On modern devices with locked bootloaders (MT6765, MT6833, MT6893), enabling runtime trace might trigger anti-debugging mechanisms that permanently blow efuses. Only use on devices where you accept this risk.

1. What is Runtime Trace Mode?

Runtime Trace Mode is a diagnostic feature within SP Flash Tool that captures real-time execution flow from a MediaTek device’s CPU cores and system-on-chip (SoC) components. Unlike logcat (Android’s userspace logging) or dmesg (kernel ring buffer), Runtime Trace Mode provides non-intrusive, cycle-accurate tracing of:

It operates by leveraging Embedded Trace Macrocell (ETM) or System Trace Macrocell (STM) blocks found in ARM Cortex-A cores, combined with MediaTek’s proprietary firmware hooks. The tool streams this data over USB while the device remains operational, albeit in a special engineering state. UART-to-USB adapters : For devices with exposed UART

Introduction

In the world of MediaTek-based device development, the Smartphone Flash Tool (SP Flash Tool) is ubiquitous. Most users know it as the utility for flashing stock ROMs, recovering bricked devices, or forcing preloaders. However, beneath its primary interface lies a suite of powerful diagnostic features often overlooked. Among these, Runtime Trace Mode stands out as a critical, yet underutilized, tool for real-time system analysis, kernel debugging, and application behavior monitoring.

This article explores the technical depths of Runtime Trace Mode, differentiating it from standard logging, explaining its architecture, and providing a practical guide to capturing and interpreting trace data.


5. Interpreting Trace Output

Raw trace data is overwhelming. Here’s how to navigate it:

Defining Runtime Trace Mode

Runtime Trace Mode is a specialized operational state within advanced flash tools (notably SP Flash Tool for MediaTek) that enables real-time logging of execution paths, register values, interrupt requests, and memory access patterns while the target device is running its low-level firmware or bootloader stages. Unlike a simple debug log, which records events after they happen, Trace Mode captures a chronological, instruction-level stream of activity as it occurs. This mode is activated by selecting specific trace options—e.g., “UART Trace,” “USB Trace,” or “Memory Dump”—before initiating a flashing or booting sequence. The output is a continuous data stream saved to a .bin or .log file, which can later be parsed with companion software (like a debugger or trace analyzer).

Step-by-Step Activation

  1. Launch SP Flash Tool as Administrator (Windows) or with sudo (Linux).
  2. Go to Options → Runtime Trace (or press Ctrl+T).
  3. In the dialog:
    • Select trace source: CPU0 ETM, System Trace, or Peripheral Bus.
    • Set buffer size: Default 4MB, increase for longer captures.
    • Enable timestamping: Required for latency analysis.
    • Choose export format: .trc (binary) or .csv (text).
  4. Connect your device via USB in Brom mode (hold volume keys while inserting cable, or short test point).
  5. Click Start Trace – the device will boot but stay in a traced state.
  6. Perform the action you want to debug (e.g., press power button, wait for crash).
  7. Click Stop Trace and Save.