Skip to content

Commit

Permalink
Add support for delta OTA
Browse files Browse the repository at this point in the history
 Put images to "old" dir for apply delta OTA
  • Loading branch information
vm03 committed Apr 28, 2020
1 parent 4632cf0 commit 277a5df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def list_content(payload_file_name):
part.new_partition_info.size))


def extract(payload_file_name, output_dir="output", partition_names=None):
def extract(payload_file_name, output_dir="output", old_dir="old", partition_names=None):
try:
os.makedirs(output_dir)
except OSError as e:
Expand All @@ -29,28 +29,32 @@ def extract(payload_file_name, output_dir="output", partition_names=None):
payload = update_payload.Payload(payload_file)
payload.Init()

if payload.IsDelta():
print("Delta payloads are not supported")
exit(1)

helper = applier.PayloadApplier(payload)
for part in payload.manifest.partitions:
if partition_names and part.partition_name not in partition_names:
continue
print("Extracting {}".format(part.partition_name))
output_file = os.path.join(output_dir, part.partition_name)
helper._ApplyToPartition(
part.operations, part.partition_name,
'install_operations', output_file,
part.new_partition_info)

if payload.IsDelta():
old_file = os.path.join(old_dir, part.partition_name)
helper._ApplyToPartition(
part.operations, part.partition_name,
'install_operations', output_file,
part.new_partition_info, old_file, part.old_partition_info)
else:
helper._ApplyToPartition(
part.operations, part.partition_name,
'install_operations', output_file,
part.new_partition_info)

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("payload", metavar="payload.bin",
help="Path to the payload.bin")
parser.add_argument("--output_dir", default="output",
help="Output directory")
parser.add_argument("--old_dir", default="old",
help="Old directory")
parser.add_argument("--partitions", type=str, nargs='+',
help="Name of the partitions to extract")
parser.add_argument("--list_partitions", action="store_true",
Expand All @@ -60,4 +64,4 @@ def extract(payload_file_name, output_dir="output", partition_names=None):
if args.list_partitions:
list_content(args.payload)
else:
extract(args.payload, args.output_dir, args.partitions)
extract(args.payload, args.output_dir, args.old_dir, args.partitions)
4 changes: 2 additions & 2 deletions update_payload/applier.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ def _ApplyDiffOperation(self, op, op_name, patch_data, old_part_file,
data_length=op.dst_length if op.dst_length else
self._BytesInExtents(op.dst_extents, "%s.dst_extents"))

new_file_name = '/dev/fd/%d' % new_part_file.fileno()
new_file_name = new_part_file.name
# Diff from source partition.
old_file_name = '/dev/fd/%d' % old_part_file.fileno()
old_file_name = old_part_file.name

if op.type in (common.OpType.BSDIFF, common.OpType.SOURCE_BSDIFF,
common.OpType.BROTLI_BSDIFF):
Expand Down

1 comment on commit 277a5df

@turb1te
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @vm03! :)

D:\Downloads\2>python extract.py payload.bin --partitions boot --output_dir output --old_dir old
Extracting boot
Traceback (most recent call last):
  File "extract.py", line 67, in <module>
    extract(args.payload, args.output_dir, args.old_dir, args.partitions)
  File "extract.py", line 43, in extract
    part.new_partition_info, old_file, part.old_partition_info)
  File "D:\Downloads\2\update_payload\applier.py", line 582, in _ApplyToPartition
    with open(old_part_file_name, 'rb') as old_part_file:
IOError: [Errno 2] No such file or directory: u'old\\boot'

I think that the file extension is missing.

        if payload.IsDelta():
            old_file    = os.path.join(old_dir,    part.partition_name)

I change it to this:

        if payload.IsDelta():
            old_file    = os.path.join(old_dir, part.partition_name + "." + "img")

But I have another error after this change:
vm03/payload_dumper#10 (comment)

Please sign in to comment.