2
1

linux.mk 25 KB

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