-
Notifications
You must be signed in to change notification settings - Fork 75
modifying a cerbo swu file
jhofstee edited this page Dec 11, 2020
·
2 revisions
mkdir tmp rootfs rootfs.user
(cd tmp && cpio -idv < ../venus-swu-einstein.swu)
gunzip tmp/venus-image-einstein.ext4.gz
e2fsck -f tmp/venus-image-einstein.ext4
resize2fs tmp/venus-image-einstein.ext4 1G
sudo mount tmp/venus-image-einstein.ext4 rootfs
sudo bindfs -u $(id -u) -g $(id -g) rootfs rootfs.user
Do what you want with rootfs.user...
sudo umount rootfs.user rootfs
pigz tmp/venus-image-einstein.ext4
(cd tmp && find -type f | sort | cpio -ov -H crc > ../venus-swu-einstein.swu)
rm -rf tmp rootfs rootfs.user
./fix-swu.py venus-swu-einstein.swu
fix-swu.py
#!/usr/bin/python3
import sys
# cpio seems to add zero padding to the swu file up to the block size. swupdate
# expects it to padding till it is 4 bytes aligned again. These trailing zeros
# can crash swupdate by causing a SIGPIPE. So make sure only the trailing zeros
# as expected by swupdate are in the swu file.
def swupdate_fix_cpio_padding(filename):
file = open(filename, "r+b")
file.seek(0, 2)
addr = file.tell() - 1
while addr:
file.seek(addr, 0)
if ord(file.read(1)) != 0:
addr += 1
addr += 4 - (addr % 4)
print("truncating " + filename + " to " + str(addr))
file.truncate(addr)
break
addr -= 1
if __name__ == "__main__":
swupdate_fix_cpio_padding(sys.argv[1])