Commit graph

220 commits

Author SHA1 Message Date
katao
9a6f520419 Bugfix:updater always retry apply patch failed,when memcpy failed.
https://code.google.com/p/android/issues/detail?id=230602
On the second attempt, open the file with O_RDONLY,
which causing a write failure。

Change-Id: If89165b8c7619fe25722073a46b3cc7c61530a71
Signed-off-by: katao <ustckato@gmail.com>
2016-12-19 08:51:07 +00:00
Rahul Chaudhry
8b640ffabc bootable/recovery: cleanup compiler warnings (potential leak of memory)
bootable/recovery/applypatch/imgdiff.cpp:195:5: warning: Potential leak
of memory pointed to by 'img' [clang-analyzer-unix.Malloc]

Bug: 26936282
Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm
Change-Id: Ie79c780233ddfebf85686a24df3bf2561f831580
2016-12-06 15:10:41 -08:00
Tao Bao
ef3bea15b8 Merge "bootable/recovery: cleanup compiler warnings (unused value)" 2016-12-01 17:03:13 +00:00
Tao Bao
d255b661a1 Merge "bootable/recovery: cleanup compiler warnings (potential leak of memory)" 2016-11-30 21:19:42 +00:00
Rahul Chaudhry
a793c58208 bootable/recovery: cleanup compiler warnings (unused value)
bootable/recovery/applypatch/imgdiff.cpp:322:11: warning: Value stored to 'ret' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
bootable/recovery/applypatch/imgdiff.cpp:447:11: warning: Value stored to 'ret' during its initialization is never read [clang-analyzer-deadcode.DeadStores]
bootable/recovery/applypatch/imgdiff.cpp:553:3: warning: Value stored to 'ret' is never read [clang-analyzer-deadcode.DeadStores]

Bug: 26936282
Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm
Change-Id: I3f865e3e9b9d19e5ea5e8dfd2fe2c644254ffbb5
2016-11-30 11:18:32 -08:00
Tao Bao
358c2ec1dc Remove ota_close(int) and ota_fclose(FILE*).
We should always use unique_fd or unique_file to hold the FD or FILE*
pointer when opening via ota_(f)open functions.

This CL avoids accidentally closing raw FDs or FILE* pointers that are
managed by unique_fd/unique_file.

Test: recovery_component_test passes.
Change-Id: If58eb8b5c5da507563f85efd5d56276472a1c957
2016-11-28 12:09:39 -08:00
Tao Bao
3dc14cb429 Add ota_close(unique_fd&) and ota_fclose(std::unique_ptr<FILE>&).
We were using the below sequence prior to the CL in [1].

unique_fd fd(ota_open(...));
ota_close(fd);
fd.reset(ota_open(...));

fd.reset() may unintentionally close the newly opened FD if it
has the same value as the early ota_open. The CL in [1] changed to
"ota_close(fd.release())" to avoid the issue. This CL adds a new
overloaded function ota_close(unique_fd&) to handle the release
automatically.

Similarly add ota_fclose(std::unique_ptr<FILE>&).

[1] commit 48cf770471.

Bug: 33034669
Test: recovery_component_test passes.
Change-Id: Ief91edc590e95a7426e33364b28754173efb1056
2016-11-22 16:44:41 -08:00
Tao Bao
48cf770471 applypatch: Release FD when explicitly calling close.
We use android::base::unique_fd() to avoid leaking FD. We also want to
call close (or ota_close) to explicitly check the close result. When
combining the two together, we need to release the unique_fd to avoid
closing the same FD twice.

Bug: 33034669
Test: Trigger applypatch with install-recovery.sh.
Change-Id: I1a4f5d5fba7a23ef98d8bd7b7b07e87ae6f705c5
2016-11-21 09:47:34 -08:00
Tao Bao
6e02ea92ec applypatch: Use unique_fd to avoid leaking FDs.
Add unique_fd that calls ota_close() instead of the default closer.

Test: recovery_component_test passes.
Test: Apply a package that calls apply_patch().

Change-Id: I0c19921731757934f76cf7d5215916673a8f2777
2016-11-17 12:01:44 -08:00
Tao Bao
8fce75a069 applypatch: Clean up LoadPartitionContents().
We don't need three vectors to sort the (size, SHA-1) pairs.

Test: recovery_component_test passes.
Test: Apply a package that calls apply_patch_check() to patch EMMC
      partitions.
Change-Id: I4a6620630a6711f490822cf30f1e7fe5cea6ce49
2016-11-17 00:02:52 -08:00
Rahul Chaudhry
b29f23f7e7 Use static_cast to cast pointers returned by malloc/calloc/realloc/mmap.
static_cast is preferable to reinterpret_cast when casting from void*
pointers returned by malloc/calloc/realloc/mmap calls.

Discovered while looking at compiler warnings (b/26936282).

Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mma
Change-Id: Iaffd537784aa857108f6981fdfd82d0496eb5592
Merged-In: I151642d5a60c94f312d0611576ad0143c249ba3d
2016-11-15 23:24:54 -08:00
Rahul Chaudhry
3a5177b16d bootable/recovery: cleanup compiler warnings (potential leak of memory)
bootable/recovery/applypatch/imgdiff.cpp:1065:3: warning: Potential leak of memory pointed to by 'patch_data'
bootable/recovery/applypatch/imgdiff.cpp:1065:3: warning: Potential leak of memory pointed to by 'patch_size'
bootable/recovery/applypatch/imgdiff.cpp:226:7: warning: Potential leak of memory pointed to by 'temp_entries'

