Finalize verified 2720 Flip release source and untrack image outputs

This commit is contained in:
Luxferre committed 2026-11-09 23:04:13 +02:00
1 parent 2a3078e42c
commit 1c011b360a
121 files changed
+8467 -686

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
FROM alpine:3.20
RUN apk add --no-cache \
gcc-arm-none-eabi \
make \
python3 \
dtc \
dtc-dev \
tar \
git \
py3-setuptools
+265
View File
@@ -0,0 +1,265 @@
# nokia-beatles lk2nd port
Source port of
[`msm8916-mainline/lk2nd`](https://github.com/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:
```bash
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
```sh
./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
```sh
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
```sh
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.
File diff suppressed because it is too large. Load diff
+53
View File
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifndef LK2ND_SPI_PANEL_INIT_H
#define LK2ND_SPI_PANEL_INIT_H
/*
* Walk a downstream qcom,mdss-spi-on-command byte stream.
*
* Every command is [wait_ms, dlen, payload[dlen]]. The first payload byte is
* the command (DC low), the rest are parameters (DC high), and wait_ms is
* applied after the command. This matches the KaiOS 3.10 mdss_spi_panel_on()
* implementation (struct spi_ctrl_hdr { char wait; char dlen; }).
*
* Returns 0 on success, a negative value on a malformed stream or a write
* error. The callbacks make this usable by both the target SPI driver and a
* host unit test.
*/
struct lk2nd_spi_panel_init_ops {
int (*write_cmd)(const unsigned char *cmd);
int (*write_data)(const unsigned char *data, unsigned int len);
void (*delay)(unsigned int ms);
};
static inline int lk2nd_spi_panel_init_run(const unsigned char *cmds,
unsigned int len, const struct lk2nd_spi_panel_init_ops *ops)
{
unsigned int off = 0, size;
unsigned char wait;
int ret;
while(off + 2 <= len) {
wait = cmds[off++];
size = cmds[off++];
if(!size || off + size > len)
return -1;
ret = ops->write_cmd(cmds + off);
if(ret)
return ret;
if(size > 1) {
ret = ops->write_data(cmds + off + 1, size - 1);
if(ret)
return ret;
}
off += size;
if(wait)
ops->delay(wait);
}
return off == len ? 0 : -1;
}
#endif /* LK2ND_SPI_PANEL_INIT_H */
+117
View File
@@ -0,0 +1,117 @@
/* Host unit test for the lk2nd SPI panel init byte-stream walker. */
#include <stdio.h>
#include <string.h>
#include "spi-panel-init.h"
#include "panel_streams.h"
static unsigned char cmds[64];
static unsigned char data[64][16];
static unsigned int data_len[64];
static unsigned int cmd_count, delay_total, delay_count;
static int fail_write;
static int rec_cmd(const unsigned char *cmd)
{
if(fail_write)
return -5;
if(cmd_count < 64)
cmds[cmd_count] = cmd[0];
cmd_count++;
return 0;
}
static int rec_data(const unsigned char *buf, unsigned int len)
{
if(fail_write)
return -5;
if(cmd_count > 0 && cmd_count <= 64 && len <= 16) {
memcpy(data[cmd_count - 1], buf, len);
data_len[cmd_count - 1] = len;
}
return 0;
}
static void rec_delay(unsigned int ms)
{
delay_total += ms;
delay_count++;
}
static const struct lk2nd_spi_panel_init_ops ops = {
.write_cmd = rec_cmd,
.write_data = rec_data,
.delay = rec_delay,
};
static void reset(void)
{
cmd_count = delay_total = delay_count = 0;
fail_write = 0;
memset(cmds, 0, sizeof(cmds));
memset(data_len, 0, sizeof(data_len));
}
#define CHECK(cond, msg) do { \
if(!(cond)) { \
printf("[fail] %s (line %d)\n", (msg), __LINE__); \
return 1; \
} \
} while(0)
static int has_cmd(const unsigned char *cmd, unsigned int len)
{
unsigned int i;
for(i = 0; i < cmd_count; i++) {
if(cmds[i] != cmd[0])
continue;
if(len == 1)
return 1;
if(data_len[i] == len - 1 && memcmp(data[i], cmd + 1, len - 1) == 0)
return 1;
}
return 0;
}
int main(void)
{
static const unsigned char rgb565[] = {0x3a, 0x05};
static const unsigned char window_x[] = {0x2a, 0x00, 0x00, 0x00, 0xef};
static const unsigned char window_y[] = {0x2b, 0x00, 0x00, 0x01, 0x3f};
static const unsigned char zero_dlen[] = {0x00, 0x00};
static const unsigned char trailing[] = {0x00, 0x01, 0x29, 0x00};
static const unsigned char truncated[] = {0x00, 0x05, 0x2a, 0x00};
reset();
CHECK(lk2nd_spi_panel_init_run(stream_v2, sizeof(stream_v2), &ops) == 0,
"v2 stream rejected");
CHECK(cmd_count == 10, "v2 stream must have 10 commands");
CHECK(delay_total == 120 && delay_count == 1,
"v2 stream must wait 120 ms once after sleep-out");
CHECK(cmds[0] == 0xfe && cmds[1] == 0xef,
"v2 stream must start with the GC9305 page select");
CHECK(has_cmd(rgb565, sizeof(rgb565)), "missing RGB565 COLMOD");
CHECK(has_cmd(window_x, sizeof(window_x)), "missing 240 column window");
CHECK(has_cmd(window_y, sizeof(window_y)), "missing 320 row window");
CHECK(has_cmd((const unsigned char *)"\x11", 1), "missing sleep-out");
CHECK(has_cmd((const unsigned char *)"\x29", 1), "missing display-on");
CHECK(cmds[cmd_count - 1] == 0x2c, "stream must end with RAMWR (0x2c)");
reset();
CHECK(lk2nd_spi_panel_init_run(zero_dlen, sizeof(zero_dlen), &ops) < 0,
"zero dlen accepted");
reset();
CHECK(lk2nd_spi_panel_init_run(trailing, sizeof(trailing), &ops) < 0,
"trailing garbage accepted");
reset();
CHECK(lk2nd_spi_panel_init_run(truncated, sizeof(truncated), &ops) < 0,
"truncated payload accepted");
reset();
fail_write = 1;
CHECK(lk2nd_spi_panel_init_run(stream_v2, sizeof(stream_v2), &ops) == -5,
"write error not propagated");
printf("[ok] SPI panel init walker: GC9305 v2 stream, framing, RGB565, "
"240x320 window, delays and error handling\n");
return 0;
}