Skip to content

Commit 1b1687b

Browse files
me-cafebabeStricted
authored andcommitted
kernel: Add support for external kernel configs
For targets that uses mainline kernel, the kernel tree usually only contains configs on top of the upstream repository. In such case, if we put the configs in elsewhere, we can simply just track the upstream kernel repo, without needing to import configs. Example usage: TARGET_KERNEL_CONFIG_EXT := \ $(COMMON_PATH)/kconfig/platform_defconfig \ $(COMMON_PATH)/kconfig/common-addons.config TARGET_KERNEL_CONFIG_EXT += \ $(DEVICE_PATH)/kconfig/device.config Change-Id: I021ffb76d0c0612343cff7b5c81541c2b88ef7e6
1 parent f171568 commit 1b1687b

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

build/tasks/kernel.mk

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
# while all the others are fragments that will be merged
2727
# to main one in .config.
2828
# TARGET_KERNEL_RECOVERY_CONFIG = Same as above, but applicable to recovery kernel instead.
29+
# TARGET_KERNEL_CONFIG_EXT = List of path to external kernel defconfigs.
30+
# Same as TARGET_KERNEL_CONFIG, but paths are specified
31+
# instead of filenames.
32+
# TARGET_KERNEL_RECOVERY_CONFIG_EXT = Same as above, but applicable to recovery kernel instead.
2933
# TARGET_KERNEL_VARIANT_CONFIG = Variant defconfig, optional
3034
# TARGET_KERNEL_SELINUX_CONFIG = SELinux defconfig, optional
3135
#
@@ -62,6 +66,11 @@
6266
#
6367
# KERNEL_LTO = Optional, force LTO to none / thin / full
6468
#
69+
# MERGE_ALL_KERNEL_CONFIGS_AT_ONCE = Optional, whether or not to merge all kernel config
70+
# fragments in one merge_configs.sh call. if true,
71+
# kernel config fragments will get merged faster, but
72+
# may cause some differences.
73+
#
6574
# NEED_KERNEL_MODULE_ROOT = Optional, if true, install kernel
6675
# modules in root instead of vendor
6776
# NEED_KERNEL_MODULE_SYSTEM = Optional, if true, install kernel
@@ -81,8 +90,11 @@ ifneq ($(TARGET_NO_KERNEL_OVERRIDE),true)
8190
## Externally influenced variables
8291
KERNEL_SRC := $(TARGET_KERNEL_SOURCE)
8392
# kernel configuration - mandatory
93+
MERGE_ALL_KERNEL_CONFIGS_AT_ONCE ?= false
8494
KERNEL_DEFCONFIG := $(TARGET_KERNEL_CONFIG)
95+
KERNEL_DEFCONFIG_EXT := $(TARGET_KERNEL_CONFIG_EXT)
8596
RECOVERY_DEFCONFIG := $(TARGET_KERNEL_RECOVERY_CONFIG)
97+
RECOVERY_DEFCONFIG_EXT := $(TARGET_KERNEL_RECOVERY_CONFIG_EXT)
8698
VARIANT_DEFCONFIG := $(TARGET_KERNEL_VARIANT_CONFIG)
8799
SELINUX_DEFCONFIG := $(TARGET_KERNEL_SELINUX_CONFIG)
88100
# dtb generation - optional
@@ -112,12 +124,13 @@ else
112124
KERNEL_DEFCONFIG_ARCH := $(KERNEL_ARCH)
113125
endif
114126
KERNEL_DEFCONFIG_DIR := $(KERNEL_SRC)/arch/$(KERNEL_DEFCONFIG_ARCH)/configs
127+
115128
ALL_KERNEL_DEFCONFIG_SRCS := $(foreach config,$(KERNEL_DEFCONFIG),$(KERNEL_DEFCONFIG_DIR)/$(config))
129+
ALL_KERNEL_DEFCONFIG_SRCS += $(KERNEL_DEFCONFIG_EXT)
116130
ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS := $(foreach config,$(RECOVERY_DEFCONFIG),$(KERNEL_DEFCONFIG_DIR)/$(config))
131+
ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS += $(RECOVERY_DEFCONFIG_EXT)
117132

118-
BASE_KERNEL_DEFCONFIG := $(word 1, $(KERNEL_DEFCONFIG))
119133
BASE_KERNEL_DEFCONFIG_SRC := $(word 1, $(ALL_KERNEL_DEFCONFIG_SRCS))
120-
BASE_RECOVERY_KERNEL_DEFCONFIG := $(word 1, $(RECOVERY_DEFCONFIG))
121134
BASE_RECOVERY_KERNEL_DEFCONFIG_SRC := $(word 1, $(ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS))
122135

123136
ifeq ($(TARGET_PREBUILT_KERNEL),)
@@ -168,7 +181,7 @@ ifeq "$(wildcard $(KERNEL_SRC) )" ""
168181
endif
169182
else
170183
NEEDS_KERNEL_COPY := true
171-
ifeq ($(TARGET_KERNEL_CONFIG),)
184+
ifeq ($(TARGET_KERNEL_CONFIG)$(TARGET_KERNEL_CONFIG_EXT),)
172185
$(warning **********************************************************)
173186
$(warning * Kernel source found, but no configuration was defined *)
174187
$(warning * Please add the TARGET_KERNEL_CONFIG variable to your *)
@@ -298,9 +311,16 @@ endef
298311

