Commit graph

5539 commits

Author SHA1 Message Date
Tao Bao
e709b094e4 releasetools: Allow generating BBOTA for images with shared blocks.
When target defines 'BOARD_EXT4_SHARE_DUP_BLOCKS := true', the generated
system/vendor images may contain shared blocks (i.e. some blocks will
show up in multiple files' block list), which violates the current
assumptions in BBOTA script.

This CL allows generating BBOTAs by considering the first occurrence as
the "owner" of the shared blocks. All the later users of the shared
blocks will have an incomplete block list, whose RangeSet's will be
tagged with 'uses_shared_blocks'.

Files with 'uses_shared_blocks' tag will not be diff'd with imgdiff,
potentially with patch size penalty. Such files will be accounted for in
imgdiff stats report, where we can revisit for a better solution.

Bug: 64109868
Test: Generate BBOTA full and incremental package with targets defining
      'BOARD_EXT4_SHARE_DUP_BLOCKS := true'.
Change-Id: I87fbc22eef7fafe2a470a03fdcfa1babf088ea8d
2018-02-13 11:14:23 -08:00
Tao Bao
4ccea8549e releasetools: Remove the unconditional fallback to bsdiff.
This CL uses the 'incomplete' tag to skip applying imgdiff to files with
incomplete block list. It's not the ideal fix to address the holes in
ext4 images, but would unhide other imgdiff issues covered by the
unconditional fallback.

Bug: 68016761
Test: Generate an incremental OTA package from images with incomplete
      block list. Check the imgdiff stats report.
Test: `python -m unittest test_blockimgdiff`
Change-Id: Ice77686414e70f5e42de35c1757fb31cf02e4fd4
2018-02-13 11:06:20 -08:00
Tao Bao
3b67cdf291 Merge changes Ia7ecd0e1,I33982473 am: 4a066a2cd2 am: b25e43bfcb
am: 000274fda1

Change-Id: I360a5b5eeda4a3cfd9bd1145f36d030118eb8361
2018-02-13 17:36:22 +00:00
Tao Bao
000274fda1 Merge changes Ia7ecd0e1,I33982473 am: 4a066a2cd2
am: b25e43bfcb

Change-Id: I52be4244cfb6faca30597a887a5abf7c5fed326f
2018-02-13 17:24:17 +00:00
Tao Bao
508b087943 releasetools: Make blockimgdiff.py pylint-clean.
************* Module blockimgdiff
C:433, 0: Unnecessary parens after 'if' keyword (superfluous-parens)
C:687, 0: Wrong hanging indentation (add 4 spaces).
            max_stashed_blocks, self._max_stashed_size, max_allowed,
            ^   | (bad-continuation)
C:688, 0: Wrong hanging indentation (add 4 spaces).
            self._max_stashed_size * 100.0 / max_allowed))
            ^   | (bad-continuation)
C:691, 0: Wrong hanging indentation (remove 2 spaces).
            max_stashed_blocks, self._max_stashed_size))
          | ^ (bad-continuation)
C:898, 0: Wrong hanging indentation (add 4 spaces).
                  "imgdiff" if imgdiff else "bsdiff",
                  ^   | (bad-continuation)
C:899, 0: Wrong hanging indentation (add 4 spaces).
                  xf.tgt_name if xf.tgt_name == xf.src_name else
                  ^   | (bad-continuation)
C:901, 0: Wrong hanging indentation (add 4 spaces).
                  xf.tgt_ranges, xf.src_ranges, e.message))
                  ^   | (bad-continuation)
C:909, 0: Wrong hanging indentation (add 4 spaces).
                      xf.tgt_name,))
                      ^   | (bad-continuation)
C:917, 0: Wrong hanging indentation (add 4 spaces).
                      xf.tgt_name, e.message))
                      ^   | (bad-continuation)
C:961, 0: Wrong hanging indentation (remove 2 spaces).
                xf.patch_len, tgt_size, xf.patch_len * 100.0 / tgt_size,
              | ^ (bad-continuation)
C:962, 0: Wrong hanging indentation (remove 2 spaces).
                xf.style,
              | ^ (bad-continuation)
C:963, 0: Wrong hanging indentation (remove 2 spaces).
                xf.tgt_name if xf.tgt_name == xf.src_name else (
              | ^ (bad-continuation)
C:965, 0: Wrong hanging indentation (remove 2 spaces).
                xf.tgt_ranges, xf.src_ranges))
              | ^ (bad-continuation)
C:1422, 0: Wrong continued indentation (add 28 spaces).
                tgt_skipped.size() * 100.0 / tgt_size, tgt_name))
                ^                           | (bad-continuation)
C:1560, 0: Wrong continued indentation (add 8 spaces).
            split_src_ranges) in enumerate(split_info_list):
            ^       | (bad-continuation)
R:566, 6: Redefinition of src_str type from list to str (redefined-variable-type)
C:1198,25: More than one statement on a single line (multiple-statements)
C:1211,25: More than one statement on a single line (multiple-statements)
C:1220,16: More than one statement on a single line (multiple-statements)
C:1277,38: More than one statement on a single line (multiple-statements)
C:1284,19: More than one statement on a single line (multiple-statements)
C: 19, 0: standard import "import copy" comes before "import common" (wrong-import-order)
C: 20, 0: standard import "import functools" comes before "import common" (wrong-import-order)
C: 21, 0: standard import "import heapq" comes before "import common" (wrong-import-order)
C: 22, 0: standard import "import itertools" comes before "import common" (wrong-import-order)
C: 23, 0: standard import "import multiprocessing" comes before "import common" (wrong-import-order)
C: 24, 0: standard import "import os" comes before "import common" (wrong-import-order)
C: 25, 0: standard import "import os.path" comes before "import common" (wrong-import-order)
C: 26, 0: standard import "import re" comes before "import common" (wrong-import-order)
C: 27, 0: standard import "import subprocess" comes before "import common" (wrong-import-order)
C: 28, 0: standard import "import sys" comes before "import common" (wrong-import-order)
C: 29, 0: standard import "import threading" comes before "import common" (wrong-import-order)
C: 31, 0: standard import "from collections import deque, OrderedDict" comes before "import common" (wrong-import-order)
C: 32, 0: standard import "from hashlib import sha1" comes before "import common" (wrong-import-order)

