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