Loading Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ LOCAL_SRC_FILES := \ asn1_decoder.cpp \ verifier.cpp \ ui.cpp LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libbase include $(BUILD_STATIC_LIBRARY) include $(LOCAL_PATH)/minui/Android.mk \ Loading applypatch/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ LOCAL_STATIC_LIBRARIES += \ libminzip \ libcrypto \ libbz LOCAL_SHARED_LIBRARIES += libz libcutils libc LOCAL_SHARED_LIBRARIES += libbase libz libcutils libc include $(BUILD_EXECUTABLE) # imgdiff (host static executable) Loading bootloader.cpp +14 −13 Original line number Diff line number Diff line Loading @@ -25,10 +25,11 @@ #include <fs_mgr.h> #include <android-base/logging.h> #include <android-base/unique_fd.h> #include "bootloader.h" #include "common.h" #include "roots.h" #include <android-base/unique_fd.h> 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 @@ -36,26 +37,26 @@ static int set_bootloader_message_block(const bootloader_message* in, const Volu int get_bootloader_message(bootloader_message* out) { Volume* v = volume_for_path("/misc"); if (v == nullptr) { LOGE("Cannot load volume /misc!\n"); LOG(ERROR) << "Cannot load volume /misc!"; return -1; } 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); LOG(ERROR) << "unknown misc partition fs_type \"" << v->fs_type << "\""; return -1; } int set_bootloader_message(const bootloader_message* in) { Volume* v = volume_for_path("/misc"); if (v == nullptr) { LOGE("Cannot load volume /misc!\n"); LOG(ERROR) << "Cannot load volume /misc!"; return -1; } 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); LOG(ERROR) << "unknown misc partition fs_type \"" << v->fs_type << "\""; return -1; } Loading Loading @@ -86,17 +87,17 @@ static int get_bootloader_message_block(bootloader_message* out, wait_for_device(v->blk_device); FILE* f = fopen(v->blk_device, "rb"); if (f == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to open \"" << v->blk_device << "\""; return -1; } bootloader_message temp; int count = fread(&temp, sizeof(temp), 1, f); if (count != 1) { LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to read \"" << v->blk_device << "\""; return -1; } if (fclose(f) != 0) { LOGE("failed to close \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to close \"" << v->blk_device << "\""; return -1; } memcpy(out, &temp, sizeof(temp)); Loading @@ -108,7 +109,7 @@ static int set_bootloader_message_block(const bootloader_message* in, wait_for_device(v->blk_device); android::base::unique_fd fd(open(v->blk_device, O_WRONLY | O_SYNC)); if (fd == -1) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to open \"" << v->blk_device << "\""; return -1; } Loading @@ -118,15 +119,15 @@ static int set_bootloader_message_block(const bootloader_message* in, while (written < total) { ssize_t wrote = TEMP_FAILURE_RETRY(write(fd, start + written, total - written)); if (wrote == -1) { LOGE("failed to write %" PRId64 " bytes: %s\n", static_cast<off64_t>(written), strerror(errno)); PLOG(ERROR) << "failed to write " << total << " bytes, " << written << " bytes written"; return -1; } written += wrote; } if (fsync(fd) == -1) { LOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to fsync \"" << v->blk_device << "\""; return -1; } return 0; Loading common.h +0 −12 Original line number Diff line number Diff line Loading @@ -21,18 +21,6 @@ #include <stdio.h> #include <stdarg.h> #define LOGE(...) ui_print("E:" __VA_ARGS__) #define LOGW(...) fprintf(stdout, "W:" __VA_ARGS__) #define LOGI(...) fprintf(stdout, "I:" __VA_ARGS__) #if 0 #define LOGV(...) fprintf(stdout, "V:" __VA_ARGS__) #define LOGD(...) fprintf(stdout, "D:" __VA_ARGS__) #else #define LOGV(...) do {} while (0) #define LOGD(...) do {} while (0) #endif #define STRINGIFY(x) #x #define EXPAND(x) STRINGIFY(x) Loading install.cpp +17 −15 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <android-base/parseint.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/logging.h> #include "common.h" #include "error_code.h" Loading Loading @@ -64,7 +65,7 @@ static int parse_build_number(const std::string& str) { } } LOGE("Failed to parse build number in %s.\n", str.c_str()); LOG(ERROR) << "Failed to parse build number in " << str; return -1; } Loading @@ -72,13 +73,13 @@ static int parse_build_number(const std::string& str) { static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) { const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH); if (meta_entry == nullptr) { LOGE("Failed to find %s in update package.\n", METADATA_PATH); LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package"; return; } std::string meta_data(meta_entry->uncompLen, '\0'); if (!mzReadZipEntry(zip, meta_entry, &meta_data[0], meta_entry->uncompLen)) { LOGE("Failed to read metadata in update package.\n"); LOG(ERROR) << "Failed to read metadata in update package"; return; } Loading Loading @@ -122,8 +123,8 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, unlink(binary); int fd = creat(binary, 0755); if (fd < 0) { PLOG(ERROR) << "Can't make " << binary; mzCloseZipArchive(zip); LOGE("Can't make %s\n", binary); return INSTALL_ERROR; } bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd); Loading @@ -131,7 +132,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, mzCloseZipArchive(zip); if (!ok) { LOGE("Can't copy %s\n", ASSUMED_UPDATE_BINARY_NAME); LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME; return INSTALL_ERROR; } Loading Loading @@ -252,7 +253,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, // last_install later. log_buffer.push_back(std::string(strtok(NULL, "\n"))); } else { LOGE("unknown command [%s]\n", command); LOG(ERROR) << "unknown command [" << command << "]"; } } fclose(from_child); Loading @@ -263,7 +264,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, return INSTALL_RETRY; } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { LOGE("Error in %s\n(Status %d)\n", path, WEXITSTATUS(status)); LOG(ERROR) << "Error in " << path << " (Status " << WEXITSTATUS(status) << ")"; return INSTALL_ERROR; } Loading @@ -279,7 +280,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, // Give verification half the progress bar... ui->SetProgressType(RecoveryUI::DETERMINATE); ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); LOGI("Update location: %s\n", path); LOG(INFO) << "Update location: " << path; // Map the update package into memory. ui->Print("Opening update package...\n"); Loading @@ -294,27 +295,28 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, MemMapping map; if (sysMapFile(path, &map) != 0) { LOGE("failed to map file\n"); LOG(ERROR) << "failed to map file"; return INSTALL_CORRUPT; } // Load keys. std::vector<Certificate> loadedKeys; if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { LOGE("Failed to load keys\n"); LOG(ERROR) << "Failed to load keys"; sysReleaseMap(&map); return INSTALL_CORRUPT; } LOGI("%zu key(s) loaded from %s\n", loadedKeys.size(), PUBLIC_KEYS_FILE); LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE; // Verify package. ui->Print("Verifying update package...\n"); auto t0 = std::chrono::system_clock::now(); int err = verify_file(map.addr, map.length, loadedKeys); std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0; ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); if (err != VERIFY_SUCCESS) { LOGE("signature verification failed\n"); LOG(ERROR) << "signature verification failed"; log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure)); sysReleaseMap(&map); Loading @@ -325,7 +327,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, ZipArchive zip; err = mzOpenZipArchive(map.addr, map.length, &zip); if (err != 0) { LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); LOG(ERROR) << "Can't open " << path; log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure)); sysReleaseMap(&map); Loading Loading @@ -359,12 +361,12 @@ install_package(const char* path, bool* wipe_cache, const char* install_file, fputs(path, install_log); fputc('\n', install_log); } else { LOGE("failed to open last_install: %s\n", strerror(errno)); PLOG(ERROR) << "failed to open last_install"; } int result; std::vector<std::string> log_buffer; if (setup_install_mounts() != 0) { LOGE("failed to set up expected mounts for install; aborting\n"); LOG(ERROR) << "failed to set up expected mounts for install; aborting"; result = INSTALL_ERROR; } else { result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); Loading Loading
Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -145,7 +145,7 @@ LOCAL_SRC_FILES := \ asn1_decoder.cpp \ verifier.cpp \ ui.cpp LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto LOCAL_STATIC_LIBRARIES := libcrypto_utils libcrypto libbase include $(BUILD_STATIC_LIBRARY) include $(LOCAL_PATH)/minui/Android.mk \ Loading
applypatch/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,7 @@ LOCAL_STATIC_LIBRARIES += \ libminzip \ libcrypto \ libbz LOCAL_SHARED_LIBRARIES += libz libcutils libc LOCAL_SHARED_LIBRARIES += libbase libz libcutils libc include $(BUILD_EXECUTABLE) # imgdiff (host static executable) Loading
bootloader.cpp +14 −13 Original line number Diff line number Diff line Loading @@ -25,10 +25,11 @@ #include <fs_mgr.h> #include <android-base/logging.h> #include <android-base/unique_fd.h> #include "bootloader.h" #include "common.h" #include "roots.h" #include <android-base/unique_fd.h> 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 @@ -36,26 +37,26 @@ static int set_bootloader_message_block(const bootloader_message* in, const Volu int get_bootloader_message(bootloader_message* out) { Volume* v = volume_for_path("/misc"); if (v == nullptr) { LOGE("Cannot load volume /misc!\n"); LOG(ERROR) << "Cannot load volume /misc!"; return -1; } 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); LOG(ERROR) << "unknown misc partition fs_type \"" << v->fs_type << "\""; return -1; } int set_bootloader_message(const bootloader_message* in) { Volume* v = volume_for_path("/misc"); if (v == nullptr) { LOGE("Cannot load volume /misc!\n"); LOG(ERROR) << "Cannot load volume /misc!"; return -1; } 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); LOG(ERROR) << "unknown misc partition fs_type \"" << v->fs_type << "\""; return -1; } Loading Loading @@ -86,17 +87,17 @@ static int get_bootloader_message_block(bootloader_message* out, wait_for_device(v->blk_device); FILE* f = fopen(v->blk_device, "rb"); if (f == nullptr) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to open \"" << v->blk_device << "\""; return -1; } bootloader_message temp; int count = fread(&temp, sizeof(temp), 1, f); if (count != 1) { LOGE("failed to read \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to read \"" << v->blk_device << "\""; return -1; } if (fclose(f) != 0) { LOGE("failed to close \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to close \"" << v->blk_device << "\""; return -1; } memcpy(out, &temp, sizeof(temp)); Loading @@ -108,7 +109,7 @@ static int set_bootloader_message_block(const bootloader_message* in, wait_for_device(v->blk_device); android::base::unique_fd fd(open(v->blk_device, O_WRONLY | O_SYNC)); if (fd == -1) { LOGE("failed to open \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to open \"" << v->blk_device << "\""; return -1; } Loading @@ -118,15 +119,15 @@ static int set_bootloader_message_block(const bootloader_message* in, while (written < total) { ssize_t wrote = TEMP_FAILURE_RETRY(write(fd, start + written, total - written)); if (wrote == -1) { LOGE("failed to write %" PRId64 " bytes: %s\n", static_cast<off64_t>(written), strerror(errno)); PLOG(ERROR) << "failed to write " << total << " bytes, " << written << " bytes written"; return -1; } written += wrote; } if (fsync(fd) == -1) { LOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno)); PLOG(ERROR) << "failed to fsync \"" << v->blk_device << "\""; return -1; } return 0; Loading
common.h +0 −12 Original line number Diff line number Diff line Loading @@ -21,18 +21,6 @@ #include <stdio.h> #include <stdarg.h> #define LOGE(...) ui_print("E:" __VA_ARGS__) #define LOGW(...) fprintf(stdout, "W:" __VA_ARGS__) #define LOGI(...) fprintf(stdout, "I:" __VA_ARGS__) #if 0 #define LOGV(...) fprintf(stdout, "V:" __VA_ARGS__) #define LOGD(...) fprintf(stdout, "D:" __VA_ARGS__) #else #define LOGV(...) do {} while (0) #define LOGD(...) do {} while (0) #endif #define STRINGIFY(x) #x #define EXPAND(x) STRINGIFY(x) Loading
install.cpp +17 −15 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ #include <android-base/parseint.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/logging.h> #include "common.h" #include "error_code.h" Loading Loading @@ -64,7 +65,7 @@ static int parse_build_number(const std::string& str) { } } LOGE("Failed to parse build number in %s.\n", str.c_str()); LOG(ERROR) << "Failed to parse build number in " << str; return -1; } Loading @@ -72,13 +73,13 @@ static int parse_build_number(const std::string& str) { static void read_source_target_build(ZipArchive* zip, std::vector<std::string>& log_buffer) { const ZipEntry* meta_entry = mzFindZipEntry(zip, METADATA_PATH); if (meta_entry == nullptr) { LOGE("Failed to find %s in update package.\n", METADATA_PATH); LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package"; return; } std::string meta_data(meta_entry->uncompLen, '\0'); if (!mzReadZipEntry(zip, meta_entry, &meta_data[0], meta_entry->uncompLen)) { LOGE("Failed to read metadata in update package.\n"); LOG(ERROR) << "Failed to read metadata in update package"; return; } Loading Loading @@ -122,8 +123,8 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, unlink(binary); int fd = creat(binary, 0755); if (fd < 0) { PLOG(ERROR) << "Can't make " << binary; mzCloseZipArchive(zip); LOGE("Can't make %s\n", binary); return INSTALL_ERROR; } bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd); Loading @@ -131,7 +132,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, mzCloseZipArchive(zip); if (!ok) { LOGE("Can't copy %s\n", ASSUMED_UPDATE_BINARY_NAME); LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME; return INSTALL_ERROR; } Loading Loading @@ -252,7 +253,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, // last_install later. log_buffer.push_back(std::string(strtok(NULL, "\n"))); } else { LOGE("unknown command [%s]\n", command); LOG(ERROR) << "unknown command [" << command << "]"; } } fclose(from_child); Loading @@ -263,7 +264,7 @@ try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache, return INSTALL_RETRY; } if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { LOGE("Error in %s\n(Status %d)\n", path, WEXITSTATUS(status)); LOG(ERROR) << "Error in " << path << " (Status " << WEXITSTATUS(status) << ")"; return INSTALL_ERROR; } Loading @@ -279,7 +280,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, // Give verification half the progress bar... ui->SetProgressType(RecoveryUI::DETERMINATE); ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); LOGI("Update location: %s\n", path); LOG(INFO) << "Update location: " << path; // Map the update package into memory. ui->Print("Opening update package...\n"); Loading @@ -294,27 +295,28 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, MemMapping map; if (sysMapFile(path, &map) != 0) { LOGE("failed to map file\n"); LOG(ERROR) << "failed to map file"; return INSTALL_CORRUPT; } // Load keys. std::vector<Certificate> loadedKeys; if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { LOGE("Failed to load keys\n"); LOG(ERROR) << "Failed to load keys"; sysReleaseMap(&map); return INSTALL_CORRUPT; } LOGI("%zu key(s) loaded from %s\n", loadedKeys.size(), PUBLIC_KEYS_FILE); LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE; // Verify package. ui->Print("Verifying update package...\n"); auto t0 = std::chrono::system_clock::now(); int err = verify_file(map.addr, map.length, loadedKeys); std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0; ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); if (err != VERIFY_SUCCESS) { LOGE("signature verification failed\n"); LOG(ERROR) << "signature verification failed"; log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure)); sysReleaseMap(&map); Loading @@ -325,7 +327,7 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount, ZipArchive zip; err = mzOpenZipArchive(map.addr, map.length, &zip); if (err != 0) { LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); LOG(ERROR) << "Can't open " << path; log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure)); sysReleaseMap(&map); Loading Loading @@ -359,12 +361,12 @@ install_package(const char* path, bool* wipe_cache, const char* install_file, fputs(path, install_log); fputc('\n', install_log); } else { LOGE("failed to open last_install: %s\n", strerror(errno)); PLOG(ERROR) << "failed to open last_install"; } int result; std::vector<std::string> log_buffer; if (setup_install_mounts() != 0) { LOGE("failed to set up expected mounts for install; aborting\n"); LOG(ERROR) << "failed to set up expected mounts for install; aborting"; result = INSTALL_ERROR; } else { result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); Loading