Test: `pylint --rcfile=pylintrc blockimgdiff.py`
Test: Generate an incremental BBOTA package.
Change-Id: Ia7ecd0e1fa48daf4e43251bdcdfcd08fb316015d
2018-02-12 13:01:34 -08:00
Tao Bao
9739514769 releasetools: Remove the global diff_done in blockimgdiff.py.
pylint complains about undefined `diff_done`:

W:754, 8: Global variable 'diff_done' undefined at the module level (global-variable-undefined)
W:820,14: Global variable 'diff_done' undefined at the module level (global-variable-undefined)

It would still warn about using global statement after adding the
definition.

W:859, 8: Using the global statement (global-statement)
W:925,14: Using the global statement (global-statement)

This CL computes 'diff_done' via 'len(diff_queue)' instead. It also
moves the progress reporting _before_ the diff work. This way it avoids
showing 100% progress with still changing filenames (because multiple
workers could see an empty queue simultaneously upon finishing their own
works).

There're possible alternatives, such as using the 'nonlocal' keyword in
Python 3 (which we're not there yet), or by using mutable object instead
(e.g. 'diff_done = [0]'). This CL looks cleaner, since it just kills the
var.

Test: Generate a BBOTA incremental. Check the on-screen progress
      report.
Test: `pylint --rcfile=pylintrc blockimgdiff.py` no longer complains
      about the global diff_done.
Change-Id: I339824735527e1f794b5b1dc99ff3fdb2da85744
2018-02-12 12:55:25 -08:00
Tao Bao
a3ee598230 Merge "releasetools: Add an ImgdiffStats class that reports imgdiff stats." am: 7eb2afb226 am: 0ced5030d8
am: e6188063f1

Change-Id: I34118e0e88042ef8477a071f6819483746b0038c
2018-02-12 20:48:54 +00:00
Tao Bao
e6188063f1 Merge "releasetools: Add an ImgdiffStats class that reports imgdiff stats." am: 7eb2afb226
am: 0ced5030d8

Change-Id: I120d8d268fc4a5e1230e16d9b9ab85b2bef20193
2018-02-12 20:28:11 +00:00
Tao Bao
7eb2afb226 Merge "releasetools: Add an ImgdiffStats class that reports imgdiff stats." 2018-02-12 19:01:24 +00:00
Tom Cherry
b01d6d33bc Merge "Place TARGET_FS_CONFIG_GEN passwd/group files in /vendor/etc" am: 3d9fa3615d am: 57dd54f623
am: c2ab6232d9

Change-Id: I8140e02a61429074840fa7b6dabdbc048de5c9f4
2018-02-12 16:46:26 +00:00
Tom Cherry
c2ab6232d9 Merge "Place TARGET_FS_CONFIG_GEN passwd/group files in /vendor/etc" am: 3d9fa3615d
am: 57dd54f623

Change-Id: Ica4d341247fc0f770ccdfafd165df05d70f39772
2018-02-12 16:38:43 +00:00
Tom Cherry
3d9fa3615d Merge "Place TARGET_FS_CONFIG_GEN passwd/group files in /vendor/etc" 2018-02-12 16:27:20 +00:00
Tao Bao
667ff57272 releasetools: Specify SWITCH_SLOT_ON_REBOOT for secondary payload.
The secondary payload should always be applied with
SWITCH_SLOT_ON_REBOOT=0. This CL moves the 'secondary' parameter from
Payload.WriteToZip() to Payload.__init__(). So it can append the flag to
secondary/payload_properties.txt.

Bug: 35724498
Test: Generate an A/B OTA with --include_secondary. Check
      secondary/payload_properties.txt entry in the generated ZIP.
Test: `python -m unittest test_ota_from_target_files`
Change-Id: I816c07ab57a1c8a52eff785801634b8b1cb134d4
2018-02-10 00:13:07 -08:00
Tao Bao
294651d7b4 releasetools: Add an ImgdiffStats class that reports imgdiff stats.
We have a couple of active imgdiff workarounds (and likely with one more
inbounding that allows having shared blocks in ext4 image). Most of
these workarounds need extending imgdiff's capability. While us not
getting there anytime soon, collect the stats to better understand the
impact of each kind so we can prioritize accordingly.

A sample report is as follows.

  Imgdiff Stats Report
========================

 APK files diff'd with imgdiff (count: 88)
-------------------------------------------

  /system/priv-app/Shell/Shell.apk
  ...

 Large APK files split and diff'd with imgdiff (count: 4)
----------------------------------------------------------

  /system/priv-app/Settings/Settings.apk
  ...

Bug: 68016761
Test: Generate an incremental BBOTA package. Check the stats report.
Test: python -m unittest test_blockimgdiff
Change-Id: I27ad862cde472ab2806db877632ce5a0607420f2
2018-02-09 23:02:32 -08:00
Tao Bao
f8255b496b Merge "releasetools: Refactor the condition checking for using imgdiff." am: bec8be51a5 am: 4a79eb0d4e
am: 194e49e06c

Change-Id: Ib383bbb47effe204fa69aac1809df08a75ffc1bc
2018-02-10 02:34:51 +00:00
Tao Bao
194e49e06c Merge "releasetools: Refactor the condition checking for using imgdiff." am: bec8be51a5
am: 4a79eb0d4e

Change-Id: Ia050150657bb373e92bf9797764ef987493e9c96
2018-02-10 02:16:54 +00:00
Tao Bao
bec8be51a5 Merge "releasetools: Refactor the condition checking for using imgdiff." 2018-02-10 00:47:42 +00:00
Tao Bao
cb73aed1f0 releasetools: Refactor the condition checking for using imgdiff.
In Transfer class, unbundle 'intact' with the monotonicity of the input
ranges. Negate the logic of 'intact', and thus rename it to 'trimmed'.
Move this property from an attribute of Transfer class as the one in
RangeSet.extra. 'trimmed' indicates whether the source / target ranges
have been modified after creating the Transfer() instance.

The logic that determines whether we can apply imgdiff has been
refactored and consolidated into BlockImageDiff.CanUseImgdiff(). Now
both of the two paths call this single copy, i.e. the one that detects
large APKs (before creating Transfer()'s), and the other that's about to
generate the patch for a given Transfer instance.

Bug: 68016761
Test: python -m unittest test_blockimgdiff
Test: Generate an incremental BBOTA package.
Change-Id: Id07195f63f1fa6c3af6e9091940d251cf09fa104
2018-02-09 12:46:01 -08:00
Tom Cherry
330670267e Merge "Add compile time check that friendly AID names are < 32 characters" am: 9f25d873bf am: cfac68eb9c
am: af0a12eded

Change-Id: I18b590bd8dc5f7f755ff391c8fbc20c53d03632c
2018-02-09 19:05:42 +00:00
Tom Cherry
af0a12eded Merge "Add compile time check that friendly AID names are < 32 characters" am: 9f25d873bf
am: cfac68eb9c

Change-Id: I52c488b8fc0b6e42ef379b517cc816fc8e759738
2018-02-09 19:00:04 +00:00
Tom Cherry
ee0610e86c Add compile time check that friendly AID names are < 32 characters
There is an internal buffer in bionic for user/group names that is 32
characters long including the trailing null, so we must restrict the
length of these names during compile time.

Bug: 27999086
Test: Successfully compile a valid config.fs
Test: Fail to compile a config.fs with AID name > 31 characters
Change-Id: I7fe887c630dd4d1033b86a5d8332480eb3b0fa07
2018-02-09 18:46:13 +00:00
Tom Cherry
55d0104f1b Place TARGET_FS_CONFIG_GEN passwd/group files in /vendor/etc
These entries are vendor provided and belong on the /vendor partition.

Bug: 27999086
Test: end to end user/group check via config.fs and getpwnam, etc.
Change-Id: I9a5d56da594bf0d04de2b9ce7fd7d9a8151d4682
2018-02-09 10:44:52 -08:00
Tao Bao
f980e046e0 Merge "releasetools: RangeSet.monotonic is not an optional attribute." am: acb3cecc46 am: c6b824ba96
am: 93c09cb740

Change-Id: I87bd661a6ac967f30beb84fafcfc8bfc9bb6fe1a
2018-02-08 06:09:44 +00:00
Tao Bao
93c09cb740 Merge "releasetools: RangeSet.monotonic is not an optional attribute." am: acb3cecc46
am: c6b824ba96

Change-Id: I58685e0b462964078147c5bc906d52d11d74668c
2018-02-08 05:17:24 +00:00
Tao Bao
acb3cecc46 Merge "releasetools: RangeSet.monotonic is not an optional attribute." 2018-02-08 04:45:44 +00:00
Luis Hector Chavez
440da2d41a Make mksquashfs generate a fs_config-friendly root entry
This change adds a flag so that the mksquashfs wrapper scripts generate
an entry that is fs_config-friendly for the root inode. Namely, the root
entry is expected to have an empty filename.

Bug: 72745016
Test: m -j100 dist
Change-Id: Iebdf79c5af0b9d999b7e5f5fe240abfe52cbadda
2018-02-07 10:22:52 -08:00
Tao Bao
f68098ff88 Merge "releasetools: Support packaging secondary payload." am: 67ba60029d am: b7d3649c14
am: adaec07d5a

Change-Id: Ic1e8e8a872b23e3376ca1feba5b0fa7fd6029576
2018-02-07 08:42:16 +00:00
Tao Bao
adaec07d5a Merge "releasetools: Support packaging secondary payload." am: 67ba60029d
am: b7d3649c14

Change-Id: Icf9c40ccdd4f59ace60a272ba354c6e145194dbe
2018-02-07 05:38:22 +00:00
Tao Bao
67ba60029d Merge "releasetools: Support packaging secondary payload." 2018-02-07 05:24:46 +00:00
Tao Bao
fe97dbd4ce releasetools: RangeSet.monotonic is not an optional attribute.
'monotonic' has been non-optional since [1] (L-MR1). Fix the comment in
RangeSet.parse(), as well as the use in blockimgdiff.py.

[1] commit 8b72aefb5a.

Test: Generate an incremental BBOTA package.
Change-Id: I7f95231683473b4f0f07f9c83fccc0e36a1340cb
2018-02-06 16:00:52 -08:00
Tao Bao
3b45d28ff6 Merge "releasetools: Capture stderr output when calling delta_generator." am: 26fc64da06 am: 1f49ccfd61
am: 58e79345f3

Change-Id: Ife6761f4f0891ee8377721ea9e4478c233b6cc37
2018-02-06 17:35:19 +00:00
Tao Bao
58e79345f3 Merge "releasetools: Capture stderr output when calling delta_generator." am: 26fc64da06
am: 1f49ccfd61

Change-Id: I689d61b9ee186f01be4dd57a5cd1dbbdd530ea9b
2018-02-06 17:31:02 +00:00
Tao Bao
3f15ada51b releasetools: Capture stderr output when calling delta_generator.
Prior to this CL, the call to delta_generator in
check_ota_package_signature.VerifyAbOtaPayload() didn't redirect stderr.
The logs (mostly INFO) on successful verification added noise to the
normal output, which also upset the unittest result parser.

This CL captures stderr outputs from delta_generator, and will only dump
them on error.

Bug: 72884343
Test: `python -m unittest -v test_ota_from_target_files > /dev/null`
      gives clean output.
Test: Inject error into delta_generator. The call to
      check_ota_package_signature correctly dumps both of stdout and
      stderr outputs.
Change-Id: I014a4b21bf758dcf0a4b9963259d6019851935ee
2018-02-05 23:39:23 -08:00
Tao Bao
22f78fcf61 Merge "releasetools: Fix an issue with pubkey extraction." am: ca2ffed06c am: 8a05f343c2
am: 4c67bb3a13

Change-Id: I306105a5e2266de39a98a197eaa0a5584ad7fbd5
2018-02-06 02:28:40 +00:00
Tao Bao
4c67bb3a13 Merge "releasetools: Fix an issue with pubkey extraction." am: ca2ffed06c
am: 8a05f343c2

Change-Id: Ief767e449ecfcb01f82aed47bfd6f0e603dae77f
2018-02-06 02:21:04 +00:00
Tao Bao
f7140c0f8c releasetools: Support packaging secondary payload.
By default, an A/B OTA package doesn't contain the images for the
secondary slot (e.g. system_other.img). Specifying
"--include_secondary" that's introduced in this CL allows generating
a separate payload that will install secondary slot images. Both
payloads will be added to the generated A/B OTA package.

An example A/B OTA package with secondary payload
  |
  +-- payload.bin
  |
  +-- payload_properties.txt
  |
  +-- secondary/payload.bin
  |
  +-- secondary/payload_properties.txt
  |
  +-- ...

Such a package needs to be applied in a two-stage manner. During the
first stage, the updater applies the primary payload only. Upon
finishing, it reboots the device into the newly updated slot. It then
continues to install the secondary payload to the inactive slot, but
without switching the active slot at the end (needs the matching support
in update_engine, i.e. SWITCH_SLOT_ON_REBOOT flag).

Due to the special install procedure, the secondary payload will be
always generated as a full payload.

Bug: 35724498
Test: Generate full and incremental OTAs with --include_secondary. Check
      the generated OTAs.
Test: python -m unittest test_ota_from_target_files
Change-Id: I975e826bec492e86eb400f99de0c355a32420127
2018-02-05 13:28:52 -08:00
Treehugger Robot
ca2ffed06c Merge "releasetools: Fix an issue with pubkey extraction." 2018-02-05 21:25:47 +00:00
Tao Bao
891ee8af2d Merge "releasetools: Add sdk and security patch level info to metadata." am: 993e1d2634 am: d00a176e22
am: 1ca91dae98

Change-Id: Ic9e823cb13bf10e48b87a2290dff0deef3f3eb77
2018-02-05 17:35:36 +00:00
Tao Bao
1ca91dae98 Merge "releasetools: Add sdk and security patch level info to metadata." am: 993e1d2634
am: d00a176e22

Change-Id: I16652f7b351200c705c1a5154bf31d150ce5f719
2018-02-05 17:32:27 +00:00
Treehugger Robot
993e1d2634 Merge "releasetools: Add sdk and security patch level info to metadata." 2018-02-05 17:25:16 +00:00
Tao Bao
04e1f012dd releasetools: Fix an issue with pubkey extraction.
When calling 'openssl x509 -pubkey' to extract the public key from a
certificate, openssl 1.0 and 1.1 handle the '-out' parameter
differently. openssl 1.0 doesn't write the output into the specified
filename, which leads to the payload verification failure in
check_ota_package_signature.VerifyAbOtaPayload(). This CL addresses
the issue by always collecting the output from stdout instead.

It also refactors the two copies into common.ExtractPublicKey(), and
adds unittest. get_testdata_dir() is moved into test_utils.py that holds
common utils for running the unittests.

Bug: 72884343
Test: python -m unittest test_common
Test: python -m unittest test_ota_from_target_files
Test: Run sign_target_files_apks with '--replace_ota_keys' on marlin
      target_files zip. Check the payload pubkey replacement.
Test: Trigger the tests with forrest, and tests no longer fail on
      machines with openssl 1.0.1.
Change-Id: Ib0389b360f064053e9aa7cc0546d718e7b23003b
2018-02-04 13:59:52 -08:00
Tao Bao
656ab5d7fb Merge "releasetools: Detect incomplete block ranges." am: 93db955964 am: dcb307c4bd
am: 405e952ec3

Change-Id: I5a76dc5589741be7971ddc134b23d2f6803eea75
2018-02-03 05:17:00 +00:00
Tao Bao
405e952ec3 Merge "releasetools: Detect incomplete block ranges." am: 93db955964
am: dcb307c4bd

Change-Id: I1f51c9567df5917ea9dfa6abe49a612c576bd6ea
2018-02-03 04:41:15 +00:00
Tao Bao
93db955964 Merge "releasetools: Detect incomplete block ranges." 2018-02-03 04:32:13 +00:00
Tao Bao
c7b403a2e8 releasetools: Add Payload class.
This breaks down the current WriteABOTAPackageWithBrilloScript() into
smaller and testable units, which also prepares for the work in
b/35724498.

Bug: 35724498
Test: python -m unittest test_ota_from_target_files
Test: Get identical A/B OTA packages w/ and w/o the CL.
Change-Id: I2ea45ce98e2d2baa58e94fb829b7242f6fe685a7
Merged-In: I2ea45ce98e2d2baa58e94fb829b7242f6fe685a7
(cherry picked from commit 036d721812)
2018-02-02 16:18:07 -08:00
Tao Bao
40b1882f40 releasetools: Add Payload class.
This breaks down the current WriteABOTAPackageWithBrilloScript() into
smaller and testable units, which also prepares for the work in
b/35724498.

Bug: 35724498
Test: python -m unittest test_ota_from_target_files
Test: Get identical A/B OTA packages w/ and w/o the CL.
Change-Id: I2ea45ce98e2d2baa58e94fb829b7242f6fe685a7
(cherry picked from commit 036d721812)
2018-02-02 23:21:16 +00:00
Tao Bao
036d721812 releasetools: Add Payload class.
This breaks down the current WriteABOTAPackageWithBrilloScript() into
smaller and testable units, which also prepares for the work in
b/35724498.

Bug: 35724498
Test: python -m unittest test_ota_from_target_files
Test: Get identical A/B OTA packages w/ and w/o the CL.
Change-Id: I2ea45ce98e2d2baa58e94fb829b7242f6fe685a7
2018-02-02 12:24:26 -08:00
Tao Bao
4258bcc17b Merge "releasetools: Clean up two no-op lines that set 'ota-wipe'." am: 76c6906bf2 am: 6c83183400
am: 73b6f5d661

Change-Id: Ia918010e2c40dd39bd37042d7457fb66f0e7f6da
2018-02-02 20:17:50 +00:00
Tao Bao
73b6f5d661 Merge "releasetools: Clean up two no-op lines that set 'ota-wipe'." am: 76c6906bf2
am: 6c83183400

Change-Id: I494b4519bd57e00237a53d29e46d935abdee1052
2018-02-02 19:04:05 +00:00
Tao Bao
91391637f9 Merge "releasetools: Make validate_target_files.py pylint clean." am: a4c7d59afc am: 41a3a414f0
am: dc68afc7f0

Change-Id: Ic5ea0d13816cfa889608e48414e34763b61c8112
2018-02-02 14:46:15 +00:00
Tao Bao
dc68afc7f0 Merge "releasetools: Make validate_target_files.py pylint clean." am: a4c7d59afc
am: 41a3a414f0

Change-Id: I5fdbf2a22e7219846e5673c1368b018b414cbf50
2018-02-02 06:59:17 +00:00
Tao Bao
24604cc5b9 releasetools: Clean up two no-op lines that set 'ota-wipe'.
The same thing has been set in GetPackageMetadata(), so they are no-op.

Also replace an occurrence of 'OPTIONS.source_info_dict' with
source_info, which has been missed from previous clean-up CLs.

Test: Generate an A/B OTA package, and an incremental BBOTA with
      --wipe_user_data. Check the metadata.
Test: Generate a two-step incremental BBOTA successfully.
Change-Id: I4bb491cac9064d93fb86d12e617c8f38f040e01e
2018-02-01 16:30:42 -08:00
Tao Bao
35dc255180 releasetools: Add sdk and security patch level info to metadata.
The info comes from the build.prop file of the target build (thus no
backward compatibility concerns). OTA server and client can optionally
use these info to understand the expected behavior of an OTA package.

Bug: 72751683
Test: python -m unittest test_ota_from_target_files
Test: `m dist`, then check the metadata in the generated OTA package.
Change-Id: I5935f67684d2486bb5f00d67ce4bc756589a56ed
2018-02-01 15:58:20 -08:00
Tao Bao
c765cca38b releasetools: Detect incomplete block ranges.
This CL detects incomplete block ranges (e.g. due to the holes in
mke2fs created images). Such block ranges will be tagged, so we won't
attempt to imgdiff those files. Note that the change to blockimgdiff.py,
which uses the tag info, will come in a separate CL.

An 'extra' attribute is added to RangeSet class, which defaults to an
empty dict. An 'incomplete' tag will be added into the dict by the
caller of the class. Not adding this tag as an immediate attribute,
because it is not a property regarding the ranges being represented, but
rather some storage space for the caller.

This CL also refactors GetSparseImage and RoundUpTo4K into common.py, so
the same code can be called from both of ota_from_target_files.py and
validate_target_files.py. Not able to add unittests for
GetSparseImage(), as SparseImage requires data in specific format.

Bug: 68016761
Test: Run validate_target_files.py on target-files.zip. It skips
      validating files with missing holes as before.
Test: Run ota_from_target_files.py on angler target-files.zip. It gives
      identical packages w/ and w/o the CL.
Test: pylint on changed files. There're warnings with common.py, but
      unrelated to this change.
Change-Id: I126ccfea13c0d5ebcc8c1b4ff1a4f9200e97423a
2018-02-01 12:35:48 -08:00
Tao Bao
bb20e8c5f2 releasetools: Make validate_target_files.py pylint clean.
C: 73, 0: Wrong hanging indentation (add 4 spaces).
      file_name, actual_sha1, expected_sha1)
      ^   | (bad-continuation)
C:171, 0: Wrong continued indentation (add 20 spaces).
        'SYSTEM/etc/recovery.img', expected_recovery_sha1)
        ^                   | (bad-continuation)