Bug: 26936282
Test: WITH_TIDY=1 WITH_STATIC_ANALYZER=1 mm
Change-Id: I3cac945d7677d367934d5619ef7419daf6f48d6f
2016-11-15 16:18:46 -08:00
Tao Bao
36c3511952 applypatch: Add testcases for applypatch executable.
Refactor applypatch/main.cpp into libapplypatch_modes so that we can add
testcases.

Some changes to applypatch/main.cpp:
 - Replace char** argv with const char**;
 - Use android::base::Split() to split ":";
 - Use android::base::ParseUInt().

Bug: 32383590
Test: Unit tests pass, install-recovery.sh works.

Change-Id: I44e7bfa5ab717d439ea1d0ee9ddb7b2c40bb95a4
2016-11-01 14:40:14 -07:00
Tao Bao
fada91ccf2 applypatch: Switch the parameter of Value** to std::vector.
Test: Unit tests and install-recovery.sh pass on angler and dragon.

Change-Id: I328e6554edca667cf850f5584ebf1ac211e3d4d1
2016-10-28 16:46:12 -07:00
Tao Bao
edf1b15fef applypatch: Fix the bug when constructing VAL_BLOB.
When constructing std::string from C-string, the string may be truncated
at null char. Use range constructor instead.

Bug: 32380016
Test: Use applypatch to install a previously failed recovery image.
Change-Id: Id3e2afb4a810594243cd21db526933d1fea5044b
2016-10-24 16:08:28 -07:00
Tianjie Xu
7df1850d37 Merge "Fix applypatch_check failure when applying update on angler" 2016-10-19 00:29:23 +00:00
Tianjie Xu
984d7d058e Fix applypatch_check failure when applying update on angler
Applypatch_check should be skipped if no sha is specified. As the
comments said: "It's okay to specify no sha1s; the check will pass if
the LoadFileContents is successful. Useful for reading partitions,
where the filename encodes the sha1s."

Test: The update package applied on angler successfully.
Bug: 32243751
Change-Id: Ib8f3dadf19f745c2dbd350d60da46ab12d75bc87
2016-10-18 21:22:48 +00: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
Tianjie Xu
aced5d9e4e Change StringValue to use std::string
Changing the field of 'Value' in edify to std::string from char*.
Meanwhile cleaning up the users of 'Value' and switching them to
cpp style.

Test: compontent tests passed.
Bug: 31713288

Change-Id: Iec5a7d601b1e4ca40935bf1c70d325dafecec235
2016-10-15 01:18:23 +00:00
Tianjie Xu
7aa88748f6 Turn on -Werror for recovery
Also remove the 0xff comparison when validating the bootloader
message fields. As the fields won't be erased to 0xff after we
remove the MTD support.

Bug: 28202046
Test: The recovery folder compiles for aosp_x86-eng
Change-Id: Ibb30ea1b2b28676fb08c7e92a1e5f7b6ef3247ab
2016-09-29 19:21:24 -07:00
Tianjie Xu
61590bbf0d Merge "Switch recovery to libbase logging" 2016-09-01 23:04:37 +00:00
Tianjie Xu
7b0ad9c638 Switch recovery to libbase logging
Clean up the recovery image and switch to libbase logging.

Bug: 28191554
Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35
Merged-In: Icd999c3cc832f0639f204b5c36cea8afe303ad35
2016-09-01 18:33:25 +00:00
Tianjie Xu
71e182bc38 Check an edge case when read(2) returns 0
We might end up in an infinite loop if read(2) reached EOF unexpectedly.
The problematic code in uncrypt mentioned in the bug has been fixed
by switching to libbase ReadFully(). So I grepped through the recovery
code and fixed some other occurences of the issue.

Bug: 31073201
Change-Id: Ib867029158ba23363b8f85d61c25058a635c5a6b
2016-08-31 19:11:41 -07:00
Josh Gao
dc97404346 Merge "Fix references to libcrypto_utils_static."
am: b97da5e0f0

Change-Id: Ia935df84e5ea36dfc6605b41872c36db69a114a0
2016-08-08 18:33:51 +00:00
Josh Gao
073164f24b Fix references to libcrypto_utils_static.
Bug: http://b/30708454
Change-Id: I7a5048beff1d8b783a9683dcb4a79606a77f20ee
2016-08-05 18:08:03 -07:00
Elliott Hughes
274d17dc0f resolve merge conflicts of 179c0d8 to stage-aosp-master
Change-Id: Iba5aec266444cabf83f600f2bdb45a3c027e5995
2016-06-15 15:22:17 -07:00
Tao Bao
38afad46d8 resolve merge conflicts of 490fad6 to nyc-dev-plus-aosp
Change-Id: I299fe15977c1a59d0c784728872c3a7f63c95e56
2016-06-13 19:12:46 -07:00
Tao Bao
490fad6791 applypatch: Don't call inflate() when it expects zero-length output.
We may have expanded_len == 0 when calling inflate(). After switching to
using std::vector, it passes a nullptr buffer to inflate() and leads to
Z_STREAM_ERROR.

