paycheck: Properly infer usable target partition size.
The payload checker used to restrict read/write block indexes to the
reported target filesystem size, unless explicitly given a partition
size value to use instead. So far this value was easy for clients (like
paygen) to come up with, because it was constant at 2GB for all known
boards. However this is no longer the case, and there is no an easy way
for clients to know the actual target partition size after the payload
has been generated (nor is it encoded in the payload). This adds logic
for inferring the usable target partition size into PayloadChecker()
itself, as follows:
1) If a partition size was given, use that.
2) Else, if this is an old delta (minor version < 2), use the
aforementioned default. This is necessary because older deltas may
actually read/write data beyond the filesystem size. It is also
sufficient because any old delta payload we generate should write to
a 2GB target partition.
3) In all other cases, just use the new filesystem size, as encoded in
the payload. This is a safe choice for full updates and newer deltas.
The command-line tool is updated accordingly. Note that the usable
kernel partition size inference remains unaffected.
BUG=chromium:508566
TEST=Unit tests (revised)
Change-Id: I987f28fdfe1d82d0f6f565ae9852b7b11bce13e8
Reviewed-on: https://chromium-review.googlesource.com/285447
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/scripts/update_payload/checker_unittest.py b/scripts/update_payload/checker_unittest.py
index 871f252..a22373f 100755
--- a/scripts/update_payload/checker_unittest.py
+++ b/scripts/update_payload/checker_unittest.py
@@ -1085,8 +1085,11 @@
self.assertRaises(update_payload.PayloadError,
payload_checker._CheckManifestMinorVersion, *args)
- def DoRunTest(self, fail_wrong_payload_type, fail_invalid_block_size,
- fail_mismatched_block_size, fail_excess_data):
+ def DoRunTest(self, rootfs_part_size_provided, kernel_part_size_provided,
+ fail_wrong_payload_type, fail_invalid_block_size,
+ fail_mismatched_block_size, fail_excess_data,
+ fail_rootfs_part_size_exceeded,
+ fail_kernel_part_size_exceeded):
# Generate a test payload. For this test, we generate a full update that
# has sample kernel and rootfs operations. Since most testing is done with
# internal PayloadChecker methods that are tested elsewhere, here we only
@@ -1096,21 +1099,35 @@
payload_gen = test_utils.EnhancedPayloadGenerator()
block_size = test_utils.KiB(4)
payload_gen.SetBlockSize(block_size)
- kernel_part_size = test_utils.KiB(16)
- rootfs_part_size = test_utils.MiB(2)
- payload_gen.SetPartInfo(False, True, rootfs_part_size,
+ kernel_filesystem_size = test_utils.KiB(16)
+ rootfs_filesystem_size = test_utils.MiB(2)
+ payload_gen.SetPartInfo(False, True, rootfs_filesystem_size,
hashlib.sha256('fake-new-rootfs-content').digest())
- payload_gen.SetPartInfo(True, True, kernel_part_size,
+ payload_gen.SetPartInfo(True, True, kernel_filesystem_size,
hashlib.sha256('fake-new-kernel-content').digest())
payload_gen.SetMinorVersion(0)
+
+ rootfs_part_size = 0
+ if rootfs_part_size_provided:
+ rootfs_part_size = rootfs_filesystem_size + block_size
+ rootfs_op_size = rootfs_part_size or rootfs_filesystem_size
+ if fail_rootfs_part_size_exceeded:
+ rootfs_op_size += block_size
payload_gen.AddOperationWithData(
False, common.OpType.REPLACE,
- dst_extents=[(0, rootfs_part_size / block_size)],
- data_blob=os.urandom(rootfs_part_size))
+ dst_extents=[(0, rootfs_op_size / block_size)],
+ data_blob=os.urandom(rootfs_op_size))
+
+ kernel_part_size = 0
+ if kernel_part_size_provided:
+ kernel_part_size = kernel_filesystem_size + block_size
+ kernel_op_size = kernel_part_size or kernel_filesystem_size
+ if fail_kernel_part_size_exceeded:
+ kernel_op_size += block_size
payload_gen.AddOperationWithData(
True, common.OpType.REPLACE,
- dst_extents=[(0, kernel_part_size / block_size)],
- data_blob=os.urandom(kernel_part_size))
+ dst_extents=[(0, kernel_op_size / block_size)],
+ data_blob=os.urandom(kernel_op_size))
# Generate payload (complete w/ signature) and create the test object.
if fail_invalid_block_size:
@@ -1135,9 +1152,14 @@
else:
payload_checker = _GetPayloadChecker(payload_gen.WriteToFileWithData,
**kwargs)
- kwargs = {'pubkey_file_name': test_utils._PUBKEY_FILE_NAME}
+
+ kwargs = {'pubkey_file_name': test_utils._PUBKEY_FILE_NAME,
+ 'rootfs_part_size': rootfs_part_size,
+ 'kernel_part_size': kernel_part_size}
should_fail = (fail_wrong_payload_type or fail_mismatched_block_size or
- fail_excess_data)
+ fail_excess_data or
+ fail_rootfs_part_size_exceeded or
+ fail_kernel_part_size_exceeded)
if should_fail:
self.assertRaises(update_payload.PayloadError, payload_checker.Run,
**kwargs)
@@ -1283,10 +1305,14 @@
# Add all Run() test cases.
AddParametricTests('Run',
- {'fail_wrong_payload_type': (True, False),
+ {'rootfs_part_size_provided': (True, False),
+ 'kernel_part_size_provided': (True, False),
+ 'fail_wrong_payload_type': (True, False),
'fail_invalid_block_size': (True, False),
'fail_mismatched_block_size': (True, False),
- 'fail_excess_data': (True, False)})
+ 'fail_excess_data': (True, False),
+ 'fail_rootfs_part_size_exceeded': (True, False),
+ 'fail_kernel_part_size_exceeded': (True, False)})
if __name__ == '__main__':