Skip to content
Nonbiri

Blog · Kernel Bring-Up · Part 1

One Bit Per Reboot: Climbing Linux 5.10 to 6.18 on a Phone With No UART

A four-rung climb across Linux 5.10, 6.1, 6.12, and Linux 6.18.32 GKI on a retail MediaTek MT6789 phone with no vendor kernel source, no UART header, and no working pstore.

·11 min read·Ilia Snezhkov
  • Linux 6.18
  • Android GKI
  • MT6789
  • Kleaf
  • Debugging

When you port a newer Linux kernel to a retail Android phone with no published vendor source, the worst failure mode is not a kernel panic. A panic leaves a trace. The worst failure mode is a black screen for twenty seconds, followed by a silent reboot back to the bootloader.

Moving my iKKO MindOne (MediaTek MT6789 / Helio G99, 8 GB RAM, 256 GB UFS) off its stock android12-5.10 vendor kernel onto Google’s prebuilt Linux 6.18.32 GKI was not a single leap. It was a four-rung climb across four kernel generations: 5.10.260 → 6.1.175 → 6.12.92 → 6.18.32 GKI.

Each rung failed for completely different reasons. The hardest part was not 6.18. The hardest part was breaking through total radio silence on 6.1 with no UART, no working pstore, and no hardware debugger.

Rung 1: The easy warm-up (5.10.233 → 5.10.260)

The phone shipped with Android 15 userspace running on a 2021 android12-5.10 kernel (5.10.233-android12-9) and roughly 350 vendor .ko modules, with zero published kernel source from the manufacturer (upstream Linux 5.10 LTS itself reached end of life on December 1, 2026 with 5.10.276).

Before touching a newer kernel branch, I built a safety net on 5.10 itself. Because stock already followed Android GKI 2.0, compiling Google’s ACK android12-5.10.260 (+27 LTS and security releases over stock) preserved the kernel module interface (KMI) symbol CRCs. Every factory .ko driver loaded against our freshly built kernel unchanged.

Within a day (August 19, 2026), that gave me “Kernel 0”: a known-good, rooted daily fallback sitting safely on slot _b while I experimented on slot _a. Over the next two days I brought 318 of 319 vendor modules up from source on 5.10 (including reverse-engineering the 85-function eta6965 charger driver and porting pn553 NFC).

Even this easy rung surfaced two traps that later mattered on 6.x:

  1. 01The modules.dep trap

    Removing a colliding module (pinctrl-mtk-v2.ko) from modules.load did nothing, because libmodprobe still pulled it in transitively through modules.dep.

  2. 02One missing symbol kills the whole list

    Once we dropped pinctrl-mtk-common-v2_debug.ko, mtk-mmc-dbg.ko (a dependency of mtk-mmc.ko) failed to resolve a single symbol, gpio_dump_regs_range (CRC 0x5d37f189). First-stage init runs libmodprobe in strict mode, so one unresolved debug symbol aborted storage bring-up entirely. Adding a two-line stub matching CRC 0x5d37f189 in pinctrl-mtk-common-v2.c booted the system cleanly (107 services, 0 failed).

That was the easy part. Then I tried to leave Linux 5.10 behind.

Rung 2: The blind-boot wall on Linux 6.1.175

Compiling ACK android14-6.1 (6.1.175) went fast enough. The freshly linked 29.7 MB Image and mt6789.dtb booted cleanly under qemu-system-aarch64 -M virt, reaching the expected rootfs mount panic with Not tainted.

On the real phone, 17 consecutive flashes produced complete silence: twenty seconds of black screen, then a silent reboot back to slot _b.

There was no exposed UART header on the board, and MediaTek’s Little Kernel (LK) rejected RAM-booting outright (fastboot boot answered remote: unknown command). Before assuming the vendor bootloader blocked newer kernels, I disassembled the 6 MiB tee binary and traced MTK_SIP_KERNEL_BOOT (SMC SIP 0x115). It ran exactly one check on the kernel entry point:

BL31 · SMC SIP 0x115

cmp x8, #0

No DRAM range check, no magic header check, no FDT check. BL31 was handing control straight to Linux 6.1, and our kernel was dying silently inside.

