From a58a6dbe3d06aace0d1419838e162aa5267a4fc0 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Wed, 6 Apr 2016 15:52:18 -0700 Subject: uncrypt: split libbootloader_message_writer for reuse. init and vold also need to write bootloader message, so split this function from uncrypt into a separate library. Bug: 27176738 Change-Id: If9b0887b4f6ffab6162d9cb47a6ceb7eedd60b4d --- uncrypt/uncrypt.cpp | 50 +++++++------------------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) (limited to 'uncrypt/uncrypt.cpp') diff --git a/uncrypt/uncrypt.cpp b/uncrypt/uncrypt.cpp index 2ef093579..d7105a01f 100644 --- a/uncrypt/uncrypt.cpp +++ b/uncrypt/uncrypt.cpp @@ -109,6 +109,7 @@ #include #include #include +#include #include #include #include @@ -117,7 +118,6 @@ #define LOG_TAG "uncrypt" #include -#include "bootloader.h" #include "unique_fd.h" #define WINDOW_SIZE 5 @@ -414,40 +414,6 @@ static int produce_block_map(const char* path, const char* map_file, const char* return 0; } -static std::string get_misc_blk_device() { - if (fstab == nullptr) { - return ""; - } - struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, "/misc"); - if (rec != nullptr) { - return rec->blk_device; - } - return ""; -} - -static int write_bootloader_message(const bootloader_message* in) { - std::string misc_blk_device = get_misc_blk_device(); - if (misc_blk_device.empty()) { - ALOGE("failed to find /misc partition."); - return -1; - } - unique_fd fd(open(misc_blk_device.c_str(), O_WRONLY | O_SYNC)); - if (!fd) { - ALOGE("failed to open %s: %s", misc_blk_device.c_str(), strerror(errno)); - return -1; - } - if (!android::base::WriteFully(fd.get(), in, sizeof(*in))) { - ALOGE("failed to write %s: %s", misc_blk_device.c_str(), strerror(errno)); - return -1; - } - // TODO: O_SYNC and fsync() duplicates each other? - if (fsync(fd.get()) == -1) { - ALOGE("failed to fsync %s: %s", misc_blk_device.c_str(), strerror(errno)); - return -1; - } - return 0; -} - static int uncrypt(const char* input_path, const char* map_file, const int socket) { ALOGI("update package is \"%s\"", input_path); @@ -510,8 +476,9 @@ static bool uncrypt_wrapper(const char* input_path, const char* map_file, const } static bool clear_bcb(const int socket) { - bootloader_message boot = {}; - if (write_bootloader_message(&boot) != 0) { + std::string err; + if (!clear_bootloader_message(&err)) { + ALOGE("failed to clear bootloader message: %s", err.c_str()); write_status_to_socket(-1, socket); return false; } @@ -538,12 +505,9 @@ static bool setup_bcb(const int socket) { ALOGI(" received command: [%s] (%zu)", content.c_str(), content.size()); // c8. setup the bcb command - bootloader_message boot = {}; - strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); - strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); - strlcat(boot.recovery, content.c_str(), sizeof(boot.recovery)); - if (write_bootloader_message(&boot) != 0) { - ALOGE("failed to set bootloader message"); + std::string err; + if (!write_bootloader_message({content}, &err)) { + ALOGE("failed to set bootloader message: %s", err.c_str()); write_status_to_socket(-1, socket); return false; } -- cgit v1.2.3