1################################################################################ 2# 3# Linux kernel target 4# 5################################################################################ 6 7LINUX_VERSION = $(call qstrip,$(BR2_LINUX_KERNEL_VERSION)) 8LINUX_LICENSE = GPL-2.0 9ifeq ($(BR2_LINUX_KERNEL_LATEST_VERSION),y) 10LINUX_LICENSE_FILES = \ 11 COPYING \ 12 LICENSES/preferred/GPL-2.0 \ 13 LICENSES/exceptions/Linux-syscall-note 14endif 15LINUX_CPE_ID_VENDOR = linux 16LINUX_CPE_ID_PRODUCT = linux_kernel 17LINUX_CPE_ID_PREFIX = cpe:2.3:o 18 19# Compute LINUX_SOURCE and LINUX_SITE from the configuration 20ifeq ($(BR2_LINUX_KERNEL_CUSTOM_TARBALL),y) 21LINUX_TARBALL = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION)) 22LINUX_SITE = $(patsubst %/,%,$(dir $(LINUX_TARBALL))) 23LINUX_SOURCE = $(notdir $(LINUX_TARBALL)) 24else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_LOCAL),y) 25LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_LOCAL_LOCATION)) 26LINUX_SITE_METHOD = local 27else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_GIT),y) 28LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL)) 29LINUX_SITE_METHOD = git 30else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_HG),y) 31LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL)) 32LINUX_SITE_METHOD = hg 33else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_SVN),y) 34LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL)) 35LINUX_SITE_METHOD = svn 36else ifeq ($(BR2_LINUX_KERNEL_LATEST_CIP_VERSION)$(BR2_LINUX_KERNEL_LATEST_CIP_RT_VERSION),y) 37LINUX_SOURCE = linux-cip-$(LINUX_VERSION).tar.gz 38LINUX_SITE = https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip.git/snapshot 39else ifneq ($(findstring -rc,$(LINUX_VERSION)),) 40# Since 4.12-rc1, -rc kernels are generated from cgit. This also works for 41# older -rc kernels. 42LINUX_SITE = https://git.kernel.org/torvalds/t 43else 44LINUX_SOURCE = linux-$(LINUX_VERSION).tar.xz 45ifeq ($(findstring x2.6.,x$(LINUX_VERSION)),x2.6.) 46LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v2.6 47else 48LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v$(firstword $(subst ., ,$(LINUX_VERSION))).x 49endif 50endif 51 52ifeq ($(BR2_LINUX_KERNEL)$(BR2_LINUX_KERNEL_LATEST_VERSION),y) 53BR_NO_CHECK_HASH_FOR += $(LINUX_SOURCE) 54endif 55 56LINUX_PATCHES = $(call qstrip,$(BR2_LINUX_KERNEL_PATCH)) 57 58# We have no way to know the hashes for user-supplied patches. 59BR_NO_CHECK_HASH_FOR += $(notdir $(LINUX_PATCHES)) 60 61# We rely on the generic package infrastructure to download and apply 62# remote patches (downloaded from ftp, http or https). For local 63# patches, we can't rely on that infrastructure, because there might 64# be directories in the patch list (unlike for other packages). 65LINUX_PATCH = $(filter ftp://% http://% https://%,$(LINUX_PATCHES)) 66 67# while the kernel is built for the target, the build may need various 68# host libraries depending on config (and version), so use 69# HOST_MAKE_ENV here. In particular, this ensures that our 70# host-pkgconf will look for host libraries and not target ones. 71LINUX_MAKE_ENV = \ 72 $(HOST_MAKE_ENV) \ 73 BR_BINARIES_DIR=$(BINARIES_DIR) 74 75LINUX_INSTALL_IMAGES = YES 76LINUX_DEPENDENCIES = host-kmod 77 78# The kernel CONFIG_EXTRA_FIRMWARE feature requires firmware files at build 79# time. Make sure they are available before the kernel builds. 80LINUX_DEPENDENCIES += \ 81 $(if $(BR2_PACKAGE_INTEL_MICROCODE),intel-microcode) \ 82 $(if $(BR2_PACKAGE_LINUX_FIRMWARE),linux-firmware) \ 83 $(if $(BR2_PACKAGE_FIRMWARE_IMX),firmware-imx) \ 84 $(if $(BR2_PACKAGE_WIRELESS_REGDB),wireless-regdb) 85 86# Starting with 4.16, the generated kconfig paser code is no longer 87# shipped with the kernel sources, so we need flex and bison, but 88# only if the host does not have them. 89LINUX_KCONFIG_DEPENDENCIES = \ 90 $(BR2_BISON_HOST_DEPENDENCY) \ 91 $(BR2_FLEX_HOST_DEPENDENCY) 92 93# Starting with 4.18, the kconfig in the kernel calls the 94# cross-compiler to check its capabilities. So we need the 95# toolchain before we can call the configurators. 96LINUX_KCONFIG_DEPENDENCIES += toolchain 97 98# host tools needed for kernel compression 99ifeq ($(BR2_LINUX_KERNEL_LZ4),y) 100LINUX_DEPENDENCIES += host-lz4 101else ifeq ($(BR2_LINUX_KERNEL_LZMA),y) 102LINUX_DEPENDENCIES += host-lzma 103else ifeq ($(BR2_LINUX_KERNEL_LZO),y) 104LINUX_DEPENDENCIES += host-lzop 105else ifeq ($(BR2_LINUX_KERNEL_XZ),y) 106LINUX_DEPENDENCIES += host-xz 107else ifeq ($(BR2_LINUX_KERNEL_ZSTD),y) 108LINUX_DEPENDENCIES += host-zstd 109endif 110LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_GZIP) += CONFIG_KERNEL_GZIP 111LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZ4) += CONFIG_KERNEL_LZ4 112LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZMA) += CONFIG_KERNEL_LZMA 113LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZO) += CONFIG_KERNEL_LZO 114LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_XZ) += CONFIG_KERNEL_XZ 115LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_ZSTD) += CONFIG_KERNEL_ZSTD 116LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_UNCOMPRESSED) += CONFIG_KERNEL_UNCOMPRESSED 117 118ifeq ($(BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL),y) 119LINUX_DEPENDENCIES += host-openssl 120endif 121 122ifeq ($(BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF),y) 123LINUX_DEPENDENCIES += host-elfutils host-pkgconf 124endif 125 126ifeq ($(BR2_LINUX_KERNEL_NEEDS_HOST_PAHOLE),y) 127LINUX_DEPENDENCIES += host-pahole 128else 129define LINUX_FIXUP_CONFIG_PAHOLE_CHECK 130 if grep -q "^CONFIG_DEBUG_INFO_BTF=y" $(KCONFIG_DOT_CONFIG); then \ 131 echo "To use CONFIG_DEBUG_INFO_BTF, enable host-pahole (BR2_LINUX_KERNEL_NEEDS_HOST_PAHOLE)" 1>&2; \ 132 exit 1; \ 133 fi 134endef 135endif 136 137# If host-uboot-tools is selected by the user, assume it is needed to 138# create a custom image 139ifeq ($(BR2_PACKAGE_HOST_UBOOT_TOOLS),y) 140LINUX_DEPENDENCIES += host-uboot-tools 141endif 142 143ifneq ($(ARCH_XTENSA_OVERLAY_FILE),) 144define LINUX_XTENSA_OVERLAY_EXTRACT 145 $(call arch-xtensa-overlay-extract,$(@D),linux) 146endef 147LINUX_POST_EXTRACT_HOOKS += LINUX_XTENSA_OVERLAY_EXTRACT 148LINUX_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL) 149endif 150 151# We don't want to run depmod after installing the kernel. It's done in a 152# target-finalize hook, to encompass modules installed by packages. 153# Disable building host tools with -Werror: newer gcc versions can be 154# extra picky about some code (https://bugs.busybox.net/show_bug.cgi?id=14826) 155LINUX_MAKE_FLAGS = \ 156 HOSTCC="$(HOSTCC) $(subst -I/,-isystem /,$(subst -I /,-isystem /,$(HOST_CFLAGS))) $(HOST_LDFLAGS)" \ 157 ARCH=$(KERNEL_ARCH) \ 158 INSTALL_MOD_PATH=$(TARGET_DIR) \ 159 CROSS_COMPILE="$(TARGET_CROSS)" \ 160 WERROR=0 \ 161 REGENERATE_PARSERS=1 \ 162 DEPMOD=$(HOST_DIR)/sbin/depmod 163 164ifeq ($(BR2_REPRODUCIBLE),y) 165LINUX_MAKE_ENV += \ 166 KBUILD_BUILD_VERSION=1 \ 167 KBUILD_BUILD_USER=buildroot \ 168 KBUILD_BUILD_HOST=buildroot \ 169 KBUILD_BUILD_TIMESTAMP="$(shell LC_ALL=C TZ='UTC' date -d @$(SOURCE_DATE_EPOCH))" 170endif 171 172# gcc-8 started warning about function aliases that have a 173# non-matching prototype. This seems rather useful in general, but it 174# causes tons of warnings in the Linux kernel, where we rely on 175# abusing those aliases for system call entry points, in order to 176# sanitize the arguments passed from user space in registers. 177# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435 178ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y) 179LINUX_MAKE_ENV += KCFLAGS=-Wno-attribute-alias 180endif 181 182ifeq ($(BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT),y) 183LINUX_MAKE_ENV += DTC_FLAGS=-@ 184endif 185 186# Get the real Linux version, which tells us where kernel modules are 187# going to be installed in the target filesystem. 188# Filter out 'w' from MAKEFLAGS, to workaround a bug in make 4.1 (#13141) 189LINUX_VERSION_PROBED = `MAKEFLAGS='$(filter-out w,$(MAKEFLAGS))' $(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease 2>/dev/null` 190 191LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME)) 192 193# We keep only the .dts files, so that the user can specify both .dts 194# and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be 195# copied to arch/<arch>/boot/dts, but only the .dts files will 196# actually be generated as .dtb. 197LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH))))) 198 199LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME)) 200 201ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y) 202LINUX_IMAGE_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_NAME)) 203LINUX_TARGET_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME)) 204ifeq ($(LINUX_IMAGE_NAME),) 205LINUX_IMAGE_NAME = $(LINUX_TARGET_NAME) 206endif 207else 208ifeq ($(BR2_LINUX_KERNEL_UIMAGE),y) 209LINUX_IMAGE_NAME = uImage 210else ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y) 211LINUX_IMAGE_NAME = uImage 212else ifeq ($(BR2_LINUX_KERNEL_BZIMAGE),y) 213LINUX_IMAGE_NAME = bzImage 214else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE),y) 215LINUX_IMAGE_NAME = zImage 216else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE_EPAPR),y) 217LINUX_IMAGE_NAME = zImage.epapr 218else ifeq ($(BR2_LINUX_KERNEL_APPENDED_ZIMAGE),y) 219LINUX_IMAGE_NAME = zImage 220else ifeq ($(BR2_LINUX_KERNEL_CUIMAGE),y) 221LINUX_IMAGE_NAME = cuImage.$(firstword $(LINUX_DTS_NAME)) 222else ifeq ($(BR2_LINUX_KERNEL_SIMPLEIMAGE),y) 223LINUX_IMAGE_NAME = simpleImage.$(firstword $(LINUX_DTS_NAME)) 224else ifeq ($(BR2_LINUX_KERNEL_IMAGE),y) 225LINUX_IMAGE_NAME = Image 226else ifeq ($(BR2_LINUX_KERNEL_IMAGEGZ),y) 227LINUX_IMAGE_NAME = Image.gz 228else ifeq ($(BR2_LINUX_KERNEL_LINUX_BIN),y) 229LINUX_IMAGE_NAME = linux.bin 230else ifeq ($(BR2_LINUX_KERNEL_VMLINUX_BIN),y) 231LINUX_IMAGE_NAME = vmlinux.bin 232else ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y) 233LINUX_IMAGE_NAME = vmlinux 234else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y) 235LINUX_IMAGE_NAME = vmlinuz 236else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ_BIN),y) 237LINUX_IMAGE_NAME = vmlinuz.bin 238endif 239# The if-else blocks above are all the image types we know of, and all 240# come from a Kconfig choice, so we know we have LINUX_IMAGE_NAME set 241# to something 242LINUX_TARGET_NAME = $(LINUX_IMAGE_NAME) 243endif 244 245LINUX_KERNEL_UIMAGE_LOADADDR = $(call qstrip,$(BR2_LINUX_KERNEL_UIMAGE_LOADADDR)) 246ifneq ($(LINUX_KERNEL_UIMAGE_LOADADDR),) 247LINUX_MAKE_FLAGS += LOADADDR="$(LINUX_KERNEL_UIMAGE_LOADADDR)" 248endif 249 250# Compute the arch path, since i386 and x86_64 are in arch/x86 and not 251# in arch/$(KERNEL_ARCH). Even if the kernel creates symbolic links 252# for bzImage, arch/i386 and arch/x86_64 do not exist when copying the 253# defconfig file. 254ifeq ($(KERNEL_ARCH),i386) 255LINUX_ARCH_PATH = $(LINUX_DIR)/arch/x86 256else ifeq ($(KERNEL_ARCH),x86_64) 257LINUX_ARCH_PATH = $(LINUX_DIR)/arch/x86 258else ifeq ($(KERNEL_ARCH),sparc64) 259LINUX_ARCH_PATH = $(LINUX_DIR)/arch/sparc 260else 261LINUX_ARCH_PATH = $(LINUX_DIR)/arch/$(KERNEL_ARCH) 262endif 263 264ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y) 265LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME) 266else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y) 267LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME) 268else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ_BIN),y) 269LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME) 270else 271LINUX_IMAGE_PATH = $(LINUX_ARCH_PATH)/boot/$(LINUX_IMAGE_NAME) 272endif # BR2_LINUX_KERNEL_VMLINUX 273 274define LINUX_APPLY_LOCAL_PATCHES 275 for p in $(filter-out ftp://% http://% https://%,$(LINUX_PATCHES)) ; do \ 276 if test -d $$p ; then \ 277 $(APPLY_PATCHES) $(@D) $$p \*.patch || exit 1 ; \ 278 else \ 279 $(APPLY_PATCHES) $(@D) `dirname $$p` `basename $$p` || exit 1; \ 280 fi \ 281 done 282endef 283 284LINUX_POST_PATCH_HOOKS += LINUX_APPLY_LOCAL_PATCHES 285 286# Older versions break on gcc 10+ because of redefined symbols 287define LINUX_DROP_YYLLOC 288 $(Q)grep -Z -l -r -E '^YYLTYPE yylloc;$$' $(@D) \ 289 |xargs -0 -r $(SED) '/^YYLTYPE yylloc;$$/d' 290endef 291LINUX_POST_PATCH_HOOKS += LINUX_DROP_YYLLOC 292 293# Kernel version < 5.6 breaks if host-gcc version is >= 10 and 294# 'yylloc' symbol is removed in previous hook, due to missing 295# '%locations' bison directive in dtc-parser.y. See: 296# https://bugs.busybox.net/show_bug.cgi?id=14971 297define LINUX_ADD_DTC_LOCATIONS 298 $(Q)DTC_PARSER=$(@D)/scripts/dtc/dtc-parser.y; \ 299 if test -e "$${DTC_PARSER}" \ 300 && ! grep -Eq '^%locations$$' "$${DTC_PARSER}" ; then \ 301 $(SED) '/^%{$$/i %locations' "$${DTC_PARSER}"; \ 302 fi 303endef 304LINUX_POST_PATCH_HOOKS += LINUX_ADD_DTC_LOCATIONS 305 306# Older linux kernels use deprecated perl constructs in timeconst.pl 307# that were removed for perl 5.22+ so it breaks on newer distributions 308# Try a dry-run patch to see if this applies, if it does go ahead 309define LINUX_TRY_PATCH_TIMECONST 310 @if patch -p1 --dry-run -f -s -d $(@D) <$(LINUX_PKGDIR)/0001-timeconst.pl-Eliminate-Perl-warning.patch.conditional >/dev/null ; then \ 311 $(APPLY_PATCHES) $(@D) $(LINUX_PKGDIR) 0001-timeconst.pl-Eliminate-Perl-warning.patch.conditional ; \ 312 fi 313endef 314LINUX_POST_PATCH_HOOKS += LINUX_TRY_PATCH_TIMECONST 315 316LINUX_KERNEL_CUSTOM_LOGO_PATH = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_LOGO_PATH)) 317ifneq ($(LINUX_KERNEL_CUSTOM_LOGO_PATH),) 318LINUX_DEPENDENCIES += host-imagemagick 319define LINUX_KERNEL_CUSTOM_LOGO_CONVERT 320 $(HOST_DIR)/bin/convert $(LINUX_KERNEL_CUSTOM_LOGO_PATH) \ 321 -dither None -colors 224 -compress none \ 322 $(LINUX_DIR)/drivers/video/logo/logo_linux_clut224.ppm 323endef 324LINUX_PRE_BUILD_HOOKS += LINUX_KERNEL_CUSTOM_LOGO_CONVERT 325endif 326 327ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y) 328LINUX_KCONFIG_DEFCONFIG = $(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG))_defconfig 329else ifeq ($(BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG),y) 330ifeq ($(BR2_powerpc64le),y) 331LINUX_KCONFIG_DEFCONFIG = ppc64le_defconfig 332else 333LINUX_KCONFIG_DEFCONFIG = defconfig 334endif 335else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y) 336LINUX_KCONFIG_FILE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE)) 337endif 338LINUX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES)) 339LINUX_KCONFIG_EDITORS = menuconfig xconfig gconfig nconfig 340 341# LINUX_MAKE_FLAGS overrides HOSTCC to allow the kernel build to find 342# our host-openssl and host-libelf. However, this triggers a bug in 343# the kconfig build script that causes it to build with 344# /usr/include/ncurses.h (which is typically wchar) but link with 345# $(HOST_DIR)/lib/libncurses.so (which is not). We don't actually 346# need any host-package for kconfig, so remove the HOSTCC override 347# again. In addition, even though linux depends on the toolchain and 348# therefore host-ccache would be ready, we use HOSTCC_NOCCACHE for 349# consistency with other kconfig packages. 350LINUX_KCONFIG_OPTS = $(LINUX_MAKE_FLAGS) HOSTCC="$(HOSTCC_NOCCACHE)" 351 352# If no package has yet set it, set it from the Kconfig option 353LINUX_NEEDS_MODULES ?= $(BR2_LINUX_NEEDS_MODULES) 354 355# Make sure the Linux kernel is built with the right endianness. Not 356# all architectures support 357# CONFIG_CPU_BIG_ENDIAN/CONFIG_CPU_LITTLE_ENDIAN in Linux, but the 358# option will be thrown away and ignored if it doesn't exist. 359ifeq ($(BR2_ENDIAN),"BIG") 360define LINUX_FIXUP_CONFIG_ENDIANNESS 361 $(call KCONFIG_ENABLE_OPT,CONFIG_CPU_BIG_ENDIAN) 362endef 363else 364define LINUX_FIXUP_CONFIG_ENDIANNESS 365 $(call KCONFIG_ENABLE_OPT,CONFIG_CPU_LITTLE_ENDIAN) 366endef 367endif 368 369define LINUX_KCONFIG_FIXUP_CMDS 370 $(if $(LINUX_NEEDS_MODULES), 371 $(call KCONFIG_ENABLE_OPT,CONFIG_MODULES)) 372 $(call KCONFIG_ENABLE_OPT,$(strip $(LINUX_COMPRESSION_OPT_y))) 373 $(foreach opt, $(LINUX_COMPRESSION_OPT_), 374 $(call KCONFIG_DISABLE_OPT,$(opt)) 375 ) 376 $(LINUX_FIXUP_CONFIG_ENDIANNESS) 377 $(LINUX_FIXUP_CONFIG_PAHOLE_CHECK) 378 $(if $(BR2_arm)$(BR2_armeb), 379 $(call KCONFIG_ENABLE_OPT,CONFIG_AEABI)) 380 $(if $(BR2_powerpc)$(BR2_powerpc64)$(BR2_powerpc64le), 381 $(call KCONFIG_ENABLE_OPT,CONFIG_PPC_DISABLE_WERROR)) 382 $(if $(BR2_ARC_PAGE_SIZE_4K), 383 $(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K) 384 $(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K) 385 $(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)) 386 $(if $(BR2_ARC_PAGE_SIZE_8K), 387 $(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K) 388 $(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K) 389 $(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)) 390 $(if $(BR2_ARC_PAGE_SIZE_16K), 391 $(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_4K) 392 $(call KCONFIG_DISABLE_OPT,CONFIG_ARC_PAGE_SIZE_8K) 393 $(call KCONFIG_ENABLE_OPT,CONFIG_ARC_PAGE_SIZE_16K)) 394 $(if $(BR2_ARM64_PAGE_SIZE_4K), 395 $(call KCONFIG_ENABLE_OPT,CONFIG_ARM64_4K_PAGES) 396 $(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_16K_PAGES) 397 $(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_64K_PAGES)) 398 $(if $(BR2_ARM64_PAGE_SIZE_64K), 399 $(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_4K_PAGES) 400 $(call KCONFIG_DISABLE_OPT,CONFIG_ARM64_16K_PAGES) 401 $(call KCONFIG_ENABLE_OPT,CONFIG_ARM64_64K_PAGES)) 402 $(if $(BR2_TARGET_ROOTFS_CPIO), 403 $(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD)) 404 # As the kernel gets compiled before root filesystems are 405 # built, we create a fake cpio file. It'll be 406 # replaced later by the real cpio archive, and the kernel will be 407 # rebuilt using the linux-rebuild-with-initramfs target. 408 $(if $(BR2_TARGET_ROOTFS_INITRAMFS), 409 mkdir -p $(BINARIES_DIR) 410 touch $(BINARIES_DIR)/rootfs.cpio 411 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio") 412 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0) 413 $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0)) 414 $(if $(BR2_ROOTFS_DEVICE_CREATION_STATIC),, 415 $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS) 416 $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS_MOUNT)) 417 $(if $(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV), 418 $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER)) 419 $(if $(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV), 420 $(call KCONFIG_ENABLE_OPT,CONFIG_NET)) 421 $(if $(BR2_LINUX_KERNEL_APPENDED_DTB), 422 $(call KCONFIG_ENABLE_OPT,CONFIG_ARM_APPENDED_DTB)) 423 $(if $(LINUX_KERNEL_CUSTOM_LOGO_PATH), 424 $(call KCONFIG_ENABLE_OPT,CONFIG_FB) 425 $(call KCONFIG_ENABLE_OPT,CONFIG_LOGO) 426 $(call KCONFIG_ENABLE_OPT,CONFIG_LOGO_LINUX_CLUT224)) 427 $(call KCONFIG_DISABLE_OPT,CONFIG_GCC_PLUGINS) 428 $(PACKAGES_LINUX_CONFIG_FIXUPS) 429endef 430 431ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT),y) 432# Starting with 4.17, the generated dtc parser code is no longer 433# shipped with the kernel sources, so we need flex and bison. For 434# reproducibility, we use our owns rather than the host ones. 435LINUX_DEPENDENCIES += host-bison host-flex 436 437ifeq ($(BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT),) 438define LINUX_BUILD_DTB 439 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_DTBS) 440endef 441ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),) 442define LINUX_INSTALL_DTB 443 # dtbs moved from arch/<ARCH>/boot to arch/<ARCH>/boot/dts since 3.8-rc1 444 $(foreach dtb,$(LINUX_DTBS), \ 445 install -D \ 446 $(or $(wildcard $(LINUX_ARCH_PATH)/boot/dts/$(dtb)),$(LINUX_ARCH_PATH)/boot/$(dtb)) \ 447 $(1)/$(if $(BR2_LINUX_KERNEL_DTB_KEEP_DIRNAME),$(dtb),$(notdir $(dtb))) 448 ) 449endef 450endif # BR2_LINUX_KERNEL_APPENDED_DTB 451endif # BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT 452endif # BR2_LINUX_KERNEL_DTS_SUPPORT 453 454ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y) 455# dtbs moved from arch/$ARCH/boot to arch/$ARCH/boot/dts since 3.8-rc1 456define LINUX_APPEND_DTB 457 (cd $(LINUX_ARCH_PATH)/boot; \ 458 for dtb in $(LINUX_DTS_NAME); do \ 459 if test -e $${dtb}.dtb ; then \ 460 dtbpath=$${dtb}.dtb ; \ 461 else \ 462 dtbpath=dts/$${dtb}.dtb ; \ 463 fi ; \ 464 cat zImage $${dtbpath} > zImage.$${dtb} || exit 1; \ 465 done) 466endef 467ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y) 468# We need to generate a new u-boot image that takes into 469# account the extra-size added by the device tree at the end 470# of the image. To do so, we first need to retrieve both load 471# address and entry point for the kernel from the already 472# generate uboot image before using mkimage -l. 473LINUX_APPEND_DTB += ; \ 474 MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\ 475 sed -n -e 's/Image Name:[ ]*\(.*\)/-n \1/p' -e 's/Load Address:/-a/p' -e 's/Entry Point:/-e/p'`; \ 476 for dtb in $(LINUX_DTS_NAME); do \ 477 $(MKIMAGE) -A $(MKIMAGE_ARCH) -O linux \ 478 -T kernel -C none $${MKIMAGE_ARGS} \ 479 -d $(LINUX_ARCH_PATH)/boot/zImage.$${dtb} $(LINUX_IMAGE_PATH).$${dtb}; \ 480 done 481endif 482endif 483 484# Compilation. We make sure the kernel gets rebuilt when the 485# configuration has changed. We call the 'all' and 486# '$(LINUX_TARGET_NAME)' targets separately because calling them in 487# the same $(MAKE) invocation has shown to cause parallel build 488# issues. 489# The call to disable gcc-plugins is a stop-gap measure: 490# http://lists.busybox.net/pipermail/buildroot/2020-May/282727.html 491define LINUX_BUILD_CMDS 492 $(call KCONFIG_DISABLE_OPT,CONFIG_GCC_PLUGINS) 493 $(foreach dts,$(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)), \ 494 cp -f $(dts) $(LINUX_ARCH_PATH)/boot/dts/ 495 ) 496 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) all 497 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME) 498 $(LINUX_BUILD_DTB) 499 $(LINUX_APPEND_DTB) 500endef 501 502ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y) 503# When a DTB was appended, install the potential several images with 504# appended DTBs. 505define LINUX_INSTALL_IMAGE 506 mkdir -p $(1) 507 cp $(LINUX_ARCH_PATH)/boot/$(LINUX_IMAGE_NAME).* $(1) 508endef 509else 510# Otherwise, just install the unique image generated by the kernel 511# build process. 512define LINUX_INSTALL_IMAGE 513 $(INSTALL) -m 0644 -D $(LINUX_IMAGE_PATH) $(1)/$(notdir $(LINUX_IMAGE_NAME)) 514endef 515endif 516 517ifeq ($(BR2_LINUX_KERNEL_INSTALL_TARGET),y) 518define LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET 519 $(call LINUX_INSTALL_IMAGE,$(TARGET_DIR)/boot) 520 $(call LINUX_INSTALL_DTB,$(TARGET_DIR)/boot) 521endef 522endif 523 524define LINUX_INSTALL_HOST_TOOLS 525 # Installing dtc (device tree compiler) as host tool, if selected 526 if grep -q "CONFIG_DTC=y" $(@D)/.config; then \ 527 $(INSTALL) -D -m 0755 $(@D)/scripts/dtc/dtc $(HOST_DIR)/bin/linux-dtc ; \ 528 $(if $(BR2_PACKAGE_HOST_DTC),,ln -sf linux-dtc $(HOST_DIR)/bin/dtc;) \ 529 fi 530endef 531 532define LINUX_INSTALL_IMAGES_CMDS 533 $(call LINUX_INSTALL_IMAGE,$(BINARIES_DIR)) 534 $(call LINUX_INSTALL_DTB,$(BINARIES_DIR)) 535endef 536 537ifeq ($(BR2_STRIP_strip),y) 538LINUX_MAKE_FLAGS += INSTALL_MOD_STRIP=1 539endif 540 541define LINUX_INSTALL_TARGET_CMDS 542 $(LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET) 543 # Install modules and remove symbolic links pointing to build 544 # directories, not relevant on the target 545 @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \ 546 $(LINUX_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) modules_install; \ 547 rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/build ; \ 548 rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/source ; \ 549 fi 550 $(LINUX_INSTALL_HOST_TOOLS) 551endef 552 553# Run depmod in a target-finalize hook, to encompass modules installed by 554# packages. 555define LINUX_RUN_DEPMOD 556 if test -d $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED) \ 557 && grep -q "CONFIG_MODULES=y" $(LINUX_DIR)/.config; then \ 558 $(HOST_DIR)/sbin/depmod -a -b $(TARGET_DIR) $(LINUX_VERSION_PROBED); \ 559 fi 560endef 561LINUX_TARGET_FINALIZE_HOOKS += LINUX_RUN_DEPMOD 562 563# Include all our extensions. 564# 565# Note: our package infrastructure uses the full-path of the last-scanned 566# Makefile to determine what package we're currently defining, using the 567# last directory component in the path. Additionally, the full path of 568# the package directory is also stored in _PKGDIR (e.g. to find patches) 569# 570# As such, including other Makefiles, like below, before we call one of 571# the *-package macros usually doesn't work. 572# 573# However, by including the in-tree extensions after the ones from the 574# br2-external trees, we're back to the situation where the last Makefile 575# scanned *is* included from the correct directory. 576# 577# NOTE: this is very fragile, and extra care must be taken to ensure that 578# we always end up with an in-tree included file. That's mostly OK, because 579# we do have in-tree linux-extensions. 580# 581include $(sort $(wildcard $(foreach ext,$(BR2_EXTERNAL_DIRS), \ 582 $(ext)/linux/linux-ext-*.mk))) 583include $(sort $(wildcard linux/linux-ext-*.mk)) 584 585LINUX_PATCH_DEPENDENCIES += $(foreach ext,$(LINUX_EXTENSIONS),\ 586 $(if $(BR2_LINUX_KERNEL_EXT_$(call UPPERCASE,$(ext))),$(ext))) 587 588LINUX_PRE_PATCH_HOOKS += $(foreach ext,$(LINUX_EXTENSIONS),\ 589 $(if $(BR2_LINUX_KERNEL_EXT_$(call UPPERCASE,$(ext))),\ 590 $(call UPPERCASE,$(ext))_PREPARE_KERNEL)) 591 592# Checks to give errors that the user can understand 593 594# When a custom repository has been set, check for the repository version 595ifeq ($(BR2_LINUX_KERNEL_CUSTOM_SVN)$(BR2_LINUX_KERNEL_CUSTOM_GIT)$(BR2_LINUX_KERNEL_CUSTOM_HG),y) 596ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION)),) 597$(error No custom repository version set. Check your BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION setting) 598endif 599ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL)),) 600$(error No custom repo URL set. Check your BR2_LINUX_KERNEL_CUSTOM_REPO_URL setting) 601endif 602endif 603 604ifeq ($(BR_BUILDING),y) 605 606ifeq ($(BR2_LINUX_KERNEL_CUSTOM_VERSION),y) 607ifeq ($(LINUX_VERSION),) 608$(error No custom kernel version set. Check your BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE setting) 609endif 610endif 611 612ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y) 613# We must use the user-supplied kconfig value, because 614# LINUX_KCONFIG_DEFCONFIG will at least contain the 615# trailing _defconfig 616ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG)),) 617$(error No kernel defconfig name specified, check your BR2_LINUX_KERNEL_DEFCONFIG setting) 618endif 619endif 620 621ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y) 622ifeq ($(LINUX_KCONFIG_FILE),) 623$(error No kernel configuration file specified, check your BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE setting) 624endif 625endif 626 627ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT):$(strip $(LINUX_DTS_NAME)),y:) 628$(error No kernel device tree source specified, check your \ 629 BR2_LINUX_KERNEL_INTREE_DTS_NAME / BR2_LINUX_KERNEL_CUSTOM_DTS_PATH settings) 630endif 631 632endif # BR_BUILDING 633 634$(eval $(kconfig-package)) 635 636# Support for rebuilding the kernel after the cpio archive has 637# been generated. 638.PHONY: linux-rebuild-with-initramfs 639linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_target_installed 640linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_images_installed 641linux-rebuild-with-initramfs: rootfs-cpio 642linux-rebuild-with-initramfs: 643 @$(call MESSAGE,"Rebuilding kernel with initramfs") 644 # Build the kernel. 645 $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) $(LINUX_TARGET_NAME) 646 $(LINUX_APPEND_DTB) 647 # Copy the kernel image(s) to its(their) final destination 648 $(call LINUX_INSTALL_IMAGE,$(BINARIES_DIR)) 649 # If there is a .ub file copy it to the final destination 650 test ! -f $(LINUX_IMAGE_PATH).ub || cp $(LINUX_IMAGE_PATH).ub $(BINARIES_DIR) 651