299312
# Generate kernel .config from a given defconfig
300313
# $(1): Output path (The value passed to O=)
301-
# $(2): The defconfig to process (just the filename, no need for full path to file)
314+
# $(2): The defconfig to process (full path to file)
302315
define make-kernel-config
303-
$(call internal-make-kernel-target,$(1),VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) $(2))
316+
cp $(word 1,$(2)) $(1)/.config
317+
$(call internal-make-kernel-target,$(1),olddefconfig)
318+
$(if $(filter true,$(MERGE_ALL_KERNEL_CONFIGS_AT_ONCE)),\
319+
$(KERNEL_SRC)/scripts/kconfig/merge_config.sh -m -O $(1) $(1)/.config $(filter %.config,$(2)),
320+
$(foreach config,$(filter %.config,$(2)),
321+
$(KERNEL_SRC)/scripts/kconfig/merge_config.sh -m -O $(1) $(1)/.config $(config); \
322+
$(call internal-make-kernel-target,$(1),olddefconfig);))
323+
$(call internal-make-kernel-target,$(1),VARIANT_DEFCONFIG=$(VARIANT_DEFCONFIG) SELINUX_DEFCONFIG=$(SELINUX_DEFCONFIG) olddefconfig)
304324
$(hide) if [ "$(KERNEL_LTO)" = "none" ]; then \
305325
$(KERNEL_SRC)/scripts/config --file $(1)/.config \
306326
-d LTO_CLANG \
@@ -485,7 +505,7 @@ $(KERNEL_OUT):
485505

486506
$(KERNEL_CONFIG): $(KERNEL_OUT) $(ALL_KERNEL_DEFCONFIG_SRCS)
487507
@echo "Building Kernel Config"
488-
$(call make-kernel-config,$(KERNEL_OUT),$(KERNEL_DEFCONFIG))
508+
$(call make-kernel-config,$(KERNEL_OUT),$(ALL_KERNEL_DEFCONFIG_SRCS))
489509

490510
$(TARGET_PREBUILT_INT_KERNEL): $(KERNEL_CONFIG) $(DEPMOD) $(DTC) $(KERNEL_MODULES_PARTITION_FILE_LIST) $(SYSTEM_KERNEL_MODULES_PARTITION_FILE_LIST)
491511
@echo "Building Kernel Image ($(BOARD_KERNEL_IMAGE_NAME))"
@@ -567,7 +587,7 @@ kerneltags: $(KERNEL_CONFIG)
567587
.PHONY: kernelsavedefconfig alldefconfig kernelconfig recoverykernelconfig
568588

569589
kernelsavedefconfig: $(KERNEL_OUT)
570-
$(call make-kernel-config,$(KERNEL_OUT),$(BASE_KERNEL_DEFCONFIG))
590+
$(call make-kernel-config,$(KERNEL_OUT),$(BASE_KERNEL_DEFCONFIG_SRC))
571591
$(call make-kernel-target,savedefconfig)
572592
cp $(KERNEL_OUT)/defconfig $(BASE_KERNEL_DEFCONFIG_SRC)
573593

@@ -577,11 +597,11 @@ alldefconfig: $(KERNEL_OUT)
577597

578598
kernelconfig: $(KERNEL_OUT) $(ALL_KERNEL_DEFCONFIG_SRCS)
579599
@echo "Building Kernel Config"
580-
$(call make-kernel-config,$(KERNEL_OUT),$(KERNEL_DEFCONFIG))
600+
$(call make-kernel-config,$(KERNEL_OUT),$(ALL_KERNEL_DEFCONFIG_SRCS))
581601

582602
recoverykernelconfig: $(KERNEL_OUT) $(ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS)
583603
@echo "Building Recovery Kernel Config"
584-
$(call make-kernel-config,$(RECOVERY_KERNEL_OUT),$(RECOVERY_DEFCONFIG))
604+
$(call make-kernel-config,$(RECOVERY_KERNEL_OUT),$(ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS))
585605

586606
ifeq (true,$(filter true, $(TARGET_NEEDS_DTBOIMAGE) $(BOARD_KERNEL_SEPARATED_DTBO)))
587607
ifneq ($(BOARD_CUSTOM_DTBOIMG_MK),)
@@ -680,7 +700,7 @@ $(RECOVERY_KERNEL_OUT):
680700

681701
$(RECOVERY_KERNEL_CONFIG): $(ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS)
682702
@echo "Building Recovery Kernel Config"
683-
$(call make-kernel-config,$(RECOVERY_KERNEL_OUT),$(RECOVERY_DEFCONFIG))
703+
$(call make-kernel-config,$(RECOVERY_KERNEL_OUT),$(ALL_RECOVERY_KERNEL_DEFCONFIG_SRCS))
684704

685705
$(TARGET_PREBUILT_INT_RECOVERY_KERNEL): $(RECOVERY_KERNEL_CONFIG) $(DEPMOD) $(DTC)
686706
@echo "Building Recovery Kernel Image ($(BOARD_KERNEL_IMAGE_NAME))"

0 commit comments

Comments
 (0)