Commit graph

421 commits

Author SHA1 Message Date
David Anderson
4c8e6eae28 Merge "Fix build for API change to DestroyLogicalPartition()." 2019-07-13 18:02:05 +00:00
Justin Yun
ea3c4a4948 Change the symlink to system_ext
As system_ext partition will be linked to system/system_ext, update
the path to system/system_ext.

Bug: 134359158
Test: build
Change-Id: I5a49adfe7e045e24bf6dfbf6990a965b8a5e1ce1
2019-07-09 23:33:26 +00:00
Robin Lee
1cf8eb7559 Add a GetMappedPackageLength to Updater
Corresponds to GetMappedPackageAddress.

There is at least one custom device recovery with an extension to copy
the package somewhere else as a backup. Ability to do this was removed
in change ag/955273.

Test: lunch cf_x86_tv-eng; make
Test: atest recovery_unit_test recovery_component_test
Change-Id: I0e61d8a8839c47721874526504ea03b9ca7bafa9
2019-07-08 19:30:11 +02:00
Tianjie Xu
4955648c4c Merge "Add unit tests for simulator" 2019-06-28 17:47:23 +00:00
Justin Yun
7ba8f18590 Rename product_services to system_ext
Bug: 134359158
Test: build and boot
Change-Id: I2ea21a0e528bdbab7d2479b48c73e7f2274ecca5
2019-06-28 16:17:26 +09:00
Tianjie Xu
c3a161e2b8 Add unit tests for simulator
Make sure the simulator succeeds executing common non-A/B update
functions.

Bug: 131911365
Test: run unit tests
Change-Id: I520ce6a8827539b88a9e36f9e67eec30d8b586d4
2019-06-27 16:17:05 -07:00
David Anderson
32148d9a0a Fix build for API change to DestroyLogicalPartition().
This method no longer contains a timeout parameter; it has been
removed in favor of changes to libdm.

Bug: 135771280
Test: builds
Change-Id: Id8c0f17c2787412bc4588af5a1bc49cc8e6edd51
2019-06-24 13:51:43 -07:00
Tianjie Xu
d118833f3e Implement updater runtime for dynamic partitions
The simulator skips executing the operations for dynamic partitions, and
will use the logical images under target_files/IMAGES directly. (Similar
to the targets without DAP enabled)

Bug: 131911365
Test: run update on cuttlefish, run simulator
Change-Id: Id318d97ece4560df9f20dc5cabeb8b2e261bdf9c
2019-06-24 12:46:28 -07:00
Tianjie Xu
74b0f7cce0 Implement the TargetFile and BuildInfo
The TargetFile class parses a target-file and provides functions to read
its contents. And the BuildInfo tries to simulate the device with files
on host. Some work it does includes parsing the build properties,
and extracting the image files for partitions specified in the fstab.

Bug: 131911365
Test: unit tests pass, run simulator with cuttlefish, wear devices and from extracted TF.
Change-Id: Iefe4a96d619d2e4b3d038e31480f11a0f9a70afa
2019-05-31 17:55:36 -07:00
Tianjie Xu
76e165d143 Disable building simulator for mac
Disable building the simulator and its support libraries to resolve the breakage
on mac host targets. Because the simulator is not intended to use on mac anyway.

Bug: 134047992
Test: mma
Change-Id: I488ab50cab1282f03250010b5334f1895d44f98b
2019-05-30 10:49:18 -07:00
Tianjie Xu
c1a5e26fd9 Implement an update simulator to verify BB OTA packages on host
Implement the simulator runtime and build the updater simulator as a host
executable. The code to parse the target-files and mocks the block devices
will be submitted in the follow-up.

Bug: 131911365
Test: unit tests pass

Change-Id: Ib1ba939aec8333ca68a45139514d772ad7a27ad8
2019-05-28 15:18:25 -07:00
Tianjie Xu
27556d089f Some clean ups to the updater
Remove some unnecessary includes or forward declarations. And include
the correct headers to build host executables.

Bug: 131911365
Test: unit tests pass
Change-Id: I62e75f60678159fe24619a4bd386b1416f1a5b5d
2019-05-22 14:58:28 -07:00
Tianjie Xu
1536db887f Add UpdaterRuntime class
This class adds a wrapper to the runtime dependent functions. Therefore,
the behavior of update on device stays the same, while simulators can
have their own implementations. Also change the caller side of the
registered updater functions to call these runtime wrappers.

Bug: 131911365
Test: unit tests pass, sideload an update on cuttlefish
Change-Id: Ib3ab67132991d67fc132f27120e4152439d16ac5
2019-05-20 18:03:27 -07:00
Tianjie Xu
3fda5d6508 Skip hashtree computation during block image verify
The hashtree computation is designed to execute after we write all the
bytes to the target block device. And executing the command during block
image verify will almost always fail since we are still on the source
build.

