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