Bug: 29312140
Change-Id: Iab7c6c07a9e8488e844e7cdda76d02bd60d2ea98
2016-06-13 16:42:52 -07:00
Elliott Hughes
63a319201f Remove obsolete MTD support.
Bug: http://b/29250988
Change-Id: Ia97ba9082a165c37f74d6e1c3f71a367adc59945
2016-06-10 13:45:35 -07:00
Tao Bao
a0c4011028 Revert "Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector."
This reverts commit 50a6f8c833.

A mix of new and free leads to memory corruptions.
2016-06-01 13:15:44 -07:00
Adam Buchbinder
50a6f8c833 Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector.
This fixes the following cppcheck reports:
[imgdiff.cpp:197]: (error) Memory leak: img
[imgdiff.cpp:386]: (error) Memory leak: img
[imgdiff.cpp:656]: (error) Memory leak: data
[imgdiff.cpp:664]: (error) Memory leak: data
[imgdiff.cpp:668]: (error) Memory leak: data
[imgdiff.cpp:668]: (error) Resource leak: f
[imgdiff.cpp:820]: (error) Memory leak: bonus_data
[imgdiff.cpp:824]: (error) Memory leak: bonus_data
[imgdiff.cpp:824]: (error) Resource leak: f
[imgdiff.cpp:847]: (error) Memory leak: bonus_data
[imgdiff.cpp:851]: (error) Memory leak: bonus_data
[imgdiff.cpp:856]: (error) Memory leak: bonus_data
[imgdiff.cpp:860]: (error) Memory leak: bonus_data
[imgdiff.cpp:227]: (error) Memory leak: temp_entries

Change-Id: I06f878d0b677a25328e0deb84f65f3b7212e24b1
(cherry picked from commit 51dc9444bc)
2016-06-01 10:28:45 -07:00
Tao Bao
16e3861c84 Revert "imgdiff: Generate statically linked imgdiff."
This reverts commit b4422bd769.

Bug: 28941046
Change-Id: Ic3c7439c64b8e55832252850514f721a944993d6
2016-06-01 00:08:40 +00:00
Tao Bao
b4422bd769 imgdiff: Generate statically linked imgdiff.
Bug: 28941046
Change-Id: If3019d8cff91fd4f6fa4516bef5a0f51c2ddebc7
2016-05-30 21:53:11 -07:00
Sen Jiang
2fffcb174b applypatch: Use bsdiff from external/bsdiff.
external/bsdiff uses divsufsort which is much faster, and also include
some bug fixes.

Bug: 26982501
Test: ./imgdiff_test.sh

Change-Id: I089a301c291ee55d79938c7a3ca6d509895440d1
2016-05-03 16:39:51 -07:00
Chih-Hung Hsieh
54a2747ef3 Fix google-runtime-int warnings.
Bug: 28220065
Change-Id: Ida199c66692a1638be6990d583d2ed42583fb592
2016-04-18 12:29:30 -07:00
Jed Estep
ff6df890a2 Control fault injection with config files instead of build flags
Bug: 27724259
Change-Id: I65bdefed10b3fb85fcb9e1147eaf0687d7d438f4
2016-03-18 17:58:25 -07:00
Tao Bao
ce5868862a Revert "DO NOT MERGE Control fault injection with config files instead of build flags"
This reverts commit f73abf36bc.

Bug: 27724259
Change-Id: I1301fdad15650837d0b1febd0c3239134e2b94fb
2016-03-17 22:29:23 +00:00
Jed Estep
f73abf36bc DO NOT MERGE Control fault injection with config files instead of build flags
Bug: 26570379
Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c
2016-03-16 12:36:57 -07:00
Alex Deymo
82f8c82046 Add include/ to the Makefile include path.
The applypatch heaaders were recently moved to the include/ directory.
This patch reflects that change in the Makefile.

Bug: None
TEST=sudo emerge imgdiff

Change-Id: I0bf3f991b5e0c98054033c5939ed69b3e3c827a9
2016-03-14 14:25:33 -07:00
Yabin Cui
1c522df25f applypatch: use vector to store data in FileContents.
Cherry pick this patch because it fixes the problem that
a newed Value is released by free().

Bug: 26906416
Change-Id: Ib53b445cd415a1ed5e95733fbc4073f9ef4dbc43
(cherry picked from commit d6c93afcc2)
2016-03-11 11:11:11 -08:00
Sen Jiang
5593342575 Merge "applypatch: add -fPIC for libimgpatch in Chrome OS." 2016-03-09 01:28:09 +00:00
Sen Jiang
ef2016f711 applypatch: add -fPIC for libimgpatch in Chrome OS.
To make the static library position independent.

Bug: 26866274
Test: emerge-peppy imgdiff; sudo emerge imgdiff; emerge nyan imgdiff

Change-Id: I319e721ccfb6a51f63d31afa49f54aa7f607f4bf
2016-03-08 17:02:50 -08:00
Tao Bao
d80a99883d Fix the improper use of LOCAL_WHOLE_STATIC_LIBRARIES.
If two libraries both use LOCAL_WHOLE_STATIC_LIBRARIES and include a same
library, there would be linking errors when generating a shared library
(or executable) that depends on the two libraries both.

