summaryrefslogtreecommitdiffstats
path: root/bootloader_message
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2019-11-10 07:07:20 +0100
committerTianjie Xu <xunchang@google.com>2019-11-12 19:53:04 +0100
commit3d57c84476ce542a7d8d623cf1f208efc1a20026 (patch)
tree98792d6c0dee1e8205a425e6519019614d66122d /bootloader_message
parentMerge "bootloader_message: Add helpers for handling IBootControl MergeStatus." (diff)
downloadandroid_bootable_recovery-3d57c84476ce542a7d8d623cf1f208efc1a20026.tar
android_bootable_recovery-3d57c84476ce542a7d8d623cf1f208efc1a20026.tar.gz
android_bootable_recovery-3d57c84476ce542a7d8d623cf1f208efc1a20026.tar.bz2
android_bootable_recovery-3d57c84476ce542a7d8d623cf1f208efc1a20026.tar.lz
android_bootable_recovery-3d57c84476ce542a7d8d623cf1f208efc1a20026.tar.xz
android_bootable_recovery-3d57c84476ce542a7d8d623cf1f208efc1a20026.tar.zst
android_bootable_recovery-3d57c84476ce542a7d8d623cf1f208efc1a20026.zip
Diffstat (limited to 'bootloader_message')
-rw-r--r--bootloader_message/bootloader_message.cpp37
-rw-r--r--bootloader_message/include/bootloader_message/bootloader_message.h15
2 files changed, 10 insertions, 42 deletions
diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp
index 4f7085db9..b70d54e5c 100644
--- a/bootloader_message/bootloader_message.cpp
+++ b/bootloader_message/bootloader_message.cpp
@@ -45,7 +45,7 @@ void SetMiscBlockDeviceForTest(std::string_view misc_device) {
g_misc_device_for_test = misc_device;
}
-static std::string get_misc_blk_device(std::string* err) {
+std::string get_misc_blk_device(std::string* err) {
if (g_misc_device_for_test.has_value() && !g_misc_device_for_test->empty()) {
return *g_misc_device_for_test;
}
@@ -111,8 +111,8 @@ static bool read_misc_partition(void* p, size_t size, const std::string& misc_bl
return true;
}
-static bool write_misc_partition(const void* p, size_t size, const std::string& misc_blk_device,
- size_t offset, std::string* err) {
+bool write_misc_partition(const void* p, size_t size, const std::string& misc_blk_device,
+ size_t offset, std::string* err) {
android::base::unique_fd fd(open(misc_blk_device.c_str(), O_WRONLY));
if (fd == -1) {
*err = android::base::StringPrintf("failed to open %s: %s", misc_blk_device.c_str(),
@@ -261,37 +261,6 @@ bool write_wipe_package(const std::string& package_data, std::string* err) {
WIPE_PACKAGE_OFFSET_IN_MISC, err);
}
-static bool OffsetAndSizeInVendorSpace(size_t offset, size_t size) {
- auto total_size = WIPE_PACKAGE_OFFSET_IN_MISC - VENDOR_SPACE_OFFSET_IN_MISC;
- return size <= total_size && offset <= total_size - size;
-}
-
-bool ReadMiscPartitionVendorSpace(void* data, size_t size, size_t offset, std::string* err) {
- if (!OffsetAndSizeInVendorSpace(offset, size)) {
- *err = android::base::StringPrintf("Out of bound read (offset %zu size %zu)", offset, size);
- return false;
- }
- auto misc_blk_device = get_misc_blk_device(err);
- if (misc_blk_device.empty()) {
- return false;
- }
- return read_misc_partition(data, size, misc_blk_device, VENDOR_SPACE_OFFSET_IN_MISC + offset,
- err);
-}
-
-bool WriteMiscPartitionVendorSpace(const void* data, size_t size, size_t offset, std::string* err) {
- if (!OffsetAndSizeInVendorSpace(offset, size)) {
- *err = android::base::StringPrintf("Out of bound write (offset %zu size %zu)", offset, size);
- return false;
- }
- auto misc_blk_device = get_misc_blk_device(err);
- if (misc_blk_device.empty()) {
- return false;
- }
- return write_misc_partition(data, size, misc_blk_device, VENDOR_SPACE_OFFSET_IN_MISC + offset,
- err);
-}
-
static bool ValidateSystemSpaceRegion(size_t offset, size_t size, std::string* err) {
if (size <= SYSTEM_SPACE_SIZE_IN_MISC && offset <= (SYSTEM_SPACE_SIZE_IN_MISC - size)) {
return true;
diff --git a/bootloader_message/include/bootloader_message/bootloader_message.h b/bootloader_message/include/bootloader_message/bootloader_message.h
index 3a3b862aa..a27e80bcc 100644
--- a/bootloader_message/include/bootloader_message/bootloader_message.h
+++ b/bootloader_message/include/bootloader_message/bootloader_message.h
@@ -212,11 +212,18 @@ struct misc_system_space_layout {
#include <string>
#include <vector>
+// Gets the block device name of /misc partition.
+std::string get_misc_blk_device(std::string* err);
// Return the block device name for the bootloader message partition and waits
// for the device for up to 10 seconds. In case of error returns the empty
// string.
std::string get_bootloader_message_blk_device(std::string* err);
+// Writes |size| bytes of data from buffer |p| to |misc_blk_device| at |offset|. If the write fails,
+// sets the error message in |err|.
+bool write_misc_partition(const void* p, size_t size, const std::string& misc_blk_device,
+ size_t offset, std::string* err);
+
// Read bootloader message into boot. Error message will be set in err.
bool read_bootloader_message(bootloader_message* boot, std::string* err);
@@ -261,14 +268,6 @@ bool read_wipe_package(std::string* package_data, size_t size, std::string* err)
// Write the wipe package into BCB (to offset WIPE_PACKAGE_OFFSET_IN_MISC).
bool write_wipe_package(const std::string& package_data, std::string* err);
-// Reads data from the vendor space in /misc partition, with the given offset and size. Note that
-// offset is in relative to the start of vendor space.
-bool ReadMiscPartitionVendorSpace(void* data, size_t size, size_t offset, std::string* err);
-
-// Writes the given data to the vendor space in /misc partition, at the given offset. Note that
-// offset is in relative to the start of the vendor space.
-bool WriteMiscPartitionVendorSpace(const void* data, size_t size, size_t offset, std::string* err);
-
// Read or write the Virtual A/B message from system space in /misc.
bool ReadMiscVirtualAbMessage(misc_virtual_ab_message* message, std::string* err);
bool WriteMiscVirtualAbMessage(const misc_virtual_ab_message& message, std::string* err);