Files
bananarchy/bootloader/lk2nd/README.md
T

14 KiB

nokia-beatles lk2nd port

Source port of msm8916-mainline/lk2nd for the Nokia 2720 Flip (nokia-beatles). Both images in images/ are compiled from source; the old binary-patching approach is gone.

Root cause of "black screen, no fastboot" (confirmed)

The phone enumerates as 05c6:900e in Sahara MEMORY_DEBUG mode after every boot attempt — aboot crashed before lk2nd ever ran. Reading aboot's RAM over Sahara exposed its WITH_DEBUG_LOG_BUF ring buffer (cookie 0x474f4c52 "RLOG"), which contains the exact failure:

[580] target_display_init  ret=0
[590] Failed to get parent node: /cpus  errno:-1
[600] panic (caller 0x8f61aa00): ASSERT FAILED at (platform/msm_shared/partial_goods.c:80): 0
[610] HALT: reboot into dload mode...

The 2720's MSM8905 is a partial-goods (2-core) part. Its stock aboot calls update_partial_goods_dtb_nodes() on the QCDT-selected device tree and ASSERT(0)s when /cpus, /cpus/cpu@2 or /cpus/cpu@3 (with a 4-byte device_type) is missing. It then rewrites those device_type values from "cpu\0" to "nak\0". Upstream lk2nd's QCDT DTBs contain no /cpus node at all (only /, /chosen, /memory, /lk2nd), so every lk2nd image — including the untouched bootloader/lk2nd-msm8909.img — crashes on this phone. That is why lk2nd never appeared, why the screen went dark, and why no fastboot ever enumerated.

Other evidence from the same dump:

  • aboot's BSS held our boot.img header (ANDROID!, kernel 345048) and cached cmdline lk2nd lk2nd.compatible=nokia,beatles; it had also built mdss_mdp3.panel=1:spi:0:qcom,mdss_spi_gc9305_v2_qvga_cmd:1:none, i.e. it accepted the image, detected the panel and initialized the panel itself.
  • The kernel payload at 0x80008000 was byte-identical to the flashed image; lk2nd's BSS at 0x80080000 was all zeros, so it never executed.
  • devinfo from the last dump has is_unlocked=1, so signature verification is not the blocker.

Crash evidence lives in backup/nokia-beatles-2720/crash-20261109/ (aboot-log.txt, aboot_full_rw.bin, memory_table.bin, aboot_bss2.bin, aboot_data.bin, mem_bootimg.bin, load_cmm.bin, rst_stat.bin, pmic_pon.bin, ocimem.bin).