Next, all five standard postmortem channels failed in a row:

  1. 01/sys/fs/pstore/console-ramoops-0 was frozen in time

    Every boot returned the exact same stock shutdown log (timestamp 733.860 s). Controlled panics wrote zero bytes to it.

  2. 02expdb (the 128 MiB crash partition) never updated

    Byte-for-byte identical across controlled crashes. LK logs later explained why: kedump: skip due to expdb has data, because userspace AEE never cleared the single crash slot.

  3. 03Three DRAM carve-outs lied by omission

    0x50700000, 0x50C00000, and 0x48160000 preserved a magic marker across an orderly reboot, then got wiped cleanly to 0xFF on every panic or watchdog reset. Worse, LK loaded its 740 KiB AEE image directly over 0x50700000, erasing anything we parked there.

  4. 04Pre-MMU memory reads killed boot silently

    A 12-instruction assembly breadcrumb in head.S before the MMU turned on proved that a posted str (write) booted cleanly, while adding a single ldr (read) from a Device-nGnRnE carve-out froze the CPU on a synchronous external abort.

  5. 05My first in-RAM ring log faulted on the first string

    Mapping the ring buffer with pgprot_noncached gave it MT_DEVICE_nGnRnE attributes, so the very first unaligned printk access threw an Alignment Fault (reproduced in qemu-system-aarch64 and fixed with pgprot_writecombine).

With zero bytes of console output coming back from a failed 6.1 boot, I needed a channel that could survive any crash or hang and carry at least one bit of information.

Turning /proc/pl_lk into a 1-bit binary oracle (~65 seconds per bit)

MediaTek’s Preloader and LK already record why the previous boot ended and pass that text log up to Linux in /proc/pl_lk. Across five controlled tests on our working 5.10 slot, two wdt_status values never overlapped:

That single bit was enough to binary-search the entire 6.1 kernel boot without recompiling the kernel between probes.

Previous boot outcomewdt_status in /proc/pl_lk
Clean software restart (PSCI machine_restart(NULL))0x2
Hardware watchdog reset (hang or silent lockup)0x800

Bootargs checkpoints

I added four boot-command-line checkpoints to init/main.c, kernel/module/main.c, and fs/exec.c:

  • mindone_rst_level=N (-2 before any initcall, 0..7 for pure through late)
  • mindone_rst_index=K (the K-th initcall inside a level)
  • mindone_rst_module=N (inside do_init_module())
  • mindone_rst_execn=N (inside fs/exec.c after switching to userspace)

When execution reached the chosen checkpoint, the kernel called machine_restart(NULL) immediately. Because the checkpoint lived in vendor_boot’s chosen/bootargs, moving the probe point took three seconds to repack vendor_boot.

A host script automated the whole loop: flash the inactive _a slot, write a single-try oneshot entry into misc (recomputing the BCAB CRC32 at offset 0x81c), reboot, wait for A/B rollback to our working 5.10 slot on _b, and parse /proc/pl_lk. One bit of truth every ~65 seconds, hands-free, with zero cable replugs and zero risk to the working slot.

When a crash itself started returning 0x2, I flipped the polarity (mindone_hang_level=N running local_irq_disable(); for (;;) cpu_relax();) so 0x800 meant “reached the checkpoint” and 0x2 meant “crashed earlier.”

Two real pitfalls burned an afternoon before the oracle became trustworthy:

  • Silent unknown bootargs

    The kernel quietly ignores misspelled command-line parameters. A typo looks identical to “never reached the checkpoint.” The fix was mandatory System.map symbol verification plus a known-pass control probe before every bisect.

  • __initdata on the module counter

    Marking the counter __initdata looked clean until free_initmem() reclaimed the page right before userspace started loading .ko modules.

On August 21, two probes shattered the two-day wall:

  1. mindone_rst_level=-2 returned 0x2: Linux 6.1.175 finished start_kernel() and entered do_initcalls().
  2. mindone_rst_level=7 also returned 0x2: all eight built-in initcall levels passed.

The core 6.1 kernel was healthy. The silent deaths were inside vendor modules. Binary-searching modules in ~8 reboots pinpointed exact hangs at module #11 (mtk_wdt.ko) and module #14 (pinctrl-mt6789.ko, colliding with built-in pinctrl). Once those were cleared, mindone_rst_execn=6 returned 0x2 twice while mindone_rst_execn=7 returned 0x800 twice.

