What happened

This incident began with an inability to reliably output debug messages via a serial console in a Linux kernel build. Initially, debugging efforts were unproductive, leading to a brute-force approach using println statements to pinpoint the source of the problem.

This process quickly identified that the issue was centered around the MMU initialization stage. By strategically inserting debug print statements early in the boot sequence, we managed to isolate the point of failure at the memory mapping section and bisected the kernel code, eventually landing on the core MMU initialization code within arch/arm64/kernel/head.S. The key finding was a specific write operation targeting the CPU register SYS_IMP_APL_VM_TMR_FIQ_ENA_EL2, which is related to virtualization, and it triggered a crash after the MMU had been enabled.

Why it matters

This seemingly obscure configuration error prevented basic kernel functionality, hindering debugging efforts and highlighting a critical misunderstanding of memory management within the ARM64 architecture.

The consequence was an incomplete boot process, making further analysis extremely difficult without a fundamental fix addressing how the kernel handles MMIO space after enabling virtualization features. The core problem lay in the mismatch between how m1n1 exposes the MMIO address space and Linux’s approach to virtual memory management – a fundamental architectural difference that resulted in unmapped access attempts once the MMU was engaged. This error had significant implications for accessing peripheral devices, specifically the UART, which relies on memory-mapped I/O.

But, but, but…

Commenting out this register write successfully unlocked the kernel and allowed the debug print statements to execute further into the boot process.

Subsequent bisecting revealed that the issue was related to the initial pagetables not having a one-to-one mapping for the MMIO space. The fix – adding this mapping – enabled functional debugging until we reached the interrupt controller initialization stage. Notably, in newer iBoot versions, this SYS_IMP_APL_VM_TMR_FIQ_ENA_EL2 write is no longer necessary, suggesting a broader change in virtualization implementations.

“‘i bisected the linux boot code and landed at the mmu init code (which is still very early, still in the assembly code in arch/arm64/kernel/head.S)’.”
— Dr Non

The counter-take

It is generally considered unacceptable that core operating system development would hinge on undocumented or implementation-specific registers like this one; such reliance introduces significant fragility and hinders cross-platform compatibility. The root cause reveals a deeper issue concerning kernel design and how developers handle the nuances of memory management in complex architectures.

The AI angle

The identification and correction of this configuration error represents an upgrade in debugging tooling within embedded systems, leveraging a methodical approach to uncover subtle hardware interactions. This asymmetry—a small fix enabling widespread debugging capabilities—highlights the potential for AI-driven automation in similar scenarios in the future.