Commit graph

1650 commits

Author SHA1 Message Date
Yifan Hong
2c0a7bc56d Merge "Really support removing / adding partitions." 2019-01-24 00:51:32 +00:00
Treehugger Robot
2463c3ab2a Merge "Support including DTB image" 2019-01-23 20:56:55 +00:00
Hridya Valsaraju
9683b2f136 Support including DTB image
Bug: 111136242
Test: When BOARD_PREBUILT_DTB_DIR is set correctly,
generated $OUT/boot.img contains the DTB image.

Change-Id: I282e31b04cc60383377b9e9b54f8fe64a8140242
2019-01-23 09:14:55 -08:00
Bowgo Tsai
1e04bf7260 Sign system_other.img with AVB
Support signing system_other.img but shouldn't include it into the
top-level vbmeta.img. system_other verifiation will not be included
in /vbmeta chains and will be done separately.

Bug: 112103720
Test: avbtool info_image --image $OUT/system_other.img
Test: avbtool info_image --image $OUT/vbmeta.img, checks 'system_other' is NOT included.
Test: Checks $OUT/obj/PACKAGING/system_other_intermediates/system_other_image_info.txt
      See the following:
        avb_system_other_hashtree_enable=true
        avb_system_other_add_hashtree_footer_args=--rollback_index 1551744000
        avb_system_other_key_path=external/avb/test/data/testkey_rsa4096.pem
        avb_system_other_algorithm=SHA256_RSA4096

Change-Id: Ia152aaab1387dcf556a42222adb39ea76881263a
2019-01-23 15:17:41 +00:00
Yifan Hong
45433e44dd Really support removing / adding partitions.
- When removing a partition, BlockDifference() object
will have tgt=EmptyImage(). Fix the asserts accordingly.
Also, BlockDifference object now allow tgt=None case.

- When adding a partition, BlockDifference() object
will have src=None. Fix the asserts accordingly.

Also, add unit tests to DynamicPartitionsDifference.

Test: create incremental OTA
Test: test_common.DynamicPartitionsDifferenceTest
Bug: 111801737

Change-Id: I3a35378ecf93111b8f44545cff6ae9696b6b4851
2019-01-18 17:09:33 -08:00
Mark Salyzyn
60fa99d491 build_image: Increase spare inodes to 12.
Test: builds device with DAP
Change-Id: I816a7da54bbe23d4eb1140ac0d101c0fee175f0a
2019-01-17 11:30:12 -08:00
xunchang
b6105dcba3 blockimgdiff: selectively convert 'diff' commands to 'new' to reduce stash size
We cannot simultaneously stash more blocks than the size limit imposed by
the cache size. As a result, some 'diff' commands will be inevitably
converted to new. We used to do this conversion blindly when iterating
through the transfer list. This leads to an unintended large package.

In order to choose the right transfers to convert, we calculate the size
of the compressed data, and build a heuristic about the package size
increase to remove each stash blocks. After the process, the given
package size for the watch device further reduces from 186M->155M.

In some rare cases, the removed stashed blocks don't directly contribute
to the maximum simultaneously stashed size. For example,
stash A: 10 blocks
stash B: 5 blocks
free B: 5 blocks  <-- stash B has been freed before we reach max stashed blocks
stash C: 10 blocks

Converting these blocks lead to an uncertain result. On one hand, patches
are generally smaller than the new data; while on the other hand, the
regenerated graph may have fewer order violation and thus give some size
reduction. But these cases are rare and it seems an overkill to consider all
possible scenarios here.

Bug: 120561199
Test: build non-A/B incrementals and check the size
(p.s. it can be tested on all target files with customed cache threshold)
Change-Id: I599420a91b80f1a1d83d22ee1b336b699050cfb4
2019-01-16 12:59:13 -08:00
Yifan Hong
885787f4d3 Merge "Generate OTA for non-A/B devices with dynamic partitions" 2019-01-16 18:42:58 +00:00
Mark Salyzyn
c25b2bf458 build_image: right-sizing at least some spare inode
To address problems creating real tiny filesystem placeholders,
make sure extra spare inodes margin is greater than 0.
For initial estimate we add 4% of total we request at least 8.
For second pass estimate we add 0.2% of total we request at least 1.

