Commit Graph

6708 Commits

Author SHA1 Message Date
Tao Bao
f3fc62c8a0 releasetools: Fix the error message.
This avoids showing a message as below:

raise BuildImageError("Failed to get tune2fs usage:\n{}".format(output))
UnboundLocalError: local variable 'output' referenced before assignment

The `output` won't be set under such a case, which unfortunately hides
the real cause. This CL addresses the issue by letting it throw
implicitly, which contains the command and outputs.

Test: `m dist`
Test: `python -m unittest test_build_image`
Change-Id: Icf015bab8869d150516246ed73552f6502127cdf
2018-10-25 12:29:44 -07:00
Mark Salyzyn
838af0dcf9 Merge "build_image: improvements to right size for dynamic partitions" am: 1bc81731c8
am: 76a397f039

Change-Id: I35bef95a39c9cb4383dcf419a1906699492639c4
2018-10-25 08:38:17 -07:00
Mark Salyzyn
780f595fac build_image: improvements to right size for dynamic partitions
If partition_reserved_size is 0 or undefined, and
use_dynamic_partition_size is true, we should approach no space
and no free inodes automatically.

Estimate the space and number of inodes required, then do a first
pass build to see how much space actually used, and use those values
to refine the estimate.

Depends on tune2fs to report the characteristics of the filesystem,
so only support for ext filesystems.  In the future if there has to
be a more generic ability, either a tool per a filesystem has to be
found, or we will need root capabilities to mount the filesystem to
acquire the characteristics live from the host system.

Test: manual + python -m unittest test_build_image
Bug: 111302946
Change-Id: I933a388be43516b6de7b5007b296765bd5556fde
2018-10-23 15:14:00 -07:00
Tao Bao
fab4c3cbb3 Merge "releasetools: Include descriptor of vbmeta_system.img in vbmeta.img." am: 7ceac730cf
am: 4211c24b87

Change-Id: I9869fb89ef0087f9710a506b6dbbba1f5ce62058
2018-10-23 13:25:59 -07:00
Tao Bao
7ceac730cf Merge "releasetools: Include descriptor of vbmeta_system.img in vbmeta.img." 2018-10-23 20:03:47 +00:00
Tianjie Xu
9f25b4af59 Merge "Install the ota keys under recovery as a zipfile" am: 1e0742e2c3
am: da0a29fc8a

Change-Id: I2397453bdd671bd5cab533a962219156953aa90d
2018-10-22 19:56:42 -07:00
Tao Bao
7106420add releasetools: Include descriptor of vbmeta_system.img in vbmeta.img.
Chained vbmeta images should be included into the top-level vbmeta.img
as chained partitions. It's done in the path of `m`, but not `m dist`.

Bug: 118115607
Test: `m dist` a target that uses chained vbmeta.
    a) Check that the `vbmeta.img` in target-img.zip contains the image
       descriptor of `vbmeta_system.img` (`avbtool info_image`).
    b) `avbtool verify_image --image vbmeta.img \
            --expected_chain_partition \
                vbmeta_system:1:/path/to/vbmeta_system/pubkey`
    c) `avbtool verify_image --image vbmeta_system.img`
Change-Id: I064e583b247c44b9b2f19355838550bb5dbb8f26
2018-10-22 15:27:54 -07:00
Tianjie Xu
ffbe6b9785 Install the ota keys under recovery as a zipfile
Recovery can now parse the pem encoded x509 keys from a zipfile. So
instead of dumping the keys into a text file with some intermediate format,
we can simply create a zipfile with the keys.

Bug: 116655889
Test: make bootimage and check the generated zipfile, run sign_target_files_apks
Change-Id: Ib76feecfb26d6be713a07644e80ec96133759004
2018-10-22 14:47:15 -07:00
Tao Bao
87a1271231 Merge "releasetools: Log to stdout when running tests." am: 60c3421896
am: 395b920354

