Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 1 | # Copyright (C) 2012 The CyanogenMod Project |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 2 | # (C) 2017-2023 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 | # |
Alexander Koskovich | 8da3fa2 | 2022-06-16 13:14:14 -0700 | [diff] [blame] | 24 | # TARGET_KERNEL_ADDITIONAL_FLAGS = Additional make flags, optional |
Sebastiano Barezzi | 94b9680 | 2022-03-16 17:42:13 +0100 | [diff] [blame] | 25 | # TARGET_KERNEL_CONFIG = List of kernel defconfigs, first one being the base one, |
Bruno Martins | f70f8a3 | 2022-04-08 21:17:01 +0100 | [diff] [blame] | 26 | # while all the others are fragments that will be merged |
Sebastiano Barezzi | 94b9680 | 2022-03-16 17:42:13 +0100 | [diff] [blame] | 27 | # to main one in .config. |
Bruno Martins | f70f8a3 | 2022-04-08 21:17:01 +0100 | [diff] [blame] | 28 | # TARGET_KERNEL_RECOVERY_CONFIG = Same as above, but applicable to recovery kernel instead. |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 29 | # TARGET_KERNEL_VARIANT_CONFIG = Variant defconfig, optional |
| 30 | # TARGET_KERNEL_SELINUX_CONFIG = SELinux defconfig, optional |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 31 | # |
Alexander Koskovich | e8e46e6 | 2022-03-07 11:29:34 -0700 | [diff] [blame] | 32 | # TARGET_KERNEL_CLANG_COMPILE = Compile kernel with clang, defaults to true |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 33 | # |
Dan Pasanen | edc1ceb | 2017-01-24 15:46:13 -0600 | [diff] [blame] | 34 | # BOARD_KERNEL_IMAGE_NAME = Built image name |
| 35 | # for ARM use: zImage |
| 36 | # for ARM64 use: Image.gz |
| 37 | # for uncompressed use: Image |
| 38 | # If using an appended DT, append '-dtb' |
| 39 | # to the end of the image name. |
| 40 | # For example, for ARM devices, |
| 41 | # use zImage-dtb instead of zImage. |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 42 | # |
basamaryan | eaba762 | 2023-10-05 14:17:47 +0200 | [diff] [blame] | 43 | # BOARD_DTB_CFG = Path to a mkdtboimg config file for dtb.img |
Tim Zimmermann | a81136e | 2022-07-14 21:25:36 +0200 | [diff] [blame] | 44 | # |
basamaryan | eaba762 | 2023-10-05 14:17:47 +0200 | [diff] [blame] | 45 | # BOARD_DTBO_CFG = Path to a mkdtboimg config file |
Luca Stefani | 05ce3dc | 2020-08-03 11:58:00 +0200 | [diff] [blame] | 46 | # |
Aaron Kling | ca7e064 | 2022-10-17 00:17:13 -0500 | [diff] [blame] | 47 | # BOARD_CUSTOM_DTBIMG_MK = Path to a custom dtbimage makefile |
| 48 | # |
Aayush Gupta | 1de3b30 | 2020-08-25 10:03:10 +0000 | [diff] [blame] | 49 | # BOARD_CUSTOM_DTBOIMG_MK = Path to a custom dtboimage makefile |
| 50 | # |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 51 | # KERNEL_CC = The C Compiler used. This is automatically set based |
| 52 | # on whether the clang version is set, optional. |
| 53 | # |
| 54 | # KERNEL_CLANG_TRIPLE = Target triple for clang (e.g. aarch64-linux-gnu-) |
| 55 | # defaults to arm-linux-gnu- for arm |
| 56 | # aarch64-linux-gnu- for arm64 |
| 57 | # x86_64-linux-gnu- for x86 |
| 58 | # |
Chirayu Desai | 3eed09a | 2021-12-03 22:39:46 +0530 | [diff] [blame] | 59 | # KERNEL_LTO = Optional, force LTO to none / thin / full |
| 60 | # |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 61 | # NEED_KERNEL_MODULE_ROOT = Optional, if true, install kernel |
Luca Stefani | a1ade7f | 2018-07-11 00:35:33 +0200 | [diff] [blame] | 62 | # modules in root instead of vendor |
| 63 | # NEED_KERNEL_MODULE_SYSTEM = Optional, if true, install kernel |
| 64 | # modules in system instead of vendor |
Luca Stefani | edc2e0c | 2020-08-01 17:24:29 +0200 | [diff] [blame] | 65 | # NEED_KERNEL_MODULE_VENDOR_OVERLAY = Optional, if true, install kernel |
| 66 | # modules in vendor_overlay instead of vendor |
Sebastiano Barezzi | c251f1b | 2021-02-09 00:31:49 +0100 | [diff] [blame] | 67 | # |
| 68 | # TARGET_FORCE_PREBUILT_KERNEL = Optional, use TARGET_PREBUILT_KERNEL even if |
| 69 | # kernel sources are present |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 70 | |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 71 | ifneq ($(TARGET_NO_KERNEL),true) |
LuK1337 | d034c3f | 2020-09-15 11:06:18 +0200 | [diff] [blame] | 72 | ifneq ($(TARGET_NO_KERNEL_OVERRIDE),true) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 73 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 74 | ## Externally influenced variables |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 75 | KERNEL_SRC := $(TARGET_KERNEL_SOURCE) |
| 76 | # kernel configuration - mandatory |
| 77 | KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 78 | RECOVERY_DEFCONFIG := $(TARGET_KERNEL_RECOVERY_CONFIG) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 79 | VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG) |
| 80 | SELINUX_DEFCONFIG := $(TARGET_KERNEL_SELINUX_CONFIG) |
| 81 | |
| 82 | ## Internal variables |
Rashed Abdel-Tawab | e523884 | 2019-10-15 00:56:52 -0400 | [diff] [blame] | 83 | DTC := $(HOST_OUT_EXECUTABLES)/dtc |
Michael Bestas | 75784d0 | 2022-09-09 13:36:19 +0300 | [diff] [blame] | 84 | PAHOLE := $(HOST_OUT_EXECUTABLES)/pahole |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 85 | KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 86 | RECOVERY_KERNEL_OUT := $(TARGET_OUT_INTERMEDIATES)/RECOVERY_KERNEL_OBJ |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 87 | DTBO_OUT := $(TARGET_OUT_INTERMEDIATES)/DTBO_OBJ |
| 88 | DTB_OUT := $(TARGET_OUT_INTERMEDIATES)/DTB_OBJ |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 89 | ifeq ($(BOARD_USES_QCOM_MERGE_DTBS_SCRIPT),true) |
| 90 | DTBS_BASE := $(DTB_OUT)/base |
| 91 | DTBS_OUT := $(DTB_OUT)/out |
| 92 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 93 | KERNEL_CONFIG := $(KERNEL_OUT)/.config |
LuK1337 | 6047f5a | 2019-07-12 12:55:35 +0200 | [diff] [blame] | 94 | KERNEL_RELEASE := $(KERNEL_OUT)/include/config/kernel.release |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 95 | RECOVERY_KERNEL_CONFIG := $(RECOVERY_KERNEL_OUT)/.config |
| 96 | RECOVERY_KERNEL_RELEASE := $(RECOVERY_KERNEL_OUT)/include/config/kernel.release |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 97 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 98 | ifeq ($(KERNEL_ARCH),x86_64) |
| 99 | KERNEL_DEFCONFIG_ARCH := x86 |
| 100 | else |
| 101 | KERNEL_DEFCONFIG_ARCH := $(KERNEL_ARCH) |
| 102 | endif |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 103 | KERNEL_DEFCONFIG_DIR := $(KERNEL_SRC)/arch/$(KERNEL_DEFCONFIG_ARCH)/configs |
Sebastiano Barezzi | 94b9680 | 2022-03-16 17:42:13 +0100 | [diff] [blame] | 104 | ALL_KERNEL_DEFCONFIG_SRCS := $(foreach config,$(KERNEL_DEFCONFIG),$(KERNEL_DEFCONFIG_DIR)/$(config)) |
| 105 | ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS := $(foreach config,$(RECOVERY_DEFCONFIG),$(KERNEL_DEFCONFIG_DIR)/$(config)) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 106 | |
Sebastiano Barezzi | 94b9680 | 2022-03-16 17:42:13 +0100 | [diff] [blame] | 107 | BASE_KERNEL_DEFCONFIG := $(word 1, $(KERNEL_DEFCONFIG)) |
| 108 | BASE_KERNEL_DEFCONFIG_SRC := $(word 1, $(ALL_KERNEL_DEFCONFIG_SRCS)) |
| 109 | BASE_RECOVERY_KERNEL_DEFCONFIG := $(word 1, $(RECOVERY_DEFCONFIG)) |
| 110 | BASE_RECOVERY_KERNEL_DEFCONFIG_SRC := $(word 1, $(ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS)) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 111 | |
Aayush Gupta | 3ebfa5e | 2020-10-27 17:59:21 +0530 | [diff] [blame] | 112 | ifeq ($(TARGET_PREBUILT_KERNEL),) |
| 113 | ifeq ($(BOARD_KERNEL_IMAGE_NAME),) |
| 114 | $(error BOARD_KERNEL_IMAGE_NAME not defined.) |
| 115 | endif |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 116 | endif |
| 117 | TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/$(BOARD_KERNEL_IMAGE_NAME) |
| 118 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 119 | TARGET_PREBUILT_INT_RECOVERY_KERNEL := $(RECOVERY_KERNEL_OUT)/arch/$(KERNEL_ARCH)/boot/$(BOARD_KERNEL_IMAGE_NAME) |
| 120 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 121 | ifeq "$(wildcard $(KERNEL_SRC) )" "" |
| 122 | ifneq ($(TARGET_PREBUILT_KERNEL),) |
| 123 | HAS_PREBUILT_KERNEL := true |
| 124 | NEEDS_KERNEL_COPY := true |
| 125 | else |
| 126 | $(foreach cf,$(PRODUCT_COPY_FILES), \ |
| 127 | $(eval _src := $(call word-colon,1,$(cf))) \ |
| 128 | $(eval _dest := $(call word-colon,2,$(cf))) \ |
| 129 | $(ifeq kernel,$(_dest), \ |
| 130 | $(eval HAS_PREBUILT_KERNEL := true))) |
| 131 | endif |
| 132 | |
| 133 | ifneq ($(HAS_PREBUILT_KERNEL),) |
| 134 | $(warning ***************************************************************) |
| 135 | $(warning * Using prebuilt kernel binary instead of source *) |
Nolen Johnson | c0b837d | 2020-04-17 13:13:20 -0400 | [diff] [blame] | 136 | $(warning * THIS IS DEPRECATED, AND IS NOT ADVISED. *) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 137 | $(warning * Please configure your device to download the kernel *) |
| 138 | $(warning * source repository to $(KERNEL_SRC)) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 139 | $(warning * for more information *) |
| 140 | $(warning ***************************************************************) |
| 141 | FULL_KERNEL_BUILD := false |
| 142 | KERNEL_BIN := $(TARGET_PREBUILT_KERNEL) |
| 143 | else |
| 144 | $(warning ***************************************************************) |
| 145 | $(warning * *) |
| 146 | $(warning * No kernel source found, and no fallback prebuilt defined. *) |
| 147 | $(warning * Please make sure your device is properly configured to *) |
| 148 | $(warning * download the kernel repository to $(KERNEL_SRC)) |
| 149 | $(warning * and add the TARGET_KERNEL_CONFIG variable to BoardConfig.mk *) |
| 150 | $(warning * *) |
| 151 | $(warning * As an alternative, define the TARGET_PREBUILT_KERNEL *) |
| 152 | $(warning * variable with the path to the prebuilt binary kernel image *) |
| 153 | $(warning * in your BoardConfig.mk file *) |
| 154 | $(warning * *) |
| 155 | $(warning ***************************************************************) |
| 156 | $(error "NO KERNEL") |
| 157 | endif |
| 158 | else |
| 159 | NEEDS_KERNEL_COPY := true |
| 160 | ifeq ($(TARGET_KERNEL_CONFIG),) |
| 161 | $(warning **********************************************************) |
| 162 | $(warning * Kernel source found, but no configuration was defined *) |
| 163 | $(warning * Please add the TARGET_KERNEL_CONFIG variable to your *) |
| 164 | $(warning * BoardConfig.mk file *) |
| 165 | $(warning **********************************************************) |
Luca Stefani | fb58f78 | 2020-08-03 11:32:19 +0200 | [diff] [blame] | 166 | $(error "NO KERNEL CONFIG") |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 167 | else |
Tim Schumacher | 6303cd7 | 2021-06-27 11:27:27 +0200 | [diff] [blame] | 168 | ifneq ($(TARGET_FORCE_PREBUILT_KERNEL),) |
| 169 | ifneq ($(filter RELEASE NIGHTLY SNAPSHOT EXPERIMENTAL,$(LINEAGE_BUILDTYPE)),) |
| 170 | $(error "PREBUILT KERNEL IS NOT ALLOWED ON OFFICIAL BUILDS!") |
| 171 | else |
Sebastiano Barezzi | c251f1b | 2021-02-09 00:31:49 +0100 | [diff] [blame] | 172 | $(warning **********************************************************) |
| 173 | $(warning * Kernel source found and configuration was defined, *) |
| 174 | $(warning * but prebuilt kernel is being forced. *) |
| 175 | $(warning * While this is likely intentional, *) |
| 176 | $(warning * it is NOT SUPPORTED WHATSOEVER. *) |
| 177 | $(warning * Generated kernel headers may not align with *) |
| 178 | $(warning * the ABI of kernel you're including. *) |
| 179 | $(warning * Please unset TARGET_FORCE_PREBUILT_KERNEL *) |
| 180 | $(warning * to build the kernel from source. *) |
| 181 | $(warning **********************************************************) |
| 182 | FULL_KERNEL_BUILD := false |
| 183 | KERNEL_BIN := $(TARGET_PREBUILT_KERNEL) |
Sebastiano Barezzi | c251f1b | 2021-02-09 00:31:49 +0100 | [diff] [blame] | 184 | endif |
Tim Schumacher | 6303cd7 | 2021-06-27 11:27:27 +0200 | [diff] [blame] | 185 | else |
| 186 | FULL_KERNEL_BUILD := true |
| 187 | KERNEL_BIN := $(TARGET_PREBUILT_INT_KERNEL) |
Sebastiano Barezzi | c251f1b | 2021-02-09 00:31:49 +0100 | [diff] [blame] | 188 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 189 | endif |
| 190 | endif |
| 191 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 192 | ifneq ($(TARGET_KERNEL_RECOVERY_CONFIG),) |
| 193 | ifeq "$(wildcard $(KERNEL_SRC) )" "" |
| 194 | ifeq ($(TARGET_PREBUILT_RECOVERY_KERNEL),) |
| 195 | $(warning ***************************************************************) |
| 196 | $(warning * *) |
| 197 | $(warning * No recovery kernel source found, and no fallback prebuilt *) |
| 198 | $(warning * defined. Please make sure your device is properly *) |
| 199 | $(warning * configured to download the kernel repository to $(KERNEL_SRC)) |
| 200 | $(warning * or remove TARGET_KERNEL_RECOVERY_CONFIG from BoardConfig.mk *) |
| 201 | $(warning * *) |
| 202 | $(warning * Or, define the TARGET_PREBUILT_RECOVERY_KERNEL *) |
| 203 | $(warning * variable with the path to the prebuilt recovery kernel image*) |
| 204 | $(warning * in your BoardConfig.mk file *) |
| 205 | $(warning * *) |
| 206 | $(warning ***************************************************************) |
| 207 | $(error "NO RECOVERY KERNEL SOURCE") |
| 208 | endif |
| 209 | endif |
| 210 | ifneq ($(BOARD_USES_RECOVERY_AS_BOOT),) |
| 211 | $(warning ********************************************************) |
| 212 | $(warning * TARGET_KERNEL_RECOVERY_CONFIG set but device uses *) |
| 213 | $(warning * RECOVERY_AS_BOOT, which uses boot kernel as recovery *) |
| 214 | $(warning * kernel, as such it's not possible to use different *) |
| 215 | $(warning * configs *) |
| 216 | $(warning ********************************************************) |
| 217 | $(error "INVALID CONFIGURATION") |
| 218 | else |
| 219 | FULL_RECOVERY_KERNEL_BUILD := true |
| 220 | RECOVERY_KERNEL_COPY := true |
| 221 | RECOVERY_BIN := $(TARGET_PREBUILT_INT_RECOVERY_KERNEL) |
| 222 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 223 | else |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 224 | ifneq ($(TARGET_PREBUILT_RECOVERY_KERNEL),) |
| 225 | RECOVERY_BIN := $(TARGET_PREBUILT_RECOVERY_KERNEL) |
| 226 | RECOVERY_KERNEL_COPY := true |
| 227 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 228 | endif |
| 229 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 230 | ifeq ($(or $(FULL_RECOVERY_KERNEL_BUILD), $(FULL_KERNEL_BUILD)),true) |
Rashed Abdel-Tawab | e523884 | 2019-10-15 00:56:52 -0400 | [diff] [blame] | 231 | # Add host bin out dir to path |
| 232 | PATH_OVERRIDE := PATH=$(KERNEL_BUILD_OUT_PREFIX)$(HOST_OUT_EXECUTABLES):$$PATH |
Alexander Koskovich | e8e46e6 | 2022-03-07 11:29:34 -0700 | [diff] [blame] | 233 | ifneq ($(TARGET_KERNEL_CLANG_COMPILE),false) |
Michael Bestas | 38ba7c0 | 2022-11-14 13:09:00 +0200 | [diff] [blame] | 234 | ifneq ($(KERNEL_NO_GCC), true) |
Michael Bestas | 3b11b2a | 2022-09-10 23:19:55 +0300 | [diff] [blame] | 235 | ifeq ($(KERNEL_ARCH),arm64) |
| 236 | KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=aarch64-linux-gnu- |
| 237 | else ifeq ($(KERNEL_ARCH),arm) |
| 238 | KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=arm-linux-gnu- |
| 239 | else ifeq ($(KERNEL_ARCH),x86) |
| 240 | KERNEL_CLANG_TRIPLE ?= CLANG_TRIPLE=x86_64-linux-gnu- |
| 241 | endif |
Michael Bestas | 8514063 | 2022-11-01 14:48:50 +0200 | [diff] [blame] | 242 | PATH_OVERRIDE += LD_LIBRARY_PATH=$(TARGET_KERNEL_CLANG_PATH)/lib64:$$LD_LIBRARY_PATH |
Joe Maples | da32895 | 2017-11-27 10:09:38 -0500 | [diff] [blame] | 243 | endif |
Michael Bestas | 8514063 | 2022-11-01 14:48:50 +0200 | [diff] [blame] | 244 | PATH_OVERRIDE += PATH=$(TARGET_KERNEL_CLANG_PATH)/bin:$$PATH |
Dan Pasanen | f65a6df | 2018-02-18 22:13:05 -0600 | [diff] [blame] | 245 | ifeq ($(KERNEL_CC),) |
dianlujitao | 8ff9727 | 2023-03-02 20:29:25 +0800 | [diff] [blame] | 246 | CLANG_EXTRA_FLAGS := --cuda-path=/dev/null |
| 247 | ifeq ($(shell $(TARGET_KERNEL_CLANG_PATH)/bin/clang -v --hip-path=/dev/null >/dev/null 2>&1; echo $$?),0) |
| 248 | CLANG_EXTRA_FLAGS += --hip-path=/dev/null |
| 249 | endif |
| 250 | KERNEL_CC := CC="$(CCACHE_BIN) clang $(CLANG_EXTRA_FLAGS)" |
Dan Pasanen | f65a6df | 2018-02-18 22:13:05 -0600 | [diff] [blame] | 251 | endif |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 252 | endif |
| 253 | |
Michael Bestas | 38ba7c0 | 2022-11-14 13:09:00 +0200 | [diff] [blame] | 254 | ifneq ($(KERNEL_NO_GCC), true) |
| 255 | PATH_OVERRIDE += PATH=$(KERNEL_TOOLCHAIN_PATH_gcc):$$PATH |
Michael Bestas | 3b11b2a | 2022-09-10 23:19:55 +0300 | [diff] [blame] | 256 | endif |
Rashed Abdel-Tawab | c648519 | 2019-09-10 08:38:34 -0700 | [diff] [blame] | 257 | |
Rashed Abdel-Tawab | dfc3d18 | 2019-09-06 10:44:50 -0700 | [diff] [blame] | 258 | # System tools are no longer allowed on 10+ |
| 259 | PATH_OVERRIDE += $(TOOLS_PATH_OVERRIDE) |
| 260 | |
Alexander Koskovich | 766d324 | 2022-06-15 22:50:47 -0700 | [diff] [blame] | 261 | ifeq (true,$(filter true, $(TARGET_NEEDS_DTBOIMAGE) $(BOARD_KERNEL_SEPARATED_DTBO))) |
| 262 | KERNEL_MAKE_FLAGS += DTC_EXT=$(KERNEL_BUILD_OUT_PREFIX)$(DTC) |
| 263 | endif |
| 264 | |
Alexander Koskovich | 8da3fa2 | 2022-06-16 13:14:14 -0700 | [diff] [blame] | 265 | ifneq ($(TARGET_KERNEL_ADDITIONAL_FLAGS),) |
| 266 | KERNEL_MAKE_FLAGS += $(TARGET_KERNEL_ADDITIONAL_FLAGS) |
| 267 | endif |
| 268 | |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 269 | # Internal implementation of make-kernel-target |
| 270 | # $(1): output path (The value passed to O=) |
| 271 | # $(2): target to build (eg. defconfig, modules, dtbo.img) |
| 272 | define internal-make-kernel-target |
Michael Bestas | 747c6ed | 2022-08-28 16:44:19 +0300 | [diff] [blame] | 273 | $(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] | 274 | endef |
| 275 | |
Neel Chauhan | e546ac8 | 2022-07-21 09:30:48 -0700 | [diff] [blame] | 276 | # Make an external module target |
| 277 | # $(1): module name |
| 278 | # $(2): module root path |
| 279 | # $(3): target to build (eg. modules_install) |
| 280 | define make-external-module-target |
Michael Bestas | 747c6ed | 2022-08-28 16:44:19 +0300 | [diff] [blame] | 281 | $(PATH_OVERRIDE) $(KERNEL_MAKE_CMD) $(KERNEL_MAKE_FLAGS) -C $(TARGET_KERNEL_EXT_MODULE_ROOT)/$(1) M=$(2)/$(1) KERNEL_SRC=$(BUILD_TOP)/$(KERNEL_SRC) OUT_DIR=$(KERNEL_BUILD_OUT_PREFIX)$(KERNEL_OUT) O=$(KERNEL_BUILD_OUT_PREFIX)$(KERNEL_OUT) ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) $(KERNEL_CLANG_TRIPLE) $(KERNEL_CC) $(3) |
Neel Chauhan | e546ac8 | 2022-07-21 09:30:48 -0700 | [diff] [blame] | 282 | endef |
| 283 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 284 | # Generate kernel .config from a given defconfig |
| 285 | # $(1): Output path (The value passed to O=) |
| 286 | # $(2): The defconfig to process (just the filename, no need for full path to file) |
| 287 | define make-kernel-config |
| 288 | $(call internal-make-kernel-target,$(1),VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(2)) |
Chirayu Desai | 3eed09a | 2021-12-03 22:39:46 +0530 | [diff] [blame] | 289 | $(hide) if [ "$(KERNEL_LTO)" = "none" ]; then \ |
| 290 | $(KERNEL_SRC)/scripts/config --file $(1)/.config \ |
| 291 | -d LTO_CLANG \ |
| 292 | -e LTO_NONE \ |
| 293 | -d LTO_CLANG_THIN \ |
| 294 | -d LTO_CLANG_FULL \ |
| 295 | -d THINLTO; \ |
| 296 | $(call make-kernel-target,olddefconfig); \ |
| 297 | elif [ "$(KERNEL_LTO)" = "thin" ]; then \ |
| 298 | $(KERNEL_SRC)/scripts/config --file $(1)/.config \ |
| 299 | -e LTO_CLANG \ |
| 300 | -d LTO_NONE \ |
| 301 | -e LTO_CLANG_THIN \ |
| 302 | -d LTO_CLANG_FULL \ |
| 303 | -e THINLTO; \ |
| 304 | $(call make-kernel-target,olddefconfig); \ |
| 305 | elif [ "$(KERNEL_LTO)" = "full" ]; then \ |
| 306 | $(KERNEL_SRC)/scripts/config --file $(1)/.config \ |
| 307 | -e LTO_CLANG \ |
| 308 | -d LTO_NONE \ |
| 309 | -d LTO_CLANG_THIN \ |
| 310 | -e LTO_CLANG_FULL \ |
| 311 | -d THINLTO; \ |
| 312 | $(call make-kernel-target,olddefconfig); \ |
| 313 | fi |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 314 | $(hide) if [ ! -z "$(KERNEL_CONFIG_OVERRIDE)" ]; then \ |
| 315 | echo "Overriding kernel config with '$(KERNEL_CONFIG_OVERRIDE)'"; \ |
| 316 | echo $(KERNEL_CONFIG_OVERRIDE) >> $(1)/.config; \ |
| 317 | $(call make-kernel-target,oldconfig); \ |
| 318 | fi |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 319 | endef |
| 320 | |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 321 | # Make a kernel target |
| 322 | # $(1): The kernel target to build (eg. defconfig, modules, modules_install) |
| 323 | define make-kernel-target |
| 324 | $(call internal-make-kernel-target,$(KERNEL_OUT),$(1)) |
| 325 | endef |
| 326 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 327 | # Make a recovery kernel target |
| 328 | # $(1): The kernel target to build (eg. defconfig, modules, modules_install) |
| 329 | define make-recovery-kernel-target |
| 330 | $(call internal-make-kernel-target,$(RECOVERY_KERNEL_OUT),$(1)) |
| 331 | endef |
| 332 | |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 333 | # Make a DTBO target |
| 334 | # $(1): The DTBO target to build (eg. dtbo.img, defconfig) |
| 335 | define make-dtbo-target |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 336 | $(call internal-make-kernel-target,$(DTBO_OUT),$(1)) |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 337 | endef |
| 338 | |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 339 | # Make a DTB targets |
| 340 | # $(1): The DTB target to build (eg. dtbs, defconfig) |
| 341 | define make-dtb-target |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 342 | $(call internal-make-kernel-target,$(DTB_OUT),$(1)) |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 343 | endef |
| 344 | |
Alessandro Astone | 1ab6313 | 2020-09-14 21:14:47 +0200 | [diff] [blame] | 345 | # $(1): modules list |
| 346 | # $(2): output dir |
| 347 | # $(3): mount point |
| 348 | # $(4): staging dir |
Alessandro Astone | 8d6e3d6 | 2021-01-08 17:43:27 +0100 | [diff] [blame] | 349 | # $(5): module load list |
Alessandro Astone | 1ab6313 | 2020-09-14 21:14:47 +0200 | [diff] [blame] | 350 | # Depmod requires a well-formed kernel version so 0.0 is used as a placeholder. |
| 351 | define build-image-kernel-modules-lineage |
Alessandro Astone | 1ab6313 | 2020-09-14 21:14:47 +0200 | [diff] [blame] | 352 | mkdir -p $(2)/lib/modules |
| 353 | cp $(1) $(2)/lib/modules/ |
| 354 | rm -rf $(4) |
| 355 | mkdir -p $(4)/lib/modules/0.0/$(3)lib/modules |
| 356 | cp $(1) $(4)/lib/modules/0.0/$(3)lib/modules |
| 357 | $(DEPMOD) -b $(4) 0.0 |
| 358 | 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] | 359 | cp $(4)/lib/modules/0.0/modules.softdep $(2)/lib/modules |
Alessandro Astone | 1ab6313 | 2020-09-14 21:14:47 +0200 | [diff] [blame] | 360 | cp $(4)/lib/modules/0.0/modules.alias $(2)/lib/modules |
Alessandro Astone | 8d6e3d6 | 2021-01-08 17:43:27 +0100 | [diff] [blame] | 361 | rm -f $(2)/lib/modules/modules.load |
| 362 | for MODULE in $(5); do \ |
| 363 | basename $$MODULE >> $(2)/lib/modules/modules.load; \ |
| 364 | done |
Alessandro Astone | 1ab6313 | 2020-09-14 21:14:47 +0200 | [diff] [blame] | 365 | endef |
| 366 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 367 | endif # FULL_RECOVERY_KERNEL_BUILD or FULL_KERNEL_BUILD |
| 368 | |
| 369 | ifeq ($(FULL_KERNEL_BUILD),true) |
| 370 | |
| 371 | ifeq ($(NEED_KERNEL_MODULE_ROOT),true) |
| 372 | KERNEL_MODULES_OUT := $(TARGET_ROOT_OUT) |
| 373 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_recovery) |
| 374 | KERNEL_MODULE_MOUNTPOINT := |
| 375 | else ifeq ($(NEED_KERNEL_MODULE_SYSTEM),true) |
| 376 | KERNEL_MODULES_OUT := $(TARGET_OUT) |
| 377 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_system) |
| 378 | KERNEL_MODULE_MOUNTPOINT := system |
| 379 | $(INSTALLED_SYSTEMIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL) |
| 380 | else ifeq ($(NEED_KERNEL_MODULE_VENDOR_OVERLAY),true) |
| 381 | KERNEL_MODULES_OUT := $(TARGET_OUT_PRODUCT)/vendor_overlay/$(PRODUCT_TARGET_VNDK_VERSION) |
| 382 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_product) |
| 383 | KERNEL_MODULE_MOUNTPOINT := vendor |
| 384 | $(INSTALLED_PRODUCTIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL) |
Alexander Koskovich | 20ca83c | 2022-01-22 22:26:50 -0700 | [diff] [blame] | 385 | else ifeq ($(BOARD_USES_VENDOR_DLKMIMAGE),true) |
| 386 | KERNEL_MODULES_OUT := $(TARGET_OUT_VENDOR_DLKM) |
| 387 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor) |
| 388 | KERNEL_MODULE_MOUNTPOINT := vendor_dlkm |
| 389 | $(INSTALLED_VENDOR_DLKMIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 390 | else |
| 391 | KERNEL_MODULES_OUT := $(TARGET_OUT_VENDOR) |
| 392 | KERNEL_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor) |
| 393 | KERNEL_MODULE_MOUNTPOINT := vendor |
| 394 | $(INSTALLED_VENDORIMAGE_TARGET): $(TARGET_PREBUILT_INT_KERNEL) |
| 395 | endif |
| 396 | MODULES_INTERMEDIATES := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,kernel_modules) |
| 397 | |
Michael Bestas | 6a9eaf0 | 2022-08-13 02:56:34 +0300 | [diff] [blame] | 398 | ifneq (,$(filter dlkm,$(BOARD_VENDOR_RAMDISK_FRAGMENTS))) |
| 399 | KERNEL_VENDOR_RAMDISK_MODULES_OUT := $(VENDOR_RAMDISK_FRAGMENT.dlkm.STAGING_DIR) |
| 400 | KERNEL_VENDOR_RAMDISK_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor_ramdisk_fragment-stage-dlkm) |
| 401 | $(INTERNAL_VENDOR_RAMDISK_FRAGMENT_TARGETS): $(TARGET_PREBUILT_INT_KERNEL) |
Michael Bestas | ecdaea3 | 2022-11-04 02:12:03 +0200 | [diff] [blame] | 402 | else ifeq ($(PRODUCT_BUILD_VENDOR_KERNEL_BOOT_IMAGE),true) |
| 403 | KERNEL_VENDOR_RAMDISK_MODULES_OUT := $(TARGET_VENDOR_KERNEL_RAMDISK_OUT) |
| 404 | KERNEL_VENDOR_RAMDISK_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor_kernel_ramdisk) |
| 405 | $(INTERNAL_VENDOR_KERNEL_RAMDISK_TARGET): $(TARGET_PREBUILT_INT_KERNEL) |
Michael Bestas | 6a9eaf0 | 2022-08-13 02:56:34 +0300 | [diff] [blame] | 406 | else |
| 407 | KERNEL_VENDOR_RAMDISK_MODULES_OUT := $(TARGET_VENDOR_RAMDISK_OUT) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 408 | KERNEL_VENDOR_RAMDISK_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_vendor_ramdisk) |
| 409 | $(INTERNAL_VENDOR_RAMDISK_TARGET): $(TARGET_PREBUILT_INT_KERNEL) |
Michael Bestas | 6a9eaf0 | 2022-08-13 02:56:34 +0300 | [diff] [blame] | 410 | endif |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 411 | |
Aaron Kling | d985814 | 2023-08-10 16:20:52 -0500 | [diff] [blame] | 412 | ifneq ($(RECOVERY_KERNEL_MODULES),) |
| 413 | KERNEL_RECOVERY_DEPMOD_STAGING_DIR := $(KERNEL_BUILD_OUT_PREFIX)$(call intermediates-dir-for,PACKAGING,depmod_recovery) |
| 414 | KERNEL_RECOVERY_MODULES_OUT := $(TARGET_RECOVERY_ROOT_OUT) |
| 415 | $(recovery_uncompressed_ramdisk): $(TARGET_PREBUILT_INT_KERNEL) |
| 416 | endif |
| 417 | |
Luca Stefani | e30626d | 2020-09-03 20:56:29 +0200 | [diff] [blame] | 418 | $(KERNEL_OUT): |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 419 | mkdir -p $(KERNEL_OUT) |
Luca Stefani | e30626d | 2020-09-03 20:56:29 +0200 | [diff] [blame] | 420 | |
Bruno Martins | 3bd34be | 2022-04-08 19:37:17 +0100 | [diff] [blame] | 421 | $(KERNEL_CONFIG): $(KERNEL_OUT) $(ALL_KERNEL_DEFCONFIG_SRCS) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 422 | @echo "Building Kernel Config" |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 423 | $(call make-kernel-config,$(KERNEL_OUT),$(KERNEL_DEFCONFIG)) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 424 | |
Michael Bestas | 75784d0 | 2022-09-09 13:36:19 +0300 | [diff] [blame] | 425 | $(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC) $(PAHOLE) |
Rashed Abdel-Tawab | e523884 | 2019-10-15 00:56:52 -0400 | [diff] [blame] | 426 | @echo "Building Kernel Image ($(BOARD_KERNEL_IMAGE_NAME))" |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 427 | $(call make-kernel-target,$(BOARD_KERNEL_IMAGE_NAME)) |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 428 | $(hide) if grep -q '^CONFIG_OF=y' $(KERNEL_CONFIG); then \ |
| 429 | echo "Building DTBs"; \ |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 430 | $(call make-kernel-target,dtbs); \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 431 | fi |
Ethan Chen | 0724f78 | 2019-02-09 21:05:01 -0800 | [diff] [blame] | 432 | $(hide) if grep -q '=m' $(KERNEL_CONFIG); then \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 433 | echo "Building Kernel Modules"; \ |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 434 | $(call make-kernel-target,modules) || exit "$$?"; \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 435 | echo "Installing Kernel Modules"; \ |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 436 | $(call make-kernel-target,INSTALL_MOD_PATH=$(MODULES_INTERMEDIATES) INSTALL_MOD_STRIP=1 modules_install); \ |
Neel Chauhan | e546ac8 | 2022-07-21 09:30:48 -0700 | [diff] [blame] | 437 | $(if $(TARGET_KERNEL_EXT_MODULES),\ |
| 438 | echo "Building and Installing External Kernel Modules"; \ |
| 439 | rpath=$$(python3 -c 'import os,sys;print(os.path.relpath(*(sys.argv[1:])))' $(TARGET_KERNEL_EXT_MODULE_ROOT) $(KERNEL_SRC)); \ |
| 440 | $(foreach p, $(TARGET_KERNEL_EXT_MODULES),\ |
| 441 | $$pwd; \ |
| 442 | $(call make-external-module-target,$(p),$$rpath,); \ |
| 443 | $(call make-external-module-target,$(p),$$rpath,INSTALL_MOD_PATH=$(MODULES_INTERMEDIATES) INSTALL_MOD_STRIP=1 KERNEL_UAPI_HEADERS_DIR=$(KERNEL_OUT) modules_install)); \ |
| 444 | ) \ |
LuK1337 | 6047f5a | 2019-07-12 12:55:35 +0200 | [diff] [blame] | 445 | kernel_release=$$(cat $(KERNEL_RELEASE)) \ |
Luca Stefani | 4b7a0a0 | 2020-08-01 21:20:23 +0200 | [diff] [blame] | 446 | kernel_modules_dir=$(MODULES_INTERMEDIATES)/lib/modules/$$kernel_release \ |
| 447 | $(foreach s, $(TARGET_MODULE_ALIASES),\ |
| 448 | $(eval p := $(subst :,$(space),$(s))) \ |
| 449 | ; mv $$(find $$kernel_modules_dir -name $(word 1,$(p))) $$kernel_modules_dir/$(word 2,$(p))); \ |
| 450 | modules=$$(find $$kernel_modules_dir -type f -name '*.ko'); \ |
Alessandro Astone | 8d6e3d6 | 2021-01-08 17:43:27 +0100 | [diff] [blame] | 451 | ($(call build-image-kernel-modules-lineage,$$modules,$(KERNEL_MODULES_OUT),$(KERNEL_MODULE_MOUNTPOINT)/,$(KERNEL_DEPMOD_STAGING_DIR),$(BOARD_VENDOR_KERNEL_MODULES_LOAD))); \ |
| 452 | $(if $(BOOT_KERNEL_MODULES),\ |
| 453 | vendor_boot_modules=$$(for m in $(BOOT_KERNEL_MODULES); do \ |
| 454 | p=$$(find $$kernel_modules_dir -type f -name $$m); \ |
| 455 | if [ -n "$$p" ]; then echo $$p; else echo "ERROR: $$m from BOOT_KERNEL_MODULES was not found" 1>&2 && exit 1; fi; \ |
| 456 | done); \ |
| 457 | [ $$? -ne 0 ] && exit 1; \ |
Michael Bestas | 6a9eaf0 | 2022-08-13 02:56:34 +0300 | [diff] [blame] | 458 | ($(call build-image-kernel-modules-lineage,$$vendor_boot_modules,$(KERNEL_VENDOR_RAMDISK_MODULES_OUT),/,$(KERNEL_VENDOR_RAMDISK_DEPMOD_STAGING_DIR),$(BOARD_VENDOR_RAMDISK_KERNEL_MODULES_LOAD))); \ |
Alessandro Astone | 8d6e3d6 | 2021-01-08 17:43:27 +0100 | [diff] [blame] | 459 | ) \ |
Aaron Kling | d985814 | 2023-08-10 16:20:52 -0500 | [diff] [blame] | 460 | $(if $(RECOVERY_KERNEL_MODULES),\ |
| 461 | recovery_modules=$$(for m in $(RECOVERY_KERNEL_MODULES); do \ |
| 462 | p=$$(find $$kernel_modules_dir -type f -name $$m); \ |
| 463 | if [ -n "$$p" ]; then echo $$p; else echo "ERROR: $$m from RECOVERY_KERNEL_MODULES was not found" 1>&2 && exit 1; fi; \ |
| 464 | done); \ |
| 465 | [ $$? -ne 0 ] && exit 1; \ |
| 466 | ($(call build-image-kernel-modules-lineage,$$recovery_modules,$(KERNEL_RECOVERY_MODULES_OUT),/,$(KERNEL_RECOVERY_DEPMOD_STAGING_DIR),$(BOARD_RECOVERY_RAMDISK_KERNEL_MODULES_LOAD))); \ |
| 467 | ) \ |
Tom Marshall | f15c371 | 2017-11-10 01:00:18 +0100 | [diff] [blame] | 468 | fi |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 469 | |
Tom Marshall | 6b83d83 | 2017-11-09 21:02:33 +0100 | [diff] [blame] | 470 | .PHONY: kerneltags |
| 471 | kerneltags: $(KERNEL_CONFIG) |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 472 | $(call make-kernel-target,tags) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 473 | |
Michael Bestas | b4c4aba | 2018-10-06 22:12:10 +0300 | [diff] [blame] | 474 | .PHONY: kernelsavedefconfig alldefconfig |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 475 | |
Luca Stefani | e30626d | 2020-09-03 20:56:29 +0200 | [diff] [blame] | 476 | kernelsavedefconfig: $(KERNEL_OUT) |
Sebastiano Barezzi | 94b9680 | 2022-03-16 17:42:13 +0100 | [diff] [blame] | 477 | $(call make-kernel-config,$(KERNEL_OUT),$(BASE_KERNEL_DEFCONFIG)) |
dianlujitao | 4d3032a | 2022-06-12 17:07:30 +0800 | [diff] [blame] | 478 | $(call make-kernel-target,savedefconfig) |
Sebastiano Barezzi | 94b9680 | 2022-03-16 17:42:13 +0100 | [diff] [blame] | 479 | cp $(KERNEL_OUT)/defconfig $(BASE_KERNEL_DEFCONFIG_SRC) |
Michael Bestas | 296008c | 2017-07-12 20:56:35 +0300 | [diff] [blame] | 480 | |
Luca Stefani | e30626d | 2020-09-03 20:56:29 +0200 | [diff] [blame] | 481 | alldefconfig: $(KERNEL_OUT) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 482 | env KCONFIG_NOTIMESTAMP=true \ |
Ethan Chen | a325446 | 2019-02-09 16:26:51 -0800 | [diff] [blame] | 483 | $(call make-kernel-target,alldefconfig) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 484 | |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 485 | ifeq (true,$(filter true, $(TARGET_NEEDS_DTBOIMAGE) $(BOARD_KERNEL_SEPARATED_DTBO))) |
Aayush Gupta | 1de3b30 | 2020-08-25 10:03:10 +0000 | [diff] [blame] | 486 | ifneq ($(BOARD_CUSTOM_DTBOIMG_MK),) |
| 487 | include $(BOARD_CUSTOM_DTBOIMG_MK) |
| 488 | else |
Michael Bestas | 159555a | 2022-06-20 09:04:48 +0200 | [diff] [blame] | 489 | MKDTIMG := $(HOST_OUT_EXECUTABLES)/mkdtimg$(HOST_EXECUTABLE_SUFFIX) |
basamaryan | eaba762 | 2023-10-05 14:17:47 +0200 | [diff] [blame] | 490 | MKDTBOIMG := $(HOST_OUT_EXECUTABLES)/mkdtboimg$(HOST_EXECUTABLE_SUFFIX) |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 491 | |
| 492 | $(DTBO_OUT): |
| 493 | mkdir -p $(DTBO_OUT) |
| 494 | |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 495 | ifeq ($(BOARD_USES_QCOM_MERGE_DTBS_SCRIPT),true) |
| 496 | $(BOARD_PREBUILT_DTBOIMAGE): $(INSTALLED_DTBIMAGE_TARGET) |
| 497 | else |
| 498 | $(BOARD_PREBUILT_DTBOIMAGE): $(DTBO_OUT) |
| 499 | endif |
| 500 | $(BOARD_PREBUILT_DTBOIMAGE): $(DTC) $(MKDTIMG) $(MKDTBOIMG) |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 501 | $(BOARD_PREBUILT_DTBOIMAGE): |
| 502 | @echo "Building dtbo.img" |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 503 | ifeq ($(BOARD_USES_QCOM_MERGE_DTBS_SCRIPT),true) |
| 504 | $(MKDTBOIMG) create $@ --page_size=$(BOARD_KERNEL_PAGESIZE) $(shell find $(DTBS_OUT) -type f -name "*.dtbo" | sort) |
| 505 | else |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 506 | $(hide) find $(DTBO_OUT)/arch/$(KERNEL_ARCH)/boot/dts -type f -name "*.dtbo" | xargs rm -f |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 507 | $(call make-dtbo-target,$(KERNEL_DEFCONFIG)) |
Michael Bestas | dd6eaa5 | 2022-08-13 15:14:17 +0300 | [diff] [blame] | 508 | $(call make-dtbo-target,$(TARGET_KERNEL_DTB)) |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 509 | ifeq ($(BOARD_KERNEL_SEPARATED_DTBO),true) |
Luca Stefani | 05ce3dc | 2020-08-03 11:58:00 +0200 | [diff] [blame] | 510 | ifdef BOARD_DTBO_CFG |
| 511 | $(MKDTBOIMG) cfg_create $@ $(BOARD_DTBO_CFG) -d $(DTBO_OUT)/arch/$(KERNEL_ARCH)/boot/dts |
| 512 | else |
Luca Stefani | 16ea814 | 2020-08-05 11:37:46 +0200 | [diff] [blame] | 513 | $(MKDTBOIMG) create $@ --page_size=$(BOARD_KERNEL_PAGESIZE) $(shell find $(DTBO_OUT)/arch/$(KERNEL_ARCH)/boot/dts -type f -name "*.dtbo" | sort) |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 514 | endif # BOARD_DTBO_CFG |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 515 | else |
Michael Bestas | 15a631e | 2022-08-10 05:18:59 +0300 | [diff] [blame] | 516 | $(call make-dtbo-target,$(TARGET_KERNEL_DTBO)) |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 517 | endif # BOARD_KERNEL_SEPARATED_DTBO |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 518 | $(hide) touch -c $(DTBO_OUT) |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 519 | endif # BOARD_USES_QCOM_MERGE_DTBS_SCRIPT |
Aayush Gupta | 1de3b30 | 2020-08-25 10:03:10 +0000 | [diff] [blame] | 520 | endif # BOARD_CUSTOM_DTBOIMG_MK |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 521 | endif # TARGET_NEEDS_DTBOIMAGE/BOARD_KERNEL_SEPARATED_DTBO |
| 522 | |
| 523 | ifeq ($(BOARD_INCLUDE_DTB_IN_BOOTIMG),true) |
Aaron Kling | ca7e064 | 2022-10-17 00:17:13 -0500 | [diff] [blame] | 524 | ifneq ($(BOARD_CUSTOM_DTBIMG_MK),) |
| 525 | include $(BOARD_CUSTOM_DTBIMG_MK) |
| 526 | else |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 527 | ifeq ($(BOARD_PREBUILT_DTBIMAGE_DIR),) |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 528 | $(DTB_OUT): |
| 529 | mkdir -p $(DTB_OUT) |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 530 | ifeq ($(BOARD_USES_QCOM_MERGE_DTBS_SCRIPT),true) |
| 531 | $(DTBS_BASE): |
| 532 | mkdir -p $(DTBS_BASE) |
| 533 | $(DTBS_OUT): |
| 534 | mkdir -p $(DTBS_OUT) |
| 535 | endif |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 536 | |
Tim Zimmermann | a81136e | 2022-07-14 21:25:36 +0200 | [diff] [blame] | 537 | ifdef BOARD_DTB_CFG |
basamaryan | eaba762 | 2023-10-05 14:17:47 +0200 | [diff] [blame] | 538 | MKDTBOIMG := $(HOST_OUT_EXECUTABLES)/mkdtboimg$(HOST_EXECUTABLE_SUFFIX) |
Tim Zimmermann | a81136e | 2022-07-14 21:25:36 +0200 | [diff] [blame] | 539 | $(INSTALLED_DTBIMAGE_TARGET): $(MKDTBOIMG) |
| 540 | endif |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 541 | ifeq ($(BOARD_USES_QCOM_MERGE_DTBS_SCRIPT),true) |
| 542 | $(INSTALLED_DTBIMAGE_TARGET): $(HOST_OUT_EXECUTABLES)/fdtget $(HOST_OUT_EXECUTABLES)/fdtput $(HOST_OUT_EXECUTABLES)/fdtoverlay $(HOST_OUT_EXECUTABLES)/fdtoverlaymerge $(HOST_OUT_EXECUTABLES)/ufdt_apply_overlay $(DTBS_BASE) $(DTBS_OUT) |
| 543 | endif |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 544 | $(INSTALLED_DTBIMAGE_TARGET): $(DTC) $(DTB_OUT) |
Luca Stefani | d01da4c | 2022-09-12 17:55:12 -0400 | [diff] [blame] | 545 | ifeq ($(TARGET_WANTS_EMPTY_DTB),true) |
| 546 | @rm -f $@ |
| 547 | echo "empty" > $@ |
| 548 | else |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 549 | @echo "Building dtb.img" |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 550 | $(hide) find $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts -type f -name "*.dtb" | xargs rm -f |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 551 | $(call make-dtb-target,$(KERNEL_DEFCONFIG)) |
Michael Bestas | a7999b0 | 2022-08-10 05:29:55 +0300 | [diff] [blame] | 552 | $(call make-dtb-target,$(TARGET_KERNEL_DTB)) |
Tim Zimmermann | a81136e | 2022-07-14 21:25:36 +0200 | [diff] [blame] | 553 | ifdef BOARD_DTB_CFG |
| 554 | $(MKDTBOIMG) cfg_create $@ $(BOARD_DTB_CFG) -d $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts |
| 555 | else |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 556 | ifeq ($(BOARD_USES_QCOM_MERGE_DTBS_SCRIPT),true) |
| 557 | $(hide) find $(DTBS_BASE) -type f -name "*.dtb*" | xargs rm -f |
| 558 | $(hide) find $(DTBS_OUT) -type f -name "*.dtb*" | xargs rm -f |
| 559 | mv $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/qcom/*.dtb $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/qcom/*.dtbo $(DTBS_BASE)/ |
| 560 | PATH=$(abspath $(HOST_OUT_EXECUTABLES)):$${PATH} python3 $(BUILD_TOP)/vendor/lineage/build/tools/merge_dtbs.py $(DTBS_BASE) $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts/vendor/qcom $(DTBS_OUT) |
| 561 | cat $(shell find $(DTB_OUT)/out -type f -name "*.dtb" | sort) > $@ |
| 562 | else |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 563 | cat $(shell find $(DTB_OUT)/arch/$(KERNEL_ARCH)/boot/dts -type f -name "*.dtb" | sort) > $@ |
Aaron Kling | 5f122e1 | 2023-08-20 15:32:58 -0500 | [diff] [blame] | 564 | endif # BOARD_USES_QCOM_MERGE_DTBS_SCRIPT |
Tim Zimmermann | a81136e | 2022-07-14 21:25:36 +0200 | [diff] [blame] | 565 | endif # BOARD_DTB_CFG |
dianlujitao | 1933ed1 | 2022-06-12 18:50:34 +0800 | [diff] [blame] | 566 | $(hide) touch -c $(DTB_OUT) |
Luca Stefani | d01da4c | 2022-09-12 17:55:12 -0400 | [diff] [blame] | 567 | endif # !TARGET_WANTS_EMPTY_DTB |
| 568 | |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 569 | endif # !BOARD_PREBUILT_DTBIMAGE_DIR |
Aaron Kling | ca7e064 | 2022-10-17 00:17:13 -0500 | [diff] [blame] | 570 | endif # BOARD_CUSTOM_DTBIMG_MK |
Luca Stefani | fe00ea9 | 2020-08-02 19:08:31 +0200 | [diff] [blame] | 571 | endif # BOARD_INCLUDE_DTB_IN_BOOTIMG |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 572 | |
Ethan Chen | 117a0fd | 2019-02-10 12:12:50 -0800 | [diff] [blame] | 573 | endif # FULL_KERNEL_BUILD |
| 574 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 575 | ifeq ($(FULL_RECOVERY_KERNEL_BUILD),true) |
| 576 | |
| 577 | $(RECOVERY_KERNEL_OUT): |
| 578 | mkdir -p $(RECOVERY_KERNEL_OUT) |
| 579 | |
Bruno Martins | 164dfec | 2022-04-08 20:49:25 +0100 | [diff] [blame] | 580 | $(RECOVERY_KERNEL_CONFIG): $(ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 581 | @echo "Building Recovery Kernel Config" |
| 582 | $(call make-kernel-config,$(RECOVERY_KERNEL_OUT),$(RECOVERY_DEFCONFIG)) |
| 583 | |
Michael Bestas | 75784d0 | 2022-09-09 13:36:19 +0300 | [diff] [blame] | 584 | $(TARGET_PREBUILT_INT_RECOVERY_KERNEL): $(RECOVERY_KERNEL_CONFIG) $(DEPMOD) $(DTC) $(PAHOLE) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 585 | @echo "Building Recovery Kernel Image ($(BOARD_KERNEL_IMAGE_NAME))" |
| 586 | $(call make-recovery-kernel-target,$(BOARD_KERNEL_IMAGE_NAME)) |
| 587 | |
| 588 | |
| 589 | endif |
| 590 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 591 | ## Install it |
| 592 | |
| 593 | ifeq ($(NEEDS_KERNEL_COPY),true) |
dianlujitao | 660c13f | 2022-06-12 16:42:37 +0800 | [diff] [blame] | 594 | $(INSTALLED_KERNEL_TARGET): $(KERNEL_BIN) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 595 | $(transform-prebuilt-to-target) |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 596 | endif |
| 597 | |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 598 | ifeq ($(RECOVERY_KERNEL_COPY),true) |
dianlujitao | 660c13f | 2022-06-12 16:42:37 +0800 | [diff] [blame] | 599 | $(INSTALLED_RECOVERY_KERNEL_TARGET): $(RECOVERY_BIN) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 600 | $(transform-prebuilt-to-target) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 601 | endif |
| 602 | |
| 603 | .PHONY: recovery-kernel |
Jarl-Penguin | 91ed129 | 2022-02-20 13:26:31 +0100 | [diff] [blame] | 604 | recovery-kernel: $(INSTALLED_RECOVERY_KERNEL_TARGET) |
marcost2 | 9b4cfe0 | 2021-07-06 12:55:59 -0300 | [diff] [blame] | 605 | |
Michael Bestas | 3952f6c | 2016-08-26 01:12:08 +0300 | [diff] [blame] | 606 | .PHONY: kernel |
dianlujitao | f30ad9e | 2019-09-12 17:37:45 +0800 | [diff] [blame] | 607 | kernel: $(INSTALLED_KERNEL_TARGET) |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 608 | |
Rashed Abdel-Tawab | 60fe935 | 2019-05-16 14:01:19 -0700 | [diff] [blame] | 609 | .PHONY: dtboimage |
| 610 | dtboimage: $(INSTALLED_DTBOIMAGE_TARGET) |
Christian Oder | 8d5db3c | 2017-11-25 16:52:17 +0100 | [diff] [blame] | 611 | |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 612 | .PHONY: dtbimage |
| 613 | dtbimage: $(INSTALLED_DTBIMAGE_TARGET) |
Rashed Abdel-Tawab | 2c247d8 | 2019-09-27 23:37:14 -0400 | [diff] [blame] | 614 | |
LuK1337 | d034c3f | 2020-09-15 11:06:18 +0200 | [diff] [blame] | 615 | endif # TARGET_NO_KERNEL_OVERRIDE |
Dan Pasanen | 8ee5d89 | 2017-12-08 13:46:30 -0600 | [diff] [blame] | 616 | endif # TARGET_NO_KERNEL |