From f47259b18492c921445d9e437a9f9ed11c52fac6 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Fri, 17 Jul 2015 18:11:12 -0700 Subject: 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: I345eaaee269f6443527f45a9be7e4ee47f6b2b39 (cherry picked from commit 68c5a6796737bb583a8bdfa4c9cd9c7f12ef4276) --- applypatch/main.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'applypatch/main.cpp') diff --git a/applypatch/main.cpp b/applypatch/main.cpp index 63ff5c2c0..966d8b91f 100644 --- a/applypatch/main.cpp +++ b/applypatch/main.cpp @@ -47,8 +47,8 @@ static int SpaceMode(int argc, char** argv) { // ":" into the new parallel arrays *sha1s and // *patches (loading file contents into the patches). Returns true on // success. -static bool ParsePatchArgs(int argc, char** argv, - char*** sha1s, Value*** patches, int* num_patches) { +static bool ParsePatchArgs(int argc, char** argv, char*** sha1s, + Value*** patches, int* num_patches) { *num_patches = argc; *sha1s = reinterpret_cast(malloc(*num_patches * sizeof(char*))); *patches = reinterpret_cast(malloc(*num_patches * sizeof(Value*))); @@ -98,7 +98,12 @@ static bool ParsePatchArgs(int argc, char** argv, return false; } -int PatchMode(int argc, char** argv) { +static int FlashMode(const char* src_filename, const char* tgt_filename, + const char* tgt_sha1, size_t tgt_size) { + return applypatch_flash(src_filename, tgt_filename, tgt_sha1, tgt_size); +} + +static int PatchMode(int argc, char** argv) { Value* bonus = NULL; if (argc >= 3 && strcmp(argv[1], "-b") == 0) { FileContents fc; @@ -114,7 +119,7 @@ int PatchMode(int argc, char** argv) { argv += 2; } - if (argc < 6) { + if (argc < 4) { return 2; } @@ -125,6 +130,16 @@ int PatchMode(int argc, char** argv) { return 1; } + // If no : is provided, it is in flash mode. + if (argc == 5) { + if (bonus != NULL) { + printf("bonus file not supported in flash mode\n"); + return 1; + } + return FlashMode(argv[1], argv[2], argv[3], target_size); + } + + char** sha1s; Value** patches; int num_patches; @@ -162,6 +177,10 @@ int PatchMode(int argc, char** argv) { // - if the sha1 hash of is , does nothing and exits // successfully. // +// - otherwise, if no : is provided, flashes with +// . must be a partition name, while must +// be a regular image file. will not be deleted on success. +// // - otherwise, if the sha1 hash of is , applies the // bsdiff to to produce a new file (the type of patch // is automatically detected from the file header). If that new -- cgit v1.2.3