Also clean up Android.mk files.

Remove the "LOCAL_MODULE_TAGS := eng" line for the updater module. The
module will then default to "optional" which won't be built until needed.

Change-Id: I3ec227109b8aa744b7568e7f82f575aae3fe0e6f
2016-03-03 14:52:44 -08:00
Jed Estep
39c1b5e872 Control fault injection with config files instead of build flags
Bug: 26570379
Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c
(cherry picked from commit d940887dde)
2016-02-22 17:31:12 -08:00
Sen Jiang
f3e05f504d applypatch: Add libimgpatch.pc
Test: pkg-config --libs libimgpatch
Bug: 26866274
Change-Id: I79a103099d951943a88768c577224fccacbb79e3
2016-02-16 11:35:29 -08:00
Sen Jiang
fa4f1b75b6 imgdiff: don't fail if gzip is corrupted.
Treat it as a normal chunk if inflate() fails.

Test: run imgdiff on corrupted gzip and apply the patch
Bug: 27153028
Change-Id: Idcbb3c1360ec0774e6c7861b21d99af8ee10604a
2016-02-12 12:57:03 -08:00
Yabin Cui
d6c93afcc2 applypatch: use vector to store data in FileContents.
Bug: 26906416
Change-Id: Ib53b445cd415a1ed5e95733fbc4073f9ef4dbc43
2016-02-11 18:10:31 -08:00
Jed Estep
a7b9a4660c IO fault injection for OTA packages
Bug: 25951086
Change-Id: I31c74c735eb7a975b7f41fe2b2eff042e5699c0c
(cherry-picked from commit f1fc48c6e6)
2016-02-10 10:49:38 -08:00
Sen Jiang
696692a3c9 applypatch: Add a Makefile to build imgdiff in Chrome OS.
Also fixed some warnings and added check for target_len.

Test: mma; emerge-peppy imgdiff; emerge-nyan imgdiff; sudo emerge imgdiff
Bug: 26866274

Change-Id: Ifbcd3afd6701c769ccf626e33ed94461706f7ee6
2016-02-09 15:26:57 -08:00
Yabin Cui
ca78c9f035 resolve merge conflicts of 715d8a203a to master.
Change-Id: Ic868ee9b27ef7251aa49ac814de7355ecd9c7d37
2016-02-05 15:27:52 -08:00
Yabin Cui
d483c20a7e applypatch: fix memory leaks reported by static analysis.
Bug: 26906416
Change-Id: I163df5a8f3abda3ba5d4ed81dfc8567054eceb27
2016-02-04 15:42:02 -08:00
Tao Bao
50aa63f9bd resolve merge conflicts of 7b6027dde4 to master.
Change-Id: I1d5232f61744bb18ca5de3a16a340bc3afd110bb
2016-02-04 11:26:29 -08:00
Sen Jiang
c48cb5e597 Switch from mincrypt to BoringSSL in applypatch and updater.
Bug: 18790686
Change-Id: I7d2136fb39b2266f5ae5be24819c617b08a6c21e
2016-02-04 16:27:43 +08:00
Tao Bao
9fcb016109 Merge "Fix build." am: 9d72d4175b
am: 2ab24d36b9

* commit '2ab24d36b91e28416a85e2c56442c22c984903ea':
  Fix build.
2016-01-29 06:09:04 +00:00
Tao Bao
8b0db11eba Fix build.
Disable libimgpatch for non-Linux host.

Change-Id: Ib3615204b76564c691ddafaa29e59fef334d9d36
2016-01-28 21:59:09 -08:00
Tao Bao
484c49e99e resolve merge conflicts of 725833e024 to master.
Change-Id: I68b8737e3bc2bd7bffd7625114723bc1efa47398
2016-01-28 20:58:59 -08:00
Sen Jiang
0cce9cda0c applypatch: Compile libimgpatch for target and host.
update_engine need it for the new IMGDIFF operation.

Also removed __unused in ApplyImagePatch() as I got error building it
for the host, and I think it's dangerous not checking the size of the
input.

Test: mma
Bug: 26628339

Change-Id: I22d4cd55c2c3f87697d6afdf10e8106fef7d1a9c
2016-01-28 13:26:25 +08:00
Jed Estep
f1fc48c6e6 IO fault injection for OTA packages
Bug: 25951086
Change-Id: I31c74c735eb7a975b7f41fe2b2eff042e5699c0c
2016-01-06 12:23:42 -08:00
David Riley
0779fc9814 imgdiff: skip spurious gzip headers in image files
dragon kernel is compressed via lz4 for boot speed and bootloader
support reasons and recent prebuilts happen to include the gzip header
sequence which is causing imgdiff to fail.

Detect a spurious gzip header and treat the section as a normal section.

Bug: 26133184
Change-Id: I369d7d576fd7d2c579c0780fc5c669a5b6ea0d3d
(cherry picked from commit 0f2f6a746af517afca9e5e089a4a17be0a9766d6)
Signed-off-by: David Riley <davidriley@google.com>
2015-12-23 09:43:59 -08:00
Elliott Hughes
4b166f0e69 Track rename from base/ to android-base/.
Change-Id: I354a8c424d340a9abe21fd716a4ee0d3b177d86f
2015-12-04 15:30:20 -08:00
Tao Bao
f2448d0cd5 Remove the building rules for applypatch_static.
The CL in [1] has stopped building and packaging the obsolete
applypatch_static tool.

