Commit graph

449 commits

Author SHA1 Message Date
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
Tao Bao
b450952d6a Merge "updater: Add ABORT command."
am: c059b6c1c6

Change-Id: Ib469e055e7a02fb870158a2ae38a83ea6c80ad7d
2018-07-09 10:49:07 -07:00
Tao Bao
91a649ab62 updater: Add ABORT command.
This will be used for testing purpose only, replacing the previously
used "fail", to intentionally abort an update.

As we're separating the logic between commands parsing and execution,
"abort" needs to be considered as a valid command during the parsing.

Test: recovery_unit_test and recovery_component_test on marlin.
Change-Id: I47c41c423e62c41cc8515fd92f3c5959be08da02
2018-07-07 04:12:19 +00:00
Tianjie Xu
65419746cb Merge "No longer print hash for stashed blocks during verification of retry"
am: 0a84d7260b

Change-Id: I567bb581faa27a6ba1a4834a8cbe82f8c4052a31
2018-07-03 13:36:21 -07:00
Tianjie Xu
3c5958f62d No longer print hash for stashed blocks during verification of retry
During block verification, load stash reads from the source blocks on
the device instead of the stashed files. And for interrupted update,
it's pretty common that the source blocks has already been overwritten
by subsequent commands.

In that case the hash printing is mostly useless. Moreover we should have
already printed the hash when the first update failed.

Bug: 80241799
Test: Unit tests pass. No longer prints mismatching stashed source blocks on retry.
Change-Id: I4effe684280b0325199f6cc4b2cc26e91295c2d7
2018-07-02 16:42:09 -07:00
Tao Bao
42f96e5516 Merge "updater: Check the number of args in Command::Parse."
am: 95b8d2b064

Change-Id: Ic78e44cdca8a1c394f63b99efdcfecea8a3fdd71
2018-06-25 20:42:01 -07:00
Tao Bao
e6604307f6 Merge "updater: Add Command parsing codes."
am: afc2962e60

Change-Id: I24cc3beca7c75786cbfad37ab273139fd2d1ca2f
2018-06-25 20:36:08 -07:00
Tao Bao
92f339372c updater: Check the number of args in Command::Parse.
Additionally checks for excess args when parsing ERASE, FREE, NEW, STASH
and ZERO. Note that the check for MOVE, BSDIFF, IMGDIFF has been covered
in Command::ParseTargetInfoAndSourceInfo.

Test: Run recovery_unit_test on marlin.
Change-Id: Ic8bc9b7a8dcf98f1f8db2e259607564508726857
2018-06-25 13:39:33 -07:00
Tao Bao
6a7e4af7c6 updater: Add Command parsing codes.
The added codes are not used in the updater yet. The switch will happen
in subsequent CLs.

Test: Run recovery_unit_test and recovery_component_test on marlin.
Change-Id: I1ae8a233280f02c2171b43ef028bdccdacb39c59
2018-06-25 13:39:29 -07:00
Tao Bao
839c40513a Merge "applypatch: {Load,Save}FileContents and ParseSha1 take std::string."
am: b4181566f9

Change-Id: I9fb25b58eaa23443d24c3d6ed75d52ac96c7788f
2018-06-25 07:44:17 -07:00
Tao Bao
b4181566f9 Merge "applypatch: {Load,Save}FileContents and ParseSha1 take std::string." 2018-06-25 14:35:03 +00:00
Jiyong Park
681ae40d41 Merge "e2fsdroid and mke2fs are dynamic executable in recovery partition"
am: 9b5d4ea20f

Change-Id: I017a76c320f29baff3183b0156c1fdf2deed66bf
2018-06-20 15:24:29 -07:00
Treehugger Robot
9b5d4ea20f Merge "e2fsdroid and mke2fs are dynamic executable in recovery partition" 2018-06-20 22:16:21 +00:00
Tao Bao
8dc704930b applypatch: {Load,Save}FileContents and ParseSha1 take std::string.
Test: mmma -j bootable/recovery
Test: Run recovery_component_test on marlin.
Change-Id: Ifcf244346a88dac833d91b169a4c2aee1fe677f1
2018-06-20 13:21:16 -07:00
Tao Bao
ae3e472a43 Merge "updater: Defer the creation of the new data writer."
am: ddc81680e6