Think about what that meant: Linux 6.1 had finished first-stage init, brought up UFS storage, mounted super, loaded SELinux policy, and executed six userspace binaries before freezing on the seventh.

If UFS storage was already alive, we did not need to live in a 1-bit world anymore.

Trying to open a log file with filp_open("/dev/block/...", ...) in early userspace failed on every path. So I bypassed the VFS path namespace completely and wrote straight through the block layer by device number:

bdev = blkdev_get_by_dev(MKDEV(259, 24), FMODE_WRITE, NULL);

Major 259, minor 24 was the 26 MiB /logo partition (the boot splash image). A tiny in-kernel dumper (mindone_logdump.c) carved it into 6 slots of 4 MiB each (0x400000), prefixed every snapshot with a 512-byte "MNDLOG02" header (slot index, payload length, trigger source, exec count, and a unique mindone_run=<HHMMSS> tag from bootargs so a failed boot could never be confused with a stale slot from the previous run), and flushed the kernel log buffer using batched multi-page bio requests via vmalloc_to_page().

To guarantee the blind phone returned to our working slot automatically, a companion kthread waited for a configurable timeout and fired emergency_restart() after dumping.

It worked on the very first try (August 22): 1,749 lines (152,331 bytes) across 6/6 snapshots. The moment I verified the dump, I moved the target minor to 259:1 (the empty 50.3 MiB /otp partition, verified 100% zeroed) and restored the original boot splash logo.

That single first dump paid off tenfold immediately:

  1. 01First 6.1 Android boot

    Right before the freeze at 1.22-1.40 s sat cpu (efault): EM: non-increasing freq: 0. Removing mediatek-cpufreq-hw.ko jumped kernel lifetime by 50x, booting Android all the way to Zygote:Preload End in 73.25 s with 39 services running.

  2. 02Why USB adb was silent

    128 lines of UDC core: g1: couldn't find an available UDC or it's busy showed musb_hdrc.ko was simply missing from modules.load.

  3. 03Log storm caught immediately

    126 kernel WARN stack traces from mtk_charger re-registering the same notifier every ten seconds.

From there, 6.1 subsystems fell one by one: Wi-Fi came up on August 24 (wmt_chrdev_wifi in 185 ms plus a NULL country-code fix), first lit-screen PIN login on August 28 (after fixing an fhctl NULL dereference in gpufreq and an IOMMU DMA cookie double-registration), and the cellular modem on August 30 after cracking two bugs disguised by a three-day numeric coincidence (0x40000044 vs 0x40000000):

  • CONNSYS memory window reset default

    A missing build flag left INFRACFG_AO+0x39C’s CONNSYS memory window at its reset default, triggering modem exception 0x305.

  • n_mtkstp overwriting N_TTY

    wmt_drv’s n_mtkstp TTY line discipline omitted .num in its descriptor struct, silently overwriting N_TTY (index 0) and crashing gsm0710muxd every 11.5 seconds.

On September 6, native LineageOS 23.2 (Android 16) booted to the home screen on Linux 6.1.175 (after fixing gzip-only LK kernel loading, TrustKernel fingerprint TA packaging, hwservicemanager under SHIPPING_API_LEVEL 35, ro.hardware=mt8781 vs mt6789 init rc mismatches, an ISoundTriggerHw watchdog hang, and resending backlight state after display_on).

Rung 3: Linux 6.12.92, swapped kCFI hooks, Kleaf, and prebuilt GKI

With 6.1 running daily, I started porting the out-of-tree modules to ACK android16-6.12 (6.12.92). Out of 338 modules, 164 compiled on the first pass; four mechanical kernel API adjustments (class_create 6.4, platform_driver.remove returning void in 6.11, i2c_driver.probe 6.3, and transitive headers) lifted that to 243, then 261/275 in a unified module tree.

