linux.mk 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. ################################################################################
  2. #
  3. # Linux kernel target
  4. #
  5. ################################################################################
  6. LINUX_VERSION = $(call qstrip,$(BR2_LINUX_KERNEL_VERSION))
  7. LINUX_LICENSE = GPL-2.0
  8. LINUX_LICENSE_FILES = COPYING
  9. define LINUX_HELP_CMDS
  10. @echo ' linux-menuconfig - Run Linux kernel menuconfig'
  11. @echo ' linux-savedefconfig - Run Linux kernel savedefconfig'
  12. @echo ' linux-update-defconfig - Save the Linux configuration to the path specified'
  13. @echo ' by BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE'
  14. endef
  15. # Compute LINUX_SOURCE and LINUX_SITE from the configuration
  16. ifeq ($(BR2_LINUX_KERNEL_CUSTOM_TARBALL),y)
  17. LINUX_TARBALL = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION))
  18. LINUX_SITE = $(patsubst %/,%,$(dir $(LINUX_TARBALL)))
  19. LINUX_SOURCE = $(notdir $(LINUX_TARBALL))
  20. else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_GIT),y)
  21. LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
  22. LINUX_SITE_METHOD = git
  23. else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_HG),y)
  24. LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
  25. LINUX_SITE_METHOD = hg
  26. else ifeq ($(BR2_LINUX_KERNEL_CUSTOM_SVN),y)
  27. LINUX_SITE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL))
  28. LINUX_SITE_METHOD = svn
  29. else ifeq ($(BR2_LINUX_KERNEL_LATEST_CIP_VERSION),y)
  30. LINUX_SITE = git://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip.git
  31. else ifneq ($(findstring -rc,$(LINUX_VERSION)),)
  32. # Since 4.12-rc1, -rc kernels are generated from cgit. This also works for
  33. # older -rc kernels.
  34. LINUX_SITE = https://git.kernel.org/torvalds/t
  35. else
  36. LINUX_SOURCE = linux-$(LINUX_VERSION).tar.xz
  37. ifeq ($(findstring x2.6.,x$(LINUX_VERSION)),x2.6.)
  38. LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v2.6
  39. else
  40. LINUX_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/v$(firstword $(subst ., ,$(LINUX_VERSION))).x
  41. endif
  42. endif
  43. ifeq ($(BR2_LINUX_KERNEL)$(BR2_LINUX_KERNEL_LATEST_VERSION),y)
  44. BR_NO_CHECK_HASH_FOR += $(LINUX_SOURCE)
  45. endif
  46. LINUX_PATCHES = $(call qstrip,$(BR2_LINUX_KERNEL_PATCH))
  47. # We have no way to know the hashes for user-supplied patches.
  48. BR_NO_CHECK_HASH_FOR += $(notdir $(LINUX_PATCHES))
  49. # We rely on the generic package infrastructure to download and apply
  50. # remote patches (downloaded from ftp, http or https). For local
  51. # patches, we can't rely on that infrastructure, because there might
  52. # be directories in the patch list (unlike for other packages).
  53. LINUX_PATCH = $(filter ftp://% http://% https://%,$(LINUX_PATCHES))
  54. LINUX_INSTALL_IMAGES = YES
  55. LINUX_DEPENDENCIES = host-kmod
  56. # Starting with 4.16, the generated kconfig paser code is no longer
  57. # shipped with the kernel sources, so we need flex and bison, but
  58. # only if the host does not have them.
  59. LINUX_KCONFIG_DEPENDENCIES = \
  60. $(BR2_BISON_HOST_DEPENDENCY) \
  61. $(BR2_FLEX_HOST_DEPENDENCY)
  62. # Starting with 4.18, the kconfig in the kernel calls the
  63. # cross-compiler to check its capabilities. So we need the
  64. # toolchain before we can call the configurators.
  65. LINUX_KCONFIG_DEPENDENCIES += toolchain
  66. # host tools needed for kernel compression
  67. ifeq ($(BR2_LINUX_KERNEL_LZ4),y)
  68. LINUX_DEPENDENCIES += host-lz4
  69. else ifeq ($(BR2_LINUX_KERNEL_LZMA),y)
  70. LINUX_DEPENDENCIES += host-lzma
  71. else ifeq ($(BR2_LINUX_KERNEL_LZO),y)
  72. LINUX_DEPENDENCIES += host-lzop
  73. else ifeq ($(BR2_LINUX_KERNEL_XZ),y)
  74. LINUX_DEPENDENCIES += host-xz
  75. endif
  76. LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_GZIP) += CONFIG_KERNEL_GZIP
  77. LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZ4) += CONFIG_KERNEL_LZ4
  78. LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZMA) += CONFIG_KERNEL_LZMA
  79. LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_LZO) += CONFIG_KERNEL_LZO
  80. LINUX_COMPRESSION_OPT_$(BR2_LINUX_KERNEL_XZ) += CONFIG_KERNEL_XZ
  81. ifeq ($(BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL),y)
  82. LINUX_DEPENDENCIES += host-openssl
  83. endif
  84. ifeq ($(BR2_LINUX_KERNEL_NEEDS_HOST_LIBELF),y)
  85. LINUX_DEPENDENCIES += host-elfutils
  86. endif
  87. # If host-uboot-tools is selected by the user, assume it is needed to
  88. # create a custom image
  89. ifeq ($(BR2_PACKAGE_HOST_UBOOT_TOOLS),y)
  90. LINUX_DEPENDENCIES += host-uboot-tools
  91. endif
  92. ifneq ($(ARCH_XTENSA_OVERLAY_FILE),)
  93. define LINUX_XTENSA_OVERLAY_EXTRACT
  94. $(call arch-xtensa-overlay-extract,$(@D),linux)
  95. endef
  96. LINUX_POST_EXTRACT_HOOKS += LINUX_XTENSA_OVERLAY_EXTRACT
  97. LINUX_EXTRA_DOWNLOADS += $(ARCH_XTENSA_OVERLAY_URL)
  98. endif
  99. LINUX_MAKE_FLAGS = \
  100. HOSTCC="$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS)" \
  101. ARCH=$(KERNEL_ARCH) \
  102. INSTALL_MOD_PATH=$(TARGET_DIR) \
  103. CROSS_COMPILE="$(TARGET_CROSS)" \
  104. DEPMOD=$(HOST_DIR)/sbin/depmod
  105. LINUX_MAKE_ENV = \
  106. $(TARGET_MAKE_ENV) \
  107. BR_BINARIES_DIR=$(BINARIES_DIR)
  108. ifeq ($(BR2_REPRODUCIBLE),y)
  109. LINUX_MAKE_ENV += \
  110. KBUILD_BUILD_VERSION=1 \
  111. KBUILD_BUILD_USER=buildroot \
  112. KBUILD_BUILD_HOST=buildroot \
  113. KBUILD_BUILD_TIMESTAMP="$(shell LC_ALL=C date -d @$(SOURCE_DATE_EPOCH))"
  114. endif
  115. # gcc-8 started warning about function aliases that have a
  116. # non-matching prototype. This seems rather useful in general, but it
  117. # causes tons of warnings in the Linux kernel, where we rely on
  118. # abusing those aliases for system call entry points, in order to
  119. # sanitize the arguments passed from user space in registers.
  120. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435
  121. ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_8),y)
  122. LINUX_MAKE_ENV += KCFLAGS=-Wno-attribute-alias
  123. endif
  124. ifeq ($(BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT),y)
  125. LINUX_MAKE_ENV += DTC_FLAGS=-@
  126. endif
  127. # Get the real Linux version, which tells us where kernel modules are
  128. # going to be installed in the target filesystem.
  129. LINUX_VERSION_PROBED = `$(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) --no-print-directory -s kernelrelease 2>/dev/null`
  130. LINUX_DTS_NAME += $(call qstrip,$(BR2_LINUX_KERNEL_INTREE_DTS_NAME))
  131. # We keep only the .dts files, so that the user can specify both .dts
  132. # and .dtsi files in BR2_LINUX_KERNEL_CUSTOM_DTS_PATH. Both will be
  133. # copied to arch/<arch>/boot/dts, but only the .dts files will
  134. # actually be generated as .dtb.
  135. LINUX_DTS_NAME += $(basename $(filter %.dts,$(notdir $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)))))
  136. LINUX_DTBS = $(addsuffix .dtb,$(LINUX_DTS_NAME))
  137. ifeq ($(BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM),y)
  138. LINUX_IMAGE_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_NAME))
  139. LINUX_TARGET_NAME = $(call qstrip,$(BR2_LINUX_KERNEL_IMAGE_TARGET_NAME))
  140. ifeq ($(LINUX_IMAGE_NAME),)
  141. LINUX_IMAGE_NAME = $(LINUX_TARGET_NAME)
  142. endif
  143. else
  144. ifeq ($(BR2_LINUX_KERNEL_UIMAGE),y)
  145. LINUX_IMAGE_NAME = uImage
  146. else ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y)
  147. LINUX_IMAGE_NAME = uImage
  148. else ifeq ($(BR2_LINUX_KERNEL_BZIMAGE),y)
  149. LINUX_IMAGE_NAME = bzImage
  150. else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE),y)
  151. LINUX_IMAGE_NAME = zImage
  152. else ifeq ($(BR2_LINUX_KERNEL_ZIMAGE_EPAPR),y)
  153. LINUX_IMAGE_NAME = zImage.epapr
  154. else ifeq ($(BR2_LINUX_KERNEL_APPENDED_ZIMAGE),y)
  155. LINUX_IMAGE_NAME = zImage
  156. else ifeq ($(BR2_LINUX_KERNEL_CUIMAGE),y)
  157. LINUX_IMAGE_NAME = cuImage.$(firstword $(LINUX_DTS_NAME))
  158. else ifeq ($(BR2_LINUX_KERNEL_SIMPLEIMAGE),y)
  159. LINUX_IMAGE_NAME = simpleImage.$(firstword $(LINUX_DTS_NAME))
  160. else ifeq ($(BR2_LINUX_KERNEL_IMAGE),y)
  161. LINUX_IMAGE_NAME = Image
  162. else ifeq ($(BR2_LINUX_KERNEL_LINUX_BIN),y)
  163. LINUX_IMAGE_NAME = linux.bin
  164. else ifeq ($(BR2_LINUX_KERNEL_VMLINUX_BIN),y)
  165. LINUX_IMAGE_NAME = vmlinux.bin
  166. else ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
  167. LINUX_IMAGE_NAME = vmlinux
  168. else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
  169. LINUX_IMAGE_NAME = vmlinuz
  170. else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ_BIN),y)
  171. LINUX_IMAGE_NAME = vmlinuz.bin
  172. endif
  173. # The if-else blocks above are all the image types we know of, and all
  174. # come from a Kconfig choice, so we know we have LINUX_IMAGE_NAME set
  175. # to something
  176. LINUX_TARGET_NAME = $(LINUX_IMAGE_NAME)
  177. endif
  178. LINUX_KERNEL_UIMAGE_LOADADDR = $(call qstrip,$(BR2_LINUX_KERNEL_UIMAGE_LOADADDR))
  179. ifneq ($(LINUX_KERNEL_UIMAGE_LOADADDR),)
  180. LINUX_MAKE_FLAGS += LOADADDR="$(LINUX_KERNEL_UIMAGE_LOADADDR)"
  181. endif
  182. # Compute the arch path, since i386 and x86_64 are in arch/x86 and not
  183. # in arch/$(KERNEL_ARCH). Even if the kernel creates symbolic links
  184. # for bzImage, arch/i386 and arch/x86_64 do not exist when copying the
  185. # defconfig file.
  186. ifeq ($(KERNEL_ARCH),i386)
  187. LINUX_ARCH_PATH = $(LINUX_DIR)/arch/x86
  188. else ifeq ($(KERNEL_ARCH),x86_64)
  189. LINUX_ARCH_PATH = $(LINUX_DIR)/arch/x86
  190. else
  191. LINUX_ARCH_PATH = $(LINUX_DIR)/arch/$(KERNEL_ARCH)
  192. endif
  193. ifeq ($(BR2_LINUX_KERNEL_VMLINUX),y)
  194. LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
  195. else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ),y)
  196. LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
  197. else ifeq ($(BR2_LINUX_KERNEL_VMLINUZ_BIN),y)
  198. LINUX_IMAGE_PATH = $(LINUX_DIR)/$(LINUX_IMAGE_NAME)
  199. else
  200. LINUX_IMAGE_PATH = $(LINUX_ARCH_PATH)/boot/$(LINUX_IMAGE_NAME)
  201. endif # BR2_LINUX_KERNEL_VMLINUX
  202. define LINUX_APPLY_LOCAL_PATCHES
  203. for p in $(filter-out ftp://% http://% https://%,$(LINUX_PATCHES)) ; do \
  204. if test -d $$p ; then \
  205. $(APPLY_PATCHES) $(@D) $$p \*.patch || exit 1 ; \
  206. else \
  207. $(APPLY_PATCHES) $(@D) `dirname $$p` `basename $$p` || exit 1; \
  208. fi \
  209. done
  210. endef
  211. LINUX_POST_PATCH_HOOKS += LINUX_APPLY_LOCAL_PATCHES
  212. # Older linux kernels use deprecated perl constructs in timeconst.pl
  213. # that were removed for perl 5.22+ so it breaks on newer distributions
  214. # Try a dry-run patch to see if this applies, if it does go ahead
  215. define LINUX_TRY_PATCH_TIMECONST
  216. @if patch -p1 --dry-run -f -s -d $(@D) <$(LINUX_PKGDIR)/0001-timeconst.pl-Eliminate-Perl-warning.patch.conditional >/dev/null ; then \
  217. $(APPLY_PATCHES) $(@D) $(LINUX_PKGDIR) 0001-timeconst.pl-Eliminate-Perl-warning.patch.conditional ; \
  218. fi
  219. endef
  220. LINUX_POST_PATCH_HOOKS += LINUX_TRY_PATCH_TIMECONST
  221. LINUX_KERNEL_CUSTOM_LOGO_PATH = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_LOGO_PATH))
  222. ifneq ($(LINUX_KERNEL_CUSTOM_LOGO_PATH),)
  223. LINUX_DEPENDENCIES += host-imagemagick
  224. define LINUX_KERNEL_CUSTOM_LOGO_CONVERT
  225. $(HOST_DIR)/bin/convert $(LINUX_KERNEL_CUSTOM_LOGO_PATH) \
  226. -dither None -colors 224 -compress none \
  227. $(LINUX_DIR)/drivers/video/logo/logo_linux_clut224.ppm
  228. endef
  229. LINUX_PRE_BUILD_HOOKS += LINUX_KERNEL_CUSTOM_LOGO_CONVERT
  230. endif
  231. ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
  232. LINUX_KCONFIG_DEFCONFIG = $(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG))_defconfig
  233. else ifeq ($(BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG),y)
  234. LINUX_KCONFIG_DEFCONFIG = defconfig
  235. else ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y)
  236. LINUX_KCONFIG_FILE = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE))
  237. endif
  238. LINUX_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES))
  239. LINUX_KCONFIG_EDITORS = menuconfig xconfig gconfig nconfig
  240. # LINUX_MAKE_FLAGS overrides HOSTCC to allow the kernel build to find
  241. # our host-openssl and host-libelf. However, this triggers a bug in
  242. # the kconfig build script that causes it to build with
  243. # /usr/include/ncurses.h (which is typically wchar) but link with
  244. # $(HOST_DIR)/lib/libncurses.so (which is not). We don't actually
  245. # need any host-package for kconfig, so remove the HOSTCC override
  246. # again. In addition, even though linux depends on the toolchain and
  247. # therefore host-ccache would be ready, we use HOSTCC_NOCCACHE for
  248. # consistency with other kconfig packages.
  249. LINUX_KCONFIG_OPTS = $(LINUX_MAKE_FLAGS) HOSTCC="$(HOSTCC_NOCCACHE)"
  250. # If no package has yet set it, set it from the Kconfig option
  251. LINUX_NEEDS_MODULES ?= $(BR2_LINUX_NEEDS_MODULES)
  252. # Make sure the Linux kernel is built with the right endianness. Not
  253. # all architectures support
  254. # CONFIG_CPU_BIG_ENDIAN/CONFIG_CPU_LITTLE_ENDIAN in Linux, but the
  255. # option will be thrown away and ignored if it doesn't exist.
  256. ifeq ($(BR2_ENDIAN),"BIG")
  257. define LINUX_FIXUP_CONFIG_ENDIANNESS
  258. $(call KCONFIG_ENABLE_OPT,CONFIG_CPU_BIG_ENDIAN,$(@D)/.config)
  259. endef
  260. else
  261. define LINUX_FIXUP_CONFIG_ENDIANNESS
  262. $(call KCONFIG_ENABLE_OPT,CONFIG_CPU_LITTLE_ENDIAN,$(@D)/.config)
  263. endef
  264. endif
  265. define LINUX_KCONFIG_FIXUP_CMDS
  266. $(if $(LINUX_NEEDS_MODULES),
  267. $(call KCONFIG_ENABLE_OPT,CONFIG_MODULES,$(@D)/.config))
  268. $(call KCONFIG_ENABLE_OPT,$(strip $(LINUX_COMPRESSION_OPT_y)),$(@D)/.config)
  269. $(foreach opt, $(LINUX_COMPRESSION_OPT_),
  270. $(call KCONFIG_DISABLE_OPT,$(opt),$(@D)/.config)
  271. )
  272. $(LINUX_FIXUP_CONFIG_ENDIANNESS)
  273. $(if $(BR2_arm)$(BR2_armeb),
  274. $(call KCONFIG_ENABLE_OPT,CONFIG_AEABI,$(@D)/.config))
  275. $(if $(BR2_TARGET_ROOTFS_CPIO),
  276. $(call KCONFIG_ENABLE_OPT,CONFIG_BLK_DEV_INITRD,$(@D)/.config))
  277. # As the kernel gets compiled before root filesystems are
  278. # built, we create a fake cpio file. It'll be
  279. # replaced later by the real cpio archive, and the kernel will be
  280. # rebuilt using the linux-rebuild-with-initramfs target.
  281. $(if $(BR2_TARGET_ROOTFS_INITRAMFS),
  282. mkdir -p $(BINARIES_DIR)
  283. touch $(BINARIES_DIR)/rootfs.cpio
  284. $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_SOURCE,"$${BR_BINARIES_DIR}/rootfs.cpio",$(@D)/.config)
  285. $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_UID,0,$(@D)/.config)
  286. $(call KCONFIG_SET_OPT,CONFIG_INITRAMFS_ROOT_GID,0,$(@D)/.config))
  287. $(if $(BR2_ROOTFS_DEVICE_CREATION_STATIC),,
  288. $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS,$(@D)/.config)
  289. $(call KCONFIG_ENABLE_OPT,CONFIG_DEVTMPFS_MOUNT,$(@D)/.config))
  290. $(if $(BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV),
  291. $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config))
  292. $(if $(BR2_PACKAGE_AUDIT),
  293. $(call KCONFIG_ENABLE_OPT,CONFIG_NET,$(@D)/.config)
  294. $(call KCONFIG_ENABLE_OPT,CONFIG_AUDIT,$(@D)/.config))
  295. $(if $(BR2_PACKAGE_INTEL_MICROCODE),
  296. $(call KCONFIG_ENABLE_OPT,CONFIG_MICROCODE,$(@D)/.config)
  297. $(call KCONFIG_ENABLE_OPT,CONFIG_MICROCODE_INTEL,$(@D)/.config))
  298. $(if $(BR2_PACKAGE_KTAP),
  299. $(call KCONFIG_ENABLE_OPT,CONFIG_DEBUG_FS,$(@D)/.config)
  300. $(call KCONFIG_ENABLE_OPT,CONFIG_ENABLE_DEFAULT_TRACERS,$(@D)/.config)
  301. $(call KCONFIG_ENABLE_OPT,CONFIG_PERF_EVENTS,$(@D)/.config)
  302. $(call KCONFIG_ENABLE_OPT,CONFIG_FUNCTION_TRACER,$(@D)/.config))
  303. $(if $(BR2_PACKAGE_LINUX_TOOLS_PERF),
  304. $(call KCONFIG_ENABLE_OPT,CONFIG_PERF_EVENTS,$(@D)/.config))
  305. $(if $(BR2_PACKAGE_PCM_TOOLS),
  306. $(call KCONFIG_ENABLE_OPT,CONFIG_X86_MSR,$(@D)/.config))
  307. $(if $(BR2_PACKAGE_SYSTEMD),
  308. $(call KCONFIG_ENABLE_OPT,CONFIG_CGROUPS,$(@D)/.config)
  309. $(call KCONFIG_ENABLE_OPT,CONFIG_INOTIFY_USER,$(@D)/.config)
  310. $(call KCONFIG_ENABLE_OPT,CONFIG_FHANDLE,$(@D)/.config)
  311. $(call KCONFIG_ENABLE_OPT,CONFIG_AUTOFS4_FS,$(@D)/.config)
  312. $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_POSIX_ACL,$(@D)/.config)
  313. $(call KCONFIG_ENABLE_OPT,CONFIG_TMPFS_XATTR,$(@D)/.config))
  314. $(if $(BR2_PACKAGE_SMACK),
  315. $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY,$(@D)/.config)
  316. $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_SMACK,$(@D)/.config)
  317. $(call KCONFIG_ENABLE_OPT,CONFIG_SECURITY_NETWORK,$(@D)/.config))
  318. $(if $(BR2_PACKAGE_SUNXI_MALI_MAINLINE_DRIVER),
  319. $(call KCONFIG_ENABLE_OPT,CONFIG_CMA,$(@D)/.config)
  320. $(call KCONFIG_ENABLE_OPT,CONFIG_DMA_CMA,$(@D)/.config))
  321. $(if $(BR2_PACKAGE_IPTABLES),
  322. $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_IPTABLES,$(@D)/.config)
  323. $(call KCONFIG_ENABLE_OPT,CONFIG_IP_NF_FILTER,$(@D)/.config)
  324. $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER,$(@D)/.config)
  325. $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_XTABLES,$(@D)/.config))
  326. $(if $(BR2_PACKAGE_XTABLES_ADDONS),
  327. $(call KCONFIG_ENABLE_OPT,CONFIG_NETFILTER_ADVANCED,$(@D)/.config)
  328. $(call KCONFIG_ENABLE_OPT,CONFIG_NF_CONNTRACK,$(@D)/.config)
  329. $(call KCONFIG_ENABLE_OPT,CONFIG_NF_CONNTRACK_MARK,$(@D)/.config))
  330. $(if $(BR2_PACKAGE_WIREGUARD),
  331. $(call KCONFIG_ENABLE_OPT,CONFIG_INET,$(@D)/.config)
  332. $(call KCONFIG_ENABLE_OPT,CONFIG_NET,$(@D)/.config)
  333. $(call KCONFIG_ENABLE_OPT,CONFIG_NET_FOU,$(@D)/.config)
  334. $(call KCONFIG_ENABLE_OPT,CONFIG_CRYPTO,$(@D)/.config)
  335. $(call KCONFIG_ENABLE_OPT,CONFIG_CRYPTO_MANAGER,$(@D)/.config))
  336. $(if $(BR2_LINUX_KERNEL_APPENDED_DTB),
  337. $(call KCONFIG_ENABLE_OPT,CONFIG_ARM_APPENDED_DTB,$(@D)/.config))
  338. $(if $(BR2_PACKAGE_KERNEL_MODULE_IMX_GPU_VIV),
  339. $(call KCONFIG_DISABLE_OPT,CONFIG_MXC_GPU_VIV,$(@D)/.config))
  340. $(if $(LINUX_KERNEL_CUSTOM_LOGO_PATH),
  341. $(call KCONFIG_ENABLE_OPT,CONFIG_FB,$(@D)/.config)
  342. $(call KCONFIG_ENABLE_OPT,CONFIG_LOGO,$(@D)/.config)
  343. $(call KCONFIG_ENABLE_OPT,CONFIG_LOGO_LINUX_CLUT224,$(@D)/.config))
  344. endef
  345. ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT),y)
  346. # Starting with 4.17, the generated dtc parser code is no longer
  347. # shipped with the kernel sources, so we need flex and bison. For
  348. # reproducibility, we use our owns rather than the host ones.
  349. LINUX_DEPENDENCIES += host-bison host-flex
  350. ifeq ($(BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT),)
  351. define LINUX_BUILD_DTB
  352. $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_DTBS)
  353. endef
  354. ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),)
  355. define LINUX_INSTALL_DTB
  356. # dtbs moved from arch/<ARCH>/boot to arch/<ARCH>/boot/dts since 3.8-rc1
  357. cp $(addprefix \
  358. $(LINUX_ARCH_PATH)/boot/$(if $(wildcard \
  359. $(addprefix $(LINUX_ARCH_PATH)/boot/dts/,$(LINUX_DTBS))),dts/),$(LINUX_DTBS)) \
  360. $(1)
  361. endef
  362. endif # BR2_LINUX_KERNEL_APPENDED_DTB
  363. endif # BR2_LINUX_KERNEL_DTB_IS_SELF_BUILT
  364. endif # BR2_LINUX_KERNEL_DTS_SUPPORT
  365. ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
  366. # dtbs moved from arch/$ARCH/boot to arch/$ARCH/boot/dts since 3.8-rc1
  367. define LINUX_APPEND_DTB
  368. (cd $(LINUX_ARCH_PATH)/boot; \
  369. for dtb in $(LINUX_DTS_NAME); do \
  370. if test -e $${dtb}.dtb ; then \
  371. dtbpath=$${dtb}.dtb ; \
  372. else \
  373. dtbpath=dts/$${dtb}.dtb ; \
  374. fi ; \
  375. cat zImage $${dtbpath} > zImage.$${dtb} || exit 1; \
  376. done)
  377. endef
  378. ifeq ($(BR2_LINUX_KERNEL_APPENDED_UIMAGE),y)
  379. # We need to generate a new u-boot image that takes into
  380. # account the extra-size added by the device tree at the end
  381. # of the image. To do so, we first need to retrieve both load
  382. # address and entry point for the kernel from the already
  383. # generate uboot image before using mkimage -l.
  384. LINUX_APPEND_DTB += ; \
  385. MKIMAGE_ARGS=`$(MKIMAGE) -l $(LINUX_IMAGE_PATH) |\
  386. sed -n -e 's/Image Name:[ ]*\(.*\)/-n \1/p' -e 's/Load Address:/-a/p' -e 's/Entry Point:/-e/p'`; \
  387. for dtb in $(LINUX_DTS_NAME); do \
  388. $(MKIMAGE) -A $(MKIMAGE_ARCH) -O linux \
  389. -T kernel -C none $${MKIMAGE_ARGS} \
  390. -d $(LINUX_ARCH_PATH)/boot/zImage.$${dtb} $(LINUX_IMAGE_PATH).$${dtb}; \
  391. done
  392. endif
  393. endif
  394. # Compilation. We make sure the kernel gets rebuilt when the
  395. # configuration has changed.
  396. define LINUX_BUILD_CMDS
  397. $(foreach dts,$(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_DTS_PATH)), \
  398. cp -f $(dts) $(LINUX_ARCH_PATH)/boot/dts/
  399. )
  400. $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) $(LINUX_TARGET_NAME)
  401. @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \
  402. $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(@D) modules ; \
  403. fi
  404. $(LINUX_BUILD_DTB)
  405. $(LINUX_APPEND_DTB)
  406. endef
  407. ifeq ($(BR2_LINUX_KERNEL_APPENDED_DTB),y)
  408. # When a DTB was appended, install the potential several images with
  409. # appended DTBs.
  410. define LINUX_INSTALL_IMAGE
  411. mkdir -p $(1)
  412. cp $(LINUX_ARCH_PATH)/boot/$(LINUX_IMAGE_NAME).* $(1)
  413. endef
  414. else
  415. # Otherwise, just install the unique image generated by the kernel
  416. # build process.
  417. define LINUX_INSTALL_IMAGE
  418. $(INSTALL) -m 0644 -D $(LINUX_IMAGE_PATH) $(1)/$(LINUX_IMAGE_NAME)
  419. endef
  420. endif
  421. ifeq ($(BR2_LINUX_KERNEL_INSTALL_TARGET),y)
  422. define LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET
  423. $(call LINUX_INSTALL_IMAGE,$(TARGET_DIR)/boot)
  424. $(call LINUX_INSTALL_DTB,$(TARGET_DIR)/boot)
  425. endef
  426. endif
  427. define LINUX_INSTALL_HOST_TOOLS
  428. # Installing dtc (device tree compiler) as host tool, if selected
  429. if grep -q "CONFIG_DTC=y" $(@D)/.config; then \
  430. $(INSTALL) -D -m 0755 $(@D)/scripts/dtc/dtc $(HOST_DIR)/bin/linux-dtc ; \
  431. $(if $(BR2_PACKAGE_HOST_DTC),,ln -sf linux-dtc $(HOST_DIR)/bin/dtc;) \
  432. fi
  433. endef
  434. define LINUX_INSTALL_IMAGES_CMDS
  435. $(call LINUX_INSTALL_IMAGE,$(BINARIES_DIR))
  436. $(call LINUX_INSTALL_DTB,$(BINARIES_DIR))
  437. endef
  438. ifeq ($(BR2_STRIP_strip),y)
  439. LINUX_MAKE_FLAGS += INSTALL_MOD_STRIP=1
  440. endif
  441. define LINUX_INSTALL_TARGET_CMDS
  442. $(LINUX_INSTALL_KERNEL_IMAGE_TO_TARGET)
  443. # Install modules and remove symbolic links pointing to build
  444. # directories, not relevant on the target
  445. @if grep -q "CONFIG_MODULES=y" $(@D)/.config; then \
  446. $(LINUX_MAKE_ENV) $(MAKE1) $(LINUX_MAKE_FLAGS) -C $(@D) modules_install; \
  447. rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/build ; \
  448. rm -f $(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED)/source ; \
  449. fi
  450. $(LINUX_INSTALL_HOST_TOOLS)
  451. endef
  452. # Include all our extensions.
  453. #
  454. # Note: our package infrastructure uses the full-path of the last-scanned
  455. # Makefile to determine what package we're currently defining, using the
  456. # last directory component in the path. As such, including other Makefile,
  457. # like below, before we call one of the *-package macro is usally not
  458. # working.
  459. # However, since the files we include here are in the same directory as
  460. # the current Makefile, we are OK. But this is a hard requirement: files
  461. # included here *must* be in the same directory!
  462. include $(sort $(wildcard linux/linux-ext-*.mk))
  463. LINUX_PATCH_DEPENDENCIES += $(foreach ext,$(LINUX_EXTENSIONS),\
  464. $(if $(BR2_LINUX_KERNEL_EXT_$(call UPPERCASE,$(ext))),$(ext)))
  465. LINUX_PRE_PATCH_HOOKS += $(foreach ext,$(LINUX_EXTENSIONS),\
  466. $(if $(BR2_LINUX_KERNEL_EXT_$(call UPPERCASE,$(ext))),\
  467. $(call UPPERCASE,$(ext))_PREPARE_KERNEL))
  468. # Checks to give errors that the user can understand
  469. # When a custom repository has been set, check for the repository version
  470. ifeq ($(BR2_LINUX_KERNEL_CUSTOM_SVN)$(BR2_LINUX_KERNEL_CUSTOM_GIT)$(BR2_LINUX_KERNEL_CUSTOM_HG),y)
  471. ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION)),)
  472. $(error No custom repository version set. Check your BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION setting)
  473. endif
  474. ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_REPO_URL)),)
  475. $(error No custom repo URL set. Check your BR2_LINUX_KERNEL_CUSTOM_REPO_URL setting)
  476. endif
  477. endif
  478. ifeq ($(BR_BUILDING),y)
  479. ifeq ($(BR2_LINUX_KERNEL_USE_DEFCONFIG),y)
  480. # We must use the user-supplied kconfig value, because
  481. # LINUX_KCONFIG_DEFCONFIG will at least contain the
  482. # trailing _defconfig
  483. ifeq ($(call qstrip,$(BR2_LINUX_KERNEL_DEFCONFIG)),)
  484. $(error No kernel defconfig name specified, check your BR2_LINUX_KERNEL_DEFCONFIG setting)
  485. endif
  486. endif
  487. ifeq ($(BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG),y)
  488. ifeq ($(LINUX_KCONFIG_FILE),)
  489. $(error No kernel configuration file specified, check your BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE setting)
  490. endif
  491. endif
  492. ifeq ($(BR2_LINUX_KERNEL_DTS_SUPPORT):$(strip $(LINUX_DTS_NAME)),y:)
  493. $(error No kernel device tree source specified, check your \
  494. BR2_LINUX_KERNEL_INTREE_DTS_NAME / BR2_LINUX_KERNEL_CUSTOM_DTS_PATH settings)
  495. endif
  496. endif # BR_BUILDING
  497. $(eval $(kconfig-package))
  498. # Support for rebuilding the kernel after the cpio archive has
  499. # been generated.
  500. .PHONY: linux-rebuild-with-initramfs
  501. linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_target_installed
  502. linux-rebuild-with-initramfs: $(LINUX_DIR)/.stamp_images_installed
  503. linux-rebuild-with-initramfs: rootfs-cpio
  504. linux-rebuild-with-initramfs:
  505. @$(call MESSAGE,"Rebuilding kernel with initramfs")
  506. # Build the kernel.
  507. $(LINUX_MAKE_ENV) $(MAKE) $(LINUX_MAKE_FLAGS) -C $(LINUX_DIR) $(LINUX_TARGET_NAME)
  508. $(LINUX_APPEND_DTB)
  509. # Copy the kernel image(s) to its(their) final destination
  510. $(call LINUX_INSTALL_IMAGE,$(BINARIES_DIR))
  511. # If there is a .ub file copy it to the final destination
  512. test ! -f $(LINUX_IMAGE_PATH).ub || cp $(LINUX_IMAGE_PATH).ub $(BINARIES_DIR)