1
0

kernel-defaults.mk 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #
  2. # Copyright (C) 2006-2015 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifdef CONFIG_STRIP_KERNEL_EXPORTS
  8. KERNEL_MAKEOPTS += \
  9. EXTRA_LDSFLAGS="-I$(KERNEL_BUILD_DIR) -include symtab.h"
  10. endif
  11. INITRAMFS_EXTRA_FILES ?= $(GENERIC_PLATFORM_DIR)/image/initramfs-base-files.txt
  12. ifneq (,$(KERNEL_CC))
  13. KERNEL_MAKEOPTS += CC="$(KERNEL_CC)"
  14. endif
  15. export HOST_EXTRACFLAGS=-I$(STAGING_DIR_HOST)/include
  16. # defined in quilt.mk
  17. Kernel/Patch:=$(Kernel/Patch/Default)
  18. ifneq (,$(findstring .xz,$(LINUX_SOURCE)))
  19. LINUX_CAT:=xzcat
  20. else
  21. LINUX_CAT:=zcat
  22. endif
  23. ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
  24. ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
  25. define Kernel/Prepare/Default
  26. $(LINUX_CAT) $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
  27. $(Kernel/Patch)
  28. $(if $(QUILT),touch $(LINUX_DIR)/.quilt_used)
  29. endef
  30. else
  31. define Kernel/Prepare/Default
  32. $(LINUX_CAT) $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
  33. endef
  34. endif
  35. else
  36. define Kernel/Prepare/Default
  37. mkdir -p $(KERNEL_BUILD_DIR)
  38. if [ -d $(LINUX_DIR) ]; then \
  39. rmdir $(LINUX_DIR); \
  40. fi
  41. ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
  42. endef
  43. endif
  44. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  45. ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
  46. define Kernel/SetInitramfs/PreConfigure
  47. grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  48. echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
  49. echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
  50. endef
  51. else
  52. define Kernel/SetInitramfs/PreConfigure
  53. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  54. echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
  55. endef
  56. endif
  57. define Kernel/SetInitramfs
  58. rm -f $(LINUX_DIR)/.config.prev
  59. mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
  60. $(call Kernel/SetInitramfs/PreConfigure)
  61. echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
  62. echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
  63. echo "$(if $(CONFIG_TARGET_INITRAMFS_FORCE),CONFIG_INITRAMFS_FORCE=y,# CONFIG_INITRAMFS_FORCE is not set)" >> $(LINUX_DIR)/.config
  64. echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
  65. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),CONFIG_INITRAMFS_COMPRESSION_GZIP=y\nCONFIG_RD_GZIP=y,# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n# CONFIG_RD_GZIP is not set)" >> $(LINUX_DIR)/.config
  66. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),CONFIG_INITRAMFS_COMPRESSION_BZIP2=y\nCONFIG_RD_BZIP2=y,# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n# CONFIG_RD_BZIP2 is not set)" >> $(LINUX_DIR)/.config
  67. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),CONFIG_INITRAMFS_COMPRESSION_LZMA=y\nCONFIG_RD_LZMA=y,# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n# CONFIG_RD_LZMA is not set)" >> $(LINUX_DIR)/.config
  68. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),CONFIG_INITRAMFS_COMPRESSION_LZO=y\nCONFIG_RD_LZO=y,# CONFIG_INITRAMFS_COMPRESSION_LZO is not set\n# CONFIG_RD_LZO is not set)" >> $(LINUX_DIR)/.config
  69. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),CONFIG_INITRAMFS_COMPRESSION_XZ=y\nCONFIG_RD_XZ=y,# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n# CONFIG_RD_XZ is not set)" >> $(LINUX_DIR)/.config
  70. echo -e "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),CONFIG_INITRAMFS_COMPRESSION_LZ4=y\nCONFIG_RD_LZ4=y,# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set\n# CONFIG_RD_LZ4 is not set)" >> $(LINUX_DIR)/.config
  71. endef
  72. else
  73. endif
  74. define Kernel/SetNoInitramfs
  75. mv $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.old
  76. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config.set
  77. echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config.set
  78. echo '# CONFIG_INITRAMFS_FORCE is not set' >> $(LINUX_DIR)/.config.set
  79. endef
  80. define Kernel/Configure/Default
  81. rm -f $(LINUX_DIR)/localversion
  82. $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
  83. # copy CONFIG_KERNEL_* settings over to .config.target
  84. awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
  85. echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target
  86. echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
  87. echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> $(LINUX_DIR)/.config.target
  88. $(SCRIPT_DIR)/package-metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
  89. $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config.set
  90. $(call Kernel/SetNoInitramfs)
  91. rm -rf $(KERNEL_BUILD_DIR)/modules
  92. cmp -s $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev || { \
  93. cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config; \
  94. cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev; \
  95. }
  96. $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(KERNEL_MAKE) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
  97. grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C sort | mkhash md5 > $(LINUX_DIR)/.vermagic
  98. endef
  99. define Kernel/Configure/Initramfs
  100. $(call Kernel/SetInitramfs)
  101. endef
  102. define Kernel/CompileModules/Default
  103. rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
  104. +$(KERNEL_MAKE) modules
  105. endef
  106. OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
  107. # AMD64 shares the location with x86
  108. ifeq ($(LINUX_KARCH),x86_64)
  109. IMAGES_DIR:=../../x86/boot
  110. endif
  111. define Kernel/CopyImage
  112. cmp -s $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug || { \
  113. $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1); \
  114. $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf; \
  115. $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug; \
  116. $(foreach k, \
  117. $(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out vmlinux dtbs,$(KERNELNAME))), \
  118. $(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1); \
  119. ) \
  120. }
  121. endef
  122. define Kernel/CompileImage/Default
  123. rm -f $(TARGET_DIR)/init
  124. +$(KERNEL_MAKE) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  125. $(call Kernel/CopyImage)
  126. endef
  127. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  128. define Kernel/CompileImage/Initramfs
  129. $(call Kernel/Configure/Initramfs)
  130. $(CP) $(GENERIC_PLATFORM_DIR)/other-files/init $(TARGET_DIR)/init
  131. rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
  132. +$(KERNEL_MAKE) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  133. $(call Kernel/CopyImage,-initramfs)
  134. endef
  135. else
  136. define Kernel/CompileImage/Initramfs
  137. endef
  138. endif
  139. define Kernel/Clean/Default
  140. rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
  141. rm -f $(LINUX_KERNEL)
  142. $(_SINGLE)$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
  143. endef