We bumped up the margin for zie on the second pass to 0.3% as the
value was too close on one of the builds.

Test: build
Bug: 122328872
Change-Id: I41707bb6fcc8bbfbdda143a9ce62446cad9c1533
2019-01-16 09:54:31 -08:00
Yifan Hong
10c530d20a Generate OTA for non-A/B devices with dynamic partitions
Test: sideload full OTA on cuttlefish
Test: sideload incremental OTA on cuttlefish (that grows
      system, shrinks vendor, and move vendor to group foo)

Bug: 111801737

Change-Id: Ie8a267a90b4df9e9e0a2fbcc1b582ab2e353df52
2019-01-15 16:04:12 -08:00
Mark Salyzyn
db3c8985be Merge changes I6457933a,I955aa0fa
* changes:
  Revert "Relax inode usage estimation slack for DAP right sizing"
  Revert "Increase slack for inode estimation algorithm"
2019-01-15 20:33:50 +00:00
Mark Salyzyn
9f23b89273 Revert "Relax inode usage estimation slack for DAP right sizing"
This reverts commit bd17fab260.

Test: build
Bug: 122328872
Change-Id: I6457933a0dc51827bd86d9c55b02a65999612bcc
2019-01-14 09:44:40 -08:00
Hridya Valsaraju
9aa42f1721 Revert "Increase slack for inode estimation algorithm"
This reverts commit e8e7958c13.

Test: build
Bug: 122328872
Change-Id: I955aa0fa489ab62ec1643127d106925dcb9675ca
2019-01-14 09:44:26 -08:00
Tao Bao
93e7ebe779 releasetools: OutputFile stages files under input dir.
We used to create the intermediate output file as a tempfile, when
adding images to a given zip file. This CL changes OutputFile to write
intermediate files under the given input dir (i.e. OPTIONS.input_tmp
that holds the unzipped files), if the final destination is a zip
archive. This allows image building codes finding the generated images
at consistent locations. The intermediate files will be cleaned up as
part of OPTIONS.input_tmp.

Bug: 122608028
Test: `m dist`
Test: Delete OTA/super*.img from a target_files.zip. Run
      `add_img_to_target_files.py -a` that re-generates split super
      images.
Change-Id: I97903a59fcc0ca5e43bb9b07c3a0b25e9baa92f9
2019-01-13 23:49:25 -08:00
Tao Bao
774c0f92bf Merge "releasetools: Skip copying split super images while signing." 2019-01-11 23:18:49 +00:00
Tao Bao
33bf268e0b releasetools: Skip copying split super images while signing.
Bug: 122608028
Test: Run sign_target_files_apks.py on a target-files zip that has split
      super images (e.g. OTA/super_system.img).
Change-Id: Iaf7263790961a897ea3f339f5af6b18cf253b946
2019-01-11 12:39:31 -08:00
Tao Bao
4b2306b41c releasetools: Update OWNERS.
Test: N/A
Change-Id: I0c6ac3cd04cc6034787d4b8b90fbd61349c54655
2019-01-11 12:28:09 -08:00
Mark Salyzyn
6541d0a80e build_image: support non-sparse right-sized images
Allow right-size to support images that are not sparse.
This is in support of cuttlefish.

Test: build
Bug: 122328872
Change-Id: Ic8ef968e750203dffde7044bc6dfc71c1e283158
2019-01-10 14:49:34 -08:00
Mark Salyzyn
60a716fe8c build_image: right-sizing add .2% margin for space and inodes
To address flakiness in image creation, add a .2% margin of safety
for both inodes and space for ext filesystems.

Test: build
Bug: 122328872
Change-Id: I6665bd6fe642291b825dba58dfd09cc55628230f
2019-01-10 14:49:24 -08:00
Mark Salyzyn
c777eaa779 build_image: hard code set inode size to 256
inode-size will jump around based on filesystem size, however
readonly Android system partitions have a specific pattern of
xattr associated with sepolicy and 256 is the most efficient at
absorbing the content.