C:185, 0: Wrong continued indentation (add 20 spaces).
        file_path='IMAGES/boot.img', expected_sha1=boot_info[3])
        ^                   | (bad-continuation)
C:191, 0: Wrong continued indentation (add 20 spaces).
        file_path='IMAGES/recovery.img',
        ^                   | (bad-continuation)
C:192, 0: Wrong continued indentation (add 20 spaces).
        expected_sha1=expected_recovery_sha1)
        ^                   | (bad-continuation)
W: 67,15: Use % formatting in logging functions and pass the % parameters as arguments (logging-format-interpolation)
W:150,17: Use % formatting in logging functions and pass the % parameters as arguments (logging-format-interpolation)
W:153,15: Use % formatting in logging functions and pass the % parameters as arguments (logging-format-interpolation)
W:194,15: Use % formatting in logging functions and pass the % parameters as arguments (logging-format-interpolation)
C: 27, 0: standard import "import logging" comes before "import common" (wrong-import-order)
C: 28, 0: standard import "import os.path" comes before "import common" (wrong-import-order)
C: 29, 0: standard import "import re" comes before "import common" (wrong-import-order)
C: 31, 0: standard import "import sys" comes before "import common" (wrong-import-order)

Test: pylint --rcfile=pylintrc validate_target_files.py
Test: Run validate_target_files.py with a target-files.zip.
Change-Id: Ie64acdb4cee4326938c4ad5a34b575d7b82478c0
2018-02-01 12:03:17 -08:00
Tao Bao
d870401863 Merge "releasetools: Move the AVB salt setup into common.LoadInfoDict()." am: 4b4c3d91b0 am: 19bd39fe3f
am: d2bc1b9718

