From f019ab400a2745b69f9bbd32b0ac438e50addf2f Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Fri, 18 Nov 2016 20:16:53 +0000 Subject: Revert "Convert update_verifier to boot HIDL HAL" This reverts commit f50593c447faf8415615b5dea2666d7f0f24a0fb. Bug: 32973182 Change-Id: I5b14a812671ea02575cb452242ff1a6f05edb9c1 (cherry picked from commit 30628db65cc7541c61d9b5e866d661d71cff6f4c) --- update_verifier/Android.mk | 5 +---- update_verifier/update_verifier.cpp | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/update_verifier/Android.mk b/update_verifier/Android.mk index 5d118f873..c822999f3 100644 --- a/update_verifier/Android.mk +++ b/update_verifier/Android.mk @@ -24,10 +24,7 @@ LOCAL_SHARED_LIBRARIES := \ libbase \ libcutils \ libhardware \ - liblog \ - libutils \ - libhidl \ - android.hardware.boot@1.0 + liblog LOCAL_C_INCLUDES += $(LOCAL_PATH)/.. LOCAL_CFLAGS := -Werror diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp index e97a3adba..93ac605b1 100644 --- a/update_verifier/update_verifier.cpp +++ b/update_verifier/update_verifier.cpp @@ -45,12 +45,7 @@ #include #include #include -#include - -using android::sp; -using android::hardware::boot::V1_0::IBootControl; -using android::hardware::boot::V1_0::BoolResult; -using android::hardware::boot::V1_0::CommandResult; +#include constexpr auto CARE_MAP_FILE = "/data/ota_package/care_map.txt"; constexpr int BLOCKSIZE = 4096; @@ -147,18 +142,21 @@ int main(int argc, char** argv) { LOG(INFO) << "Started with arg " << i << ": " << argv[i]; } - sp module = IBootControl::getService("bootctrl"); - if (module == nullptr) { + const hw_module_t* hw_module; + if (hw_get_module("bootctrl", &hw_module) != 0) { LOG(ERROR) << "Error getting bootctrl module."; return -1; } - uint32_t current_slot = module->getCurrentSlot(); - BoolResult is_successful = module->isSlotMarkedSuccessful(current_slot); - LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful=" - << static_cast(is_successful); + boot_control_module_t* module = reinterpret_cast( + const_cast(hw_module)); + module->init(module); + + unsigned current_slot = module->getCurrentSlot(module); + int is_successful= module->isSlotMarkedSuccessful(module, current_slot); + LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful=" << is_successful; - if (is_successful == BoolResult::FALSE) { + if (is_successful == 0) { // The current slot has not booted successfully. char verity_mode[PROPERTY_VALUE_MAX]; if (property_get("ro.boot.veritymode", verity_mode, "") == -1) { @@ -177,10 +175,9 @@ int main(int argc, char** argv) { return -1; } - CommandResult cr; - module->markBootSuccessful([&cr](CommandResult result) { cr = result; }); - if (!cr.success) { - LOG(ERROR) << "Error marking booted successfully: " << cr.errMsg; + int ret = module->markBootSuccessful(module); + if (ret != 0) { + LOG(ERROR) << "Error marking booted successfully: " << strerror(-ret); return -1; } LOG(INFO) << "Marked slot " << current_slot << " as booted successfully."; -- cgit v1.2.3 From 37cd3ae5d274d64dd5875a95f34272c619aa316b Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 21 Nov 2016 09:42:33 -0800 Subject: applypatch: Release FD when explicitly calling close. We use android::base::unique_fd() to avoid leaking FD. We also want to call close (or ota_close) to explicitly check the close result. When combining the two together, we need to release the unique_fd to avoid closing the same FD twice. Bug: 33034669 Test: Trigger applypatch with install-recovery.sh. Change-Id: I1a4f5d5fba7a23ef98d8bd7b7b07e87ae6f705c5 (cherry picked from commit 48cf770471ef53fbf0a1837196220862a0bdb18d) --- applypatch/applypatch.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp index 9b84fa104..41a8d582b 100644 --- a/applypatch/applypatch.cpp +++ b/applypatch/applypatch.cpp @@ -210,7 +210,7 @@ int SaveFileContents(const char* filename, const FileContents* file) { printf("fsync of \"%s\" failed: %s\n", filename, strerror(errno)); return -1; } - if (ota_close(fd) != 0) { + if (ota_close(fd.release()) != 0) { printf("close of \"%s\" failed: %s\n", filename, strerror(errno)); return -1; } @@ -268,7 +268,7 @@ int WriteToPartition(const unsigned char* data, size_t len, const std::string& t printf("failed to sync to %s: %s\n", partition, strerror(errno)); return -1; } - if (ota_close(fd) != 0) { + if (ota_close(fd.release()) != 0) { printf("failed to close %s: %s\n", partition, strerror(errno)); return -1; } @@ -287,7 +287,7 @@ int WriteToPartition(const unsigned char* data, size_t len, const std::string& t } else { printf(" caches dropped\n"); } - ota_close(dc); + ota_close(dc.release()); sleep(1); // Verify. @@ -339,7 +339,7 @@ int WriteToPartition(const unsigned char* data, size_t len, const std::string& t return -1; } - if (ota_close(fd) == -1) { + if (ota_close(fd.release()) == -1) { printf("error closing %s: %s\n", partition, strerror(errno)); return -1; } @@ -782,7 +782,7 @@ static int GenerateTarget(FileContents* source_file, printf("failed to fsync file \"%s\": %s\n", tmp_target_filename.c_str(), strerror(errno)); result = 1; } - if (ota_close(output_fd) != 0) { + if (ota_close(output_fd.release()) != 0) { printf("failed to close file \"%s\": %s\n", tmp_target_filename.c_str(), strerror(errno)); result = 1; } -- cgit v1.2.3