-
Notifications
You must be signed in to change notification settings - Fork 21
/
AndroidKernelModule.mk
189 lines (167 loc) · 7.94 KB
/
AndroidKernelModule.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
ifeq ($(call is-board-platform-in-list,taro kalama parrot), true)
ifneq (,$(findstring $(LOCAL_MODULE),$(BOARD_VENDOR_KERNEL_MODULES)))
#Taro and beyond are using a new mechanisim to build kernel modules
include device/qcom/common/dlkm/Build_external_kernelmodule.mk
endif
else
ifneq (,$(findstring gki,$(KERNEL_DEFCONFIG)))
#GKI product should use Qcom latest dlkm compile file
include device/qcom/common/dlkm/AndroidKernelModule.mk
else
DISABLE_THIS_DLKM := $(strip $(TARGET_KERNEL_DLKM_DISABLE))
ifeq ($(DISABLE_THIS_DLKM),true)
ifneq (,$(filter $(LOCAL_MODULE),$(TARGET_KERNEL_DLKM_OVERRIDE)))
DISABLE_THIS_DLKM = false
else
endif
endif
ifeq ($(DISABLE_THIS_DLKM),true)
$(warning DLKM '$(LOCAL_MODULE)' disabled for target)
else
# Assign external kernel modules to the DLKM class
LOCAL_MODULE_CLASS := DLKM
# Set the default install path to vendor/lib/modules
LOCAL_MODULE_PATH := $(strip $(LOCAL_MODULE_PATH))
ifeq ($(LOCAL_MODULE_PATH),)
LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/lib/modules
endif
# Set the default Kbuild file path to LOCAL_PATH
KBUILD_FILE := $(strip $(KBUILD_FILE))
ifeq ($(KBUILD_FILE),)
KBUILD_FILE := $(LOCAL_PATH)/Kbuild
endif
# Get rid of any whitespace
LOCAL_MODULE_KBUILD_NAME := $(strip $(LOCAL_MODULE_KBUILD_NAME))
include $(BUILD_SYSTEM)/base_rules.mk
# The kernel build system doesn't support parallel kernel module builds
# that share the same output directory. Thus, in order to build multiple
# kernel modules that reside in a single directory (and therefore have
# the same output directory), there must be just one invocation of the
# kernel build system that builds all the modules of a given directory.
#
# Therefore, all kernel modules must depend on the same, unique target
# that invokes the kernel build system and builds all of the modules
# for the directory. The $(KBUILD_TARGET) target serves this purpose.
# To ensure the value of KBUILD_TARGET is unique, it is essentially set
# to the path of the source directory, i.e. LOCAL_PATH.
#
# Since KBUILD_TARGET is used as a target and a variable name, it should
# not contain characters other than letters, numbers, and underscores.
KBUILD_TARGET := $(strip \
$(subst .,_, \
$(subst -,_, \
$(subst :,_, \
$(subst /,_,$(LOCAL_PATH))))))
# Intermediate directory where the kernel modules are created
# by the kernel build system. Ideally this would be the same
# directory as LOCAL_BUILT_MODULE, but because we're using
# relative paths for both O= and M=, we don't have much choice
KBUILD_OUT_DIR := $(TARGET_OUT_INTERMEDIATES)/$(LOCAL_PATH)
# Path to the intermediate location where the kernel build
# system creates the kernel module.
KBUILD_MODULE := $(KBUILD_OUT_DIR)/$(LOCAL_MODULE)
# Since we only invoke the kernel build system once per directory,
# each kernel module must depend on the same target.
$(KBUILD_MODULE): kbuild_out := $(KBUILD_OUT_DIR)/$(LOCAL_MODULE_KBUILD_NAME)
$(KBUILD_MODULE): $(KBUILD_TARGET)
ifneq "$(LOCAL_MODULE_KBUILD_NAME)" ""
mv -f $(kbuild_out) $@
endif
# To ensure KERNEL_OUT and TARGET_PREBUILT_INT_KERNEL are defined,
# kernel/AndroidKernel.mk (kernel_definitions.mk) must be included. While m and regular
# make builds will include kernel/AndroidKernel.mk, mm and mmm builds
# do not. Therefore, we need to explicitly include kernel/AndroidKernel.mk (kernel_definitions.mk).
# It is safe to include it more than once because the entire file is
# guarded by "ifeq ($(TARGET_PREBUILT_KERNEL),) ... endif".
# If AndroidKernel.mk is not found, fall back to use the kernel_definitions.mk
ifneq ($(wildcard $(TARGET_KERNEL_SOURCE)/AndroidKernel.mk),)
TARGET_KERNEL_PATH := $(TARGET_KERNEL_SOURCE)/AndroidKernel.mk
else
TARGET_KERNEL_PATH := device/qcom/kernelscripts/kernel_definitions.mk
endif
include $(TARGET_KERNEL_PATH)
# Simply copy the kernel module from where the kernel build system
# created it to the location where the Android build system expects it.
# If LOCAL_MODULE_DEBUG_ENABLE is set, strip debug symbols. So that,
# the final images generated by ABS will have the stripped version of
# the modules
ifeq ($(TARGET_KERNEL_VERSION),3.18)
MODULE_SIGN_FILE := perl ./$(TARGET_KERNEL_SOURCE)/scripts/sign-file
MODSECKEY := $(KERNEL_OUT)/signing_key.priv
MODPUBKEY := $(KERNEL_OUT)/signing_key.x509
else
MODULE_SIGN_FILE := $(KERNEL_OUT)/scripts/sign-file
MODSECKEY := $(KERNEL_OUT)/certs/signing_key.pem
MODPUBKEY := $(KERNEL_OUT)/certs/signing_key.x509
endif
$(LOCAL_BUILT_MODULE): $(KBUILD_MODULE) | $(ACP)
ifneq "$(LOCAL_MODULE_DEBUG_ENABLE)" ""
mkdir -p $(dir $@)
cp $< $<.unstripped
$(TARGET_STRIP) --strip-debug $<
cp $< $<.stripped
endif
@sh -c "\
KMOD_SIG_ALL=`cat $(KERNEL_OUT)/.config | grep CONFIG_MODULE_SIG_ALL | cut -d'=' -f2`; \
KMOD_SIG_HASH=`cat $(KERNEL_OUT)/.config | grep CONFIG_MODULE_SIG_HASH | cut -d'=' -f2 | sed 's/\"//g'`; \
if [ \"\$$KMOD_SIG_ALL\" = \"y\" ] && [ -n \"\$$KMOD_SIG_HASH\" ]; then \
echo \"Signing kernel module: \" `basename $<`; \
cp $< $<.unsigned; \
$(MODULE_SIGN_FILE) \$$KMOD_SIG_HASH $(MODSECKEY) $(MODPUBKEY) $<; \
fi; \
"
$(transform-prebuilt-to-target)
# This should really be cleared in build/core/clear-vars.mk, but for
# the time being, we need to clear it ourselves
LOCAL_MODULE_KBUILD_NAME :=
LOCAL_MODULE_DEBUG_ENABLE :=
# Ensure the kernel module created by the kernel build system, as
# well as all the other intermediate files, are removed during a clean.
$(cleantarget): PRIVATE_CLEAN_FILES := $(PRIVATE_CLEAN_FILES) $(KBUILD_OUT_DIR)
# Since this file will be included more than once for directories
# with more than one kernel module, the shared KBUILD_TARGET rule should
# only be defined once to avoid "overriding commands ..." warnings.
ifndef $(KBUILD_TARGET)_RULE
$(KBUILD_TARGET)_RULE := 1
# Kernel modules have to be built after:
# * the kernel config has been created
# * host executables, like scripts/basic/fixdep, have been built
# (otherwise parallel invocations of the kernel build system will
# fail as they all try to compile these executables at the same time)
# * a full kernel build (to make module versioning work)
#
# For these reasons, kernel modules are dependent on
# TARGET_PREBUILT_INT_KERNEL which will ensure all of the above.
#
# NOTE: Due to a bug in the kernel build system when using a Kbuild file
# and relative paths for both O= and M=, the Kbuild file must
# be copied to the output directory.
#
# NOTE: The following paths are equivalent:
# $(KBUILD_OUT_DIR)
# $(KERNEL_OUT)/../$(LOCAL_PATH)
.PHONY: $(KBUILD_TARGET)
$(KBUILD_TARGET): local_path := $(LOCAL_PATH)
$(KBUILD_TARGET): kbuild_out_dir := $(KBUILD_OUT_DIR)
$(KBUILD_TARGET): kbuild_options := $(KBUILD_OPTIONS)
ifneq ($(USE_CLANG_FOR_MODULES),)
$(KBUILD_TARGET): $(TARGET_PREBUILT_INT_KERNEL)
@mkdir -p $(kbuild_out_dir)
$(hide) cp -f $(local_path)/Kbuild $(kbuild_out_dir)/Kbuild
$(MAKE) -C $(TARGET_KERNEL_SOURCE) M=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(local_path) O=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(real_cc) $(KERNEL_CFLAGS) modules $(kbuild_options) ANDROID_BUILD_TOP=$$(pwd) TOP=$$(pwd)
else
$(KBUILD_TARGET): $(TARGET_PREBUILT_INT_KERNEL)
@mkdir -p $(kbuild_out_dir)
$(hide) cp -f $(local_path)/Kbuild $(kbuild_out_dir)/Kbuild
$(MAKE) -C $(TARGET_KERNEL_SOURCE) M=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(local_path) O=$(KERNEL_TO_BUILD_ROOT_OFFSET)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) CROSS_COMPILE=$(KERNEL_CROSS_COMPILE) $(KERNEL_CFLAGS) modules $(kbuild_options) TOP=$$(pwd)
endif
# Once the KBUILD_OPTIONS variable has been used for the target
# that's specific to the LOCAL_PATH, clear it. If this isn't done,
# then every kernel module would need to explicitly set KBUILD_OPTIONS,
# or the variable would have to be cleared in 'include $(CLEAR_VARS)'
# which would require a change to build/core.
KBUILD_OPTIONS :=
endif
endif
endif #(findstring gki,$(KERNEL_DEFCONFIG))
endif #(is-board-platform-in-list,taro....)