blob: 3150c936d5a67b9ad248c13c85baac2bf2c693ba [file] [log] [blame]
diff --git a/update_verifier/include/update_verifier/update_verifier.h b/update_verifier/include/update_verifier/update_verifier.h
index 16b394e98..c700a170b 100644
--- a/update_verifier/include/update_verifier/update_verifier.h
+++ b/update_verifier/include/update_verifier/update_verifier.h
@@ -22,3 +22,4 @@ int update_verifier(int argc, char** argv);
// Exposed for testing purpose.
bool verify_image(const std::string& care_map_name);
+std::string GetProperty(const char* strProperity);
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp
index 92d931371..45b12cb9f 100644
--- a/update_verifier/update_verifier.cpp
+++ b/update_verifier/update_verifier.cpp
@@ -34,9 +34,6 @@
* The current slot will be marked as having booted successfully if the
* verifier reaches the end after the verification.
*/
-
-#include "update_verifier/update_verifier.h"
-
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -52,20 +49,22 @@
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/parseint.h>
-#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
-#include <android/hardware/boot/1.0/IBootControl.h>
-#include <cutils/android_reboot.h>
+#include <hardware/boot_control.h>
+#include <hardware/hardware.h>
+#include <sys/reboot.h>
#include "otautil/rangeset.h"
+#include "update_verifier/update_verifier.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;
+using std::string;
// Find directories in format of "/sys/block/dm-X".
+
+extern const hw_module_t HAL_MODULE_INFO_SYM;
+boot_control_module_t* module;
+
static int dm_name_filter(const dirent* de) {
if (android::base::StartsWith(de->d_name, "dm-")) {
return 1;
@@ -73,6 +72,72 @@ static int dm_name_filter(const dirent* de) {
return 0;
}
+#define COMMAND_LINE_PATH "/proc/cmdline"
+#define COMMAND_LINE_SIZE 2048
+
+std::string GetProperty(const char* strProperity)
+{
+ int fd, err, slot;
+ ssize_t size = COMMAND_LINE_SIZE, sz;
+ char *buf, *ptr;
+ char *str;
+ std::string res;
+
+ fd = open(COMMAND_LINE_PATH, O_RDONLY);
+ if (fd < 0) {
+ err = -errno;
+ LOG(ERROR) << "error reading commandline\n";
+ return NULL;
+ }
+ ptr = buf = (char *)malloc(size);
+ if (!buf) {
+ err = -errno;
+ LOG(ERROR) << "Error allocating memory";
+ close(fd);
+ return NULL;
+ }
+ do {
+ sz = read(fd, buf, size);
+ if (sz == 0) {
+ break;
+ } else if (sz < 0) {
+ if (errno == EINTR) {
+ continue;
+ }
+ err = -errno;
+ LOG(ERROR) << "Error reading file";
+ free(ptr);
+ close(fd);
+ return NULL;
+ }
+ size -= sz;
+ buf += sz;
+ } while(size > 0);
+
+ str = strstr((char *)ptr, strProperity);
+ if (!str) {
+ err = -EIO;
+ LOG(ERROR) << "Cannot find %s in kernel commandline" << strProperity;
+ free(ptr);
+ close(fd);
+ return NULL;
+ }
+ str += strlen(strProperity);
+ while(1){
+ str++;
+ if(((*str == ' ') || (*str == '\0' ) || (*str == '\n'))){
+ break;
+ }else{
+ res.push_back(*str);
+ }
+ }
+ LOG(INFO) << "Find kernel commandline" << res;
+
+ free(ptr);
+ close(fd);
+ return res;
+}
+
static bool read_blocks(const std::string& partition, const std::string& range_str) {
if (partition != "system" && partition != "vendor" && partition != "product") {
LOG(ERROR) << "Invalid partition name \"" << partition << "\"";
@@ -103,6 +168,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
PLOG(WARNING) << "Failed to read " << path;
} else {
std::string dm_block_name = android::base::Trim(content);
+ LOG(ERROR) << "dm_block_name namelist[n]->d_name " << dm_block_name << namelist[n]->d_name;
#ifdef BOARD_AVB_ENABLE
// AVB is using 'vroot' for the root block device but we're expecting 'system'.
if (dm_block_name == "vroot") {
@@ -135,7 +201,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
LOG(ERROR) << "Error parsing RangeSet string " << range_str;
return false;
}
-
+
// RangeSet::Split() splits the ranges into multiple groups with same number of blocks (except for
// the last group).
size_t thread_num = std::thread::hardware_concurrency() ?: 4;
@@ -147,13 +213,27 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dm_block_device.c_str(), O_RDONLY)));
if (fd.get() == -1) {
PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition;
- return false;
+ //return false;
+ std::string path = "/sys/class/block/dm-0/dev";
+ std::string content;
+ if (!android::base::ReadFileToString(path, &content)) {
+ PLOG(WARNING) << "Failed to read " << path;
+ } else {
+ std::string dev_name = android::base::Trim(content);
+ dm_block_device = DEV_PATH + dev_name;
+ }
}
-
+ fd.reset(open(dm_block_device.c_str(), O_RDONLY));
+ if (fd.get() == -1) {
+ PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition;
+ return false;
+ }
+
static constexpr size_t kBlockSize = 4096;
std::vector<uint8_t> buf(1024 * kBlockSize);
size_t block_count = 0;
+
for (const auto& range : group) {
size_t range_start = range.first;
size_t range_end = range.second;
@@ -161,7 +241,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
PLOG(ERROR) << "lseek to " << range_start << " failed";
return false;
}
-
+ PLOG(ERROR) << "range start " << range_start << " range_end " << range_end;
size_t remain = (range_end - range_start) * kBlockSize;
while (remain > 0) {
size_t to_read = std::min(remain, 1024 * kBlockSize);
@@ -173,7 +253,7 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
}
block_count += (range_end - range_start);
}
- LOG(INFO) << "Finished reading " << block_count << " blocks on " << dm_block_device;
+ LOG(ERROR) << "Finished reading " << block_count << " blocks on " << dm_block_device ;
return true;
};
@@ -238,10 +318,13 @@ bool verify_image(const std::string& care_map_name) {
}
static int reboot_device() {
- if (android_reboot(ANDROID_RB_RESTART2, 0, nullptr) == -1) {
- LOG(ERROR) << "Failed to reboot.";
- return -1;
- }
+ //if (android_reboot(ANDROID_RB_RESTART2, 0, nullptr) == -1) {
+ // LOG(ERROR) << "Failed to reboot.";
+ // return -1;
+ //}
+ //system("reboot");
+ reboot(RB_AUTOBOOT);
+
while (true) pause();
}
@@ -250,23 +333,45 @@ int update_verifier(int argc, char** argv) {
LOG(INFO) << "Started with arg " << i << ": " << argv[i];
}
- sp<IBootControl> module = IBootControl::getService();
+ /************* Bootctrl Init Start *************/
+ //sp<IBootControl> module = IBootControl::getService();
+ const hw_module_t* hw_module;
+ int ret;
+
+ // For update_engine_sideload, we simulate the hw_get_module() by accessing it
+ // from the current process directly.
+ hw_module = &HAL_MODULE_INFO_SYM;
+ ret = 0;
+ if (!hw_module ||
+ strcmp(BOOT_CONTROL_HARDWARE_MODULE_ID, hw_module->id) != 0) {
+ ret = -EINVAL;
+ }
+ if (ret != 0) {
+ LOG(ERROR) << "Error loading boot_control HAL implementation.";
+ return false;
+ }
+
+ module = reinterpret_cast<boot_control_module_t*>(
+ const_cast<hw_module_t*>(hw_module));
+ module->init(module);
+
if (module == nullptr) {
LOG(ERROR) << "Error getting bootctrl module.";
return reboot_device();
}
+ /************* Bootctrl Init End *************/
- uint32_t current_slot = module->getCurrentSlot();
- BoolResult is_successful = module->isSlotMarkedSuccessful(current_slot);
+ uint32_t current_slot = module->getCurrentSlot(module);
+ //bool is_successful = module->isSlotMarkedSuccessful(current_slot);
+ bool is_successful = module->isSlotMarkedSuccessful(module, current_slot);
LOG(INFO) << "Booting slot " << current_slot << ": isSlotMarkedSuccessful="
- << static_cast<int32_t>(is_successful);
+ << is_successful;
- if (is_successful == BoolResult::FALSE) {
+ if (is_successful == false) {
// The current slot has not booted successfully.
-
#if defined(PRODUCT_SUPPORTS_VERITY) || defined(BOARD_AVB_ENABLE)
bool skip_verification = false;
- std::string verity_mode = android::base::GetProperty("ro.boot.veritymode", "");
+ std::string verity_mode = GetProperty("androidboot.veritymode");
if (verity_mode.empty()) {
// With AVB it's possible to disable verification entirely and
// in this case ro.boot.veritymode is empty.
@@ -290,7 +395,7 @@ int update_verifier(int argc, char** argv) {
}
if (!skip_verification) {
- static constexpr auto CARE_MAP_FILE = "/data/ota_package/care_map.txt";
+ static constexpr auto CARE_MAP_FILE = "/var/lib/update_engine/care_map.txt";
if (!verify_image(CARE_MAP_FILE)) {
LOG(ERROR) << "Failed to verify all blocks in care map file.";
return reboot_device();
@@ -300,10 +405,10 @@ int update_verifier(int argc, char** argv) {
LOG(WARNING) << "dm-verity not enabled; marking without verification.";
#endif
- CommandResult cr;
- module->markBootSuccessful([&cr](CommandResult result) { cr = result; });
- if (!cr.success) {
- LOG(ERROR) << "Error marking booted successfully: " << cr.errMsg;
+ //bool cr = module->markBootSuccessful([&cr](CommandResult result) { cr = result; });
+ int cr = module->markBootSuccessful(module);
+ if (cr < 0) {
+ LOG(ERROR) << "Error marking booted successfully: " << cr;
return reboot_device();
}
LOG(INFO) << "Marked slot " << current_slot << " as booted successfully.";
diff --git a/update_verifier/update_verifier_main.cpp b/update_verifier/update_verifier_main.cpp
index a86203bfb..c22582341 100644
--- a/update_verifier/update_verifier_main.cpp
+++ b/update_verifier/update_verifier_main.cpp
@@ -19,12 +19,15 @@
#include <string>
#include <android-base/logging.h>
-#include <android-base/properties.h>
+//#include <android-base/properties.h>
#include "update_verifier/update_verifier.h"
int main(int argc, char** argv) {
- std::string s = android::base::GetProperty("ro.boot.slot_suffix", "");
+ //std::string s = android::base::GetProperty("ro.boot.slot_suffix", "");
+
+
+ std::string s = GetProperty("androidboot.slot");
if (s.empty()) {
return 0; // non-A/B update device, so we quit
@@ -32,7 +35,7 @@ int main(int argc, char** argv) {
// Set up update_verifier logging to be written to kmsg; because we may not have Logd during
// boot time.
- android::base::InitLogging(argv, &android::base::KernelLogger);
+ android::base::InitLogging(argv, android::base::StderrLogger);
return update_verifier(argc, argv);
}