Test: manual
Bug: 122328872
Change-Id: I06dd6a503067ab6477293b386d56a89dd86b0e83
2019-01-10 14:49:12 -08:00
Tao Bao
519d18286e Don't build retrofit OTA package if vendor.img is unavailable.
We used to build retrofit full OTA package as long as
PRODUCT_RETROFIT_DYNAMIC_PARTITIONS is true. This doesn't work with AOSP
targets that have the flag set but without any available vendor image.

This CL detects such a condition and uses a separate flag to guard the
retrofit OTA building as well as the split super images generation.

Bug: 120852744
Test: `m -j dist` on blueline (w/ vendor images) and aosp_blueline (w/o
      vendor images).
Change-Id: I65726f24f8fc546be6802941a6a06590a3804c16
2019-01-07 12:22:48 -08:00
Treehugger Robot
dacde2259f Merge "Increase slack for inode estimation algorithm" 2019-01-05 01:22:43 +00:00
Hridya Valsaraju
e8e7958c13 Increase slack for inode estimation algorithm
This is required to prevent build failure on some targets.

Test: mmm
Bug: 119115481

Change-Id: Idf7c21b163a4e10e2ef435c2b2a7795a42feb200
2019-01-04 09:18:07 -08:00
Yifan Hong
cc46eae994 Put system_other in super.img
... for launch A/B devices.
Test: build super image and lpdump
Bug: 113182233

Change-Id: I79ad9da2f6852b39b23e862ff00f320b6565db2f
2019-01-02 12:05:10 -08:00
xunchang
3df4d5eb6d blockimgdiff: add a function to select and convert 'diff' to new
Package size will be unintended large if we stash more blocks than the
stash limit specified by the cache size. To reduce the maximum size of
simultaneous stashed blocks, we will inevitably convert some 'diff'
commands to 'new' commands.

To mitigate the impact, we add a new function to smartly select the
transfers to convert based on their patch size and compressed size.
This cl converts the transfers that have a larger patch size than the
compressed target sizes. And there's a slightly improvement in the
final package size: from 194M -> 185M.

Bug: 120561199
Test: build a non-A/B incremental package, run simulator
Change-Id: Id73ff736ba4e6901d245ad5549d42310d0740284
2018-12-19 20:21:25 -08:00
Treehugger Robot
7cac3adf1a Merge "Relax inode usage estimation slack for DAP right sizing" 2018-12-18 02:13:10 +00:00
Hridya Valsaraju
bd17fab260 Relax inode usage estimation slack for DAP right sizing
The current increase of 4 % is insufficient for some
targets.

Test: mmm
Bug: 119115481
Change-Id: Idcba8025b913da9b70794bfc7464d15b4d99ad34
(cherry picked from commit 3e02e34090)
2018-12-14 14:13:24 -08:00
Tianjie Xu
8ab919dcce Merge "blockimgdiff: Factor out the diff_worker" 2018-12-13 18:45:30 +00:00
xunchang
2153183acf blockimgdiff: Factor out the diff_worker
We will call it at an earlier time to compute the patch size; and
choose the transfers to convert to 'new'.

Bug: 120561199
Test: Generate an incremental update on shiner
Change-Id: I29a0c8e75c9e5b66a266c1387186692a86fcbe43
2018-12-12 17:02:39 -08:00
Chen, ZhiminX
752439b321 Add recovery_acpio option to make recovery image
Test: can generate recovery image with recovery_acpio
Fixes: 111871613

Change-Id: I9174a4741f571a00bcadc548cd9e1316b4175132
2018-12-11 15:23:28 +08:00
Yifan Hong
e98427ac3f Don't build super image if source images are missing
For some internal branches, vendor.img isn't built, so there
is no need to build super image / super split images there.

Test: remove vendor.img and VENDOR/ from target_files_intermediates, then
      run add_img_to_target_files
Fixes: 120634805

Change-Id: I2834a27ce232538f203733c204dd257279c789fc
2018-12-07 11:01:21 -08:00
Tao Bao
2a20f344fc releasetools: Keep the original RangeSet for 'uses_shared_blocks' case.
Setting 'uses_shared_blocks' indicates that the block list for a given
file is incomplete, as some of the blocks are "owned" by others. As a
result, such a file will be skipped from imgdiff'ing.

