Package release ZIPs, streamline docs, and backport X11 DPMS/lock fixes

- Streamline README, INSTALL, MANUAL, ARCHITECTURE, and POWER-OPTIMIZATION docs
- Add release ZIP packager (package-image.sh, scripts/package-release-zip.py, rebuild-image.sh --package) with sanitized rootfs, SHA256SUMS, and FLASH-INSTRUCTIONS.txt
- Add automatic offline MT6797 firmware ext4 injection in flash-mtk.py and scripts/extract-vendor-fw.py
- Backport X11 DPMS wake + XResetScreenSaver in geminux-powerd and _GEMINUX_LOCK_READY + grab-first sync in geminux-lock, rebuild aarch64 prebuilts, and expand tests
This commit is contained in:
Luxferre committed 2026-11-28 09:18:51 +02:00
1 parent 5472d4273a
commit 180d0a91e6
18 files changed
+1242 -480

No files matched your search

+207
View File
@@ -731,6 +731,210 @@ def test_luks2_encryption_offline():
print("[PASS] Offline LUKS2 encryption, PTY passphrase unlock, and XTS-256 ext4 decryption verified")
def test_firmware_injection_ext4():
if not all(shutil.which(cmd) for cmd in ("mke2fs", "debugfs", "e2fsck")):
print("[SKIP] mke2fs/debugfs/e2fsck not available for firmware injection test")
return
fw_mod = flash_mtk.load_firmware_module()
with tempfile.TemporaryDirectory(prefix="geminux-fwinj-test-") as tmp:
sysroot = os.path.join(tmp, "sysroot")
os.makedirs(os.path.join(sysroot, "etc"), exist_ok=True)
os.makedirs(os.path.join(sysroot, "home", "user"), exist_ok=True)
with open(os.path.join(sysroot, "etc", "passwd"), "w", encoding="utf-8") as f:
f.write("root:x:0:0:root:/root:/bin/bash\nuser:x:10000:10000::/home/user:/bin/bash\n")
with open(os.path.join(sysroot, "etc", "group"), "w", encoding="utf-8") as f:
f.write("root:x:0:root\nuser:x:10000:\n")
with open(os.path.join(sysroot, "etc", "shadow"), "w", encoding="utf-8") as f:
f.write("root:*:::::::\nuser:*:::::::\n")
fw_dir = os.path.join(tmp, "fw")
os.makedirs(fw_dir, exist_ok=True)
expected_blobs = {
"WIFI_RAM_CODE_6797": b"WIFI_FW_HDR" * 100,
"WMT_SOC.cfg": b"cfg=1\n",
"ROMv3_patch_1_0_hdr.bin": b"ROM10",
"pcm_suspend.bin": b"PCM_SUSPEND",
}
for name, data in expected_blobs.items():
with open(os.path.join(fw_dir, name), "wb") as bf:
bf.write(data)
with open(os.path.join(fw_dir, "ignored.txt"), "w", encoding="utf-8") as uf:
uf.write("ignore-me\n")
img_dir = os.path.join(tmp, "images")
os.makedirs(img_dir, exist_ok=True)
orig_img = os.path.join(img_dir, "geminux-rootfs.img")
out_img = os.path.join(tmp, "out-rootfs.img")
subprocess.run(
["mke2fs", "-t", "ext4", "-F", "-q", "-d", sysroot, orig_img, "8M"],
check=True,
)
orig_sha = flash_mtk.sha256_file(orig_img)
res = subprocess.run(
[
os.path.join(BASE_DIR, "flash-mtk.sh"),
"--customize-rootfs", out_img,
"--images-dir", img_dir,
"--firmware-dir", fw_dir,
"--use-default-credentials",
],
capture_output=True, text=True, check=False,
)
assert res.returncode == 0, f"customize-rootfs fw inject failed: {res.stdout}\n{res.stderr}"
assert flash_mtk.sha256_file(orig_img) == orig_sha, "Source rootfs image was mutated!"
e2 = subprocess.run(["e2fsck", "-fn", out_img], capture_output=True, text=True)
assert e2.returncode == 0, f"e2fsck failed after fw inject: {e2.stdout}\n{e2.stderr}"
ls_entries = fw_mod.debugfs_ls(out_img, "lib/firmware/mediatek/mt6797")
assert set(ls_entries) == set(expected_blobs.keys()), ls_entries
for name, expected in expected_blobs.items():
dump_p = os.path.join(tmp, f"dump-{name}")
assert fw_mod.debugfs_dump(out_img, f"lib/firmware/mediatek/mt6797/{name}", dump_p)
with open(dump_p, "rb") as df:
assert df.read() == expected
st = subprocess.run(
["debugfs", "-R", f"stat /lib/firmware/mediatek/mt6797/{name}", out_img],
capture_output=True, text=True, check=True,
)
assert re.search(r"Mode:\s*0644\b", st.stdout), st.stdout
# Verify --skip-firmware-inject skips injection
out_skip = os.path.join(tmp, "out-skip.img")
res_skip = subprocess.run(
[
os.path.join(BASE_DIR, "flash-mtk.sh"),
"--customize-rootfs", out_skip,
"--images-dir", img_dir,
"--firmware-dir", fw_dir,
"--skip-firmware-inject",
"--use-default-credentials",
],
capture_output=True, text=True, check=False,
)
assert res_skip.returncode == 0, res_skip.stderr
assert fw_mod.debugfs_ls(out_skip, "lib/firmware/mediatek/mt6797") == []
print("[PASS] Offline MT6797 firmware ext4 injection verified")
def test_release_zip_packager():
import zipfile
if not all(shutil.which(cmd) for cmd in ("mke2fs", "debugfs", "e2fsck")):
print("[SKIP] mke2fs/debugfs/e2fsck not available for release ZIP packager test")
return
pkg_mod = _load_mod(
"package_release_zip", os.path.join(SCRIPTS_DIR, "package-release-zip.py")
)
with tempfile.TemporaryDirectory(prefix="geminux-zip-test-") as tmp:
sysroot = os.path.join(tmp, "sysroot")
os.makedirs(os.path.join(sysroot, "etc", "ssh"), exist_ok=True)
os.makedirs(os.path.join(sysroot, "root", ".ssh"), exist_ok=True)
os.makedirs(os.path.join(sysroot, "home", "user", ".ssh"), exist_ok=True)
os.makedirs(os.path.join(sysroot, "lib", "firmware", "mediatek", "mt6797"), exist_ok=True)
with open(os.path.join(sysroot, "etc", "passwd"), "w", encoding="utf-8") as f:
f.write("root:x:0:0:root:/root:/bin/bash\nuser:x:10000:10000::/home/user:/bin/bash\n")
with open(os.path.join(sysroot, "etc", "ssh", "sshd_config"), "w", encoding="utf-8") as f:
f.write("Port 22\n")
with open(os.path.join(sysroot, "etc", "ssh", "ssh_host_ed25519_key"), "w", encoding="utf-8") as f:
f.write("PRIVATE HOST KEY\n")
with open(os.path.join(sysroot, "etc", "ssh", "ssh_host_ed25519_key.pub"), "w", encoding="utf-8") as f:
f.write("ssh-ed25519 AAAAC3...\n")
with open(os.path.join(sysroot, "root", ".ssh", "authorized_keys"), "w", encoding="utf-8") as f:
f.write("ssh-ed25519 AAAA_USER_KEY\n")
with open(os.path.join(sysroot, "home", "user", ".ssh", "authorized_keys"), "w", encoding="utf-8") as f:
f.write("ssh-ed25519 AAAA_USER_KEY\n")
with open(os.path.join(sysroot, "lib", "firmware", "mediatek", "mt6797", "WIFI_RAM_CODE_6797"), "wb") as f:
f.write(b"PROPRIETARY_WIFI_BLOB")
with open(os.path.join(sysroot, "lib", "firmware", "mediatek", "mt6797", "MANIFEST.sha256"), "w", encoding="utf-8") as f:
f.write("abc WIFI_RAM_CODE_6797\n")
img_dir = os.path.join(tmp, "images")
os.makedirs(img_dir, exist_ok=True)
with open(os.path.join(img_dir, "boot-geminux.img"), "wb") as f:
f.write(b"ANDROID!" + b"\x00" * 4088)
with open(os.path.join(img_dir, "recovery-geminux.img"), "wb") as f:
f.write(b"ANDROID!" + b"\x11" * 4088)
root_img = os.path.join(img_dir, "geminux-rootfs.img")
subprocess.run(
["mke2fs", "-t", "ext4", "-F", "-q", "-d", sysroot, root_img, "8M"],
check=True,
)
orig_root_sha = flash_mtk.sha256_file(root_img)
out_zip = os.path.join(tmp, "geminux-0.1.0-helio-gemini-x27.zip")
res = subprocess.run(
[
os.path.join(BASE_DIR, "package-image.sh"),
"--images-dir", img_dir,
"--output", out_zip,
"--version", "0.1.0",
"--codename", "helio",
],
capture_output=True, text=True, check=False,
)
assert res.returncode == 0, f"package-image.sh failed:\n{res.stdout}\n{res.stderr}"
assert flash_mtk.sha256_file(root_img) == orig_root_sha, "Source rootfs image was mutated!"
assert os.path.isfile(out_zip) and os.path.isfile(out_zip + ".sha256")
top = "geminux-0.1.0-helio-gemini-x27"
with zipfile.ZipFile(out_zip, "r") as zf:
assert zf.testzip() is None
names = set(zf.namelist())
for req in (
f"{top}/FLASH-INSTRUCTIONS.txt",
f"{top}/SHA256SUMS.txt",
f"{top}/flash-mtk.sh",
f"{top}/flash-mtk.py",
f"{top}/images/boot-geminux.img",
f"{top}/images/recovery-geminux.img",
f"{top}/images/geminux-rootfs.img",
f"{top}/scripts/bootstrap-flash-deps.sh",
f"{top}/scripts/extract-vendor-fw.py",
f"{top}/scripts/geminux_accounts.py",
f"{top}/scripts/geminux_gpt.py",
f"{top}/scripts/geminux_luks.py",
f"{top}/vendor/mtkclient/mtkclient/Loader/MTK_DA_V5_MT6797.bin",
):
assert req in names, f"ZIP missing {req}"
assert not any("__pycache__" in n or n.endswith((".pyc", ".pyo")) for n in names), "Found bytecode in ZIP"
sh_info = zf.getinfo(f"{top}/flash-mtk.sh")
assert ((sh_info.external_attr >> 16) & 0o111) == 0o111, "flash-mtk.sh missing +x attr"
txt = zf.read(f"{top}/FLASH-INSTRUCTIONS.txt").decode("utf-8")
for needle in ("./flash-mtk.sh --flash-full", "sha256sum -c SHA256SUMS.txt", "LEFT USB-C port", "Docker is NOT required"):
assert needle in txt, f"FLASH-INSTRUCTIONS.txt missing {needle!r}"
# Extract with unzip to verify preserved executable bits, SHA256SUMS, and flasher launch
ext_dir = os.path.join(tmp, "extracted")
os.makedirs(ext_dir, exist_ok=True)
subprocess.run(["unzip", "-q", out_zip, "-d", ext_dir], check=True)
rel_dir = os.path.join(ext_dir, top)
subprocess.run(["sha256sum", "-c", "SHA256SUMS.txt"], cwd=rel_dir, check=True, stdout=subprocess.DEVNULL)
ext_env = dict(os.environ)
if os.path.isdir(FLASH_DEPS):
ext_env["PYTHONPATH"] = FLASH_DEPS
hres = subprocess.run(
["./flash-mtk.sh", "--help"],
cwd=rel_dir, env=ext_env, capture_output=True, text=True, check=False,
)
assert hres.returncode == 0, f"Extracted flash-mtk.sh --help failed:\n{hres.stdout}\n{hres.stderr}"
sanitized_img = os.path.join(rel_dir, "images", "geminux-rootfs.img")
assert subprocess.run(["e2fsck", "-fn", sanitized_img], capture_output=True).returncode == 0
fw_mod = flash_mtk.load_firmware_module()
assert fw_mod.debugfs_ls(sanitized_img, "lib/firmware/mediatek/mt6797") == []
assert [n for n, _m in pkg_mod._debugfs_ls_details(sanitized_img, "etc/ssh") if n.startswith("ssh_host_")] == []
assert "sshd_config" in fw_mod.debugfs_ls(sanitized_img, "etc/ssh")
assert not fw_mod._debugfs_path_exists(sanitized_img, "/root/.ssh/authorized_keys")
assert not fw_mod._debugfs_path_exists(sanitized_img, "/home/user/.ssh/authorized_keys")
print("[PASS] Release ZIP packager (sanitized rootfs, FLASH-INSTRUCTIONS.txt, SHA256SUMS, runnable flasher) verified")
def test_cli_help():
res = subprocess.run(
[os.path.join(BASE_DIR, "flash-mtk.sh"), "--help"],
@@ -744,6 +948,7 @@ def test_cli_help():
"--flash-full",
"--flash-rootfs-only",
"--customize-rootfs",
"--skip-firmware-inject",
"--username",
"--user-password",
"--ask-user-password",
@@ -773,6 +978,8 @@ def main():
test_sha512_crypt_and_username_validation()
test_account_customization_ext4()
test_luks2_encryption_offline()
test_firmware_injection_ext4()
test_release_zip_packager()
test_cli_help()