Change-Id: Ibfcc5b765103b41316549ee45636ebf4c377cf84
2018-06-20 09:28:19 -07:00
Jiyong Park
69364fe553 e2fsdroid and mke2fs are dynamic executable in recovery partition
The two utilities are now converted to dynamic executables as shared
libraries are supported in recovery mode.

As part of the conversion, their location has moved from /sbin to
/system/bin. Reflect the change in the program 'recovery'

Bug: 79146551
Test: adb reboot recovery, and select 'Wipe data/factory reset'. The
data partition is formatted and there is no selinux denial.

Change-Id: Ie7cfc4c50ab1e6767e4a5170533ccf826ec7d7f3
2018-06-20 14:24:05 +09:00
Tao Bao
0a883c18f6 updater: Defer the creation of the new data writer.
This avoids leaving the created new data writer thread unjoined, in the
presence of transfer list parsing errors, or the early exit case on
`total_blocks == 0`.

Also fix a minor issue when dumping the errno on pthread_create error
(pthread_create returns the error number, as opposed to setting errno).

Test: Run recovery_component_test on marlin.
Change-Id: Icfac27fef0c64736eb8c76264da73c223b4960cb
2018-06-18 13:00:43 -07:00
Tao Bao
941d3ab754 Merge "updater: Drop the 'overlap' parameter in LoadSrcTgtVersion3()."
am: 0eb10b382a

Change-Id: I0bba5a09ac62b7c152d22d72f0432868008592cc
2018-06-08 16:50:38 -07:00
Xin Li
d8a411c90a Merge "Merge pi-dev-plus-aosp-without-vendor into stage-aosp-master" into stage-aosp-master 2018-06-08 23:09:59 +00:00
Tao Bao
4a13508f0b updater: Drop the 'overlap' parameter in LoadSrcTgtVersion3().
Test: Run recovery_component_test on marlin.
Change-Id: I93afca891c5c9c1a351c907b023cd20c4704a66a
2018-06-08 12:53:31 -07:00
Tao Bao
ffede3e8d9 updater: Remove the redundant check on line count.
Test: recovery_component_test on marlin.
Change-Id: I2ac2bd47469d1aec8a97a8c4ed0fe80ffd65c95b
2018-06-07 10:43:24 -07:00
Tao Bao
a0e3e6f489 Merge "updater: Replace the reference arguments with pointers." am: cef8431fed
am: 9c22d924e8

