1# Android makefile for the WLAN Module
2
3# set WLAN_BUILD_DEBUG=y in your environment to enable debug logging
4define wlog
5$(if $(WLAN_BUILD_DEBUG),$(info $(1)))
6endef
7
8define target_is_dual_wlan
9$(strip \
10  $(if $(TARGET_SUPPORT_DUAL_WLAN), \
11     $(if $(findstring cnss2,$(1)),true,), \
12  ) \
13)
14endef
15
16LOCAL_MODULE_DDK_BUILD := false
17LOCAL_MODULE_DDK_ALLOW_UNSAFE_HEADERS := false
18
19ifeq ($(TARGET_BOARD_PLATFORM), sun)
20LOCAL_MODULE_DDK_BUILD := true
21LOCAL_MODULE_DDK_ALLOW_UNSAFE_HEADERS := true
22endif
23ifeq ($(TARGET_BOARD_PLATFORM), pineapple)
24LOCAL_MODULE_DDK_BUILD := true
25LOCAL_MODULE_DDK_ALLOW_UNSAFE_HEADERS := true
26endif
27
28ifeq ($(TARGET_BOARD_PLATFORM), niobe)
29LOCAL_MODULE_DDK_BUILD := true
30LOCAL_MODULE_DDK_ALLOW_UNSAFE_HEADERS := true
31endif
32
33ifeq ($(TARGET_BOARD_PLATFORM), volcano)
34LOCAL_MODULE_DDK_BUILD := true
35LOCAL_MODULE_DDK_ALLOW_UNSAFE_HEADERS := true
36endif
37
38ifeq ($(TARGET_BOARD_PLATFORM),parrot)
39ifeq ($(TARGET_BOARD_SUFFIX),66)
40LOCAL_MODULE_DDK_BUILD := true
41LOCAL_MODULE_DDK_ALLOW_UNSAFE_HEADERS := true
42endif
43endif
44
45LOCAL_PATH := $(call my-dir)
46$(call wlog,LOCAL_PATH=$(LOCAL_PATH))
47BOARD_OPENSOURCE_DIR ?= vendor/qcom/opensource
48
49ENABLE_QCACLD := true
50ifeq ($(TARGET_USES_QMAA), true)
51ifneq ($(TARGET_USES_QMAA_OVERRIDE_WLAN), true)
52ENABLE_QCACLD := false
53else
54ENABLE_QCACLD := true
55endif
56endif
57
58ifeq ($(BOARD_COMMON_DIR),)
59    BOARD_COMMON_DIR := device/qcom/common
60endif
61
62ifeq  ($(ENABLE_QCACLD), true)
63
64# Assume no targets will be supported
65WLAN_CHIPSET :=
66
67ifeq ($(BOARD_HAS_QCOM_WLAN), true)
68
69# Check if this driver needs be built for current target
70ifneq ($(findstring qca_cld3,$(WIFI_DRIVER_BUILT)),)
71	WLAN_CHIPSET := qca_cld3
72	WLAN_SELECT  := CONFIG_QCA_CLD_WLAN=m
73endif
74
75# Build/Package only in case of supported target
76ifneq ($(WLAN_CHIPSET),)
77
78# This makefile is only for DLKM
79ifneq ($(findstring vendor,$(LOCAL_PATH)),)
80
81ifneq ($(findstring opensource,$(LOCAL_PATH)),)
82	WLAN_BLD_DIR := $(BOARD_OPENSOURCE_DIR)/wlan
83endif # opensource
84
85# Multi-ko check
86LOCAL_DEV_NAME := $(patsubst .%,%,\
87	$(lastword $(strip $(subst /, ,$(LOCAL_PATH)))))
88
89$(call wlog,LOCAL_DEV_NAME=$(LOCAL_DEV_NAME))
90$(call wlog,TARGET_WLAN_CHIP=$(TARGET_WLAN_CHIP))
91
92TARGET_WLAN_CHIP ?= wlan
93LOCAL_MULTI_KO := false
94ifneq ($(TARGET_WLAN_CHIP), wlan)
95ifeq ($(LOCAL_DEV_NAME), qcacld-3.0)
96LOCAL_MULTI_KO := true
97endif
98endif
99
100ifeq ($(LOCAL_MULTI_KO), true)
101LOCAL_ANDROID_ROOT := $(shell pwd)
102LOCAL_WLAN_BLD_DIR := $(LOCAL_ANDROID_ROOT)/$(WLAN_BLD_DIR)
103$(shell `find $(LOCAL_WLAN_BLD_DIR)/qcacld-3.0/ -maxdepth 1 -name '.*' ! -name '.git' -delete`)
104
105ifeq ($(LOCAL_MODULE_DDK_BUILD), true)
106ifeq ($(CHIPSET),)
107$(foreach chip, $(TARGET_WLAN_CHIP),\
108	$(eval CHIPSET := $(chip))\
109	$(eval include $(LOCAL_PATH)/Android.mk))
110else
111# DLKM_DIR was moved for JELLY_BEAN (PLATFORM_SDK 16)
112BAZEL_CHIPSET_NAME := $(subst _,-,$(CHIPSET))
113ifeq ($(call is-platform-sdk-version-at-least,16),true)
114        DLKM_DIR := $(TOP)/$(BOARD_COMMON_DIR)/dlkm
115else
116        DLKM_DIR := build/dlkm
117endif # platform-sdk-version
118
119include $(CLEAR_VARS)
120LOCAL_MOD_NAME := wlan
121LOCAL_MODULE              := qca_cld3_$(CHIPSET).ko
122LOCAL_MODULE_KBUILD_NAME  := qca_cld3_$(CHIPSET).ko
123LOCAL_MODULE_DEBUG_ENABLE := true
124LOCAL_MODULE_DDK_SUBTARGET_REGEX := "all.*"
125ifeq ($(PRODUCT_VENDOR_MOVE_ENABLED),true)
126    ifeq ($(WIFI_DRIVER_INSTALL_TO_KERNEL_OUT),true)
127        LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT)
128    else
129        LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/lib/modules/$(WLAN_CHIPSET)
130    endif
131else
132    LOCAL_MODULE_PATH := $(TARGET_OUT)/lib/modules/$(WLAN_CHIPSET)
133endif
134
135
136LOCAL_DEV_NAME := $(CHIPSET)
137LOCAL_CHIP_NAME := $(LOCAL_DEV_NAME)
138TARGET_MAC_BIN_PATH := /mnt/vendor/persist/$(LOCAL_CHIP_NAME)
139TARGET_FW_DIR := firmware/wlan/qca_cld/$(LOCAL_CHIP_NAME)
140TARGET_CFG_PATH := /vendor/etc/wifi/$(LOCAL_CHIP_NAME)
141TARGET_MAC_BIN_PATH := /mnt/vendor/persist/$(LOCAL_CHIP_NAME)
142
143ifeq ($(PRODUCT_VENDOR_MOVE_ENABLED),true)
144TARGET_FW_PATH := $(TARGET_OUT_VENDOR)/$(TARGET_FW_DIR)
145else
146TARGET_FW_PATH := $(TARGET_OUT_ETC)/$(TARGET_FW_DIR)
147endif
148
149# Create wlan_mac.bin symbolic link as part of the module
150$(call symlink-file,,$(TARGET_MAC_BIN_PATH)/wlan_mac.bin,$(TARGET_FW_PATH)/wlan_mac.bin)
151LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_FW_PATH)/wlan_mac.bin
152
153# Conditionally create module symbolic link
154ifneq ($(findstring $(WLAN_CHIPSET),$(WIFI_DRIVER_DEFAULT)),)
155ifeq ($(PRODUCT_VENDOR_MOVE_ENABLED),true)
156ifneq ($(WIFI_DRIVER_INSTALL_TO_KERNEL_OUT),true)
157$(call symlink-file,,$(TARGET_COPY_OUT_VENDOR)/lib/modules/$(WLAN_CHIPSET)/$(LOCAL_MODULE),$(TARGET_OUT_VENDOR)/lib/modules/$(LOCAL_MODULE))
158LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT_VENDOR)/lib/modules/$(LOCAL_MODULE)
159endif
160else
161$(call symlink-file,,/system/lib/modules/$(WLAN_CHIPSET)/$(LOCAL_MODULE),$(TARGET_OUT)/lib/modules/$(LOCAL_MODULE))
162LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT)/lib/modules/$(LOCAL_MODULE)
163endif
164endif
165
166# Conditionally create ini symbolic link
167ifeq ($(TARGET_BOARD_AUTO),true)
168$(call symlink-file,,$(TARGET_CFG_PATH)/WCNSS_qcom_cfg.ini,$(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini)
169LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini
170$(call wlog,"generate soft link because TARGET_BOARD_AUTO true")
171else
172ifneq ($(GENERIC_ODM_IMAGE),true)
173$(call symlink-file,,$(TARGET_CFG_PATH)/WCNSS_qcom_cfg.ini,$(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini)
174LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini
175$(call wlog,"generate soft link because GENERIC_ODM_IMAGE not true")
176endif
177endif
178
179# Set dependencies so that CNSS family drivers can be compiled ahead.
180ifneq ($(WLAN_PLATFORM_KBUILD_OPTIONS),)
181LOCAL_REQUIRED_MODULES := wlan-platform-module-symvers
182LOCAL_ADDITIONAL_DEPENDENCIES += $(call intermediates-dir-for,DLKM,wlan-platform-module-symvers)/Module.symvers
183endif
184
185$(call wlog,TARGET_USES_KERNEL_PLATFORM=$(TARGET_USES_KERNEL_PLATFORM))
186ifeq ($(TARGET_USES_KERNEL_PLATFORM),true)
187    include $(DLKM_DIR)/Build_external_kernelmodule.mk
188else
189    include $(DLKM_DIR)/AndroidKernelModule.mk
190endif
191endif
192else
193$(foreach chip, $(TARGET_WLAN_CHIP), \
194	$(shell ln -sf . $(LOCAL_WLAN_BLD_DIR)/qcacld-3.0/.$(chip)))
195include $(foreach chip, $(TARGET_WLAN_CHIP), $(LOCAL_PATH)/.$(chip)/Android.mk)
196endif
197
198else # Multi-ok check
199
200# When dual wlan enabled, secondary dev name would be $(chip)_cnss2.
201# Use LOCAL_CHIP_NAME instead of LOCAL_DEV_NAME for secondary one.
202LOCAL_CHIP_NAME := $(LOCAL_DEV_NAME)
203TARGET_SECONDARY_WLAN := $(call target_is_dual_wlan,$(LOCAL_DEV_NAME))
204ifeq ($(TARGET_SECONDARY_WLAN), true)
205LOCAL_CHIP_NAME := $(patsubst %_cnss2,%,$(strip $(LOCAL_DEV_NAME)))
206endif
207
208ifeq ($(WLAN_PROFILE),)
209WLAN_PROFILE := default
210endif
211
212ifeq ($(LOCAL_DEV_NAME), qcacld-3.0)
213
214LOCAL_DEV_NAME := wlan
215LOCAL_MOD_NAME := wlan
216LOCAL_SRC_DIR :=
217TARGET_FW_DIR := firmware/wlan/qca_cld
218TARGET_CFG_PATH := /vendor/etc/wifi
219TARGET_MAC_BIN_PATH := /mnt/vendor/persist
220
221else
222
223LOCAL_SRC_DIR := .$(LOCAL_DEV_NAME)
224# Use default profile if WLAN_CFG_USE_DEFAULT defined.
225ifeq ($(WLAN_CFG_USE_DEFAULT),)
226WLAN_PROFILE := $(LOCAL_CHIP_NAME)
227endif
228TARGET_FW_DIR := firmware/wlan/qca_cld/$(LOCAL_CHIP_NAME)
229TARGET_CFG_PATH := /vendor/etc/wifi/$(LOCAL_CHIP_NAME)
230TARGET_MAC_BIN_PATH := /mnt/vendor/persist/$(LOCAL_CHIP_NAME)
231
232ifneq ($(TARGET_MULTI_WLAN), true)
233LOCAL_MOD_NAME := wlan
234DYNAMIC_SINGLE_CHIP := $(LOCAL_DEV_NAME)
235else
236LOCAL_MOD_NAME := $(LOCAL_DEV_NAME)
237endif
238
239ifeq ($(TARGET_SECONDARY_WLAN), true)
240TARGET_SECONDARY_WLAN_NUMBER := 2
241LOCAL_MOD_NAME := $(LOCAL_CHIP_NAME)_$(TARGET_SECONDARY_WLAN_NUMBER)
242DYNAMIC_SINGLE_CHIP := $(LOCAL_CHIP_NAME)
243endif
244
245endif
246
247# DLKM_DIR was moved for JELLY_BEAN (PLATFORM_SDK 16)
248ifeq ($(call is-platform-sdk-version-at-least,16),true)
249	DLKM_DIR := $(TOP)/$(BOARD_COMMON_DIR)/dlkm
250else
251	DLKM_DIR := build/dlkm
252endif # platform-sdk-version
253
254# Build wlan.ko as $(WLAN_CHIPSET)_wlan.ko
255###########################################################
256# This is set once per LOCAL_PATH, not per (kernel) module
257KBUILD_OPTIONS := WLAN_ROOT=$(WLAN_BLD_DIR)/qcacld-3.0/$(LOCAL_SRC_DIR)
258KBUILD_OPTIONS += WLAN_COMMON_ROOT=cmn
259KBUILD_OPTIONS += WLAN_COMMON_INC=$(WLAN_BLD_DIR)/qcacld-3.0/cmn
260KBUILD_OPTIONS += WLAN_FW_API=$(WLAN_BLD_DIR)/fw-api
261KBUILD_OPTIONS += WLAN_PROFILE=$(WLAN_PROFILE)
262KBUILD_OPTIONS += DYNAMIC_SINGLE_CHIP=$(DYNAMIC_SINGLE_CHIP)
263
264# We are actually building wlan.ko here, as per the
265# requirement we are specifying <chipset>_wlan.ko as LOCAL_MODULE.
266# This means we need to rename the module to <chipset>_wlan.ko
267# after wlan.ko is built.
268KBUILD_OPTIONS += MODNAME=$(LOCAL_MOD_NAME)
269KBUILD_OPTIONS += DEVNAME=$(LOCAL_DEV_NAME)
270KBUILD_OPTIONS += BOARD_PLATFORM=$(TARGET_BOARD_PLATFORM)
271KBUILD_OPTIONS += $(WLAN_SELECT)
272
273KBUILD_REQUIRED_KOS := ipam.ko
274
275ifneq ($(WLAN_CFG_OVERRIDE_$(LOCAL_DEV_NAME)),)
276KBUILD_OPTIONS += WLAN_CFG_OVERRIDE="$(WLAN_CFG_OVERRIDE_$(LOCAL_DEV_NAME))"
277endif
278
279# driver expects "/dev/<name>" for wifi driver state ctrl parameter.
280# i.e. WIFI_DRIVER_STATE_CTRL_PARAM="/dev/wlan" is defined for single wlan.
281# WIFI_DRIVER_STATE_CTRL_PARAM_SECONDARY="/dev/wlan2" is defined for 2nd wlan.
282ifeq ($(TARGET_SECONDARY_WLAN), true)
283$(call wlog,STATE_CTRL_PARAM_SECONDARY=$(WIFI_DRIVER_STATE_CTRL_PARAM_SECONDARY))
284PARAM_SECONDARY := $(patsubst "%",%,$(WIFI_DRIVER_STATE_CTRL_PARAM_SECONDARY))
285$(call wlog,PARAM_SECONDARY=$(PARAM_SECONDARY))
286ifeq ($(dir $(PARAM_SECONDARY)),/dev/)
287KBUILD_OPTIONS += WLAN_CTRL_NAME=$(notdir $(PARAM_SECONDARY))
288endif
289else
290$(call wlog,WIFI_DRIVER_STATE_CTRL_PARAM=$(WIFI_DRIVER_STATE_CTRL_PARAM))
291PARAM := $(patsubst "%",%,$(WIFI_DRIVER_STATE_CTRL_PARAM))
292$(call wlog,PARAM=$(PARAM))
293ifeq ($(dir $(PARAM)),/dev/)
294KBUILD_OPTIONS += WLAN_CTRL_NAME=$(notdir $(PARAM))
295endif
296endif
297
298# Pass build options per chip to Kbuild. This will be injected from upper layer
299# makefile.
300#
301# e.g.
302#  WLAN_KBUILD_OPTIONS_qca6390 := CONFIG_CNSS_QCA6390=y
303ifneq ($(WLAN_KBUILD_OPTIONS_$(LOCAL_DEV_NAME)),)
304KBUILD_OPTIONS += "$(WLAN_KBUILD_OPTIONS_$(LOCAL_DEV_NAME))"
305endif
306
307ifeq ($(PRODUCT_VENDOR_MOVE_ENABLED),true)
308TARGET_FW_PATH := $(TARGET_OUT_VENDOR)/$(TARGET_FW_DIR)
309else
310TARGET_FW_PATH := $(TARGET_OUT_ETC)/$(TARGET_FW_DIR)
311endif
312
313# WLAN_PLATFORM_KBUILD_OPTIONS should be passed from upper level Makefiles
314# like wlan.mk. It indicates sources of CNSS family drivers (cnss2, cnss_nl,
315# cnss_prealloc and cnss_utils etc.) are built out of kernel tree and it
316# should also include all necessary config flags (e.g. CONFIG_CNSS2) which
317# are originally defined from kernel Kconfig/defconfig. KBUILD_EXTRA_SYMBOLS
318# is also needed to indicate all the symbols from these drivers.
319ifneq ($(WLAN_PLATFORM_KBUILD_OPTIONS),)
320KBUILD_OPTIONS += $(foreach wlan_platform_kbuild_option, \
321		   $(WLAN_PLATFORM_KBUILD_OPTIONS), \
322		   $(wlan_platform_kbuild_option))
323
324KBUILD_OPTIONS += KBUILD_EXTRA_SYMBOLS+=$(shell pwd)/$(call intermediates-dir-for,DLKM,wlan-platform-module-symvers)/Module.symvers
325endif
326
327include $(CLEAR_VARS)
328
329# Create the module
330LOCAL_MODULE              := $(WLAN_CHIPSET)_$(LOCAL_DEV_NAME).ko
331LOCAL_MODULE_KBUILD_NAME  := $(LOCAL_MOD_NAME).ko
332LOCAL_MODULE_DEBUG_ENABLE := true
333ifeq ($(PRODUCT_VENDOR_MOVE_ENABLED),true)
334    ifeq ($(WIFI_DRIVER_INSTALL_TO_KERNEL_OUT),true)
335        LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT)
336    else
337        LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR)/lib/modules/$(WLAN_CHIPSET)
338    endif
339else
340    LOCAL_MODULE_PATH := $(TARGET_OUT)/lib/modules/$(WLAN_CHIPSET)
341endif
342
343# Create wlan_mac.bin symbolic link as part of the module
344$(call symlink-file,,$(TARGET_MAC_BIN_PATH)/wlan_mac.bin,$(TARGET_FW_PATH)/wlan_mac.bin)
345LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_FW_PATH)/wlan_mac.bin
346
347# Conditionally create module symbolic link
348ifneq ($(findstring $(WLAN_CHIPSET),$(WIFI_DRIVER_DEFAULT)),)
349ifeq ($(PRODUCT_VENDOR_MOVE_ENABLED),true)
350ifneq ($(WIFI_DRIVER_INSTALL_TO_KERNEL_OUT),true)
351$(call symlink-file,,$(TARGET_COPY_OUT_VENDOR)/lib/modules/$(WLAN_CHIPSET)/$(LOCAL_MODULE),$(TARGET_OUT_VENDOR)/lib/modules/$(LOCAL_MODULE))
352LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT_VENDOR)/lib/modules/$(LOCAL_MODULE)
353endif
354else
355$(call symlink-file,,/system/lib/modules/$(WLAN_CHIPSET)/$(LOCAL_MODULE),$(TARGET_OUT)/lib/modules/$(LOCAL_MODULE))
356LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_OUT)/lib/modules/$(LOCAL_MODULE)
357endif
358endif
359
360# Conditionally create ini symbolic link
361ifeq ($(TARGET_BOARD_AUTO),true)
362$(call symlink-file,,$(TARGET_CFG_PATH)/WCNSS_qcom_cfg.ini,$(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini)
363LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini
364$(call wlog,"generate soft link because TARGET_BOARD_AUTO true")
365else
366ifneq ($(GENERIC_ODM_IMAGE),true)
367$(call symlink-file,,$(TARGET_CFG_PATH)/WCNSS_qcom_cfg.ini,$(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini)
368LOCAL_ADDITIONAL_DEPENDENCIES += $(TARGET_FW_PATH)/WCNSS_qcom_cfg.ini
369$(call wlog,"generate soft link because GENERIC_ODM_IMAGE not true")
370endif
371endif
372
373# Set dependencies so that CNSS family drivers can be compiled ahead.
374ifneq ($(WLAN_PLATFORM_KBUILD_OPTIONS),)
375LOCAL_REQUIRED_MODULES := wlan-platform-module-symvers
376LOCAL_ADDITIONAL_DEPENDENCIES += $(call intermediates-dir-for,DLKM,wlan-platform-module-symvers)/Module.symvers
377endif
378
379$(call wlog,TARGET_USES_KERNEL_PLATFORM=$(TARGET_USES_KERNEL_PLATFORM))
380ifeq ($(TARGET_USES_KERNEL_PLATFORM),true)
381    include $(DLKM_DIR)/Build_external_kernelmodule.mk
382else
383    include $(DLKM_DIR)/AndroidKernelModule.mk
384endif
385
386endif # Multi-ko check
387endif # DLKM check
388endif # supported target check
389endif # WLAN enabled check
390endif # ENABLE_QCACLD
391