diff options
Diffstat (limited to '')
-rw-r--r-- | update_verifier/Android.mk | 10 | ||||
-rw-r--r-- | update_verifier/update_verifier.cpp | 70 |
2 files changed, 45 insertions, 35 deletions
diff --git a/update_verifier/Android.mk b/update_verifier/Android.mk index 2bfd01622..49d19b0e1 100644 --- a/update_verifier/Android.mk +++ b/update_verifier/Android.mk @@ -20,8 +20,16 @@ LOCAL_CLANG := true LOCAL_SRC_FILES := update_verifier.cpp LOCAL_MODULE := update_verifier -LOCAL_SHARED_LIBRARIES := libbase libcutils libhardware liblog +LOCAL_SHARED_LIBRARIES := \ + libbase \ + libcutils \ + libhardware \ + liblog \ + libutils \ + libhidlbase \ + android.hardware.boot@1.0 +LOCAL_CFLAGS := -Werror LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. include $(BUILD_EXECUTABLE) diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp index 5cff8be93..e97a3adba 100644 --- a/update_verifier/update_verifier.cpp +++ b/update_verifier/update_verifier.cpp @@ -40,13 +40,17 @@ #include <vector> #include <android-base/file.h> +#include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <cutils/properties.h> -#include <hardware/boot_control.h> -#define LOG_TAG "update_verifier" -#include <log/log.h> +#include <android/hardware/boot/1.0/IBootControl.h> + +using android::sp; +using android::hardware::boot::V1_0::IBootControl; +using android::hardware::boot::V1_0::BoolResult; +using android::hardware::boot::V1_0::CommandResult; constexpr auto CARE_MAP_FILE = "/data/ota_package/care_map.txt"; constexpr int BLOCKSIZE = 4096; @@ -57,7 +61,7 @@ static bool read_blocks(const std::string& blk_device_prefix, const std::string& std::string blk_device = blk_device_prefix + std::string(slot_suffix); android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(blk_device.c_str(), O_RDONLY))); if (fd.get() == -1) { - SLOGE("Error reading partition %s: %s\n", blk_device.c_str(), strerror(errno)); + PLOG(ERROR) << "Error reading partition " << blk_device; return false; } @@ -70,7 +74,7 @@ static bool read_blocks(const std::string& blk_device_prefix, const std::string& bool status = android::base::ParseUint(ranges[0].c_str(), &range_count); if (!status || (range_count == 0) || (range_count % 2 != 0) || (range_count != ranges.size()-1)) { - SLOGE("Error in parsing range string.\n"); + LOG(ERROR) << "Error in parsing range string."; return false; } @@ -80,26 +84,25 @@ static bool read_blocks(const std::string& blk_device_prefix, const std::string& bool parse_status = android::base::ParseUint(ranges[i].c_str(), &range_start); parse_status = parse_status && android::base::ParseUint(ranges[i+1].c_str(), &range_end); if (!parse_status || range_start >= range_end) { - SLOGE("Invalid range pair %s, %s.\n", ranges[i].c_str(), ranges[i+1].c_str()); + LOG(ERROR) << "Invalid range pair " << ranges[i] << ", " << ranges[i+1]; return false; } if (lseek64(fd.get(), static_cast<off64_t>(range_start) * BLOCKSIZE, SEEK_SET) == -1) { - SLOGE("lseek to %u failed: %s.\n", range_start, strerror(errno)); + PLOG(ERROR) << "lseek to " << range_start << " failed"; return false; } size_t size = (range_end - range_start) * BLOCKSIZE; std::vector<uint8_t> buf(size); if (!android::base::ReadFully(fd.get(), buf.data(), size)) { - SLOGE("Failed to read blocks %u to %u: %s.\n", range_start, range_end, - strerror(errno)); + PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end; return false; } blk_count += (range_end - range_start); } - SLOGI("Finished reading %zu blocks on %s.\n", blk_count, blk_device.c_str()); + LOG(INFO) << "Finished reading " << blk_count << " blocks on " << blk_device; return true; } @@ -109,7 +112,7 @@ static bool verify_image(const std::string& care_map_name) { // in /data/ota_package. To allow the device to continue booting in this situation, // we should print a warning and skip the block verification. if (care_map_fd.get() == -1) { - SLOGI("Warning: care map %s not found.\n", care_map_name.c_str()); + LOG(WARNING) << "Warning: care map " << care_map_name << " not found."; return true; } // Care map file has four lines (two lines if vendor partition is not present): @@ -118,15 +121,15 @@ static bool verify_image(const std::string& care_map_name) { // The next two lines have the same format but for vendor partition. std::string file_content; if (!android::base::ReadFdToString(care_map_fd.get(), &file_content)) { - SLOGE("Error reading care map contents to string.\n"); + LOG(ERROR) << "Error reading care map contents to string."; return false; } std::vector<std::string> lines; lines = android::base::Split(android::base::Trim(file_content), "\n"); if (lines.size() != 2 && lines.size() != 4) { - SLOGE("Invalid lines in care_map: found %zu lines, expecting 2 or 4 lines.\n", - lines.size()); + LOG(ERROR) << "Invalid lines in care_map: found " << lines.size() + << " lines, expecting 2 or 4 lines."; return false; } @@ -141,49 +144,48 @@ static bool verify_image(const std::string& care_map_name) { int main(int argc, char** argv) { for (int i = 1; i < argc; i++) { - SLOGI("Started with arg %d: %s\n", i, argv[i]); + LOG(INFO) << "Started with arg " << i << ": " << argv[i]; } - const hw_module_t* hw_module; - if (hw_get_module("bootctrl", &hw_module) != 0) { - SLOGE("Error getting bootctrl module.\n"); + sp<IBootControl> module = IBootControl::getService("bootctrl"); + if (module == nullptr) { + LOG(ERROR) << "Error getting bootctrl module."; return -1; } - boot_control_module_t* module = reinterpret_cast<boot_control_module_t*>( - const_cast<hw_module_t*>(hw_module)); - module->init(module); + uint32_t current_slot = module->getCurrentSlot(); + BoolResult is_successful = module->isSlotMarkedSuccessful(current_slot); + LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful=" + << static_cast<int32_t>(is_successful); - unsigned current_slot = module->getCurrentSlot(module); - int is_successful= module->isSlotMarkedSuccessful(module, current_slot); - SLOGI("Booting slot %u: isSlotMarkedSuccessful=%d\n", current_slot, is_successful); - if (is_successful == 0) { + if (is_successful == BoolResult::FALSE) { // The current slot has not booted successfully. char verity_mode[PROPERTY_VALUE_MAX]; if (property_get("ro.boot.veritymode", verity_mode, "") == -1) { - SLOGE("Failed to get dm-verity mode"); + LOG(ERROR) << "Failed to get dm-verity mode."; return -1; } else if (strcasecmp(verity_mode, "eio") == 0) { // We shouldn't see verity in EIO mode if the current slot hasn't booted // successfully before. Therefore, fail the verification when veritymode=eio. - SLOGE("Found dm-verity in EIO mode, skip verification."); + LOG(ERROR) << "Found dm-verity in EIO mode, skip verification."; return -1; } else if (strcmp(verity_mode, "enforcing") != 0) { - SLOGE("Unexpected dm-verity mode : %s, expecting enforcing.", verity_mode); + LOG(ERROR) << "Unexpected dm-verity mode : " << verity_mode << ", expecting enforcing."; return -1; } else if (!verify_image(CARE_MAP_FILE)) { - SLOGE("Failed to verify all blocks in care map file.\n"); + LOG(ERROR) << "Failed to verify all blocks in care map file."; return -1; } - int ret = module->markBootSuccessful(module); - if (ret != 0) { - SLOGE("Error marking booted successfully: %s\n", strerror(-ret)); + CommandResult cr; + module->markBootSuccessful([&cr](CommandResult result) { cr = result; }); + if (!cr.success) { + LOG(ERROR) << "Error marking booted successfully: " << cr.errMsg; return -1; } - SLOGI("Marked slot %u as booted successfully.\n", current_slot); + LOG(INFO) << "Marked slot " << current_slot << " as booted successfully."; } - SLOGI("Leaving update_verifier.\n"); + LOG(INFO) << "Leaving update_verifier."; return 0; } |