- Migrate nokia-tough to canonical nokia-coconut while keeping CLI aliases, add layered bootloader/lk2nd/nokia-coconut.patch, bootfs/bootimg validators, and offline scripts/inspect-stock-msm8905-dump.py - Complete nokia-coconut Stage 2 hardware bring-up: wire 6-column 22-key keypad (gpio0, gpio3, gpio7, gpio99, gpio6, gpio1), gpio98 KEY_POWER, and pon@800:resin KEY_DOWN (0x6c); split leds-msm8905-torch into GPIO_13 white:torch (dedicated top-edge flashlight) and GPIO_32 camera:flash (rear camera flash for camera.so and bananarchy-photo) - Restore sdhci@7864000 non-removable across all six DTS/DTB targets, remove unwired gpio38 cd-gpios/sdc2-cd-* states, and harden sxmo_sdcard.sh under flock - Register upcoming build a1120 (cocojamboo) in scripts/version.sh, scripts/check-rebuild.sh, CHANGELOG.md, AGENTS.md, README.md, and MANUAL.md with verified hashes across nokia-argon, nokia-beatles, and nokia-coconut
184 lines
6.1 KiB
Python
Executable File
184 lines
6.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Validate the 2720 Flip boot image before it is flashed over EDL.
|
|
|
|
Checks the Android header, the kernel+0x2c appended-DTB pointer, the exact
|
|
stock Qualcomm match IDs and the 512 MiB memory fallback inside the DTB. Skips
|
|
cleanly when the image has not been built yet, so check-rebuild.sh stays useful
|
|
in a fresh clone.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import struct
|
|
import sys
|
|
|
|
BOOT_MAGIC = b"ANDROID!"
|
|
FDT_MAGIC = 0xd00dfeed
|
|
DTB_OFFSET_FIELD = 0x2c
|
|
BOOT_PARTITION_BYTES = 26165248
|
|
FDT_BEGIN_NODE = 1
|
|
FDT_END_NODE = 2
|
|
FDT_PROP = 3
|
|
FDT_NOP = 4
|
|
FDT_END = 9
|
|
|
|
STOCK_MSM_ID = struct.pack(">2I", 0x14b, 0)
|
|
STOCK_BOARD_ID = struct.pack(">2I", 0x1000b, 0x100)
|
|
STOCK_PMIC_ID = struct.pack(">4I", 0x1000d, 0, 0, 0)
|
|
MEMORY_512M = struct.pack(">2I", 0x80000000, 0x20000000)
|
|
|
|
DEVICE_MODELS = {
|
|
"nokia-beatles": "Nokia 2720 Flip",
|
|
"nokia-coconut": "Nokia 800 Tough",
|
|
}
|
|
DEVICE_SHORT = {
|
|
"nokia-beatles": "2720",
|
|
"nokia-coconut": "800 Tough",
|
|
}
|
|
|
|
|
|
def align(value, page):
|
|
return (value + page - 1) // page * page
|
|
|
|
|
|
def parse_fdt(data):
|
|
vals = struct.unpack_from(">10I", data, 0)
|
|
magic, totalsize, off_struct, off_strings, off_rsv, version = vals[:6]
|
|
size_strings, size_struct = vals[8], vals[9]
|
|
if magic != FDT_MAGIC:
|
|
raise ValueError("bad FDT magic")
|
|
if version not in (16, 17):
|
|
raise ValueError("unsupported FDT version %d" % version)
|
|
strings = data[off_strings:off_strings + size_strings]
|
|
nodes = {}
|
|
stack = []
|
|
pos = off_struct
|
|
while True:
|
|
token = struct.unpack_from(">I", data, pos)[0]
|
|
pos += 4
|
|
if token == FDT_BEGIN_NODE:
|
|
end = data.index(b"\0", pos)
|
|
name = data[pos:end].decode("utf-8", "replace")
|
|
pos = (end + 4) & ~3
|
|
if not stack:
|
|
path = "/"
|
|
elif stack[-1] == "/":
|
|
path = "/" + name
|
|
else:
|
|
path = stack[-1] + "/" + name
|
|
stack.append(path)
|
|
nodes[stack[-1]] = {}
|
|
elif token == FDT_END_NODE:
|
|
stack.pop()
|
|
if not stack:
|
|
break
|
|
elif token == FDT_PROP:
|
|
length, nameoff = struct.unpack_from(">II", data, pos)
|
|
pos += 8
|
|
value = data[pos:pos + length]
|
|
pos = (pos + length + 3) & ~3
|
|
end = strings.index(b"\0", nameoff)
|
|
prop = strings[nameoff:end].decode("utf-8", "replace")
|
|
nodes[stack[-1]][prop] = value
|
|
elif token == FDT_NOP:
|
|
continue
|
|
elif token == FDT_END:
|
|
break
|
|
else:
|
|
raise ValueError("bad FDT token 0x%x" % token)
|
|
return nodes, totalsize
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(
|
|
description="Validate MSM8905 lk2nd-chained mainline boot.img"
|
|
)
|
|
parser.add_argument(
|
|
"--device",
|
|
choices=tuple(DEVICE_MODELS.keys()),
|
|
default="nokia-beatles",
|
|
help="Target device to validate (default: nokia-beatles)",
|
|
)
|
|
parser.add_argument(
|
|
"--image",
|
|
default="",
|
|
help="Explicit path to boot-bananarchy-<device>.img",
|
|
)
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
device = args.device
|
|
short_name = DEVICE_SHORT[device]
|
|
expected_model = DEVICE_MODELS[device]
|
|
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
boot = args.image or os.path.join(base, "images", "boot-bananarchy-%s.img" % device)
|
|
if not os.path.isfile(boot):
|
|
print("[skip] %s boot image not built yet" % short_name)
|
|
return 0
|
|
data = open(boot, "rb").read()
|
|
problems = []
|
|
if data[:8] != BOOT_MAGIC:
|
|
problems.append("not an Android boot image")
|
|
fields = struct.unpack_from("<8s8I", data, 0)
|
|
kernel_size, kernel_addr, ramdisk_size, ramdisk_addr = fields[1:5]
|
|
second_size, second_addr, tags_addr, page = fields[5:9]
|
|
if page != 2048:
|
|
problems.append("page size is %d, expected 2048" % page)
|
|
if len(data) > BOOT_PARTITION_BYTES:
|
|
problems.append("boot image is larger than the 25 MiB boot partition")
|
|
cmdline = data[64:576].split(b"\0")[0].decode("utf-8", "replace")
|
|
cmdline_parts = cmdline.split()
|
|
if "earlycon" in cmdline_parts:
|
|
problems.append("cmdline still contains earlycon")
|
|
if "quiet" not in cmdline_parts or "splash" not in cmdline_parts:
|
|
problems.append("cmdline is missing 'quiet splash' (Plymouth never starts)")
|
|
for flag in ("loglevel=8", "ignore_loglevel", "initcall_debug"):
|
|
if flag in cmdline_parts:
|
|
problems.append("cmdline still has kernel debug flag %s" % flag)
|
|
if kernel_addr != 0x80008000 or ramdisk_addr != 0x81000000 or tags_addr != 0x80000100:
|
|
problems.append("boot header load addresses do not match the stock %s" % short_name)
|
|
kernel_off = page
|
|
dtb_rel = struct.unpack_from("<I", data, kernel_off + DTB_OFFSET_FIELD)[0]
|
|
dtb_abs = kernel_off + dtb_rel
|
|
if not 0 < dtb_rel < kernel_size:
|
|
problems.append("kernel+0x2c points outside the kernel payload")
|
|
elif data[dtb_abs:dtb_abs + 4] != b"\xd0\x0d\xfe\xed":
|
|
problems.append("kernel+0x2c does not point at an FDT header")
|
|
else:
|
|
dtb = data[dtb_abs:kernel_off + kernel_size]
|
|
nodes, totalsize = parse_fdt(dtb)
|
|
if totalsize > len(dtb):
|
|
problems.append("appended DTB is truncated")
|
|
root = nodes.get("/", {})
|
|
model = root.get("model", b"").rstrip(b"\0").decode("utf-8", "replace")
|
|
if model != expected_model:
|
|
problems.append("appended DTB model is %r (expected %r)" % (model, expected_model))
|
|
for prop, expected in (("qcom,msm-id", STOCK_MSM_ID),
|
|
("qcom,board-id", STOCK_BOARD_ID),
|
|
("qcom,pmic-id", STOCK_PMIC_ID)):
|
|
if root.get(prop) != expected:
|
|
problems.append("%s does not match the stock %s QRD SKUB value" % (prop, short_name))
|
|
mem = None
|
|
for path, props in nodes.items():
|
|
if props.get("device_type") == b"memory\0":
|
|
mem = props
|
|
break
|
|
if mem is None:
|
|
problems.append("appended DTB has no /memory node")
|
|
elif mem.get("reg") != MEMORY_512M:
|
|
problems.append("appended DTB /memory:reg is not the 512 MiB fallback")
|
|
if ramdisk_size <= 0 or second_size != 0:
|
|
problems.append("unexpected ramdisk/second sizes")
|
|
if problems:
|
|
for problem in problems:
|
|
print("FAIL: %s" % problem)
|
|
return 1
|
|
print("[ok] %s boot image: exact stock IDs, 512 MiB memory fallback, appended DTB pointer" % short_name)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|