diff options
author | Yabin Cui <yabinc@google.com> | 2016-06-21 19:10:49 +0200 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-06-21 19:10:49 +0200 |
commit | ed4c49c199224dfe2cf99a26864c5848487da2c3 (patch) | |
tree | 470a094131460851765cd88e9b576b7458348b5a /uncrypt/bootloader_message_writer.cpp | |
parent | Check the results from applypatch (diff) | |
parent | Verify wipe package when wiping A/B device in recovery. (diff) | |
download | android_bootable_recovery-ed4c49c199224dfe2cf99a26864c5848487da2c3.tar android_bootable_recovery-ed4c49c199224dfe2cf99a26864c5848487da2c3.tar.gz android_bootable_recovery-ed4c49c199224dfe2cf99a26864c5848487da2c3.tar.bz2 android_bootable_recovery-ed4c49c199224dfe2cf99a26864c5848487da2c3.tar.lz android_bootable_recovery-ed4c49c199224dfe2cf99a26864c5848487da2c3.tar.xz android_bootable_recovery-ed4c49c199224dfe2cf99a26864c5848487da2c3.tar.zst android_bootable_recovery-ed4c49c199224dfe2cf99a26864c5848487da2c3.zip |
Diffstat (limited to 'uncrypt/bootloader_message_writer.cpp')
-rw-r--r-- | uncrypt/bootloader_message_writer.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/uncrypt/bootloader_message_writer.cpp b/uncrypt/bootloader_message_writer.cpp index 3bb106aa0..42df31efa 100644 --- a/uncrypt/bootloader_message_writer.cpp +++ b/uncrypt/bootloader_message_writer.cpp @@ -58,7 +58,7 @@ static std::string get_misc_blk_device(std::string* err) { return record->blk_device; } -static bool write_bootloader_message(const bootloader_message& boot, std::string* err) { +static bool write_misc_partition(const void* p, size_t size, size_t misc_offset, std::string* err) { std::string misc_blk_device = get_misc_blk_device(err); if (misc_blk_device.empty()) { return false; @@ -69,11 +69,18 @@ static bool write_bootloader_message(const bootloader_message& boot, std::string strerror(errno)); return false; } - if (!android::base::WriteFully(fd.get(), &boot, sizeof(boot))) { + if (lseek(fd.get(), static_cast<off_t>(misc_offset), SEEK_SET) != + static_cast<off_t>(misc_offset)) { + *err = android::base::StringPrintf("failed to lseek %s: %s", misc_blk_device.c_str(), + strerror(errno)); + return false; + } + if (!android::base::WriteFully(fd.get(), p, size)) { *err = android::base::StringPrintf("failed to write %s: %s", misc_blk_device.c_str(), strerror(errno)); return false; } + // TODO: O_SYNC and fsync duplicates each other? if (fsync(fd.get()) == -1) { *err = android::base::StringPrintf("failed to fsync %s: %s", misc_blk_device.c_str(), @@ -83,6 +90,10 @@ static bool write_bootloader_message(const bootloader_message& boot, std::string return true; } +static bool write_bootloader_message(const bootloader_message& boot, std::string* err) { + return write_misc_partition(&boot, sizeof(boot), BOOTLOADER_MESSAGE_OFFSET_IN_MISC, err); +} + bool clear_bootloader_message(std::string* err) { bootloader_message boot = {}; return write_bootloader_message(boot, err); @@ -101,6 +112,11 @@ bool write_bootloader_message(const std::vector<std::string>& options, std::stri return write_bootloader_message(boot, err); } +bool write_wipe_package(const std::string& package_data, std::string* err) { + return write_misc_partition(package_data.data(), package_data.size(), + WIPE_PACKAGE_OFFSET_IN_MISC, err); +} + extern "C" bool write_bootloader_message(const char* options) { std::string err; return write_bootloader_message({options}, &err); |