linux.mk 23 KB

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