1 ###############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2023 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
19 ###############################################################################
21 ###############################################################################
23 ###############################################################################
28 ARM_PATCHES = 6.1.y-ipfire0
30 THISAPP = linux-$(VER)
31 DL_FILE = linux-$(VER).tar.xz
32 DL_FROM = $(URL_IPFIRE)
33 DIR_APP = $(DIR_SRC)/$(THISAPP)
37 HEADERS_ARCH = $(BUILD_PLATFORM)
38 KERNEL_ARCH = $(BUILD_ARCH)
39 KERNEL_TARGET = bzImage
41 ifeq "$(BUILD_ARCH)" "aarch64"
47 ifeq "$(BUILD_ARCH)" "riscv64"
49 KERNEL_TARGET = Image.gz
52 VERSUFIX=ipfire$(KCFG)
54 ifeq "$(TOOLCHAIN)" "1"
55 TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)-tools
56 HEADERS_PREFIX = $(TOOLS_DIR)
57 EXTRAMAKE = CROSS_COMPILE=$(CROSSTARGET)-
59 TARGET = $(DIR_INFO)/linux-$(VER)-$(VERSUFIX)
67 ###############################################################################
69 ###############################################################################
73 arm-multi-patches-$(ARM_PATCHES).patch.xz
75 $(DL_FILE) = $(URL_IPFIRE)/$(DL_FILE)
76 arm-multi-patches-$(ARM_PATCHES).patch.xz = $(URL_IPFIRE)/arm-multi-patches-$(ARM_PATCHES).patch.xz
78 $(DL_FILE)_BLAKE2 = 2f20ad999655226bc79caca109bde0f940420d87a293cf000f2d8304122bdfcc388c1a558ff26f2f551c9b6133b8fb120dbd537f914e1b88d0fbbd5408e648b0
79 arm-multi-patches-$(ARM_PATCHES).patch.xz_BLAKE2 = 3ef9a778c5c41ee8bf2942a48f63b21228a632a2910d2123f01155bbf571592898cffffa61c387a5a6c817b62e458947b4c406c6591b23b5401faa47b020337f
83 check : $(patsubst %,$(DIR_CHK)/%,$(objects))
85 download :$(patsubst %,$(DIR_DL)/%,$(objects))
87 b2 : $(subst %,%_BLAKE2,$(objects))
92 ###############################################################################
93 # Downloading, checking, b2sum
94 ###############################################################################
96 $(patsubst %,$(DIR_CHK)/%,$(objects)) :
99 $(patsubst %,$(DIR_DL)/%,$(objects)) :
102 $(subst %,%_BLAKE2,$(objects)) :
105 ###############################################################################
106 # Installation Details
107 ###############################################################################
109 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
111 @rm -rf $(DIR_APP) $(DIR_SRC)/linux && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)
113 ln -svf linux-$(VER) $(DIR_SRC)/linux
116 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-6.1-layer7.patch
119 cd $(DIR_APP) && patch -Np2 < $(DIR_SRC)/src/patches/v4l-dvb_fix_tua6034_pll.patch
122 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.14_ath_user_regd.patch
123 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8-iwlwifi-noibss_only_on_radar_chan.patch
125 # Fix igb and e1000e crash
126 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.14.1-igb-e1000e_fix_lock_at_update_stats.patch
128 # cs5535audio spams syslog if no ac97 was present (geos router)
129 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-4.9.8_cs5535audio_fix_logspam_on_geos.patch
131 # Fix uevent PHYSDEVDRIVER
132 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-2.6.32.27_mcs7830-fix-driver-name.patch
134 # fix Boot with enabled usercopy hardening
135 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-5.9-crypto_testmgr_allocate_buffers_with____GFP_COMP.patch
137 # Patch performance monitoring restrictions to allow further hardening
138 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-5.15.17-security-perf-allow-further-restriction-of-perf_event_open.patch
140 # https://bugzilla.ipfire.org/show_bug.cgi?id=12760
141 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-5.15-NFQUEUE-Hold-RCU-read-lock-while-calling-nf_reinject.patch
143 # Fix external module compile
144 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-6.0-fix_external_module_build.patch
146 # Fix pmc compile dependency errors
147 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-6.0.7-platform-x86-amd-Fix-pmc-compile-dependency-errors.patch
149 ifeq "$(BUILD_ARCH)" "aarch64"
150 # Apply Arm-multiarch kernel patches.
151 cd $(DIR_APP) && xzcat $(DIR_DL)/arm-multi-patches-$(ARM_PATCHES).patch.xz | patch -Np1
153 cd $(DIR_APP) && patch -Np1 < $(DIR_SRC)/src/patches/linux/linux-3.14.79-amba-fix.patch
155 ifeq "$(KCFG)" "-headers"
156 # Install the header files
157 cd $(DIR_APP) && make ARCH=$(HEADERS_ARCH) $(EXTRAMAKE) headers
158 -mkdir -pv $(BUILDROOT)/$(HEADERS_PREFIX)/include
159 cd $(DIR_APP) && find usr/include -name '.*' -delete
160 cd $(DIR_APP) && rm usr/include/Makefile
161 cd $(DIR_APP) && cp -rv usr/include/* $(BUILDROOT)/$(HEADERS_PREFIX)/include
164 # Install ipfire logo
165 cd $(DIR_APP) && cp -vf $(DIR_SRC)/config/kernel/ipfire_logo.ppm \
166 drivers/video/logo/logo_linux_clut224.ppm
168 # Cleanup kernel source
169 cp $(DIR_SRC)/config/kernel/kernel.config.$(BUILD_ARCH)-$(VERSUFIX) $(DIR_APP)/.config
170 cd $(DIR_APP) && make oldconfig
171 cd $(DIR_APP) && make clean
172 cd $(DIR_APP) && sed -i -e 's/EXTRAVERSION\ =.*/EXTRAVERSION\ =\ -$(VERSUFIX)/' Makefile
174 # Copy Module signing key configuration
175 cp -f $(DIR_SRC)/config/kernel/x509.genkey $(DIR_APP)/certs/x509.genkey
177 # Remove modules folder if exists
178 rm -rf /lib/modules/$(VER)-$(VERSUFIX)
181 cd $(DIR_APP) && make $(MAKETUNING) $(KERNEL_TARGET) modules
184 cd $(DIR_APP) && cp -v arch/$(KERNEL_ARCH)/boot/$(KERNEL_TARGET) /boot/vmlinuz-$(VER)-$(VERSUFIX)
185 cd $(DIR_APP) && cp -v System.map /boot/System.map-$(VER)-$(VERSUFIX)
186 cd $(DIR_APP) && cp -v .config /boot/config-$(VER)-$(VERSUFIX)
187 cd $(DIR_APP) && make $(MAKETUNING) modules_install
189 ifeq "$(BUILD_PLATFORM)" "arm"
190 cd $(DIR_APP) && make $(MAKETUNING) dtbs
191 mkdir -p /boot/dtb-$(VER)-$(VERSUFIX)
192 cd $(DIR_APP)/arch/$(KERNEL_ARCH)/boot/dts && for f in $$(find -name "*.dtb"); do \
193 cp -v --parents $$f /boot/dtb-$(VER)-$(VERSUFIX)/ ; \
194 chmod 644 /boot/dtb-$(VER)-$(VERSUFIX)/$$f ; \
198 # Recreate source and build links
199 rm -rf /lib/modules/$(VER)-$(VERSUFIX)/{build,source}
200 mkdir -p /lib/modules/$(VER)-$(VERSUFIX)/build
201 ln -sf build /lib/modules/$(VER)-$(VERSUFIX)/source
203 # Create dirs for extra modules
204 mkdir -p /lib/modules/$(VER)-$(VERSUFIX)/extra
206 cd $(DIR_APP) && cp --parents $$(find -type f -name "Makefile*" -o -name "Kconfig*") \
207 /lib/modules/$(VER)-$(VERSUFIX)/build
208 cd $(DIR_APP) && cp Module.symvers System.map /lib/modules/$(VER)-$(VERSUFIX)/build
209 rm -rf /lib/modules/$(VER)-$(VERSUFIX)/build/{Documentation,scripts,include}
211 cd $(DIR_APP) && cp .config /lib/modules/$(VER)-$(VERSUFIX)/build
212 cd $(DIR_APP) && cp -a scripts /lib/modules/$(VER)-$(VERSUFIX)/build
213 find /lib/modules/$(VER)-$(VERSUFIX)/build/scripts -name "*.o" -exec rm -vf {} \;
215 cd $(DIR_APP) && cp -a --parents arch/$(HEADERS_ARCH)/include /lib/modules/$(VER)-$(VERSUFIX)/build
216 cd $(DIR_APP) && cp -a include /lib/modules/$(VER)-$(VERSUFIX)/build/include
218 # Copy module signing key for off tree modules
219 cd $(DIR_APP) && cp -f certs/signing_key.* /lib/modules/$(VER)-$(VERSUFIX)/build/certs/
222 cd $(DIR_APP) && cp -a tools/objtool/objtool \
223 /lib/modules/$(VER)-$(VERSUFIX)/build/tools/objtool/ || :
224 cd $(DIR_APP) && cp -a --parents tools/build/{Build,Build.include,fixdep.c} \
225 tools/scripts/utilities.mak /lib/modules/$(VER)-$(VERSUFIX)/build
227 # Make sure we can build external modules
228 touch -r /lib/modules/$(VER)-$(VERSUFIX)/build/Makefile \
229 /lib/modules/$(VER)-$(VERSUFIX)/build/include/generated/uapi/linux/version.h
230 touch -r /lib/modules/$(VER)-$(VERSUFIX)/build/.config \
231 /lib/modules/$(VER)-$(VERSUFIX)/build/autoconf.h
232 cp /lib/modules/$(VER)-$(VERSUFIX)/build/.config \
233 /lib/modules/$(VER)-$(VERSUFIX)/build/include/config/auto.conf
236 find /lib/modules/$(VER)-$(VERSUFIX) -name "modules.order" \
237 -exec chmod 644 {} \;
239 find /lib/modules/$(VER)-$(VERSUFIX) -name ".*.cmd" -exec rm -f {} \;
241 ifeq "$(LASTKERNEL)" "1"
243 cd $(DIR_APP) && install -m 755 usr/gen_init_cpio /sbin/
245 # disable drm by install drm to /bin/false because i915 ignore blacklisting
246 echo install drm /bin/false > /etc/modprobe.d/framebuffer.conf
248 # Blacklist old framebuffer modules
249 for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/video/fbdev/ -name *.ko.xz); do \
250 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
252 # Blacklist new drm framebuffer modules
253 for f in $$(find /lib/modules/$(VER)-$(VERSUFIX)/kernel/drivers/gpu/drm -name *.ko.xz); do \
254 echo "blacklist $$(basename $$f)" >> /etc/modprobe.d/framebuffer.conf ; \
256 sed -i -e "s|.ko.xz||g" /etc/modprobe.d/framebuffer.conf
258 # Disable ipv6 at runtime
259 echo "options ipv6 disable_ipv6=1" > /etc/modprobe.d/ipv6.conf
263 #force new build of external modules and initrd if the kernel was rebuild
264 -rm -f /usr/src/log/*-kmod-$(VER)-$(VERSUFIX)
265 -rm -f /usr/src/log/linux-initrd-$(VER)-$(VERSUFIX)
267 @rm -rf $(DIR_APP) $(DIR_SRC)/linux