Change-Id: Id1257333de15e3f362e7b4c6d8442ca5e503559f
2018-10-18 21:10:54 -07:00
Tao Bao
898a924904 releasetools: Log to stdout when running tests.
This sets up the root logger while running tests. It also logs to
stdout, as our Python test result parser doesn't like outputs from
stderr.

Test: `python -m unittest discover build/make/tools/releasetools \
          > /dev/null` doesn't print log lines.
Change-Id: Ic99711bd458bc4b67b38226786fed604c2168476
2018-10-18 15:05:49 -07:00
Andreas Gampe
06be921a7b Merge "Build: update warn.py for Errorprone 2.3.2" am: d68c98538d
am: a5301878fe

Change-Id: I2157def7c57b6936dcfb624a793cd34a3c21bafa
2018-10-18 12:01:42 -07:00
Treehugger Robot
d68c98538d Merge "Build: update warn.py for Errorprone 2.3.2" 2018-10-18 18:45:16 +00:00
Tao Bao
2710a60539 Merge "releasetools: Switch to Python logging." am: 185ce5ffb3
am: c4c8c99741

Change-Id: If26cc658d33d3cd985b7f4eb6fdc4cd940669b3c
2018-10-18 11:37:09 -07:00
Tao Bao
32fcdab512 releasetools: Switch to Python logging.
Converts the following files to Python logging.

add_img_to_target_files.py
blockimgdiff.py
build_image.py
check_ota_package_signature.py
common.py
img_from_target_files.py
make_recovery_patch.py
ota_from_target_files.py
sparse_img.py
verity_utils.py

This separates logging outputs from normal outputs, and allows easier
switching between different verbosity levels. It also supports adjusting
logging config via environment variable (LOGGING_CONFIG).

Test: `m dist`
Test: `python -m unittest discover build/make/tools/releasetools`
Change-Id: Idfc3f7aff83e03f41f3c9b5067d64fd595d5192d
2018-10-17 07:51:04 -07:00
Chih-Hung Hsieh
c997781ee9 Merge "Fix implicit-fallthrough warning." am: 160bbc42f8
am: 6cae701e1e

Change-Id: I330babfff19470fadf71ace9666d99bef18007db
2018-10-16 15:26:58 -07:00
David Anderson
a9ee679d4c Merge "Rename vbmeta_mainline to vbmeta_system." am: 86fb70dcdc
am: 11d4c35bfb

Change-Id: Iac12f4e7d2627a5cab607f259b6816f5b8680802
2018-10-16 15:25:28 -07:00
Treehugger Robot
160bbc42f8 Merge "Fix implicit-fallthrough warning." 2018-10-16 22:04:01 +00:00
Treehugger Robot
86fb70dcdc Merge "Rename vbmeta_mainline to vbmeta_system." 2018-10-16 22:02:48 +00:00
Chih-Hung Hsieh
1ce134aab7 Fix implicit-fallthrough warning.
Bug: 112564944
Test: make checkbuild
Change-Id: I7fcc52cd96cd781fe026e07c8029feeea8ceced0
2018-10-16 11:50:18 -07:00
Tao Bao
f3d4d120fa Merge "releasetools: Clean up the logging while calling external commands." am: 909c332fab
am: 4fdbd7ddd8

Change-Id: Ie857739c1fb1e57544abe9c063e1ef9ac2e8db89
2018-10-15 21:51:51 -07:00
David Anderson
7709ab2b69 Rename vbmeta_mainline to vbmeta_system.
Bug: 116859651
Test: device builds with chained vbmeta_system enabled
      vbmeta_system.img is generated

Change-Id: I75b52a89feeec8dd0e1e271d2a8c3c94036c932c
2018-10-15 14:42:29 -07:00
Tao Bao
bec89c1e1e releasetools: Clean up the logging while calling external commands.
common.RunAndCheckOutput() checks the exit code and will raise on errors.

Test: python -m unittest test_ota_from_target_files
Test: Call ota_from_target_files.py with aosp_marlin target_files zip
Test: Inject an error to the command. Repeat the call without verbose
      flag. It dumps the stack trace on error.