[1]: commit a04fca31bf1fadcdf982090c942ccbe4d9b95c71

Bug: 24621915
Change-Id: I5e98951ad7ea5c2a7b351af732fd6722763f59bd
2015-12-02 14:05:38 -08:00
Jeremy Compostella
a91c66d7c1 imgdiff: fix file descriptor leak
mkstemp() allocates a file description that is never released.  If
MakePatch() is called too many time, imgdiff reaches the Operating
System EMFILE (too many open files) limit.

Change-Id: Icbe1399f6f6d32cfa1830f879cacf7d75bbd9fc3
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
Signed-off-by: Gaelle Nassiet <gaellex.nassiet@intel.com>
2015-09-08 19:15:09 +02:00
Tao Bao
e6aa3326c1 updater: Clean up char* with std::string.
So we can remove a few free()s. And also replace a few pointers with
references.

Change-Id: I4b6332216704f4f9ea4a044b8d4bb7aa42a7ef26
2015-08-06 13:05:00 -07:00
Tao Bao
1ce7a2a63d applypatch: Fix the checking in WriteToPartition().
WriteToPartition() should consider a target name as valid if it contains
multiple colons. But only the first two fields will be used.

Bug: 22725128
Change-Id: Ie9404375e24045c115595eec6ce5b6423da8fc3e
2015-07-24 15:33:35 -07:00
Tao Bao
abba55b4c5 applypatch: Support flash mode.
We may carry a full copy of recovery image in the /system, and use
/system/bin/install-recovery.sh to install the recovery. This CL adds
support to flash the recovery partition with the given image.

Bug: 22641135
Change-Id: I7a275b62fdd1bf41f97f6aab62d0200f7dae5aa1
(cherry picked from commit 68c5a67967)
2015-07-24 11:15:19 -07:00
Tao Bao
aca8e89603 applypatch: Refactor strtok().
We have android::base::Split() for the work.

Change-Id: I0fb562feb203c9b15e2f431d8e84355fd682376a
(cherry picked from commit 0a47ce27de)
2015-07-24 11:08:14 -07:00
Tao Bao
ba9a42aa7e recovery: Switch applypatch/ and updater/ to cpp.
Mostly trivial changes to make cpp compiler happy.

Change-Id: I69bd1d96fcccf506007f6144faf37e11cfba1270
2015-07-13 17:21:31 -07:00
Tao Bao
80e46e08de recovery: Switch to clang
And a few trival fixes to suppress warnings.

Change-Id: I38734b5f4434643e85feab25f4807b46a45d8d65
2015-06-03 11:30:03 -07:00
caozhiyuan
3b4977638f Use f_bavail to calculate free space
Failures are seen on devices with
Linux 3.10. And they are mainly due to this change:
https://lwn.net/Articles/546473/
The blocks reserved in this change is not the same thing as what we
think are reserved for common usage of root user. And this part is
included in free blocks but not in available blocks.

Change-Id: Ib29e12d775b86ef657c0af7fa7a944d2b1e12dc8
2015-05-29 13:32:49 +08:00
Dan Albert
e49a9e527a Stop using libstdc++.
These are already getting libc++, so it isn't necessary. If any of the
other static libraries (such as adb) use new or delete from libc++,
there will be symbol collisions.

Change-Id: I55e43ec60006d3c2403122fa1174bde06f18e09f
2015-05-19 11:33:18 -07:00
Elliott Hughes
7bad7c4646 Check all lseek calls succeed.
Also add missing TEMP_FAILURE_RETRYs on read, write, and lseek.

Bug: http://b/20625546
Change-Id: I03b198e11c1921b35518ee2dd005a7cfcf4fd94b
2015-04-29 17:46:43 -07:00
Johan Redestig
c68bd34dc8 imgdiff: Avoid infinite loop if inflate fails
Break out of the loop if inflate returns an error
and print some details.

Change-Id: Ie157cf943291b1a26f4523b17691dfcefbc881dc
2015-04-15 13:09:54 +02:00
Elliott Hughes
40862ab59e am aeecac54: Merge "Add missing includes."
* commit 'aeecac5444ce55d2e82ee1b2aa35ff61a038c14e':
  Add missing includes.
2015-01-30 21:16:36 +00:00
Elliott Hughes
cd3c55ab40 Add missing includes.
Change-Id: I06ea08400efa511e627be37a4fd70fbdfadea2e6
2015-01-29 20:50:08 -08:00
Elliott Hughes
22b8fe9666 am dab56cac: Merge "Add missing includes."
* commit 'dab56cac959ce9c78e3a0a22e9ee2ff917d61bd3':
  Add missing includes.
2015-01-28 20:48:30 +00:00
Elliott Hughes
26dbad2b98 Add missing includes.
Change-Id: I0737456e0221ebe9cc854d65c95a7d37d0869d56
2015-01-28 12:09:05 -08:00
Michael Runge
be81e51c17 Use more aggressive sync writing to applypatch.
We have seen cases where the boot partition is patched, but upon
recovery the partition appears to be corrupted.  Open up all
patched files/partitions with O_SYNC, and do not ignore the
errors from fsync/close operations.