Change-Id: I995829e85bfdfb7024212e1c6427c00934db303d
2018-02-01 00:48:07 +00:00
Tao Bao
d2bc1b9718 Merge "releasetools: Move the AVB salt setup into common.LoadInfoDict()." am: 4b4c3d91b0
am: 19bd39fe3f

Change-Id: I4b8271f022b7c27420cf8b0b6532b2cced0bd44f
2018-02-01 00:26:52 +00:00
Tao Bao
12d87fc174 releasetools: Move the AVB salt setup into common.LoadInfoDict().
We used to do this in add_img_to_target_files.AddImagesToTargetFiles(),
which didn't cover the path when calling from make_recovery_patch. As a
result, /system/bin/install-recovery.sh contains different SHA values
from the actual images.

Test: Set up aosp_bullhead to use AVB. `m dist`, then run the following
      command to verify the generated install-recovery.sh.

  $ ./build/make/tools/releasetools/validate_target_files.py \
      out/dist/aosp_bullhead-target_files-eng.zip

Change-Id: Id7be8fb17072252fcd4d08db2057b8c4af053376
2018-01-31 12:25:10 -08:00
Tianjie Xu
54ec40b263 Merge "Protect SparseImage._GetRangeData() with lock" am: 5edd2821de am: e517144ac9
am: c3b193255b