Test: run simulator
Change-Id: If8ebb66739969520367a0815f5f8f89f6fae47cf
2019-05-09 10:58:10 -07:00
Tianjie Xu
58d59129e1 Add Updater class and remove UpdaterInfo
The UpdaterInfo class is merely a collection of pointers and POD types.
We can replace it with a Updater class that has the ownership of the
resources. This also makes this class extensible as we plan to add more
functionality in the host simulator.

Bug: 131911365
Test: unit tests pass, run an update on cuttlefish and check last_install
Change-Id: I07ca5963bbee8ae3cb85ccc184464910aa73d4e4
2019-05-08 23:07:04 -07:00
Elliott Hughes
a86dddbfa5 Track libziparchive API change.
Bug: http://b/129068177
Test: treehugger
Change-Id: Ie5b2b0cff087f2e9e65a4e77c187e3173357f3ad
2019-05-06 10:28:14 -07:00
Tao Bao
782dcc1996 Consolidate the codes that handle reboot/shutdown.
Test: Choose `Reboot system now`, `Power off`, `Reboot to bootloader`
      from recovery UI respectively.
Test: `adb reboot recovery` while under sideload mode.
Change-Id: I0f3d55b80b472178ea4f6970b29cd9df0778b639
2019-04-29 12:12:25 -07:00
xunchang
53158e51d0 Fix potential size overflow in blockimg.cpp
Switch to 64 bit integers since the size of the entire src/tgt images may
not fit in size_t of ILP32.

There are other theoretical overflow cases in memory allocation and I/O
functions. However, they reside within a single transfer command and are
less likely to happen. I will evaluate and address them in separate
cls.

Test: unit tests pass
Bug: 122461124
Change-Id: Ib719ee695920877458fcfaa25c6ac058a5bbabf2
2019-01-17 09:26:12 -08:00
Yifan Hong
8ff84d7cfb updater: add functions to modify dynamic partition metadata
Test: sideload full OTA on cuttlefish
Test: sideload incremental OTA on cuttlefish (that grows
      system, shrinks vendor, and move vendor to group foo)
Test: verify that /cache/recovery/cc46ebfd04058569d0c6c1431c6af6c1328458e4
      exists (sha1sum of "system")

Bug: 111801737

Change-Id: Ibdf6565bc1b60f3665c01739b4c95a85f0261ae5
2019-01-14 14:01:13 -08:00
Yifan Hong
63f5260c6c Create stash dir recursively.
When applying an OTA package onto the device in OTA mode,
if the recovery logs haven't been viewed, there is a chance
that /cache/recovery does not exist. Then, stash creation will
fail. Create stash directories recursively to avoid this error.

Test: without /cache/recovery, sideload the OTA on cuttlefish
Change-Id: I5cc01a067d866476a3594e795dcb5b15649e817b
2019-01-11 15:13:22 -08:00
Tao Bao
22a27f9965 Merge "Use dynamically linked f2fs executables." 2019-01-08 19:49:20 +00:00
Yifan Hong
363d624d53 updater: erase ignores EOPNOTSUPP for BLKDISCARD
Test: sideload on cuttlefish
Bug: 111801737
Change-Id: I784a2142049054f38d6b70c7af7e88a451996d83
2019-01-04 15:24:52 -08:00
Tao Bao
c674dfb584 Use dynamically linked f2fs executables.
It also reduces the space cost for devices using f2fs (e.g. crosshatch).
/sbin/mkfs.f2fs   722560 => /system/bin/make_f2fs   49568
/sbin/sload.f2fs 1182456 => /system/bin/sload_f2fs 150032

Test: Build and boot recovery on crosshatch. Factory reset.
Test: Install a non-A/B OTA package that formats a f2fs partition.
Change-Id: Ibe70c8d91a1d07e1c78ff9eac19b1f7955800161
2018-12-20 14:47:11 -08:00
Tao Bao
3d69f0df96 Clean up the arg setup for exec(3).
Test: Build and boot into recovery on marlin. Factory reset.
Test: Build and install a non-A/B OTA that calls format.
Change-Id: I72416e775e237fc15ca5eff1036175a9eef43b76
2018-12-20 10:46:06 -08:00
Jaegeuk Kim
91e631d4dd make_f2fs: use -g android by default
Bug: 119875846
Change-Id: Ibff18ea6f92620852222fff4073379ec8afd0e10
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-11-21 12:53:09 -08:00
Tao Bao
a2cff952cf updater: Error out on underrun during patching.
Test: Run recovery_component_test on marlin.
Change-Id: If23baf42aeacb48500edabc2eadd2e7119a848da
2018-11-05 08:55:11 -08:00
Tom Cherry
04e4afb9cf Use only signed/unsigned numbers with ParseInt/ParseUint respectively
Test: build
Change-Id: If56b33c9c420237ff441779ba1dbebffd9dae8e3
2018-10-05 14:37:13 -07:00
Tao Bao
5609bc8b34 applypatch: Refactor applypatch().
applypatch() was initially designed for file-based OTA, operating on
individual files. It was later extended to allow patching eMMC targets
as a whole, in favor of block-based updates.

