package-image: default to maximum ZIP deflate compression level 9

This commit is contained in:
Luxferre committed 2026-11-28 12:39:02 +02:00
1 parent 2c3278024e
commit a015ef64ef
2 files changed
+26 -3

No files matched your search

+13 -3
View File
@@ -350,6 +350,14 @@ Step C - Full Geminux installation:
""" """
def _set_zipinfo_compress_level(zinfo, compress_level):
level = None if compress_level == 0 else compress_level
if hasattr(zinfo, "compress_level"):
zinfo.compress_level = level
elif hasattr(zinfo, "_compresslevel"):
zinfo._compresslevel = level
def _write_zip_entry(zf, src_path, arcname, is_exec, compress_level): def _write_zip_entry(zf, src_path, arcname, is_exec, compress_level):
st = os.stat(src_path) st = os.stat(src_path)
dt = time.localtime(st.st_mtime)[:6] dt = time.localtime(st.st_mtime)[:6]
@@ -357,6 +365,7 @@ def _write_zip_entry(zf, src_path, arcname, is_exec, compress_level):
dt = (1980, 1, 1, 0, 0, 0) dt = (1980, 1, 1, 0, 0, 0)
zinfo = zipfile.ZipInfo(arcname, date_time=dt) zinfo = zipfile.ZipInfo(arcname, date_time=dt)
zinfo.compress_type = zipfile.ZIP_STORED if compress_level == 0 else zipfile.ZIP_DEFLATED zinfo.compress_type = zipfile.ZIP_STORED if compress_level == 0 else zipfile.ZIP_DEFLATED
_set_zipinfo_compress_level(zinfo, compress_level)
zinfo.create_system = 3 zinfo.create_system = 3
mode = stat.S_IFREG | (0o755 if is_exec else 0o644) mode = stat.S_IFREG | (0o755 if is_exec else 0o644)
zinfo.external_attr = (mode & 0xFFFF) << 16 zinfo.external_attr = (mode & 0xFFFF) << 16
@@ -370,6 +379,7 @@ def _write_zip_bytes(zf, raw_bytes, arcname, is_exec, compress_level):
dt = time.gmtime()[:6] dt = time.gmtime()[:6]
zinfo = zipfile.ZipInfo(arcname, date_time=dt) zinfo = zipfile.ZipInfo(arcname, date_time=dt)
zinfo.compress_type = zipfile.ZIP_STORED if compress_level == 0 else zipfile.ZIP_DEFLATED zinfo.compress_type = zipfile.ZIP_STORED if compress_level == 0 else zipfile.ZIP_DEFLATED
_set_zipinfo_compress_level(zinfo, compress_level)
zinfo.create_system = 3 zinfo.create_system = 3
mode = stat.S_IFREG | (0o755 if is_exec else 0o644) mode = stat.S_IFREG | (0o755 if is_exec else 0o644)
zinfo.external_attr = (mode & 0xFFFF) << 16 zinfo.external_attr = (mode & 0xFFFF) << 16
@@ -404,7 +414,7 @@ def package_release_zip(
codename=None, codename=None,
include_firmware=True, include_firmware=True,
keep_ssh_keys=False, keep_ssh_keys=False,
compress_level=6, compress_level=9,
verify=True, verify=True,
): ):
"""Create a redistributable Geminux release ZIP archive with TXT flashing guide.""" """Create a redistributable Geminux release ZIP archive with TXT flashing guide."""
@@ -527,8 +537,8 @@ def build_arg_parser():
help="Strip /lib/firmware/mediatek/mt6797 blobs for clean redistribution") help="Strip /lib/firmware/mediatek/mt6797 blobs for clean redistribution")
p.add_argument("--keep-ssh-keys", action="store_true", p.add_argument("--keep-ssh-keys", action="store_true",
help="Keep SSH authorized_keys and ssh_host_* keys in packaged rootfs") help="Keep SSH authorized_keys and ssh_host_* keys in packaged rootfs")
p.add_argument("--compress-level", type=int, default=6, choices=range(0, 10), metavar="0..9", p.add_argument("--compress-level", type=int, default=9, choices=range(0, 10), metavar="0..9",
help="ZIP deflate compression level (default: 6)") help="ZIP deflate compression level (default: 9)")
p.add_argument("--no-verify", action="store_true", help="Skip ZIP CRC verification pass") p.add_argument("--no-verify", action="store_true", help="Skip ZIP CRC verification pass")
return p return p
+13
View File
@@ -822,6 +822,7 @@ def test_firmware_injection_ext4():
def test_release_zip_packager(): def test_release_zip_packager():
import datetime import datetime
import zipfile import zipfile
import zlib
if not all(shutil.which(cmd) for cmd in ("mke2fs", "debugfs", "e2fsck")): if not all(shutil.which(cmd) for cmd in ("mke2fs", "debugfs", "e2fsck")):
print("[SKIP] mke2fs/debugfs/e2fsck not available for release ZIP packager test") print("[SKIP] mke2fs/debugfs/e2fsck not available for release ZIP packager test")
@@ -830,6 +831,7 @@ def test_release_zip_packager():
pkg_mod = _load_mod( pkg_mod = _load_mod(
"package_release_zip", os.path.join(SCRIPTS_DIR, "package-release-zip.py") "package_release_zip", os.path.join(SCRIPTS_DIR, "package-release-zip.py")
) )
assert pkg_mod.build_arg_parser().parse_args([]).compress_level == 9
git_res = subprocess.run( git_res = subprocess.run(
["git", "-C", BASE_DIR, "log", "-1", "--format=%ct %h"], ["git", "-C", BASE_DIR, "log", "-1", "--format=%ct %h"],
capture_output=True, text=True, check=True, capture_output=True, text=True, check=True,
@@ -913,6 +915,7 @@ def test_release_zip_packager():
env=pkg_env, capture_output=True, text=True, check=False, env=pkg_env, capture_output=True, text=True, check=False,
) )
assert res.returncode == 0, f"package-image.sh failed:\n{res.stdout}\n{res.stderr}" assert res.returncode == 0, f"package-image.sh failed:\n{res.stdout}\n{res.stderr}"
assert "(deflate level 9)" in res.stdout, res.stdout
assert "stripped 4 SSH key file(s); firmware kept; e2fsck clean" in res.stdout, res.stdout assert "stripped 4 SSH key file(s); firmware kept; e2fsck clean" in res.stdout, res.stdout
assert "firmware/key" not in res.stdout, res.stdout assert "firmware/key" not in res.stdout, res.stdout
assert flash_mtk.sha256_file(root_img) == orig_root_sha, "Source rootfs image was mutated!" assert flash_mtk.sha256_file(root_img) == orig_root_sha, "Source rootfs image was mutated!"
@@ -940,6 +943,16 @@ def test_release_zip_packager():
assert not any("__pycache__" in n or n.endswith((".pyc", ".pyo")) for n in names), "Found bytecode in ZIP" 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") sh_info = zf.getinfo(f"{top}/flash-mtk.sh")
assert ((sh_info.external_attr >> 16) & 0o111) == 0o111, "flash-mtk.sh missing +x attr" assert ((sh_info.external_attr >> 16) & 0o111) == 0o111, "flash-mtk.sh missing +x attr"
with open(os.path.join(BASE_DIR, "flash-mtk.py"), "rb") as f:
flash_py_bytes = f.read()
c9 = zlib.compressobj(9, zlib.DEFLATED, -15)
len9 = len(c9.compress(flash_py_bytes) + c9.flush())
c6 = zlib.compressobj(6, zlib.DEFLATED, -15)
len6 = len(c6.compress(flash_py_bytes) + c6.flush())
actual_cs = zf.getinfo(f"{top}/flash-mtk.py").compress_size
assert actual_cs == len9, f"Expected deflate level 9 size {len9}, got {actual_cs} (level 6={len6})"
if len6 != len9:
assert actual_cs != len6
txt = zf.read(f"{top}/FLASH-INSTRUCTIONS.txt").decode("utf-8") txt = zf.read(f"{top}/FLASH-INSTRUCTIONS.txt").decode("utf-8")
for needle in ( for needle in (
f"Release: {expected_ver} (helio)", f"Release: {expected_ver} (helio)",