linux.mk 25 KB

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