Change-Id: I752d1921fddc4de293698f42973930d4bca72e9e
2018-01-30 23:51:38 +00:00
Tianjie Xu
c3b193255b Merge "Protect SparseImage._GetRangeData() with lock" am: 5edd2821de
am: e517144ac9

Change-Id: I075d7daacaf92def5233a18243f12cde4ff8db6f
2018-01-30 23:49:35 +00:00
Tianjie Xu
5edd2821de Merge "Protect SparseImage._GetRangeData() with lock" 2018-01-30 23:34:50 +00:00
Andreas Gampe
a9e3f4f36c Merge "Warn.py: Update errorprone categories" am: 709ee786cd am: 2192dda42a
am: 7417ece30a

Change-Id: I1f62020caa042fa00533e13da14c69dd1aeecccf
2018-01-30 02:16:04 +00:00
Andreas Gampe
7417ece30a Merge "Warn.py: Update errorprone categories" am: 709ee786cd
am: 2192dda42a

Change-Id: If813b0e077ecf356ac82ece41a9eef2bde6ab242
2018-01-30 02:13:56 +00:00
Treehugger Robot
709ee786cd Merge "Warn.py: Update errorprone categories" 2018-01-30 02:05:19 +00:00
Tianjie Xu
6b3a9f8a40 Merge "Double check the sha1 for ranges during package generation" am: 92d73d3ab9 am: e62b278865
am: 65ac13cf08

