/hardware/libhardware/hardware.c

本文深入探讨了Android系统中硬件模块的加载过程,重点分析了如何在/system/lib/hw和/vendor/lib/hw目录下查找并加载gralloc.xxx.so文件。通过调用load接口和gralloc_device_open函数,完成gralloc设备的初始化。涉及到的关键源代码位于/hardware/libhardware/modules/gralloc目录下的gralloc.cpp和framebuffer.cpp文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://blog.youkuaiyun.com/u012728256/article/details/71130877

/hardware/libhardware/hardware.c

#include <hardware/hardware.h>

#include <cutils/properties.h>

#include <dlfcn.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <unistd.h>

#define LOG_TAG "HAL"
#include <log/log.h>

#include <vndksupport/linker.h>

/** Base path of the hal modules */
#if defined(__LP64__)
#define HAL_LIBRARY_PATH1 "/system/lib64/hw"
#define HAL_LIBRARY_PATH2 "/vendor/lib64/hw"
#define HAL_LIBRARY_PATH3 "/odm/lib64/hw"
#else
#define HAL_LIBRARY_PATH1 "/system/lib/hw"
#define HAL_LIBRARY_PATH2 "/vendor/lib/hw"
#define HAL_LIBRARY_PATH3 "/odm/lib/hw"
#endif

/**
 * There are a set of variant filename for modules. The form of the filename
 * is "<MODULE_ID>.variant.so" so for the led module the Dream variants
 * of base "ro.product.board", "ro.board.platform" and "ro.arch" would be:
 *
 * led.trout.so
 * led.msm7k.so
 * led.ARMV6.so
 * led.default.so
 */

static const char *variant_keys[] = {
    "ro.hardware",  /* This goes first so that it can pick up a different
                       file on the emulator. */
    "ro.product.board",
    "ro.board.platform",
    "ro.arch"
};

static const int HAL_VARIANT_KEYS_COUNT =
    (sizeof(variant_keys)/sizeof(variant_keys[0]));

/**
 * Load the file defined by the variant and if successful
 * return the dlopen handle and the hmi.
 * @return 0 = success, !0 = failure.
 */