This CL makes a copy of the original block list before removing the
shared blocks. It uses the original RangeSet as the value of
extra['uses_shared_blocks']. validate_target_files.py will try to read
the file as in the original RangeSet, unless the original list is also
incomplete or has non-monotonic ranges.

Test: Run validate_target_files on a target that uses
      `BOARD_EXT4_SHARE_DUP_BLOCKS := true`.
Change-Id: I259e871ecc249ba0c14b5796bef413185a1b8242
2018-12-06 10:28:49 -08:00
Yifan Hong
5df29604b9 Merge changes from topic "super_target_files"
* changes:
  add_img_to_target_files uses build_super_image
  Build super_empty with build_super_image.py
  Build super.img from images in target_files
2018-12-04 23:20:21 +00:00
Yifan Hong
055e6cf5c8 add_img_to_target_files uses build_super_image
Use the new script to build super_empty and super split images. No more
transformation to lpmake_args.

Test: build target_files_package for retrofit device
Change-Id: Id5f6bd607654ca869bcdf58d86b7ae300e3927eb
2018-12-03 11:33:44 -08:00
Yifan Hong
2b891ac024 Build super.img from images in target_files
For non-retrofit (launch) devices, super.img is used for factory, so
source images should be from target_files.

In this change, build-superimage-target procedure is converted to a
more flexible script so that it can be built.

Bug: 119322123
Test: build target files for device launch with dynamic partitions
Change-Id: I6ee0cc3e145357dfc74be248f81f5f8f4e51fc5c
2018-12-03 11:33:44 -08:00
David Anderson
6f693f04c2 releasetools: Specify a minimum size for right-sized images.
On aosp_blueline, system_other gets right-sized to 61,440 bytes. This
messes up the AVB footer calculation, and is too small to store an ext4
image.

Bug: 116608795
Test: build aosp_blueline w/ dynamic partitions
Change-Id: If0138a9d858765ff82cb957532504a066fd113ff
2018-11-29 13:27:47 -08:00
Tao Bao
03fecb669c releasetools: Remove the mismatch map files when generating retrofit OTAs.
The map files contain the filename-block mapping for the original
images.

Bug: 120109184
Test: Generate an incremental OTA that was previously failing.
Change-Id: I1285d0b24a435477b958e6c2e4f474acf8f7578b
2018-11-28 10:59:23 -08:00
Treehugger Robot
08d07f5aa9 Merge "Infer prebuilt image size" 2018-11-28 00:36:50 +00:00
Yifan Hong
70fc029ab8 Infer prebuilt image size
Test: call script twice; the second time uses prebuilts
Fixes: 119769527

Change-Id: Icd98a4dbfed91538cbc07aab957c7b042c05b330
2018-11-27 11:21:21 -08:00
Tao Bao
f21a8f5376 Merge "Use common.RunAndCheckOutput() in add_img_to_target_files.py." 2018-11-26 18:41:36 +00:00
Yifan Hong
50611038e9 dynamic_partition_use -> use_dynamic_partitions.
Test: build OTA package
Change-Id: Ia43d23f49fc024ecc767da1c2186c4b446c034de
2018-11-21 13:00:57 -08:00
Tao Bao
2764aee664 Use common.RunAndCheckOutput() in add_img_to_target_files.py.
Test: `m dist` with aosp_marlin-userdebug
Test: python -m unittest test_add_img_to_target_files.py
Change-Id: Icff60a44e5c189c2443fbaba3fc6a2b106b409ea
2018-11-21 11:04:32 -08:00
Yifan Hong
50e7954ac9 Generate retrofit OTA.
Test: m otapackage -j, manual apply on top of P
Bug: 118506262

