Add flasher credential provisioning, LUKS2 FDE, LED fixes, and docs
This commit is contained in:
1 parent
2706b9a901
commit
b7dca4f15f
49 files changed
+1524
-183
No files matched your search
@@ -159,21 +159,103 @@ DTB_SZ="$(stat -c %s "$BASE_DIR/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.d
|
||||
[ "$DTB_SZ" -le 524288 ] || { echo "FAIL: DTB > 512 KiB ($DTB_SZ)" >&2; exit 1; }
|
||||
|
||||
python3 - "$IMAGES_DIR/boot-geminux.img" "$IMAGES_DIR/recovery-geminux.img" \
|
||||
"$BASE_DIR/prebuilt/kernel/boot/config-7.3.5-geminux" "$ROOTFS_DIR" <<'PYEOF'
|
||||
"$BASE_DIR/prebuilt/kernel/boot/config-7.3.5-geminux" "$ROOTFS_DIR" \
|
||||
"$BASE_DIR/src/initramfs/init" "$BASE_DIR/src/initramfs/init-recovery" <<'PYEOF'
|
||||
import gzip
|
||||
import os
|
||||
import re
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def parse_newc_entries(cpio_bytes):
|
||||
entries = {}
|
||||
pos = 0
|
||||
total = len(cpio_bytes)
|
||||
while pos + 110 <= total:
|
||||
hdr = cpio_bytes[pos:pos + 110]
|
||||
if hdr[:6] not in (b"070701", b"070702"):
|
||||
raise SystemExit(f"FAIL: invalid cpio newc magic at offset {pos}: {hdr[:6]!r}")
|
||||
filesize = int(hdr[54:62], 16)
|
||||
namesize = int(hdr[94:102], 16)
|
||||
name_start = pos + 110
|
||||
name_end = name_start + namesize
|
||||
name = cpio_bytes[name_start:name_end].rstrip(b"\x00").decode("utf-8", "replace")
|
||||
if name == "TRAILER!!!":
|
||||
break
|
||||
data_start = (name_end + 3) & ~3
|
||||
rel = name[2:] if name.startswith("./") else name
|
||||
entries[rel] = cpio_bytes[data_start:data_start + filesize]
|
||||
pos = (data_start + filesize + 3) & ~3
|
||||
return entries
|
||||
|
||||
|
||||
GEMINI_HW_KEYCODES = (
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 28, 29,
|
||||
30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 42,
|
||||
44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 56, 57,
|
||||
103, 105, 106, 108, 125,
|
||||
)
|
||||
|
||||
for init_script in sys.argv[5:7]:
|
||||
subprocess.run(["sh", "-n", init_script], check=True)
|
||||
with open(init_script, "r", encoding="utf-8") as f:
|
||||
txt = f.read()
|
||||
if "cryptsetup resize" in txt:
|
||||
raise SystemExit(f"FAIL: redundant interactive 'cryptsetup resize' found in {init_script}")
|
||||
for line in txt.splitlines():
|
||||
if "loadkmap" in line and line.count("<") > 1:
|
||||
raise SystemExit(f"FAIL: double stdin redirection on loadkmap in {init_script}: {line}")
|
||||
if init_script == sys.argv[5]:
|
||||
stripped = line.strip()
|
||||
if stripped.startswith(("resize2fs ", "e2fsck -p ")) and "</dev/null" not in line:
|
||||
raise SystemExit(f"FAIL: missing '</dev/null' stdin guard in {init_script}: {stripped}")
|
||||
|
||||
for path in sys.argv[1:3]:
|
||||
with open(path, "rb") as f:
|
||||
hdr = f.read(640)
|
||||
blob = f.read()
|
||||
hdr = blob[:640]
|
||||
if hdr[:8] != b"ANDROID!":
|
||||
raise SystemExit(f"FAIL: invalid boot image magic in {path}")
|
||||
kernel_size = struct.unpack("<I", hdr[8:12])[0]
|
||||
kernel_addr = struct.unpack("<I", hdr[12:16])[0]
|
||||
ramdisk_size = struct.unpack("<I", hdr[16:20])[0]
|
||||
page_size = struct.unpack("<I", hdr[36:40])[0] or 2048
|
||||
if kernel_addr != 0x40080000:
|
||||
raise SystemExit(
|
||||
f"FAIL: {path} kernel_addr={kernel_addr:#010x}, expected 0x40080000 for Gemini LK"
|
||||
)
|
||||
k_pages = (kernel_size + page_size - 1) // page_size
|
||||
r_off = (1 + k_pages) * page_size
|
||||
cpio_bytes = gzip.decompress(blob[r_off:r_off + ramdisk_size])
|
||||
rd_entries = parse_newc_entries(cpio_bytes)
|
||||
for req_rd in ("init", "sbin/cryptsetup", "etc/gemini-us.kmap", "bin/loadkmap"):
|
||||
if req_rd not in rd_entries:
|
||||
raise SystemExit(f"FAIL: {path} ramdisk missing '{req_rd}'")
|
||||
rd_init_txt = rd_entries["init"].decode("utf-8", "replace")
|
||||
if "cryptsetup resize" in rd_init_txt:
|
||||
raise SystemExit(f"FAIL: {path} init still contains 'cryptsetup resize'")
|
||||
kmap = rd_entries["etc/gemini-us.kmap"]
|
||||
if len(kmap) < 7 + 256 + 256 or kmap[:7] != b"bkeymap" or kmap[7] != 1:
|
||||
raise SystemExit(f"FAIL: {path} invalid bkeymap header in etc/gemini-us.kmap")
|
||||
map0 = struct.unpack_from("<128H", kmap, 7 + 256)
|
||||
holes = [kc for kc in GEMINI_HW_KEYCODES if map0[kc] == 0x0200]
|
||||
if holes:
|
||||
raise SystemExit(f"FAIL: {path} etc/gemini-us.kmap has unbound Gemini keycodes: {holes}")
|
||||
for kc, exp, label in (
|
||||
(28, 0x0201, "Return"),
|
||||
(42, 0x0700, "LShift"),
|
||||
(54, 0x0700, "RShift"),
|
||||
(57, 0x0020, "Space"),
|
||||
(1, 0x001B, "Escape"),
|
||||
(125, 0x0701, "AltGr/Fn"),
|
||||
):
|
||||
if map0[kc] != exp:
|
||||
raise SystemExit(
|
||||
f"FAIL: {path} etc/gemini-us.kmap keycode {kc} ({label}) = {map0[kc]:#06x}, expected {exp:#06x}"
|
||||
)
|
||||
cmdline = hdr[64:576].split(b"\x00", 1)[0].decode("ascii", "replace")
|
||||
for req in ("clk_ignore_unused", "maxcpus=8", "noautodetect"):
|
||||
if req not in cmdline.split():
|
||||
@@ -189,8 +271,9 @@ for line in kcfg.splitlines():
|
||||
break
|
||||
else:
|
||||
raise SystemExit(f"FAIL: {sys.argv[3]} missing CONFIG_CMDLINE")
|
||||
if "CONFIG_REGULATOR_FIXED_VOLTAGE=y" not in kcfg.splitlines():
|
||||
raise SystemExit(f"FAIL: {sys.argv[3]} missing CONFIG_REGULATOR_FIXED_VOLTAGE=y")
|
||||
for req_cfg in ("CONFIG_REGULATOR_FIXED_VOLTAGE=y", "CONFIG_BLK_DEV_DM=y", "CONFIG_DM_CRYPT=y"):
|
||||
if req_cfg not in kcfg.splitlines():
|
||||
raise SystemExit(f"FAIL: {sys.argv[3]} missing {req_cfg}")
|
||||
|
||||
rootfs = sys.argv[4]
|
||||
for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit",
|
||||
@@ -200,12 +283,15 @@ for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit",
|
||||
"usr/sbin/geminux-wifi-nvram", "usr/sbin/geminux-tzctl",
|
||||
"usr/bin/geminux-datetime",
|
||||
"usr/bin/bantam",
|
||||
"etc/keymap/gemini-us.map",
|
||||
"etc/skel/.gitconfig",
|
||||
"home/user/.gitconfig",
|
||||
"etc/NetworkManager/dispatcher.d/30-geminux-chrony",
|
||||
"etc/polkit-1/rules.d/10-geminux.rules"):
|
||||
if not os.path.lexists(os.path.join(rootfs, req_rel)):
|
||||
raise SystemExit(f"FAIL: missing required path {os.path.join(rootfs, req_rel)}")
|
||||
if not any(os.path.lexists(os.path.join(rootfs, p)) for p in ("sbin/cryptsetup", "usr/sbin/cryptsetup")):
|
||||
raise SystemExit(f"FAIL: missing cryptsetup binary in {rootfs}")
|
||||
if os.path.lexists(os.path.join(rootfs, "etc/runlevels/sysinit/hwdrivers")):
|
||||
raise SystemExit("FAIL: hwdrivers must not be enabled in sysinit")
|
||||
if os.path.lexists(os.path.join(rootfs, "etc/runlevels/default/wpa_supplicant")):
|
||||
|
||||
Reference in new issue
Block a user