As we have deprecated file-based OTA since Oreo, part of the code in
applypatch() has become obsolete. This CL refactors the related
functions, by removing the obsolete logic and focusing on eMMC targets.

Since this CL substantially changes applypatch APIs, it adds new
functions to avoid unintentionally mixing them together. In particular,
it removes `applypatch()`, `applypatch_check()`, `applypatch_flash()`,
and adds `PatchPartition()`, `PatchPartitionCheck()`, `FlashPartition()`
and `CheckPartition()`. It also replaces the old Edify functions
`apply_patch()` and `apply_patch_check()` with `patch_partition()` and
`patch_partition_check()` respectively.

This CL requires matching changes to OTA generation script (in the same
topic).

Bug: 110106408
Test: Run recovery_unit_test and recovery_component_test on marlin.
Test: `m dist` with non-A/B target. Verify
      /system/bin/install-recovery.sh on device.
Test: `m dist` with non-A/B target using BOARD_USES_FULL_RECOVERY_IMAGE.
      Verify /system/bin/install-recovery.sh on device.
Test: Install an incremental OTA with the new updater and scripts.
Change-Id: Ia34a90114bb227f4216eb478c22dc98c8194cb7f
2018-08-31 09:21:15 -07:00
Tao Bao
43bfa6e429 Enable c++17 in recovery_defaults.
And add the first few users.

Test: Run recovery_unit_test and recovery_component_test on marlin.
Change-Id: Ifdf093d011478b6a1dd0405b0ba48c145b509cc8
2018-08-28 10:49:07 -07:00
Tianjie Xu
22f11205a1 Remove otafault
Now it's less beneficial to inject I/O faults since we don't see many of
them. Remove the library that mocks I/O failures. And switch to android::base
I/O when possible.

Bug: 113032079
Test: unit tests pass
Change-Id: I9f2a92b7ba80f4da6ff9e2abc27f2680138f942c
2018-08-27 17:16:19 -07:00
Tao Bao
f8811bbd3a updater: Add TransferList class.
This would be the top-level class that represents and holds the info
parsed from a transfer list file.

Bug: 112151972
Test: Run recovery_unit_test and recovery_component_test on marlin.
Change-Id: I83b54df9d1411542eeeb8ef4a2db167e97f989c3
2018-08-17 09:37:26 -07:00
Tao Bao
3c8927390e updater: Add SourceInfo::{ReadAll,DumpBuffer,Overlaps}.
Bug: 112151972
Test: Run recovery_unit_test on marlin.
Change-Id: Ica2a7b3c768f5d8ca5d591a9560bca9f8ed847c5
2018-08-16 11:09:35 -07:00
Tao Bao
ef5e38fef0 tests: Move to Android.bp.
Also separate libupdater_defaults out to be shareable.

It turns out the `data` property in `cc_test` doesn't follow symlinks as
LOCAL_TEST_DATA does in Android.mk. This CL creates a filegroup in
top-level Android.bp in order to pick up the testdata for ResourcesTest.

Test: `mmma -j bootable/recovery` with aosp_marlin-userdebug
Test: Run recovery_{unit,component,manual}_test on marlin.
Test: Run recovery_host_test.
Change-Id: I4532ab25aeb83c0b0baa8051d5fe34ba7b910a35
2018-08-14 21:46:45 -07:00
Tao Bao
c205dd9d43 Merge "updater: Move libupdater to Soong." 2018-08-14 16:43:15 +00:00
Tianjie Xu
c0195801dc Merge "Add the hash_tree_info class in Command" 2018-08-14 16:33:10 +00:00
Tianjie Xu
8f64bf635f Add the hash_tree_info class in Command
Add hash_tree_info to represent the hash tree computation arguments in
the transfer commands 'compute_hash_tree'. Also add its parsing code in
the Command class.

Bug: 25170618
Test: unit tests pass
Change-Id: Ie8607968377968e8fb3e58d1af0b8ca315e145be
2018-08-13 17:27:30 -07:00
Tao Bao
673bb6f051 updater: Move libupdater to Soong.
Test: mmma -j bootable/recovery
Test: Run recovery_unit_test and recovery_component_test on marlin.
Change-Id: I2617b87d13c585addf0ed2fbae8c3ce443ea7200
2018-08-13 09:44:48 -07:00
Tianjie Xu
b5bc978432 Merge "Add an updater function to compute hash tree"
am: dbe4420325

