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