linux.mk 27 KB

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