From 2f272c0551f984e83bc5abaf240e0dddb38a3326 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Fri, 24 Jun 2016 18:22:02 -0700 Subject: Create bootloader_message static library. bootloader_messages merges bootloader_message_writer and bootloader.cpp, so we can use the same library to manage bootloader_message in normal boot and recovery mode. Bug: 29582118 Change-Id: I9efdf776ef8f02b53911ff43a518e035e0c29618 --- recovery.cpp | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'recovery.cpp') diff --git a/recovery.cpp b/recovery.cpp index 98148af0a..c4b36557b 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include /* Android Log packet format */ @@ -52,7 +53,6 @@ #include #include "adb_install.h" -#include "bootloader.h" #include "common.h" #include "device.h" #include "error_code.h" @@ -303,9 +303,13 @@ static void redirect_stdio(const char* filename) { // - the contents of COMMAND_FILE (one per line) static void get_args(int *argc, char ***argv) { - struct bootloader_message boot; - memset(&boot, 0, sizeof(boot)); - get_bootloader_message(&boot); // this may fail, leaving a zeroed structure + bootloader_message boot = {}; + std::string err; + if (!read_bootloader_message(&boot, &err)) { + LOGE("%s\n", err.c_str()); + // If fails, leave a zeroed bootloader_message. + memset(&boot, 0, sizeof(boot)); + } stage = strndup(boot.stage, sizeof(boot.stage)); if (boot.command[0] != 0 && boot.command[0] != 255) { @@ -367,16 +371,20 @@ get_args(int *argc, char ***argv) { strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery)); strlcat(boot.recovery, "\n", sizeof(boot.recovery)); } - set_bootloader_message(&boot); + if (!write_bootloader_message(boot, &err)) { + LOGE("%s\n", err.c_str()); + } } static void set_sdcard_update_bootloader_message() { - struct bootloader_message boot; - memset(&boot, 0, sizeof(boot)); + bootloader_message boot = {}; strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); - set_bootloader_message(&boot); + std::string err; + if (!write_bootloader_message(boot, &err)) { + LOGE("%s\n", err.c_str()); + } } // Read from kernel log into buffer and write out to file. @@ -537,9 +545,11 @@ finish_recovery(const char *send_intent) { copy_logs(); // Reset to normal system boot so recovery won't cycle indefinitely. - struct bootloader_message boot; - memset(&boot, 0, sizeof(boot)); - set_bootloader_message(&boot); + bootloader_message boot = {}; + std::string err; + if (!write_bootloader_message(boot, &err)) { + LOGE("%s\n", err.c_str()); + } // Remove the command file, so recovery won't repeat indefinitely. if (has_cache) { @@ -916,8 +926,9 @@ static bool check_wipe_package(size_t wipe_package_size) { return false; } std::string wipe_package; - if (!read_wipe_package(wipe_package_size, &wipe_package)) { - LOGE("Failed to read wipe package.\n"); + std::string err_str; + if (!read_wipe_package(&wipe_package, wipe_package_size, &err_str)) { + LOGE("Failed to read wipe package: %s\n", err_str.c_str()); return false; } if (!verify_package(reinterpret_cast(wipe_package.data()), @@ -1369,7 +1380,7 @@ static bool is_battery_ok() { } static void set_retry_bootloader_message(int retry_count, int argc, char** argv) { - struct bootloader_message boot {}; + bootloader_message boot = {}; strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); @@ -1388,7 +1399,10 @@ static void set_retry_bootloader_message(int retry_count, int argc, char** argv) snprintf(buffer, sizeof(buffer), "--retry_count=%d\n", retry_count+1); strlcat(boot.recovery, buffer, sizeof(boot.recovery)); } - set_bootloader_message(&boot); + std::string err; + if (!write_bootloader_message(boot, &err)) { + LOGE("%s\n", err.c_str()); + } } static ssize_t logbasename( -- cgit v1.2.3