Change-Id: I9aff2f5580681386cc63eadf8b567bd986d195e0
2018-01-29 20:03:43 +00:00
Tianjie Xu
65ac13cf08 Merge "Double check the sha1 for ranges during package generation" am: 92d73d3ab9
am: e62b278865

Change-Id: Icc1145a71430470ee9ef44043cd4b3532207bed9
2018-01-29 20:00:05 +00:00
Tianjie Xu
df1166e92f Protect SparseImage._GetRangeData() with lock
The generator function is not thread safe and is prone to race
conditions. This CL uses a lock to protect this generator and loose the
locks elsewhere, e.g. 'WriteRangeDataToFd()'.

Bug: 71908713
Test: Generate an incremental package several times for angler 4208095 to 4442250.
Change-Id: I9e6f0a182a1ba7904a597f403f2b12fe05016513
2018-01-29 11:52:10 -08:00
Tianjie Xu
8a7ed9f771 Double check the sha1 for ranges during package generation
Check that the Sha1 for src&tgt ranges are correct before computing
patches. This adds ~6 seconds overhead for ~2400 commands.

Bug: 71908713
Test: Generate an incremental package from angler 4208095 to 4442250.
Change-Id: I8cf8ce132fb09a22f7d6689274ddb4a27770be76
2018-01-28 01:54:52 +00:00
Andreas Gampe
cf528ca79d Warn.py: Update errorprone categories
From current tip-of-tree.

Bug: 72451126
Test: build/make/tools/warn.py errorprone.log
Change-Id: I1d632fb8801b74af695b4f7f464a99792e46637a
2018-01-25 12:25:20 -08:00
Jaekyun Seok
d1b1d594a5 Merge "Support /product partition" am: 8fe7f9bfa2 am: 039e0991d5
am: f430ea5ebf

Change-Id: I91381c19408afc350ba7cecf2ca6daf0881f9abd
2018-01-25 04:16:57 +00:00
Jaekyun Seok
f430ea5ebf Merge "Support /product partition" am: 8fe7f9bfa2
am: 039e0991d5

