Loading Android.mk +13 −9 Original line number Diff line number Diff line Loading @@ -17,15 +17,23 @@ LOCAL_PATH := $(call my-dir) # libfusesideload (static library) # =============================== include $(CLEAR_VARS) LOCAL_SRC_FILES := fuse_sideload.cpp LOCAL_CLANG := true LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter -Werror LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE LOCAL_MODULE := libfusesideload LOCAL_STATIC_LIBRARIES := libcutils libc libcrypto_static include $(BUILD_STATIC_LIBRARY) # libmounts (static library) # =============================== include $(CLEAR_VARS) LOCAL_SRC_FILES := mounts.cpp LOCAL_CLANG := true LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror LOCAL_MODULE := libmounts include $(BUILD_STATIC_LIBRARY) # recovery (static executable) # =============================== include $(CLEAR_VARS) Loading Loading @@ -70,8 +78,8 @@ LOCAL_STATIC_LIBRARIES := \ libext4_utils_static \ libsparse_static \ libminzip \ libmounts \ libz \ libmtdutils \ libminadbd \ libfusesideload \ libminui \ Loading @@ -89,11 +97,8 @@ LOCAL_STATIC_LIBRARIES := \ LOCAL_HAL_STATIC_LIBRARIES := libhealthd ifeq ($(TARGET_USERIMAGES_USE_EXT4), true) LOCAL_CFLAGS += -DUSE_EXT4 LOCAL_C_INCLUDES += system/extras/ext4_utils LOCAL_STATIC_LIBRARIES += libext4_utils_static libz endif LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin Loading Loading @@ -145,7 +150,6 @@ include $(BUILD_STATIC_LIBRARY) include $(LOCAL_PATH)/minui/Android.mk \ $(LOCAL_PATH)/minzip/Android.mk \ $(LOCAL_PATH)/minadbd/Android.mk \ $(LOCAL_PATH)/mtdutils/Android.mk \ $(LOCAL_PATH)/tests/Android.mk \ $(LOCAL_PATH)/tools/Android.mk \ $(LOCAL_PATH)/edify/Android.mk \ Loading applypatch/Android.mk +0 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ LOCAL_C_INCLUDES += \ LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_STATIC_LIBRARIES += \ libotafault \ libmtdutils \ libbase \ libcrypto_static \ libbz \ Loading Loading @@ -79,7 +78,6 @@ LOCAL_STATIC_LIBRARIES += \ libedify \ libotafault \ libminzip \ libmtdutils \ libcrypto_static \ libbz LOCAL_SHARED_LIBRARIES += libz libcutils libc Loading applypatch/applypatch.cpp +101 −207 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ #include "openssl/sha.h" #include "applypatch/applypatch.h" #include "mtdutils/mtdutils.h" #include "edify/expr.h" #include "ota_io.h" #include "print_sha1.h" Loading @@ -49,17 +48,14 @@ static int GenerateTarget(FileContents* source_file, size_t target_size, const Value* bonus_data); static bool mtd_partitions_scanned = false; // Read a file into memory; store the file contents and associated // metadata in *file. // // Return 0 on success. int LoadFileContents(const char* filename, FileContents* file) { // A special 'filename' beginning with "MTD:" or "EMMC:" means to // A special 'filename' beginning with "EMMC:" means to // load the contents of a partition. if (strncmp(filename, "MTD:", 4) == 0 || strncmp(filename, "EMMC:", 5) == 0) { if (strncmp(filename, "EMMC:", 5) == 0) { return LoadPartitionContents(filename, file); } Loading Loading @@ -87,10 +83,9 @@ int LoadFileContents(const char* filename, FileContents* file) { return 0; } // Load the contents of an MTD or EMMC partition into the provided // Load the contents of an EMMC partition into the provided // FileContents. filename should be a string of the form // "MTD:<partition_name>:<size_1>:<sha1_1>:<size_2>:<sha1_2>:..." (or // "EMMC:<partition_device>:..."). The smallest size_n bytes for // "EMMC:<partition_device>:...". The smallest size_n bytes for // which that prefix of the partition contents has the corresponding // sha1 hash will be loaded. It is acceptable for a size value to be // repeated with different sha1s. Will return 0 on success. Loading @@ -102,8 +97,6 @@ int LoadFileContents(const char* filename, FileContents* file) { // "end-of-file" marker), so the caller must specify the possible // lengths and the hash of the data, and we'll do the load expecting // to find one of those hashes. enum PartitionType { MTD, EMMC }; static int LoadPartitionContents(const char* filename, FileContents* file) { std::string copy(filename); std::vector<std::string> pieces = android::base::Split(copy, ":"); Loading @@ -112,12 +105,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { return -1; } enum PartitionType type; if (pieces[0] == "MTD") { type = MTD; } else if (pieces[0] == "EMMC") { type = EMMC; } else { if (pieces[0] != "EMMC") { printf("LoadPartitionContents called with bad filename (%s)\n", filename); return -1; } Loading Loading @@ -145,37 +133,11 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { } ); MtdReadContext* ctx = NULL; FILE* dev = NULL; switch (type) { case MTD: { if (!mtd_partitions_scanned) { mtd_scan_partitions(); mtd_partitions_scanned = true; } const MtdPartition* mtd = mtd_find_partition_by_name(partition); if (mtd == NULL) { printf("mtd partition \"%s\" not found (loading %s)\n", partition, filename); return -1; } ctx = mtd_read_partition(mtd); if (ctx == NULL) { printf("failed to initialize read of mtd partition \"%s\"\n", partition); return -1; } break; } case EMMC: dev = ota_fopen(partition, "rb"); FILE* dev = ota_fopen(partition, "rb"); if (dev == NULL) { printf("failed to open emmc partition \"%s\": %s\n", partition, strerror(errno)); return -1; } } SHA_CTX sha_ctx; SHA1_Init(&sha_ctx); Loading @@ -192,16 +154,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { // we're trying the possibilities in order of increasing size). size_t next = size[index[i]] - data_size; if (next > 0) { size_t read = 0; switch (type) { case MTD: read = mtd_read_data(ctx, p, next); break; case EMMC: read = ota_fread(p, 1, next, dev); break; } size_t read = ota_fread(p, 1, next, dev); if (next != read) { printf("short read (%zu bytes of %zu) for partition \"%s\"\n", read, next, partition); Loading Loading @@ -234,16 +187,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { } } switch (type) { case MTD: mtd_read_close(ctx); break; case EMMC: ota_fclose(dev); break; } if (!found) { // Ran off the end of the list of (size,sha1) pairs without finding a match. Loading Loading @@ -302,7 +246,7 @@ int SaveFileContents(const char* filename, const FileContents* file) { } // Write a memory buffer to 'target' partition, a string of the form // "MTD:<partition>[:...]" or "EMMC:<partition_device>[:...]". The target name // "EMMC:<partition_device>[:...]". The target name // might contain multiple colons, but WriteToPartition() only uses the first // two and ignores the rest. Return 0 on success. int WriteToPartition(const unsigned char* data, size_t len, const char* target) { Loading @@ -314,57 +258,12 @@ int WriteToPartition(const unsigned char* data, size_t len, const char* target) return -1; } enum PartitionType type; if (pieces[0] == "MTD") { type = MTD; } else if (pieces[0] == "EMMC") { type = EMMC; } else { if (pieces[0] != "EMMC") { printf("WriteToPartition called with bad target (%s)\n", target); return -1; } const char* partition = pieces[1].c_str(); switch (type) { case MTD: { if (!mtd_partitions_scanned) { mtd_scan_partitions(); mtd_partitions_scanned = true; } const MtdPartition* mtd = mtd_find_partition_by_name(partition); if (mtd == NULL) { printf("mtd partition \"%s\" not found for writing\n", partition); return -1; } MtdWriteContext* ctx = mtd_write_partition(mtd); if (ctx == NULL) { printf("failed to init mtd partition \"%s\" for writing\n", partition); return -1; } size_t written = mtd_write_data(ctx, reinterpret_cast<const char*>(data), len); if (written != len) { printf("only wrote %zu of %zu bytes to MTD %s\n", written, len, partition); mtd_write_close(ctx); return -1; } if (mtd_erase_blocks(ctx, -1) < 0) { printf("error finishing mtd write of %s\n", partition); mtd_write_close(ctx); return -1; } if (mtd_write_close(ctx)) { printf("error closing mtd write of %s\n", partition); return -1; } break; } case EMMC: { size_t start = 0; bool success = false; int fd = ota_open(partition, O_RDWR | O_SYNC); Loading Loading @@ -469,9 +368,6 @@ int WriteToPartition(const unsigned char* data, size_t len, const char* target) return -1; } sync(); break; } } return 0; } Loading Loading @@ -729,7 +625,7 @@ int applypatch_flash(const char* source_filename, const char* target_filename, std::string target_str(target_filename); std::vector<std::string> pieces = android::base::Split(target_str, ":"); if (pieces.size() != 2 || (pieces[0] != "MTD" && pieces[0] != "EMMC")) { if (pieces.size() != 2 || pieces[0] != "EMMC") { printf("invalid target name \"%s\"", target_filename); return 1; } Loading Loading @@ -778,8 +674,7 @@ static int GenerateTarget(FileContents* source_file, FileContents* source_to_use; int made_copy = 0; bool target_is_partition = (strncmp(target_filename, "MTD:", 4) == 0 || strncmp(target_filename, "EMMC:", 5) == 0); bool target_is_partition = (strncmp(target_filename, "EMMC:", 5) == 0); const std::string tmp_target_filename = std::string(target_filename) + ".patch"; // assume that target_filename (eg "/system/app/Foo.apk") is located Loading Loading @@ -860,8 +755,7 @@ static int GenerateTarget(FileContents* source_file, // copy the source file to cache, then delete it from the original // location. if (strncmp(source_filename, "MTD:", 4) == 0 || strncmp(source_filename, "EMMC:", 5) == 0) { if (strncmp(source_filename, "EMMC:", 5) == 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. Loading applypatch/main.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -160,9 +160,9 @@ static int PatchMode(int argc, char** argv) { // - otherwise, or if any error is encountered, exits with non-zero // status. // // <src-file> (or <file> in check mode) may refer to an MTD partition // <src-file> (or <file> in check mode) may refer to an EMMC partition // to read the source data. See the comments for the // LoadMTDContents() function above for the format of such a filename. // LoadPartitionContents() function for the format of such a filename. int main(int argc, char** argv) { if (argc < 2) { Loading @@ -175,8 +175,8 @@ int main(int argc, char** argv) { " or %s -l\n" "\n" "Filenames may be of the form\n" " MTD:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...\n" "to specify reading from or writing to an MTD partition.\n\n", " EMMC:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...\n" "to specify reading from or writing to an EMMC partition.\n\n", argv[0], argv[0], argv[0], argv[0]); return 2; } Loading bootloader.cpp +2 −87 Original line number Diff line number Diff line Loading @@ -27,12 +27,9 @@ #include "bootloader.h" #include "common.h" #include "mtdutils/mtdutils.h" #include "roots.h" #include <android-base/unique_fd.h> static int get_bootloader_message_mtd(bootloader_message* out, const Volume* v); static int set_bootloader_message_mtd(const bootloader_message* in, const Volume* v); static int get_bootloader_message_block(bootloader_message* out, const Volume* v); static int set_bootloader_message_block(const bootloader_message* in, const Volume* v); Loading @@ -42,9 +39,7 @@ int get_bootloader_message(bootloader_message* out) { LOGE("Cannot load volume /misc!\n"); return -1; } if (strcmp(v->fs_type, "mtd") == 0) { return get_bootloader_message_mtd(out, v); } else if (strcmp(v->fs_type, "emmc") == 0) { if (strcmp(v->fs_type, "emmc") == 0) { return get_bootloader_message_block(out, v); } LOGE("unknown misc partition fs_type \"%s\"\n", v->fs_type); Loading @@ -57,93 +52,13 @@ int set_bootloader_message(const bootloader_message* in) { LOGE("Cannot load volume /misc!\n"); return -1; } if (strcmp(v->fs_type, "mtd") == 0) { return set_bootloader_message_mtd(in, v); } else if (strcmp(v->fs_type, "emmc") == 0) { if (strcmp(v->fs_type, "emmc") == 0) { return set_bootloader_message_block(in, v); } LOGE("unknown misc partition fs_type \"%s\"\n", v->fs_type); return -1; } // ------------------------------ // for misc partitions on MTD // ------------------------------ static const int MISC_PAGES = 3; // number of pages to save static const int MISC_COMMAND_PAGE = 1; // bootloader command is this page static int get_bootloader_message_mtd(bootloader_message* out, const Volume* v) { size_t write_size; mtd_scan_partitions(); const MtdPartition* part = mtd_find_partition_by_name(v->blk_device); if (part == nullptr || mtd_partition_info(part, nullptr, nullptr, &write_size)) { LOGE("failed to find \"%s\"\n", v->blk_device); return -1; } MtdReadContext* read = mtd_read_partition(part); if (read == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } const ssize_t size = write_size * MISC_PAGES; char data[size]; ssize_t r = mtd_read_data(read, data, size); if (r != size) LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); mtd_read_close(read); if (r != size) return -1; memcpy(out, &data[write_size * MISC_COMMAND_PAGE], sizeof(*out)); return 0; } static int set_bootloader_message_mtd(const bootloader_message* in, const Volume* v) { size_t write_size; mtd_scan_partitions(); const MtdPartition* part = mtd_find_partition_by_name(v->blk_device); if (part == nullptr || mtd_partition_info(part, nullptr, nullptr, &write_size)) { LOGE("failed to find \"%s\"\n", v->blk_device); return -1; } MtdReadContext* read = mtd_read_partition(part); if (read == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } ssize_t size = write_size * MISC_PAGES; char data[size]; ssize_t r = mtd_read_data(read, data, size); if (r != size) LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); mtd_read_close(read); if (r != size) return -1; memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in)); MtdWriteContext* write = mtd_write_partition(part); if (write == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } if (mtd_write_data(write, data, size) != size) { LOGE("failed to write \"%s\": %s\n", v->blk_device, strerror(errno)); mtd_write_close(write); return -1; } if (mtd_write_close(write)) { LOGE("failed to finish \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : ""); return 0; } // ------------------------------------ // for misc partitions on block devices // ------------------------------------ Loading Loading
Android.mk +13 −9 Original line number Diff line number Diff line Loading @@ -17,15 +17,23 @@ LOCAL_PATH := $(call my-dir) # libfusesideload (static library) # =============================== include $(CLEAR_VARS) LOCAL_SRC_FILES := fuse_sideload.cpp LOCAL_CLANG := true LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter -Werror LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE LOCAL_MODULE := libfusesideload LOCAL_STATIC_LIBRARIES := libcutils libc libcrypto_static include $(BUILD_STATIC_LIBRARY) # libmounts (static library) # =============================== include $(CLEAR_VARS) LOCAL_SRC_FILES := mounts.cpp LOCAL_CLANG := true LOCAL_CFLAGS := -Wall -Wno-unused-parameter -Werror LOCAL_MODULE := libmounts include $(BUILD_STATIC_LIBRARY) # recovery (static executable) # =============================== include $(CLEAR_VARS) Loading Loading @@ -70,8 +78,8 @@ LOCAL_STATIC_LIBRARIES := \ libext4_utils_static \ libsparse_static \ libminzip \ libmounts \ libz \ libmtdutils \ libminadbd \ libfusesideload \ libminui \ Loading @@ -89,11 +97,8 @@ LOCAL_STATIC_LIBRARIES := \ LOCAL_HAL_STATIC_LIBRARIES := libhealthd ifeq ($(TARGET_USERIMAGES_USE_EXT4), true) LOCAL_CFLAGS += -DUSE_EXT4 LOCAL_C_INCLUDES += system/extras/ext4_utils LOCAL_STATIC_LIBRARIES += libext4_utils_static libz endif LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/sbin Loading Loading @@ -145,7 +150,6 @@ include $(BUILD_STATIC_LIBRARY) include $(LOCAL_PATH)/minui/Android.mk \ $(LOCAL_PATH)/minzip/Android.mk \ $(LOCAL_PATH)/minadbd/Android.mk \ $(LOCAL_PATH)/mtdutils/Android.mk \ $(LOCAL_PATH)/tests/Android.mk \ $(LOCAL_PATH)/tools/Android.mk \ $(LOCAL_PATH)/edify/Android.mk \ Loading
applypatch/Android.mk +0 −2 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ LOCAL_C_INCLUDES += \ LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include LOCAL_STATIC_LIBRARIES += \ libotafault \ libmtdutils \ libbase \ libcrypto_static \ libbz \ Loading Loading @@ -79,7 +78,6 @@ LOCAL_STATIC_LIBRARIES += \ libedify \ libotafault \ libminzip \ libmtdutils \ libcrypto_static \ libbz LOCAL_SHARED_LIBRARIES += libz libcutils libc Loading
applypatch/applypatch.cpp +101 −207 Original line number Diff line number Diff line Loading @@ -32,7 +32,6 @@ #include "openssl/sha.h" #include "applypatch/applypatch.h" #include "mtdutils/mtdutils.h" #include "edify/expr.h" #include "ota_io.h" #include "print_sha1.h" Loading @@ -49,17 +48,14 @@ static int GenerateTarget(FileContents* source_file, size_t target_size, const Value* bonus_data); static bool mtd_partitions_scanned = false; // Read a file into memory; store the file contents and associated // metadata in *file. // // Return 0 on success. int LoadFileContents(const char* filename, FileContents* file) { // A special 'filename' beginning with "MTD:" or "EMMC:" means to // A special 'filename' beginning with "EMMC:" means to // load the contents of a partition. if (strncmp(filename, "MTD:", 4) == 0 || strncmp(filename, "EMMC:", 5) == 0) { if (strncmp(filename, "EMMC:", 5) == 0) { return LoadPartitionContents(filename, file); } Loading Loading @@ -87,10 +83,9 @@ int LoadFileContents(const char* filename, FileContents* file) { return 0; } // Load the contents of an MTD or EMMC partition into the provided // Load the contents of an EMMC partition into the provided // FileContents. filename should be a string of the form // "MTD:<partition_name>:<size_1>:<sha1_1>:<size_2>:<sha1_2>:..." (or // "EMMC:<partition_device>:..."). The smallest size_n bytes for // "EMMC:<partition_device>:...". The smallest size_n bytes for // which that prefix of the partition contents has the corresponding // sha1 hash will be loaded. It is acceptable for a size value to be // repeated with different sha1s. Will return 0 on success. Loading @@ -102,8 +97,6 @@ int LoadFileContents(const char* filename, FileContents* file) { // "end-of-file" marker), so the caller must specify the possible // lengths and the hash of the data, and we'll do the load expecting // to find one of those hashes. enum PartitionType { MTD, EMMC }; static int LoadPartitionContents(const char* filename, FileContents* file) { std::string copy(filename); std::vector<std::string> pieces = android::base::Split(copy, ":"); Loading @@ -112,12 +105,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { return -1; } enum PartitionType type; if (pieces[0] == "MTD") { type = MTD; } else if (pieces[0] == "EMMC") { type = EMMC; } else { if (pieces[0] != "EMMC") { printf("LoadPartitionContents called with bad filename (%s)\n", filename); return -1; } Loading Loading @@ -145,37 +133,11 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { } ); MtdReadContext* ctx = NULL; FILE* dev = NULL; switch (type) { case MTD: { if (!mtd_partitions_scanned) { mtd_scan_partitions(); mtd_partitions_scanned = true; } const MtdPartition* mtd = mtd_find_partition_by_name(partition); if (mtd == NULL) { printf("mtd partition \"%s\" not found (loading %s)\n", partition, filename); return -1; } ctx = mtd_read_partition(mtd); if (ctx == NULL) { printf("failed to initialize read of mtd partition \"%s\"\n", partition); return -1; } break; } case EMMC: dev = ota_fopen(partition, "rb"); FILE* dev = ota_fopen(partition, "rb"); if (dev == NULL) { printf("failed to open emmc partition \"%s\": %s\n", partition, strerror(errno)); return -1; } } SHA_CTX sha_ctx; SHA1_Init(&sha_ctx); Loading @@ -192,16 +154,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { // we're trying the possibilities in order of increasing size). size_t next = size[index[i]] - data_size; if (next > 0) { size_t read = 0; switch (type) { case MTD: read = mtd_read_data(ctx, p, next); break; case EMMC: read = ota_fread(p, 1, next, dev); break; } size_t read = ota_fread(p, 1, next, dev); if (next != read) { printf("short read (%zu bytes of %zu) for partition \"%s\"\n", read, next, partition); Loading Loading @@ -234,16 +187,7 @@ static int LoadPartitionContents(const char* filename, FileContents* file) { } } switch (type) { case MTD: mtd_read_close(ctx); break; case EMMC: ota_fclose(dev); break; } if (!found) { // Ran off the end of the list of (size,sha1) pairs without finding a match. Loading Loading @@ -302,7 +246,7 @@ int SaveFileContents(const char* filename, const FileContents* file) { } // Write a memory buffer to 'target' partition, a string of the form // "MTD:<partition>[:...]" or "EMMC:<partition_device>[:...]". The target name // "EMMC:<partition_device>[:...]". The target name // might contain multiple colons, but WriteToPartition() only uses the first // two and ignores the rest. Return 0 on success. int WriteToPartition(const unsigned char* data, size_t len, const char* target) { Loading @@ -314,57 +258,12 @@ int WriteToPartition(const unsigned char* data, size_t len, const char* target) return -1; } enum PartitionType type; if (pieces[0] == "MTD") { type = MTD; } else if (pieces[0] == "EMMC") { type = EMMC; } else { if (pieces[0] != "EMMC") { printf("WriteToPartition called with bad target (%s)\n", target); return -1; } const char* partition = pieces[1].c_str(); switch (type) { case MTD: { if (!mtd_partitions_scanned) { mtd_scan_partitions(); mtd_partitions_scanned = true; } const MtdPartition* mtd = mtd_find_partition_by_name(partition); if (mtd == NULL) { printf("mtd partition \"%s\" not found for writing\n", partition); return -1; } MtdWriteContext* ctx = mtd_write_partition(mtd); if (ctx == NULL) { printf("failed to init mtd partition \"%s\" for writing\n", partition); return -1; } size_t written = mtd_write_data(ctx, reinterpret_cast<const char*>(data), len); if (written != len) { printf("only wrote %zu of %zu bytes to MTD %s\n", written, len, partition); mtd_write_close(ctx); return -1; } if (mtd_erase_blocks(ctx, -1) < 0) { printf("error finishing mtd write of %s\n", partition); mtd_write_close(ctx); return -1; } if (mtd_write_close(ctx)) { printf("error closing mtd write of %s\n", partition); return -1; } break; } case EMMC: { size_t start = 0; bool success = false; int fd = ota_open(partition, O_RDWR | O_SYNC); Loading Loading @@ -469,9 +368,6 @@ int WriteToPartition(const unsigned char* data, size_t len, const char* target) return -1; } sync(); break; } } return 0; } Loading Loading @@ -729,7 +625,7 @@ int applypatch_flash(const char* source_filename, const char* target_filename, std::string target_str(target_filename); std::vector<std::string> pieces = android::base::Split(target_str, ":"); if (pieces.size() != 2 || (pieces[0] != "MTD" && pieces[0] != "EMMC")) { if (pieces.size() != 2 || pieces[0] != "EMMC") { printf("invalid target name \"%s\"", target_filename); return 1; } Loading Loading @@ -778,8 +674,7 @@ static int GenerateTarget(FileContents* source_file, FileContents* source_to_use; int made_copy = 0; bool target_is_partition = (strncmp(target_filename, "MTD:", 4) == 0 || strncmp(target_filename, "EMMC:", 5) == 0); bool target_is_partition = (strncmp(target_filename, "EMMC:", 5) == 0); const std::string tmp_target_filename = std::string(target_filename) + ".patch"; // assume that target_filename (eg "/system/app/Foo.apk") is located Loading Loading @@ -860,8 +755,7 @@ static int GenerateTarget(FileContents* source_file, // copy the source file to cache, then delete it from the original // location. if (strncmp(source_filename, "MTD:", 4) == 0 || strncmp(source_filename, "EMMC:", 5) == 0) { if (strncmp(source_filename, "EMMC:", 5) == 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. Loading
applypatch/main.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -160,9 +160,9 @@ static int PatchMode(int argc, char** argv) { // - otherwise, or if any error is encountered, exits with non-zero // status. // // <src-file> (or <file> in check mode) may refer to an MTD partition // <src-file> (or <file> in check mode) may refer to an EMMC partition // to read the source data. See the comments for the // LoadMTDContents() function above for the format of such a filename. // LoadPartitionContents() function for the format of such a filename. int main(int argc, char** argv) { if (argc < 2) { Loading @@ -175,8 +175,8 @@ int main(int argc, char** argv) { " or %s -l\n" "\n" "Filenames may be of the form\n" " MTD:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...\n" "to specify reading from or writing to an MTD partition.\n\n", " EMMC:<partition>:<len_1>:<sha1_1>:<len_2>:<sha1_2>:...\n" "to specify reading from or writing to an EMMC partition.\n\n", argv[0], argv[0], argv[0], argv[0]); return 2; } Loading
bootloader.cpp +2 −87 Original line number Diff line number Diff line Loading @@ -27,12 +27,9 @@ #include "bootloader.h" #include "common.h" #include "mtdutils/mtdutils.h" #include "roots.h" #include <android-base/unique_fd.h> static int get_bootloader_message_mtd(bootloader_message* out, const Volume* v); static int set_bootloader_message_mtd(const bootloader_message* in, const Volume* v); static int get_bootloader_message_block(bootloader_message* out, const Volume* v); static int set_bootloader_message_block(const bootloader_message* in, const Volume* v); Loading @@ -42,9 +39,7 @@ int get_bootloader_message(bootloader_message* out) { LOGE("Cannot load volume /misc!\n"); return -1; } if (strcmp(v->fs_type, "mtd") == 0) { return get_bootloader_message_mtd(out, v); } else if (strcmp(v->fs_type, "emmc") == 0) { if (strcmp(v->fs_type, "emmc") == 0) { return get_bootloader_message_block(out, v); } LOGE("unknown misc partition fs_type \"%s\"\n", v->fs_type); Loading @@ -57,93 +52,13 @@ int set_bootloader_message(const bootloader_message* in) { LOGE("Cannot load volume /misc!\n"); return -1; } if (strcmp(v->fs_type, "mtd") == 0) { return set_bootloader_message_mtd(in, v); } else if (strcmp(v->fs_type, "emmc") == 0) { if (strcmp(v->fs_type, "emmc") == 0) { return set_bootloader_message_block(in, v); } LOGE("unknown misc partition fs_type \"%s\"\n", v->fs_type); return -1; } // ------------------------------ // for misc partitions on MTD // ------------------------------ static const int MISC_PAGES = 3; // number of pages to save static const int MISC_COMMAND_PAGE = 1; // bootloader command is this page static int get_bootloader_message_mtd(bootloader_message* out, const Volume* v) { size_t write_size; mtd_scan_partitions(); const MtdPartition* part = mtd_find_partition_by_name(v->blk_device); if (part == nullptr || mtd_partition_info(part, nullptr, nullptr, &write_size)) { LOGE("failed to find \"%s\"\n", v->blk_device); return -1; } MtdReadContext* read = mtd_read_partition(part); if (read == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } const ssize_t size = write_size * MISC_PAGES; char data[size]; ssize_t r = mtd_read_data(read, data, size); if (r != size) LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); mtd_read_close(read); if (r != size) return -1; memcpy(out, &data[write_size * MISC_COMMAND_PAGE], sizeof(*out)); return 0; } static int set_bootloader_message_mtd(const bootloader_message* in, const Volume* v) { size_t write_size; mtd_scan_partitions(); const MtdPartition* part = mtd_find_partition_by_name(v->blk_device); if (part == nullptr || mtd_partition_info(part, nullptr, nullptr, &write_size)) { LOGE("failed to find \"%s\"\n", v->blk_device); return -1; } MtdReadContext* read = mtd_read_partition(part); if (read == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } ssize_t size = write_size * MISC_PAGES; char data[size]; ssize_t r = mtd_read_data(read, data, size); if (r != size) LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); mtd_read_close(read); if (r != size) return -1; memcpy(&data[write_size * MISC_COMMAND_PAGE], in, sizeof(*in)); MtdWriteContext* write = mtd_write_partition(part); if (write == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } if (mtd_write_data(write, data, size) != size) { LOGE("failed to write \"%s\": %s\n", v->blk_device, strerror(errno)); mtd_write_close(write); return -1; } if (mtd_write_close(write)) { LOGE("failed to finish \"%s\": %s\n", v->blk_device, strerror(errno)); return -1; } LOGI("Set boot command \"%s\"\n", in->command[0] != 255 ? in->command : ""); return 0; } // ------------------------------------ // for misc partitions on block devices // ------------------------------------ Loading