r/qemu_kvm • • 2h ago

How can I solve this?

Post image
4 Upvotes

r/qemu_kvm • • 18h ago

I got the original TC Electronic Clarity M firmware running in QEMU on an Apple Silicon Mac

Post image
0 Upvotes

I've been working on a personal reverse-engineering project: getting the original firmware of the TC Electronic Clarity M running inside QEMU on my MacBook Pro M1 Pro.

Not a recreation of its interface, not a software clone. The actual embedded Linux system and the original "tcmeter" application running in an emulated hardware environment.

And after quite a bit of debugging, it's finally working!

The hardware and the challenge

The Clarity M is based on a Freescale i.MX35 SoC, with an ARM1136 CPU, Linux 2.6.31.12-rt21 and an IPUv1 graphics controller driving an 800×480 LCD.

QEMU already had an i.MX31-based KZM machine, which gave me a starting point. However, the i.MX35 is not simply an i.MX31 with a different name. Its memory map, peripherals, interrupts and clock configuration required substantial changes.

I started by extracting the firmware and examining the SD card, kernel, initramfs and application. Then came the first boot attempts.

Linux was running, the application was initializing, but the display was completely black.

Reconstructing the hardware

One of the biggest challenges was getting the original LCD working.

I initially tried reading a fixed framebuffer address, but that wasn't enough. I eventually had to understand how the IPUv1 actually works, decode its CPMEM configuration and reproduce its double-buffering behavior.

The first buffer I was displaying was actually empty. The firmware was drawing into the other one!

I also had to reconstruct significant parts of the i.MX35 hardware model, using the surviving QEMU binary, disassembly, memory maps and register behavior as references.

The work eventually extended beyond graphics: GPIO, the GPT timer, SDMA, ESAI and I2C-based AES receiver emulation all became part of the project.

Making the audio work

The next challenge was getting real audio into the original firmware.

The Clarity M uses an ESAI audio interface fed by SDMA. I implemented a functional DMA model and emulated the AES receiver status so the firmware could recognize a valid input signal.

On macOS, I'm using Loopback to route audio into QEMU.

The current setup captures audio at 44100/48 kHz and feeds it to the firmware. The original application then performs the actual measurements.

I tested it with a known signal: LUFS, true peak and RTA results were consistent with the expected values.

The unexpected part: time itself was broken

Getting the display and audio working wasn't the end of it.

The application would freeze after a while, sometimes after 30 seconds, sometimes after several minutes.

The problem turned out to involve several interacting issues: GPT timer frequency, missed compare interrupts, SDMA channel shutdown and kernel deadlocks.

I ended up inspecting the guest's RAM, reconstructing its kernel symbol table (kallsyms) and examining sleeping kernel stacks to understand what was blocked.

On the macOS side, I also had to deal with App Nap and thread scheduling to keep audio capture stable when the application was running in the background.

Where it stands now

The current version can:

  • Boot the original Clarity M firmware.
  • Display its native 800×480 interface. (add some changes for having a perfect circle for the radar (800X447)).
  • Navigate Radar, RTA and VSCOPE views.
  • Control SW1–SW6 using the Mac keyboard. (1 to 6)
  • Operate the rotary encoder using the arrow keys.
  • Receive and analyze real audio at 41000 and 48 kHz.
  • Run for 15 minutes under RTA load, with no freeze or AES lock loss during the test.

I've also packaged everything into a native macOS application: Clarity M.app.

This started with an SD card image, a Linux kernel and a black QEMU window. It turned into a much deeper dive into ARM emulation, SoC reconstruction, graphics, DMA, audio and real-time scheduling.

Still plenty to improve, but seeing the original Clarity M software running and measuring an actual audio signal on a Mac is incredibly satisfying.

I'd be happy to discuss the QEMU hardware emulation, IPUv1 implementation or the audio pipeline with anyone interested!