Change-Id: I325ae6518c55f1fc310233a5f67ce3df1ae4940f
2018-01-25 04:11:49 +00:00
Jaekyun Seok
b7735d8105 Support /product partition
This CL adds the following build flags to support building product partition
from Android build system.
- BOARD_AVB_PRODUCT_ADD_HASHTREE_FOOTER_ARGS
- BOARD_AVB_PRODUCT_KEY_PATH
- BOARD_AVB_PRODUCT_ALGORITHM
- BOARD_AVB_PRODUCT_ROLLBACK_INDEX_LOCATION
- BOARD_PREBUILT_PRODUCTIMAGE
- BOARD_PRODUCTIMAGE_EXTFS_INODE_COUNT
- BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE
- BOARD_PRODUCTIMAGE_PARTITION_SIZE
- BOARD_PRODUCTIMAGE_SQUASHFS_BLOCK_SIZE
- BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR
- BOARD_PRODUCTIMAGE_SQUASHFS_COMPRESSOR_OPT
- BOARD_PRODUCTIMAGE_SQUASHFS_DISABLE_4K_ALIGN
- BOARD_USES_PRODUCTIMAGE
- LOCAL_PRODUCT_MODULE
- PRODUCT_FOOTER_ARGS
- PRODUCT_PRODUCT_BASE_FS_PATH
- PRODUCT_PRODUCT_VERITY_PARTITION
- TARGET_COPY_OUT_PRODUCT
- TARGET_OUT_PRODUCT*

And PRODUCT_PRODUCT_PROPERTIES is added to save product-specific
properties in /product/build.prop.

Bug: 64195575
Test: succeeded building product.img with BOARD_PRODUCTIMAGE_PARTITION_SIZE,
BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE and PRODUCT_PRODUCT_VERITY_PARTITION.

Change-Id: I774e6a38003734421591e51bed103802ff84f432
2018-01-25 09:33:58 +09:00
Jin Qian
95873268f3 Merge "Add BOARD_EXT4_SHARE_DUP_BLOCKS to share duplicated blocks on ext4" am: 082837365d am: b6ff980ba5
am: 931d76e1c4

Change-Id: I8bfcd310517c8814907e55b1a328c29392612872
2018-01-24 04:21:38 +00:00
Jin Qian
931d76e1c4 Merge "Add BOARD_EXT4_SHARE_DUP_BLOCKS to share duplicated blocks on ext4" am: 082837365d
am: b6ff980ba5

Change-Id: If48c84eae8f4a447e63c6b32e0c43758b8271242
2018-01-24 04:19:35 +00:00
Treehugger Robot
082837365d Merge "Add BOARD_EXT4_SHARE_DUP_BLOCKS to share duplicated blocks on ext4" 2018-01-24 04:10:42 +00:00
Tianjie Xu
a988cae609 Merge "Don't check the stderr output from bsdiff/imgdiff" am: 07a4299182 am: 759dcbd1ed
am: 6b3337db4a

Change-Id: Ic845bffaa3e92b708188963ce7389e1b16b9045f
2018-01-23 19:00:55 +00:00
Tianjie Xu
6b3337db4a Merge "Don't check the stderr output from bsdiff/imgdiff" am: 07a4299182
am: 759dcbd1ed

Change-Id: If17dcdb8daaf74325bcbc9ae2ef0ba1932a30e94
2018-01-23 18:48:09 +00:00
Tianjie Xu
07a4299182 Merge "Don't check the stderr output from bsdiff/imgdiff" 2018-01-23 06:10:46 +00:00
Tianjie Xu
a2a9f9990f Don't check the stderr output from bsdiff/imgdiff
bsdiff/imgdiff returns non-zero values correctly in case of failures.
So we don't need to check the stderr anymore. This avoids some false
reports of the diff program.

Bug: 72335938
Bug: 71505046
Test: Check the exit value of bsdiff/imgdiff in code search,
      generate a package for angler.

Change-Id: I18f0c3882a40a5288d6aee715713a05270e0db2b
2018-01-23 01:29:56 +00:00
Jin Qian
fde9f7906b Add BOARD_EXT4_SHARE_DUP_BLOCKS to share duplicated blocks on ext4
This option applies to system.img and vendor.img.

Bug: 64109868
Change-Id: Ib4c7384049dca08e57441ef71cc81c2fba4462dd
2018-01-22 17:21:11 -08:00
Tao Bao
718707e403 Merge "releasetools: Track the change to BuildInfo." into oc-mr1-dev-plus-aosp
am: 412e36c6e3

Change-Id: I5cc36eb90a71a6df9c617f0fbcb53a7b8306f003
2018-01-22 22:23:28 +00:00
Tao Bao
2a12ed7dbd releasetools: Track the change to BuildInfo.
The global GetBuildProp() has been factored into BuildInfo class.

ota_from_target_files stderr: Traceback (most recent call last):
  File "/tmp/otatest1734786148718419730/releasetools/ota_from_target_files.py", line 1509, in <module>
    main(sys.argv[1:])
  File "/tmp/otatest1734786148718419730/releasetools/ota_from_target_files.py", line 1421, in main
    source_file=OPTIONS.incremental_source)
  File "/tmp/otatest1734786148718419730/releasetools/ota_from_target_files.py", line 1117, in WriteABOTAPackageWithBrilloScript
    max_timestamp = GetBuildProp("ro.build.date.utc", OPTIONS.source_info_dict)
NameError: global name 'GetBuildProp' is not defined

Test: Build an incremental A/B package with "--downgrade" flag.
Change-Id: I5c304c8b1ea79f3e5465b203bb990cbdffb9b328
2018-01-22 11:37:28 -08:00
Tao Bao
fd65d676f0 Merge "releasetools: Add PayloadSigner class." am: 8413824f4b am: 9704dddd1f
am: 7e7e6a3005

Change-Id: I2761ccd77557d392500745d4d46766b2604b47db
2018-01-22 19:07:37 +00:00
Tao Bao
7e7e6a3005 Merge "releasetools: Add PayloadSigner class." am: 8413824f4b
am: 9704dddd1f

Change-Id: I61e2ca212ce17edd3c9d5b5d733101e9ecdaeb10
2018-01-22 19:05:08 +00:00
Treehugger Robot
8413824f4b Merge "releasetools: Add PayloadSigner class." 2018-01-22 18:54:57 +00:00
Zhi An Ng
c1ad415862 Merge "Fix order of args passed to mksquashfsimage.sh" am: 8eae9fc5f5 am: 7db3875c4c
am: fffa70a1b7

