From bd82bb4fefead55610d771802bc13036c576b66f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 18 Dec 2016 12:25:35 +0100 Subject: [PATCH] Add utility to build a delta file with a single insert For hijacking build a complete delta for a single insert. Need to externalize the parameters. It could work for multiple files too. --- update-ec20/build_diff.py | 124 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 update-ec20/build_diff.py diff --git a/update-ec20/build_diff.py b/update-ec20/build_diff.py new file mode 100644 index 0000000..c23293f --- /dev/null +++ b/update-ec20/build_diff.py @@ -0,0 +1,124 @@ +#!/usr/bin/python3 +""" +Build a single insert for RedBend OTA filesystem updates +All rights reversed +""" + +from PyCRC import CRC32 +import subprocess +import os +import io +import struct + +permission_bytes = bytes.fromhex('1A 5F 72 65 64 62 65 6E 64 5F 30 34 30 37 35 35 3A 30 30 30 30 3A 30 30 30 30 00 1A 5F 72 65 64 62 65 6E 64 5F 30 34 31 37 37 37 3A 30 30 30 30 3A 30 30 30 30 00 1A 5F 72 65 64 62 65 6E 64 5F 30 34 32 37 35 35 3A 30 30 30 30 3A 30 30 30 30 00 1A 5F 72 65 64 62 65 6E 64 5F 31 30 30 36 34 34 3A 30 30 30 30 3A 30 30 30 30 00 1A 5F 72 65 64 62 65 6E 64 5F 31 30 30 37 35 35 3A 30 30 30 30 3A 30 30 30 30 00 1A 5F 72 65 64 62 65 6E 64 5F 31 30 30 37 37 37 3A 30 30 30 30 3A 30 30 30 30 00 1A 5F 72 65 64 62 65 6E 64 5F 31 30 34 37 35 35 3A 30 30 30 30 3A 30 30 30 30 00 1A 5F 72 65 64 62 65 6E 64 5F 31 32 30 37 37 37 3A 30 30 30 30 3A 30 30 30 30 00') +general_bytes = bytes.fromhex('50 40 01 00 80 38 01 00 00 00 00') +fs_bytes = bytes.fromhex('80 80 02 00 00 ') + +# initialize tables only once +crc32 = CRC32.CRC32() + +def compress(fname): + """I compress a file with LZMA and return the byte array""" + lzma_fname = fname + ".lzma" + print(lzma_fname) + ret = subprocess.call(["lzma", "e", fname, lzma_fname]) + assert ret == 0 + with open(lzma_fname, "rb") as f: + return f.read() + +def build_toc(fname, size, compr_size): + """I build the table of content for a single file and insert""" + wr = io.BytesIO() + # name + NUL + wr.write(fname.encode('utf8')) + wr.write(b'\0') + # permissions + wr.write(permission_bytes) + # FILE_SIZE + D100 0000 (offset to permission) + COMPR_SIZE + off = len(wr.getvalue()) + wr.write(struct.pack('