Skip to content

Commit

Permalink
add SOURCE_COPY and SOURCE_BSDIFF types
Browse files Browse the repository at this point in the history
  • Loading branch information
vm03 committed Aug 20, 2019
1 parent 3453cbc commit f2b247e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions payload_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import bz2
import sys
import argparse
import bsdiff4
import io

try:
import lzma
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
protobuf==3.6.0
six==1.11.0
bsdiff4>=1.1.5

0 comments on commit f2b247e

Please sign in to comment.