static int load(const char *id,
        const char *path,
        const struct hw_module_t **pHmi)
{
    int status = -EINVAL;
    void *handle = NULL;
    struct hw_module_t *hmi = NULL;
#ifdef __ANDROID_VNDK__
    const bool try_system = false;
#else
    const bool try_system = true;
#endif

    /*
     * load the symbols resolving undefined symbols before
     * dlopen returns. Since RTLD_GLOBAL is not or'd in with
     * RTLD_NOW the external symbols will not be global
     */
    if (try_system &&
        strncmp(path, HAL_LIBRARY_PATH1, strlen(HAL_LIBRARY_PATH1)) == 0) {
        /* If the library is in system partition, no need to check
         * sphal namespace. Open it with dlopen.
         */
        handle = dlopen(path, RTLD_NOW);
    } else {
        handle = android_load_sphal_library(path, RTLD_NOW);
    }
    if (handle == NULL) {
        char const *err_str = dlerror();
        ALOGE("load: module=%s\n%s", path, err_str?err_str:"unknown");
        status = -EINVAL;
        goto done;
    }

    /* Get the address of the struct hal_module_info. */
    const char *sym = HAL_MODULE_INFO_SYM_AS_STR;
    hmi = (struct hw_module_t *)dlsym(handle, sym);
    if (hmi == NULL) {
        ALOGE("load: couldn't find symbol %s", sym);
      
FAILED: out/target/product/p3q/obj/SHARED_LIBRARIES/libcdsprpc_intermediates/check_elf_files.timestamp /bin/bash -c "(rm -f out/target/product/p3q/obj/SHARED_LIBRARIES/libcdsprpc_intermediates/check_elf_files.timestamp ) && (out/host/linux-x86/bin/check_elf_file --skip-bad-elf-magic --skip-unknown-elf-machine --soname libcdsprpc.so --shared-lib out/target/product/p3q/obj/SHARED_LIBRARIES/liblog.vendor_intermediates/liblog.vendor.so --shared-lib out/target/product/p3q/obj/SHARED_LIBRARIES/libcutils.vendor_intermediates/libcutils.vendor.so --shared-lib out/target/product/p3q/obj/SHARED_LIBRARIES/libc.vendor_intermediates/libc.vendor.so --shared-lib out/target/product/p3q/obj/SHARED_LIBRARIES/libm.vendor_intermediates/libm.vendor.so --shared-lib out/target/product/p3q/obj/SHARED_LIBRARIES/libc++.vendor_intermediates/libc++.vendor.so --shared-lib out/target/product/p3q/obj/SHARED_LIBRARIES/libdl.vendor_intermediates/libdl.vendor.so --system-shared-lib libc --system-shared-lib libm --system-shared-lib libdl --llvm-readobj=prebuilts/clang/host/linux-x86/clang-r536225/bin/llvm-readobj out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so ) && (touch out/target/product/p3q/obj/SHARED_LIBRARIES/libcdsprpc_intermediates/check_elf_files.timestamp )" out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: error: DT_NEEDED "libhidlbase.so" is not specified in shared_libs. out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: error: DT_NEEDED "libhardware.so" is not specified in shared_libs. out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: error: DT_NEEDED "libutils.so" is not specified in shared_libs. out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: error: DT_NEEDED "vendor.qti.hardware.dsp@1.0.so" is not specified in shared_libs. out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: error: DT_NEEDED "libion.so" is not specified in shared_libs. out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: Fix suggestions: out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: Android.bp: shared_libs: ["libc++", "libcutils", "libhardware", "libhidlbase", "libion", "liblog", "libutils", "vendor.qti.hardware.dsp@1.0"], out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: Android.mk: LOCAL_SHARED_LIBRARIES := libc++ libcutils libhardware libhidlbase libion liblog libutils vendor.qti.hardware.dsp@1.0 out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: If the fix above doesn't work, bypass this check with: out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: Android.bp: check_elf_files: false, out/soong/.intermediates/vendor/samsung/sm8350-common/libcdsprpc/android_vendor_arm64_armv8-a_shared/libcdsprpc.so: note: Android.mk: LOCAL_CHECK_ELF_FILES := false 19:17:44 ninja failed with: exit status 1 #### failed to build some targets (04:38:33 (hh:mm:ss)) ####
最新发布
08-08
bootstrap_go_package { name: "soong-customParser", pkgPath: "android/soong/customParser", deps: [ "blueprint", "blueprint-pathtools", "soong", "soong-android", "soong-cc", "soong-genrule", ], srcs: [ "custom.go", ], pluginFor: ["soong_build"], } cc_library_headers { name: "libssccalapi_headers@2.0", vendor_available: true, min_sdk_version: "29", export_include_dirs: ["libssccalapi/inc", "custom/common/inc", ], } libssccalapi_parser_defaults { name: "libssccalapi_parser_defaults" } cc_library_shared { name: "libssccalapi@2.0", defaults: ["libssccalapi_parser_defaults"], clang: true, owner: "xiaomi", proprietary: true, // device_specific: true, srcs: [ "libssccalapi/src/*.cpp", "custom/common/src/sensorImpl.cpp", ], cflags: [ "-Wall", "-Werror", "-fexceptions", "-Wno-unused-variable", "-Wno-unused-parameter", ], include_dirs: [ "hardware/libhardware/include/hardware/", "hardware/libhardware/include/", "vendor/mediatek/proprietary/hardware/sensor/2.0/core/", ], header_libs: [ // "vendor_common_inc", // "libsensorlog_headers", // "libssc_headers", MTK need? // "libsensor_cal_headers@2.0", "libandroid_sensor_headers", "libssccalapi_headers@2.0", ], shared_libs: [ "liblog", // "libsnsapi", // "libsensorslog", // "libssc", "libutils", "libcutils", "libhardware", "libdl", "libhidltransport", "libhidlbase", "android.hardware.sensors@2.0", "android.hardware.sensors@2.0-ScopedWakelock", "android.frameworks.sensorservice@1.0", "libjsoncpp", "libhfmanagerwrapper", "libmisight", ], } cc_library_headers { name: "citsensorservice_headers@2.0", vendor_available: true, min_sdk_version: "29", export_include_dirs: [ "citsensorservice-hidl-impl/inc", "display-parse-algo/include/", ], } citsensorserviceImpl_parser_defaults { name: "citsensorserviceImpl_parser_defaults" } cc_library_shared { name: "vendor.xiaomi.sensor.citsensorservice@2.0-impl", defaults: ["citsensorserviceImpl_parser_defaults"], proprietary: true, // device_specific: true, relative_install_path: "hw", owner: "xiaomi", cflags: [ "-fexceptions", " -DDISPLAY_PARSE_ALGO_ENABLE", ], include_dirs: [ "vendor/xiaomi/proprietary/sensor/sensorToolKit@2.0/display-parse-algo/include/", // "vendor/xiaomi/proprietary/display/libdisplayfeaturehal/common/v3.0/middm/", "frameworks/native/include", "device/mediatek/common/kernel-headers/linux/", "external/libdrm/include/drm/", "vendor/xiaomi/proprietary/misight", ], srcs: [ "citsensorservice-hidl-impl/src/*.cpp", "custom/common/src/notifierImpl.cpp", "display-parse-algo/src/*.cpp", ], shared_libs: [ "libhidlbase", "libhidltransport", "libutils", "libdl", "liblog", "libcutils", "libhardware", "libbase", "libssccalapi@2.0",//need by ourself //"libsnsapi", "vendor.xiaomi.sensor.citsensorservice@1.1", "vendor.xiaomi.sensor.citsensorservice@2.0", "android.frameworks.sensorservice@1.0", "android.hardware.graphics.allocator@4.0", "android.hardware.graphics.mapper@4.0", "android.hardware.graphics.common@1.2", //"vendor.display.config@2.0", //"libqdutils", // "vendor.qti.hardware.display.composer@3.0", // "vendor.qti.hardware.display.allocator@4.0", // "vendor.qti.hardware.display.mapper@4.0", // "vendor.qti.hardware.display.mapperextensions@1.1", // "libdisplayconfig.qti", "libtinyxml2", "libjsoncpp", "libdrm", "libbinder", "libui", "libcomposer_ext", "libmisight", ], static_libs: [ "android.hardware.sensors@1.0-convert", ], header_libs: [ // "vendor_common_inc", // "libsensorlog_headers", // "libssc_headers", // "libsensor_cal_headers@2.0", "libssccalapi_headers@2.0", "libandroid_sensor_headers", "citsensorservice_headers@2.0", // "qti_display_kernel_headers", //"display_intf_headers", // "mtk_drm_headers", ], } 怎么单编custom.go
07-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值