Change-Id: If426801d3494be02404c8e4f6d4f064fd6540a4d
2018-08-06 15:36:55 -07:00
Tianjie Xu
69ffa15338 Add an updater function to compute hash tree
The new command is part of the transfer.list and allows us to compute the hash
tree on non-ab devices.

The required arguments for the hash_tree computation are:
  hash_tree_ranges
  source_ranges
  hash_algorithm
  salt_hex
  root_hash

Bug: 25170618
Test: unit tests pass;  run simulator with compute_hash_tree
Change-Id: I8ff0d582cc8adabb8a060db7845f38b35b28e62c
2018-08-06 12:17:50 -07:00
Tao Bao
603b7ed470 Merge "applypatch: Consolidate CacheSizeCheck() and MakeFreeSpaceOnCache()."
am: 624b6b6cd5

Change-Id: I16278b00abcdcc532928b534462ff0762c64c1a2
2018-07-13 12:48:45 -07:00
Tao Bao
5ee25666cc applypatch: Consolidate CacheSizeCheck() and MakeFreeSpaceOnCache().
They are doing exactly the same thing, except for the slightly different
error return value (1 vs -1).

int CacheSizeCheck(size_t bytes);
int MakeFreeSpaceOnCache(size_t bytes_needed);

This CL consolidates the two functions and uses bool as its return type.

// Checks whether /cache partition has at least 'bytes'-byte free space. Returns true immediately
// if so. Otherwise, it will try to free some space by removing older logs, checks again and
// returns the checking result.
bool CheckAndFreeSpaceOnCache(size_t bytes);

Test: Run recovery_unit_test and recovery_component_test on marlin.
Change-Id: I94a96934d2b18713f8f39ad5aa96a02c98d87963
2018-07-13 09:42:19 -07:00
Tao Bao
e089c1a149 Merge "updater: Let read_file() return Value::Type::STRING."
am: ac234b4493

Change-Id: Ia5cc991c7b1d8800aa211349eeb3f8676a056191
2018-07-10 12:38:22 -07:00
Tao Bao
bafd6c7afb updater: Let read_file() return Value::Type::STRING.
It used to return a Value blob to be consumed by sha1_check() (which has
been deprecated). Currently there's no other generic updater function
that works with BLOB Values. This CL changes read_file() to return a
string Value to make it more useful (e.g. allowing equality check).

Test: Run recovery_component_test and recovery_unit_test on marlin.
Change-Id: Iba986ba649030112babefe898f26aa9ffe69eeb7
2018-07-10 10:38:47 -07:00
Tao Bao
17cda674f3 Merge "edify: Rename parse_string to ParseString and let it take std::string."
am: 6b18eb706e

Change-Id: I39aad0a1b39cb89adc405bcd8abd9ccc305ee855
2018-07-10 09:52:45 -07:00
Tao Bao
d8a2c2682a Merge "edify: Remove VAL_INVALID and move ValueType into Value class."
am: 503ff38043

Change-Id: I0a99b445b643892f147cde48ae312e87674ba96d
2018-07-10 09:50:33 -07:00
Tao Bao
6b18eb706e Merge "edify: Rename parse_string to ParseString and let it take std::string." 2018-07-10 16:38:08 +00:00
Tao Bao
d8d514fa33 edify: Rename parse_string to ParseString and let it take std::string.
Also simplify the helper function expect() in {edify,updater}_test.cpp.

Test: Run recovery_component_test on marlin.
Change-Id: If54febba4b5013f6d71546318a1ca6b635204ac8
2018-07-10 06:27:50 +00:00
Tao Bao
511d759627 edify: Remove VAL_INVALID and move ValueType into Value class.
Test: mmma -j bootable/recovery
Test: Run recovery_component_test and recovery_unit_test on marlin.
Change-Id: I4b240e3e771c387b9694be9c0f2f74e0265ab4cb
2018-07-09 23:20:30 -07:00
Tao Bao
e2136c46cb Merge "updater: Remove the support for sha1_check()."
am: fbc0f6062c

Change-Id: I487b1f9bd35335f39c1dd3ab7a4e5dfe722b1863
2018-07-09 17:17:36 -07:00
Tao Bao
0b58e9a011 updater: Remove the support for sha1_check().
The matching edify function has been removed from EdifyGenerator [1]. In
theory device-specific releasetools script may still use this function,
but it no longer looks useful. Because a) we should use range_sha1()
when asserting the SHA-1 hash of a block device; b) we should look into
the contents when asserting a text file.

[1] https://android-review.googlesource.com/c/platform/build/+/714104

Test: Run recovery_component_test on marlin.
Test: Code search shows no active user.
Change-Id: Id39439101534fb89cf8c5cea80a4b758c8a1a60d
2018-07-09 12:38:19 -07:00