update_payload: Add zero operation support
Currenlty the applier.py and checker.py does not support ZERO
operation. This patch adds support for it. In addition, when generating
ZERO operation, we were not clearing the source length and extent
properties out of the protobuf. ZERO operation has no source length or
extent.
BUG=chromium:768461
TEST=unittest pass; scripts/paycheck.py --check payload.delta;
Change-Id: I766deaca4380686797893c2686036d59525546f4
Reviewed-on: https://chromium-review.googlesource.com/713539
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/scripts/update_payload/applier.py b/scripts/update_payload/applier.py
index fa419bd..cc77165 100644
--- a/scripts/update_payload/applier.py
+++ b/scripts/update_payload/applier.py
@@ -301,6 +301,27 @@
_WriteExtents(part_file, in_data, op.dst_extents, block_size,
'%s.dst_extents' % op_name)
+ def _ApplyZeroOperation(self, op, op_name, part_file):
+ """Applies a ZERO operation.
+
+ Args:
+ op: the operation object
+ op_name: name string for error reporting
+ part_file: the partition file object
+
+ Raises:
+ PayloadError if something goes wrong.
+ """
+ block_size = self.block_size
+ base_name = '%s.dst_extents' % op_name
+
+ # Iterate over the extents and write zero.
+ for ex, ex_name in common.ExtentIter(op.dst_extents, base_name):
+ # Only do actual writing if this is not a pseudo-extent.
+ if ex.start_block != common.PSEUDO_EXTENT_MARKER:
+ part_file.seek(ex.start_block * block_size)
+ part_file.write('\0' * (ex.num_blocks * block_size))
+
def _ApplyBsdiffOperation(self, op, op_name, patch_data, new_part_file):
"""Applies a BSDIFF operation.
@@ -463,6 +484,8 @@
self._ApplyReplaceOperation(op, op_name, data, new_part_file, part_size)
elif op.type == common.OpType.MOVE:
self._ApplyMoveOperation(op, op_name, new_part_file)
+ elif op.type == common.OpType.ZERO:
+ self._ApplyZeroOperation(op, op_name, new_part_file)
elif op.type == common.OpType.BSDIFF:
self._ApplyBsdiffOperation(op, op_name, data, new_part_file)
elif op.type == common.OpType.SOURCE_COPY: