e57b4fd173400ffc79f2716e6977aee2a7728e7d
[ipfire-2.x.git] / lfs / linux
1 ###############################################################################
2 #                                                                             #
3 # IPFire.org - A linux based firewall                                         #
4 # Copyright (C) 2007-2017  IPFire Team <info@ipfire.org>                      #
5 #                                                                             #
6 # This program is free software: you can redistribute it and/or modify        #
7 # it under the terms of the GNU General Public License as published by        #
8 # the Free Software Foundation, either version 3 of the License, or           #
9 # (at your option) any later version.                                         #
10 #                                                                             #
11 # This program is distributed in the hope that it will be useful,             #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
14 # GNU General Public License for more details.                                #
15 #                                                                             #
16 # You should have received a copy of the GNU General Public License           #
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
18 #                                                                             #
19 ###############################################################################
20
21 ###############################################################################
22 # Definitions
23 ###############################################################################
24
25 include Config
26
27 VER         = 4.9.58
28 RPI_PATCHES = 3.14.79-grsec-ipfire1
29 A7M_PATCHES = 3.14.79-grsec-ipfire1
30 GRS_PATCHES = grsecurity-3.1-4.9.58-ipfire1.patch.xz
31
32
33 THISAPP    = linux-$(VER)
34 DL_FILE    = linux-$(VER).tar.xz
35 DL_FROM    = $(URL_IPFIRE)
36 DIR_APP    = $(DIR_SRC)/$(THISAPP)
37 CFLAGS     =
38 CXXFLAGS   =
39
40 PAK_VER    = 73
41 DEPS       = ""
42
43 ifeq "$(BUILD_ARCH)" "i586"
44         KERNEL_ARCH = i386
45 else
46         KERNEL_ARCH = $(BUILD_ARCH)
47 endif
48
49 ifeq "$(BUILD_ARCH)" "aarch64"
50         HEADERS_ARCH = arm64
51 else
52         HEADERS_ARCH = $(BUILD_PLATFORM)
53 endif
54
55 VERSUFIX=ipfire$(KCFG)
56
57 ifeq "$(TOOLCHAIN)" "1"
58         TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)-tools
59         HEADERS_PREFIX = /tools
60 else
61         TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)
62         HEADERS_PREFIX = /usr
63 endif
64
65 ifeq "$(KCFG)" ""
66 LASTKERNEL=1
67 endif
68 ifeq "$(KCFG)" "-kirkwood"
69 LASTKERNEL=1
70 endif
71
72 # The buildsystem does not correctly detect if our compiler supports plugins
73 export DISABLE_PAX_PLUGINS=y
74
75 ###############################################################################
76 # Top-level Rules
77 ###############################################################################
78 objects =$(DL_FILE) \
79         rpi-patches-$(RPI_PATCHES).patch.xz \
80         arm7-multi-patches-$(A7M_PATCHES).patch.xz \
81         $(GRS_PATCHES)
82
83
84 $(DL_FILE)                                      = $(URL_IPFIRE)/$(DL_FILE)
85 rpi-patches-$(RPI_PATCHES).patch.xz             = $(URL_IPFIRE)/rpi-patches-$(RPI_PATCHES).patch.xz
86 arm7-multi-patches-$(A7M_PATCHES).patch.xz      = $(URL_IPFIRE)/arm7-multi-patches-$(A7M_PATCHES).patch.xz
87 $(GRS_PATCHES)                                  = $(URL_IPFIRE)/$(GRS_PATCHES)
88
89 $(DL_FILE)_MD5                                  = 243225673ff85521aab0a9c9a1898c9e
90 rpi-patches-$(RPI_PATCHES).patch.xz_MD5         = a02a7fd54c642c1e3578a00ed22f54f8
91 arm7-multi-patches-$(A7M_PATCHES).patch.xz_MD5  = 6c3b11e51caa278dbeacd1e23c2b171b
92 $(GRS_PATCHES)_MD5                              = 786066df2576fe05730d70e3eb8cfacd
93
94
95 install : $(TARGET)
96
97 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
98
99 download :$(patsubst %,$(DIR_DL)/%,$(objects))
100
101 md5 : $(subst %,%_MD5,$(objects))
102
103 dist:
104         @$(PAK)
105 ###############################################################################
106 # Downloading, checking, md5sum
107 ###############################################################################
108
109 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
110         @$(CHECK)
111
112 $(patsubst %,$(DIR_DL)/%,$(objects)) :
113         @$(LOAD)
114
115 $(subst %,%_MD5,$(objects)) :
116         @$(MD5)
117
118 ###############################################################################
119 # Installation Details
120 ###############################################################################
121
122 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
123         @$(PREBUILD)
124         @rm -rf $(DIR_APP) $(DIR_SRC)/linux && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
125
126         ln -svf linux-$(VER) $(DIR_SRC)/linux
127
128         # Linux Intermediate Queueing Device
129         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9-imq.diff
130
131         # Layer7-patch
132         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.13-layer7.patch
133
134
135 ifneq "$(KCFG)" "-headers"
136         # Grsecurity-patches
137         cd $(DIR_APP) && xz -c -d $(DIR_DL)/$(GRS_PATCHES) | patch -Np1
138         cd $(DIR_APP) && rm localversion-grsec
139 endif
140
141         # DVB Patches
142         cd $(DIR_APP) && patch -Np2 < $(DIR_SRC)/src/patches/v4l-dvb_fix_tua6034_pll.patch
143
144         # Wlan Patches
145         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/backports-4.2.6-1_ath10k_remove_logspam.patch
146         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-ath_ignore_eeprom_regd.patch
147         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-iwlwifi-noibss_only_on_radar_chan.patch
148         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-rt2x00usb_suppress_queue_warnings.patch
149 #       cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.10.39-add_libertas_uap.patch
150
151         # mISDN Patches
152         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/mISDN_hfc-s_add_id.patch
153         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/mISDN-hfcusb-reportl1down.patch
154
155         # Add LED trigger
156         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.16-ledtrig_netdev.patch
157
158         # Fix igb and e1000e crash
159         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.17-igb-e1000e_fix_lock_at_update_stats.patch
160
161         # cs5535audio spams syslog if no ac97 was present (geos router)
162         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8_cs5535audio_fix_logspam_on_geos.patch
163
164         # Add PC Engines APU led support
165         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-apu_leds.patch
166
167         # Fix uevent PHYSDEVDRIVER
168         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-2.6.32.27_mcs7830-fix-driver-name.patch
169
170 ifeq "$(KCFG)" "-kirkwood"
171         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.10.10-mv_cesa_disable_failing_hmac_sha1.patch
172         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.14.22-kirkwood_legacy_boot.patch
173 endif
174
175 ifeq "$(KCFG)" "-multi"
176         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.10-smsc95xx-add_mac_addr_param.patch
177
178         # Apply Arm7-multiarch kernel patches.
179         cd $(DIR_APP) && xzcat $(DIR_DL)/arm7-multi-patches-$(A7M_PATCHES).patch.xz | patch -Np1
180         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/arm-multi-grsec-compile-fixes.patch
181
182         # Install switch api userspace header
183         cd $(DIR_APP) && install -v -m644 include/uapi/linux/switch.h /usr/include/linux/
184
185 endif
186
187 ifeq "$(KCFG)" "-rpi"
188         # Apply Raspberry Pi kernel patches.
189         cd $(DIR_APP) && xzcat $(DIR_DL)/rpi-patches-$(RPI_PATCHES).patch.xz | patch -Np1
190         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-3.14.79-rpi-suspend-not-inline.patch
191 endif
192
193         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-3.14.79-amba-fix.patch
194
195 ifeq "$(KCFG)" "-headers"
196         # Install the header files
197         cd $(DIR_APP) && make ARCH=$(HEADERS_ARCH) INSTALL_HDR_PATH=dest headers_install
198         -mkdir -pv $(BUILDROOT)/$(HEADERS_PREFIX)/include
199         cd $(DIR_APP) && find dest/include \( -name .install -o -name ..install.cmd \) -delete
200         cd $(DIR_APP) && cp -rv dest/include/* $(BUILDROOT)/$(HEADERS_PREFIX)/include
201 else
202
203         # Install ipfire logo
204         cd $(DIR_APP) && cp -vf $(DIR_SRC)/config/kernel/ipfire_logo.ppm \
205                 drivers/video/logo/logo_linux_clut224.ppm
206
207         # Cleanup kernel source
208         cp $(DIR_SRC)/config/kernel/kernel.config.$(BUILD_ARCH)-$(VERSUFIX) $(DIR_APP)/.config
209         cd $(DIR_APP) && make oldconfig
210         cd $(DIR_APP) && make clean
211         cd $(DIR_APP) && sed -i -e 's/EXTRAVERSION\ =.*/EXTRAVERSION\ =\ -$(VERSUFIX)/' Makefile
212
213 ifeq "$(KCFG)" "-kirkwood"
214         cd $(DIR_APP) && make $(MAKETUNING) uImage modules
215         cd $(DIR_APP) && cp -v arch/arm/boot/uImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
216         cd $(DIR_APP) && cp -v arch/arm/boot/uImage /boot/uImage-$(VERSUFIX)
217 else
218 ifeq "$(KCFG)" "-multi"
219         cd $(DIR_APP) && make $(MAKETUNING) zImage modules
220         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
221         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/zImage-$(VERSUFIX)
222 else
223 ifeq "$(KCFG)" "-rpi"
224         cd $(DIR_APP) && make $(MAKETUNING) zImage modules
225         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
226         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/kernel.img
227 else
228         cd $(DIR_APP) && make $(MAKETUNING) bzImage modules
229         cd $(DIR_APP) && cp -v arch/$(KERNEL_ARCH)/boot/bzImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
230 endif
231 endif
232 endif
233
234         cd $(DIR_APP) && cp -v System.map /boot/System.map-$(VER)-$(VERSUFIX)
235         cd $(DIR_APP) && cp -v .config /boot/config-$(VER)-$(VERSUFIX)
236         cd $(DIR_APP) && make $(MAKETUNING) modules_install
237         cd $(DIR_APP) && make $(MAKETUNING) firmware_install
238
239 ifeq "$(BUILD_PLATFORM)" "arm"
240         cd $(DIR_APP) && make $(MAKETUNING) dtbs
241         cd $(DIR_APP) && for f in $$(find arch/arm/boot/dts/ -name *.dtb); do \
242                                 mkdir -p /boot/dtb-$(VER)-$(VERSUFIX) ; \
243                                 install -m 644 $$f /boot/dtb-$(VER)-$(VERSUFIX)/ ; \
244                         done
245 endif
246
247 ifeq "$(LASTKERNEL)" "1"
248         # Only do this once
249         cd $(DIR_APP) && install -m 755 usr/gen_init_cpio /sbin/
250
251         # Blacklist matroxfb_base
252         echo "blacklist matroxfb_base" >> /etc/modprobe.d/framebuffer.conf
253         # Blacklist old framebuffer modules
254         for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/video -name *fb.ko); do \
255                 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
256         done
257         # Blacklist new drm framebuffer modules
258         for f in $$(ls -1 /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/gpu/drm/*/*.ko); do \
259                 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
260         done
261         sed -i -e "s|.ko||g" /etc/modprobe.d/framebuffer.conf
262
263         # Blacklist isdn modules
264         for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/isdn -name *.ko); do \
265                 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/isdn.conf ; \
266         done
267         sed -i -e "s|.ko||g" /etc/modprobe.d/isdn.conf
268
269         # Disable ipv6 at runtime
270         echo "options ipv6 disable_ipv6=1" > /etc/modprobe.d/ipv6.conf
271 endif
272 endif
273
274         #force new build of external modules and initrd if the kernel was rebuild
275         -rm -f /usr/src/log/*-kmod-$(VER)-$(VERSUFIX)
276         -rm -f /usr/src/log/linux-initrd-$(VER)-$(VERSUFIX)
277
278         @rm -rf $(DIR_SRC)/patch-o-matic* $(DIR_SRC)/iptables* $(DIR_SRC)/squashfs* $(DIR_SRC)/netfilter-layer7-*
279         @$(POSTBUILD)