1
0

kernel-defaults.mk 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
  19. ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
  20. define Kernel/Prepare/Default
  21. xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
  22. $(Kernel/Patch)
  23. $(if $(QUILT),touch $(LINUX_DIR)/.quilt_used)
  24. endef
  25. else
  26. define Kernel/Prepare/Default
  27. xzcat $(DL_DIR)/$(LINUX_SOURCE) | $(TAR) -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
  28. endef
  29. endif
  30. else
  31. define Kernel/Prepare/Default
  32. mkdir -p $(KERNEL_BUILD_DIR)
  33. if [ -d $(LINUX_DIR) ]; then \
  34. rmdir $(LINUX_DIR); \
  35. fi
  36. ln -s $(CONFIG_EXTERNAL_KERNEL_TREE) $(LINUX_DIR)
  37. endef
  38. endif
  39. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  40. ifeq ($(strip $(CONFIG_EXTERNAL_CPIO)),"")
  41. define Kernel/SetInitramfs/PreConfigure
  42. grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  43. echo 'CONFIG_BLK_DEV_INITRD=y' >> $(LINUX_DIR)/.config
  44. echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $(LINUX_DIR)/.config
  45. endef
  46. else
  47. define Kernel/SetInitramfs/PreConfigure
  48. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  49. echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $(LINUX_DIR)/.config
  50. endef
  51. endif
  52. define Kernel/SetInitramfs
  53. rm -f $(LINUX_DIR)/.config.prev
  54. mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
  55. $(call Kernel/SetInitramfs/PreConfigure)
  56. echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $(LINUX_DIR)/.config
  57. echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $(LINUX_DIR)/.config
  58. echo "$(if $(CONFIG_TARGET_INITRAMFS_FORCE),CONFIG_INITRAMFS_FORCE=y,# CONFIG_INITRAMFS_FORCE is not set)" >> $(LINUX_DIR)/.config
  59. echo "$(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE),CONFIG_INITRAMFS_COMPRESSION_NONE=y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set)" >> $(LINUX_DIR)/.config
  60. 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
  61. 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
  62. 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
  63. 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
  64. 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
  65. 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
  66. endef
  67. else
  68. endif
  69. define Kernel/SetNoInitramfs
  70. mv $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.old
  71. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config.set
  72. echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config.set
  73. echo '# CONFIG_INITRAMFS_FORCE is not set' >> $(LINUX_DIR)/.config.set
  74. endef
  75. define Kernel/Configure/Default
  76. rm -f $(LINUX_DIR)/localversion
  77. $(LINUX_CONF_CMD) > $(LINUX_DIR)/.config.target
  78. # copy CONFIG_KERNEL_* settings over to .config.target
  79. awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $(TOPDIR)/.config >> $(LINUX_DIR)/.config.target
  80. echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $(LINUX_DIR)/.config.target
  81. echo "# CONFIG_KALLSYMS_ALL is not set" >> $(LINUX_DIR)/.config.target
  82. echo "CONFIG_KALLSYMS_UNCOMPRESSED=y" >> $(LINUX_DIR)/.config.target
  83. $(SCRIPT_DIR)/package-metadata.pl kconfig $(TMP_DIR)/.packageinfo $(TOPDIR)/.config $(KERNEL_PATCHVER) > $(LINUX_DIR)/.config.override
  84. $(SCRIPT_DIR)/kconfig.pl 'm+' '+' $(LINUX_DIR)/.config.target /dev/null $(LINUX_DIR)/.config.override > $(LINUX_DIR)/.config.set
  85. $(call Kernel/SetNoInitramfs)
  86. rm -rf $(KERNEL_BUILD_DIR)/modules
  87. cmp -s $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev || { \
  88. cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config; \
  89. cp $(LINUX_DIR)/.config.set $(LINUX_DIR)/.config.prev; \
  90. }
  91. $(_SINGLE) [ -d $(LINUX_DIR)/user_headers ] || $(KERNEL_MAKE) INSTALL_HDR_PATH=$(LINUX_DIR)/user_headers headers_install
  92. grep '=[ym]' $(LINUX_DIR)/.config.set | LC_ALL=C sort | mkhash md5 > $(LINUX_DIR)/.vermagic
  93. endef
  94. define Kernel/Configure/Initramfs
  95. $(call Kernel/SetInitramfs)
  96. endef
  97. define Kernel/CompileModules/Default
  98. rm -f $(LINUX_DIR)/vmlinux $(LINUX_DIR)/System.map
  99. +$(KERNEL_MAKE) modules
  100. endef
  101. OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
  102. # AMD64 shares the location with x86
  103. ifeq ($(LINUX_KARCH),x86_64)
  104. IMAGES_DIR:=../../x86/boot
  105. endif
  106. define Kernel/CopyImage
  107. cmp -s $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug || { \
  108. $(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1); \
  109. $(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf; \
  110. $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).debug; \
  111. $(foreach k, \
  112. $(if $(KERNEL_IMAGES),$(KERNEL_IMAGES),$(filter-out vmlinux dtbs,$(KERNELNAME))), \
  113. $(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1); \
  114. ) \
  115. }
  116. endef
  117. define Kernel/CompileImage/Default
  118. rm -f $(TARGET_DIR)/init
  119. +$(KERNEL_MAKE) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  120. $(call Kernel/CopyImage)
  121. endef
  122. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  123. define Kernel/CompileImage/Initramfs
  124. $(call Kernel/Configure/Initramfs)
  125. $(CP) $(GENERIC_PLATFORM_DIR)/other-files/init $(TARGET_DIR)/init
  126. rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
  127. +$(KERNEL_MAKE) $(if $(KERNELNAME),$(KERNELNAME),all) modules
  128. $(call Kernel/CopyImage,-initramfs)
  129. endef
  130. else
  131. define Kernel/CompileImage/Initramfs
  132. endef
  133. endif
  134. define Kernel/Clean/Default
  135. rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
  136. rm -f $(LINUX_KERNEL)
  137. $(_SINGLE)$(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
  138. endef