Bug: 18170529
Change-Id: I392ad0a321d937c4ad02eaeea9170be384a4744b
2014-10-29 13:00:21 -07:00
Doug Zongker
bc7ffeda98 installer for new block OTA system
(Cherry-pick back from master.)

Bug: 16984795
Change-Id: Ifa3d8345c5e2a0be86fb28faa080ca82592a96b4
2014-08-19 16:53:39 -07:00
Doug Zongker
ddb1b74498 am c4804e9b: am d4592694: am 3ca99f6c: Merge "fix vulnerability in bspatch"
* commit 'c4804e9b9c143652d17441b4b672b920b11cc94a':
  fix vulnerability in bspatch
2014-05-16 15:09:35 +00:00
Doug Zongker
d4592694b4 am 3ca99f6c: Merge "fix vulnerability in bspatch"
* commit '3ca99f6cb8ffbe19c7ef5409f3dac18ea0c254bd':
  fix vulnerability in bspatch
2014-05-16 15:03:24 +00:00
Doug Zongker
4aa12dd0de fix vulnerability in bspatch
Patches with control data tuples with negative numbers in the first
and/or second can cause bspatch to write to arbitrary locations in the
heap.

Change-Id: I8c5d81948be773e6483241131d3d166b6da27cb8
2014-05-13 08:40:49 -07:00
Mark Salyzyn
679baa06b7 am 4b6de1ba: am 026ebe02: Merge "Recovery 64-bit compile issues"
* commit '4b6de1ba1ce0fff95c18a8abb7ba6e5762006d49':
  Recovery 64-bit compile issues
2014-03-14 21:35:41 +00:00
Mark Salyzyn
52d0b765ab am 026ebe02: Merge "Recovery 64-bit compile issues"
* commit '026ebe0214d6c1c9b3ddc22c35e9ac37e5f622bc':
  Recovery 64-bit compile issues
2014-03-14 21:02:33 +00:00
Mark Salyzyn
4b6de1ba1c am 026ebe02: Merge "Recovery 64-bit compile issues"
* commit '026ebe0214d6c1c9b3ddc22c35e9ac37e5f622bc':
  Recovery 64-bit compile issues
2014-03-14 20:59:56 +00:00
Mark Salyzyn
f3bb31c32f Recovery 64-bit compile issues
Change-Id: I92d5abd1a628feab3b0246924fab7f97ba3b9d34
2014-03-14 13:51:39 -07:00
Doug Zongker
3eb681d1de remove remaining libminelf references
Change-Id: Id38b08607829bccc031693cc03e60e849903b6f8
2014-02-13 15:49:35 -08:00
Doug Zongker
a1bc148c7c remove 'retouch' ASLR support
Older versions of android supported an ASLR system where binaries were
randomly twiddled at OTA install time.  Remove support for this; we
now use the ASLR support in the linux kernel.

Change-Id: I8348eb0d6424692668dc1a00e2416fbef6c158a2
2014-02-13 15:18:19 -08:00
Doug Zongker
168724c31a fix unnecessarily slow writing of EMMC partitions
These were attempts to write partitions "conservatively" in hopes of
fixing the problems with writing the radio partition on Nexus 4.  They
didn't work (a kernel patch was needed), but got left in.  They make
writing of partitions unnecessarily slow (ie, we really shouldn't need
to sync() after every 4kb).  Roll back most of them, but leave the
verification read-back in.

Change-Id: I94badc0979e88816c5aa0485f6316c02be69173c
2013-12-19 15:16:57 -08:00
Doug Zongker
51c84694b0 am a69b50c5: am 901b898d: recovery: remove O_DIRECT, use O_SYNC only
* commit 'a69b50c567d46afad73c4d6ab9e57f078ee73327':
  recovery: remove O_DIRECT, use O_SYNC only
2013-07-11 14:23:44 -07:00
Doug Zongker
bce44d8b55 am 660637f3: am e8d953aa: recovery: more cargo-cult programming
* commit '660637f3fc6fe20e8b7f47b98152138c2c92b7ec':
  recovery: more cargo-cult programming
2013-07-11 14:23:36 -07:00
Doug Zongker
901b898d5e recovery: remove O_DIRECT, use O_SYNC only
O_DIRECT writes fail with EINVAL due to alignment issues.

Change-Id: If8cf38a636313e4f4b4e61e66287dc903c473e5b
2013-07-11 12:31:25 -07:00
Doug Zongker
e8d953aa7e recovery: more cargo-cult programming
Add O_DIRECT|O_SYNC when opening partitions for write.

Change-Id: I9825ad8e60fba87e482f8abc5593d6f54a1e3a1c
2013-07-11 12:11:11 -07:00
Doug Zongker
65c37aa0d3 am fbcfad33: am bf4a69ac: recovery: sleep after writing partition and closing it
* commit 'fbcfad33face5d3b9e6b8cb04379168bceb517df':
  recovery: sleep after writing partition and closing it
2013-07-11 10:17:48 -07:00
Doug Zongker
5d0da12878 am 2148133d: am c870a99c: recovery: write partitions more conservatively
* commit '2148133d46cb875316b01947dd5719ed995f7d67':
  recovery: write partitions more conservatively