Change-Id: Iedc389a1058007a604de0482f2348a9ef0d5892a
2018-11-20 11:17:39 -08:00
Yifan Hong
c767f7cbfc Add split super images to target_files.
Test: build target files package
Bug: 118506262
Change-Id: Iee6143987c9bfa6f2d287e20c06ea5ef25e82985
2018-11-20 11:17:39 -08:00
Tao Bao
9788b4ed31 releasetools: Temporarily disable verifying AVB-signed images.
Bug: 119624011
Test: Run validate_target_files.py on aosp_blueline-target_files.zip.
Change-Id: I0c3a93dd2ec9fe26c62be2ac2cc26780fb9fe1a6
2018-11-15 13:46:56 -08:00
Mark Salyzyn
3cd2460edc build: Split out mkfs in BuildImageMkfs (retry)
NB: second attempt, issue with scope for mkfs_output.

Separate out BuildImageMkfs from BuildImage, which just makes the
filesystem without any verity, avb, or other decisions.  BuildImage
does all the wrapping for such.  This will hopefully ease maintenance
and drop the issues surrounding BuildImage reentrancy.

Change right-size estimation path to use BuildImageMkfs, and thus do
so without verity or avb wrappings.  Add partition_headroom to space
consideration.  This makes the results of the estimation more
accurate and predictable.

Test: build
Bug: 111302946
Change-Id: I2549bd4e403c21290470b2fa1835492ae883f0fd
2018-11-08 15:42:22 -08:00
Mark Salyzyn
533558ec96 Revert "build: Split out mkfs in BuildImageMkfs"
This reverts commit 2b72b7f01e.

out/target/product/generic_x86/installed-files.txt \${DIST_DIR}/installed-files-rescued.txt; exit 1 ) )" 
2018-11-08 19:12:28 - build_image.py - ERROR : Failed to build out/target/product/generic_x86/obj/PACKAGING/systemimage_intermediates/system.img from out/target/product/generic_x86/system 
Traceback (most recent call last): 
File "build/make/tools/releasetools/build_image.py", line 767, in <module> 
main(sys.argv[1:]) 
File "build/make/tools/releasetools/build_image.py", line 755, in main 
BuildImage(in_dir, image_properties, out_file, target_out) 
File "build/make/tools/releasetools/build_image.py", line 449, in BuildImage 
CheckHeadroom(mkfs_output, prop_dict) 
NameError: global name 'mkfs_output' is not defined 


Bug: 111302946
Reason for revert: Build problem

Change-Id: I786f232e07af653a7207509055df5a07a6d8bb9e
2018-11-08 19:26:50 +00:00
Mark Salyzyn
2b72b7f01e build: Split out mkfs in BuildImageMkfs
Separate out BuildImageMkfs from BuildImage, which just makes the
filesystem without any verity, avb, or other decisions.  BuildImage
does all the wrapping for such.  This will hopefully ease maintenance
and drop the issues surrounding BuildImage reentrancy.  Change
right-size estimation path to use BuildImageMkfs, and do so without
verity or avb wrappings.

Test: build
Bug: 111302946
Change-Id: I30e2e2b727f40ecca5164142f34139f5244f6424
2018-11-07 15:51:32 -08:00
Mark Salyzyn
41f781de9e build_image: right size image problems.
Neglected to correct for filesystem size in estimate for verity.

To keep build space optimized and make sure that the existing image
does not confuse the tools, remove the out_file after the test build
image phase.

Test: build
Bug: 111302946
Change-Id: I360775d862d02a721d061bbc43e8b4e2f03bd01e
2018-11-07 14:50:33 -08:00
Tao Bao
68b081fd5a Merge "releasetools: Add tests for VerityImageBuilder." 2018-11-07 20:23:12 +00:00
Anton Hansson
0e60f8a42c Make right-sizing less aggressive
This is a rollback of Id5ae6645b9aa2d036e6fefe2fb17672e8f8ef6f0
and the followup I6a0f3919e8d45d0b3e7cd558a6ad4d3799012f2c

The magic constant introduced appears to be too aggressive.
Note that the new constant in I0f32c75e80b5da4d47671055ac274ccc2b485992
doesn't appear to fix the broken builds.

Bug: 111302946
Test: make
Change-Id: I29207265172d293c6fee98212e3266bde85895df
2018-11-07 14:02:42 +00:00
Mark Salyzyn
2b191894c2 build_image still too aggressive with right sizing (part troix)
Regression introduced by c3d408e3c1

