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