Change-Id: Ie9b67865a5050438a91f37956b192290fe4a4ee4
2018-01-20 06:12:49 +00:00
Zhi An Ng
fffa70a1b7 Merge "Fix order of args passed to mksquashfsimage.sh" am: 8eae9fc5f5
am: 7db3875c4c

Change-Id: I7c6ee9fad1665bfe72a3ae6bb50cb06c1a20c20a
2018-01-20 06:09:41 +00:00
Ng Zhi An
9446c1df98 Fix order of args passed to mksquashfsimage.sh
Bug: 72234456
Test: make systemimage
Change-Id: I1b4b07f0a488eade2f297fea12d02b6e8ccba7d8
2018-01-19 15:55:39 -08:00
Tao Bao
3bc775a4fc Merge "releasetools: Dump mkfs/fsck/simg2img outputs on error." am: 3221f0f387 am: c20b59eabe
am: ed184a50ea

Change-Id: If13865e513d12ad58e0874b6504ef777398df783
2018-01-19 22:48:17 +00:00
Tao Bao
ed184a50ea Merge "releasetools: Dump mkfs/fsck/simg2img outputs on error." am: 3221f0f387
am: c20b59eabe

Change-Id: Iede2a76f87298fc0c389883b4e57d87d32968fb6
2018-01-19 22:45:34 +00:00
Treehugger Robot
3221f0f387 Merge "releasetools: Dump mkfs/fsck/simg2img outputs on error." 2018-01-19 22:35:47 +00:00
Tao Bao
fabe08352c releasetools: Add PayloadSigner class.
Create a wrapper class that handles the payload signing, which unifies
the paths with and without external signer. Also add tests for the newly
added class.

The test keys under testdata/ are created with the script in
development/tools/make_key. testdata/testkey_with_passwd.pk8 uses
password "foo".

Test: python -m unittest test_ota_from_target_files
Test: Get identical A/B OTA packages w/ and w/o the CL.
Change-Id: Ic770aec726498a3babb88ec509985e7f1210fb18
2018-01-19 13:25:04 -08:00
Tao Bao
de2fd74ebf Merge "releasetools: Clean up three functions in add_img_to_target_files.py." am: a5b48fcf7f am: 6ff60cee22
am: 96041d3435

Change-Id: I13d7b98f028652442889ca4d5003a4a1a3894a11
2018-01-19 20:47:22 +00:00
Tao Bao
4f47b05060 Merge "releasetools: Refactor AddImagesToTargetFiles()." am: 1eddcad909 am: 53c3f1589b
am: 8ede95e991

Change-Id: I6ae707a06e82b4e784c40ddb8902e6adf1fdca03
2018-01-19 20:46:15 +00:00
Tao Bao
96041d3435 Merge "releasetools: Clean up three functions in add_img_to_target_files.py." am: a5b48fcf7f
am: 6ff60cee22

Change-Id: I54d8ba7656c4fc1c4ca2b0454649ce66bc5ba185
2018-01-19 20:43:47 +00:00
Tao Bao
8ede95e991 Merge "releasetools: Refactor AddImagesToTargetFiles()." am: 1eddcad909
am: 53c3f1589b

Change-Id: Ibc2656d220cf0cdf8eb9947c928fd11736f30c86
2018-01-19 20:43:12 +00:00
Tao Bao
cd53a89599 releasetools: Dump mkfs/fsck/simg2img outputs on error.
The output (stdout and stderr combined) would be helpful in understanding
the cause of the failure.

Not changing other occurrences in build_image.py yet, since it's less
obvious if a failed call should be considered fatal (thus whether to
dump such outputs). For example, GetVeritySize() simply returns 0 on
failed calls. They deserve further clean-ups in later CLs (with unit
tests).

Bug: 71864688
Test: Inject errors into mke2fs/e2fsck/simg2img. `m snod` prints outputs.
Test: `m snod` remains quiet on successful runs.
Change-Id: I172403f6cd05bce93767265dbcb110271a68e2a8
2018-01-19 11:15:42 -08:00
Tao Bao
a2ff4c9b06 releasetools: Clean up three functions in add_img_to_target_files.py.
This CL makes the following changes:
 (a) cleans up the similar codes in AddCareMapTxtForAbOta() that handle
     'system' and 'vendor' partitions;
 (b) fixes an issue with the arcname in AddPackRadioImages() and
     AddRadioImagesForAbOta(), where forward slash should always be used
     in zip entry names;
 (c) refactors the branching statements in AddRadioImagesForAbOta() to
     reduce indentation levels.

Test: python -m unittest test_add_img_to_target_files
Test: `m dist` with aosp_marlin-userdebug. Check META/care_map.txt in the
      generated target_files.zip.
Change-Id: I3d6f794962d0c68390fbd18eb13c2622acab3ff5
2018-01-18 23:37:29 -08:00
Tao Bao
bea20ac722 releasetools: Refactor AddImagesToTargetFiles().
Separate three functions out of AddImagesToTargetFiles(), into
AddCareMapTxtForAbOta(), AddRadioImagesForAbOta() and
AddPackRadioImages() respectively. This CL tries to apply minimal
changes for the refactoring purpose.

Also add tests for AddRadioImagesForAbOta() and AddPackRadioImages().
The tests for AddCareMapTxtForAbOta() require better testing support to
mock sparse_img.SparseImage, which will be added in later CLs.

Test: python -m unittest test_add_img_to_target_files
Test: `m dist` with aosp_marlin-userdebug. Check META/care_map.txt in
      the generated target_files.zip.
Change-Id: I1bb723c15237ff721f165cfce0ce996008ce9948
2018-01-18 23:37:23 -08:00
Tao Bao
9daf3419ba Merge "releasetools: Remove the reloading of target info dict." am: 13f228ebde am: 815a167ae4
am: ee3155c09c

Change-Id: I97f63a561634bb7ded0e0968e5751eaaaf60e5fa
2018-01-18 23:03:38 +00:00