Change-Id: I85b765a33b9087bcbcb0571d6e632a07bb86c65c
2018-10-15 12:01:42 -07:00
Andreas Gampe
161ec1ecc1 Build: update warn.py for Errorprone 2.3.2
Bug: 114129741
Test: manual
Change-Id: I7fb34881a623ffb115a92bfffb108b503d4645ad
2018-10-15 08:56:58 -07:00
Tao Bao
e3c845ba2b Merge "releasetools: Fix a broken test due to verity utils relocation." am: 1e5a23f9b0
am: 39eb5ff367

Change-Id: I8248702c2b67b6b49b20b3cead11980288853339
2018-10-14 08:25:11 -07:00
Tao Bao
28f201b417 releasetools: Fix a broken test due to verity utils relocation.
Test: python -m unittest test_validate_target_files
Change-Id: I2267e18f63d4a36ecd5fff911848470a860ab6cf
2018-10-13 19:27:52 -07:00
Tao Bao
6ad6eccca3 Merge "releasetools: Move verity related functions into verity_utils.py." am: d685239e37
am: ca6cdfe973

Change-Id: I4986fbf5f224fa22801ff6aeee1576acac6a4ae2
2018-10-13 08:52:38 -07:00
Tao Bao
71197515bb releasetools: Move verity related functions into verity_utils.py.
This prepares for upcoming changes that refactor verity-related
functions into classes.

This CL makes minimal changes to the moved functions, by creating a new
BuildVerityImageError class in verity_utils.py replacing the former
BuildImageError that's specific to build_image.py. As part of the
change, it also moves the tests for AVBCalcMinPartitionSize into
test_verity_utils.py.

Test: python -m unittest test_verity_utils
Test: `m dist` with aosp_marlin-userdebug (Verified Boot 1.0)
Test: `m dist` with aosp_taimen-userdebug (Verified Boot 2.0)
Change-Id: I19b52714d8980705ea1f9484ac03eb0af9483240
2018-10-12 12:09:34 -07:00
Tao Bao
387daaba8e Merge "releasetools: Add a common base class for unittests." am: e95680a60f
am: d2c34f3a07

Change-Id: Iee495df7a9c0494721549a25394df5a85a504898
2018-10-12 11:57:48 -07:00
Tao Bao
f8803ab70c Merge "releasetools: Rename test names in test_verity_utils.py." am: f77560ec12
am: 3cfdcd4918

Change-Id: Ia6611d05dd5534eb3c70be82c074fc28546b86dd
2018-10-11 23:28:25 -07:00
Tao Bao
65b94e92be releasetools: Add a common base class for unittests.
All the releasetools unittests extend the common base class of
test_utils.ReleaseToolsTestCase. Define tearDown() in the base class to
do the clean-up works.

Test: `pylint --rcfile=pylintrc test_*.py`
Test: `python -m unittest discover .`
Change-Id: I51775d964ef032dcdf3bb89c55e1a31371cde708
2018-10-11 23:01:09 -07:00
Tao Bao
5fe287beb4 releasetools: Rename test names in test_verity_utils.py.
There's a naming convention between the testcase and the class/method
being tested.

Also remove VerifiedBootVersion2HashtreeInfoGenerator as it's merely a
placeholder without telling anything much (e.g. whether it's to be
implemented or working as intended).

Test: python -m unittest test_verity_utils
Change-Id: Ieb156765c865aa551e3882f381e3a6db2cac4cbc
2018-10-11 14:39:09 -07:00
Tao Bao
53c86dec73 Merge "releasetools: Move build_image.RunCommand into common.py." am: b2dd1b6365
am: 6c22649500

Change-Id: I6257243b7bee2ea8fdc45cd3f1841417307e0f73
2018-10-11 14:18:53 -07:00
Tao Bao
986ee86854 releasetools: Move build_image.RunCommand into common.py.
build_image.RunCommand and common.Run are essentially doing the same
work, but with different interfaces and return values. This CL
consolidates them by moving build_image.RunCommand into common.py as
common.RunAndCheckOutput, with the former calling common.Run internally.