Then 6.12 delivered four classic upgrade killers that had nothing to do with compilation:

  1. 01Missing clk_ignore_unused (silent bus abort at 5 seconds)

    Bisection traced a silent watchdog wipe at 5.0-5.5 s to scp.ko calling turn_onoff_ulposc2(OFF). The culprit was my own candidate image builder, which zeroed boot.img’s header cmdline and dropped clk_ignore_unused. The Common Clock Framework shut off SCP’s bus clock before scp.ko loaded, causing an instant bus abort. Restoring clk_ignore_unused let all 278 stage-1 modules boot cleanly.

  2. 02Missing mmap_read_lock under 6.12 maple tree

    TrustKernel’s tkcore called find_vma() inside tee_supp_write() without holding mmap_read_lock. Linux 6.1 tolerated it; Linux 6.12’s per-VMA locks panicked immediately.

  3. 03Swapped Android vendor hook signatures (Oops - CFI)

    This one looked like a random TEE/SMC deadlock for a full day (SMP: failed to stop secondary CPUs). The actual cause was task_turbo.ko registering Android vendor hooks whose signatures swapped between 6.1 and 6.12 (android_rvh_set_user_nice vs android_rvh_set_user_nice_locked, plus two extra arguments on android_vh_cgroup_set_task). Macro-based registration hid the type mismatch at compile time, and kCFI tripped at runtime on whichever CPU hit the hook first.

  4. 04Silent NULL PHY and UBSAN strict flex-arrays

    CONFIG_NOP_USB_XCEIV was unset, so usb_phy_generic_register() compiled to return NULL, while musb_probe() only checked IS_ERR(), parking USB adb in -EPROBE_DEFER forever. At the same time, 6.12’s UBSAN_BOUNDS + UBSAN_TRAP + -fstrict-flex-arrays=3 trapped on legacy [0] and [1] trailing arrays in ccci_ringbuf.c and nic_cmd_event.c (fixed by converting them to C99 []), and 6.7+’s get_file_rcu change created an infinite loop under dmabuf_list_mutex that hung dumpsys meminfo.

On September 7, 6.12.92 booted to USB adb in 36 seconds with 280/280 modules loaded. On September 9, native LineageOS 23.2 on 6.12 became my daily driver. Four days later, an Android 17 AOSP GSI booted via DSU on the same kernel at 96 fps.

The second half of Rung 3 was architectural: dropping hand-rolled make builds in favor of Kleaf DDK, splitting modules Pixel-style into vendor_boot and vendor_dlkm, and switching from a custom-compiled kernel binary to Google’s unmodified prebuilt GKI (android16-6.12-2026-09_r7, then r10, with Google-signed system_dlkm).

Moving to Kleaf and unmodified GKI caught one particularly nasty toolchain bug: leds_mtk_disp.ko passed every modcheck, vermagic, and CRC check, yet failed first-stage init with Exec format error (unsupported RELA relocation: 312). A single if (!weak_func) null check caused clang arm64 to emit R_AARCH64_ADR_GOT_PAGE, which Android’s kernel module loader rejects. That single failure became a permanent static gate (reloc-check.sh).

On November 2, the first native LineageOS 24 (Android 17) build ran on Google’s prebuilt 6.12 GKI.

Rung 4: Linux 6.18.32 GKI and silent struct-copy drift

On November 2, I imported the module set onto Google’s prebuilt android17-6.18 GKI (6.18.32).

Before a single module compiled on my Mac host (running x86_64 Kleaf via Rosetta inside a Linux VM), android17-6.18 broke every host tool in the tree: Google dropped glibc host binaries in favor of musl relinterp PIE executables that omit PT_INTERP and read AT_BASE from the auxiliary vector, which Rosetta does not populate. Every tool aborted with AT_BASE not found in aux vector. Patching Scrt1.o and --dyld-prefix to emit a real PT_INTERP plus libc_musl.so wrappers got Kleaf building natively again, alongside Bazel 8 rule updates and 6.18’s bare transitional Kconfig attribute (CFI_CLANG → CONFIG_CFI).

Porting across 6.12 → 6.18 API churn (MODULE_IMPORT_NS strings, hrtimer_setup(), iommu domain_alloc_paging, drm_panel/fb_create changes, fbdev blank notifier removal, mali_kbase page migration removal) got a full candidate image built in three days.

