Commit graph

28 commits

Author SHA1 Message Date
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
Tao Bao
13446c032b otautil: Only build the needed files for host build.
This avoids unnecessarily breaking mac build.

Test: `mmma -j bootable/recovery` on Linux and macOS.
Change-Id: I1dc00364c895866a4757c2a43beb3432ae1e4113
2018-05-03 23:16:03 -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
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
Tianjie Xu
d5fbcc1ba9 Remove the old log files if cache space is insufficient for OTA
We set the limit of the max stash size to 80% of cache size. But the
cache space can still be insufficient for the update if the log files
occupy a large chunk of /cache. So remove the old logs for now to make
room for the update.

Bug: 77528881
Test: unit tests pass
Change-Id: Ia8bcb0ace11f8164ad9290bfb360e08e31d282cb
2018-04-13 11:33:47 -07: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
Tao Bao
160514bf2b Load-balancing update_verifier worker threads.
Prior to this CL, the block verification works were assigned based on
the pattern of the ranges, which could lead to unbalanced workloads. This
CL adds RangeSet::Split() and moves update_verifier over.

a) For the following care_map.txt on walleye:
system
20,0,347,348,540,556,32770,33084,98306,98620,163842,164156,229378,229692,294914,295228,524289,524291,524292,524348,529059
vendor
8,0,120,135,32770,32831,94564,98304,98306

Measured the time costs prior to and with this CL with the following
script.

$ cat test_update_verifier.sh
  #!/bin/sh

  adb shell stop
  adb shell "cp /data/local/tmp/care_map.txt /data/ota_package/"
  for i in $(seq 1 50)
  do
    echo "Iteration: $i"
    adb shell "bootctl set-active-boot-slot 0"
    adb shell "echo 3 > /proc/sys/vm/drop_caches"
    adb shell "time /data/local/tmp/update_verifier"
    sleep 3
  done

Without this CL, the average time cost is 5.66s, while with the CL it's
reduced to 3.2s.

b) For the following care_map.txt, measured the performance on marlin:
system
18,0,271,286,457,8350,32770,33022,98306,98558,163842,164094,196609,204800,229378,229630,294914,295166,501547
vendor
10,0,42,44,85,2408,32770,32806,32807,36902,74242

It takes 12.9s and 5.6s without and with the CL respectively.

Fixes: 68553827
Test: recovery_unit_test
Test: Flash new build and trigger update_verifier. Check the balanced
      block verification.
Change-Id: I5fa4bf09a84e6b9b0975ee5f522724464181333f
2017-11-08 23:04:28 -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
Tao Bao
4568582002 otautil: Move RangeSet implementation into rangeset.cpp.
Since it has grown much larger, users of the header shouldn't compile
and carry their full copies.

Also add missing header includes in imgdiff.cpp and imgdiff_test.cpp.

Test: mmma bootable/recovery
Test: recovery_unit_test; recovery_component_test; recovery_host_test
Change-Id: I88ca54171765e5606ab0d61580fbc1ada578fd7d
2017-10-16 11:28:18 -07:00
Tao Bao
b9bffdffb9 otautil: #include <errno.h> for TEMP_FAILURE_RETRY.
Test: mmma bootable/recovery
Change-Id: I5959303528c6f704f10ce153f6fcb2054ce35b1e
2017-10-11 12:15:49 -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
c13d2ec772 otautil: Fix mac build.
bootable/recovery/otautil/SysUtil.cpp:103:19: error: use of undeclared identifier 'mmap64'; did you mean 'mmap'?
  void* reserve = mmap64(nullptr, blocks * blksize, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0);
                  ^~~~~~

Test: mmma bootable/recovery
Change-Id: I22d7dc4d994069201e5a633cec21421e2c4182fa
2017-10-10 10:56:09 -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
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
Tao Bao
623fe7e701 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".

Test: mmma bootable/recovery
Change-Id: Ia4649789cef2aaeb2785483660e9ea5a8b389c62
2017-10-04 08:55:24 -07:00
Tao Bao
cfe53c2c01 otautil: Export headers.
Test: mmma bootable/recovery
Change-Id: Ic01b68e2a394d578fc9fc09da2dabe9061b98122
2017-10-03 14:41:32 -07:00
Tao Bao
ac3d1edca0 otautil: Clean up dirCreateHierarchy().
- Changed to std::string based implementation (mostly moved from the
  former make_parents() in updater/install.cpp);