common.RunAndCheckOutput checks the exit code: it returns the output
string on success, or raises common.ExternalError otherwise.

Test: `m dist` with aosp_marlin-userdebug
Test: python -m unittest test_build_image
Test: python -m unittest test_common
Change-Id: I3cd0e9301c576572194618eba8dc00db06c3c35f
2018-10-10 18:13:24 -07:00
Elliott Hughes
5dafee7e80 Merge "Move zipalign off NO_ERROR." am: 3f7223984c
am: 54045b181c

Change-Id: I0207ed8a09ddeb3b8b9a0146a05ec27be412480d
2018-10-08 19:19:13 -07:00
Elliott Hughes
ad7d562d27 Move zipalign off NO_ERROR.
I really only care about code that's built for Windows, but I may as
well clean up anywhere that's easy to clean up too...

Bug: N/A
Test: builds
Change-Id: I3ef34fb12ac90e9411b6421e9c23dd8524f056ae
2018-10-08 11:19:28 -07:00
Tao Bao
565274ac12 Merge "releasetools: Set default stdout and stderr in common.Run()." am: d124240719
am: 45cd372ba9

Change-Id: I0f94fd8c9593fa3f2650db3ffccc6b15010e0d2f
2018-10-04 20:24:54 -07:00
Tao Bao
73dd4f45f3 releasetools: Set default stdout and stderr in common.Run().
stdout and stderr will default to subprocess.PIPE and subprocess.STDOUT
respectively (which is the expected behavior from most of the existing
callers), unless caller specifies any of them.

Test: `m dist`
Test: python -m unittest \
          test_common \
          test_add_img_to_target_files \
          test_ota_from_target_files \
          test_validate_target_files
Change-Id: I43b3f08edfa8a9bcfe54baf9848dc705c048e327
2018-10-04 17:05:09 -07:00
David Anderson
5e9e0a3880 Merge "Remove uuidgen.py and update lpmake parameters." am: d1428e2748
am: df6037fbf7

Change-Id: I9dba21e574408f2cabe7a8b1d944e6cb7d72f7b1
2018-10-04 12:09:15 -07:00
David Anderson
d1428e2748 Merge "Remove uuidgen.py and update lpmake parameters." 2018-10-04 18:20:47 +00:00
Tao Bao
bf9021285a Merge "releasetools: build_image.BuildVerityTree() returns a tuple." am: 4d36fcba8c
am: 589952772f

Change-Id: Ie3a0e7264aa51d5cab688f2a0759983d2e184792
2018-10-04 07:46:12 -07:00
Tao Bao
2f057467eb releasetools: build_image.BuildVerityTree() returns a tuple.
We don't need verity_root_hash or verity_salt to be in the prop dict.

Test: `m dist` with aosp_marlin-userdebug
Test: python -m unittest test_verity_utils
Change-Id: I5a9c50f4741dfb1083b3f590136335b6bc0e5216
2018-10-03 16:37:58 -07:00
Tianjie Xu
7a4bde165d Merge "Generate the compute_hash_tree command" am: 08fff56237
am: ebf3195528

Change-Id: I55ac9cf7964ef23296f6555792fcb59545435bfb
2018-10-03 16:29:08 -07:00
David Anderson
b954afec0b Remove uuidgen.py and update lpmake parameters.
Bug: 117229984
Test: device builds with PRODUCT_USE_LOGICAL_PARTITIONS=true
Change-Id: Ib39d19726861dd79d90923163f9e594ed91da4ca
2018-10-03 14:24:34 -07:00
Tao Bao
9ae934f9d9 Merge "releasetools: Raise on image building errors." am: fabb2c9792
am: db6450a6e4

