diff options
Diffstat (limited to 'applypatch')
-rw-r--r-- | applypatch/Android.mk | 24 | ||||
-rw-r--r-- | applypatch/applypatch.cpp | 46 |
2 files changed, 57 insertions, 13 deletions
diff --git a/applypatch/Android.mk b/applypatch/Android.mk index 887a570db..48eab014e 100644 --- a/applypatch/Android.mk +++ b/applypatch/Android.mk @@ -16,26 +16,30 @@ 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_C_INCLUDES += \ + external/bzip2 \ + external/zlib \ + $(commands_recovery_local_path) + LOCAL_CLANG := true LOCAL_SRC_FILES := applypatch.cpp bspatch.cpp freecache.cpp imgpatch.cpp utils.cpp LOCAL_MODULE := libapplypatch LOCAL_MODULE_TAGS := eng LOCAL_C_INCLUDES += bootable/recovery -LOCAL_STATIC_LIBRARIES += libbase libotafault libmtdutils libcrypto_static libbz libz +LOCAL_STATIC_LIBRARIES += libbase libotafault libmtdutils libmincrypttwrp libbz libz include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) -LOCAL_CLANG := true -LOCAL_SRC_FILES := bspatch.cpp imgpatch.cpp utils.cpp -LOCAL_MODULE := libimgpatch -LOCAL_C_INCLUDES += bootable/recovery -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include -LOCAL_STATIC_LIBRARIES += libcrypto_static libbz libz - -include $(BUILD_STATIC_LIBRARY) - ifeq ($(HOST_OS),linux) include $(CLEAR_VARS) diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 7985fc0c6..cc2858551 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -32,6 +32,7 @@ #include "openssl/sha.h" #include "applypatch.h" +#include "bmlutils/bmlutils.h" #include "mtdutils/mtdutils.h" #include "edify/expr.h" #include "ota_io.h" @@ -59,7 +60,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); } @@ -117,12 +119,22 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { type = MTD; } else if (pieces[0] == "EMMC") { type = EMMC; + } else if (strcmp(magic, "BML") == 0) { + type = EMMC; } else { printf("LoadPartitionContents called with bad filename (%s)\n", filename); return -1; } const char* partition = pieces[1].c_str(); + if (strcmp(magic, "BML") == 0) { + if (strcmp(partition, "boot") == 0) { + partition = BOARD_BML_BOOT; + } else if (strcmp(partition, "recovery") == 0) { + partition = BOARD_BML_RECOVERY; + } + } + size_t pairs = (pieces.size() - 2) / 2; // # of (size, sha1) pairs in filename std::vector<size_t> index(pairs); std::vector<size_t> size(pairs); @@ -319,12 +331,37 @@ int WriteToPartition(const unsigned char* data, size_t len, const char* target) type = MTD; } else if (pieces[0] == "EMMC") { 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 = pieces[1].c_str(); + 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; + } + switch (type) { case MTD: { if (!mtd_partitions_scanned) { @@ -779,7 +816,8 @@ static int GenerateTarget(FileContents* source_file, int made_copy = 0; bool target_is_partition = (strncmp(target_filename, "MTD:", 4) == 0 || - strncmp(target_filename, "EMMC:", 5) == 0); + strncmp(target_filename, "EMMC:", 5) == 0 || + strncmp(target_filename, "BML:", 4) == 0); const std::string tmp_target_filename = std::string(target_filename) + ".patch"; // assume that target_filename (eg "/system/app/Foo.apk") is located @@ -861,7 +899,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. @@ -889,6 +928,7 @@ static int GenerateTarget(FileContents* source_file, SinkFn sink = NULL; void* token = NULL; + int output_fd = -1; if (target_is_partition) { // We store the decoded output in memory. |