2013-07-11 10:08:23 -07:00
Doug Zongker
bf4a69ac41 recovery: sleep after writing partition and closing it
Another speculative attempt to get everything we write actually stored
to the device.

Change-Id: Icf40b0741b4c535e55ea34848073a97d90dc0e70
2013-07-10 13:46:46 -07:00
Doug Zongker
c870a99c4a recovery: write partitions more conservatively
Write and verify partitions using write(2) and read(2) rather than the
stdio functions.  Read and write in 4kb blocks.  When writing, fsync()
every 1MB.

Bug: 9602014
Change-Id: Ie98ce38e857786fc0f4ebf36bb5ffc93b41bc96f
2013-07-09 10:42:15 -07:00
Doug Zongker
602c4ebd39 am 0ccaccf7: am 044a0b4d: recovery: try to write EMMC partitions more reliably
* commit '0ccaccf7d0f50bb9555ee13a841c246a1fea80f2':
  recovery: try to write EMMC partitions more reliably
2013-07-08 14:14:24 -07:00
Doug Zongker
044a0b4d49 recovery: try to write EMMC partitions more reliably
Nexus 4 has flash errors that manifest during large writes (eg, of the
radio partition).  Writes of some blocks seem to be dropped silently,
without any errors being returned to the user level.

Make two changes to the partition-writing code:

- break it up into 1MB writes instead of writing partitions with a
  single fwrite() call.  Pause for 50ms in between every chunk.

- read the partition back after writing and verify that we read what
  we wrote.  Drop caches before reading so we (hopefully) are reading
  off the actual flash and not some cache.

Neither of these should be necessary.

Bug: 9602014

Change-Id: Ice2e24dd4c11f1a57968277b5eb1468c772f6f63
2013-07-08 12:59:22 -07:00
Doug Zongker
bac7fba027 verifier: update to support certificates using SHA-256
Change-Id: Ifd5a29d459acf101311fa1c220f728c3d0ac2e4e
2013-04-10 11:32:17 -07:00
Doug Zongker
bf80f49edc reduce some recovery logging
Make minzip log only a count of files when extracting, not individual
filenames.  Make patching only chatter about free space if there's not
enough and compact the other messages.

Only the last 8k of the recovery log gets uploaded; this makes it more
likely that we will get all of it.

Change-Id: I529cb4947fe2185df82b9da5fae450a7480dcecd
2012-10-19 12:24:26 -07:00
Doug Zongker
a3ccba6d31 add bonus data feature to imgdiff/imgpatch/applypatch
The bonus data option lets you give an additional blob of uncompressed
data to be used when constructing a patch for chunk #1 of an image.
The same blob must be available at patch time, and can be passed to
the command-line applypatch tool (this feature is not accessible from
edify scripts).

This will be used to reduce the size of recovery-from-boot patches by
storing parts of the recovery ramdisk (the UI images) on the system
partition.

Change-Id: Iac1959cdf7f5e4582f8d434e83456e483b64c02c
2012-08-20 15:28:02 -07:00
Joe Onorato
5585025814 am 3733d218: Merge changes I664f8dc7,I4154db06,I5e1df90f
* commit '3733d2185bbcedd9ef626907f1f32628986cc0f5':
  Use the static version of libsparse
  Multiple modules with the same name are going away.
  host modules don't need LOCAL_MODULE_TAGS
2012-08-17 00:11:55 -07:00
Joe Onorato
c0481af406 host modules don't need LOCAL_MODULE_TAGS
Change-Id: I5e1df90f18fbaf98e3207c553a8fb859c1064137
2012-07-21 15:24:56 -07:00
Nick Kralevich
956cde8578 Add mode when open(O_CREAT) is used.
When creating a new file using open(..., O_CREAT), it is an error
to fail to specify a creation mode. If a mode is not specified, a
random stack provided value is used as the "mode".

This will become a compile error in a future Android change.

Change-Id: I73c1e1a39ca36bf01704b07302af4971d234b5a8
2012-06-26 15:01:03 -07:00
Wei Zhong
6e960cd221 Add NOTICE file
1. AOSP_APACH2
2. BSD for bsdiff.c and bspatch.c

Bug: 6299628

Change-Id: If9a5f7f8f07ad51bb62202253da189d804674e54
Signed-off-by: Wei Zhong <wzhong@google.com>
(cherry picked from commit 592e7a9cf1c856bee2adb8f285ac359e2d7f68e1)
2012-04-06 13:51:00 -07:00
Doug Zongker
b07b293944 fix build
Change-Id: I44a75f5451af053778be299b23274ecce9b2db76
2012-02-28 12:07:30 -08:00
Doug Zongker
1c43c9741b fix failure to free memory
The applypatch function is somewhat sloppy about freeing memory (since
it was originally a standalone binary).  Fix some of that.

Change-Id: Ifd44d71ea189c0b5115493119fd57bc37533fd59
2012-02-28 11:07:09 -08:00
Jeff Brown
b0462e6ae2 Remove the simulator target from all makefiles.
Bug: 5010576

Change-Id: Ib465fdb42c8621899bea15c04a427d7ab1641a8c
2011-07-11 22:11:45 -07:00
Ying Wang
4c05d95112 Fix x86 build.
Change-Id: Iada6268b0a72ee832113ea397334cc7950a37051
2011-02-08 19:51:07 -08:00
Doug Zongker
baf6e35473 am c080bc54: am fbd7ae7a: am 201cd466: remove shadowed variable declaration
Merge commit 'c080bc549aaf272c77fe7903e52c2a2c0d8de1bb'