Found a case where 1 + 1/60 reduction in size based on free space
failed when right sizing an ext4 image. Reduced the math to 1 + 1/61.

Test: compile
Bug: 111302946
Change-Id: I0f32c75e80b5da4d47671055ac274ccc2b485992
2018-11-06 15:57:03 -08:00
Tao Bao
d0b9758203 Merge "releasetools: Create VerityImageBuilder." 2018-11-06 23:37:15 +00:00
Tao Bao
46901fb8ca releasetools: Log the exceptions before rethrowing.
In Append2Simg and Append in verity_utils.py, we catch and rethrow
exceptions as BuildVerityImageError. However, this suppresses the
traceback from the original exception which usually indicates the actual
cause. We can better handle this with the raise statement in Python 3,
which is however unavailable in Python 2.

This CL logs the exception before rethrowing to retain the useful bits.

Test: Inject an error to append2simg. `m -j systemimage` with
      aosp_marlin-userdebug. Check the output.
Change-Id: I0c2f57d6023fa1038256b85fa98d57ad0244a70d
2018-11-06 10:42:35 -08:00
Tao Bao
4a0d5134e1 releasetools: Add tests for VerityImageBuilder.
`testdata/verity_mincrypt` is generated with the following command.
  $ generate_verity_key \
        -convert testdata/verity.x509.pem \
        testdata/verity_mincrypt

Test: python -m unittest test_verity_utils
Change-Id: I3f2f0cd89da0fd5d2420e0e2b09761cc77f893c5
2018-11-06 10:00:51 -08:00
Tao Bao
7549e5e919 releasetools: Create VerityImageBuilder.
Test: `m dist` with aosp_marlin-userdebug (VB 1.0)
Test: `m dist` with aosp_taimen-userdebug (VB 2.0)
Test: `python -m unittest discover .`
Change-Id: I8c016b7621b73f220fb2a4586cc45a21eeee438d
2018-11-06 10:00:28 -08:00
Mark Salyzyn
4a6ce93f27 build_image too aggressive with right sizing
Regression introduced by c3d408e3c1

Found a case where 1 + 1/59 reduction in size based on free space
failed when right sizing an ext4 image. Reduced the math to 1 + 1/60.

Test: compile
Bug: 111302946
Change-Id: I6a0f3919e8d45d0b3e7cd558a6ad4d3799012f2c
2018-11-01 12:45:29 -07:00
Tao Bao
757dfe8792 Merge "Revert "Work around e2fsck issue for building sparse GSIs"" 2018-10-30 15:18:58 +00:00
Tao Bao
27809667b4 Revert "Work around e2fsck issue for building sparse GSIs"
This reverts commit ec7fa1cd09.

The earlier e2fsck issue has been addressed by [1].

[1] https://android-review.googlesource.com/c/platform/external/e2fsprogs/+/725259/

Bug: 112062612
Test: m PRODUCT-aosp_x86_64-eng \
          SANITIZE_HOST=address ASAN_OPTIONS=detect_leaks=0 \
          -j e2fsck systemimage
Change-Id: I7287cb8639ae45abdf753821421bd070b819a30e
2018-10-29 16:02:47 -07:00
Mark Salyzyn
f0cef8d8bf build_image setup ext4 dedupe on more images.
Add ext4 dedupe to system_other, product, product_services, odm and
oem images.  Experimental savings without any other configuration
changes was 0%, .75%, 3.4% respectively for the raw image file size
for the first three.

Test: manual
Bug: 111302946
Change-Id: Ia8fb5696151acad59bb144ea93f2c2ddac962bbd
2018-10-29 13:37:10 -07:00
Mark Salyzyn
c3d408e3c1 build_image tune right-size image
To more quickly settle on a no free space result, recognize that
there is roughly 1/58.5 overhead managing the free space pool as
determined experimentally.  This algorithm carries with it some
risk of being sensitive to any alterations in ext4.

This also addresses the issue of a much larger apparent free space
available calculated on the sample pass when deploying ext4 dedupe,
and resolves the poorer estimation that happens without accounting
for the overhead.