Change-Id: Iaaab2c50ded479ce7bebd94837d9610da5f27865
2018-10-03 13:53:25 -07:00
Tianjie Xu
67c7cbb9c8 Generate the compute_hash_tree command
Generate the transfer command "compute_hash_tree" for incremental
updates of the non-A/B devices that enable verified boot 1.0

Other changes include:
i.  factor out verity_utils to use both in build_image and blockimgdiff
ii. add a new flag 'hashtree_info_generator' in sparse_image to generate
    the hashtree information.

Bug: 25170618
Test: generate a package for aosp_angler; and run simulator
Change-Id: I4d4d7a3e41dc3da810d2cbf8988e85d187c9ab0e
2018-10-03 13:36:35 -07:00
Tao Bao
c6bd70a5e6 releasetools: Raise on image building errors.
The image building functions in build_image.py have been returning
(success, result) or special values to indicate the validity of the
result. The same logic can be better expressed by raising exceptions
instead, because
 a) using a special value relies on caller to check for that magic
    value;
 b) exceptions can carry additional messages other than a boolean does,
    e.g. the output from the failing command;
 c) caller can have cleaner code flow without explicitly checking for
    the validity of the result.

This CL changes such functions to raise on errors. The majority of these
functions are internal to build_image.py only, except for BuildImage()
that has a few callers in add_img_to_target_files.py (which all die upon
error anyway).

Test: `m dist`
Test: python -m unittest test_build_image
Test: python -m unittest test_add_img_to_target_files
Test: python -m unittest test_validate_target_files
Test: Inject an error to the depended binaries (e.g. avbtool), and check
      that build_image.py exits with error messages.
Change-Id: Ibe4d51e267756bb1a00fa9238a213f9d55fd9b58
2018-10-03 11:31:44 -07:00
Bowgo Tsai
90b5ae2ccb Merge "Prevent AVB signing from using _RESERVED_SIZE" am: 943be51cf1
am: 09db6562ae

Change-Id: I02099ec5977fba86b1cf1eda7fd42b8ac219c45f
2018-10-03 07:46:28 -07:00
Bowgo Tsai
040410c104 Prevent AVB signing from using _RESERVED_SIZE
When AVB is enabled with PRODUCT_USE_DYNAMIC_PARTITION_SIZE, AVB
metadata (e.g., hash tree, fec metadata) will consume _RESERVED_SIZE,
resulting in smaller reserved size in file system (e.g., ext4).

Adding additional space for AVB signing and keep the _RESERVED_SIZE only
for file system. This is done by adding a function to binary search an
optimal partition size for a given image size (disk usage + _RESERVED_SIZE).

Bug: 112322265
Test: Build aosp_arm64-userdebug, calculate the running time of
      AVBCalcMinPartitionSize() is about 0.3-0.4 seconds.
Test: python -m unittest test_build_image
Change-Id: I8f0051b57701d6fbba6a9db3756dd194066c74b8
2018-10-03 10:08:45 +08:00
Tao Bao
26e4adf4ba Merge "releasetools: Clean up the use of partition_size." am: c7aa0dbf0d
am: b2577cdbb9

Change-Id: I68ec8904508792f367f0285fdf676c9a9c7f50f8
2018-09-30 21:34:45 -07:00
Tao Bao
35f4ebc957 releasetools: Clean up the use of partition_size.
Unless using dynamic partitions, `partition_size` should be a fixed
value that equals to the partition size in BoardConfig. It should stay
the same when building an image for that partition. Only the actual
image size that's used to hold the filesystem could be adjusted. This CL
cleans up the uses of `partition_size` and `image_size` to better
reflect such logic.

With dynamic partitions, the only thing that changes is the need to
compute `partition_size` upfront. Once that's done, `partition_size`
should remain unchanged.

Test: `m dist`
Test: `python -m unittest test_add_img_to_target_files`
Test: `python -m unittest test_validate_target_files`
Change-Id: Idedb3e018c95e8f63dc4d9c423be27f30ebb584f
2018-09-27 18:06:59 -07:00