diff options
Diffstat (limited to 'bootloader_message')
-rw-r--r-- | bootloader_message/Android.NObp (renamed from bootloader_message/Android.bp) | 0 | ||||
-rw-r--r-- | bootloader_message/Android.mk | 29 | ||||
-rw-r--r-- | bootloader_message/bootloader_message.cpp | 29 | ||||
-rw-r--r-- | bootloader_message/include/bootloader_message/bootloader_message.h | 15 |
4 files changed, 70 insertions, 3 deletions
diff --git a/bootloader_message/Android.bp b/bootloader_message/Android.NObp index f0d76e718..f0d76e718 100644 --- a/bootloader_message/Android.bp +++ b/bootloader_message/Android.NObp diff --git a/bootloader_message/Android.mk b/bootloader_message/Android.mk new file mode 100644 index 000000000..0d84713c3 --- /dev/null +++ b/bootloader_message/Android.mk @@ -0,0 +1,29 @@ +# Copyright (C) 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_CLANG := true +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 f91446b43..6c237e620 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 2ffbfc9e3..4da1171cd 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 |