The alternative of adding a second pass works to a similar, and
likely more comforting algorithm and result.  But doing so adds
a minute to the typical incremental build time, or +50% to the
time it takes to determine ext4 right sized images.

Test: manual
Bug: 111302946
Change-Id: Id5ae6645b9aa2d036e6fefe2fb17672e8f8ef6f0
2018-10-29 13:37:04 -07:00
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
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
7ceac730cf Merge "releasetools: Include descriptor of vbmeta_system.img in vbmeta.img." 2018-10-23 20:03:47 +00: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
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
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
Treehugger Robot
86fb70dcdc Merge "Rename vbmeta_mainline to vbmeta_system." 2018-10-16 22:02:48 +00: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
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
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
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
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
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
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
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
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
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
Tianjie Xu
75844bd171 Merge "Generates the care_map with fingerprint" 2018-09-27 17:32:33 +00:00
Tianjie Xu
861f413fad Generates the care_map with fingerprint
Reads the fingerprint of a partition from the build props and embeds it
into the care_map. Later, the update_verifier will compare the
fingerprint before it performs the verification.

Bug: 114778109
Test: generate care_map for sailfish and new pixel
Change-Id: I06afa01bf6dd3de4456a08ee7960954facc775fb
2018-09-26 23:35:32 -07:00
Tom Cherry
b6eeba5bab Merge "Allow BOARD_USES_RECOVERY_AS_BOOT without BOARD_BUILD_SYSTEM_ROOT_IMAGE" 2018-09-26 22:24:54 +00:00
Tom Cherry
2929cadb3b Allow BOARD_USES_RECOVERY_AS_BOOT without BOARD_BUILD_SYSTEM_ROOT_IMAGE
The recovery image already contains a copy of first stage init, so we
can boot unconditionally to the recovery image and instruct first
stage init whether or not to boot to Android or to recovery.  In this
case, we need neither the kernel to mount /system as / nor a separate
partition for recovery, so this change modifies the build scripts to
allow this combination.

Bug: 114062208
Test: Boot pixel from recovery to Android with BOARD_USES_RECOVERY_AS_BOOT
      But without BOARD_BUILD_SYSTEM_ROOT_IMAGE
Change-Id: Icd047afb7f22d2724b3bcaca1aa0c837426dcce7
2018-09-26 20:30:36 +00:00
Tianjie Xu
5875ca06ce Merge "Rename care map in pb format to care_map.pb" 2018-09-21 00:03:40 +00:00
Tianjie Xu
4c05f4a41e Rename care map in pb format to care_map.pb
The new suffix distinguishes the new care_map from the ones in plain
text format; and thus the old update_verifier won't report an error
upon parsing failures.

Bug: 115740187
Test: Generate OTA files for Pixels
Change-Id: Ia782afd8cbb0f4bb8c363edaa00e92ab302d5d1b
2018-09-18 15:42:40 -07:00
Tao Bao
92cc5d2ebe Merge "Support building chained VBMeta images." 2018-09-11 18:27:37 +00:00
Treehugger Robot
860f9d11a8 Merge "Use the new executable for mkuserimg_mke2fs" 2018-09-08 03:50:32 +00:00
Tao Bao
744c4c7604 Support building chained VBMeta images.
Bug: 112007947
Test: `m dist` with aosp_taimen-userdebug.
Test: Set up a target that uses chained VBMeta images of
      `vbmeta_mainline` and `vbmeta_vendor`. `m dist` and check the
      build log, as well as outputs from
      `avbtool info_image --image vbmeta.img`,
      `avbtool info_image --image vbmeta_mainline.img`,
      `avbtool info_image --image vbmeta_vendor.img`.
Change-Id: Ib1d4e97f583b65245703eae15d211adcd9e83741
2018-09-06 16:55:51 -07:00
Treehugger Robot
71034e3764 Merge "Adding better AVB error message" 2018-09-06 07:45:34 +00:00
Bowgo Tsai
99ed1b4fbd Adding better AVB error message
Also removing the requirement of BOARD_BOOTIMAGE_PARTITION_SIZE when
BOARD_AVB_ENABLE is set. Some targets (e.g., emulator) doesn't build
boot.img when AVB is enabled.

