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

+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""Rewrite the cmdline field of an Android v0 boot.img header.
Only the 512-byte cmdline field changes; kernel, ramdisk, DTB and load
addresses stay byte-identical, so the image still fits its partition.
"""
import argparse
import os
import struct
import sys
BOOT_MAGIC = b"ANDROID!"
CMDLINE_OFFSET = 64
CMDLINE_SIZE = 512
def main():
parser = argparse.ArgumentParser()
parser.add_argument("src")
parser.add_argument("dst")
parser.add_argument("--cmdline", required=True)
args = parser.parse_args()
data = bytearray(open(args.src, "rb").read())
if len(data) < CMDLINE_OFFSET + CMDLINE_SIZE or data[:8] != BOOT_MAGIC:
print("FAIL: not an Android boot image")
return 1
raw = args.cmdline.encode("utf-8")
if len(raw) >= CMDLINE_SIZE:
print("FAIL: cmdline is too long (%d >= %d)" % (len(raw), CMDLINE_SIZE))
return 1
old = bytes(data[CMDLINE_OFFSET:CMDLINE_OFFSET + CMDLINE_SIZE]).rstrip(b"\0")
data[CMDLINE_OFFSET:CMDLINE_OFFSET + CMDLINE_SIZE] = (
raw + b"\0" * (CMDLINE_SIZE - len(raw)))
with open(args.dst, "wb") as handle:
handle.write(data)
fields = struct.unpack_from("<8s8I", data)
print("old cmdline: %r" % old.decode("utf-8", "replace"))
print("new cmdline: %r" % args.cmdline)
print("kernel=%d ramdisk=%d page=%d -> %s (%d bytes)" %
(fields[1], fields[3], fields[8], args.dst, len(data)))
return 0
if __name__ == "__main__":
sys.exit(main())