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