new image diffing tool and support for image patches in applypatch
Images (like boot and recovery) consist of large sections of gzipped
data interspersed with other data. To do effective binary patching of
these files, we need to apply patches to the gzipped parts in
'uncompressed space', that is, we decompress, apply a patch, then
recompress to obtain the desired output.
This change defines a new format with these patches, which is
basically a description of how the source and target files are to be
divided up into chunks and a bsdiff patch for each chunk. We add a
new host executable, "imgdiff", for generating these patches from
source and target images, and add support in applypatch for
recognizing this format and applying it on the device.
diff --git a/tools/applypatch/applypatch.c b/tools/applypatch/applypatch.c
index 23b41d7..b9f28a2 100644
--- a/tools/applypatch/applypatch.c
+++ b/tools/applypatch/applypatch.c
@@ -431,11 +431,19 @@
} else if (header_bytes_read >= 8 &&
memcmp(header, "BSDIFF40", 8) == 0) {
int result = ApplyBSDiffPatch(source_to_use->data, source_to_use->size,
- patch_filename, output, &ctx);
+ patch_filename, 0, output, &ctx);
if (result != 0) {
fprintf(stderr, "ApplyBSDiffPatch failed\n");
return result;
}
+ } else if (header_bytes_read >= 8 &&
+ memcmp(header, "IMGDIFF1", 8) == 0) {
+ int result = ApplyImagePatch(source_to_use->data, source_to_use->size,
+ patch_filename, output, &ctx);
+ if (result != 0) {
+ fprintf(stderr, "ApplyImagePatch failed\n");
+ return result;
+ }
} else {
fprintf(stderr, "Unknown patch file format");
return 1;