Merge remote-tracking branch 'origin/next' into kernel-4.14
[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.14.2
28 RPI_PATCHES = 3.14.79-grsec-ipfire1
29 A7M_PATCHES = 3.14.79-grsec-ipfire1
30
31
32 THISAPP    = linux-$(VER)
33 DL_FILE    = linux-$(VER).tar.xz
34 DL_FROM    = $(URL_IPFIRE)
35 DIR_APP    = $(DIR_SRC)/$(THISAPP)
36 CFLAGS     =
37 CXXFLAGS   =
38
39 PAK_VER    = 73
40 DEPS       = ""
41
42 ifeq "$(BUILD_ARCH)" "i586"
43         KERNEL_ARCH = i386
44 else
45         KERNEL_ARCH = $(BUILD_ARCH)
46 endif
47
48 ifeq "$(BUILD_ARCH)" "aarch64"
49         HEADERS_ARCH = arm64
50 else
51         HEADERS_ARCH = $(BUILD_PLATFORM)
52 endif
53
54 VERSUFIX=ipfire$(KCFG)
55
56 ifeq "$(TOOLCHAIN)" "1"
57         TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)-tools
58         HEADERS_PREFIX = $(TOOLS_DIR)
59 else
60         TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)
61         HEADERS_PREFIX = /usr
62 endif
63
64 ifeq "$(KCFG)" ""
65 LASTKERNEL=1
66 endif
67 ifeq "$(KCFG)" "-kirkwood"
68 LASTKERNEL=1
69 endif
70
71 ###############################################################################
72 # Top-level Rules
73 ###############################################################################
74 objects =$(DL_FILE) \
75         rpi-patches-$(RPI_PATCHES).patch.xz \
76         arm7-multi-patches-$(A7M_PATCHES).patch.xz
77
78 $(DL_FILE)                                      = $(URL_IPFIRE)/$(DL_FILE)
79 rpi-patches-$(RPI_PATCHES).patch.xz             = $(URL_IPFIRE)/rpi-patches-$(RPI_PATCHES).patch.xz
80 arm7-multi-patches-$(A7M_PATCHES).patch.xz      = $(URL_IPFIRE)/arm7-multi-patches-$(A7M_PATCHES).patch.xz
81
82 $(DL_FILE)_MD5                                  = 0164a000bd7b302037de4e91dff3018b
83 rpi-patches-$(RPI_PATCHES).patch.xz_MD5         = a02a7fd54c642c1e3578a00ed22f54f8
84 arm7-multi-patches-$(A7M_PATCHES).patch.xz_MD5  = 6c3b11e51caa278dbeacd1e23c2b171b
85
86 install : $(TARGET)
87
88 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
89
90 download :$(patsubst %,$(DIR_DL)/%,$(objects))
91
92 md5 : $(subst %,%_MD5,$(objects))
93
94 dist:
95         @$(PAK)
96 ###############################################################################
97 # Downloading, checking, md5sum
98 ###############################################################################
99
100 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
101         @$(CHECK)
102
103 $(patsubst %,$(DIR_DL)/%,$(objects)) :
104         @$(LOAD)
105
106 $(subst %,%_MD5,$(objects)) :
107         @$(MD5)
108
109 ###############################################################################
110 # Installation Details
111 ###############################################################################
112
113 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
114         @$(PREBUILD)
115         @rm -rf $(DIR_APP) $(DIR_SRC)/linux && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
116
117         ln -svf linux-$(VER) $(DIR_SRC)/linux
118
119         # Linux Intermediate Queueing Device
120         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.14-imq.diff
121
122         # Layer7-patch
123         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.14-layer7.patch
124
125         # DVB Patches
126         cd $(DIR_APP) && patch -Np2 < $(DIR_SRC)/src/patches/v4l-dvb_fix_tua6034_pll.patch
127
128         # Wlan Patches
129 #       cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/backports-4.2.6-1_ath10k_remove_logspam.patch
130         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-ath_ignore_eeprom_regd.patch
131         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-iwlwifi-noibss_only_on_radar_chan.patch
132 #       cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-rt2x00usb_suppress_queue_warnings.patch
133 #       cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.10.39-add_libertas_uap.patch
134
135         # mISDN Patches
136         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/mISDN_hfc-s_add_id.patch
137         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/mISDN-hfcusb-reportl1down.patch
138
139         # Add LED trigger
140         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.16-ledtrig_netdev.patch
141
142         # Fix igb and e1000e crash
143         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.14.1-igb-e1000e_fix_lock_at_update_stats.patch
144
145         # cs5535audio spams syslog if no ac97 was present (geos router)
146         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8_cs5535audio_fix_logspam_on_geos.patch
147
148         # Add PC Engines APU led support
149         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-apu_leds.patch
150
151         # Fix uevent PHYSDEVDRIVER
152         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-2.6.32.27_mcs7830-fix-driver-name.patch
153
154 ifeq "$(KCFG)" "-kirkwood"
155         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.10.10-mv_cesa_disable_failing_hmac_sha1.patch
156         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.14.22-kirkwood_legacy_boot.patch
157 endif
158
159 ifeq "$(KCFG)" "-multi"
160         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux-3.10-smsc95xx-add_mac_addr_param.patch
161
162         # Apply Arm7-multiarch kernel patches.
163         cd $(DIR_APP) && xzcat $(DIR_DL)/arm7-multi-patches-$(A7M_PATCHES).patch.xz | patch -Np1
164         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/arm-multi-grsec-compile-fixes.patch
165
166         # Install switch api userspace header
167         cd $(DIR_APP) && install -v -m644 include/uapi/linux/switch.h /usr/include/linux/
168
169 endif
170
171 ifeq "$(KCFG)" "-rpi"
172         # Apply Raspberry Pi kernel patches.
173         cd $(DIR_APP) && xzcat $(DIR_DL)/rpi-patches-$(RPI_PATCHES).patch.xz | patch -Np1
174         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-3.14.79-rpi-suspend-not-inline.patch
175 endif
176
177         cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-3.14.79-amba-fix.patch
178
179 ifeq "$(KCFG)" "-headers"
180         # Install the header files
181         cd $(DIR_APP) && make ARCH=$(HEADERS_ARCH) INSTALL_HDR_PATH=dest headers_install
182         -mkdir -pv $(BUILDROOT)/$(HEADERS_PREFIX)/include
183         cd $(DIR_APP) && find dest/include \( -name .install -o -name ..install.cmd \) -delete
184         cd $(DIR_APP) && cp -rv dest/include/* $(BUILDROOT)/$(HEADERS_PREFIX)/include
185 else
186
187         # Install ipfire logo
188         cd $(DIR_APP) && cp -vf $(DIR_SRC)/config/kernel/ipfire_logo.ppm \
189                 drivers/video/logo/logo_linux_clut224.ppm
190
191         # Cleanup kernel source
192         cp $(DIR_SRC)/config/kernel/kernel.config.$(BUILD_ARCH)-$(VERSUFIX) $(DIR_APP)/.config
193         cd $(DIR_APP) && make oldconfig
194         cd $(DIR_APP) && make clean
195         cd $(DIR_APP) && sed -i -e 's/EXTRAVERSION\ =.*/EXTRAVERSION\ =\ -$(VERSUFIX)/' Makefile
196
197 ifeq "$(KCFG)" "-kirkwood"
198         cd $(DIR_APP) && make $(MAKETUNING) uImage modules
199         cd $(DIR_APP) && cp -v arch/arm/boot/uImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
200         cd $(DIR_APP) && cp -v arch/arm/boot/uImage /boot/uImage-$(VERSUFIX)
201 else
202 ifeq "$(KCFG)" "-multi"
203         cd $(DIR_APP) && make $(MAKETUNING) zImage modules
204         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
205         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/zImage-$(VERSUFIX)
206 else
207 ifeq "$(KCFG)" "-rpi"
208         cd $(DIR_APP) && make $(MAKETUNING) zImage modules
209         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
210         cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/kernel.img
211 else
212         cd $(DIR_APP) && make $(MAKETUNING) bzImage modules
213         cd $(DIR_APP) && cp -v arch/$(KERNEL_ARCH)/boot/bzImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
214 endif
215 endif
216 endif
217
218         cd $(DIR_APP) && cp -v System.map /boot/System.map-$(VER)-$(VERSUFIX)
219         cd $(DIR_APP) && cp -v .config /boot/config-$(VER)-$(VERSUFIX)
220         cd $(DIR_APP) && make $(MAKETUNING) modules_install
221
222 ifeq "$(BUILD_PLATFORM)" "arm"
223         cd $(DIR_APP) && make $(MAKETUNING) dtbs
224         cd $(DIR_APP) && for f in $$(find arch/arm/boot/dts/ -name *.dtb); do \
225                                 mkdir -p /boot/dtb-$(VER)-$(VERSUFIX) ; \
226                                 install -m 644 $$f /boot/dtb-$(VER)-$(VERSUFIX)/ ; \
227                         done
228 endif
229
230 ifeq "$(LASTKERNEL)" "1"
231         # Only do this once
232         cd $(DIR_APP) && install -m 755 usr/gen_init_cpio /sbin/
233
234         # Blacklist matroxfb_base
235         echo "blacklist matroxfb_base" >> /etc/modprobe.d/framebuffer.conf
236         # Blacklist old framebuffer modules
237         for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/video -name *fb.ko); do \
238                 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
239         done
240         # Blacklist new drm framebuffer modules
241         for f in $$(ls -1 /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/gpu/drm/*/*.ko); do \
242                 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
243         done
244         sed -i -e "s|.ko||g" /etc/modprobe.d/framebuffer.conf
245
246         # Blacklist isdn modules
247         for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/isdn -name *.ko); do \
248                 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/isdn.conf ; \
249         done
250         sed -i -e "s|.ko||g" /etc/modprobe.d/isdn.conf
251
252         # Disable ipv6 at runtime
253         echo "options ipv6 disable_ipv6=1" > /etc/modprobe.d/ipv6.conf
254 endif
255 endif
256
257         #force new build of external modules and initrd if the kernel was rebuild
258         -rm -f /usr/src/log/*-kmod-$(VER)-$(VERSUFIX)
259         -rm -f /usr/src/log/linux-initrd-$(VER)-$(VERSUFIX)
260
261         @rm -rf $(DIR_SRC)/patch-o-matic* $(DIR_SRC)/iptables* $(DIR_SRC)/squashfs* $(DIR_SRC)/netfilter-layer7-*
262         @$(POSTBUILD)