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