* commit 'c080bc549aaf272c77fe7903e52c2a2c0d8de1bb':
  remove shadowed variable declaration
2010-08-16 07:44:51 -07:00
Doug Zongker
fbd7ae7a1c am 201cd466: remove shadowed variable declaration
Merge commit '201cd46680f5789e21a57fb4476ab0ba0c0ed4c0' into gingerbread

* commit '201cd46680f5789e21a57fb4476ab0ba0c0ed4c0':
  remove shadowed variable declaration
2010-08-13 09:59:52 -07:00
Doug Zongker
201cd46680 remove shadowed variable declaration
An accidental variable declaration ("int enough_space = ..." instead
of "enough_space = " inside a block) shadowing the real one meant we
were always using the copy-to-cache path for patching, even when not
necessary.  Remove it.  Enforce an absolute minimum of free space as
well, to avoid running into problems patching small files, now that
the copy-to-cache path is (inadvertently) well-tested.

Change-Id: Idb7d57241a9adcda2e11001fa44f0cd67ce40d19
2010-08-13 09:41:21 -07:00
Doug Zongker
80dcee145f am c4e32005: am 17986e6b: am 8cd9e4f3: fix bug in applying patches
Merge commit 'c4e3200578ad670bee9f5a88e90e7a77089d5df7'

* commit 'c4e3200578ad670bee9f5a88e90e7a77089d5df7':
  fix bug in applying patches
2010-08-12 17:57:45 -07:00
Doug Zongker
17986e6b87 am 8cd9e4f3: fix bug in applying patches
Merge commit '8cd9e4f3d4eba481b411482331293c8079ab24b2' into gingerbread

* commit '8cd9e4f3d4eba481b411482331293c8079ab24b2':
  fix bug in applying patches
2010-08-12 17:52:34 -07:00
Doug Zongker
8cd9e4f3d4 fix bug in applying patches
When restarting a patch from crashing in the middle of a large file,
we're not finding the correct patch to apply to the copy saved in
cache.

Change-Id: I41cb2b87d096bb7a28a10c4cf3902facd45d4c9d
2010-08-12 17:38:09 -07:00
Hristo Bojinov
db314d69f0 Working ASLR implementation
Separate files for retouch functionality are in minelf/*

ASLR for shared libraries is controlled by "-a" in ota_from_target_files.
Binary files are self-contained. Retouch logic can recover from crashes.

Signed-off-by: Hristo Bojinov <hristo@google.com>
Change-Id: I76c596abf4febd68c14f9d807ac62e8751e0b1bd
2010-08-02 14:17:33 -07:00
Doug Zongker
f291d858f8 EMMC support in applypatch
Let applypatch read and write EMMC partitions as well as MTD ones.
This enables incremental updates that include boot image changes, as
well as OTA of new recovery partitions.

Change-Id: I3766b9e77c639769ddf693b675da51d57f6e6b1d
2010-07-07 15:18:27 -07:00
Bruce Beare
97ca48e7f4 generic_x86 support
Add in Makefiles and support files for x86 builds
  Based on changes by: wonjong.lee <wonjong.lee@windriver.com>
  Additional changes by: Mark Gross <mark.gross@intel.com>
  Additional changes by: Bruce Beare <brucex.j.beare@intel.com>

Change-Id: I71fcf58f116e4e9047e7d03fdb28e3308553ce5c
2010-05-03 15:58:50 -07:00
Doug Zongker
c4351c7910 refactor applypatch and friends
Change the applypatch function to take meaningful arguments instead of
argc and argv.  Move all the parsing of arguments into main.c (for the
standalone binary) and into install.c (for the updater function).
applypatch() takes patches as Value objects, so we can pass in blobs
extracted from the package without ever writing them to temp files.

The patching code is changed to read the patch from memory instead of
a file.

A bunch of compiler warnings (mostly about signed vs unsigned types)
are fixed.

Support for the IMGDIFF1 format is dropped.  (We've been generating
IMGDIFF2 packages for some time now.)

Change-Id: I217563c500012750f27110db821928a06211323f
2010-02-22 15:30:33 -08:00
Doug Zongker
512536a54a relocate applypatch; add type system and new functions to edify
- Move applypatch to this package (from build).

- Add a rudimentary type system to edify:  instead of just returning a
  char*, functions now return a Value*, which is a struct that can
  carry different types of value (currently just STRING and BLOB).
  Convert all functions to this new scheme.

- Change the one-argument form of package_extract_file to return a
  Value of the new BLOB type.

- Add read_file() to load a local file and return a blob, and
  sha1_check() to test a blob (or string) against a set of possible
  sha1s.  read_file() uses the file-loading code from applypatch so it
  can read MTD partitions as well.

This is the start of better integration between applypatch and the
rest of edify.

b/2361316 - VZW Issue PP628: Continuous reset to Droid logo:
            framework-res.apk update failed (CR LIBtt59130)

Change-Id: Ibd038074749a4d515de1f115c498c6c589ee91e5
2010-02-18 14:22:12 -08:00