summaryrefslogtreecommitdiffstats
path: root/bootloader_message
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2019-05-16 23:42:42 +0200
committerTao Bao <tbao@google.com>2019-05-21 00:51:26 +0200
commit7ae01698424cc3adf635c324961b1405594f5156 (patch)
tree70ea4a53c7f20236f6388e1ebd1b5c933783f615 /bootloader_message
parentDO NOT MERGE - Skip pi-platform-release (PPRL.190505.001) in stage-aosp-master (diff)
downloadandroid_bootable_recovery-7ae01698424cc3adf635c324961b1405594f5156.tar
android_bootable_recovery-7ae01698424cc3adf635c324961b1405594f5156.tar.gz
android_bootable_recovery-7ae01698424cc3adf635c324961b1405594f5156.tar.bz2
android_bootable_recovery-7ae01698424cc3adf635c324961b1405594f5156.tar.lz
android_bootable_recovery-7ae01698424cc3adf635c324961b1405594f5156.tar.xz
android_bootable_recovery-7ae01698424cc3adf635c324961b1405594f5156.tar.zst
android_bootable_recovery-7ae01698424cc3adf635c324961b1405594f5156.zip
Diffstat (limited to 'bootloader_message')
-rw-r--r--bootloader_message/Android.bp34
-rw-r--r--bootloader_message/bootloader_message.cpp42
-rw-r--r--bootloader_message/include/bootloader_message/bootloader_message.h13
3 files changed, 75 insertions, 14 deletions
diff --git a/bootloader_message/Android.bp b/bootloader_message/Android.bp
index e76305fd7..8d72a1163 100644
--- a/bootloader_message/Android.bp
+++ b/bootloader_message/Android.bp
@@ -14,10 +14,8 @@
// limitations under the License.
//
-cc_library {
- name: "libbootloader_message",
- recovery_available: true,
- host_supported: true,
+cc_defaults {
+ name: "libbootloader_message_defaults",
srcs: ["bootloader_message.cpp"],
cflags: [
"-Wall",
@@ -26,24 +24,36 @@ cc_library {
shared_libs: [
"libbase",
],
+ static_libs: [
+ "libfstab",
+ ],
export_include_dirs: ["include"],
+}
+
+cc_library {
+ name: "libbootloader_message",
+ defaults: [
+ "libbootloader_message_defaults",
+ ],
+ recovery_available: true,
+ host_supported: true,
target: {
- android: {
- shared_libs: [
- "libfs_mgr",
- ],
- },
host: {
shared_libs: [
"libcutils", // for strlcpy
],
- static_libs: [
- "libfstab",
- ],
},
darwin: {
enabled: false,
},
}
}
+
+cc_library_static {
+ name: "libbootloader_message_vendor",
+ defaults: [
+ "libbootloader_message_defaults",
+ ],
+ vendor: true,
+}
diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp
index 331a42b2a..e684abbad 100644
--- a/bootloader_message/bootloader_message.cpp
+++ b/bootloader_message/bootloader_message.cpp
@@ -21,6 +21,7 @@
#include <string.h>
#include <string>
+#include <string_view>
#include <vector>
#include <android-base/file.h>
@@ -36,7 +37,17 @@
using android::fs_mgr::Fstab;
using android::fs_mgr::ReadDefaultFstab;
+static std::string g_misc_device_for_test;
+
+// Exposed for test purpose.
+void SetMiscBlockDeviceForTest(std::string_view misc_device) {
+ g_misc_device_for_test = misc_device;
+}
+
static std::string get_misc_blk_device(std::string* err) {
+ if (!g_misc_device_for_test.empty()) {
+ return g_misc_device_for_test;
+ }
Fstab fstab;
if (!ReadDefaultFstab(&fstab)) {
*err = "failed to read default fstab";
@@ -242,6 +253,37 @@ 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);
+}
+
extern "C" bool write_reboot_bootloader(void) {
std::string err;
return write_reboot_bootloader(&err);
diff --git a/bootloader_message/include/bootloader_message/bootloader_message.h b/bootloader_message/include/bootloader_message/bootloader_message.h
index 2207d4cb3..5c0a450fc 100644
--- a/bootloader_message/include/bootloader_message/bootloader_message.h
+++ b/bootloader_message/include/bootloader_message/bootloader_message.h
@@ -28,8 +28,9 @@
// 16K - 64K Used by uncrypt and recovery to store wipe_package for A/B devices
// Note that these offsets are admitted by bootloader,recovery and uncrypt, so they
// are not configurable without changing all of them.
-static const size_t BOOTLOADER_MESSAGE_OFFSET_IN_MISC = 0;
-static const size_t WIPE_PACKAGE_OFFSET_IN_MISC = 16 * 1024;
+constexpr size_t BOOTLOADER_MESSAGE_OFFSET_IN_MISC = 0;
+constexpr size_t VENDOR_SPACE_OFFSET_IN_MISC = 2 * 1024;
+constexpr size_t WIPE_PACKAGE_OFFSET_IN_MISC = 16 * 1024;
/* Bootloader Message (2-KiB)
*
@@ -233,6 +234,14 @@ 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);
+
#else
#include <stdbool.h>