mkimage: --user content fill (keeps GPT)
This commit is contained in:
+22
-2
@@ -70,12 +70,19 @@ def gpt_header(nent, lba_backup, disk_guid, crc_entries, cur=1):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
out = sys.argv[1] if len(sys.argv) > 1 else "images/emmc.img"
|
out = sys.argv[-1] if not sys.argv[-1].startswith("-") else "images/emmc.img"
|
||||||
|
user_src = None
|
||||||
|
if "--user" in sys.argv:
|
||||||
|
user_src = sys.argv[sys.argv.index("--user") + 1]
|
||||||
pre = (BOOT_MB * 2 + RPMB_MB) * 1024 * 1024
|
pre = (BOOT_MB * 2 + RPMB_MB) * 1024 * 1024
|
||||||
total = FILE_SIZE
|
total = FILE_SIZE
|
||||||
assert pre + USER_SECTORS * SECTOR <= total
|
assert pre + USER_SECTORS * SECTOR <= total
|
||||||
print(f"[mkimage] {out}: boot {BOOT_MB}M x2 + rpmb {RPMB_MB}M + "
|
print(f"[mkimage] {out}: boot {BOOT_MB}M x2 + rpmb {RPMB_MB}M + "
|
||||||
f"user {USER_SECTORS} sectors")
|
f"user {USER_SECTORS} sectors" +
|
||||||
|
(f" + content {user_src}" if user_src else " (zero)"))
|
||||||
|
with open(out, "wb") as f:
|
||||||
|
f.truncate(total) # sparse
|
||||||
|
uoff = pre
|
||||||
with open(out, "wb") as f:
|
with open(out, "wb") as f:
|
||||||
f.truncate(total) # sparse
|
f.truncate(total) # sparse
|
||||||
uoff = pre
|
uoff = pre
|
||||||
@@ -106,6 +113,19 @@ def main():
|
|||||||
f.seek(uoff + (USER_SECTORS - 1) * SECTOR)
|
f.seek(uoff + (USER_SECTORS - 1) * SECTOR)
|
||||||
f.write(gpt_header(128, 1, disk, crc_e,
|
f.write(gpt_header(128, 1, disk, crc_e,
|
||||||
cur=USER_SECTORS - 1))
|
cur=USER_SECTORS - 1))
|
||||||
|
if user_src:
|
||||||
|
print(f"[mkimage] copying User content (keeps GPT in place)...")
|
||||||
|
with open(user_src, "rb") as u:
|
||||||
|
# copy in 128M chunks, skipping GPT areas (LBA 0..33, backup)
|
||||||
|
u.seek(34 * SECTOR)
|
||||||
|
f.seek(uoff + 34 * SECTOR)
|
||||||
|
left = (USER_SECTORS - 33) * SECTOR - 34 * SECTOR
|
||||||
|
while left > 0:
|
||||||
|
d = u.read(min(left, 134217728))
|
||||||
|
if not d:
|
||||||
|
break
|
||||||
|
f.write(d)
|
||||||
|
left -= len(d)
|
||||||
print(f"[mkimage] OK: {len(PARTS)} partitions, primary+backup GPT, CRC ok")
|
print(f"[mkimage] OK: {len(PARTS)} partitions, primary+backup GPT, CRC ok")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user