summaryrefslogtreecommitdiffstats
path: root/bootloader_message
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader_message')
-rw-r--r--bootloader_message/Android.mk4
-rw-r--r--bootloader_message/bootloader_message.cpp29
-rw-r--r--bootloader_message/include/bootloader_message/bootloader_message.h15
3 files changed, 45 insertions, 3 deletions
diff --git a/bootloader_message/Android.mk b/bootloader_message/Android.mk
index a8c50819b..0d84713c3 100644
--- a/bootloader_message/Android.mk
+++ b/bootloader_message/Android.mk
@@ -20,6 +20,10 @@ LOCAL_SRC_FILES := bootloader_message.cpp
LOCAL_MODULE := libbootloader_message
LOCAL_STATIC_LIBRARIES := libbase libfs_mgr
LOCAL_CFLAGS := -Werror
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -lt 26; echo $$?),0)
+ TARGET_GLOBAL_CFLAGS += -DUSE_OLD_BOOTLOADER_MESSAGE
+ CLANG_TARGET_GLOBAL_CFLAGS += -DUSE_OLD_BOOTLOADER_MESSAGE
+endif
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
include $(BUILD_STATIC_LIBRARY)
diff --git a/bootloader_message/bootloader_message.cpp b/bootloader_message/bootloader_message.cpp
index d8086be28..dcaeb794f 100644
--- a/bootloader_message/bootloader_message.cpp
+++ b/bootloader_message/bootloader_message.cpp
@@ -24,19 +24,46 @@
#include <vector>
#include <android-base/file.h>
-#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <fs_mgr.h>
+#ifdef USE_OLD_BOOTLOADER_MESSAGE
+#include <sys/system_properties.h>
+
+static struct fstab* read_fstab(std::string* err) {
+ // The fstab path is always "/fstab.${ro.hardware}".
+ std::string fstab_path = "/fstab.";
+ char value[PROP_VALUE_MAX];
+ if (__system_property_get("ro.hardware", value) == 0) {
+ *err = "failed to get ro.hardware";
+ return nullptr;
+ }
+ fstab_path += value;
+ struct fstab* fstab = fs_mgr_read_fstab(fstab_path.c_str());
+ if (fstab == nullptr) {
+ *err = "failed to read " + fstab_path;
+ }
+ return fstab;
+}
+#endif
+
static std::string get_misc_blk_device(std::string* err) {
+#ifdef USE_OLD_BOOTLOADER_MESSAGE
+ struct fstab* fstab = read_fstab(err);
+#else
std::unique_ptr<fstab, decltype(&fs_mgr_free_fstab)> fstab(fs_mgr_read_fstab_default(),
fs_mgr_free_fstab);
+#endif
if (!fstab) {
*err = "failed to read default fstab";
return "";
}
+#ifdef USE_OLD_BOOTLOADER_MESSAGE
+ fstab_rec* record = fs_mgr_get_entry_for_mount_point(fstab, "/misc");
+#else
fstab_rec* record = fs_mgr_get_entry_for_mount_point(fstab.get(), "/misc");
+#endif
if (record == nullptr) {
*err = "failed to find /misc partition";
return "";
diff --git a/bootloader_message/include/bootloader_message/bootloader_message.h b/bootloader_message/include/bootloader_message/bootloader_message.h
index bc5104ddf..4ad18f2d9 100644
--- a/bootloader_message/include/bootloader_message/bootloader_message.h
+++ b/bootloader_message/include/bootloader_message/bootloader_message.h
@@ -65,6 +65,16 @@ struct bootloader_message {
char status[32];
char recovery[768];
+#ifdef USE_OLD_BOOTLOADER_MESSAGE
+ // The 'recovery' field used to be 1024 bytes. It has only ever
+ // been used to store the recovery command line, so 768 bytes
+ // should be plenty. We carve off the last 256 bytes to store the
+ // stage string (for multistage packages) and possible future
+ // expansion.
+ char stage[32];
+ char slot_suffix[32];
+ char reserved[192];
+#else
// The 'recovery' field used to be 1024 bytes. It has only ever
// been used to store the recovery command line, so 768 bytes
// should be plenty. We carve off the last 256 bytes to store the
@@ -77,13 +87,14 @@ struct bootloader_message {
// 1184-byte so that the entire bootloader_message struct rounds up
// to 2048-byte.
char reserved[1184];
+#endif
};
/**
* We must be cautious when changing the bootloader_message struct size,
* because A/B-specific fields may end up with different offsets.
*/
-#if (__STDC_VERSION__ >= 201112L) || defined(__cplusplus)
+#if !defined(USE_OLD_BOOTLOADER_MESSAGE) && ((__STDC_VERSION__ >= 201112L) || defined(__cplusplus))
static_assert(sizeof(struct bootloader_message) == 2048,
"struct bootloader_message size changes, which may break A/B devices");
#endif
@@ -116,7 +127,7 @@ struct bootloader_message_ab {
* Be cautious about the struct size change, in case we put anything post
* bootloader_message_ab struct (b/29159185).
*/
-#if (__STDC_VERSION__ >= 201112L) || defined(__cplusplus)
+#if !defined(USE_OLD_BOOTLOADER_MESSAGE) && ((__STDC_VERSION__ >= 201112L) || defined(__cplusplus))
static_assert(sizeof(struct bootloader_message_ab) == 4096,
"struct bootloader_message_ab size changes");
#endif