The port

  • /cpus fix in the common lk2nd/device/dts/lk2nd.dtsi: a /cpus node with cpu@0..cpu@3, each device_type = "cpu" (exactly 4 bytes so aboot's fdt_setprop_inplace(..., "nak", 4) succeeds). Because it is in the common dtsi, all eight QCDT DTBs in the image have it — aboot cannot pick one without it. The mainline qcom-msm8905-nokia-beatles.dtb already has /cpus, so the Volume Up recovery path is fine too.
  • No separate QCDT DTB. msm8905-qrd-skub.dts keeps upstream's qcom,msm-id = <0x14b 0> and qcom,board-id = <0x0b 0x100>, <0x1000b 0x100>. Both 0x14b entries (0xb/0x100 and 0x1000b/0x100) point at the same DTB. Growing dt_size is harmless — aboot happily processed a 24576-byte QCDT before patching it.
  • nokia-beatles.dtsi injects a compact /lk2nd/nokia-beatles node: model = "Nokia 2720 Flip", compatible = "nokia,beatles", lk2nd,match-panel, lk2nd,dtb-files = "msm8905-nokia-beatles" (lk2nd resolves this to qcom-msm8905-nokia-beatles.dtb), and three panel subnodes matching every name the aboot can report.
  • Only qcom,mdss_spi_gc9305_v2_qvga_cmd — the panel the live aboot reports — carries lk2nd,panel-init: the downstream KaiOS 3.10 qcom,mdss-spi-on-command stream in [wait dlen payload...] form, setting RGB565, the 240x320 window, sleep-out, display-on and RAMWR. lk2nd.force-panel-init forces a replay; by default lk2nd keeps aboot's cont-splash init because aboot reports 1:spi:0:.
  • lk2nd/include/lk2nd/spi-panel-init.h: byte-stream walker shared between platform/msm_shared/mdss_spi.c and the host unit test.
  • lk2nd/device/2nd/spi-display.c: guards a NULL interface, looks up the stream, and paints the Bananarchy RGB565 boot splash before the first framebuffer flush (DISABLE_SPLASH_PARTITION=1 plus menu.c's bottom-only text otherwise leaves a nearly black frame).
  • Cmdline: lk2nd lk2nd.compatible=nokia,beatles — an upstream lk2nd feature that selects the beatles node directly.

Current state: lk2nd works; the display is opt-in and probeable

lk2nd boots, reaches fastboot and the extlinux chain. The mainline kernel still has not been observed booting successfully; that is a separate issue (the kernel side, not lk2nd). The remaining lk2nd work was to make panel initialization safe and verifiable rather than disabled forever.

Earlier attempts to enable the SPI display during LK2ND_INIT wedged lk2nd before USB came up (boot vibrator stuck on, no fastboot). The cause is QUP SPI/clock register polls with no timeout: several loops in spi_qup.c and clock_lib2.c spin forever when the clock never comes up. The port now:

  • Bounds every QUP FIFO wait (QUP_FIFO_TIMEOUT) and every stuck clock poll (CLK_POLL_TIMEOUT), so a dead bus can never wedge the bootloader.
  • Registers a RAM-only 240x320 RGB565 framebuffer at boot by default (lk2nd.no-display), which keeps fbcon_display() non-NULL so cont-splash does not try to read MDP registers.
  • Adds fastboot commands that run after USB is up:
    • fastboot oem display-init — mdss_spi_init(), the GC9305 v2 lk2nd,panel-init stream (RGB565, 240x320 window, sleep-out, display-on, RAMWR), then paint the branded boot splash and flush one frame. Safe because all polls are bounded; failures are reported and logged, not hung.
    • fastboot oem display-test — repaint and flush.
    • fastboot oem screenshot && fastboot get_staged shot.ppm — verify the framebuffer contents.
    • fastboot oem scan-dtb && fastboot get_staged kernel.dtb — stage the exact DTB lk2nd hands the kernel (after DT updates) for offline inspection.
    • fastboot oem scan-boot / oem log — extlinux scan and boot log.
  • images/boot-lk2nd-nokia-beatles-display.img uses lk2nd.display=on to run the same panel init during boot. Flash it with --lk2nd-image ./images/boot-lk2nd-nokia-beatles-display.img.

Corrections to earlier notes: the pmOS initramfs jumps straight to stage 2 when /init_2nd.sh is present (it is), so a missing /boot/initramfs-extra is not the cause of a hang. And an all-0xff ramoops region after a hard power cycle is decayed DRAM, not proof that the kernel hung before pstore.

Decisive finding: extlinux is fine, the mainline kernel hangs

oem scan-boot run on the live device proved the boot chain: wrp0p32p0 (pmOS_boot, 256 MiB) enumerated and mounted, /extlinux/extlinux.conf parsed, vmlinuz / qcom-msm8905-nokia-beatles.dtb / initramfs all resolved and lk2nd_boot_label() reached boot_linux() without errors. oem read-partition also verified the live userdata MBR (55aa, two 0x83 partitions) and its ext2 superblock (53ef at 1 MiB).

So the mainline kernel is where the remaining hang is. fastboot boot of the standalone debug boot.img also downloaded OKAY then produced no USB RNDIS, consistent with a kernel that stops before userspace. lk2nd now always injects the ramoops reserved-memory node on Linux boots, and CONFIG_PSTORE_RAM=y / CONFIG_PSTORE_CONSOLE=y are enabled; a warm reset (power-cycle into fastboot with Vol Down + Power) should preserve oem ramoops console output. A hard power-off decays DRAM instead, which is why one earlier read of that region was all 0xff.

Note: the panel init stream in lk2nd,panel-init is the downstream KaiOS 3.10 qcom,mdss-spi-on-command sequence for spi_gc9305_v2_qvga_cmd, byte-for-byte ([wait dlen payload...] with the wait applied after the command). lk2nd/include/lk2nd/spi-panel-init.h walks it; the host C test verifies framing, RGB565, 240x320 window, delays and error handling.

Live hardware confirmation and next step

The GC9305 v2 panel init is confirmed on the phone. A chain-loaded diagnostic image initially lacked aboot's mdss_mdp3.panel tag, so the port now falls back to the beats QCDT node's only lk2nd,panel-init stream and keeps the known SPI interface. With that fallback, oem display-init and oem display-test both returned OKAY, USB stayed up, and oem screenshot staged a 240x320 P6 framebuffer with exactly the three test colors: a cyan 20-pixel top bar and alternating blue/dark a branded splash. The boot-time lk2nd.display=on path also pushes SPI traffic; the forced-fastboot menu redraws over the splash afterwards.

The diagnostics were tightened after that live run:

  • oem scan-boot now lets boot_linux() apply the final cmdline and DT updates, then returns before the kernel jump. oem scan-dtb therefore stages the actual post-update DTB, not the raw extlinux file.
  • oem ramoops console validates the pstore signature, size and offset, rotates a wrapped ring buffer, and reports No valid pstore console for decayed DRAM instead of trying to stage 0xffffffff bytes.
  • The upstream per-word QUP SPEW log was removed. Earlier DEBUG=2 builds spent about 40 seconds per full frame and overwrote the whole 32 KiB log with FIFO status lines.

From fastboot, without reflashing:

fastboot boot ./images/boot-lk2nd-nokia-beatles-diagnostic.img
fastboot getvar lk2nd:panel
fastboot oem display-init
fastboot oem display-test
fastboot oem screenshot && fastboot get_staged shot.ppm
fastboot oem scan-boot
fastboot oem scan-dtb && fastboot get_staged kernel.dtb
fastboot oem log && fastboot get_staged lk2nd.log
fastboot oem ramoops console && fastboot get_staged console.log

Use kernel.dtb to check whether cpu@2/cpu@3 are status = "fail" on this dual-core partial-goods part (fuse 0x58000 reads 0x30100094). The r2 diagnostic staged a 41440-byte final DTB that differs from the source DTB: cpu@2/cpu@3 are status = "fail", /reserved-memory/ramoops@9fa80000 has a 256 KiB console, and /chosen contains the final bootargs plus linux,initrd-start / linux,initrd-end. The partial-goods DT update is therefore confirmed; enabled CPU2/3 are no longer the leading kernel-hang suspect. If pstore was populated by a warm reset, console.log gives the kernel console; a hard power-off decays DRAM and produces no valid console. Upstream oem read-partition passes the requested byte count directly to mmc_read(), which asserts unless the size is a 512-byte multiple; the 16-byte SEANDROIDENFORCE tail used to drop USB during boot-slot read-back. The r3 port rounds the MMC read up internally, rejects unaligned offsets and stages only the requested byte count. Use fastboot reboot, not fastboot reboot-bootloader, to test a persisted boot slot. reboot-bootloader now writes the low-bit FASTBOOT_MODE cookie and returns to this lk2nd Fastboot menu; it is not a way to test the newly flashed image. A fastboot flash boot handoff can still drop USB, so power-cycle with Vol Down + Power if fastboot does not reappear.

Power-menu Fastboot menu

sxmo_power.sh loader writes 0x02 into PON_SOFT_RB_SPARE[1:0]. The stock boot chain scrubs the upstream high-bit cookie before chain-loading lk2nd, so this port's check_hard_reboot_mode() prefers bits [1:0] and its reboot_device() writes the same low-bit cookie for FASTBOOT_MODE. That keeps Bootloader, EDL, Reboot, Recovery and Shutdown visible on the display-enabled image. Live verification: the menu appears within 6 s, fastboot oem screenshot stages the 240x320 menu frame, and fastboot reboot-bootloader returns to lk2nd:version instead of booting Linux.

Building

./scripts/build-lk2nd-beatles.sh          # build normal + diagnostic + display + validate
./scripts/build-lk2nd-beatles.sh --check  # validate the shipped images only
./scripts/build-lk2nd-beatles.sh --only normal|diagnostic|display
./scripts/build-lk2nd-beatles.sh --only normal --force-panel-init
WITH_DISPLAY=1 ./scripts/build-lk2nd-beatles.sh --only normal

Pins upstream commit cf45aefd22d744b2bf9b39455afae697ce430063, applies nokia-beatles.patch, builds inside the rootless Docker toolchain image from Dockerfile (gcc-arm-none-eabi, dtc, libfdt). All three images are reproducible byte for byte. Overrides: BANANARCHY_LK2ND_SRC, BANANARCHY_LK2ND_BUILD_DIR, JOBS.

Validating

python3 scripts/check-lk2nd-beatles.py       # boot header, QCDT, DTB, /cpus, stream
python3 scripts/check-lk2nd-beatles.py \
  --image images/boot-lk2nd-nokia-beatles-display.img --expect-display 1
python3 scripts/test-lk2nd-beatles-port.py   # all 3 images + host C parser unit test

The validator is pure Python (it parses the FDT itself) and enforces that every QCDT DTB has /cpus/cpu@2 and /cpus/cpu@3 with a 4-byte device_type, that both 0x14b entries share one DTB, and that the 2720 DTB carries the beatles node with a valid GC9305 v2 lk2nd,panel-init stream.

Panel data provenance and limits

The v2 init stream comes from the 2720 downstream KaiOS 3.10 arch/arm/boot/dts/qcom/spi-panel-gc9305-qvga-cmd.dtsi as adapted by the archived pmaports linux-nokia-beatles package. The other two panel names are match-only nodes: aboot detects and initializes those sources itself and their exact streams are not published. The 240x240 external cover display is a separate SPI panel, untouched by lk2nd. The kernel spi-mux modules are built and loaded, but the overlay remains hardware-gated until gpio13 and the external reset/DC routing are validated.

SPI wiring matches downstream: BLSP_QUP_BASE(1, 4) is spi@78b9000 (BLSP1 QUP5 in 1-based numbering), DC GPIO 110.

Normal flashing

sudo ./flash-edl.sh nokia-beatles --backup-dir ./backup/nokia-beatles-2720 --verify

flash-edl.py writes the normal image to boot and the standalone mainline boot.img to recovery (Volume Up fallback), and unlocks eMMC devinfo first. A successful Bananarchy boot has not been observed yet.