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