- Removed the timestamp parameter, which is only neeed by file-based OTA;
- Changed the type of mode from int to mode_t;
- Renamed dirCreateHierarchy() to mkdir_recursively().

Test: recovery_unit_test passes.
Test: No external user of dirCreateHierarchy() in code search.
Change-Id: I71f8c4b29bab625513bbc3af6d0d1ecdc3a2719a
2017-07-27 10:33:07 -07:00
Tao Bao
7934985e0c otautil: Delete dirUnlinkHierarchy().
This function has become obsolete since we've removed file-based OTA
support (it was needed by 'delete_recursive' edify function earlier).

Test: mmma -j bootable/recovery
Test: Code search shows no active user of the function.
Change-Id: If6faaa759d4c849b79acba4e6adb82baadc89f7a
2017-07-24 20:35:48 -07:00
Tianjie Xu
53c38b1538 kill package_extract_dir
It's only used by file-based OTA which has been deprecated for O.

Test: mma
Change-Id: I439c93155ca94554d827142c99aa6c0845cc7561
2017-05-23 17:09:45 -07:00
Steven Moreland
f3ae55a167 otautil: Android.mk -> Android.bp
Test: flash and boot recovery on internal angler
Change-Id: Id8845b4b422d0078b251333eb6d30ce14771ef10
2017-05-09 16:09:41 -07:00
Tianjie Xu
f38401a27c Update the comment for obsolete symlink handling .
Symlink is a filebased OTA feature, and the corresponding updater
function has been removed in
https://android-review.googlesource.com/#/c/350357/.

Also the only place where we call "package_extract_dir()" is to unpack
some bootloader dir in vendor's code. We plan to remove it also in a
separate bug.

Bug: 31917448
Test: mma
Change-Id: I3986d60958e64e0d5d8fa5f5bd508c579fb7fa2c
2017-05-03 23:34:42 +00:00
Tao Bao
b656a154ea Move sysMapFile and sysReleaseMap into MemMapping class.
Test: recovery_component_test
Test: recovery_unit_test
Test: Apply an OTA on angler.
Change-Id: I7170f03e4ce1fe06184ca1d7bcce0a695f33ac4d
2017-05-01 21:51:54 -07:00
Tianjie Xu
3ee2b9db5a Log temperature during OTA update
Log the maximum temperature as well as the start/end temperature of an
update to last_install. Check the temperature at the end of each
block_image_update(verify). To get the maximum temp, we iterate through
/sys/class/thermal/thermal_zone*/temp and find the maximum value
present.

Bug: 32518487
Test: temperature logs in last_install
Change-Id: Iaf22a9fbc5b18611bbc5320ffea995417872e514
2017-03-28 11:28:47 -07:00
Tao Bao
14b61e7b96 otautil: Clean up obsolete includes.
external/zlib and external/safe-iop/include were used by Zip.c, which
became obsolete after [1].

Removing
 - <assert.h>: we no longer call assert(3);
 - <limits.h>: we no longer use PATH_MAX;
 - <stdio.h>: we don't need FILE anymore;
 - <stdlib.h>: no more malloc(3)/calloc(3);
 - <unistd.h>: was once needed for lseek(2);
 - <string.h>: no more memset(3).

Adding
 - <stdint.h> for SIZE_MAX.

[1] commit 8cf5c8f60f: "Replace minzip
with libziparchive".

Test: `mmma bootable/recovery`
Change-Id: I349e909ba83d0f6ade5f92856ce3934f29fdca6c
2016-11-08 13:39:12 -08:00
Tao Bao
c3292f3fcb otautil: Clean up SysUtil.cpp.
Add unit testcases for sysMapFile().

Test: recovery_unit_test passes.
Test: Build and use the new recovery image to sideload a package.
Test: Build and use the new recovery image to install an update.

Change-Id: I77d8f1ea151ab513865d992c256ba93a1fcb51a4
2016-11-07 13:00:38 -08:00
Tianjie Xu
8cf5c8f60f Replace minzip with libziparchive
Clean up the duplicated codes that handle the zip files in
bootable/recovery; and rename the library of the remaining
utility functions to libotautil.

Test: Update package installed successfully on angler.
Bug: 19472796

Change-Id: Iea8962fcf3004473cb0322b6bb3a9ea3ca7f679e
2016-10-17 17:41:51 -07:00