1# Maintainer: Natanael Copa <ncopa@alpinelinux.org>23_flavor=${FLAVOR:-lts}4pkgname=linux-$_flavor5pkgver=6.18.136_kernver=${pkgver%.*}7pkgrel=28pkgdesc="Linux lts kernel"9url="https://www.kernel.org"10depends="initramfs-generator"11_depends_dev="perl gmp-dev mpc1-dev mpfr-dev elfutils-dev bash flex bison zstd"12makedepends="$_depends_dev sed installkernel bc linux-headers linux-firmware-any openssl-dev>3 mawk13 diffutils elfutils findutils zstd pahole python3 gcc>=13.1.1_git20230624 bpftool"14options="!strip !check"15source="https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz16 0001-powerpc-boot-wrapper-Add-z-notext-flag-for-ppc64le.patch17 0002-x86-Compress-vmlinux-with-zstd-19-instead-of-22.patch18 0003-kexec-add-kexec_load_disabled-boot-option.patch19 0004-objtool-respect-AWK-setting.patch20 0005-powerpc-config-defang-gcc-check-for-stack-protector-.patch21 0001-x86-CPU-AMD-avoid-printing-reset-reasons-on-Xen-domU.patch22 sophgo-fixes.patch23 xe_drm_non_4k_page.patch2425 lts.aarch64.config26 lts.armv7.config27 lts.loongarch64.config28 lts.ppc64le.config29 lts.riscv64.config30 lts.s390x.config31 lts.x86.config32 lts.x86_64.config3334 virt.aarch64.config35 virt.armv7.config36 virt.ppc64le.config37 virt.x86.config38 virt.x86_64.config39 "4041# Allow adding custom flavor config via FLAVOR var42# The config file should be named ${FLAVOR}.${CARCH}.config43if [ -n "$FLAVOR" ]; then44 source="$source45 ${FLAVOR}.${CARCH}.config"46fi4748subpackages="$pkgname-dev:_dev:$CBUILD_ARCH $pkgname-doc"49for _i in $source; do50 case $_i in51 *.$CARCH.config)52 _f=${_i%."$CARCH".config}53 if [ -n "$FLAVOR" ] && [ "$_f" != "$FLAVOR" ]; then54 # skip flavors that don't match55 continue56 fi57 _flavors="$_flavors $_f"58 if [ "linux-$_f" != "$pkgname" ]; then59 subpackages="$subpackages linux-$_f::$CBUILD_ARCH linux-$_f-dev:_dev:$CBUILD_ARCH"60 fi61 ;;62 esac63done64builddir="$srcdir"/linux-$_kernver6566if [ "${pkgver%.0}" = "$pkgver" ]; then67 # Prepend to apply first68 source="patch-$pkgver.patch.xz::https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/patch-$pkgver.xz $source"69fi70arch="loongarch64"71license="GPL-2.0-only"7273# secfixes:74# 5.10.4-r0:75# - CVE-2020-2956876# - CVE-2020-2956977# 5.15.74-r0:78# - CVE-2022-4167479# - CVE-2022-4271980# - CVE-2022-4272081# - CVE-2022-4272182# - CVE-2022-4272283# 6.1.27-r3:84# - CVE-2023-3223385# 6.6.13-r1:86# - CVE-468388788prepare() {89 default_prepare9091 # remove localversion from patch if any92 rm -f localversion*93}9495_kernelarch() {96 local arch="$1"97 case "$arch" in98 aarch64*) arch="arm64" ;;99 arm*) arch="arm" ;;100 ppc*) arch="powerpc" ;;101 s390*) arch="s390" ;;102 riscv*) arch="riscv" ;;103 loongarch64) arch="loongarch" ;;104 esac105 echo "$arch"106}107108_prepareconfig() {109 local _flavor="$1"110 local _arch="$2"111 local _config=$_flavor.$_arch.config112 local _builddir="$srcdir"/build-$_flavor.$_arch113 mkdir -p "$_builddir"114 echo "-$pkgrel-$_flavor" > "$_builddir"/localversion-alpine115116 cp "$srcdir"/$_config "$_builddir"/.config117 msg "Configuring $_flavor kernel ($_arch)"118 make -C "$builddir" \119 O="$_builddir" \120 ARCH="$(_kernelarch $_arch)" \121 olddefconfig122123 if grep "CONFIG_MODULE_SIG=y" "$_builddir"/.config >/dev/null; then124 if [ -f "$KERNEL_SIGNING_KEY" ]; then125 sed -i -e "s:^CONFIG_MODULE_SIG_KEY=.*:CONFIG_MODULE_SIG_KEY=\"$KERNEL_SIGNING_KEY\":" \126 "$_builddir"/.config127 msg "Using $KERNEL_SIGNING_KEY to sign $_flavor kernel ($_arch) modules"128 else129 warning "KERNEL_SIGNING_KEY was not set. A signing key will be generated, but 3rd"130 warning "party modules can not be signed"131 fi132 fi133}134135listconfigs() {136 for i in $source; do137 case "$i" in138 *.config) echo $i;;139 esac140 done141}142143prepareconfigs() {144 for _config in $(listconfigs); do145 local _flavor=${_config%%.*}146 local _arch=${_config%.config}147 _arch=${_arch#*.}148 local _builddir="$srcdir"/build-$_flavor.$_arch149 _prepareconfig "$_flavor" "$_arch"150 done151}152153# this is supposed to be run before version is bumped so we can compare154# what new kernel config knobs are introduced155prepareupdate() {156 clean && fetch && unpack && prepare && deps157 prepareconfigs158 rm -r "$builddir"159}160161updateconfigs() {162 if ! [ -d "$builddir" ]; then163 deps && fetch && unpack && prepare164 fi165 for _config in ${CONFIGS:-$(listconfigs)}; do166 msg "updating $_config"167 local _flavor=${_config%%.*}168 local _arch=${_config%.config}169 _arch=${_arch#*.}170 local _builddir="$srcdir"/build-$_flavor.$_arch171 mkdir -p "$_builddir"172 echo "-$pkgrel-$_flavor" > "$_builddir"/localversion-alpine173 local actions="listnewconfig oldconfig"174 if ! [ -f "$_builddir"/.config ]; then175 cp "$srcdir"/$_config "$_builddir"/.config176 actions="olddefconfig"177 fi178 env | grep ^CONFIG_ >> "$_builddir"/.config || true179 make -j1 -C "$builddir" \180 O="$_builddir" \181 ARCH="$(_kernelarch $_arch)" \182 $actions savedefconfig183184 cp "$_builddir"/defconfig "$startdir"/$_config185 done186}187188set_kbuild_timestamp() {189 # KBUILD_BUILD_TIMESTAMP needs to be parsable by busybox date190 export KBUILD_BUILD_TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S' -u${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH})"191}192193build() {194 unset LDFLAGS195 # for some reason these sometimes leak into the kernel build,196 # -Werror=format-security breaks some stuff197 unset CFLAGS CPPFLAGS CXXFLAGS198 set_kbuild_timestamp199 for i in $_flavors; do200 _prepareconfig "$i" "$CARCH"201 done202 for i in $_flavors; do203 msg "Building $i kernel"204 cd "$srcdir"/build-$i.$CARCH205206 # set org in cert for modules signing207 # https://www.kernel.org/doc/html/v6.1/admin-guide/module-signing.html#generating-signing-keys208 mkdir -p certs209 sed -e 's/#O = Unspecified company/O = alpinelinux.org/' \210 "$builddir"/certs/default_x509.genkey \211 > certs/x509.genkey212213 make ARCH="$(_kernelarch $CARCH)" \214 CC="${CC:-gcc}" \215 AWK="${AWK:-mawk}" \216 KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine"217218 if grep -q '^CONFIG_DEBUG_INFO_BTF=y' .config; then219 # Generate vmlinux.h220 bpftool btf dump file vmlinux format c > vmlinux.h221222 if [ "$CARCH" = "ppc64le" ]; then223 # ppc64le installs the uncompressed vmlinux, which is extremely224 # large with BTF debuginfo unless stripped225 eu-strip --remove-comment vmlinux226 fi227 fi228 done229}230231_package() {232 local _buildflavor="$1" _outdir="$2"233 set_kbuild_timestamp234235 cd "$srcdir"/build-$_buildflavor.$CARCH236 local _abi_release="$(make -s kernelrelease)"237 # modules_install seems to regenerate a defect Modules.symvers on s390x. Work238 # around it by backing it up and restore it after modules_install239 cp Module.symvers Module.symvers.backup240241 mkdir -p "$_outdir"/boot "$_outdir"/lib/modules242243 local _install244 case "$CARCH" in245 arm*|aarch64|riscv*) _install="zinstall dtbs_install";;246 *) _install=install;;247 esac248249 make modules_install $_install \250 ARCH="$(_kernelarch $CARCH)" \251 INSTALL_MOD_PATH="$_outdir" \252 INSTALL_MOD_STRIP=1 \253 INSTALL_PATH="$_outdir"/boot \254 INSTALL_DTBS_PATH="$_outdir/boot/dtbs-$_buildflavor"255256 cp Module.symvers.backup Module.symvers257258 rm -f "$_outdir"/lib/modules/"$_abi_release"/build \259 "$_outdir"/lib/modules/"$_abi_release"/source260 rm -rf "$_outdir"/lib/firmware261262 install -D -m644 include/config/kernel.release \263 "$_outdir"/usr/share/kernel/$_buildflavor/kernel.release264}265266# main flavor installs in $pkgdir267package() {268 depends="$depends linux-firmware-any"269270 _package "$_flavor" "$pkgdir"271272 # copy files for linux-lts-doc sub package273 mkdir -p "$pkgdir"/usr/share/doc274 cp -r "$builddir"/Documentation \275 "$pkgdir"/usr/share/doc/linux-doc-"$pkgver"/276 # remove files that aren't part of the documentation itself277 for nondoc in \278 .gitignore conf.py docutils.conf \279 Kconfig Makefile280 do281 rm "$pkgdir"/usr/share/doc/linux-doc-"$pkgver"/"$nondoc"282 done283 # create /usr/share/doc/linux-doc symlink284 cd "$pkgdir"/usr/share/doc; ln -s linux-doc-"$pkgver" linux-doc285}286287# subflavors install in $subpkgdir288virt() {289 _package virt "$subpkgdir"290}291292_dev() {293 local _flavor=$(echo $subpkgname | sed -E 's/(^linux-|-dev$)//g')294 local _builddir="$srcdir"/build-$_flavor.$CARCH295 local _abi_release="$(make -C "$_builddir" -s kernelrelease)"296 local _karch="$(_kernelarch $CARCH | sed 's/x86_64/x86/')"297 # copy the only the parts that we really need for build 3rd party298 # kernel modules and install those as /usr/src/linux-headers,299 # simlar to what ubuntu does300 #301 # this way you dont need to install the 300-400 kernel sources to302 # build a tiny kernel module303 #304 pkgdesc="Headers and script for third party modules for $_flavor kernel"305 depends="$_depends_dev"306 local dir="$subpkgdir"/usr/src/linux-headers-"$_abi_release"307 set_kbuild_timestamp308309 # first we import config, run prepare to set up for building310 # external modules, and create the scripts311 mkdir -p "$dir"312 cp -a "$_builddir"/.config "$_builddir"/localversion-alpine \313 "$dir"/314315 install -D -t "$dir"/certs "$_builddir"/certs/signing_key.x509 || :316317 # Install vmlinux.h318 if grep -q '^CONFIG_DEBUG_INFO_BTF=y' "$_builddir"/.config; then319 install -Dm644 "$_builddir"/vmlinux.h -t "$dir/"320 fi321322 make -C "$builddir" \323 O="$dir" \324 ARCH="$(_kernelarch $CARCH)" \325 AWK="${AWK:-mawk}" \326 prepare modules_prepare scripts327328 # remove the stuff that points to real sources. we want 3rd party329 # modules to believe this is the sources330 rm "$dir"/Makefile "$dir"/source331332 # copy the needed stuff from real sources333 #334 # this is taken from ubuntu kernel build script335 # http://kernel.ubuntu.com/git/ubuntu/ubuntu-zesty.git/tree/debian/rules.d/3-binary-indep.mk336 cd "$builddir"337 find . -path './include/*' -prune \338 -o -path './scripts/*' -prune -o -type f \339 \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \340 -name '*.sh' -o -name '*.pl' -o -name '*.lds' -o -name 'Platform' \) \341 -print | cpio -pdm "$dir"342343 cp -a scripts include "$dir"344345 find "arch/$_karch" "tools/include" "tools/arch/$_karch" -type f -path '*/include/*' \346 -print | cpio -pdm "$dir"347348 install -Dm644 "$srcdir"/build-$_flavor.$CARCH/Module.symvers \349 "$dir"/Module.symvers350351 # remove unneeded things352 msg "Removing documentation..."353 rm -r "$dir"/Documentation354 sed -i -e '/Documentation/d' "$dir"/Kconfig355 find "$dir" -type f \( -name '*.o' -o -name '*.cmd' \) -exec rm -v -- {} +356357 mkdir -p "$subpkgdir"/lib/modules/"$_abi_release"358 ln -sf /usr/src/linux-headers-"$_abi_release" \359 "$subpkgdir"/lib/modules/"$_abi_release"/build360}361362sha512sums="363cc33f4a83116c0ac91b2c3288eaa6224096f11860aca1ad7ac2ffa5f464bcc5d8dab0df0b3dc4e87c0d5adb905928fad3f96e42084b008836f1c3790d3fde639 patch-6.18.13.patch.xz36488599ffdec96d150c1feb9b261ba93bb0301a9d0e1ad6bef7aeab1f5372cbfc57d8b43c7e902bd8f76921d1dbd8189663c142ea869e51d0e2b483b150ee00fe0 linux-6.18.tar.xz365b296717ef0cd63978142b4d47b3bc49faa04daf77e115e702ba611cc254a6e782cdab7d5639e724cd5f029cfb6a3dc33c3036f346d681d1fdfe0df723c7e0321 0001-powerpc-boot-wrapper-Add-z-notext-flag-for-ppc64le.patch366055e10e7b3e00bb3621389315d5206a8feb5022a1f0dc51c3aa107facfe83d191da05a502a0c62488be7299677a63c1da84f87c42cbf3125788c56db67e810ee 0002-x86-Compress-vmlinux-with-zstd-19-instead-of-22.patch367e1d2d5358f5b8189236108973395f00eafce8db6d5baaf55025b1360f08ab7cffc930d3818719f220b98e7e8541cc8a7f056611b6e290f224a102c1addbe34ac 0003-kexec-add-kexec_load_disabled-boot-option.patch36828c83be4c97152001381cd5e3a8acb8552a42d9dac9aaec8f096e3762b7944035aa5a4363fb4602f9bb427c4f72cfd2f996a0a725f7f9e07ab250317985aff9e 0004-objtool-respect-AWK-setting.patch3695ce79416f8f111c36393718656e3eeb4cb0adccd117dcf661876d1564010e5c58b6351cc4116d187d0a9a838bcca0fecc236d81ac71afb940b89ccb14f21e179 0005-powerpc-config-defang-gcc-check-for-stack-protector-.patch3704e72af8e77a555d2a850837b64a525a51d5d118048584dc3ea0d0e8620bb56bf56b69a94aa67dac879b841c9ba033e33d94610da0028fde7b6602ad2fe63f02f 0001-x86-CPU-AMD-avoid-printing-reset-reasons-on-Xen-domU.patch371855522b816bbb2b0738251cf24714c2566c7aacad39aaf6adcebd0a256d11f64ff2762ecdace0ab1bac38db87fd579863f852f799356a368f057c166e4deb03c sophgo-fixes.patch372a95dbc0a321de716782035d72bb5fab639ab91b67e4a322f5e789bd1213fd9f119346b672fe7ca0d8ba6e01a5d3dde168569520d55f6fefeb8cbbb0f9fb8bed3 xe_drm_non_4k_page.patch373e0495d44f0337e8b87dcaa425159f7c0d9f62a00d8fd360ed494ed0bf744b33b702bd5e69c93e669b2f26f114b52fe84b7b8d0bf37792ede49971d7c4a6c1db0 lts.aarch64.config374b4980153573f79849b242dc18d04108f537b44054c5ffbc8a7e07c099f9c5151cbbd1fd605dd0a7f6efa48a67047355f9b5cc70a8972c1f1a02179fb2e8e12ca lts.armv7.config375beb236f1b175d2a1ce19cd21f8928146e4306e6a7a7cdb73b66c2e914889aa9f521e02ad15514f2c3bfb23180e09ee43c65c94e0bab920923ef520d0c78234ec lts.loongarch64.config376cc11c0463178ef12587703ca1132c72a1e59eaa716d3dda59fe47964556eb98a5a6df024f1cee807e2b82c009f99f78b9d2a51f7c2a1d8744bdef8e3b6ebd8ca lts.ppc64le.config37793854d4420a6a016dd1bd6b9009cf3081eeb0bd0e2b3e1710df1cf4aaaac35f278ca67a7478f9ebc96c517f528023ba4bd6abc3b41cc1e611564270d334864a4 lts.riscv64.config378785e88e7c0fd7bafe9d56f0090e573689e1bab9d6e6a7f1fcad5e619c52d8b9b09f9a02e3cf0e2c6a160146f56d810d5afa2a5e970411bf46502cbb79b82d6e4 lts.s390x.config379837ac36e3780342bdcef444951341667c8e4b287409ec0ac474716d44d2e5bbb462076d19777e07d45f0e9234f5e35795ed04017924896efc1f411b7197b3ef4 lts.x86.config3807d805c39281bc5d760cfe6bcd721162d3337a6dc0b9ea89ff0098f0ebca41bb75af850589b5db10cdab69c6c5f599005f43f9ff5d74a6b005f989fede355c865 lts.x86_64.config381000ac56fa4b4a972f1a0489ac1dfc8410f570e5f1d4067deba928c4c8e7c627de323cfa8f3a69442036e9e23c2049d8c397a430800c93a35b3f021f2e2e60c94 virt.aarch64.config3828b32458a7bfad8241223fb7295dbbe3eaf039ebdfb23c8295723cd6e6f7aaf892b020782c523c312b2cd5c8d9ab7c3712c2ec419826e1433fea80d5c5574e690 virt.armv7.config38392f24e1ebbcd662db3a05386e897ca2db767379338dc383b77a26138cd1f3352f6f1aa6184e80de25f85aaf06c74d247ec95b93ce2d03ae3351606be6c2b3494 virt.ppc64le.config384f218044468547105aec8be38618e187731906434225b8a8b5b904d574bcb3156b838288eb0c4acb45b9cb100dc3bda5059ef69354013c89ae0698012963a64c0 virt.x86.config38520a171a3906733a35530b8b092214cc1170e787307d8ac5dec8b131afcc9f1f2c64ba6f09f2c0591babdec3fa991ad8d62a20eec3a1c949c31ea9d6015685981 virt.x86_64.config386"