The first 6.18 test boot on November 5 panicked at 27.2 seconds and auto-rolled back to 6.12, handing us four textbook 6.18 regressions in one clean crash log:

  1. 01V4L2 ioctl priv == NULL Oops

    Linux 6.18 passes NULL as the second (priv) argument to V4L2 ioctl handlers. The moment mediacodec issued VIDIOC_ENUM_FMT, mtk_jpeg_enum_fmt_vid_out ran container_of(NULL) and panicked the system at 27.2 s. Fixing all 36 handlers across mtk_jpeg, mtk_vcodec_dec_v2, and mtk_vcodec_enc_v2 to pull context from file->private_data cleared it permanently.

  2. 02of_find_device_by_node(NULL) strictness

    Linux 6.18 stopped matching NULL nodes in drivers/base/core.c, breaking camera_dip_isp6s (missing larb11) and camera_fdvt_isp51 (helper node without a larb).

  3. 03ASoC DPCM backend validation moved to startup

    Linux 6.18’s soc-pcm.c moved backend validation from prepare to startup and started rejecting pcm_open with EINVAL (ASoC: no backend DAIs enabled) on speaker and wired audio because our HAL configured the AFE crossbar after opening the PCM stream. Reordering crossbar setup before pcm_open restored audio immediately.

  4. 04Silent header-copy struct drift (two drivers at once)

    Out-of-tree vendor modules love carrying private copies of internal kernel headers instead of including the kernel’s own headers. In Linux 6.18:

    • struct rpmsg_endpoint_ops dropped send_offchannel and trysend_offchannel, shifting .trysend in mtk_rpmsg_mbox’s stale copy of rpmsg_internal.h straight onto NULL. Every rpmsg_trysend() returned -ENXIO (-6), triggering 26 SCP ULPOSC calibration warnings.
    • struct mt6397_chip grew five u16[2] arrays to u16[3], shifting chip_id from byte offset 116 to 126. pmic_lbat_service read garbage and misidentified the MT6366 PMIC as an MT6359P.

    Neither bug triggers a compiler warning or a KMI CRC mismatch because the struct is not part of the exported symbol signature. That immediately turned into an automated header-copy-drift static gate comparing every private header copy against the exact ACK 6.18 source tree.

Signed LineageOS 24 release build running Linux 6.18.32-android17-5-g3bdb5dacc0fd-ab16990439-4k GKI on MindOne hardware. Click to enlarge.

On November 6, Linux 6.18.32 GKI booted LineageOS 24 cleanly to boot_completed in 34.8 seconds.

Over the next three weeks, I advanced prebuilt GKI from r12 through r13 to android17-6.18-2026-09_r15 (6.18.32-android17-5-g3bdb5dacc0fd-ab16990439-4k), replaced legacy vendor BSP forks with upstream ACK 6.18 drivers (clocks, pinctrl, pwrap, pm-domains, mainline tcpm + tcpci_rt1711h replacing ~29,000 lines of Richtek PD code, IRQ-driven LVTS thermal, pmic_keys, btcvsd, mmc, wdt, cpufreq-hw, and clk_sync_state replacing clk_disable_unused), and pruned 47+ dead modules down to 210 source-built Kleaf device modules + 24 Google-signed system_dlkm modules.

Side bonus: the exact same binary-search harness pattern later solved a blind BootROM hang on the RISC-V SPV5048 Snap-In Case in ten minutes, proving that reading the 0x48000000 XIP flash window while in BootROM service mode locks up the SoC.

What stayed in the permanent toolchain

Every debugging war story above turned into an automated pre-flash gate so the same class of failure can never brick a slot twice:

Failure class caught during bring-upPermanent automated gate before flashing
Missing symbol / modules.dep strict-loader abort / KMI mismatchStatic modcheck gate against exact Kleaf Module.symvers + two-stage (vendor_boot / vendor_dlkm) dependency closure
Clang arm64 R_AARCH64_ADR_GOT_PAGE (reloc 312) from weak symbolsAutomated ELF RELA relocation scan across all 210 .ko binaries (reloc-check.sh)
Silent rpmsg / mt6397 private header-copy struct driftAutomated header-copy-drift checker diffing every local header copy against the pinned ACK 6.18 tree
Regressions in charger, MUSB host suspend, TCPM, GPU cooling, GNSS, audioHost unit + mutation tests under Clang ASan/UBSan + lock-rank checking on every CI run
misc CRC32 corruption or broken A/B rollbackmisc-edit.py with mandatory CRC32 calculation + full SHA-256 readback verification before reboot

The LineageOS 24 device tree (Apache-2.0), zero-backend Chrome WebUSB installer, SLSA-attested community builds, published kernel snapshots, and Kumi Snap-In Case stack are available here: