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/paycheck.py b/scripts/paycheck.py
index 36edc59..5290e9d 100755
--- a/scripts/paycheck.py
+++ b/scripts/paycheck.py
@@ -19,14 +19,6 @@
 import update_payload
 
 
-# The default sizes of partitions, based on current partitioning practice.
-# TODO(garnold)(chromium:243559) we should stop using these values once
-# partition sizes are encoded in newly generated payloads; that said, we should
-# allow users to specify partition sizes on the command-line, so as to be able
-# to check older payloads.
-_DEFAULT_ROOTFS_PART_SIZE = 2 * 1024 * 1024 * 1024
-_DEFAULT_KERNEL_PART_SIZE = 16 * 1024 * 1024
-
 _TYPE_FULL = 'full'
 _TYPE_DELTA = 'delta'
 
@@ -85,13 +77,11 @@
   check_opts.add_option('-m', '--meta-sig', metavar='FILE',
                         help='verify metadata against its signature')
   check_opts.add_option('-p', '--root-part-size', metavar='NUM',
-                        default=_DEFAULT_ROOTFS_PART_SIZE, type='int',
-                        help=('override default (%default) rootfs partition '
-                              'size'))
+                        default=0, type='int',
+                        help=('override rootfs partition size auto-inference'))
   check_opts.add_option('-P', '--kern-part-size', metavar='NUM',
-                        default=_DEFAULT_KERNEL_PART_SIZE, type='int',
-                        help=('override default (%default) kernel partition '
-                              'size'))
+                        default=0, type='int',
+                        help=('override kernel partition size auto-inference'))
   parser.add_option_group(check_opts)
 
   trace_opts = optparse.OptionGroup(parser, 'Applying payload')
@@ -135,8 +125,7 @@
   opts.check = (opts.check or opts.report or opts.assert_type or
                 opts.block_size or opts.allow_unhashed or
                 opts.disabled_tests or opts.meta_sig or opts.key or
-                opts.root_part_size != _DEFAULT_ROOTFS_PART_SIZE or
-                opts.kern_part_size != _DEFAULT_KERNEL_PART_SIZE)
+                opts.root_part_size or opts.kern_part_size)
 
   # Check number of arguments, enforce payload type accordingly.
   if len(args) == 3: