Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 1 | # Copyright (C) 2012 The CyanogenMod Project |
Dan Pasanen | 0344771 | 2016-12-19 11:22:55 -0600 | [diff] [blame] | 2 | # (C) 2017 The LineageOS Project |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 3 | # |
| 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 31 | # TARGET_KERNEL_CROSS_COMPILE_PREFIX = Compiler prefix (e.g. arm-eabi-) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 32 | # defaults to arm-linux-androidkernel- for arm |
| 33 | # aarch64-linux-androidkernel- for arm64 |
| 34 | # x86_64-linux-androidkernel- for x86 |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 35 | # |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 36 | # 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 Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 42 | # 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 50 | # |
| 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 Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 57 | # |
| 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 66 | # 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 Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 71 | ifneq ($(TARGET_NO_KERNEL),true) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 72 | |
| 73 | TARGET_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> |
| 77 | TARGET_KERNEL_SOURCE ?= $(TARGET_AUTO_KDIR) |
| 78 | KERNEL_SRC := $(TARGET_KERNEL_SOURCE) |
| 79 | # kernel configuration - mandatory |
| 80 | KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG) |
| 81 | VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG) |
| 82 | SELINUX_DEFCONFIG := $(TARGET_KERNEL_SELINUX_CONFIG) |
| 83 | |
| 84 | ## Internal variables |
| 85 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 86 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 87 | |
| 88 | TARGET_KERNEL_ARCH := $(strip $(TARGET_KERNEL_ARCH)) |
| 89 | ifeq ($(TARGET_KERNEL_ARCH),) |
| 90 | KERNEL_ARCH := $(TARGET_ARCH) |
| 91 | else |
| 92 | KERNEL_ARCH := $(TARGET_KERNEL_ARCH) |
| 93 | endif |
| 94 | |
| 95 | ifeq ($(KERNEL_ARCH),x86_64) |
| 96 | KERNEL_DEFCONFIG_ARCH := x86 |
| 97 | else |
| 98 | KERNEL_DEFCONFIG_ARCH := $(KERNEL_ARCH) |
| 99 | endif |
| 100 | KERNEL_DEFCONFIG_SRC := $(KERNEL_SRC)/arch/$(KERNEL_DEFCONFIG_ARCH)/configs/$(KERNEL_DEFCONFIG) |
| 101 | |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 102 | ifeq ($(BOARD_KERNEL_IMAGE_NAME),) |
| 103 | $(error BOARD_KERNEL_IMAGE_NAME not defined.) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 104 | endif |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 105 | ifneq ($(TARGET_USES_UNCOMPRESSED_KERNEL),) |
| 106 | $(error TARGET_USES_UNCOMPRESSED_KERNEL is deprecated.) |
| 107 | endif |
| 108 | ifneq ($(TARGET_KERNEL_APPEND_DTB),) |
| 109 | $(error TARGET_KERNEL_APPEND_DTB is deprecated.) |
| 110 | endif |
| 111 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/$(BOARD_KERNEL_IMAGE_NAME) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 112 | |
| 113 | # Clear this first to prevent accidental poisoning from env |
| 114 | MAKE_FLAGS := |
| 115 | |
Ziyan | 54648c2 | 2017-01-12 18:47:54 +0100 | [diff] [blame] | 116 | ifeq ($(KERNEL_ARCH),arm) |
| 117 | # Avoid "Unknown symbol _GLOBAL_OFFSET_TABLE_" errors |
| 118 | MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
| 119 | endif |
| 120 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 121 | ifeq ($(KERNEL_ARCH),arm64) |
| 122 | # Avoid "unsupported RELA relocation: 311" errors (R_AARCH64_ADR_GOT_PAGE) |
| 123 | MAKE_FLAGS += CFLAGS_MODULE="-fno-pic" |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 124 | endif |
| 125 | |
| 126 | ifneq ($(TARGET_KERNEL_ADDITIONAL_CONFIG),) |
| 127 | KERNEL_ADDITIONAL_CONFIG := $(TARGET_KERNEL_ADDITIONAL_CONFIG) |
| 128 | KERNEL_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 |
| 133 | else |
| 134 | KERNEL_ADDITIONAL_CONFIG_SRC := /dev/null |
| 135 | endif |
| 136 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 137 | ifeq "$(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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 155 | $(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 |
| 174 | else |
| 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 |
| 188 | endif |
| 189 | |
| 190 | ifeq ($(FULL_KERNEL_BUILD),true) |
| 191 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 192 | KERNEL_HEADERS_INSTALL_DIR := $(KERNEL_OUT)/usr |
| 193 | KERNEL_HEADERS_INSTALL_DEPS := $(KERNEL_OUT)/.headers_install_deps |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 194 | |
| 195 | ifeq ($(NEED_KERNEL_MODULE_ROOT),true) |
| 196 | KERNEL_MODULES_INSTALL := root |
| 197 | KERNEL_MODULES_OUT := $(TARGET_ROOT_OUT)/lib/modules |
Ethan Chen | bf38db2 | 2017-12-03 23:59:48 -0800 | [diff] [blame] | 198 | KERNEL_DEPMOD_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_recovery) |
| 199 | KERNEL_MODULE_MOUNTPOINT := |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 200 | else |
Ethan Chen | bf38db2 | 2017-12-03 23:59:48 -0800 | [diff] [blame] | 201 | KERNEL_MODULES_INSTALL := $(TARGET_COPY_OUT_VENDOR) |
| 202 | KERNEL_MODULES_OUT := $(TARGET_OUT_VENDOR)/lib/modules |
| 203 | KERNEL_DEPMOD_STAGING_DIR := $(call intermediates-dir-for,PACKAGING,depmod_vendor) |
| 204 | KERNEL_MODULE_MOUNTPOINT := vendor |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 205 | endif |
| 206 | |
| 207 | TARGET_KERNEL_CROSS_COMPILE_PREFIX := $(strip $(TARGET_KERNEL_CROSS_COMPILE_PREFIX)) |
| 208 | ifneq ($(TARGET_KERNEL_CROSS_COMPILE_PREFIX),) |
| 209 | KERNEL_TOOLCHAIN_PREFIX ?= $(TARGET_KERNEL_CROSS_COMPILE_PREFIX) |
Zhao Wei Liew | 9689bb9 | 2016-11-10 20:02:58 +0800 | [diff] [blame] | 210 | else ifeq ($(KERNEL_ARCH),arm64) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 211 | KERNEL_TOOLCHAIN_PREFIX ?= aarch64-linux-androidkernel- |
Zhao Wei Liew | 9689bb9 | 2016-11-10 20:02:58 +0800 | [diff] [blame] | 212 | else ifeq ($(KERNEL_ARCH),arm) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 213 | KERNEL_TOOLCHAIN_PREFIX ?= arm-linux-androidkernel- |
Zhao Wei Liew | 9689bb9 | 2016-11-10 20:02:58 +0800 | [diff] [blame] | 214 | else ifeq ($(KERNEL_ARCH),x86) |
Michael Bestas | 1d55ece | 2016-09-28 20:16:25 +0300 | [diff] [blame] | 215 | KERNEL_TOOLCHAIN_PREFIX ?= x86_64-linux-androidkernel- |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 216 | endif |
| 217 | |
| 218 | ifeq ($(KERNEL_TOOLCHAIN),) |
| 219 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN_PREFIX) |
| 220 | else |
| 221 | ifneq ($(KERNEL_TOOLCHAIN_PREFIX),) |
| 222 | KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX) |
| 223 | endif |
| 224 | endif |
| 225 | |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 226 | ifeq ($(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 Chancellor | ca40331 | 2018-04-11 16:23:19 -0700 | [diff] [blame] | 231 | # 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 Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 233 | 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 |
| 242 | endif |
| 243 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 244 | ifneq ($(USE_CCACHE),) |
Steve Kondik | 6a37828 | 2016-09-25 22:37:01 -0700 | [diff] [blame] | 245 | # 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 253 | endif |
| 254 | |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 255 | ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true) |
| 256 | KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)" |
Dan Pasanen | f65a6df | 2018-02-18 22:13:05 -0600 | [diff] [blame] | 257 | ifeq ($(KERNEL_CC),) |
| 258 | KERNEL_CC := CC="$(ccache) $(TARGET_KERNEL_CLANG_PATH)/clang" |
| 259 | endif |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 260 | else |
| 261 | KERNEL_CROSS_COMPILE := CROSS_COMPILE="$(ccache) $(KERNEL_TOOLCHAIN_PATH)" |
| 262 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 263 | ccache = |
| 264 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 265 | ifeq ($(HOST_OS),darwin) |
Christopher N. Hesse | 1e7c3f0 | 2017-04-12 00:57:44 +0200 | [diff] [blame] | 266 | MAKE_FLAGS += C_INCLUDE_PATH=$(ANDROID_BUILD_TOP)/external/elfutils/libelf:/usr/local/opt/openssl/include |
Rashed Abdel-Tawab | 7fb9251 | 2017-03-16 14:37:07 -0400 | [diff] [blame] | 267 | MAKE_FLAGS += LIBRARY_PATH=/usr/local/opt/openssl/lib |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 268 | endif |
| 269 | |
| 270 | ifeq ($(TARGET_KERNEL_MODULES),) |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 271 | TARGET_KERNEL_MODULES := INSTALLED_KERNEL_MODULES |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 272 | endif |
| 273 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 274 | KERNEL_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 Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 280 | $(KERNEL_CONFIG): $(KERNEL_DEFCONFIG_SRC) $(KERNEL_ADDITIONAL_CONFIG_OUT) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 281 | @echo "Building Kernel Config" |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 282 | $(hide) mkdir -p $(KERNEL_OUT) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 283 | $(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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 284 | $(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 Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 287 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) oldconfig; fi |
Sam Mortimer | b0cecb7 | 2016-10-01 09:56:52 -0700 | [diff] [blame] | 288 | # Create defconfig build artifact |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 289 | $(hide) $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) savedefconfig |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 290 | $(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 Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 293 | $(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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 294 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 295 | .PHONY: TARGET_KERNEL_BINARIES |
| 296 | TARGET_KERNEL_BINARIES: $(KERNEL_CONFIG) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 297 | @echo "Building Kernel" |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 298 | $(hide) rm -rf $(KERNEL_MODULES_OUT) |
| 299 | $(hide) mkdir -p $(KERNEL_MODULES_OUT) |
| 300 | $(hide) rm -rf $(KERNEL_DEPMOD_STAGING_DIR) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 301 | $(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 Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 302 | $(hide) if grep -q '^CONFIG_OF=y' $(KERNEL_CONFIG); then \ |
| 303 | echo "Building DTBs"; \ |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 304 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) dtbs; \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 305 | fi |
| 306 | $(hide) if grep -q '^CONFIG_MODULES=y' $(KERNEL_CONFIG); then \ |
| 307 | echo "Building Kernel Modules"; \ |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 308 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) modules; \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 309 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 310 | |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 311 | .PHONY: INSTALLED_KERNEL_MODULES |
Aaron Kling | a078a22 | 2018-01-12 18:19:27 -0600 | [diff] [blame] | 312 | INSTALLED_KERNEL_MODULES: depmod-host |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 313 | $(hide) if grep -q '^CONFIG_MODULES=y' $(KERNEL_CONFIG); then \ |
| 314 | echo "Installing Kernel Modules"; \ |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 315 | $(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 Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 316 | 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 Chen | bf38db2 | 2017-12-03 23:59:48 -0800 | [diff] [blame] | 322 | 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 Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 327 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 328 | |
| 329 | $(TARGET_KERNEL_MODULES): TARGET_KERNEL_BINARIES |
| 330 | |
| 331 | $(TARGET_PREBUILT_INT_KERNEL): $(TARGET_KERNEL_MODULES) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 332 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 333 | # 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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 349 | @echo "Building Kernel Headers" |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 350 | $(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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 370 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 371 | .PHONY: INSTALLED_KERNEL_HEADERS |
| 372 | INSTALLED_KERNEL_HEADERS: $(KERNEL_HEADERS_INSTALL_DEPS) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 373 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 374 | # 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 |
| 381 | kerneltags: $(KERNEL_CONFIG) |
| 382 | $(hide) mkdir -p $(KERNEL_OUT) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 383 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) tags |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 384 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 385 | .PHONY: kernelconfig kernelxconfig kernelsavedefconfig alldefconfig |
| 386 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 387 | kernelconfig: KERNELCONFIG_MODE := menuconfig |
| 388 | kernelxconfig: KERNELCONFIG_MODE := xconfig |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 389 | kernelxconfig kernelconfig: |
| 390 | $(hide) mkdir -p $(KERNEL_OUT) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 391 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_DEFCONFIG) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 392 | env KCONFIG_NOTIMESTAMP=true \ |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 393 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNELCONFIG_MODE) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 394 | env KCONFIG_NOTIMESTAMP=true \ |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 395 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) savedefconfig |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 396 | cp $(KERNEL_OUT)/defconfig $(KERNEL_DEFCONFIG_SRC) |
| 397 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 398 | kernelsavedefconfig: |
| 399 | $(hide) mkdir -p $(KERNEL_OUT) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 400 | $(MAKE) $(MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(KERNEL_DEFCONFIG) |
Michael Bestas | 296008c | 2017-07-12 20:56:35 +0300 | [diff] [blame] | 401 | env KCONFIG_NOTIMESTAMP=true \ |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 402 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) savedefconfig |
Michael Bestas | 296008c | 2017-07-12 20:56:35 +0300 | [diff] [blame] | 403 | cp $(KERNEL_OUT)/defconfig $(KERNEL_DEFCONFIG_SRC) |
| 404 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 405 | alldefconfig: |
| 406 | $(hide) mkdir -p $(KERNEL_OUT) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 407 | env KCONFIG_NOTIMESTAMP=true \ |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 408 | $(MAKE) -C $(KERNEL_SRC) O=$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) alldefconfig |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 409 | |
| 410 | endif # FULL_KERNEL_BUILD |
| 411 | |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 412 | TARGET_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 Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 423 | ## Install it |
| 424 | |
| 425 | ifeq ($(NEEDS_KERNEL_COPY),true) |
| 426 | file := $(INSTALLED_KERNEL_TARGET) |
| 427 | ALL_PREBUILT += $(file) |
| 428 | $(file) : $(KERNEL_BIN) | $(ACP) |
| 429 | $(transform-prebuilt-to-target) |
| 430 | |
| 431 | ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET) |
| 432 | endif |
| 433 | |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 434 | ifeq ($(TARGET_NEEDS_DTBOIMAGE),true) |
| 435 | file := $(INSTALLED_DTBOIMAGE_TARGET) |
| 436 | ALL_PREBUILT += $(file) |
| 437 | $(file) : $(TARGET_PREBUILT_DTBO) | $(ACP) |
| 438 | $(transform-prebuilt-to-target) |
| 439 | |
| 440 | ALL_PREBUILT += $(INSTALLED_DTBOIMAGE_TARGET) |
| 441 | endif |
| 442 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 443 | .PHONY: kernel |
| 444 | kernel: $(INSTALLED_KERNEL_TARGET) |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 445 | |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 446 | .PHONY: dtbo |
| 447 | dtbo: $(INSTALLED_DTBOIMAGE_TARGET) |
| 448 | |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 449 | endif # TARGET_NO_KERNEL |