Change-Id: Ibb4ee1d240768e2cb941d1c4c89e5584c126290b
2018-06-06 18:55:06 -07:00
Tao Bao
de3bbb81c2 updater: Replace the reference arguments with pointers.
As suggested by the style guide
(https://google.github.io/styleguide/cppguide.html#Reference_Arguments),
all parameters passed by reference must be labeled const. This CL moves
most of the non-const references in blockimg.cpp to pointers, except for
the CommandParameters& parameter in PerformCommand* functions, which
will be handled in separate CLs.

Test: mmma -j bootable/recovery
Test: Run recovery_component_test on marlin.
Change-Id: I84299208e9a1699f5381fb2228d4120f0c8dacb3
2018-06-04 23:14:54 -07:00
Tao Bao
98dc45f0f0 Merge "tests: Add ResumableUpdaterTest." am: a21a63bf56
am: 1d33962b86

Change-Id: I558dc711f65a970195daa60d741fa83d375c7cb0
2018-06-04 16:31:37 -07:00
Tao Bao
c0299edd46 tests: Add ResumableUpdaterTest.
This is a stress test that instantiates multiple testcases that
interrupt a BBOTA update at every transfer command. Each testcase
asserts the last_command_file after the interruption, verifies the
update resumability, then resumes the update and asserts the updated
image.

The transfer list in the testcase covers most of the transfer commands
(stash/free/move/bsdiff/zero/new), as well as some special pattern like
having duplicate stash ids.

This CL also addresses one issue in the updater code, by resetting the
stash_map before each run. The stash map should be valid only per
block_image_verify/block_image_update run. Having leftover may cause
issue in subsequent runs, in particular when calling block_image_verify
after a previous run of block_image_{update,verify}.

Test: Run recovery_component_test on marlin.
Change-Id: I6f9a0368d194a754ce41a9c9819c6d5be2657248
2018-06-04 16:19:45 +00:00
Tao Bao
8d6905d952 Merge "updater: Drop the 'blocks' parameter in LoadStash()." am: 0b80ba14d7
am: 838f30a8f7

Change-Id: I7eac9d3a708fc70c5dc8c73c4b7a05c861c37cc2
2018-05-31 17:14:33 -07:00
Tao Bao
64957ce4b1 updater: Drop the 'blocks' parameter in LoadStash().
None of the callers actually uses the value.

(Even in the earlier versions, e.g. the one in M, the value wasn't used
either.)

Test: Run recovery_component_test on marlin.
Change-Id: I53e61a1afa211f71a200889ed3aa4046763b46ea
2018-05-30 16:34:24 -07:00
Tao Bao
7096f6b23c Merge "updater: Add Commmand class to manage BBOTA commands." am: a488bd992f
am: 89d65805c6

Change-Id: Ief7bf42681ebffe92ac78d523b9f796fbca56c17
2018-05-29 12:43:15 -07:00
Tao Bao
c3901231ce updater: Add Commmand class to manage BBOTA commands.
Move the commands map parsing out of PerformBlockImageUpdate(), as this
can be done more easily by the caller.

The goal (not done in this CL) is to decouple command parsing logic from
the performers. This allows (a) focusing on the command logic in the
performer; and (b) extending BBOTA commands syntax separately.

Test: Run recovery_unit_test and recovery_component_test.
Change-Id: Ife202398a7660b152d84a3ba17b90f93d19c55f2
2018-05-25 15:26:42 -07:00
Tao Bao
09dbf50713 Merge "updater: Use a bool to indicate if allowed to skip a command." am: 3a8b348936
am: 082733b555

Change-Id: Ia8bd235b2cc4a2a53339e848c34cb89c4af0621f
2018-05-21 18:46:04 -07:00
Tao Bao
b8a04272c8 Merge "updater: Clean up the header lines computation." am: a5735e9b5f
am: 1e29bb6717

Change-Id: I48a43bb615d9850375774b6827bc34352b0b7c76
2018-05-21 17:05:04 -07:00
Tao Bao
26efb0ae3a updater: Use a bool to indicate if allowed to skip a command.
This avoids the signedness issue, and makes the code more readable.

Test: mmma bootable/recovery
Test: Run recovery_component_test.
Change-Id: I01c3a0357887cfd7c9d4aba4239ef650cfa18388
2018-05-21 15:05:53 -07:00
Tao Bao
ab20706a84 updater: Clean up the header lines computation.
It no longer needs to be conditional, as we've removed the support for
BBOTA v1/v2.

Test: mmma bootable/recovery
Change-Id: I881de8afa38cc5b41b48e6d48d85170699ea5eb4
2018-05-21 14:48:49 -07:00
Tianjie Xu
567570954e Merge "Last command file should be updated after a command finishes" am: 6dfc54cae1
am: 45b7dbea74

Change-Id: Ic9da282f5b09e36b0b64c56f595b25ebc6cf60c6
2018-05-16 16:05:19 -07:00
Tianjie Xu
c2b2bb5d78 Last command file should be updated after a command finishes
The last command file has the last executed stash command by convention.
So we should update the file after we actually finishes executing the command;
instead of after loading src/tgt.

Bug: 79756267
Test: unit tests pass
Change-Id: I4535b5836e7eb13b3abe3d02f9f362ec5e9ec969
2018-05-15 21:05:30 -07:00
Tao Bao
6ca5e0c252 Merge "updater: Skip an updated partition on retry." am: 0ffe13b56f
am: 83906f75bb

Change-Id: I7b7b4d974bb639be0bc97ef03a63f81ceaaae76d
2018-05-07 18:21:17 -07:00
Tao Bao
0ffe13b56f Merge "updater: Skip an updated partition on retry." 2018-05-08 00:57:14 +00:00
Tao Bao
13784d1511 Merge "updater: Fix an issue when resuming an update." am: 1dc9e2ddef
am: 47bf5e68e6

Change-Id: I2e555a2534bb0e14b520aa4c9036aaa7d73407c4
2018-05-07 17:36:32 -07:00
Tao Bao
98f875eee7 updater: Fix an issue when resuming an update.
We cannot skip "new" commands while resuming an update with
last_command_file, because they read in the data sequentially from the
package.

Bug: 69858743
Test: Interrupt an update that has new commands. Check the update log.
Change-Id: I05fb67246f5ea3ba2a0f78f10255c0d9b0bc2f5a
2018-05-07 22:14:45 +00:00
Tao Bao
864c668dd2 updater: Skip an updated partition on retry.
Prior to the change, the BBOTA updater would try to re-run all the
commands for a given partition on retry, including creating stashes
according to the list of commands. This could fail a retry when the
previous update had moved on to next stage, with leftovers in /cache.

This CL creates a marker on /cache upon successfully updating a
partition. The update commands will be skipped when trying to apply
updates on an updated partition. Note that the marker is expected to be
removed while doing a normal boot (in particular, handled by
RecoverySystem#handleAftermath). If that didn't happen, the updater
would also remove the marker before starting next fresh update.

Alternatively, we can achieve the same goal by changing the OTA script,
which needs to additionally compare the checksum against the target
build. For example,

  range_sha1("/system", "ranges") == SHA1_of_updated_system ||
  block_image_update("/system");

The downside is that we need to pay that cost on each install, as the
edify script doesn't support caching the result in a variable.

Bug: 79165963
Test: Simulate the process on device (by triggering a reboot while
      updating /vendor). Check the update log and result.
Change-Id: I731031fa336133e1221b33edfc469969706e8091
2018-05-07 15:05:00 -07:00
android-build-prod (mdb)
13415d9138 Merge changes I1cc5d702,I32ab9854 am: 420f7f8df4
am: c4ba6b738f

Change-Id: I7696fb68e13e214ee830b9de1bf66dc6f1cac691
2018-05-04 10:43:36 -07:00
Tao Bao
2c52639d01 Move reboot() from common.h into otautil/sysutil.h.
This breaks the dependency on common.h (which belongs to
recovery/librecovery) from librecovery_ui. reboot() is now owned by
libotautil, which is expected to be a leaf node to be depended on.

With the change, recovery and updater also share the same reboot() code
now.

Test: mmma -j bootable/recovery
Change-Id: I1cc5d702cfe49302048db33d31c9c87ddc97ac71
2018-05-03 23:18:38 -07:00
Tao Bao
17054c051a otautil: Rename dir/sys/thermal utils.
Test: mmma -j bootable/recovery
Change-Id: I32ab98549e91f993364306e4a88dc654221b3869
2018-05-03 23:17:29 -07:00
android-build-prod (mdb)
1c1737b660 Merge "Merge libmounts into libotautil." am: 686353215f
am: cddf5dbf67

Change-Id: I57bcd1195084d2e60861aa5b410e2eb50c41c3c3
2018-04-28 09:55:49 -07:00
Tao Bao
9a319f01f8 Merge libmounts into libotautil.
Export its header (mounts.h) from there, and drop the dot dot dependency
from libupdater / updater.

Test: mmma bootable/recovery
Test: recovery_component_test
Change-Id: Ic26a6b9b78a34dbe1f178b138f3abaafffbec44c
2018-04-27 21:13:57 -07:00
android-build-prod (mdb)
7acf21c34a Merge "Rename CacheLocation to Paths." am: 49c7f1cec3
am: ce562bacfd

Change-Id: I5b084052f3f84a6e58e1267e58a125a7ed47080e
2018-04-26 09:43:25 -07:00
Tao Bao
641fa97def Rename CacheLocation to Paths.
We have a general need for overriding more paths (e.g. "/tmp"), mostly
for testing purpose. Rename CacheLocation to Paths, and use that to
manage TEMPORARY_{INSTALL,LOG}_FILE.

Test: mmma -j bootable/recovery
Test: recovery_component_test
Change-Id: Ia8ce8e5695df37ca434f13ac4d3206de1e8e9396
2018-04-25 21:46:00 -07:00
android-build-prod (mdb)
beeef60446 Merge "updater: Remove an unneeded strdup()." am: ab3c24bd51
am: 76f0edc05e

Change-Id: I0836af0b9ba9485c1908303b496fb86899aa4f43
2018-04-25 11:09:02 -07:00
Tao Bao
188f3a5bf8 updater: Remove an unneeded strdup().
StringValue() makes a copy of the arg.

Test: mmma bootable/recovery
Change-Id: I1002994e7496c840aa05c785019bdeca281f467e
2018-04-25 07:16:00 -07:00
Tao Bao
0d6de12e68 Merge "applypatch: Drop the SHA_CTX parameter in Apply{BSDiff,Image}Patch." am: bcb015239c
am: 4cf3bc1875

Change-Id: I211d0252ae33cc8fc203360de8d982c2a3b597ae
2018-04-20 11:15:26 -07:00
Tao Bao
8b0b0f1f02 applypatch: Drop the SHA_CTX parameter in Apply{BSDiff,Image}Patch.
As they're accepting the SinkFn callback, it makes more sense to leave
the work to their callers.

Test: mmma -j bootable/recovery
Test: Run recovery_component_test on marlin.
Test: No other active user of the two functions.
Change-Id: I8d67b38ce037925442296f136b483e0c71983777
2018-04-20 09:27:50 -07:00
Jaegeuk Kim
2e5dc84d51 recovery: enable fsverity feature bit
Bug: 74604441
Bug 67380979
Change-Id: Iab1cc9aef356f0ddf6e2491578a2bd53009182ce
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-06 10:17:47 -07:00
Jaegeuk Kim
fc66f3fbc6 install: mkfs.f2fs: specify sector size for target image size
The total sectors that we want to format is used in different meanings from
various users. This notifies its size based on 512 bytes explicitly.

Bug: 76407663
Change-Id: I20687b40a1733d3b459a45f8b64a338c37a7bc95
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-04 21:16:19 -07:00
Jaegeuk Kim
1224544806 install: mkfs.f2fs: specify sector size for target image size
The total sectors that we want to format is used in different meanings from
various users. This notifies its size based on 512 bytes explicitly.

Bug: 76407663
Change-Id: I20687b40a1733d3b459a45f8b64a338c37a7bc95
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2018-04-04 21:14:01 -07:00
Tianjie Xu
01daebbe68 Set the update locations to default in CacheLocation's constructor
Otherwise the applypatch executable will fail to back up the source
file to /cache when patching the recovery image.

Bug: 74198354
Test: run applypatch from boot to recovery
(cherry picked from commit b4e3a370bf)

Change-Id: I37b7fd88d66ab49ef953d4b7dca22577bd1472e1
2018-03-08 14:40:09 -08:00
Tianjie Xu
b4e3a370bf Set the update locations to default in CacheLocation's constructor
Otherwise the applypatch executable will fail to back up the source
file to /cache when patching the recovery image.

Bug: 74198354
Test: run applypatch from boot to recovery
Change-Id: I6e5b9cd06d6ed0b26066b779a348437ecf984b92
2018-03-08 14:24:02 -08:00
Tianjie Xu
3bbb20f557 Add a singleton CacheLocation to replace the hard coded locations
This class allows us to set the following locations dynamically:
cache_temp_source, last_command_file, stash_directory_base.

In the updater's main function, we reset the values of these variables
to their default locations in /cache; while we can set them to temp
files in unit tests or host simulation.

Test: unit tests pass
Change-Id: I528652650caa41373617ab055d41b1f1a4ec0f87
2018-02-28 11:19:11 -08:00
Tianjie Xu
c242084539 Fix the behavior of undefined commands in BlockImageVerify
In BlockImageVerify some commands are undefined, e.g. "erase", "new",
"zero". And we should not error out if the corresponding function
pointer of these commands is null; otherwise we will fail the
verification.

The old code is:
if (cmd->f != nullptr && cmd->f(params) == -1)
  return false;

In the last_command_file change the logic was wrongly modified to
if (cmd->f == nullptr)
  return false;
...
if (cmd->f(params) == -1)
  return false;

Test: sideload an incremental OTA twice on bullhead
Change-Id: I2561c365badb850da0e416629ccd61f0df7da5d7
2018-02-27 23:04:14 -08:00
Tianjie Xu
5419ad31e7 Reorder the functions in updater/install.cpp
There is no logical change to the file; merely the function definition
reorder and some comestic change to make the future review easier.

Test: mma
Change-Id: I7ffe952f8c78e840f10aa6bfad0c4b5a58e29896
2018-02-12 11:55:05 -08:00
Tianjie Xu
284752e2bc Log the last command to cache
When performing an update, save the index and cmdline of the current
command into the last command file if this command writes to the stash
either explicitly of implicitly. This mitigates the overhead to update
the last command file for every command. I ran a simple test on angler
and the time to update 1000 times is ~2.3 seconds.

Upon resuming an update, read the saved index first; then
  1. In verification mode, check if all commands before the saved index
     have already produced the expected target blocks. If not, delete the
     last command file so that we will later resume the update from the
     start of the transfer list.
  2. In update mode, skip all commands before the saved index. Therefore,
     we can avoid deleting stashes with duplicate id unintentionally;
     and also speed up the update.

If an update succeeds or is unresumable, delete the last command file.
Bug: 69858743
Test: Unittest passed, apply a failed update with invalid cmd on angler
and check the last_command content, apply a failed update with invalid
source hash and last_command is deleted.
Change-Id: Ib60ba1e3c6d111d9f33097759b17dbcef97a37bf
2018-02-06 16:16:49 -08:00
Tianjie Xu
5ad802839d Avoid overwrite of the error message in AbortFn
The AbortFn() used to overwrite the error message, hiding the real
failure reported in ErrorAbort(). And we will miss the failure in
the script patterns like 'blockimageupdate() || abort()'

We will ensure there's one line break at the end of ErrorAbort's
error message; and append to the existing error message when calling
abort().

Test: Message from ErrorAbort shows up in the log
Change-Id: I3aebd06629c5129330250c7fe5e8cdead2ae85bc
2018-01-29 11:42:59 -08:00
Jaegeuk Kim
c1c7311b8a add sload.f2fs for recovery format
Change-Id: Iddfe54b2b36f2d531925cbe61c98dbfb4903c0d1
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-12-04 20:27:49 -08:00
Tianjie Xu
99b73be3a8 Detect interrupted update due to power off
An interrupted update may stash extra blocks in /cache, leading to a
failure when checking the cache size. We can save the incremented
retry_count in the BCB before installing the update; and distinguish
a fresh update from an interrupted one this way.

Bug: 68679601
Test: An interrupted update reapplies successfully.
Change-Id: Ic1403e1fd25a937c91ef34c14b92a0f6c8f1c0f4
2017-11-30 16:25:47 -08:00
Jaegeuk Kim
1a8bb0f542 recovery: format f2fs with encrypt/quota
Change-Id: Ia393b7b78b45f09964449ec0e255aa26bb3b8ddf
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
2017-11-13 14:05:00 -08:00
Tao Bao
1e0941f4f6 applypatch: Change the patch parameter to const Value& in Apply{BSDiff,Image}Patch.
It used to be "const Value*", but nullptr won't be a valid input.

Test: recovery_host_test; recovery_component_test
Change-Id: I904b5689ac3e64504088bf0544c9fb5d45a52243
2017-11-10 12:18:34 -08:00
Tao Bao
6798315327 otautil: Remove the aborts in RangeSet::Parse().
We used to CHECK and abort on parsing errors. While it works fine for
the updater use case (because recovery starts updater in a forked
process and collects the process exit code), it's difficult for other
clients to use RangeSet as a library (e.g. update_verifier).

This CL switches the aborts to returning empty RangeSet instead. Callers
need to check the parsing results explicitly.

The CL also separates RangeSet::PushBack() into a function, and moves
SortedRangeSet::Clear() into RangeSet.

Test: recovery_unit_test
Test: Sideload an OTA package with the new updater on angler.
Test: Sideload an OTA package with injected range string errors. The
      updater aborts from the explicit checks.
Change-Id: If2b7f6f41dc93af917a21c7877a83e98dc3fd016
2017-11-07 12:50:02 -08:00
Jin Qian
502fd1c5e8 recovery: remove make_ext4fs from updater
Bug: 64395169
Change-Id: I6f6a4f82b225435c6ad5c828e110fa135e6f7579
2017-11-03 13:54:59 -07:00
Tianjie Xu
5450c84ba4 Finish the new data receiver when update fails
The thread to receive new data may still be alive after we exit
PerformBlockImageUpdate() upon failures. This caused memory corruption
when we run the unittest repeatedly. Set the receiver_available flag
to false and make sure the receiver exits when the update fails.

Bug: 65430057
Test: unittests passed with tsan
Change-Id: Icb232d13fb96c78262249ffbd29cdbe5b77f1fce
2017-10-20 11:14:56 -07:00
Tao Bao
99f0d9e52b Drop -Wno-unused-parameter.
The only one left is libedify. Will handle that in a separate CL.

Test: mmma bootable/recovery
Change-Id: I732a5f85229da90fd767bee2e46c5c95f529c396
2017-10-11 16:56:12 -07:00
Tao Bao
09e468f84c Move rangeset.h and print_sha1.h into otautil.
Also drop the "bootable/recovery" path in LOCAL_C_INCLUDES from
applypatch modules.

Test: lunch aosp_{angler,bullhead,fugu,dragon,sailfish}-userdebug;
      mmma bootable/recovery
Change-Id: Idd602a796894f971ee4f8fa3eafe36c42d9de986
2017-10-10 15:52:11 -07:00
Tao Bao
1fc5bf353a Revert "Revert "Move error_code.h into otautil.""
This reverts commit 26436d6d60 to re-land
"Move error_code.h into otautil.".

This way it stops requiring relative path ".." in LOCAL_C_INCLUDES
(uncrypt and edify). Soong doesn't accept non-local ".." in
"local_include_dirs".

This CL needs to land with device-specific module changes (e.g. adding
the dependency on libotautil).

Test: lunch aosp_{angler,bullhead,dragon,fugu,sailfish}-userdebug;
      mmma bootable/recovery
Change-Id: If193241801af2dae73eccd31ce57cd2b81c9fd96
2017-10-09 14:07:54 -07:00
Tao Bao
0bf20d5133 Don't include "error_code.h" in edify/expr.h.
Use forward declartion to avoid pull in the module that contains
error_code.h (trying to move it into libotautil). Otherwise all the
modules that include "edify/expr.h" need to depend on the module that
exports error_code.h.

.cpp sources should include "error_code.h" explicitly to use the enums.

Test: lunch aosp_{angler,bullhead,dragon,fugu,sailfish}-userdebug;
      mmma bootable/recovery
Change-Id: Ic82db2746c7deb866e8cdfb3c57e0b1ecc71c4dc
2017-10-05 12:46:18 -07:00
Tao Bao
26436d6d60 Revert "Move error_code.h into otautil."
This reverts commit 623fe7e701.

Reason for revert: Need to address device-specific modules.

Change-Id: Ib7a4191e7f193dfff49b02d3de76dda856800251
2017-10-05 17:16:31 +00:00