Bug: 112293933
Test: build a failure case and checks the error output is expected
Change-Id: I290c707719193ddaedcd9fd0b31de566ad17078c
2018-09-06 09:38:45 +08:00
Tianjie Xu
573322279a Use the new executable for mkuserimg_mke2fs
This is in line with the change of mkuserimg_mke2fs.sh to python binary.

Bug: 112555072
Bug: 63866463
Test: unittests pass
Change-Id: I82c0be1e5bbc685edc15120da73aa43fdc9f2f05
2018-09-05 20:52:47 +00:00
Tao Bao
ea6cbd0765 releasetools: Handle the case of not having ro.vendor.build.fingerprint.
Commit d572632f3d added support in build
system to blacklist given vendor properties. When
ro.vendor.build.fingerprint gets blacklisted, the OTA generation script
can't rely on those properties to determine a change in vendor images.
This CL considers such a case as "vendor images must have changed"
between the two builds.

Bug: 113892939
Test: Generate an incremental package with builds not having
      ro.vendor.build.fingerprint.
Test: python -m unittest test_ota_from_target_files
Change-Id: I188de9c3cbeecf26132c92b9356e9d5fef75205e
2018-09-05 13:14:55 -07:00
Tao Bao
3e9e6af0ff Merge "releasetools: common.LoadInfoDict() takes a bool parameter for repacking." 2018-08-31 22:08:41 +00:00
Tao Bao
639fe0c7cd Merge "releasetools: Track edify function API changes." 2018-08-31 21:24:31 +00:00
David Anderson
1ef03e2b79 Add super_empty.img to target-files and the update package.
super_empty.img is needed for "fastboot update" to work, as such, it
must be included in the update package. This change adds lpmake
parameters to misc_info.txt for add_img_to_target_files.py, and ensures
that lpmake is packaged with otatools.zip.

The build-superimage-target macro is now split into two functions - one
to generate the device-specific arguments, and another to build the full
command-line for convenience. The former is used to pass arguments
directly to add_img_to_target_files.

Bug: 113524256
Test: make updatepackage builds and includes super_empty.img
      make otatools includes lpmake

Change-Id: I25091c964b036beeea2a8b8f738e2c18937c1eb4
2018-08-30 16:02:23 -07:00
Tao Bao
410ad8bb92 releasetools: common.LoadInfoDict() takes a bool parameter for repacking.
It used to accept a non-None input_dir to indicate the need to
re-generate images (called from add_img_to_target_files.py). During that
flow, both of the two parameters redundantly refer to the same input
dir. This CL replaces the second parameter with a bool value instead.

Test: `python -m unittest test_common`
Test: `m dist` with aosp_taimen-userdebug
Test: `zip -d aosp_taimen-target_files-eng.zip IMAGES/\* &&
       add_img_to_target_files.py -a aosp_taimen-target_files-eng.zip`
Change-Id: I0a5a164366acb116407f94bb350872a3a0b207d1
2018-08-29 22:07:21 -07:00
Tao Bao
5121655643 releasetools: Track edify function API changes.
In particular, it replaces the generated calls to edify function of
`apply_patch()` and `apply_patch_check()` with `patch_partition()` and
`patch_partition_check()` instead.

It adds two functions to EdifyGenerator: PatchPartition() and
PatchPartitionCheck() for Python releasetools callers. It also tries to
handle the callers of obsolete EdifyGenerator.PatchCheck() and
EdifyGenerator.ApplyPatch(), if their inputs are in known format.
Otherwise it raises an exception to avoid generating an OTA that updater
doesn't understand.

It requires the matching updater changes in the same topic.

Bug: 110106408
Test: Generate an incremental package with the new script and updater.
      Apply the package on device.
Test: Revert the change in ota_from_target_files.py, so that it calls
      the obsolete EdifyGenerator functions. Check that it generates the
      same incremental package.
Change-Id: Ifc55cb40d3a45116fd4d408536d037eca249effa
2018-08-29 11:53:19 -07:00