blob: 4d23c33423294def45a1a2e8b3be83114a39ac19 [file] [log] [blame]
Michael Bestas3952f6c2016-08-26 01:12:08 +03001# Copyright (C) 2012 The CyanogenMod Project
Dan Pasanen03447712016-12-19 11:22:55 -06002# (C) 2017 The LineageOS Project
Michael Bestas3952f6c2016-08-26 01:12:08 +03003#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17# Android makefile to build kernel as a part of Android Build
18#
19# Configuration
20# =============
21#
22# These config vars are usually set in BoardConfig.mk:
23#
24# TARGET_KERNEL_SOURCE = Kernel source dir, optional, defaults
25# to kernel/$(TARGET_DEVICE_DIR)
26# TARGET_KERNEL_CONFIG = Kernel defconfig
27# TARGET_KERNEL_VARIANT_CONFIG = Variant defconfig, optional
28# TARGET_KERNEL_SELINUX_CONFIG = SELinux defconfig, optional
29# TARGET_KERNEL_ADDITIONAL_CONFIG = Additional defconfig, optional
30# TARGET_KERNEL_ARCH = Kernel Arch
Michael Bestas3952f6c2016-08-26 01:12:08 +030031# TARGET_KERNEL_CROSS_COMPILE_PREFIX = Compiler prefix (e.g. arm-eabi-)
Michael Bestas1d55ece2016-09-28 20:16:25 +030032# defaults to arm-linux-androidkernel- for arm
33# aarch64-linux-androidkernel- for arm64
34# x86_64-linux-androidkernel- for x86
Michael Bestas3952f6c2016-08-26 01:12:08 +030035#
Joe Maplesda328952017-11-27 10:09:38 -050036# TARGET_KERNEL_CLANG_COMPILE = Compile kernel with clang, defaults to false
37#
38# TARGET_KERNEL_CLANG_VERSION = Clang prebuilts version, optional, defaults to clang-stable
39#
40# TARGET_KERNEL_CLANG_PATH = Clang prebuilts path, optional
41#
Dan Pasanenedc1ceb2017-01-24 15:46:13 -060042# BOARD_KERNEL_IMAGE_NAME = Built image name
43# for ARM use: zImage
44# for ARM64 use: Image.gz
45# for uncompressed use: Image
46# If using an appended DT, append '-dtb'
47# to the end of the image name.
48# For example, for ARM devices,
49# use zImage-dtb instead of zImage.
Michael Bestas3952f6c2016-08-26 01:12:08 +030050#
51# KERNEL_TOOLCHAIN_PREFIX = Overrides TARGET_KERNEL_CROSS_COMPILE_PREFIX,
52# Set this var in shell to override
53# toolchain specified in BoardConfig.mk
54# KERNEL_TOOLCHAIN = Path to toolchain, if unset, assumes
55# TARGET_KERNEL_CROSS_COMPILE_PREFIX
56# is in PATH
Joe Maplesda328952017-11-27 10:09:38 -050057#
58# KERNEL_CC = The C Compiler used. This is automatically set based
59# on whether the clang version is set, optional.
60#
61# KERNEL_CLANG_TRIPLE = Target triple for clang (e.g. aarch64-linux-gnu-)
62# defaults to arm-linux-gnu- for arm
63# aarch64-linux-gnu- for arm64
64# x86_64-linux-gnu- for x86
65#
Michael Bestas3952f6c2016-08-26 01:12:08 +030066# USE_CCACHE = Enable ccache (global Android flag)
67#
68# NEED_KERNEL_MODULE_ROOT = Optional, if true, install kernel
69# modules in root instead of system
70
Dan Pasanen8ee5d892017-12-08 13:46:30 -060071ifneq ($(TARGET_NO_KERNEL),true)
Michael Bestas3952f6c2016-08-26 01:12:08 +030072
73TARGET_AUTO_KDIR := $(shell echo $(TARGET_DEVICE_DIR) | sed -e 's/^device/kernel/g')
74
75## Externally influenced variables
76# kernel location - optional, defaults to kernel/<vendor>/<device>
77TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR)
78KERNEL_SRC := $(TARGET_KERNEL_SOURCE)
79# kernel configuration - mandatory
80KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG)
81VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG)
82SELINUX_DEFCONFIG := $(TARGET_KERNEL_SELINUX_CONFIG)
83
84## Internal variables
85KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ
86KERNEL_CONFIG := $(KERNEL_OUT)/.config
Michael Bestas3952f6c2016-08-26 01:12:08 +030087
88TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH))
89ifeq ($(TARGET_KERNEL_ARCH),)
90KERNEL_ARCH := $(TARGET_ARCH)
91else
92KERNEL_ARCH := $(TARGET_KERNEL_ARCH)
93endif
94
95ifeq ($(KERNEL_ARCH),x86_64)
96KERNEL_DEFCONFIG_ARCH := x86
97else
98KERNEL_DEFCONFIG_ARCH := $(KERNEL_ARCH)
99endif
100KERNEL_DEFCONFIG_SRC := $(KERNEL_SRC)/arch/$(KERNEL_DEFCONFIG_ARCH)/configs/$(KERNEL_DEFCONFIG)
101
Dan Pasanenedc1ceb2017-01-24 15:46:13 -0600102ifeq ($(BOARD_KERNEL_IMAGE_NAME),)
103$(error BOARD_KERNEL_IMAGE_NAME not defined.)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300104endif
Dan Pasanenedc1ceb2017-01-24 15:46:13 -0600105ifneq ($(TARGET_USES_UNCOMPRESSED_KERNEL),)
106$(error TARGET_USES_UNCOMPRESSED_KERNEL is deprecated.)
107endif
108ifneq ($(TARGET_KERNEL_APPEND_DTB),)
109$(error TARGET_KERNEL_APPEND_DTB is deprecated.)
110endif
111TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/$(BOARD_KERNEL_IMAGE_NAME)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300112
113# Clear this first to prevent accidental poisoning from env
114MAKE_FLAGS :=
115
Ziyan54648c22017-01-12 18:47:54 +0100116ifeq ($(KERNEL_ARCH),arm)
117 # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors
118 MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
119endif
120
Michael Bestas3952f6c2016-08-26 01:12:08 +0300121ifeq ($(KERNEL_ARCH),arm64)
122 # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE)
123 MAKE_FLAGS += CFLAGS_MODULE="-fno-pic"
Michael Bestas3952f6c2016-08-26 01:12:08 +0300124endif
125
126ifneq ($(TARGET_KERNEL_ADDITIONAL_CONFIG),)
127KERNEL_ADDITIONAL_CONFIG := $(TARGET_KERNEL_ADDITIONAL_CONFIG)
128KERNEL_ADDITIONAL_CONFIG_SRC := $(KERNEL_SRC)/arch/$(KERNEL_ARCH)/configs/$(KERNEL_ADDITIONAL_CONFIG)
129 ifeq ("$(wildcard $(KERNEL_ADDITIONAL_CONFIG_SRC))","")
130 $(warning TARGET_KERNEL_ADDITIONAL_CONFIG '$(TARGET_KERNEL_ADDITIONAL_CONFIG)' doesn't exist)
131 KERNEL_ADDITIONAL_CONFIG_SRC := /dev/null
132 endif
133else
134 KERNEL_ADDITIONAL_CONFIG_SRC := /dev/null
135endif
136
Michael Bestas3952f6c2016-08-26 01:12:08 +0300137ifeq "$(wildcard $(KERNEL_SRC) )" ""
138 ifneq ($(TARGET_PREBUILT_KERNEL),)
139 HAS_PREBUILT_KERNEL := true
140 NEEDS_KERNEL_COPY := true
141 else
142 $(foreach cf,$(PRODUCT_COPY_FILES), \
143 $(eval _src := $(call word-colon,1,$(cf))) \
144 $(eval _dest := $(call word-colon,2,$(cf))) \
145 $(ifeq kernel,$(_dest), \
146 $(eval HAS_PREBUILT_KERNEL := true)))
147 endif
148
149 ifneq ($(HAS_PREBUILT_KERNEL),)
150 $(warning ***************************************************************)
151 $(warning * Using prebuilt kernel binary instead of source *)
152 $(warning * THIS IS DEPRECATED, AND WILL BE DISCONTINUED *)
153 $(warning * Please configure your device to download the kernel *)
154 $(warning * source repository to $(KERNEL_SRC))
Michael Bestas3952f6c2016-08-26 01:12:08 +0300155 $(warning * for more information *)
156 $(warning ***************************************************************)
157 FULL_KERNEL_BUILD := false
158 KERNEL_BIN := $(TARGET_PREBUILT_KERNEL)
159 else
160 $(warning ***************************************************************)
161 $(warning * *)
162 $(warning * No kernel source found, and no fallback prebuilt defined. *)
163 $(warning * Please make sure your device is properly configured to *)
164 $(warning * download the kernel repository to $(KERNEL_SRC))
165 $(warning * and add the TARGET_KERNEL_CONFIG variable to BoardConfig.mk *)
166 $(warning * *)
167 $(warning * As an alternative, define the TARGET_PREBUILT_KERNEL *)
168 $(warning * variable with the path to the prebuilt binary kernel image *)
169 $(warning * in your BoardConfig.mk file *)
170 $(warning * *)
171 $(warning ***************************************************************)
172 $(error "NO KERNEL")
173 endif
174else
175 NEEDS_KERNEL_COPY := true
176 ifeq ($(TARGET_KERNEL_CONFIG),)
177 $(warning **********************************************************)
178 $(warning * Kernel source found, but no configuration was defined *)
179 $(warning * Please add the TARGET_KERNEL_CONFIG variable to your *)
180 $(warning * BoardConfig.mk file *)
181 $(warning **********************************************************)
182 # $(error "NO KERNEL CONFIG")
183 else
184 #$(info Kernel source found, building it)
185 FULL_KERNEL_BUILD := true
186 KERNEL_BIN := $(TARGET_PREBUILT_INT_KERNEL)
187 endif
188endif
189
190ifeq ($(FULL_KERNEL_BUILD),true)
191
Tom Marshall6b83d832017-11-09 21:02:33 +0100192KERNEL_HEADERS_INSTALL_DIR := $(KERNEL_OUT)/usr
193KERNEL_HEADERS_INSTALL_DEPS := $(KERNEL_OUT)/.headers_install_deps
Michael Bestas3952f6c2016-08-26 01:12:08 +0300194
195ifeq ($(NEED_KERNEL_MODULE_ROOT),true)
196KERNEL_MODULES_INSTALL := root
197KERNEL_MODULES_OUT := $(TARGET_ROOT_OUT)/lib/modules
Ethan Chenbf38db22017-12-03 23:59:48 -0800198KERNEL_DEPMOD_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_recovery)
199KERNEL_MODULE_MOUNTPOINT :=
Michael Bestas3952f6c2016-08-26 01:12:08 +0300200else
Ethan Chenbf38db22017-12-03 23:59:48 -0800201KERNEL_MODULES_INSTALL := $(TARGET_COPY_OUT_VENDOR)
202KERNEL_MODULES_OUT := $(TARGET_OUT_VENDOR)/lib/modules
203KERNEL_DEPMOD_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_vendor)
204KERNEL_MODULE_MOUNTPOINT := vendor
Michael Bestas3952f6c2016-08-26 01:12:08 +0300205endif
206
207TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX))
208ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),)
209KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)
Zhao Wei Liew9689bb92016-11-10 20:02:58 +0800210else ifeq ($(KERNEL_ARCH),arm64)
Michael Bestas1d55ece2016-09-28 20:16:25 +0300211KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-androidkernel-
Zhao Wei Liew9689bb92016-11-10 20:02:58 +0800212else ifeq ($(KERNEL_ARCH),arm)
Michael Bestas1d55ece2016-09-28 20:16:25 +0300213KERNEL_TOOLCHAIN_PREFIX ?= arm-linux-androidkernel-
Zhao Wei Liew9689bb92016-11-10 20:02:58 +0800214else ifeq ($(KERNEL_ARCH),x86)
Michael Bestas1d55ece2016-09-28 20:16:25 +0300215KERNEL_TOOLCHAIN_PREFIX ?= x86_64-linux-androidkernel-
Michael Bestas3952f6c2016-08-26 01:12:08 +0300216endif
217
218ifeq ($(KERNEL_TOOLCHAIN),)
219KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX)
220else
221ifneq ($(KERNEL_TOOLCHAIN_PREFIX),)
222KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX)
223endif
224endif
225
Joe Maplesda328952017-11-27 10:09:38 -0500226ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
227 ifneq ($(TARGET_KERNEL_CLANG_VERSION),)
228 # Find the clang-* directory containing the specified version
229 KERNEL_CLANG_VERSION := $(shell find $(ANDROID_BUILD_TOP)/prebuilts/clang/host/$(HOST_OS)-x86/ -name AndroidVersion.txt -exec grep -l $(TARGET_KERNEL_CLANG_VERSION) "{}" \; | sed -e 's|/AndroidVersion.txt$$||g;s|^.*/||g')
230 else
Nathan Chancellorca403312018-04-11 16:23:19 -0700231 # Use the default version of clang if TARGET_KERNEL_CLANG_VERSION hasn't been set by the device config
232 KERNEL_CLANG_VERSION := $(LLVM_PREBUILTS_VERSION)
Joe Maplesda328952017-11-27 10:09:38 -0500233 endif
234 TARGET_KERNEL_CLANG_PATH ?= $(ANDROID_BUILD_TOP)/prebuilts/clang/host/$(HOST_OS)-x86/$(KERNEL_CLANG_VERSION)/bin
235 ifeq ($(KERNEL_ARCH),arm64)
236 KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=aarch64-linux-gnu-
237 else ifeq ($(KERNEL_ARCH),arm)
238 KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=arm-linux-gnu-
239 else ifeq ($(KERNEL_ARCH),x86)
240 KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=x86_64-linux-gnu-
241 endif
242endif
243
Michael Bestas3952f6c2016-08-26 01:12:08 +0300244ifneq ($(USE_CCACHE),)
Steve Kondik6a378282016-09-25 22:37:01 -0700245 # Detect if the system already has ccache installed to use instead of the prebuilt
246 ccache := $(shell which ccache)
247
248 ifeq ($(ccache),)
249 ccache := $(ANDROID_BUILD_TOP)/prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
250 # Check that the executable is here.
251 ccache := $(strip $(wildcard $(ccache)))
252 endif
Michael Bestas3952f6c2016-08-26 01:12:08 +0300253endif
254
Joe Maplesda328952017-11-27 10:09:38 -0500255ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true)
256 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)"
Dan Pasanenf65a6df2018-02-18 22:13:05 -0600257 ifeq ($(KERNEL_CC),)
258 KERNEL_CC := CC="$(ccache) $(TARGET_KERNEL_CLANG_PATH)/clang"
259 endif
Joe Maplesda328952017-11-27 10:09:38 -0500260else
261 KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(ccache) $(KERNEL_TOOLCHAIN_PATH)"
262endif
Michael Bestas3952f6c2016-08-26 01:12:08 +0300263ccache =
264
Michael Bestas3952f6c2016-08-26 01:12:08 +0300265ifeq ($(HOST_OS),darwin)
Christopher N. Hesse1e7c3f02017-04-12 00:57:44 +0200266 MAKE_FLAGS += C_INCLUDE_PATH=$(ANDROID_BUILD_TOP)/external/elfutils/libelf:/usr/local/opt/openssl/include
Rashed Abdel-Tawab7fb92512017-03-16 14:37:07 -0400267 MAKE_FLAGS += LIBRARY_PATH=/usr/local/opt/openssl/lib
Michael Bestas3952f6c2016-08-26 01:12:08 +0300268endif
269
270ifeq ($(TARGET_KERNEL_MODULES),)
Tom Marshallf15c3712017-11-10 01:00:18 +0100271 TARGET_KERNEL_MODULES := INSTALLED_KERNEL_MODULES
Michael Bestas3952f6c2016-08-26 01:12:08 +0300272endif
273
Michael Bestas3952f6c2016-08-26 01:12:08 +0300274KERNEL_ADDITIONAL_CONFIG_OUT := $(KERNEL_OUT)/.additional_config
275
276.PHONY: force_additional_config
277$(KERNEL_ADDITIONAL_CONFIG_OUT): force_additional_config
278 $(hide) cmp -s $(KERNEL_ADDITIONAL_CONFIG_SRC) $@ || cp $(KERNEL_ADDITIONAL_CONFIG_SRC) $@;
279
Tom Marshall6b83d832017-11-09 21:02:33 +0100280$(KERNEL_CONFIG): $(KERNEL_DEFCONFIG_SRC) $(KERNEL_ADDITIONAL_CONFIG_OUT)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300281 @echo "Building Kernel Config"
Tom Marshall6b83d832017-11-09 21:02:33 +0100282 $(hide) mkdir -p $(KERNEL_OUT)
Joe Maplesda328952017-11-27 10:09:38 -0500283 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(KERNEL_DEFCONFIG)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300284 $(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \
285 echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \
286 echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \
Joe Maplesda328952017-11-27 10:09:38 -0500287 $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) oldconfig; fi
Sam Mortimerb0cecb72016-10-01 09:56:52 -0700288 # Create defconfig build artifact
Joe Maplesda328952017-11-27 10:09:38 -0500289 $(hide) $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) savedefconfig
Michael Bestas3952f6c2016-08-26 01:12:08 +0300290 $(hide) if [ ! -z "$(KERNEL_ADDITIONAL_CONFIG)" ]; then \
291 echo "Using additional config '$(KERNEL_ADDITIONAL_CONFIG)'"; \
292 $(KERNEL_SRC)/scripts/kconfig/merge_config.sh -m -O $(KERNEL_OUT) $(KERNEL_OUT)/.config $(KERNEL_SRC)/arch/$(KERNEL_ARCH)/configs/$(KERNEL_ADDITIONAL_CONFIG); \
Joe Maplesda328952017-11-27 10:09:38 -0500293 $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) KCONFIG_ALLCONFIG=$(KERNEL_OUT)/.config alldefconfig; fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300294
Tom Marshall6b83d832017-11-09 21:02:33 +0100295.PHONY: TARGET_KERNEL_BINARIES
296TARGET_KERNEL_BINARIES: $(KERNEL_CONFIG)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300297 @echo "Building Kernel"
Tom Marshall6b83d832017-11-09 21:02:33 +0100298 $(hide) rm -rf $(KERNEL_MODULES_OUT)
299 $(hide) mkdir -p $(KERNEL_MODULES_OUT)
300 $(hide) rm -rf $(KERNEL_DEPMOD_STAGING_DIR)
Joe Maplesda328952017-11-27 10:09:38 -0500301 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(BOARD_KERNEL_IMAGE_NAME)
Tom Marshallf15c3712017-11-10 01:00:18 +0100302 $(hide) if grep -q '^CONFIG_OF=y' $(KERNEL_CONFIG); then \
303 echo "Building DTBs"; \
Joe Maplesda328952017-11-27 10:09:38 -0500304 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) dtbs; \
Tom Marshallf15c3712017-11-10 01:00:18 +0100305 fi
306 $(hide) if grep -q '^CONFIG_MODULES=y' $(KERNEL_CONFIG); then \
307 echo "Building Kernel Modules"; \
Joe Maplesda328952017-11-27 10:09:38 -0500308 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) modules; \
Tom Marshallf15c3712017-11-10 01:00:18 +0100309 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300310
Tom Marshallf15c3712017-11-10 01:00:18 +0100311.PHONY: INSTALLED_KERNEL_MODULES
Aaron Klinga078a222018-01-12 18:19:27 -0600312INSTALLED_KERNEL_MODULES: depmod-host
Tom Marshallf15c3712017-11-10 01:00:18 +0100313 $(hide) if grep -q '^CONFIG_MODULES=y' $(KERNEL_CONFIG); then \
314 echo "Installing Kernel Modules"; \
Joe Maplesda328952017-11-27 10:09:38 -0500315 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) INSTALL_MOD_PATH=../../$(KERNEL_MODULES_INSTALL) modules_install && \
Tom Marshallf15c3712017-11-10 01:00:18 +0100316 mofile=$$(find $(KERNEL_MODULES_OUT) -type f -name modules.order) && \
317 mpath=$$(dirname $$mofile) && \
318 for f in $$(find $$mpath/kernel -type f -name '*.ko'); do \
319 $(KERNEL_TOOLCHAIN_PATH)strip --strip-unneeded $$f; \
320 mv $$f $(KERNEL_MODULES_OUT); \
321 done && \
Ethan Chenbf38db22017-12-03 23:59:48 -0800322 rm -rf $$mpath && \
323 mkdir -p $(KERNEL_DEPMOD_STAGING_DIR)/lib/modules/0.0/$(KERNEL_MODULE_MOUNTPOINT)/lib/modules && \
324 find $(KERNEL_MODULES_OUT) -name *.ko -exec cp {} $(KERNEL_DEPMOD_STAGING_DIR)/lib/modules/0.0/$(KERNEL_MODULE_MOUNTPOINT)/lib/modules \; && \
325 $(DEPMOD) -b $(KERNEL_DEPMOD_STAGING_DIR) 0.0 && \
326 sed -e 's/\(.*modules.*\):/\/\1:/g' -e 's/ \([^ ]*modules[^ ]*\)/ \/\1/g' $(KERNEL_DEPMOD_STAGING_DIR)/lib/modules/0.0/modules.dep > $(KERNEL_MODULES_OUT)/modules.dep; \
Tom Marshallf15c3712017-11-10 01:00:18 +0100327 fi
Michael Bestas3952f6c2016-08-26 01:12:08 +0300328
329$(TARGET_KERNEL_MODULES): TARGET_KERNEL_BINARIES
330
331$(TARGET_PREBUILT_INT_KERNEL): $(TARGET_KERNEL_MODULES)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300332
Tom Marshall6b83d832017-11-09 21:02:33 +0100333# Install kernel (uapi) headers.
334#
335# The dependency file serves two purposes:
336# - It is a stamp indicating when the headers were last installed.
337# - It contains a rule to regenerate itself when any kernel header
338# files change. This rule is identical to the rule emitted by
339# GCC using the M/MM flags.
340#
341# Note that the location of installed kernel headers changed when the
342# kernel uapi system was introduced in 3.7. Unfortunately, it is not
343# sufficient to test whether the uapi directories exist because some
344# kernels backport patches that contain uapi headers. So we look for
345# the string "version_h" in the kernel makefile which was introduced
346# as a part of the uapi system (commit d183e6f570f3).
347-include $(KERNEL_HEADERS_INSTALL_DEPS)
348$(KERNEL_HEADERS_INSTALL_DEPS):
Michael Bestas3952f6c2016-08-26 01:12:08 +0300349 @echo "Building Kernel Headers"
Tom Marshall6b83d832017-11-09 21:02:33 +0100350 $(hide) mkdir -p $(KERNEL_OUT)
351 $(hide) rm -f $@
352 $(hide) $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) headers_install
353 $(hide) echo "$@: \\" > $@
354 $(hide) ( cd $(KERNEL_SRC); \
355 if grep -q '^version_h' 'Makefile'; then \
356 depdirs="arch/$(KERNEL_ARCH)/include/uapi include/uapi"; \
357 else \
358 depdirs="arch/$(KERNEL_ARCH)/include/asm include"; \
359 fi; \
360 deps="Makefile $$(find $$depdirs -type f -name '*.h')"; \
361 for f in $$deps; do \
362 echo " $(KERNEL_SRC)/$$f \\" >> $@; \
363 done ; \
364 echo "" >> $@ ; \
365 for f in $$deps; do \
366 echo "$(KERNEL_SRC)/$$f:" >> $@; \
367 echo "" >> $@; \
368 done \
369 )
Michael Bestas3952f6c2016-08-26 01:12:08 +0300370
Tom Marshall6b83d832017-11-09 21:02:33 +0100371.PHONY: INSTALLED_KERNEL_HEADERS
372INSTALLED_KERNEL_HEADERS: $(KERNEL_HEADERS_INSTALL_DEPS)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300373
Tom Marshall6b83d832017-11-09 21:02:33 +0100374# Dependencies on $(KERNEL_OUT)/usr are deprecated
375$(KERNEL_HEADERS_INSTALL_DIR): $(KERNEL_HEADERS_INSTALL_DEPS)
376 @echo "Depending on $(KERNEL_HEADERS_INSTALL_DIR) is deprecated." 1>&2
377 @echo "Use INSTALLED_KERNEL_HEADERS instead." 1>&2
378 @exit 1
379
380.PHONY: kerneltags
381kerneltags: $(KERNEL_CONFIG)
382 $(hide) mkdir -p $(KERNEL_OUT)
Joe Maplesda328952017-11-27 10:09:38 -0500383 $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) tags
Michael Bestas3952f6c2016-08-26 01:12:08 +0300384
Tom Marshall6b83d832017-11-09 21:02:33 +0100385.PHONY: kernelconfig kernelxconfig kernelsavedefconfig alldefconfig
386
Michael Bestas3952f6c2016-08-26 01:12:08 +0300387kernelconfig: KERNELCONFIG_MODE := menuconfig
388kernelxconfig: KERNELCONFIG_MODE := xconfig
Tom Marshall6b83d832017-11-09 21:02:33 +0100389kernelxconfig kernelconfig:
390 $(hide) mkdir -p $(KERNEL_OUT)
Joe Maplesda328952017-11-27 10:09:38 -0500391 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_DEFCONFIG)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300392 env KCONFIG_NOTIMESTAMP=true \
Joe Maplesda328952017-11-27 10:09:38 -0500393 $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNELCONFIG_MODE)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300394 env KCONFIG_NOTIMESTAMP=true \
Joe Maplesda328952017-11-27 10:09:38 -0500395 $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) savedefconfig
Michael Bestas3952f6c2016-08-26 01:12:08 +0300396 cp $(KERNEL_OUT)/defconfig $(KERNEL_DEFCONFIG_SRC)
397
Tom Marshall6b83d832017-11-09 21:02:33 +0100398kernelsavedefconfig:
399 $(hide) mkdir -p $(KERNEL_OUT)
Joe Maplesda328952017-11-27 10:09:38 -0500400 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_DEFCONFIG)
Michael Bestas296008c2017-07-12 20:56:35 +0300401 env KCONFIG_NOTIMESTAMP=true \
Joe Maplesda328952017-11-27 10:09:38 -0500402 $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) savedefconfig
Michael Bestas296008c2017-07-12 20:56:35 +0300403 cp $(KERNEL_OUT)/defconfig $(KERNEL_DEFCONFIG_SRC)
404
Tom Marshall6b83d832017-11-09 21:02:33 +0100405alldefconfig:
406 $(hide) mkdir -p $(KERNEL_OUT)
Michael Bestas3952f6c2016-08-26 01:12:08 +0300407 env KCONFIG_NOTIMESTAMP=true \
Joe Maplesda328952017-11-27 10:09:38 -0500408 $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) alldefconfig
Michael Bestas3952f6c2016-08-26 01:12:08 +0300409
410endif # FULL_KERNEL_BUILD
411
Christian Oder8d5db3c2017-11-25 16:52:17 +0100412TARGET_PREBUILT_DTBO = $(PRODUCT_OUT)/dtbo/arch/$(KERNEL_ARCH)/boot/dtbo.img
413$(TARGET_PREBUILT_DTBO): $(AVBTOOL)
414 echo -e ${CL_GRN}"Building DTBO.img"${CL_RST}
415 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(PRODUCT_OUT)/dtbo ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_DEFCONFIG)
416 $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(PRODUCT_OUT)/dtbo ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) dtbo.img
417 $(AVBTOOL) add_hash_footer \
418 --image $@ \
419 --partition_size $(BOARD_DTBOIMG_PARTITION_SIZE) \
420 --partition_name dtbo $(INTERNAL_AVB_DTBO_SIGNING_ARGS) \
421 $(BOARD_AVB_DTBO_ADD_HASH_FOOTER_ARGS)
422
Michael Bestas3952f6c2016-08-26 01:12:08 +0300423## Install it
424
425ifeq ($(NEEDS_KERNEL_COPY),true)
426file := $(INSTALLED_KERNEL_TARGET)
427ALL_PREBUILT += $(file)
428$(file) : $(KERNEL_BIN) | $(ACP)
429 $(transform-prebuilt-to-target)
430
431ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET)
432endif
433
Christian Oder8d5db3c2017-11-25 16:52:17 +0100434ifeq ($(TARGET_NEEDS_DTBOIMAGE),true)
435file := $(INSTALLED_DTBOIMAGE_TARGET)
436ALL_PREBUILT += $(file)
437$(file) : $(TARGET_PREBUILT_DTBO) | $(ACP)
438 $(transform-prebuilt-to-target)
439
440ALL_PREBUILT += $(INSTALLED_DTBOIMAGE_TARGET)
441endif
442
Michael Bestas3952f6c2016-08-26 01:12:08 +0300443.PHONY: kernel
444kernel: $(INSTALLED_KERNEL_TARGET)
Dan Pasanen8ee5d892017-12-08 13:46:30 -0600445
Christian Oder8d5db3c2017-11-25 16:52:17 +0100446.PHONY: dtbo
447dtbo: $(INSTALLED_DTBOIMAGE_TARGET)
448
Dan Pasanen8ee5d892017-12-08 13:46:30 -0600449endif # TARGET_NO_KERNEL