diff options
Diffstat (limited to 'applypatch')
-rw-r--r-- | applypatch/Android.mk | 27 | ||||
-rw-r--r-- | applypatch/applypatch.c | 42 |
2 files changed, 58 insertions, 11 deletions
diff --git a/applypatch/Android.mk b/applypatch/Android.mk index 4984093dd..2cce81f6d 100644 --- a/applypatch/Android.mk +++ b/applypatch/Android.mk @@ -15,11 +15,22 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) +BOARD_RECOVERY_DEFINES := BOARD_BML_BOOT BOARD_BML_RECOVERY + +$(foreach board_define,$(BOARD_RECOVERY_DEFINES), \ + $(if $($(board_define)), \ + $(eval LOCAL_CFLAGS += -D$(board_define)=\"$($(board_define))\") \ + ) \ + ) + LOCAL_SRC_FILES := applypatch.c bspatch.c freecache.c imgpatch.c utils.c LOCAL_MODULE := libapplypatch LOCAL_MODULE_TAGS := eng -LOCAL_C_INCLUDES += external/bzip2 external/zlib bootable/recovery -LOCAL_STATIC_LIBRARIES += libmtdutils libmincrypt libbz libz +LOCAL_C_INCLUDES += \ + external/bzip2 \ + external/zlib \ + $(commands_recovery_local_path) +LOCAL_STATIC_LIBRARIES += libmtdutils libmincrypttwrp libbz libz include $(BUILD_STATIC_LIBRARY) @@ -27,8 +38,9 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := main.c LOCAL_MODULE := applypatch -LOCAL_C_INCLUDES += bootable/recovery -LOCAL_STATIC_LIBRARIES += libapplypatch libmtdutils libmincrypt libbz +LOCAL_MODULE_TAGS := optional +LOCAL_C_INCLUDES += $(commands_recovery_local_path) +LOCAL_STATIC_LIBRARIES += libapplypatch libmtdutils libmincrypttwrp libbz LOCAL_SHARED_LIBRARIES += libz libcutils libstdc++ libc include $(BUILD_EXECUTABLE) @@ -38,9 +50,9 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES := main.c LOCAL_MODULE := applypatch_static LOCAL_FORCE_STATIC_EXECUTABLE := true -LOCAL_MODULE_TAGS := eng -LOCAL_C_INCLUDES += bootable/recovery -LOCAL_STATIC_LIBRARIES += libapplypatch libmtdutils libmincrypt libbz +LOCAL_MODULE_TAGS := optional eng +LOCAL_C_INCLUDES += $(commands_recovery_local_path) +LOCAL_STATIC_LIBRARIES += libapplypatch libmtdutils libmincrypttwrp libbz LOCAL_STATIC_LIBRARIES += libz libcutils libstdc++ libc include $(BUILD_EXECUTABLE) @@ -52,5 +64,6 @@ LOCAL_MODULE := imgdiff LOCAL_FORCE_STATIC_EXECUTABLE := true LOCAL_C_INCLUDES += external/zlib external/bzip2 LOCAL_STATIC_LIBRARIES += libz libbz +LOCAL_MODULE_TAGS := eng include $(BUILD_HOST_EXECUTABLE) diff --git a/applypatch/applypatch.c b/applypatch/applypatch.c index 2358d4292..bc45e3c45 100644 --- a/applypatch/applypatch.c +++ b/applypatch/applypatch.c @@ -28,6 +28,7 @@ #include "mincrypt/sha.h" #include "applypatch.h" +#include "bmlutils/bmlutils.h" #include "mtdutils/mtdutils.h" #include "edify/expr.h" @@ -55,7 +56,8 @@ int LoadFileContents(const char* filename, FileContents* file) { // A special 'filename' beginning with "MTD:" or "EMMC:" means to // load the contents of a partition. if (strncmp(filename, "MTD:", 4) == 0 || - strncmp(filename, "EMMC:", 5) == 0) { + strncmp(filename, "EMMC:", 5) == 0 || + strncmp(filename, "BML:", 4) == 0) { return LoadPartitionContents(filename, file); } @@ -131,6 +133,8 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { type = MTD; } else if (strcmp(magic, "EMMC") == 0) { type = EMMC; + } else if (strcmp(magic, "BML") == 0) { + type = EMMC; } else { printf("LoadPartitionContents called with bad filename (%s)\n", filename); @@ -138,6 +142,14 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { } const char* partition = strtok(NULL, ":"); + if (strcmp(magic, "BML") == 0) { + if (strcmp(partition, "boot") == 0) { + partition = BOARD_BML_BOOT; + } else if (strcmp(partition, "recovery") == 0) { + partition = BOARD_BML_RECOVERY; + } + } + int i; int colons = 0; for (i = 0; filename[i] != '\0'; ++i) { @@ -358,12 +370,31 @@ int WriteToPartition(unsigned char* data, size_t len, type = MTD; } else if (strcmp(magic, "EMMC") == 0) { type = EMMC; + } else if (strcmp(magic, "BML") == 0) { + type = EMMC; } else { printf("WriteToPartition called with bad target (%s)\n", target); return -1; } const char* partition = strtok(NULL, ":"); + if (strcmp(magic, "BML") == 0) { + if (strcmp(partition, "boot") == 0) { + partition = BOARD_BML_BOOT; + } else if (strcmp(partition, "recovery") == 0) { + partition = BOARD_BML_RECOVERY; + } + + int bmlpartition = open(partition, O_RDWR | O_LARGEFILE); + if (bmlpartition < 0) + return -1; + if (ioctl(bmlpartition, BML_UNLOCK_ALL, 0)) { + printf("failed to unlock BML partition: (%s)\n", partition); + return -1; + } + close(bmlpartition); + } + if (partition == NULL) { printf("bad partition target name \"%s\"\n", target); return -1; @@ -838,7 +869,8 @@ static int GenerateTarget(FileContents* source_file, // file? if (strncmp(target_filename, "MTD:", 4) == 0 || - strncmp(target_filename, "EMMC:", 5) == 0) { + strncmp(target_filename, "EMMC:", 5) == 0 || + strncmp(target_filename, "BML:", 4) == 0) { // If the target is a partition, we're actually going to // write the output to /tmp and then copy it to the // partition. statfs() always returns 0 blocks free for @@ -880,7 +912,8 @@ static int GenerateTarget(FileContents* source_file, // location. if (strncmp(source_filename, "MTD:", 4) == 0 || - strncmp(source_filename, "EMMC:", 5) == 0) { + strncmp(source_filename, "EMMC:", 5) == 0 || + strncmp(source_filename, "BML:", 4) == 0) { // It's impossible to free space on the target filesystem by // deleting the source if the source is a partition. If // we're ever in a state where we need to do this, fail. @@ -925,7 +958,8 @@ static int GenerateTarget(FileContents* source_file, output = -1; outname = NULL; if (strncmp(target_filename, "MTD:", 4) == 0 || - strncmp(target_filename, "EMMC:", 5) == 0) { + strncmp(target_filename, "EMMC:", 5) == 0 || + strncmp(target_filename, "BML:", 4) == 0) { // We store the decoded output in memory. msi.buffer = malloc(target_size); if (msi.buffer == NULL) { |