From ee6a0b5a8b2949ae442fc5c930f5a65f1598f685 Mon Sep 17 00:00:00 2001 From: Connor O'Brien Date: Fri, 28 Sep 2018 12:53:02 -0700 Subject: [PATCH] Add statically linked boot HAL impl in recovery The default Treble boot HAL implementation currently can only work in recovery on devices that specifically build their libhardware implementation as a shared library for recovery. This CL adds the option to statically link the libhardware implementation in recovery instead of finding it using hw_get_module(). This new approach allows devices that define PRODUCT_STATIC_BOOT_CONTROL_HAL to begin using the Treble HAL in recovery without requiring device-specific changes. Test: adb sideload succeeds Bug: 78598708 Change-Id: I7e1651fad64c2e55da256a164d2875956f68fb67 Signed-off-by: Connor O'Brien --- boot/1.0/default/Android.mk | 29 +++++++++++++++++++++++++++++ boot/1.0/default/BootControl.cpp | 22 +++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 boot/1.0/default/Android.mk diff --git a/boot/1.0/default/Android.mk b/boot/1.0/default/Android.mk new file mode 100644 index 0000000000..cd4b499ae6 --- /dev/null +++ b/boot/1.0/default/Android.mk @@ -0,0 +1,29 @@ +# TODO(connoro): Remove this file once we eliminate existing usage of +# PRODUCT_STATIC_BOOT_CONTROL_HAL + +LOCAL_PATH := $(call my-dir) + +ifneq ($(strip $(PRODUCT_STATIC_BOOT_CONTROL_HAL)),) +include $(CLEAR_VARS) + +LOCAL_MODULE := android.hardware.boot@1.0-impl-wrapper.recovery +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_MULTILIB := first +ifeq ($(TARGET_IS_64_BIT),true) +LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/lib64/hw +else +LOCAL_MODULE_PATH := $(TARGET_RECOVERY_ROOT_OUT)/system/lib/hw +endif +LOCAL_SRC_FILES := BootControl.cpp +LOCAL_CFLAGS := -DBOOT_CONTROL_RECOVERY +LOCAL_SHARED_LIBRARIES := \ + liblog.recovery \ + libhidlbase.recovery \ + libhidltransport.recovery \ + libhardware.recovery \ + libutils.recovery \ + android.hardware.boot@1.0.recovery +LOCAL_STATIC_LIBRARIES := $(PRODUCT_STATIC_BOOT_CONTROL_HAL) +include $(BUILD_SHARED_LIBRARY) + +endif diff --git a/boot/1.0/default/BootControl.cpp b/boot/1.0/default/BootControl.cpp index 9a900767d7..e36407fe26 100644 --- a/boot/1.0/default/BootControl.cpp +++ b/boot/1.0/default/BootControl.cpp @@ -21,6 +21,10 @@ #include #include "BootControl.h" +#ifdef BOOT_CONTROL_RECOVERY +extern const hw_module_t HAL_MODULE_INFO_SYM; +#endif + namespace android { namespace hardware { namespace boot { @@ -92,7 +96,23 @@ Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { return Void(); } +#ifdef BOOT_CONTROL_RECOVERY +IBootControl* HIDL_FETCH_IBootControl(const char * /* hal */) { + boot_control_module_t* module; + // For devices that don't build a standalone libhardware bootctrl impl for recovery, + // we simulate the hw_get_module() by accessing it from the current process directly. + const hw_module_t* hw_module = &HAL_MODULE_INFO_SYM; + if (!hw_module || + strcmp(BOOT_CONTROL_HARDWARE_MODULE_ID, hw_module->id) != 0) { + ALOGE("Error loading boot_control HAL implementation: %d.", -EINVAL); + return nullptr; + } + module = reinterpret_cast(const_cast(hw_module)); + module->init(module); + return new BootControl(module); +} +#else IBootControl* HIDL_FETCH_IBootControl(const char* /* hal */) { int ret = 0; boot_control_module_t* module = NULL; @@ -106,7 +126,7 @@ IBootControl* HIDL_FETCH_IBootControl(const char* /* hal */) { module->init(module); return new BootControl(module); } - +#endif } // namespace implementation } // namespace V1_0 } // namespace boot