From f2b247e7889f0b7a7ce5f50421c016ab7c34e062 Mon Sep 17 00:00:00 2001 From: vm03 Date: Tue, 20 Aug 2019 14:20:16 +0300 Subject: [PATCH] add SOURCE_COPY and SOURCE_BSDIFF types --- payload_dumper.py | 34 ++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 2 files changed, 35 insertions(+) diff --git a/payload_dumper.py b/payload_dumper.py index f2b0a8d..880a1c1 100644 --- a/payload_dumper.py +++ b/payload_dumper.py @@ -4,6 +4,8 @@ import bz2 import sys import argparse +import bsdiff4 +import io try: import lzma @@ -50,6 +52,38 @@ def data_for_op(op,out_file,old_file): elif op.type == op.REPLACE: out_file.seek(op.dst_extents[0].start_block*block_size) out_file.write(data) + elif op.type == op.SOURCE_COPY: + if not args.diff: + print ("SOURCE_COPY supported only for differential OTA") + sys.exit(-2) + out_file.seek(op.dst_extents[0].start_block*block_size) + for ext in op.src_extents: + old_file.seek(ext.start_block*block_size) + data = old_file.read(ext.num_blocks*block_size) + out_file.write(data) + elif op.type == op.SOURCE_BSDIFF: + if not args.diff: + print ("SOURCE_BSDIFF supported only for differential OTA") + sys.exit(-3) + out_file.seek(op.dst_extents[0].start_block*block_size) + tmp_buff = io.BytesIO() + for ext in op.src_extents: + old_file.seek(ext.start_block*block_size) + old_data = old_file.read(ext.num_blocks*block_size) + tmp_buff.write(old_data) + tmp_buff.seek(0) + old_data = tmp_buff.read() + data = bsdiff4.patch(old_data, data) + tmp_buff.seek(0) + tmp_buff.write(data) + n = 0; + tmp_buff.seek(0) + for ext in op.dst_extents: + tmp_buff.seek(n*block_size) + n += ext.num_blocks + data = tmp_buff.read(ext.num_blocks*block_size) + out_file.seek(ext.start_block*block_size) + out_file.write(data) else: print ("Unsupported type = %d" % op.type) sys.exit(-1) diff --git a/requirements.txt b/requirements.txt index f6704b4..dad42c0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ protobuf==3.6.0 six==1.11.0 +bsdiff4>=1.1.5