summaryrefslogtreecommitdiffstats
path: root/applypatch (unfollow)
Commit message (Collapse)AuthorFilesLines
2018-04-27Save the target file when applypatch tests failTianjie Xu2-14/+18
Save the target file to tempfile upon unittest failures so that we can try to decompress the deflate chunks in the flaky unittests. And print the zlib version in case that gets changed. Also the SHA1 of the uncompressed data seems correct; so only keep the final SHA1 to double confirm. Bug: 67849209 Test: recovery_component_test Change-Id: Ic6447c2b75c29379d6844cd23a0ff1c4305694a0
2018-04-26Rename CacheLocation to Paths.Tao Bao2-9/+9
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-26Dump the uncompressed data's SHA1 to debug flaky testsTianjie Xu1-1/+23
Dump the SHA1 of the uncompressed data in applypatch to confirm if we are at least doing the bspatch part correctly. (I expect so since the actual length of the uncompressed data matches the expected length). Also try to decompress the deflate chunk inside the recovery image for these two flacky tests. In theory, there shouldn't be randomness in zlib; so we would know if we process the data wrongly if the deflate fails to decompress. Bug: 67849209 Test: recovery_component_test Change-Id: Id947522153b1eeb0d10d161298a96fb045f92018
2018-04-24Dump debug information for apply_patch unit testsTianjie Xu2-0/+10
The apply patch test should have a deterministic way to append patch data. Add debug logs to dump the length and SHA1 of each step to further track down the flakiness. Also redirect the debug logging to stdout in case the logcat becomes too chatty. Bug: 67849209 Test: Run recovery_component_test Change-Id: I42bafef2d9dee599719ae57840b3d8c00d243ebd
2018-04-20applypatch: Drop the SHA_CTX parameter in Apply{BSDiff,Image}Patch.Tao Bao4-34/+22
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-19applypatch: Dump patch info on mismatching patching result.Tao Bao1-1/+16
After splitting the previously flaky ApplyPatchModesTest#PatchModeEmmcTarget tests, PatchModeEmmcTargetWithMultiplePatches now becomes the sole victim. This CL dumps additional info to narrow down the cause. Bug: 67849209 Test: `recovery_component_test` on marlin. Test: It dumps additional info after using corrupt bonus.file. Change-Id: Ic5436de457cc882a51d03f49d5cee70077f7d3df
2018-04-13Remove the old log files if cache space is insufficient for OTATianjie Xu3-59/+129
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-02-28Add a singleton CacheLocation to replace the hard coded locationsTianjie Xu3-13/+7
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-23Remove the assumption of target chunk size in imgdiffTianjie Xu2-20/+30
In the split mode of imgdiff, we used to assume that the size of a split target chunk is always greater than the blocksize i.e. 4096. This may lead to the following assertion failure: I0221 04:57:33.451323 818464 common.py:205 imgdiff F 02-21 04:57:33 821203 821203 imgdiff.cpp:999] Check failed: tgt_size >= BLOCK_SIZE (tgt_size=476, BLOCK_SIZE=4096) This CL removes the assumption and handles the edge cases. Test: generate and verify the incremental update for TFs in the bug; unit test passes Bug: 73757557 Bug: 73711365 Change-Id: Iadbb4ee658995f5856cd488f3793980881a59620
2018-02-18Disable building libapplypatch on macTianjie Xu1-0/+6
The sdk_mac on build server fails with the error: bootable/recovery/applypatch/freecache.cpp:23:10: fatal error: 'sys/statfs.h' file not found So we will disable libapplypatch on mac. Test: the library still builds on linux; and check the other host targets in the same cl. Change-Id: Ie4a30708726e51c810f7ad7f1085d38154076cca
2018-02-13Skip the cache size check on hostTianjie Xu3-3/+10
When running the update simulation, we choose to skip the cache size check for now due to the lack of "/cache" on host. And in later cls we can implement a cache size estimator to make the check more constrained. Also build the host version of support libraries. Test: unit test pass Change-Id: I3ed93c857fd02f7b62f5baba9130f75c3236e717
2017-12-07applypatch: Remove the 'st' field from FileContents.Tao Bao2-17/+3
It used to keep track of the stat(2) info (e.g. st_mode/st_gid/st_uid) while patching a file in file-based OTA. Test: Build and use the new updater to apply an update on bullhead. Change-Id: Ibf8f0f4b14298a9489bf24a2678bb279c5d9c8f3
2017-11-16Switch imgdiff to libbase loggingTianjie Xu2-97/+109
Also add a verbose option. And we won't print messages of 'info' severity unless '-v' is present. Test: run imgdiff and check the logs. Change-Id: I1b90874baea8e72e2a2323a0b63bc5d35e653e6b
2017-11-10applypatch: Change the patch parameter to const Value& in Apply{BSDiff,Image}Patch.Tao Bao4-45/+47
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-08Include bspatch.h from bsdiff/Alex Deymo1-1/+1
The function ApplyBSDiffPatch() defined in bspatch.cpp is declared in applypatch.h, but it includes "bspatch.h" from the bsdiff/ project, which is at least confusing. There is no "bspatch.h" in this repo, so the include actually reffers to the one in bsdiff. This patch uses the "bsdiff/bspatch.h" form instead to avoid confusion. Bug: None Test: It builds. Change-Id: I6b6ffd6725b2b34ff644aed93683f69779103661
2017-11-03Add libbrotli as a dependency when building applypatch binaryTianjie Xu1-0/+1
libbrotli is now used in libbspatch. Bug: 34220646 Test: mma Change-Id: I8d3527141539ffdae112d9042355fd705caeb250
2017-11-03Switch to bionic gtest in bootable/recoveryTianjie Xu3-19/+17
We encountered segfaults in Imgdiff host tests due to the failure to reset states of getopt. The problem can be solved by switching to use bionic's gtest where a new process is forked for each test. Also modify the recovery_component_test to make sure it runs in parallel. Changes include: 1. Merge the writes to misc partition into one single test. 2. Change the hard coded location "/cache/saved.file" into a configurable variable. Bug: 67849209 Test: recovery tests pass Change-Id: I165d313f32b83393fb7922c5078636ac40b50bc2
2017-11-01Add libbrotli as a dependency for libbsdiffTianjie Xu1-0/+1
Bug: 34220646 Test: mma Change-Id: If00285943fff8226f1bc7239db5570a277739904
2017-10-24applypatch: Fix a memory leak in ApplyImagePatch().Tao Bao1-17/+22
$ valgrind --leak-check=full out/host/linux-x86/nativetest64/recovery_host_test/recovery_host_test ==36755== 112 bytes in 1 blocks are definitely lost in loss record 4 of 16 ==36755== at 0x40307C4: malloc (valgrind/coregrind/m_replacemalloc/vg_replace_malloc.c:270) ==36755== by 0x40C1669: operator new(unsigned long) (external/libcxxabi/src/cxa_new_delete.cpp:46) ==36755== by 0x18D6A8: ApplyImagePatch(unsigned char const*, unsigned long, Value const*, std::__1::function<unsigned long (unsigned char const*, unsigned long)>, sha_state_st*, Value const*) (bootable/recovery/applypatch/imgpatch.cpp:62) ==36755== by 0x18D02B: ApplyImagePatch(unsigned char const*, unsigned long, unsigned char const*, unsigned long, std::__1::function<unsigned long (unsigned char const*, unsigned long)>) (bootable/recovery/applypatch/imgpatch.cpp:134) ==36755== by 0x160D15: GenerateTarget(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) (bootable/recovery/tests/component/imgdiff_test.cpp:85) ==36755== by 0x11FA7D: verify_patched_image(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) (bootable/recovery/tests/component/imgdiff_test.cpp:96) ==36755== by 0x12966C: ImgdiffTest_zip_mode_smoke_trailer_zeros_Test::TestBody() (bootable/recovery/tests/component/imgdiff_test.cpp:295) ==36755== by 0x235EF9: testing::Test::Run() (external/googletest/googletest/src/gtest.cc:2455) ==36755== by 0x236CBF: testing::TestInfo::Run() (external/googletest/googletest/src/gtest.cc:2653) ==36755== by 0x2372D6: testing::TestCase::Run() (external/googletest/googletest/src/gtest.cc:2771) ==36755== by 0x23EEE6: testing::internal::UnitTestImpl::RunAllTests() (external/googletest/googletest/src/gtest.cc:4648) ==36755== by 0x23EB45: testing::UnitTest::Run() (external/googletest/googletest/src/gtest.cc:2455) std::unique_ptr<z_stream, decltype(&deflateEnd)> strm(new z_stream(), deflateEnd); Only the internally allocated buffers inside 'strm' would be free'd by deflateEnd(), but not 'strm' itself. This CL fixes the issue by moving 'strm' to stack variable. Note that we only need to call deflateEnd() on successful return of deflateInit2(). Test: recovery_host_test && recovery_component_test Change-Id: I39b9bdf62376b8029f95cab82c8542bfcb874009
2017-10-24Use SuffixArrayIndexInterface opaque type instead of the underlying data pointer.Alex Deymo2-7/+10
bsdiff interface is changing such that it hides the suffix array pointer from the public interface. This allows to use a different suffix array data size depending on the input size, running much faster in the normal case. Bug: 34220646 Test: `make checkbuild`; Ran an incremental update generation on a non-A/B device. Change-Id: I78e766da56cf28bc7774b8c8e58527bc11d919fb
2017-10-16otautil: Move RangeSet implementation into rangeset.cpp.Tao Bao2-0/+3
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-12applypatch: Move to Soong.Tao Bao2-196/+195
Test: mmma bootable/recovery Change-Id: Ie163aff1c4c2b3b15bb705825779ada6bc38ad67
2017-10-12applypatch: Remove the Makefile for building imgdiff in Chrome OS.Tao Bao2-39/+0
The former user system/update_engine has dropped the support for imgdiff (https://android-review.googlesource.com/c/platform/system/update_engine/+/400427/). Test: N/A Change-Id: Ia8f770dc51800b45064c4affc3514cf513877edc
2017-10-11applypatch: Use shared lib for libbz.Tao Bao1-2/+2
We have shared lib target for libbz now (and libbz.so is already on device because of /system/bin/bzip2). Test: m applypatch Change-Id: I5fe2468a8d535840245f081a92d436240dddbf6b
2017-10-11Move rangeset.h and print_sha1.h into otautil.Tao Bao5-21/+21
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-11applypatch: Use shared libs for libbase/libcrypto/liblog/libziparchive.Tao Bao1-6/+3
This reduces the size of /system/bin/applypatch by ~69KB (aosp_bullhead-userdebug). Also remove the unneeded libcutils dependency. Test: mmma bootable/recovery Test: Check that /system/bin/install-recovery.sh successfully installs the recovery image. Change-Id: I5063be9a9b7b8029d45ab5c2a7c45ef2cda81d26
2017-10-09edify: Export the header and move to Soong.Tao Bao1-0/+1
Also make matching changes to applypatch modules which include edify/expr.h. Test: mmma bootable/recovery Change-Id: Ia72be3caa010d7f56a70add2da345e631b306378
2017-10-09Revert "Revert "Move error_code.h into otautil.""Tao Bao1-0/+1
This reverts commit 26436d6d6010d5323349af7e119ff8f34f85c40c 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-09applypatch: Forward declare struct Value.Tao Bao4-2/+8
And move '#include "edify/expr.h"' into .cpp files. This breaks the transitive dependency on libedify. Modules that include "applypatch/applypatch.h" don't need to add libedify into their dependency list, unless they really need anything from libedify. Build libedify static library for host, which is needed by libimgpatch. Test: mmma bootable/recovery Change-Id: Ibb53d322579fcbf593438d058d9bcee240625941
2017-10-05Revert "Move error_code.h into otautil."Tao Bao1-5/+0
This reverts commit 623fe7e701d5d0fb17082d1ced14498af1b44e5b. Reason for revert: Need to address device-specific modules. Change-Id: Ib7a4191e7f193dfff49b02d3de76dda856800251
2017-10-04Move error_code.h into otautil.Tao Bao1-0/+5
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-09-29otafault: Move headers under otafault/.Tao Bao1-1/+1
Test: mmma bootable/recovery Change-Id: I3ceb72f703c7c2857d656c137d71baa1fccd8238
2017-09-29otafault: Remove the use of LOCAL_WHOLE_STATIC_LIBRARIES.Tao Bao1-2/+4
Commit d80a99883d5ae2b117c54f076fe1df7eae86d2f8 has explanation of potential issues. Test: mmma bootable/recovery Change-Id: I25ca9920952b7bbdd8a661d9dc90962431410bc4
2017-09-21Output split information for imgdiff when handling large apksTianjie Xu2-61/+134
Add a mandatory option in imgdiff to write the split info (i.e. patch_size, tgt_size, src_ranges) to file when handling large apks. Therefore, the caller of imgdiff can create split transfers based on the info. Bug: 63542719 Test: unit tests pass Change-Id: I853d55d1f999fd576474faa81077f7307f4d856d
2017-09-06Improve imgdiff for large zip filesTianjie Xu2-19/+480
Due to the cache size limit for OTA generation, we used to split large zip files linearly into pieces and do bsdiff on them. As a result, i) we lose the advantage of imgdiff; ii) if there's an accidental order change of some huge files inside the zip, we'll create an insanely large patch. This patch splits the src&tgt more smartly based on the zip entry_name. If the entry_name is empty or no matching source is found for a target chunk, we'll skip adding its source and later do a bsdiff against the whole split source image (this rarely happens in our use cases except for the metadata inside a ziparchive). After the split, the target pieces are continuous and block aligned, while the sources pieces are mutually exclusive. (Some of the source blocks may not be used if there's no matching entry_name in the target.) Then we will generate patches accordingly between each split image pairs. Afterwards, if we apply imgpatch to each pair of split source/target images and add up the patched result, we can get back the original target image. For example: Input: [src_image, tgt_image] Split: [src-0,tgt-0; src-1,tgt-1, src-2,tgt-2] Diff: [ patch-0; patch-1; patch-2] Patch: [(src-0,patch-0)=tgt-0; (src-1,patch-1)=tgt-1; (src-2,patch-2)=tgt-2;] Append: [tgt-0 + tgt-1 + tgt-2 = tgt_image] Peformance: For the small package in b/34220646, we decrease the patch size of chrome.apk dramatically from 30M to 400K due to the order change of two big .so files. On two versions of angler, I also observe decent patch size decrease. For chrome.apk, we reduced the size from 5.9M to 3.2M; and for vevlet.apk from 8.0M to 6.5M. Bug: 34220646 Test: recovery component test && apply imgdiff & imgpatch on two chrome.apk Change-Id: I145d802984fa805efbbac9d01a2e64d82ef9728b
2017-08-29Turn on -Wall for recovery modulesTianjie Xu1-3/+7
Turn on -Wall for all modules. Also remove the obsolete file_cmp() in apply_patch test and now() in wear_ui. The only exception is lib_edify due to the unused functions in the intermediate cpp files generated from the lex files. It will be handled in a seperate CL. Bug: 64939312 Test: mma, unit tests pass Change-Id: Ic53f76b60b6401ab20db3d98130d674c08e3702f
2017-08-19Move Image/ImageChunk/PatchChunk declaration into header filesTianjie Xu3-272/+319
1. Move the declaration of the Image classes to the header file to make testing easier. 2. Also move rangeset.h to bootable/recovery to allow access in imgdiff. Test: recovery component test Change-Id: I68a863e60a3f2e7ae46ee48f48eb15391f5f4330
2017-08-13Add a new PatchChunk class in imgdiffTianjie Xu1-236/+292
This way we can keep the input images const when calling genetatepatches(). Test: recovery component test; diff and patch on chrome.apk; generate recovery-from-boot.p for angler. Change-Id: I65b5689b88f6719c6ede46bb82def0c4caeb8a61
2017-08-02Refactor the imgdiffTianjie Xu2-393/+569
This helps us to add a new mode to handle large APKs in the follow up CL. Changes include: 1. Create a new interface class 'Image' 1. Create subclasses 'ZipModeImage' and 'ImageModeImage' and move the related functions there. Bug: 63542719 Test: recovery_component_test passes Change-Id: I7729b0ba39b19a9c84811636a60dd0a0b1acc2f0
2017-07-07Fix a rare failure for imgdiff when random data equals gzip headerTianjie Xu1-11/+14
In a rare case, a random chunk will pass both the gzip header check and the inflation process; but fail the uncompressed length check in the footer. This leads to a imgdiff failure. So, we should treat this chunk as 'normal' instead of 'inflated' while generating the patch. Bug: 63334984 Test: imgdiff generates patch successfully on previous failing images. Change-Id: Ice84f22d3653bce9756bda91e70528c0d2f264a0
2017-05-26Implement a custom deflate sink function for bspatchTianjie Xu1-58/+86
This new sink function works as a wrapper of the old sink. It deflates the available patch data on the fly. Therefore, we don't need to store the full uncompressed patch data in memory. Test: recovery_component_test && apply an incremental update on angler Change-Id: I2274ec50a1607089abcc9d0954a2a748f28c3122
2017-05-16Print SHA1 of the patch if bsdiff fails with data errorTianjie Xu3-22/+32
This will help us to identify the patch corruption. Meanwhile fix a wrong size parameter passed to bspatch. (patch->data.size() into patch->data.size() - patch_offset). Also remove the only usage of "ApplyBSDiffPatchMem()" and inline its Sink function for simplicity. Bug: 37855643 Test: Prints SHA1 for corrupted patch in imgdiff_test. Change-Id: Ibf2db8c08b0ded1409bb7c91a3547a6bf99c601d
2017-04-26applypatch: Remove the obsolete support for "applypatch -s".Tao Bao1-17/+1
The SpaceMode (applypatch -s) was used in amend script (cupcake) only, which has been removed since commit 9ce2ebf5d300eba5f6086583b0941ef68a3e4b42 (platform/build). The later (and current) edify script uses apply_patch_space(). Note that other modes (PatchMode, CheckMode) of applypatch executable are mostly used by install-recovery.sh script. Test: No active user of "applypatch -s". Test: recovery_component_test Change-Id: I1d689b7fedd3884077e88ed1d6c22f7a2198859d
2017-04-26applypatch: Add determine the return value of ApplyDiffPatch andJinguang Dong1-1/+4
capture the error flow. Construct ota package which is bsdiff exception scene ,then do simulation test, native code can not capture exception scenes. Test: recovery_component_test Test: Apply an bsdiff exception scene ota package. Change-Id: Icd9f6eac78739bd35c74b9fcaaf8154335d680a5
2017-04-02applypatch: Remove duplicate test files.Tao Bao5-468/+0
CL in commit b8a693bbc73808924f4be8c4d47bbc4da0647e3a has ported the tests to gtest-based recovery_component_tests. Test: N/A Change-Id: I485fa11413df68a11416d4a9f91f090f302bcfc0
2017-03-28applypatch: Let Apply{BSDiff,Image}Patch accept std::function.Tao Bao5-30/+28
Test: mmma bootable/recovery system/update_engine Test: recovery_component_test Change-Id: I93c2caa87bf94a53509bb37f98f2c02bcadb6f5c
2017-03-28applypatch: Change the ssize_t length parameters to size_t.Tao Bao5-47/+40
Mostly for applypatch family APIs like ApplyBSDiffPatch() and ApplyImagePatch(). Changing to size_t doesn't indicate they would necessarily work with very large size_t (e.g. > ssize_t), just similar to write(2). But otherwise accepting negative length doesn't make much sense. Also change the return type of SinkFn from ssize_t to size_t. Callers tell a successful sink by comparing the number of written bytes against the desired value. Negative return values like -1 are not needed. This also makes it consistent with bsdiff::bspatch interface. Test: recovery_component_test Test: Apply an incremental with the new updater. Change-Id: I7ff1615203a5c9854134f75d019e266f4ea6e714
2017-03-16More cleanup to imgdiff & imgpatchTianjie Xu5-193/+128
Also remove the utils in applypatch and replace them with the corresponding libbase functions. Test: recovery tests pass. Change-Id: I77254c141bd3e7d3d6894c23b60e866009516f81
2017-03-16applypatch: Drop the support for patching non-EMMC targets.Tao Bao1-277/+109
Patching regular files is used in file-based OTA only, which has become obsolete. Bug: 35853185 Test: Apply an incremental that patches the boot.img. Test: /system/bin/install-recovery.sh works. Test: recovery_component_test passes. Change-Id: Id44e42c4bc63f2162ecc8a6df1cb528b7ae6b0a9
2017-03-07Refractor the code for imgdiffTianjie Xu2-618/+596
Put ImageChunk and some helper functions into a class. Also switch to using std::vector instead of malloc. Bug: 18606652 Test: imgdiff_test passed on host. Also generate a complete incremental OTA package. The file content is the same and time consumption is similar. Change-Id: Id603ada4e130ef521218400761a119001a86ca79
2017-02-02Use bspatch from external/bsdiff.Sen Jiang3-183/+28
Now ApplyBSDiffPatch() will stream the output to sink as we go instead of sinking everything at the end. Test: recovery_host_test Bug: 26982501 Change-Id: I05b6ed40d45e4b1b19ae72784cf705b731b976e3
2017-01-20imgpatch: Compile with ZLIB_CONST defined.Tao Bao2-4/+10
So z_stream.next_in takes pointer to const data. Test: mmma bootable/recovery/applypatch Change-Id: If269b766a7c84fa2f67424ee61ba5afab0159261
2017-01-19imgdiff: cache bsdiff suffix array in zip mode.Sen Jiang2-16/+20
In zip mode, if a chunk is not deflate or its filename can't be found in source chunks, the entire source file is used as old data for bsdiff, To avoid repeatedly construct the suffix array used by bsdiff, we cache the suffix array of the entire source file. Bug: 34281147 Test: =time -v imgdiff -z Chrome-ORF74B.apk Chrome-ORF76B.apk Chrome.imgdiff Change-Id: Ifd957ccecf7226fcb44dbf28c58969a06ef74f4b
2016-12-28imgdiff: Fix an edge case that leads to infinite loop.Tao Bao2-15/+11
When the input image ends with the magic value sequence of 0x1f, 0x8b, 0x0b (optionally with 0x00), the image parsing code will be stuck in an infinite loop. Test: recovery_component_test passes. Change-Id: Ie3629dfdc41360387b19cc3e0359c95ae4fb998e
2016-12-28applypatch: Don't expose FindMatchingPatch().Tao Bao2-3/+2
Test: make Change-Id: Ic77c4669574b6129e06aa6051804f419bcc8196c
2016-12-20Add tests for imgdiff.Tao Bao6-266/+335
Factor out libimgdiff static library for testing purpose. This CL adds the imgdiff tests on host and on target both (similar to libimgpatch). In practice, we only need imgdiff binary on host, and libimgpatch on target. But they should build and pass tests on both platforms. Test: recovery_host_test passes; recovery_component_test passes. Change-Id: I0eafb7faf727cdf70066310e845af6ee245d4f60
2016-12-19Bugfix:updater always retry apply patch failed,when memcpy failed.katao1-0/+11
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-07bootable/recovery: cleanup compiler warnings (potential leak of memory)Rahul Chaudhry1-0/+1
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-11-30bootable/recovery: cleanup compiler warnings (unused value)Rahul Chaudhry1-0/+16
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-28Remove ota_close(int) and ota_fclose(FILE*).Tao Bao1-2/+2
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-23Add ota_close(unique_fd&) and ota_fclose(std::unique_ptr<FILE>&).Tao Bao1-7/+7
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 48cf770471ef53fbf0a1837196220862a0bdb18d. Bug: 33034669 Test: recovery_component_test passes. Change-Id: Ief91edc590e95a7426e33364b28754173efb1056
2016-11-21applypatch: Release FD when explicitly calling close.Tao Bao1-5/+5
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-17applypatch: Use unique_fd to avoid leaking FDs.Tao Bao1-282/+270
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-17applypatch: Clean up LoadPartitionContents().Tao Bao1-283/+257
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-16Use static_cast to cast pointers returned by malloc/calloc/realloc/mmap.Rahul Chaudhry1-16/+16
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-16bootable/recovery: cleanup compiler warnings (potential leak of memory)Rahul Chaudhry1-0/+4
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-09Use static_cast to cast pointers returned by malloc/calloc/realloc/mmap.Rahul Chaudhry1-16/+16
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: I151642d5a60c94f312d0611576ad0143c249ba3d
2016-11-01applypatch: Add testcases for applypatch executable.Tao Bao4-30/+102
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-10-29applypatch: Switch the parameter of Value** to std::vector.Tao Bao3-23/+23
Test: Unit tests and install-recovery.sh pass on angler and dragon. Change-Id: I328e6554edca667cf850f5584ebf1ac211e3d4d1
2016-10-25applypatch: Fix the bug when constructing VAL_BLOB.Tao Bao1-2/+3
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-18Fix applypatch_check failure when applying update on anglerTianjie Xu1-1/+1
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-18Replace minzip with libziparchiveTianjie Xu1-1/+0
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-15Change StringValue to use std::stringTianjie Xu7-79/+75
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-09-30Turn on -Werror for recoveryTianjie Xu1-0/+5
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 (cherry picked from commit 7aa88748f6ec4e53333d1a15747bc44826ccc410)
2016-09-30Turn on -Werror for recoveryTianjie Xu1-0/+5
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-01Switch recovery to libbase loggingTianjie Xu1-1/+1
Clean up the recovery image and switch to libbase logging. Bug: 28191554 Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35 (cherry picked from commit 747781433fb01f745529c7e9dd97c5599070ad0d)
2016-09-01Switch recovery to libbase loggingTianjie Xu1-1/+1
Clean up the recovery image and switch to libbase logging. Bug: 28191554 Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35 Merged-In: Icd999c3cc832f0639f204b5c36cea8afe303ad35
2016-09-01Switch recovery to libbase loggingTianjie Xu1-1/+1
Clean up the recovery image and switch to libbase logging. Bug: 28191554 Change-Id: Icd999c3cc832f0639f204b5c36cea8afe303ad35
2016-09-01Check an edge case when read(2) returns 0Tianjie Xu1-0/+3
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-06Fix references to libcrypto_utils_static.Josh Gao1-4/+4
Bug: http://b/30708454 Change-Id: I7a5048beff1d8b783a9683dcb4a79606a77f20ee
2016-06-14applypatch: Don't call inflate() when it expects zero-length output.Tao Bao1-57/+66
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-10Remove obsolete MTD support.Elliott Hughes3-213/+105
Bug: http://b/29250988 Change-Id: Ia97ba9082a165c37f74d6e1c3f71a367adc59945
2016-06-01Revert "Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector."Tao Bao1-38/+40
This reverts commit 51dc9444bcf8d8900a521795e873d07f6cd445ef. A new/free mismatch may lead to memory corruptions. Change-Id: I3e10ae9e514abe59c351d2f27bedd3f8fcd1d137
2016-06-01Revert "Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector."Tao Bao1-38/+40
This reverts commit 50a6f8c8335be920833d06e5dabd37de279c98a9. A mix of new and free leads to memory corruptions.
2016-06-01Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector.Adam Buchbinder1-40/+38
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 51dc9444bcf8d8900a521795e873d07f6cd445ef)
2016-06-01Revert "imgdiff: Generate statically linked imgdiff."Tao Bao1-2/+1
This reverts commit b4422bd76952be4321cfbce3220bcb4fd41b5154. Bug: 28941046 Change-Id: Ic3c7439c64b8e55832252850514f721a944993d6
2016-05-31imgdiff: Generate statically linked imgdiff.Tao Bao1-1/+2
Bug: 28941046 Change-Id: If3019d8cff91fd4f6fa4516bef5a0f51c2ddebc7
2016-05-26Fix memory/resource handling in imgdiff.cpp, using unique_ptr and vector.Adam Buchbinder1-40/+38
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
2016-05-04applypatch: Use bsdiff from external/bsdiff.Sen Jiang3-425/+10
external/bsdiff uses divsufsort which is much faster, and also include some bug fixes. Bug: 26982501 Test: ./imgdiff_test.sh Change-Id: I089a301c291ee55d79938c7a3ca6d509895440d1
2016-04-18Fix google-runtime-int warnings.Chih-Hung Hsieh4-15/+16
Bug: 28220065 Change-Id: Ida199c66692a1638be6990d583d2ed42583fb592
2016-03-19Control fault injection with config files instead of build flagsJed Estep1-1/+1
Bug: 27724259 Change-Id: I65bdefed10b3fb85fcb9e1147eaf0687d7d438f4
2016-03-17Revert "DO NOT MERGE Control fault injection with config files instead of build flags"Tao Bao1-1/+1
This reverts commit f73abf36bcfd433a3fdd1664a77e8e531346c1b1. Bug: 27724259 Change-Id: I1301fdad15650837d0b1febd0c3239134e2b94fb
2016-03-16DO NOT MERGE Control fault injection with config files instead of build flagsJed Estep1-1/+1
Bug: 26570379 Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c
2016-03-14Add include/ to the Makefile include path.Alex Deymo1-1/+1
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-11applypatch: use vector to store data in FileContents.Yabin Cui3-117/+67
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 d6c93afcc28cc65217ba65eeb646009c4f15a2ad)
2016-03-09applypatch: add -fPIC for libimgpatch in Chrome OS.Sen Jiang1-0/+1
To make the static library position independent. Bug: 26866274 Test: emerge-peppy imgdiff; sudo emerge imgdiff; emerge nyan imgdiff Change-Id: I319e721ccfb6a51f63d31afa49f54aa7f607f4bf
2016-03-03Fix the improper use of LOCAL_WHOLE_STATIC_LIBRARIES.Tao Bao7-25/+49
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-02-23Control fault injection with config files instead of build flagsJed Estep1-1/+1
Bug: 26570379 Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c (cherry picked from commit d940887dde23597dc358b16d96ca48dd7480fee6)
2016-02-20Control fault injection with config files instead of build flagsJed Estep1-1/+1
Bug: 26570379 Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c
2016-02-16applypatch: Add libimgpatch.pcSen Jiang1-0/+6
Test: pkg-config --libs libimgpatch Bug: 26866274 Change-Id: I79a103099d951943a88768c577224fccacbb79e3
2016-02-12imgdiff: don't fail if gzip is corrupted.Sen Jiang1-12/+10
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-12applypatch: use vector to store data in FileContents.Yabin Cui3-116/+66
Bug: 26906416 Change-Id: Ib53b445cd415a1ed5e95733fbc4073f9ef4dbc43
2016-02-10IO fault injection for OTA packagesJed Estep2-28/+29
Bug: 25951086 Change-Id: I31c74c735eb7a975b7f41fe2b2eff042e5699c0c (cherry-picked from commit f1fc48c6e62cfee42d25ad12f443e22d50c15d0b)
2016-02-10applypatch: Add a Makefile to build imgdiff in Chrome OS.Sen Jiang6-4/+39
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-05applypatch: fix memory leaks reported by static analysis.Yabin Cui7-303/+202
Bug: 26906416 Change-Id: I163df5a8f3abda3ba5d4ed81dfc8567054eceb27
2016-02-04Switch from mincrypt to BoringSSL in applypatch and updater.Sen Jiang6-38/+37
Bug: 18790686 Change-Id: I7d2136fb39b2266f5ae5be24819c617b08a6c21e
2016-01-29Fix build.Tao Bao1-0/+2
Disable libimgpatch for non-Linux host. Change-Id: Ib3615204b76564c691ddafaa29e59fef334d9d36
2016-01-28applypatch: Compile libimgpatch for target and host.Sen Jiang4-2/+69
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-06IO fault injection for OTA packagesJed Estep2-26/+27
Bug: 25951086 Change-Id: I31c74c735eb7a975b7f41fe2b2eff042e5699c0c
2015-12-23imgdiff: skip spurious gzip headers in image filesDavid Riley1-6/+13
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-05Track rename from base/ to android-base/.Elliott Hughes1-1/+1
Change-Id: I354a8c424d340a9abe21fd716a4ee0d3b177d86f
2015-12-02Remove the building rules for applypatch_static.Tao Bao1-13/+0
The CL in [1] has stopped building and packaging the obsolete applypatch_static tool. [1]: commit a04fca31bf1fadcdf982090c942ccbe4d9b95c71 Bug: 24621915 Change-Id: I5e98951ad7ea5c2a7b351af732fd6722763f59bd
2015-11-16applypatch: Fix the checking in WriteToPartition().Tao Bao1-3/+4
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: I9d0236eaf97df9db9704acf53690d0ef85188e45 (cherry picked from commit 1ce7a2a63db84527e6195a6b123b1617f87c0f38)
2015-11-16applypatch: Support flash mode.Tao Bao3-16/+97
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: I345eaaee269f6443527f45a9be7e4ee47f6b2b39 (cherry picked from commit 68c5a6796737bb583a8bdfa4c9cd9c7f12ef4276)
2015-11-16applypatch: Refactor strtok().Tao Bao2-86/+56
We have android::base::Split() for the work. Change-Id: Ic529db42090f700e6455d465c8b84b7f52d34d63 (cherry picked from commit 0a47ce27de454e272a883a0c452fad627fd7f419)
2015-11-16DO NOT MERGE recovery: Switch applypatch/ and updater/ to cpp.Tao Bao9-186/+183
Mostly trivial changes to make cpp compiler happy. Change-Id: I69bd1d96fcccf506007f6144faf37e11cfba1270 (cherry picked from commit ba9a42aa7e10686de186636fe9fecbf8c4cc7c19)
2015-11-16Stop using libstdc++.Dan Albert1-2/+2
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 (cherry picked from commit e49a9e527a51f43db792263bb60bfc91293848da)
2015-11-16recovery: Switch to clangTao Bao1-0/+5
And a few trival fixes to suppress warnings. Change-Id: Id28e3581aaca4bda59826afa80c0c1cdfb0442fc (cherry picked from commit 80e46e08de5f65702fa7f7cd3ef83f905d919bbc)
2015-09-08imgdiff: fix file descriptor leakJeremy Compostella1-1/+9
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-08-06updater: Clean up char* with std::string.Tao Bao1-11/+1
So we can remove a few free()s. And also replace a few pointers with references. Change-Id: I4b6332216704f4f9ea4a044b8d4bb7aa42a7ef26
2015-07-25applypatch: Fix the checking in WriteToPartition().Tao Bao1-3/+4
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-24applypatch: Support flash mode.Tao Bao3-16/+97
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 68c5a6796737bb583a8bdfa4c9cd9c7f12ef4276)
2015-07-24applypatch: Refactor strtok().Tao Bao2-86/+56
We have android::base::Split() for the work. Change-Id: I0fb562feb203c9b15e2f431d8e84355fd682376a (cherry picked from commit 0a47ce27de454e272a883a0c452fad627fd7f419)
2015-07-22applypatch: Support flash mode.Tao Bao3-16/+97
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: I345eaaee269f6443527f45a9be7e4ee47f6b2b39
2015-07-17applypatch: Refactor strtok().Tao Bao2-86/+56
We have android::base::Split() for the work. Change-Id: Ic529db42090f700e6455d465c8b84b7f52d34d63
2015-07-14recovery: Switch applypatch/ and updater/ to cpp.Tao Bao9-186/+183
Mostly trivial changes to make cpp compiler happy. Change-Id: I1b0481465c67c3bbca35a839d0764190d84ff34e (cherry picked from commit ba9a42aa7e10686de186636fe9fecbf8c4cc7c19)
2015-07-14recovery: Switch applypatch/ and updater/ to cpp.Tao Bao9-186/+183
Mostly trivial changes to make cpp compiler happy. Change-Id: I69bd1d96fcccf506007f6144faf37e11cfba1270
2015-06-26Use f_bavail to calculate free spacecaozhiyuan1-1/+1
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. Bug: 22118089 Change-Id: I81c9531703298019a4fc11839f28d2cc8b9df34e (cherry picked from commit 3b4977638f48e59d23d7ea2bb6dde78552c257fb)
2015-06-03recovery: Switch to clangTao Bao1-0/+5
And a few trival fixes to suppress warnings. Change-Id: I38734b5f4434643e85feab25f4807b46a45d8d65
2015-05-29Use f_bavail to calculate free spacecaozhiyuan1-1/+1
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-19Stop using libstdc++.Dan Albert1-2/+2
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-04-30Check all lseek calls succeed.Elliott Hughes1-24/+27
Also add missing TEMP_FAILURE_RETRYs on read, write, and lseek. Bug: http://b/20625546 Change-Id: I03b198e11c1921b35518ee2dd005a7cfcf4fd94b (cherry picked from commit 7bad7c4646ee8fd8d6e6ed0ffd3ddbb0c1b41a2f)
2015-04-30Check all lseek calls succeed.Elliott Hughes1-24/+27
Also add missing TEMP_FAILURE_RETRYs on read, write, and lseek. Bug: http://b/20625546 Change-Id: I03b198e11c1921b35518ee2dd005a7cfcf4fd94b
2015-04-15imgdiff: Avoid infinite loop if inflate failsJohan Redestig1-0/+9
Break out of the loop if inflate returns an error and print some details. Change-Id: Ie157cf943291b1a26f4523b17691dfcefbc881dc
2015-01-30Add missing includes.Elliott Hughes1-0/+1
Change-Id: I06ea08400efa511e627be37a4fd70fbdfadea2e6
2015-01-28Add missing includes.Elliott Hughes1-0/+1
Change-Id: I0737456e0221ebe9cc854d65c95a7d37d0869d56
2014-10-29Use more aggressive sync writing to applypatch.Michael Runge1-8/+36
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-08-20installer for new block OTA systemDoug Zongker4-9/+7
(Cherry-pick back from master.) Bug: 16984795 Change-Id: Ifa3d8345c5e2a0be86fb28faa080ca82592a96b4
2014-08-19installer for new block OTA systemDoug Zongker4-9/+7
Bug: 16984795 Change-Id: I90f958446baed83dec658de2430c8fc5e9c3047e
2014-05-13fix vulnerability in bspatchDoug Zongker1-0/+5
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-03-14Recovery 64-bit compile issuesMark Salyzyn2-9/+10
Change-Id: I92d5abd1a628feab3b0246924fab7f97ba3b9d34
2014-02-14remove remaining libminelf referencesDoug Zongker1-2/+2
Change-Id: Id38b08607829bccc031693cc03e60e849903b6f8
2014-02-14remove 'retouch' ASLR supportDoug Zongker3-32/+11
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
2013-12-20fix unnecessarily slow writing of EMMC partitionsDoug Zongker1-15/+3
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-09-25verifier: update to support certificates using SHA-256Doug Zongker1-1/+1
(cherry picked from commit bac7fba02763ae5e78e8e4ba0bea727330ad953e) Change-Id: I01c38d7fea088622a8b0bbf2c833fa2d969417af
2013-07-11recovery: remove O_DIRECT, use O_SYNC onlyDoug Zongker1-2/+2
O_DIRECT writes fail with EINVAL due to alignment issues. Change-Id: If8cf38a636313e4f4b4e61e66287dc903c473e5b
2013-07-11recovery: more cargo-cult programmingDoug Zongker1-2/+2
Add O_DIRECT|O_SYNC when opening partitions for write. Change-Id: I9825ad8e60fba87e482f8abc5593d6f54a1e3a1c
2013-07-11recovery: sleep after writing partition and closing itDoug Zongker1-2/+7
Another speculative attempt to get everything we write actually stored to the device. Change-Id: Icf40b0741b4c535e55ea34848073a97d90dc0e70
2013-07-10recovery: sleep after writing partition and closing itDoug Zongker1-2/+7
Another speculative attempt to get everything we write actually stored to the device. Change-Id: Icf40b0741b4c535e55ea34848073a97d90dc0e70
2013-07-10recovery: write partitions more conservativelyDoug Zongker1-24/+46
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-10recovery: try to write EMMC partitions more reliablyDoug Zongker2-7/+73
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-09recovery: write partitions more conservativelyDoug Zongker1-24/+46
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-08recovery: try to write EMMC partitions more reliablyDoug Zongker2-7/+73
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-04-10verifier: update to support certificates using SHA-256Doug Zongker1-1/+1
Change-Id: Ifd5a29d459acf101311fa1c220f728c3d0ac2e4e
2012-10-19reduce some recovery loggingDoug Zongker1-6/+21
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-08-21add bonus data feature to imgdiff/imgpatch/applypatchDoug Zongker5-21/+99
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-14host modules don't need LOCAL_MODULE_TAGSJoe Onorato1-1/+0
Change-Id: I5e1df90f18fbaf98e3207c553a8fb859c1064137
2012-07-22host modules don't need LOCAL_MODULE_TAGSJoe Onorato1-1/+0
Change-Id: I5e1df90f18fbaf98e3207c553a8fb859c1064137
2012-06-27Add mode when open(O_CREAT) is used.Nick Kralevich1-2/+2
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-04-06Add NOTICE fileWei Zhong1-0/+41
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-02-28fix buildDoug Zongker2-2/+2
Change-Id: I44a75f5451af053778be299b23274ecce9b2db76
2012-02-28fix failure to free memoryDoug Zongker2-19/+45
The applypatch function is somewhat sloppy about freeing memory (since it was originally a standalone binary). Fix some of that. Change-Id: Ifd44d71ea189c0b5115493119fd57bc37533fd59
2011-07-12Remove the simulator target from all makefiles.Jeff Brown1-4/+0
Bug: 5010576 Change-Id: Ib465fdb42c8621899bea15c04a427d7ab1641a8c
2011-02-09Fix x86 build.Ying Wang1-2/+0
Change-Id: Iada6268b0a72ee832113ea397334cc7950a37051
2010-09-15(cherry-pick) EMMC support in applypatchDoug Zongker1-102/+175
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: Ib1861219c7ca66dff29ad02d6a0a14e5f03eb4d8
2010-08-13fix bug in applying patchesDoug Zongker1-1/+1
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-13remove shadowed variable declarationDoug Zongker1-1/+2
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-13remove shadowed variable declarationDoug Zongker1-1/+2
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-13fix bug in applying patchesDoug Zongker1-1/+1
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-02Working ASLR implementationHristo Bojinov4-16/+41
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-07-08EMMC support in applypatchDoug Zongker1-102/+175
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-05-04generic_x86 supportBruce Beare1-0/+2
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-02-23refactor applypatch and friendsDoug Zongker9-1256/+1185
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-18relocate applypatch; add type system and new functions to edifyDoug Zongker17-0/+3882
- 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