linux.mk 23 KB

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