Sanitized research log, build/reproducibility docs, DTS, kernel configs, patches, initramfs sources, bootchain migration plans and test logs. B5 direct boot PASS; B6 modem lifecycle in progress. No dumps, NV/EFS, vendor firmware or device identifiers included.
27 lines
1.9 KiB
Python
27 lines
1.9 KiB
Python
import struct, zlib, uuid
|
|
P = open("../gpt/gpt-primary-34sectors.bin", "rb").read() # LBA 0..33
|
|
B = open("../gpt/gpt-backup-33sectors.bin", "rb").read() # entries (32 sectors) + header (last LBA)
|
|
def entries_of(buf, off, n, esz): return bytearray(buf[off: off + n*esz])
|
|
hdrP = bytearray(P[512:1024]); ent_lba, n, esz = struct.unpack("<QII", hdrP[72:88])
|
|
ents = entries_of(P, ent_lba*512, n, esz)
|
|
assert bytes(ents) == B[:n*esz], "primary/backup entry arrays differ"
|
|
def name(i): return ents[i*esz+56:i*esz+128].decode("utf-16le").rstrip("\0")
|
|
idx = {name(i): i for i in range(n) if ents[i*esz:i*esz+16] != b"\0"*16}
|
|
def setlba(i, first, last): ents[i*esz+32:i*esz+48] = struct.pack("<QQ", first, last)
|
|
def getlba(i): return struct.unpack("<QQ", ents[i*esz+32:i*esz+48])
|
|
tz, tzb = idx["tz"], idx["tzbak"]
|
|
assert getlba(tz) == (270336, 271359) and getlba(tzb) == (271360, 272383)
|
|
setlba(tz, 270336, 272383)
|
|
setlba(tzb, 305184, 306207)
|
|
ecrc = zlib.crc32(bytes(ents)) & 0xffffffff
|
|
def fix(h):
|
|
h = bytearray(h); h[88:92] = struct.pack("<I", ecrc); h[16:20] = b"\0"*4
|
|
hs = struct.unpack("<I", h[12:16])[0]; h[16:20] = struct.pack("<I", zlib.crc32(bytes(h[:hs])) & 0xffffffff); return h
|
|
newP = bytearray(P); newP[512:1024] = fix(hdrP); newP[ent_lba*512: ent_lba*512+n*esz] = ents
|
|
hdrB = B[32*512:33*512]; newB = bytearray(B); newB[:n*esz] = ents; newB[32*512:33*512] = fix(hdrB)
|
|
open("aurora-new-gpt-primary-34sectors.bin", "wb").write(newP); open("aurora-new-gpt-backup-33sectors.bin", "wb").write(newB)
|
|
# diff report
|
|
for i in range(n):
|
|
a = P[ent_lba*512+i*esz: ent_lba*512+(i+1)*esz]; b = bytes(ents[i*esz:(i+1)*esz])
|
|
if a != b: print("changed entry %2d %-8s %s -> %s" % (i, name(i), struct.unpack("<QQ", a[32:48]), struct.unpack("<QQ", b[32:48])))
|
|
nd = sum(1 for x, y in zip(P, newP) if x != y); print("primary bytes changed:", nd, " backup bytes changed:", sum(1 for x, y in zip(B, newB) if x != y))
|