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 | # |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 24 | # TARGET_KERNEL_CONFIG = Kernel defconfig |
| 25 | # TARGET_KERNEL_VARIANT_CONFIG = Variant defconfig, optional |
| 26 | # TARGET_KERNEL_SELINUX_CONFIG = SELinux defconfig, optional |
| 27 | # TARGET_KERNEL_ADDITIONAL_CONFIG = Additional defconfig, optional |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 28 | # |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 29 | # TARGET_KERNEL_CLANG_COMPILE = Compile kernel with clang, defaults to false |
| 30 | # |
| 31 | # TARGET_KERNEL_CLANG_VERSION = Clang prebuilts version, optional, defaults to clang-stable |
| 32 | # |
| 33 | # TARGET_KERNEL_CLANG_PATH = Clang prebuilts path, optional |
| 34 | # |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 35 | # BOARD_KERNEL_IMAGE_NAME = Built image name |
| 36 | # for ARM use: zImage |
| 37 | # for ARM64 use: Image.gz |
| 38 | # for uncompressed use: Image |
| 39 | # If using an appended DT, append '-dtb' |
| 40 | # to the end of the image name. |
| 41 | # For example, for ARM devices, |
| 42 | # use zImage-dtb instead of zImage. |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 43 | # |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 44 | # KERNEL_CC = The C Compiler used. This is automatically set based |
| 45 | # on whether the clang version is set, optional. |
| 46 | # |
| 47 | # KERNEL_CLANG_TRIPLE = Target triple for clang (e.g. aarch64-linux-gnu-) |
| 48 | # defaults to arm-linux-gnu- for arm |
| 49 | # aarch64-linux-gnu- for arm64 |
| 50 | # x86_64-linux-gnu- for x86 |
| 51 | # |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 52 | # NEED_KERNEL_MODULE_ROOT = Optional, if true, install kernel |
Luca Stefani | a1ade7f | 2018-07-11 00:35:33 +0200 | [diff] [blame] | 53 | # modules in root instead of vendor |
| 54 | # NEED_KERNEL_MODULE_SYSTEM = Optional, if true, install kernel |
| 55 | # modules in system instead of vendor |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 56 | |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 57 | ifneq ($(TARGET_NO_KERNEL),true) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 58 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 59 | ## Externally influenced variables |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 60 | KERNEL_SRC := $(TARGET_KERNEL_SOURCE) |
| 61 | # kernel configuration - mandatory |
| 62 | KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG) |
| 63 | VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG) |
| 64 | SELINUX_DEFCONFIG := $(TARGET_KERNEL_SELINUX_CONFIG) |
| 65 | |
| 66 | ## Internal variables |
Rashed Abdel-Tawab | d7c6fb7 | 2019-10-13 16:59:57 -0700 | [diff] [blame] | 67 | DTBS_OUT := $(PRODUCT_OUT)/dtbs |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 68 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
| 69 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
LuK1337 | 6047f5a | 2019-07-12 12:55:35 +0200 | [diff] [blame] | 70 | KERNEL_RELEASE := $(KERNEL_OUT)/include/config/kernel.release |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 71 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 72 | ifeq ($(KERNEL_ARCH),x86_64) |
| 73 | KERNEL_DEFCONFIG_ARCH := x86 |
| 74 | else |
| 75 | KERNEL_DEFCONFIG_ARCH := $(KERNEL_ARCH) |
| 76 | endif |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 77 | KERNEL_DEFCONFIG_DIR := $(KERNEL_SRC)/arch/$(KERNEL_DEFCONFIG_ARCH)/configs |
| 78 | KERNEL_DEFCONFIG_SRC := $(KERNEL_DEFCONFIG_DIR)/$(KERNEL_DEFCONFIG) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 79 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 80 | ifneq ($(TARGET_KERNEL_ADDITIONAL_CONFIG),) |
| 81 | KERNEL_ADDITIONAL_CONFIG := $(TARGET_KERNEL_ADDITIONAL_CONFIG) |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 82 | KERNEL_ADDITIONAL_CONFIG_SRC := $(KERNEL_DEFCONFIG_DIR)/$(KERNEL_ADDITIONAL_CONFIG) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 83 | ifeq ("$(wildcard $(KERNEL_ADDITIONAL_CONFIG_SRC))","") |
| 84 | $(warning TARGET_KERNEL_ADDITIONAL_CONFIG '$(TARGET_KERNEL_ADDITIONAL_CONFIG)' doesn't exist) |
| 85 | KERNEL_ADDITIONAL_CONFIG_SRC := /dev/null |
| 86 | endif |
| 87 | else |
| 88 | KERNEL_ADDITIONAL_CONFIG_SRC := /dev/null |
| 89 | endif |
| 90 | |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 91 | ifeq ($(BOARD_KERNEL_IMAGE_NAME),) |
| 92 | $(error BOARD_KERNEL_IMAGE_NAME not defined.) |
| 93 | endif |
| 94 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/$(BOARD_KERNEL_IMAGE_NAME) |
| 95 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 96 | ifeq "$(wildcard $(KERNEL_SRC) )" "" |
| 97 | ifneq ($(TARGET_PREBUILT_KERNEL),) |
| 98 | HAS_PREBUILT_KERNEL := true |
| 99 | NEEDS_KERNEL_COPY := true |
| 100 | else |
| 101 | $(foreach cf,$(PRODUCT_COPY_FILES), \ |
| 102 | $(eval _src := $(call word-colon,1,$(cf))) \ |
| 103 | $(eval _dest := $(call word-colon,2,$(cf))) \ |
| 104 | $(ifeq kernel,$(_dest), \ |
| 105 | $(eval HAS_PREBUILT_KERNEL := true))) |
| 106 | endif |
| 107 | |
| 108 | ifneq ($(HAS_PREBUILT_KERNEL),) |
| 109 | $(warning ***************************************************************) |
| 110 | $(warning * Using prebuilt kernel binary instead of source *) |
| 111 | $(warning * THIS IS DEPRECATED, AND WILL BE DISCONTINUED *) |
| 112 | $(warning * Please configure your device to download the kernel *) |
| 113 | $(warning * source repository to $(KERNEL_SRC)) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 114 | $(warning * for more information *) |
| 115 | $(warning ***************************************************************) |
| 116 | FULL_KERNEL_BUILD := false |
| 117 | KERNEL_BIN := $(TARGET_PREBUILT_KERNEL) |
| 118 | else |
| 119 | $(warning ***************************************************************) |
| 120 | $(warning * *) |
| 121 | $(warning * No kernel source found, and no fallback prebuilt defined. *) |
| 122 | $(warning * Please make sure your device is properly configured to *) |
| 123 | $(warning * download the kernel repository to $(KERNEL_SRC)) |
| 124 | $(warning * and add the TARGET_KERNEL_CONFIG variable to BoardConfig.mk *) |
| 125 | $(warning * *) |
| 126 | $(warning * As an alternative, define the TARGET_PREBUILT_KERNEL *) |
| 127 | $(warning * variable with the path to the prebuilt binary kernel image *) |
| 128 | $(warning * in your BoardConfig.mk file *) |
| 129 | $(warning * *) |
| 130 | $(warning ***************************************************************) |
| 131 | $(error "NO KERNEL") |
| 132 | endif |
| 133 | else |
| 134 | NEEDS_KERNEL_COPY := true |
| 135 | ifeq ($(TARGET_KERNEL_CONFIG),) |
| 136 | $(warning **********************************************************) |
| 137 | $(warning * Kernel source found, but no configuration was defined *) |
| 138 | $(warning * Please add the TARGET_KERNEL_CONFIG variable to your *) |
| 139 | $(warning * BoardConfig.mk file *) |
| 140 | $(warning **********************************************************) |
| 141 | # $(error "NO KERNEL CONFIG") |
| 142 | else |
| 143 | #$(info Kernel source found, building it) |
| 144 | FULL_KERNEL_BUILD := true |
| 145 | KERNEL_BIN := $(TARGET_PREBUILT_INT_KERNEL) |
| 146 | endif |
| 147 | endif |
| 148 | |
| 149 | ifeq ($(FULL_KERNEL_BUILD),true) |
| 150 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 151 | ifeq ($(NEED_KERNEL_MODULE_ROOT),true) |
Ethan Chen | 9985f59 | 2019-02-09 15:15:11 -0800 | [diff] [blame] | 152 | KERNEL_MODULES_OUT := $(TARGET_ROOT_OUT) |
Rashed Abdel-Tawab | 6802b72 | 2019-09-10 08:44:55 -0700 | [diff] [blame] | 153 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_recovery) |
Ethan Chen | bf38db2 | 2017-12-03 23:59:48 -0800 | [diff] [blame] | 154 | KERNEL_MODULE_MOUNTPOINT := |
Luca Stefani | a1ade7f | 2018-07-11 00:35:33 +0200 | [diff] [blame] | 155 | else ifeq ($(NEED_KERNEL_MODULE_SYSTEM),true) |
Ethan Chen | 9985f59 | 2019-02-09 15:15:11 -0800 | [diff] [blame] | 156 | KERNEL_MODULES_OUT := $(TARGET_OUT) |
Rashed Abdel-Tawab | 6802b72 | 2019-09-10 08:44:55 -0700 | [diff] [blame] | 157 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_system) |
Luca Stefani | a1ade7f | 2018-07-11 00:35:33 +0200 | [diff] [blame] | 158 | KERNEL_MODULE_MOUNTPOINT := system |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 159 | else |
Ethan Chen | 9985f59 | 2019-02-09 15:15:11 -0800 | [diff] [blame] | 160 | KERNEL_MODULES_OUT := $(TARGET_OUT_VENDOR) |
Rashed Abdel-Tawab | 6802b72 | 2019-09-10 08:44:55 -0700 | [diff] [blame] | 161 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor) |
Ethan Chen | bf38db2 | 2017-12-03 23:59:48 -0800 | [diff] [blame] | 162 | KERNEL_MODULE_MOUNTPOINT := vendor |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 163 | endif |
Rashed Abdel-Tawab | 6802b72 | 2019-09-10 08:44:55 -0700 | [diff] [blame] | 164 | MODULES_INTERMEDIATES := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,kernel_modules) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 165 | |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 166 | PATH_OVERRIDE := |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 167 | ifeq ($(TARGET_KERNEL_CLANG_COMPILE),true) |
| 168 | ifneq ($(TARGET_KERNEL_CLANG_VERSION),) |
Luca Stefani | 736f1be | 2019-09-14 16:26:26 +0200 | [diff] [blame] | 169 | KERNEL_CLANG_VERSION := clang-$(TARGET_KERNEL_CLANG_VERSION) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 170 | else |
Nathan Chancellor | ca40331 | 2018-04-11 16:23:19 -0700 | [diff] [blame] | 171 | # Use the default version of clang if TARGET_KERNEL_CLANG_VERSION hasn't been set by the device config |
| 172 | KERNEL_CLANG_VERSION := $(LLVM_PREBUILTS_VERSION) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 173 | endif |
Rashed Abdel-Tawab | c648519 | 2019-09-10 08:38:34 -0700 | [diff] [blame] | 174 | TARGET_KERNEL_CLANG_PATH ?= $(BUILD_TOP)/prebuilts/clang/host/$(HOST_OS)-x86/$(KERNEL_CLANG_VERSION) |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 175 | ifeq ($(KERNEL_ARCH),arm64) |
| 176 | KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=aarch64-linux-gnu- |
| 177 | else ifeq ($(KERNEL_ARCH),arm) |
| 178 | KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=arm-linux-gnu- |
| 179 | else ifeq ($(KERNEL_ARCH),x86) |
| 180 | KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=x86_64-linux-gnu- |
| 181 | endif |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 182 | PATH_OVERRIDE += PATH=$(TARGET_KERNEL_CLANG_PATH)/bin:$$PATH LD_LIBRARY_PATH=$(TARGET_KERNEL_CLANG_PATH)/lib64:$$LD_LIBRARY_PATH |
Dan Pasanen | f65a6df | 2018-02-18 22:13:05 -0600 | [diff] [blame] | 183 | ifeq ($(KERNEL_CC),) |
Nathan Chancellor | 4d0d438 | 2018-10-21 19:07:47 -0700 | [diff] [blame] | 184 | KERNEL_CC := CC="$(CCACHE_BIN) clang" |
Dan Pasanen | f65a6df | 2018-02-18 22:13:05 -0600 | [diff] [blame] | 185 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 186 | endif |
| 187 | |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 188 | ifneq ($(TARGET_KERNEL_MODULES),) |
| 189 | $(error TARGET_KERNEL_MODULES is no longer supported!) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 190 | endif |
| 191 | |
Rashed Abdel-Tawab | 168fd23 | 2019-09-24 17:22:39 +0200 | [diff] [blame] | 192 | PATH_OVERRIDE += PATH=$(KERNEL_TOOLCHAIN_PATH_gcc)/bin:$$PATH |
Rashed Abdel-Tawab | c648519 | 2019-09-10 08:38:34 -0700 | [diff] [blame] | 193 | |
Rashed Abdel-Tawab | dfc3d18 | 2019-09-06 10:44:50 -0700 | [diff] [blame] | 194 | # System tools are no longer allowed on 10+ |
| 195 | PATH_OVERRIDE += $(TOOLS_PATH_OVERRIDE) |
| 196 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 197 | KERNEL_ADDITIONAL_CONFIG_OUT := $(KERNEL_OUT)/.additional_config |
| 198 | |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 199 | # Internal implementation of make-kernel-target |
| 200 | # $(1): output path (The value passed to O=) |
| 201 | # $(2): target to build (eg. defconfig, modules, dtbo.img) |
| 202 | define internal-make-kernel-target |
Rashed Abdel-Tawab | ba5ea35 | 2019-09-07 17:01:13 -0700 | [diff] [blame] | 203 | $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(KERNEL_SRC) O=$(KERNEL_BUILD_OUT_PREFIX)$(1) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(2) |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 204 | endef |
| 205 | |
| 206 | # Make a kernel target |
| 207 | # $(1): The kernel target to build (eg. defconfig, modules, modules_install) |
| 208 | define make-kernel-target |
| 209 | $(call internal-make-kernel-target,$(KERNEL_OUT),$(1)) |
| 210 | endef |
| 211 | |
| 212 | # Make a DTBO target |
| 213 | # $(1): The DTBO target to build (eg. dtbo.img, defconfig) |
| 214 | define make-dtbo-target |
| 215 | $(call internal-make-kernel-target,$(PRODUCT_OUT)/dtbo,$(1)) |
| 216 | endef |
| 217 | |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 218 | # Make a DTB targets |
| 219 | # $(1): The DTB target to build (eg. dtbs, defconfig) |
| 220 | define make-dtb-target |
Rashed Abdel-Tawab | d7c6fb7 | 2019-10-13 16:59:57 -0700 | [diff] [blame] | 221 | $(call internal-make-kernel-target,$(DTBS_OUT),$(1)) |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 222 | endef |
| 223 | |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 224 | $(KERNEL_OUT): |
| 225 | mkdir -p $(KERNEL_OUT) |
| 226 | |
| 227 | $(KERNEL_ADDITIONAL_CONFIG_OUT): $(KERNEL_OUT) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 228 | $(hide) cmp -s $(KERNEL_ADDITIONAL_CONFIG_SRC) $@ || cp $(KERNEL_ADDITIONAL_CONFIG_SRC) $@; |
| 229 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 230 | $(KERNEL_CONFIG): $(KERNEL_DEFCONFIG_SRC) $(KERNEL_ADDITIONAL_CONFIG_OUT) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 231 | @echo "Building Kernel Config" |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 232 | $(call make-kernel-target,VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(KERNEL_DEFCONFIG)) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 233 | $(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \ |
| 234 | echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \ |
| 235 | echo $(KERNEL_CONFIG_OVERRIDE) >> $(KERNEL_OUT)/.config; \ |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 236 | $(call make-kernel-target,oldconfig); \ |
| 237 | fi |
Sam Mortimer | b0cecb7 | 2016-10-01 09:56:52 -0700 | [diff] [blame] | 238 | # Create defconfig build artifact |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 239 | $(call make-kernel-target,savedefconfig) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 240 | $(hide) if [ ! -z "$(KERNEL_ADDITIONAL_CONFIG)" ]; then \ |
| 241 | echo "Using additional config '$(KERNEL_ADDITIONAL_CONFIG)'"; \ |
| 242 | $(KERNEL_SRC)/scripts/kconfig/merge_config.sh -m -O $(KERNEL_OUT) $(KERNEL_OUT)/.config $(KERNEL_SRC)/arch/$(KERNEL_ARCH)/configs/$(KERNEL_ADDITIONAL_CONFIG); \ |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 243 | $(call make-kernel-target,KCONFIG_ALLCONFIG=$(KERNEL_OUT)/.config alldefconfig); \ |
| 244 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 245 | |
Rashed Abdel-Tawab | 3467b7a | 2019-09-30 11:11:50 -0400 | [diff] [blame] | 246 | $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 247 | @echo "Building Kernel" |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 248 | $(call make-kernel-target,$(BOARD_KERNEL_IMAGE_NAME)) |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 249 | $(hide) if grep -q '^CONFIG_OF=y' $(KERNEL_CONFIG); then \ |
| 250 | echo "Building DTBs"; \ |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 251 | $(call make-kernel-target,dtbs); \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 252 | fi |
Ethan Chen | 0724f78 | 2019-02-09 21:05:01 -0800 | [diff] [blame] | 253 | $(hide) if grep -q '=m' $(KERNEL_CONFIG); then \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 254 | echo "Building Kernel Modules"; \ |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 255 | $(call make-kernel-target,modules) || exit "$$?"; \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 256 | echo "Installing Kernel Modules"; \ |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 257 | $(call make-kernel-target,INSTALL_MOD_PATH=$(MODULES_INTERMEDIATES) INSTALL_MOD_STRIP=1 modules_install); \ |
LuK1337 | 6047f5a | 2019-07-12 12:55:35 +0200 | [diff] [blame] | 258 | kernel_release=$$(cat $(KERNEL_RELEASE)) \ |
| 259 | modules=$$(find $(MODULES_INTERMEDIATES)/lib/modules/$$kernel_release -type f -name '*.ko'); \ |
Thor Lee | 7597589 | 2019-05-02 09:31:30 +0200 | [diff] [blame] | 260 | ($(call build-image-kernel-modules,$$modules,$(KERNEL_MODULES_OUT),$(KERNEL_MODULE_MOUNTPOINT)/,$(KERNEL_DEPMOD_STAGING_DIR))); \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 261 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 262 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 263 | .PHONY: kerneltags |
| 264 | kerneltags: $(KERNEL_CONFIG) |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 265 | $(call make-kernel-target,tags) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 266 | |
Michael Bestas | b4c4aba | 2018-10-06 22:12:10 +0300 | [diff] [blame] | 267 | .PHONY: kernelsavedefconfig alldefconfig |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 268 | |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 269 | kernelsavedefconfig: $(KERNEL_OUT) |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 270 | $(call make-kernel-target,$(KERNEL_DEFCONFIG)) |
Michael Bestas | 296008c | 2017-07-12 20:56:35 +0300 | [diff] [blame] | 271 | env KCONFIG_NOTIMESTAMP=true \ |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 272 | $(call make-kernel-target,savedefconfig) |
Michael Bestas | 296008c | 2017-07-12 20:56:35 +0300 | [diff] [blame] | 273 | cp $(KERNEL_OUT)/defconfig $(KERNEL_DEFCONFIG_SRC) |
| 274 | |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 275 | alldefconfig: $(KERNEL_OUT) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 276 | env KCONFIG_NOTIMESTAMP=true \ |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 277 | $(call make-kernel-target,alldefconfig) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 278 | |
Rashed Abdel-Tawab | 60fe935 | 2019-05-16 14:01:19 -0700 | [diff] [blame] | 279 | ifeq ($(TARGET_NEEDS_DTBOIMAGE),true) |
Rashed Abdel-Tawab | 60fe935 | 2019-05-16 14:01:19 -0700 | [diff] [blame] | 280 | $(BOARD_PREBUILT_DTBOIMAGE): |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 281 | echo -e ${CL_GRN}"Building DTBO.img"${CL_RST} |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 282 | $(call make-dtbo-target,$(KERNEL_DEFCONFIG)) |
| 283 | $(call make-dtbo-target,dtbo.img) |
Rashed Abdel-Tawab | 60fe935 | 2019-05-16 14:01:19 -0700 | [diff] [blame] | 284 | endif # TARGET_NEEDS_DTBOIMAGE |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 285 | |
Ethan Chen | 117a0fd | 2019-02-10 12:12:50 -0800 | [diff] [blame] | 286 | endif # FULL_KERNEL_BUILD |
| 287 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 288 | ## Install it |
| 289 | |
| 290 | ifeq ($(NEEDS_KERNEL_COPY),true) |
| 291 | file := $(INSTALLED_KERNEL_TARGET) |
| 292 | ALL_PREBUILT += $(file) |
| 293 | $(file) : $(KERNEL_BIN) | $(ACP) |
| 294 | $(transform-prebuilt-to-target) |
| 295 | |
| 296 | ALL_PREBUILT += $(INSTALLED_KERNEL_TARGET) |
| 297 | endif |
| 298 | |
Rashed Abdel-Tawab | 60fe935 | 2019-05-16 14:01:19 -0700 | [diff] [blame] | 299 | INSTALLED_DTBOIMAGE_TARGET := $(PRODUCT_OUT)/dtbo.img |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 300 | ALL_PREBUILT += $(INSTALLED_DTBOIMAGE_TARGET) |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 301 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 302 | .PHONY: kernel |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 303 | kernel: $(INSTALLED_KERNEL_TARGET) |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 304 | |
Rashed Abdel-Tawab | 60fe935 | 2019-05-16 14:01:19 -0700 | [diff] [blame] | 305 | .PHONY: dtboimage |
| 306 | dtboimage: $(INSTALLED_DTBOIMAGE_TARGET) |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 307 | |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 308 | ifeq ($(BOARD_INCLUDE_DTB_IN_BOOTIMG),true) |
Rashed Abdel-Tawab | 15d91cd | 2019-11-20 15:22:57 -0500 | [diff] [blame] | 309 | ifeq ($(BOARD_PREBUILT_DTBIMAGE_DIR),) |
Rashed Abdel-Tawab | e3c319a | 2019-10-07 14:42:30 -0400 | [diff] [blame] | 310 | $(INSTALLED_DTBIMAGE_TARGET): |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 311 | echo -e ${CL_GRN}"Building DTBs"${CL_RST} |
| 312 | $(call make-dtb-target,$(KERNEL_DEFCONFIG)) |
| 313 | $(call make-dtb-target,dtbs) |
Rashed Abdel-Tawab | e3c319a | 2019-10-07 14:42:30 -0400 | [diff] [blame] | 314 | cat $(shell find $(DTBS_OUT)/arch/$(KERNEL_ARCH)/boot/dts/** -type f -name "*.dtb" | sort) > $@ |
Rashed Abdel-Tawab | 15d91cd | 2019-11-20 15:22:57 -0500 | [diff] [blame] | 315 | endif |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 316 | .PHONY: dtbimage |
| 317 | dtbimage: $(INSTALLED_DTBIMAGE_TARGET) |
| 318 | endif # BOARD_INCLUDE_DTB_IN_BOOTIMG |
| 319 | |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 320 | endif # TARGET_NO_KERNEL |