我正在尝试将linux内核驱动程序添加到android源代码中。
我将它添加到要构建的配置文件中(kernel / msm-4.9 / arch / arm64 / config / sdm845_defconfig)。
CONFIG_LEDS_QPNP_WLED=y
# CONFIG_LEDS_QPNP_HAPTICS is not set
CONFIG_HAPTICS_MISC=y
kernel / msm-4.9 / drivers / misc /中的makefile和Kconfig文件也会更新以包含驱动程序。
Makefile文件:
haptics-misc-objs := haptics-misc.o hatpics-misc-tables.o
obj-$(CONFIG_HAPTICS_MISC) += haptics-misc.o
的Kconfig:
config HAPTICS_MISC
tristate "Haptics driver"
depends on I2C && SYSFS && NEW_LEDS
help
Boosted Haptics Driver
我尝试使用以下步骤构建内核:
$ source build/envsetup.sh
$ lunch 41
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=8.1.0
TARGET_PRODUCT=sdm845
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_PLATFORM_VERSION=OPM1
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=kryo300
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=cortex-a9
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.15.0-24-generic-x86_64-with-Ubuntu-16.04-xenial
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=OPM1.171019.026
OUT_DIR=out
AUX_OS_VARIANT_LIST=
$ make -j12
构建失败,并出现以下错误:
Haptics driver (HAPTICS_MISC) [N/m/y/?] (NEW) aborted!
Console input/output is redirected. Run 'make oldconfig' to update configuration.
/media/ftreven/quarter-b/Open-Q_845_Android-O_v1.0/Source_Package/SDA845_Open-Q_845_Android-O_v1.0/kernel/msm-4.9/scripts/kconfig/Makefile:37: recipe for target 'silentoldconfig' failed
make[3]: *** [silentoldconfig] Error 1
/media/ftreven/quarter-b/Open-Q_845_Android-O_v1.0/Source_Package/SDA845_Open-Q_845_Android-O_v1.0/kernel/msm-4.9/Makefile:550: recipe for target 'silentoldconfig' failed
make[2]: *** [silentoldconfig] Error 2
make[1]: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/kernel.release'. Stop.
make[1]: Leaving directory '/media/ftreven/quarter-b/Open-Q_845_Android-O_v1.0/Source_Package/SDA845_Open-Q_845_Android-O_v1.0/out/target/product/sdm845/obj/kernel/msm-4.9'
Makefile:150: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2
从错误消息看来,命令仅因为符号是新的而失败。它建议使用oldconfig,但这也会失败:
$ make oldconfig
ninja: error: unknown target 'oldconfig', did you mean 'fmconfig'?
13:08:18 ninja failed with: exit status 1
#### failed to build some targets (38 seconds) ####
我不确定“fmconfig”是什么,但我尝试按照建议构建它并且它成功了。但是,尝试构建整个内核失败的原因与上述相同。知道是什么原因引起的吗?它是在添加新符号之前成功构建的。
我发现Linux内核版本4.9发布后,android框架停止允许内置驱动程序。为了解决这个问题,我不得不将驱动程序构建为动态可加载内核模块。为此,我在vendor / called dlkm /下创建了一个目录,其中我放置了所有源代码和configs / Makefile。
完成此操作后,我可以成功构建源代码。
$ source build/envsetup.sh
$ lunch 41
$ make -j12
#### build completed successfully (03:38 (mm:ss)) ###
在android框架的实际内核部分中不能引用驱动程序,否则构建将失败。例外情况是设备树(.dtsi,.dts文件)仍将在内核中构建。